HandleBoxAction.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. namespace app\admin\controller\box;
  3. use app\common\model\BoxMidHandleModel;
  4. use app\admin\traits\Curd;
  5. use app\common\controller\AdminController;
  6. use app\common\model\ShopGoodsModel;
  7. use app\common\model\ThirddataLogModel;
  8. use app\common\model\ThirddataModel;
  9. use think\App;
  10. use think\facade\Db;
  11. /**
  12. * Class Admin
  13. * @package app\admin\controller\system
  14. * @ControllerAnnotation(title="盲盒开奖")
  15. */
  16. class HandleBoxAction extends AdminController
  17. {
  18. use Curd;
  19. public function __construct(App $app)
  20. {
  21. parent::__construct($app);
  22. $this->model = new BoxMidHandleModel();
  23. }
  24. /**
  25. * @NodeAnotation(title="系统自动前置开奖结果")
  26. */
  27. public function index(){
  28. if ($this->request->isAjax()) {
  29. if (input('selectFields')) {
  30. return $this->selectList();
  31. }
  32. list($page, $limit, $where) = $this->buildTableParames();
  33. $count = $this->model
  34. ->alias('r')
  35. ->leftJoin('user u', 'u.id = r.uid')
  36. ->field('r.*,u.mobile,u.total_null_box,u.total_free,u.total_income')
  37. ->order('r.box_type desc')
  38. ->page($page, $limit)
  39. ->count();
  40. $list = $this->model
  41. ->alias('r')
  42. ->leftJoin('user u', 'u.id = r.uid')
  43. ->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')
  44. ->order('r.box_type desc')
  45. ->page($page, $limit)
  46. ->select()->toArray();
  47. $data = [
  48. 'code' => 0,
  49. 'msg' => '',
  50. 'count' => $count,
  51. 'data' => $list,
  52. ];
  53. return json($data);
  54. }
  55. return $this->fetch();
  56. }
  57. public function updateUserBox(){
  58. $list = Db::name('box_record')->where('status', 1)->select()->toArray();
  59. $model = new ShopGoodsModel();
  60. foreach ($list as $key=>$val){
  61. for ($i = 0; $i < $val['num']; $i++){
  62. $box_type = rand(0, 4);
  63. if ($box_type > 0){
  64. $goods = $model
  65. ->where('box_type', $box_type*10)
  66. // ->field('goods_id,box_type,goods_img,price,goods_name')
  67. ->paginate(1)
  68. ->toArray();
  69. Db::name('box_mid_handle')->insert([
  70. 'status'=>1,
  71. 'h_sn'=>createdHandleOrderSn(),
  72. 'uid'=>$val['uid'],
  73. 'rid'=>$val['id'],
  74. 'goods_id'=>$goods['data'][0]['goods_id'],
  75. 'create_time'=>sr_getcurtime(time()),
  76. 'box_type'=>$box_type*10,
  77. 'goods_price'=>$goods['data'][0]['price']
  78. ]);
  79. }
  80. // 把记录表改变状态
  81. Db::name('box_record')->where('id', '>', 0)->save([
  82. 'status'=>2
  83. ]);
  84. }
  85. }
  86. }
  87. }