ScoreClockin.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php namespace App\Http\Controllers\Admin;
  2. use App\Http\Requests\Admin\ScoreClockin as Request;
  3. use App\Models\Score\Clockin as Model;
  4. /**
  5. * 打卡任务
  6. *
  7. * @author 刘相欣
  8. *
  9. */
  10. class ScoreClockin extends Auth{
  11. protected function _initialize(){
  12. parent::_initialize();
  13. $this->assign('breadcrumb1','任务打卡');
  14. $this->assign('breadcrumb2','打卡任务');
  15. }
  16. /**
  17. * 首页列表
  18. *
  19. * */
  20. public function index(Model $Model){
  21. // 组合查询条件
  22. $map = [];
  23. // 查询数据
  24. $list = $Model->where($map)->orderBy('what_day')->orderBy('id')->paginate(request('limit',config('page_num',10)))->appends(request()->all());
  25. // 分配数据
  26. $this->assign('empty', '<tr><td colspan="20">~~暂无数据</td></tr>');
  27. $this->assign('list', $list);
  28. // 加载模板
  29. return $this->fetch();
  30. }
  31. /**
  32. * 添加
  33. *
  34. * */
  35. public function add( Request $request,Model $Model ){
  36. if( request()->isMethod('post') ){
  37. // 验证参数
  38. $request->scene('add')->validate();
  39. // 组合数据
  40. $data['what_day'] = (int) request('what_day',0);
  41. $data['reward'] = (int) request('reward',0);
  42. // 写入用户表
  43. $result = $Model->add($data);
  44. // 提示新增失败
  45. if( isset($result['error']) ) return json_send(['code'=>'error','msg'=>$result['error']]);
  46. // 告知结果
  47. return json_send(['code'=>'success','msg'=>'新增成功','action'=>'add']);
  48. }
  49. // 分配数据
  50. $this->assign('crumbs','新增');
  51. // 加载模板
  52. return $this->fetch();
  53. }
  54. /**
  55. * 编辑
  56. *
  57. * */
  58. public function edit( Request $request,Model $Model ){
  59. // 接收参数
  60. $id = request('id',0);
  61. // 如果是post
  62. if(request()->isMethod('post')){
  63. // 验证参数
  64. $request->scene('edit')->validate();
  65. $data['what_day'] = (int) request('what_day',0);
  66. $data['reward'] = (int) request('reward',0);
  67. // 写入用户表
  68. $result = $Model->edit($id,$data);
  69. // 提示新增失败
  70. if( isset($result['error']) ) return json_send(['code'=>'error','msg'=>$result['error']]);
  71. // 告知结果
  72. return json_send(['code'=>'success','msg'=>'修改成功','action'=>'edit']);
  73. }
  74. // 查询数据
  75. $oldData = $Model->where(['id'=>$id])->first();
  76. // 如果是没有数据
  77. if( !$oldData ) return $this->error('查无数据');
  78. // 分配数据
  79. $this->assign('crumbs','修改');
  80. $this->assign('oldData',$oldData);
  81. // 加载模板
  82. return $this->fetch();
  83. }
  84. /**
  85. * 删除
  86. *
  87. * */
  88. public function set_status( Request $request,Model $Model ){
  89. // 验证参数
  90. $request->scene('set_status')->validate();
  91. // 接收参数
  92. $id = request('id',0);
  93. $status = request('status',0);
  94. // 查询数据
  95. $result = $Model->edit($id,['status'=>$status,'update_time'=>time()]);
  96. // 提示新增失败
  97. if( !$result ) return json_send(['code'=>'error','msg'=>'设置失败']);
  98. // 告知结果
  99. return json_send(['code'=>'success','msg'=>'设置成功','path'=>'']);
  100. }
  101. }