OpenBoxAction.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <?php
  2. namespace app\admin\controller\box;
  3. use app\common\model\BoxMidHandleModel;
  4. use app\common\model\BoxRecordModel;
  5. use app\admin\traits\Curd;
  6. use app\common\controller\AdminController;
  7. use app\common\service\BoxRecordService;
  8. use think\App;
  9. use think\facade\Db;
  10. use utils\RedisCache;
  11. /**
  12. * 开福袋 by wes
  13. * Class Admin
  14. * @package app\admin\controller\system
  15. * @ControllerAnnotation(title="盲盒开奖")
  16. */
  17. class OpenBoxAction extends AdminController
  18. {
  19. public function __construct(App $app)
  20. {
  21. parent::__construct($app);
  22. $this->model = new BoxRecordModel();
  23. }
  24. use Curd;
  25. /**
  26. * @NodeAnotation(title="福袋预约记录")
  27. */
  28. public function index()
  29. {
  30. if ($this->request->isAjax()) {
  31. if (input('selectFields')) {
  32. return $this->selectList();
  33. }
  34. list($page, $limit, $where) = $this->buildTableParames();
  35. $isMatch = $this->request->get('match', 0);
  36. if ($isMatch) {
  37. $where['is_set_match'] = 1;
  38. $where['box10'] = 1;
  39. }
  40. $list = BoxRecordService::make()->getCatchList($where, $limit);
  41. $data = [
  42. 'code' => 0,
  43. 'msg' => '获取成功',
  44. 'count' => isset($list['total']) ? $list['total'] : 0,
  45. 'data' => isset($list['data']) ? $list['data'] : [],
  46. ];
  47. return json($data);
  48. }
  49. $totalNum = BoxRecordModel::where('id', '>', 0)->sum('num');
  50. $totalCurnum = BoxRecordModel::where('id', '>', 0)
  51. ->where('status', 1)
  52. ->where('create_time', '>=', date('Y-m-d'))
  53. ->sum('num');
  54. $this->assign('cur_info', [
  55. 'total_num' => $totalNum,
  56. 'total_money' => $totalNum * env('boxsetting.ONE_BOX_PRICE'),
  57. 'total_curnum' => $totalCurnum,
  58. 'total_curmoney' => $totalCurnum * env('boxsetting.ONE_BOX_PRICE'),
  59. ]);
  60. return $this->fetch();
  61. }
  62. /**
  63. * @NodeAnotation(title="手动干预福袋开奖")
  64. */
  65. public function beforeopen($id)
  66. {
  67. if ($this->request->isPost()) {
  68. $data = $this->request->post();
  69. $result = BoxRecordService::make()->setBoxMatch($id, $data);
  70. if ($result === true) {
  71. $this->success('设置成功');
  72. } else {
  73. $this->error($result ? $result : '设置失败');
  74. }
  75. }
  76. $info = $this->model->where('id', $id)->find();
  77. $this->assign('data', $info);
  78. return $this->fetch();
  79. }
  80. /**
  81. * @NodeAnotation(title="系统自动前置开奖结果")
  82. */
  83. public function beforehandle()
  84. {
  85. if ($this->request->isAjax()) {
  86. if (input('selectFields')) {
  87. return $this->selectList();
  88. }
  89. list($page, $limit, $where) = $this->buildTableParames();
  90. $model = new BoxMidHandleModel();
  91. $count = $list = $model
  92. ->alias('m')
  93. ->leftJoin('user u', 'u.id = r.uid')
  94. ->field('r.*,u.mobile')
  95. ->order('r.num desc')
  96. ->page($page, $limit)
  97. ->count();
  98. $list = $this->model
  99. ->alias('r')
  100. ->leftJoin('user u', 'u.id = r.uid')
  101. ->field('r.*,u.mobile,u.total_null_box,u.total_free,u.total_income')
  102. ->order('r.num desc')
  103. ->page($page, $limit)
  104. ->select()->toArray();
  105. $data = [
  106. 'code' => 0,
  107. 'msg' => '',
  108. 'count' => $count,
  109. 'data' => $list,
  110. ];
  111. return json($data);
  112. }
  113. return $this->fetch();
  114. }
  115. /**
  116. * 设置匹配
  117. * @param $id
  118. * @return mixed
  119. * @throws \think\db\exception\DataNotFoundException
  120. * @throws \think\db\exception\DbException
  121. * @throws \think\db\exception\ModelNotFoundException
  122. */
  123. public function setting($id)
  124. {
  125. if ($this->request->isAjax()) {
  126. $data = $this->request->post();
  127. $result = BoxRecordService::make()->setBoxMatch($id, $data);
  128. if ($result === true) {
  129. $this->success('设置成功');
  130. } else {
  131. $this->error($result ? $result : '设置失败');
  132. }
  133. }
  134. $this->assign('id', $id);
  135. return $this->fetch();
  136. }
  137. /**
  138. * 手动开奖
  139. * @param $id
  140. * @return mixed
  141. * @throws \think\db\exception\DataNotFoundException
  142. * @throws \think\db\exception\DbException
  143. * @throws \think\db\exception\ModelNotFoundException
  144. */
  145. public function openBox()
  146. {
  147. $data = $this->request->post();
  148. $ids = isset($data['id']) ? $data['id'] : [];
  149. $result = BoxRecordService::make()->openBox($ids, $data);
  150. if (is_array($result)) {
  151. $this->success($result['msg'], $result['data'], '', 10);
  152. } else {
  153. $this->error($result ? $result : '开奖失败');
  154. }
  155. }
  156. }