LotteryOrderRecord.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php namespace App\Http\Controllers\Admin;
  2. use App\Http\Requests\Admin\Lottery\OrderReward as Request;
  3. use App\Models\Custom;
  4. use App\Models\Lottery\OrderRecord as Model;
  5. use App\Models\Lottery\Order as LotteryOrder;
  6. /**
  7. * 抽奖记录
  8. *
  9. * @author 刘相欣
  10. *
  11. */
  12. class LotteryOrderRecord 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,LotteryOrder $LotteryOrder,Custom $Custom){
  23. // 接受参数
  24. // 接受参数
  25. $lotteryId = request('lottery_id',0);
  26. $customCode = request('custom_code','');
  27. $startTime = request('start_time','');
  28. $endTime = request('end_time','');
  29. $status = request('status');
  30. // 查询条件
  31. $map = [];
  32. // 编码转ID
  33. $customUid = $customCode ? $Custom->codeToId($customCode) : 0;
  34. if( $customUid ) $map[] = ['custom_uid','=',$customUid];
  35. if( $lotteryId ) $map[] = ['lottery_id','=',$lotteryId];
  36. if( $startTime ) $map[] = ['insert_time','>=',strtotime($startTime)];
  37. if( $endTime ) $map[] = ['insert_time','<=',strtotime($endTime)];
  38. if( !is_null($status) ) $map[] = ['status','=',$status];
  39. // 查询数据
  40. $list = $Model->query()->where($map)->orderByDesc('id')->paginate(config('page_num',10));
  41. // 循环处理数据
  42. foreach ($list as $key => $value) {
  43. // 组合数据
  44. $value['state'] = $Model->getRecordState($value['status'],'name');
  45. // id转编号
  46. $value['custom_code'] = $Custom->idToCode($value['custom_uid']);
  47. // 重组
  48. $list[$key] = $value;
  49. }
  50. // 获取列表
  51. $statusList = $Model->getRecordStateList();
  52. // 获取列表
  53. $lotteryList = $LotteryOrder->query()->get(['id','name'])->toArray();
  54. // 分配数据
  55. $this->assign('empty', '<tr><td colspan="20">~~暂无数据</td></tr>');
  56. $this->assign('list',$list);
  57. $this->assign('statusList',$statusList);
  58. $this->assign('lotteryList',$lotteryList);
  59. // 加载模板
  60. return $this->fetch();
  61. }
  62. /**
  63. * 修改状态
  64. *
  65. * */
  66. public function set_status(Request $request,Model $Model){
  67. // 验证参数
  68. $request->scene('set_status')->validate();
  69. // 设置状态
  70. $id = request('id',0);
  71. $status = request('status',0);
  72. // 查询用户
  73. $oldData = $Model->where(['id'=>$id])->first();
  74. // 如果用户不存在
  75. if( !$oldData ) return json_send(['code'=>'error','msg'=>'数据不存在']);
  76. // 执行修改
  77. $result = $Model->edit($id,['status'=>$status]);
  78. // 提示新增失败
  79. if( !$result ) return json_send(['code'=>'error','msg'=>'设置失败']);
  80. // 记录行为
  81. $this->addAdminHistory(admin('uid'),$Model->getTable(),$id,2,$oldData,['status'=>$status]);
  82. // 告知结果
  83. return json_send(['code'=>'success','msg'=>'设置成功','path'=>'']);
  84. }
  85. }