LotteryScoreRecord.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php namespace App\Http\Controllers\Admin;
  2. use App\Http\Requests\Admin\LotteryScoreReward as Request;
  3. use App\Models\Coupon;
  4. use App\Models\Lottery\ScoreRecord as Model;
  5. use App\Models\Lottery\Score as LotteryScore;
  6. /**
  7. * 抽奖记录
  8. *
  9. * @author 刘相欣
  10. *
  11. */
  12. class LotteryScoreRecord extends Auth{
  13. protected function _initialize(){
  14. parent::_initialize();
  15. $this->assign('breadcrumb1','积分抽奖');
  16. $this->assign('breadcrumb2','抽奖记录');
  17. }
  18. /**
  19. * 列表页
  20. *
  21. * */
  22. public function index(Model $Model,LotteryScore $LotteryScore){
  23. // 查询条件
  24. $map = [];
  25. // 查询数据
  26. $list = $Model->query()->where($map)->orderByDesc('id')->paginate(config('page_num',10));
  27. // 循环处理数据
  28. foreach ($list as $key => $value) {
  29. // 重组
  30. $list[$key] = $value;
  31. }
  32. // 获取列表
  33. $lotteryList = $LotteryScore->query()->get(['id','name'])->toArray();
  34. // 分配数据
  35. $this->assign('empty', '<tr><td colspan="20">~~暂无数据</td></tr>');
  36. $this->assign('list',$list);
  37. $this->assign('lotteryList',$lotteryList);
  38. // 加载模板
  39. return $this->fetch();
  40. }
  41. /**
  42. * 修改状态
  43. *
  44. * */
  45. public function set_status(Request $request,Model $Model){
  46. // 验证参数
  47. $request->scene('set_status')->validate();
  48. // 设置状态
  49. $id = request('id',0);
  50. $status = request('status',0);
  51. // 查询用户
  52. $oldData = $Model->where(['id'=>$id])->first();
  53. // 如果用户不存在
  54. if( !$oldData ) return json_send(['code'=>'error','msg'=>'数据不存在']);
  55. // 执行修改
  56. $result = $Model->edit($id,['status'=>$status]);
  57. // 提示新增失败
  58. if( !$result ) return json_send(['code'=>'error','msg'=>'设置失败']);
  59. // 记录行为
  60. $this->addAdminHistory(admin('uid'),$Model->getTable(),$id,2,$oldData,['status'=>$status]);
  61. // 告知结果
  62. return json_send(['code'=>'success','msg'=>'设置成功','path'=>'']);
  63. }
  64. }