OpenBoxAction.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. <?php
  2. namespace app\admin\controller\box;
  3. use app\admin\model\SystemAdmin;
  4. use app\common\model\BoxMidHandleModel;
  5. use app\common\model\BoxModel;
  6. use app\common\model\BoxRecordModel;
  7. use app\common\model\CouponAreaModel;
  8. use app\common\model\CouponPlanModel;
  9. use app\common\model\ShopCategory;
  10. use app\admin\traits\Curd;
  11. use app\common\controller\AdminController;
  12. use app\common\model\ShopGoodsModel;
  13. use app\common\model\ThirddataLogModel;
  14. use app\common\model\ThirddataModel;
  15. use Darabonba\GatewaySpi\Models\InterceptorContext\request;
  16. use EasyAdmin\annotation\ControllerAnnotation;
  17. use EasyAdmin\annotation\NodeAnotation;
  18. use think\App;
  19. use think\facade\Db;
  20. use think\Model;
  21. /**
  22. * Class Admin
  23. * @package app\admin\controller\system
  24. * @ControllerAnnotation(title="盲盒开奖")
  25. */
  26. class OpenBoxAction extends AdminController
  27. {
  28. public function __construct(App $app)
  29. {
  30. parent::__construct($app);
  31. $this->model = new BoxRecordModel();
  32. }
  33. use Curd;
  34. // protected $allowModifyFields = [
  35. // 'can_buy',
  36. // 'status'
  37. // ];
  38. /**
  39. * @NodeAnotation(title="福袋预约记录")
  40. */
  41. public function index ()
  42. {
  43. if ($this->request->isAjax()) {
  44. if (input('selectFields')) {
  45. return $this->selectList();
  46. }
  47. list($page, $limit, $where) = $this->buildTableParames();
  48. foreach ($where as $key=>&$val){
  49. if ($val[0] == 'status'){
  50. $where[$key] = 'r.status';
  51. }
  52. }
  53. $count = $list = $this->model
  54. ->alias('r')
  55. ->where('r.status', '=',1)
  56. ->where($where)
  57. ->leftJoin('user u', 'u.id = r.uid')
  58. ->field('r.*,u.mobile,u.yesterday_money')
  59. ->order('r.num desc')
  60. ->page($page, $limit)
  61. ->count();
  62. $list = $this->model
  63. ->alias('r')
  64. ->where($where)
  65. ->where('r.status', '=',1)
  66. ->leftJoin('user u', 'u.id = r.uid')
  67. ->field(Db::raw('r.*,u.mobile,u.total_null_box,sum(r.num) as appoint_num,u.total_free,u.total_appoint_count,u.total_income,u.yesterday_money,u.box10 as ubox10,u.box20 as ubox20,u.box30 as ubox30,u.box40 as ubox40'))
  68. // ->group_concat('box_id','lun_count','uid')
  69. ->group(Db::raw('concat(box_id,lun_count,uid)'))
  70. ->order('r.num desc')
  71. ->order('r.create_time desc')
  72. ->page($page, $limit)
  73. ->select()->toArray();
  74. echo $this->model->getLastSql();
  75. $data = [
  76. 'code' => 0,
  77. 'msg' => '',
  78. 'count' => $count,
  79. 'data' => $list,
  80. ];
  81. return json($data);
  82. }
  83. $total_num = Db::name('box_record')->where('id', '>', 0)->sum('num');
  84. $total_curnum = Db::name('box_record')->where('id', '>', 0)->where('status', 1)->sum('num');
  85. $this->assign('cur_info', [
  86. 'total_num'=>$total_num,
  87. 'total_money'=>$total_num * env('boxsetting.ONE_BOX_PRICE'),
  88. 'total_curnum'=>$total_curnum,
  89. 'total_curmoney'=>$total_curnum * env('boxsetting.ONE_BOX_PRICE'),
  90. ]);
  91. return $this->fetch();
  92. }
  93. /**
  94. * @NodeAnotation(title="手动干预福袋开奖")
  95. */
  96. public function beforeopen($id){
  97. if ($this->request->isPost()){
  98. //
  99. $data = $this->request->post();
  100. $box10 = $data['box10'];
  101. $box20 = $data['box20'];
  102. $box30 = $data['box30'];
  103. $box40 = $data['box40'];
  104. if (isset($data['hs_xy']) && $data['hs_xy'] == 'on'){
  105. $hs_xy = 1;
  106. }else{
  107. $hs_xy = 0;
  108. }
  109. $total_box = $box10 + $box20+ $box30+ $box40;
  110. $info = $this->model->where('id', $id)->find();
  111. if ($info['num'] < $total_box){
  112. $this->error('不能超过最大预约量');
  113. }
  114. $this->model->where('id', $id)->save([
  115. 'box10'=>$box10, 'box20'=>$box20, 'box30'=>$box30, 'box40'=>$box40,'hs_xy'=>$hs_xy
  116. ]);
  117. $this->success('成功');
  118. }
  119. $info = $this->model->where('id', $id)->find();
  120. $this->assign('data', $info);
  121. return $this->fetch();
  122. }
  123. /**
  124. * @NodeAnotation(title="系统自动前置开奖结果")
  125. */
  126. public function beforehandle(){
  127. if ($this->request->isAjax()) {
  128. if (input('selectFields')) {
  129. return $this->selectList();
  130. }
  131. list($page, $limit, $where) = $this->buildTableParames();
  132. $model = new BoxMidHandleModel();
  133. $count = $list = $model
  134. ->alias('m')
  135. ->leftJoin('user u', 'u.id = r.uid')
  136. // ->leftJoin('shop_order_shipping s', 's.order_id = o.order_id')
  137. ->field('r.*,u.mobile')
  138. ->order('r.num desc')
  139. // ->withAttr('order_sn', function($val, $data){
  140. // return '编号:'.$val;
  141. // })
  142. ->page($page, $limit)
  143. ->count();
  144. // return 11;
  145. // foreach ($where as $key=>&$val){
  146. // $val[$key] = 'r'.$val;
  147. // }
  148. // $where[] = ['r.status', '=', 1];
  149. $list = $this->model
  150. ->alias('r')
  151. ->leftJoin('user u', 'u.id = r.uid')
  152. // ->leftJoin('shop_order_shipping s', 's.order_id = o.order_id')
  153. ->field('r.*,u.mobile,u.total_null_box,u.total_free,u.total_income')
  154. ->order('r.num desc')
  155. // ->withAttr('order_sn', function($val, $data){
  156. // return '编号:'.$val;
  157. // })
  158. ->page($page, $limit)
  159. ->select()->toArray();
  160. // $list = $this->model
  161. // ->alias('r')
  162. // ->leftJoin('user u', 'u.id = r.uid')
  163. //
  164. // ->withoutField('password')
  165. //
  166. // ->where($where)
  167. // ->page($page, $limit)
  168. // ->field('r.*,u.mobile,s.sp_id,s.sp_name,s.sp_mergename,s.sp_mobile')
  169. // ->select();
  170. $data = [
  171. 'code' => 0,
  172. 'msg' => '',
  173. 'count' => $count,
  174. 'data' => $list,
  175. ];
  176. return json($data);
  177. // return $this->success('成功');
  178. }
  179. // if (!Db::name('box_mid_handle')->where('id', '>', 0)->find()){
  180. // // 算法写界面
  181. // $this->updateUserBox();
  182. // }
  183. return $this->fetch();
  184. }
  185. public function setting($id){
  186. if ($this->request->isAjax()){
  187. $data = $this->request->post();
  188. $box10 = $data['box10'];
  189. $box20 = $data['box20'];
  190. $box30 = $data['box30'];
  191. $box40 = $data['box40'];
  192. $list = Db::name('box_record')->whereIn('id', $id)->where('status', 1)->select();
  193. // $has_error = false;
  194. $setting_arr = [];
  195. foreach ($list as $key=>$val){
  196. $total_box = $box10 + $box20+ $box30+ $box40;
  197. if ($val['num'] < $total_box){
  198. $this->error('不能超过最大预约量');
  199. // $has_error = true;
  200. }
  201. $val['box10'] = $box10;
  202. $val['box20'] = $box20;
  203. $val['box30'] = $box30;
  204. $val['box40'] = $box40;
  205. $setting_arr[] = $val;
  206. }
  207. // if ($has_error){
  208. // sr_testDb('aaaa', 999);
  209. // }
  210. Db::startTrans();
  211. try {
  212. $this->model->saveAll($setting_arr);
  213. Db::commit();
  214. }catch (\Exception $e){
  215. Db::rollback();
  216. $this->error('失败');
  217. }
  218. $this->success('成功');
  219. }
  220. $this->assign('id', $id);
  221. return $this->fetch();
  222. }
  223. }