| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298 |
- <?php
- namespace app\admin\controller\box;
- use app\admin\model\SystemAdmin;
- use app\common\model\BoxMidHandleModel;
- use app\common\model\BoxModel;
- use app\common\model\BoxRecordModel;
- use app\common\model\CouponAreaModel;
- use app\common\model\CouponPlanModel;
- use app\common\model\ShopCategory;
- use app\admin\traits\Curd;
- use app\common\controller\AdminController;
- use app\common\model\ShopGoodsModel;
- use app\common\model\ThirddataLogModel;
- use app\common\model\ThirddataModel;
- use Darabonba\GatewaySpi\Models\InterceptorContext\request;
- use EasyAdmin\annotation\ControllerAnnotation;
- use EasyAdmin\annotation\NodeAnotation;
- use think\App;
- use think\facade\Db;
- use think\Model;
- /**
- * Class Admin
- * @package app\admin\controller\system
- * @ControllerAnnotation(title="盲盒开奖")
- */
- class OpenBoxAction extends AdminController
- {
- public function __construct(App $app)
- {
- parent::__construct($app);
- $this->model = new BoxRecordModel();
- }
- use Curd;
- // protected $allowModifyFields = [
- // 'can_buy',
- // 'status'
- // ];
- /**
- * @NodeAnotation(title="福袋预约记录")
- */
- public function index ()
- {
- if ($this->request->isAjax()) {
- if (input('selectFields')) {
- return $this->selectList();
- }
- list($page, $limit, $where) = $this->buildTableParames();
- foreach ($where as $key=>&$val){
- if ($val[0] == 'status'){
- $where[$key] = 'r.status';
- }
- }
- $count = $list = $this->model
- ->alias('r')
- ->where('r.status', '=',1)
- ->where($where)
- ->leftJoin('user u', 'u.id = r.uid')
- ->field('r.*,u.mobile,u.yesterday_money')
- ->order('r.num desc')
- ->page($page, $limit)
- ->count();
- $list = $this->model
- ->alias('r')
- ->where($where)
- ->where('r.status', '=',1)
- ->leftJoin('user u', 'u.id = r.uid')
- ->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'))
- // ->group_concat('box_id','lun_count','uid')
- ->group(Db::raw('concat(box_id,lun_count,uid)'))
- ->order('r.num desc')
- ->order('r.create_time desc')
- ->page($page, $limit)
- ->select()->toArray();
- echo $this->model->getLastSql();
- $data = [
- 'code' => 0,
- 'msg' => '',
- 'count' => $count,
- 'data' => $list,
- ];
- return json($data);
- }
- $total_num = Db::name('box_record')->where('id', '>', 0)->sum('num');
- $total_curnum = Db::name('box_record')->where('id', '>', 0)->where('status', 1)->sum('num');
- $this->assign('cur_info', [
- 'total_num'=>$total_num,
- 'total_money'=>$total_num * env('boxsetting.ONE_BOX_PRICE'),
- 'total_curnum'=>$total_curnum,
- 'total_curmoney'=>$total_curnum * env('boxsetting.ONE_BOX_PRICE'),
- ]);
- return $this->fetch();
- }
- /**
- * @NodeAnotation(title="手动干预福袋开奖")
- */
- public function beforeopen($id){
- if ($this->request->isPost()){
- //
- $data = $this->request->post();
- $box10 = $data['box10'];
- $box20 = $data['box20'];
- $box30 = $data['box30'];
- $box40 = $data['box40'];
- if (isset($data['hs_xy']) && $data['hs_xy'] == 'on'){
- $hs_xy = 1;
- }else{
- $hs_xy = 0;
- }
- $total_box = $box10 + $box20+ $box30+ $box40;
- $info = $this->model->where('id', $id)->find();
- if ($info['num'] < $total_box){
- $this->error('不能超过最大预约量');
- }
- $this->model->where('id', $id)->save([
- 'box10'=>$box10, 'box20'=>$box20, 'box30'=>$box30, 'box40'=>$box40,'hs_xy'=>$hs_xy
- ]);
- $this->success('成功');
- }
- $info = $this->model->where('id', $id)->find();
- $this->assign('data', $info);
- return $this->fetch();
- }
- /**
- * @NodeAnotation(title="系统自动前置开奖结果")
- */
- public function beforehandle(){
- if ($this->request->isAjax()) {
- if (input('selectFields')) {
- return $this->selectList();
- }
- list($page, $limit, $where) = $this->buildTableParames();
- $model = new BoxMidHandleModel();
- $count = $list = $model
- ->alias('m')
- ->leftJoin('user u', 'u.id = r.uid')
- // ->leftJoin('shop_order_shipping s', 's.order_id = o.order_id')
- ->field('r.*,u.mobile')
- ->order('r.num desc')
- // ->withAttr('order_sn', function($val, $data){
- // return '编号:'.$val;
- // })
- ->page($page, $limit)
- ->count();
- // return 11;
- // foreach ($where as $key=>&$val){
- // $val[$key] = 'r'.$val;
- // }
- // $where[] = ['r.status', '=', 1];
- $list = $this->model
- ->alias('r')
- ->leftJoin('user u', 'u.id = r.uid')
- // ->leftJoin('shop_order_shipping s', 's.order_id = o.order_id')
- ->field('r.*,u.mobile,u.total_null_box,u.total_free,u.total_income')
- ->order('r.num desc')
- // ->withAttr('order_sn', function($val, $data){
- // return '编号:'.$val;
- // })
- ->page($page, $limit)
- ->select()->toArray();
- // $list = $this->model
- // ->alias('r')
- // ->leftJoin('user u', 'u.id = r.uid')
- //
- // ->withoutField('password')
- //
- // ->where($where)
- // ->page($page, $limit)
- // ->field('r.*,u.mobile,s.sp_id,s.sp_name,s.sp_mergename,s.sp_mobile')
- // ->select();
- $data = [
- 'code' => 0,
- 'msg' => '',
- 'count' => $count,
- 'data' => $list,
- ];
- return json($data);
- // return $this->success('成功');
- }
- // if (!Db::name('box_mid_handle')->where('id', '>', 0)->find()){
- // // 算法写界面
- // $this->updateUserBox();
- // }
- return $this->fetch();
- }
- public function setting($id){
- if ($this->request->isAjax()){
- $data = $this->request->post();
- $box10 = $data['box10'];
- $box20 = $data['box20'];
- $box30 = $data['box30'];
- $box40 = $data['box40'];
- $list = Db::name('box_record')->whereIn('id', $id)->where('status', 1)->select();
- // $has_error = false;
- $setting_arr = [];
- foreach ($list as $key=>$val){
- $total_box = $box10 + $box20+ $box30+ $box40;
- if ($val['num'] < $total_box){
- $this->error('不能超过最大预约量');
- // $has_error = true;
- }
- $val['box10'] = $box10;
- $val['box20'] = $box20;
- $val['box30'] = $box30;
- $val['box40'] = $box40;
- $setting_arr[] = $val;
- }
- // if ($has_error){
- // sr_testDb('aaaa', 999);
- // }
- Db::startTrans();
- try {
- $this->model->saveAll($setting_arr);
- Db::commit();
- }catch (\Exception $e){
- Db::rollback();
- $this->error('失败');
- }
- $this->success('成功');
- }
- $this->assign('id', $id);
- return $this->fetch();
- }
- }
|