HandleBoxAction.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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 jobs\SystemMiddleOpenBox;
  19. use think\App;
  20. use utils\Queue;
  21. use think\facade\Db;
  22. use think\Model;
  23. /**
  24. * Class Admin
  25. * @package app\admin\controller\system
  26. * @ControllerAnnotation(title="盲盒开奖")
  27. */
  28. class HandleBoxAction extends AdminController
  29. {
  30. public function __construct(App $app)
  31. {
  32. parent::__construct($app);
  33. $this->model = new BoxMidHandleModel();
  34. }
  35. use Curd;
  36. /**
  37. * @NodeAnotation(title="系统自动前置开奖结果")
  38. */
  39. public function index(){
  40. if ($this->request->isAjax()) {
  41. if (input('selectFields')) {
  42. return $this->selectList();
  43. }
  44. list($page, $limit, $where) = $this->buildTableParames();
  45. $count = $this->model
  46. ->alias('r')
  47. ->leftJoin('user u', 'u.id = r.uid')
  48. ->field('r.*,u.mobile,u.total_null_box,u.total_free,u.total_income')
  49. ->order('r.box_type desc')
  50. ->page($page, $limit)
  51. ->count();
  52. $list = $this->model
  53. ->alias('r')
  54. ->leftJoin('user u', 'u.id = r.uid')
  55. ->field('r.*,u.mobile,u.total_null_box,u.total_free,u.total_income,u.total_appoint_count,u.box10,u.box20,u.box30,u.box40')
  56. ->order('r.box_type desc')
  57. ->page($page, $limit)
  58. ->select()->toArray();
  59. $data = [
  60. 'code' => 0,
  61. 'msg' => '',
  62. 'count' => $count,
  63. 'data' => $list,
  64. ];
  65. return json($data);
  66. }
  67. //
  68. // if (!Db::name('box_mid_handle')->where('id', '>', 0)->find()){
  69. // $redis = new \think\cache\driver\Redis();
  70. // $redis->connect('127.0.0.1', 6379);
  71. //// has_handle_mapping 是否在进行队列跑数据 0 没有 1 有
  72. // if ($redis->get('has_handle_mapping') == 0){
  73. // Queue::instance()->log('确定手动执行匹配福袋')->do('SystemHandleBox')->job(SystemMiddleOpenBox::class)->push([1]);
  74. // $redis->set('has_handle_mapping',1);
  75. // return $this->fetch();
  76. // }
  77. //
  78. //
  79. // }
  80. return $this->fetch();
  81. }
  82. public function updateUserBox(){
  83. $list = Db::name('box_record')->where('status', 1)->select()->toArray();
  84. $model = new ShopGoodsModel();
  85. foreach ($list as $key=>$val){
  86. for ($i = 0; $i < $val['num']; $i++){
  87. $box_type = rand(0, 4);
  88. if ($box_type > 0){
  89. $goods = $model
  90. ->where('box_type', $box_type*10)
  91. // ->field('goods_id,box_type,goods_img,price,goods_name')
  92. ->paginate(1)
  93. ->toArray();
  94. Db::name('box_mid_handle')->insert([
  95. 'status'=>1,
  96. 'h_sn'=>createdHandleOrderSn(),
  97. 'uid'=>$val['uid'],
  98. 'rid'=>$val['id'],
  99. 'goods_id'=>$goods['data'][0]['goods_id'],
  100. 'create_time'=>sr_getcurtime(time()),
  101. 'box_type'=>$box_type*10,
  102. 'goods_price'=>$goods['data'][0]['price']
  103. ]);
  104. }
  105. // if ($box_type == 0){
  106. //
  107. //
  108. // }
  109. // // 空盒 原路返回
  110. // if ($val['pay_type'] == 1){
  111. // edit_user_score(2, $val['uid'], env('boxsetting.ONE_BOX_PRICE'));
  112. // }
  113. // if ($val['pay_type'] == 2){
  114. // edit_user_money(3, $val['uid'], env('boxsetting.ONE_BOX_PRICE'));
  115. // }
  116. // 把记录表改变状态
  117. Db::name('box_record')->where('id', '>', 0)->save([
  118. 'status'=>2
  119. ]);
  120. }
  121. }
  122. }
  123. }