OpenBoxAction.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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. // ->with(['goods'])
  56. ->where('r.status', '=',1)
  57. ->where($where)
  58. // ->where('o.status', '<>', 3)
  59. ->leftJoin('user u', 'u.id = r.uid')
  60. // ->leftJoin('shop_order_shipping s', 's.order_id = o.order_id')
  61. ->field('r.*,u.mobile,u.yesterday_money')
  62. ->order('r.num desc')
  63. // ->withAttr('order_sn', function($val, $data){
  64. // return '编号:'.$val;
  65. // })
  66. ->page($page, $limit)
  67. ->count();
  68. // return 11;
  69. // foreach ($where as $key=>&$val){
  70. // $val[$key] = 'r'.$val;
  71. // }
  72. // $where[] = ['r.status', '=', 1];
  73. $list = $this->model
  74. ->alias('r')
  75. // ->with(['goods'])
  76. ->where($where)
  77. ->where('r.status', '=',1)
  78. // ->where('o.status', '<>', 3)
  79. ->leftJoin('user u', 'u.id = r.uid')
  80. // ->leftJoin('shop_order_shipping s', 's.order_id = o.order_id')
  81. ->field('r.*,u.mobile,u.total_null_box,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')
  82. ->order('r.num desc')
  83. // ->withAttr('order_sn', function($val, $data){
  84. // return '编号:'.$val;
  85. // })
  86. ->page($page, $limit)
  87. ->select()->toArray();
  88. // $list = $this->model
  89. // ->alias('r')
  90. // ->leftJoin('user u', 'u.id = r.uid')
  91. //
  92. // ->withoutField('password')
  93. //
  94. // ->where($where)
  95. // ->page($page, $limit)
  96. // ->field('r.*,u.mobile,s.sp_id,s.sp_name,s.sp_mergename,s.sp_mobile')
  97. // ->select();
  98. $data = [
  99. 'code' => 0,
  100. 'msg' => '',
  101. 'count' => $count,
  102. 'data' => $list,
  103. ];
  104. return json($data);
  105. // return $this->success('成功');
  106. }
  107. $total_num = Db::name('box_record')->where('id', '>', 0)->sum('num');
  108. $total_curnum = Db::name('box_record')->where('id', '>', 0)->where('status', 1)->sum('num');
  109. $this->assign('cur_info', [
  110. 'total_num'=>$total_num,
  111. 'total_money'=>$total_num * env('boxsetting.ONE_BOX_PRICE'),
  112. 'total_curnum'=>$total_curnum,
  113. 'total_curmoney'=>$total_curnum * env('boxsetting.ONE_BOX_PRICE'),
  114. ]);
  115. return $this->fetch();
  116. }
  117. /**
  118. * @NodeAnotation(title="手动干预福袋开奖")
  119. */
  120. public function beforeopen($id){
  121. if ($this->request->isPost()){
  122. //
  123. $data = $this->request->post();
  124. $box10 = $data['box10'];
  125. $box20 = $data['box20'];
  126. $box30 = $data['box30'];
  127. $box40 = $data['box40'];
  128. if (isset($data['hs_xy']) && $data['hs_xy'] == 'on'){
  129. $hs_xy = 1;
  130. }else{
  131. $hs_xy = 0;
  132. }
  133. $total_box = $box10 + $box20+ $box30+ $box40;
  134. $info = $this->model->where('id', $id)->find();
  135. if ($info['num'] < $total_box){
  136. $this->error('不能超过最大预约量');
  137. }
  138. $this->model->where('id', $id)->save([
  139. 'box10'=>$box10, 'box20'=>$box20, 'box30'=>$box30, 'box40'=>$box40,'hs_xy'=>$hs_xy
  140. ]);
  141. $this->success('成功');
  142. }
  143. $info = $this->model->where('id', $id)->find();
  144. $this->assign('data', $info);
  145. return $this->fetch();
  146. }
  147. /**
  148. * @NodeAnotation(title="系统自动前置开奖结果")
  149. */
  150. public function beforehandle(){
  151. if ($this->request->isAjax()) {
  152. if (input('selectFields')) {
  153. return $this->selectList();
  154. }
  155. list($page, $limit, $where) = $this->buildTableParames();
  156. $model = new BoxMidHandleModel();
  157. $count = $list = $model
  158. ->alias('m')
  159. ->leftJoin('user u', 'u.id = r.uid')
  160. // ->leftJoin('shop_order_shipping s', 's.order_id = o.order_id')
  161. ->field('r.*,u.mobile')
  162. ->order('r.num desc')
  163. // ->withAttr('order_sn', function($val, $data){
  164. // return '编号:'.$val;
  165. // })
  166. ->page($page, $limit)
  167. ->count();
  168. // return 11;
  169. // foreach ($where as $key=>&$val){
  170. // $val[$key] = 'r'.$val;
  171. // }
  172. // $where[] = ['r.status', '=', 1];
  173. $list = $this->model
  174. ->alias('r')
  175. ->leftJoin('user u', 'u.id = r.uid')
  176. // ->leftJoin('shop_order_shipping s', 's.order_id = o.order_id')
  177. ->field('r.*,u.mobile,u.total_null_box,u.total_free,u.total_income')
  178. ->order('r.num desc')
  179. // ->withAttr('order_sn', function($val, $data){
  180. // return '编号:'.$val;
  181. // })
  182. ->page($page, $limit)
  183. ->select()->toArray();
  184. // $list = $this->model
  185. // ->alias('r')
  186. // ->leftJoin('user u', 'u.id = r.uid')
  187. //
  188. // ->withoutField('password')
  189. //
  190. // ->where($where)
  191. // ->page($page, $limit)
  192. // ->field('r.*,u.mobile,s.sp_id,s.sp_name,s.sp_mergename,s.sp_mobile')
  193. // ->select();
  194. $data = [
  195. 'code' => 0,
  196. 'msg' => '',
  197. 'count' => $count,
  198. 'data' => $list,
  199. ];
  200. return json($data);
  201. // return $this->success('成功');
  202. }
  203. // if (!Db::name('box_mid_handle')->where('id', '>', 0)->find()){
  204. // // 算法写界面
  205. // $this->updateUserBox();
  206. // }
  207. return $this->fetch();
  208. }
  209. public function setting($id){
  210. if ($this->request->isAjax()){
  211. $data = $this->request->post();
  212. $box10 = $data['box10'];
  213. $box20 = $data['box20'];
  214. $box30 = $data['box30'];
  215. $box40 = $data['box40'];
  216. $list = Db::name('box_record')->whereIn('id', $id)->where('status', 1)->select();
  217. // $has_error = false;
  218. $setting_arr = [];
  219. foreach ($list as $key=>$val){
  220. $total_box = $box10 + $box20+ $box30+ $box40;
  221. if ($val['num'] < $total_box){
  222. $this->error('不能超过最大预约量');
  223. // $has_error = true;
  224. }
  225. $val['box10'] = $box10;
  226. $val['box20'] = $box20;
  227. $val['box30'] = $box30;
  228. $val['box40'] = $box40;
  229. $setting_arr[] = $val;
  230. }
  231. // if ($has_error){
  232. // sr_testDb('aaaa', 999);
  233. // }
  234. Db::startTrans();
  235. try {
  236. $this->model->saveAll($setting_arr);
  237. Db::commit();
  238. }catch (\Exception $e){
  239. Db::rollback();
  240. $this->error('失败');
  241. }
  242. $this->success('成功');
  243. }
  244. $this->assign('id', $id);
  245. return $this->fetch();
  246. }
  247. }