diff --git a/app/api/controller/Demo.php b/app/api/controller/Demo.php index 5c8f05e..c88539b 100644 --- a/app/api/controller/Demo.php +++ b/app/api/controller/Demo.php @@ -13,7 +13,9 @@ use Firebase\JWT\JWT; use Firebase\JWT\Key; use think\facade\Db; use think\facade\Request; - +use app\project\model\ProjectTask as TaskList; +use app\project\validate\TaskCheck; +use think\exception\ValidateException; class Demo extends BaseController { /** @@ -21,7 +23,7 @@ class Demo extends BaseController * @var array */ protected $middleware = [ - Auth::class => ['except' => ['index','login'] ] + Auth::class => ['except' => ['index','login','task_add'] ] ]; /** @@ -128,4 +130,48 @@ class Demo extends BaseController $userInfo = Db::name('Admin')->where(['id' => $uid])->find(); $this->apiSuccess('请求成功', ['user' => $userInfo]); } + + //添加 + public function task_add() + { + $param = get_params(); + if (request()->isPost()) { + if (isset($param['end_time'])) { + $param['end_time'] = strtotime(urldecode($param['end_time'])); + } + + try { + validate(TaskCheck::class)->scene('add')->check($param); + } catch (ValidateException $e) { + // 验证失败 输出错误信息 + return to_assign(1, $e->getError()); + } + $param['create_time'] = time(); + $param['admin_id'] = 1; + if(!empty($param['md5']) &&strlen($param['md5'])>2){ + $id = TaskList::where('md5',$param['md5'])->value('id'); + if($id){ + return to_assign(1,'已存在'); + } + } + $sid = TaskList::strict(false)->field(true)->insertGetId($param); + if ($sid) { + add_log('add', $sid, $param); + $log_data = array( + 'module' => 'task', + 'task_id' => $sid, + 'new_content' => $param['title'], + 'field' => 'new', + 'action' => 'add', + 'admin_id' => 1, + 'create_time' => time(), + ); + Db::name('ProjectLog')->strict(false)->field(true)->insert($log_data); + //发消息 + //$users = $param['director_uid']; + //sendMessage($users, 21, ['title' => $param['title'],'from_uid' => $this->uid, 'create_time'=>date('Y-m-d H:i:s',time()), 'action_id' => $sid]); + } + return to_assign(); + } + } } diff --git a/app/api/controller/Index.php b/app/api/controller/Index.php index 60ec358..0eb3a2e 100644 --- a/app/api/controller/Index.php +++ b/app/api/controller/Index.php @@ -10,22 +10,12 @@ declare(strict_types=1); namespace app\api\controller; -use app\project\model\ProjectTask as TaskList; use app\api\BaseController; use think\facade\Db; -use app\project\validate\TaskCheck; -use think\exception\ValidateException; -use app\api\middleware\Auth; class Index extends BaseController { - /** - * 控制器中间件 [登录、注册 不需要鉴权] - * @var array - */ - protected $middleware = [ - Auth::class => ['except' => ['task_add'] ] - ]; + //上传文件 public function upload() { @@ -663,48 +653,4 @@ class Index extends BaseController $cate = get_work_cate(); return to_assign(0, '', $cate); } - - //添加 - public function task_add() - { - $param = get_params(); - if (request()->isPost()) { - if (isset($param['end_time'])) { - $param['end_time'] = strtotime(urldecode($param['end_time'])); - } - - try { - validate(TaskCheck::class)->scene('add')->check($param); - } catch (ValidateException $e) { - // 验证失败 输出错误信息 - return to_assign(1, $e->getError()); - } - $param['create_time'] = time(); - $param['admin_id'] = 1; - if(!empty($param['md5']) &&strlen($param['md5'])>2){ - $id = TaskList::where('md5',$param['md5'])->value('id'); - if($id){ - return to_assign(1,'已存在'); - } - } - $sid = TaskList::strict(false)->field(true)->insertGetId($param); - if ($sid) { - add_log('add', $sid, $param); - $log_data = array( - 'module' => 'task', - 'task_id' => $sid, - 'new_content' => $param['title'], - 'field' => 'new', - 'action' => 'add', - 'admin_id' => 1, - 'create_time' => time(), - ); - Db::name('ProjectLog')->strict(false)->field(true)->insert($log_data); - //发消息 - //$users = $param['director_uid']; - //sendMessage($users, 21, ['title' => $param['title'],'from_uid' => $this->uid, 'create_time'=>date('Y-m-d H:i:s',time()), 'action_id' => $sid]); - } - return to_assign(); - } - } }