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(); } }