This commit is contained in:
2025-04-11 11:32:41 +08:00
parent f9175f7dd4
commit 88dc849bd5
8 changed files with 435 additions and 11 deletions
+100
View File
@@ -0,0 +1,100 @@
<?php
namespace app\controller;
use app\middleware\DataTracker;
use app\model\Daily;
use app\model\FeishuUser;
use app\model\User;
use app\util\Util;
use config\constants\Constants;
use support\Log;
use support\Request;
use support\exception\BusinessException;
class DailyController
{
/**
* 日报列表
* @return \support\Response
*/
public function list(Request $request)
{
$page = $request->input('page', 1);
$perPage = $request->input('per_page', 10);
//id
$user_id = $request->user['id'];
if(Util::isEmpty($user_id)){
return Util::fail([],'user_id'.trans('not_null'));
}
$where = [];
$where['user_id'] = $user_id;
// 执行分页查询
$data = Daily::with('user')->where($where)
->orderBy('id', 'desc')
->paginate($perPage, ['*'], 'page', $page);
return Util::success($data,trans('success'));
}
/**
* 日报列表
* @return \support\Response
*/
public function detail(Request $request)
{
//日报id
$id = Util::getParam($request,'id');
if(Util::isEmpty($id)){
return Util::fail([],'id'.trans('not_null'));
}
$where = [];
$where['id'] = $id;
// 执行分页查询
$data = Daily::with('user')->where($where)
->first();
$data['self'] = 0;
return Util::success($data,trans('success'));
}
/**
* 日报编辑
* @param Request $request
* @return \support\Response
*/
public function save(Request $request)
{
$id = Util::getParam($request, 'id');
$text = Util::getParam($request, 'text');
if (empty($id)) {
return Util::fail([], '日报id' . trans('not_null'));
}
if (Util::isEmpty($text)) {
return Util::fail([], 'text' . trans('not_null'));
}
$data = [
'text' => $text,
'remark' => Util::getParam($request, 'remark', '')
];
$res = Daily::where(['id' => $id])->update($data);
if ($res) {
return Util::success($res,trans('save_success'));
} else {
return Util::fail($res,trans('save_fail'));
}
}
}
+85 -9
View File
@@ -141,17 +141,18 @@ class FeishuController
/**
* @param $receiveId openid
* @param $title 推送标题
* @param $content 推送内容
* @param $href 详情链接
* @param $receiveId //openid
* @param $title //推送标题
* @param $content //推送内容
* @param $href //详情链接
* @param $msgType = 'post'; //卡片消息:interactive,富文本消息:post
* @return \support\Response
*/
public static function send($config='xinyouhe',$receiveId='ou_e33bb3017ada6c4781398a68e55a4696',$title='ceshi',$content='测试',$href='http://219.157.255.213:8085/pages/index/mine')
public static function send($config='xinyouhe',$receiveId='ou_e33bb3017ada6c4781398a68e55a4696',$content = '' , $msgType = 'post')
{
// 获取凭证
$certificate = config('feishu.'.$config);
Log::info('feishu send', [$certificate,'config'=>$config,'receiveId' => $receiveId, 'title' => $title, 'content' => $content, 'href' => $href]);
Log::info('feishu send', [$certificate,'config'=>$config,'receiveId' => $receiveId, 'content' => $content]);
// 飞书服务
$class = new \app\service\FeishuService($certificate['appId'], $certificate['appSecret'], $certificate['state']);
@@ -160,7 +161,7 @@ class FeishuController
// $receiveId = 'ou_a3b97543acbf1b28d978356bb08f85dd';
// 富文本 类型
$content = "{
/*$content = "{
\"zh_cn\":{
\"title\":\"$title\",
\"content\":[
@@ -179,7 +180,7 @@ class FeishuController
}]
]
}
}";
}";*/
// 卡片 类型
/*$content = "{
@@ -212,13 +213,88 @@ class FeishuController
}
}";*/
// $msgType = 'interactive';
$msgType = 'post'; //卡片消息:interactive,富文本消息:post
// $msgType = 'post'; //卡片消息:interactive,富文本消息:post
$receiveIdtype = 'open_id';
$result = $class->sendMessages($receiveId, $content, $msgType, $receiveIdtype);
return json($result);
}
/**
* 富文本消息
* @param $title
* @param $content
* @param $href
* @return string
*/
public static function postMsg($title,$content,$href)
{
// 富文本 类型
$content = "{
\"zh_cn\":{
\"title\":\"$title\",
\"content\":[
[{
\"tag\":\"text\",
\"text\":\"$content\",
\"style\":[\"bold\"]
}],
[{
\"tag\":\"hr\"
}],
[{
\"tag\":\"a\",
\"href\":\"$href\",
\"text\":\"查看详情\"
}]
]
}
}";
return $content;
}
/**
* 卡片消息
* @param $title
* @param $content
* @param $href
* @return string
*/
public static function interactiveMsg($title,$content,$href)
{
// 富文本 类型
$content = "{
\"config\":{
\"wide_screen_mode\":true
},
\"elements\":[{
\"tag\":\"div\",
\"text\":{
\"content\":\"$content \",
\"tag\":\"lark_md\"
}},{
\"actions\":[{
\"tag\":\"button\",
\"text\":{
\"content\":\"立即查看\",
\"tag\":\"plain_text\"
},
\"type\":\"primary\",
\"url\":\"$href\"
}],
\"tag\":\"action\"
}],
\"header\":{
\"template\":\"turquoise\",
\"title\":{
\"content\":\"📚$title\",
\"tag\":\"plain_text\"
}
}
}";
return $content;
}
public function show()
{
return '<div>查看详情 - 示例页面</div>';