assign('breadcrumb1','任务打卡'); $this->assign('breadcrumb2','打卡任务'); } /** * 首页列表 * * */ public function index(Model $Model){ // 组合查询条件 $map = []; // 查询数据 $list = $Model->where($map)->orderBy('what_day')->orderBy('id')->paginate(request('limit',config('page_num',10)))->appends(request()->all()); // 分配数据 $this->assign('empty', '~~暂无数据'); $this->assign('list', $list); // 加载模板 return $this->fetch(); } /** * 添加 * * */ public function add( Request $request,Model $Model ){ if( request()->isMethod('post') ){ // 验证参数 $request->scene('add')->validate(); // 组合数据 $data['what_day'] = (int) request('what_day',0); $data['reward'] = (int) request('reward',0); // 写入用户表 $result = $Model->add($data); // 提示新增失败 if( isset($result['error']) ) return json_send(['code'=>'error','msg'=>$result['error']]); // 告知结果 return json_send(['code'=>'success','msg'=>'新增成功','action'=>'add']); } // 分配数据 $this->assign('crumbs','新增'); // 加载模板 return $this->fetch(); } /** * 编辑 * * */ public function edit( Request $request,Model $Model ){ // 接收参数 $id = request('id',0); // 如果是post if(request()->isMethod('post')){ // 验证参数 $request->scene('edit')->validate(); $data['what_day'] = (int) request('what_day',0); $data['reward'] = (int) request('reward',0); // 写入用户表 $result = $Model->edit($id,$data); // 提示新增失败 if( isset($result['error']) ) return json_send(['code'=>'error','msg'=>$result['error']]); // 告知结果 return json_send(['code'=>'success','msg'=>'修改成功','action'=>'edit']); } // 查询数据 $oldData = $Model->where(['id'=>$id])->first(); // 如果是没有数据 if( !$oldData ) return $this->error('查无数据'); // 分配数据 $this->assign('crumbs','修改'); $this->assign('oldData',$oldData); // 加载模板 return $this->fetch(); } /** * 删除 * * */ public function set_status( Request $request,Model $Model ){ // 验证参数 $request->scene('set_status')->validate(); // 接收参数 $id = request('id',0); $status = request('status',0); // 查询数据 $result = $Model->edit($id,['status'=>$status,'update_time'=>time()]); // 提示新增失败 if( !$result ) return json_send(['code'=>'error','msg'=>'设置失败']); // 告知结果 return json_send(['code'=>'success','msg'=>'设置成功','path'=>'']); } }