日报
This commit is contained in:
@@ -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'));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user