107 lines
2.4 KiB
PHP
107 lines
2.4 KiB
PHP
<?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
|
|
$userId = $request->user['id'];
|
|
if(Util::isEmpty($userId)){
|
|
return Util::fail([],'user_id'.trans('not_null'));
|
|
}
|
|
|
|
$where = [];
|
|
|
|
//判断领导
|
|
$mast = config('const.daily_group_2');
|
|
if ($userId == $mast['master']) {
|
|
$where['leader_id'] = $mast['master'];
|
|
}else{
|
|
$where['user_id'] = $userId;
|
|
}
|
|
|
|
// 执行分页查询
|
|
$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'));
|
|
}
|
|
}
|
|
|
|
} |