| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- <?php
- namespace app\admin\controller\box;
- use app\common\model\BoxMidHandleModel;
- use app\common\model\BoxRecordModel;
- use app\admin\traits\Curd;
- use app\common\controller\AdminController;
- use app\common\service\BoxRecordService;
- use think\App;
- use think\facade\Db;
- use utils\RedisCache;
- /**
- * 开福袋 by wes
- * 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;
- /**
- * @NodeAnotation(title="福袋预约记录")
- */
- public function index()
- {
- if ($this->request->isAjax()) {
- if (input('selectFields')) {
- return $this->selectList();
- }
- list($page, $limit, $where) = $this->buildTableParames();
- $isMatch = $this->request->get('match', 0);
- if ($isMatch) {
- $where['is_set_match'] = 1;
- $where['box10'] = 1;
- }
- $list = BoxRecordService::make()->getCatchList($where, $limit);
- $data = [
- 'code' => 0,
- 'msg' => '获取成功',
- 'count' => isset($list['total']) ? $list['total'] : 0,
- 'data' => isset($list['data']) ? $list['data'] : [],
- ];
- return json($data);
- }
- $totalNum = BoxRecordModel::where('id', '>', 0)->sum('num');
- $totalCurnum = BoxRecordModel::where('id', '>', 0)
- ->where('status', 1)
- ->where('create_time', '>=', date('Y-m-d'))
- ->sum('num');
- $this->assign('cur_info', [
- 'total_num' => $totalNum,
- 'total_money' => $totalNum * env('boxsetting.ONE_BOX_PRICE'),
- 'total_curnum' => $totalCurnum,
- 'total_curmoney' => $totalCurnum * env('boxsetting.ONE_BOX_PRICE'),
- ]);
- return $this->fetch();
- }
- /**
- * @NodeAnotation(title="手动干预福袋开奖")
- */
- public function beforeopen($id)
- {
- if ($this->request->isPost()) {
- $data = $this->request->post();
- $result = BoxRecordService::make()->setBoxMatch($id, $data);
- if ($result === true) {
- $this->success('设置成功');
- } else {
- $this->error($result ? $result : '设置失败');
- }
- }
- $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')
- ->field('r.*,u.mobile')
- ->order('r.num desc')
- ->page($page, $limit)
- ->count();
- $list = $this->model
- ->alias('r')
- ->leftJoin('user u', 'u.id = r.uid')
- ->field('r.*,u.mobile,u.total_null_box,u.total_free,u.total_income')
- ->order('r.num desc')
- ->page($page, $limit)
- ->select()->toArray();
- $data = [
- 'code' => 0,
- 'msg' => '',
- 'count' => $count,
- 'data' => $list,
- ];
- return json($data);
- }
- return $this->fetch();
- }
- /**
- * 设置匹配
- * @param $id
- * @return mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function setting($id)
- {
- if ($this->request->isAjax()) {
- $data = $this->request->post();
- $result = BoxRecordService::make()->setBoxMatch($id, $data);
- if ($result === true) {
- $this->success('设置成功');
- } else {
- $this->error($result ? $result : '设置失败');
- }
- }
- $this->assign('id', $id);
- return $this->fetch();
- }
- /**
- * 手动开奖
- * @param $id
- * @return mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function openBox()
- {
- $data = $this->request->post();
- $ids = isset($data['id']) ? $data['id'] : [];
- $result = BoxRecordService::make()->openBox($ids, $data);
- if (is_array($result)) {
- $this->success($result['msg'], $result['data'], '', 10);
- } else {
- $this->error($result ? $result : '开奖失败');
- }
- }
- }
|