123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- <?php
- // +----------------------------------------------------------------------
- // | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
- // +----------------------------------------------------------------------
- // | Author: Powerless < wzxaini9@gmail.com>
- // +----------------------------------------------------------------------
- namespace app\love\controller;
- use app\love\model\LotteryLogModel;
- use app\love\model\LotteryPrizeModel;
- use app\love\model\UserModel;
- use cmf\controller\AdminBaseController;
- use think\Db;
- class AdminLotteryController extends AdminBaseController
- {
- /**
- * 列表
- */
- public function prize()
- {
- $status = $this->request->param('status',1);
- $where = [];
- if (!empty($status)) {
- $where[] = ['status', '=', $status];
- }
- $list = LotteryPrizeModel::where($where)->order('id asc')->paginate(10);
- // 获取分页显示
- $page = $list->render();
- $this->assign('list', $list);
- $this->assign('page', $page);
- // 渲染模板输出
- $this->assign('status', $status);
- return $this->fetch();
- }
- /**
- * 添加
- */
- public function add()
- {
- return $this->fetch();
- }
- /**
- * 添加提交
- */
- public function addPost()
- {
- if ($this->request->isPost()) {
- $data = $this->request->param();
- $post = $data['post'];
- if ($post['odds'] < 0 || $post['odds'] > 100) {
- $this->error('中奖概率需要0到100之间');
- }
- if ($post['number'] < 0) {
- $this->error('奖品数量不能小于0');
- }
- LotteryPrizeModel::create($post);
- $this->success('添加成功!', url('prize'));
- }
- }
- /**
- * 编辑
- */
- public function edit()
- {
- $id = $this->request->param('id', 0, 'intval');
- $post = LotteryPrizeModel::get($id);
- $this->assign('post', $post);
- return $this->fetch();
- }
- /**
- * 编辑提交
- */
- public function editPost()
- {
- if ($this->request->isPost()) {
- $data = $this->request->param();
- $post = $data['post'];
- if ($post['odds'] < 0 || $post['odds'] > 100) {
- $this->error('中奖概率需要0到100之间');
- }
- if ($post['number'] < 0) {
- $this->error('奖品数量不能小于0');
- }
- LotteryPrizeModel::update($post, ['id' => $post['id']]);
- $this->success('编辑成功!', url('prize'));
- }
- }
- /**
- * 调整状态
- */
- public function setStatus()
- {
- $id = input('param.id', 0, 'intval');
- $status = input('param.status', 0, 'intval');
- if (empty($id) || empty($status)) {
- $this->error('数据有误');
- }
- LotteryPrizeModel::update(['status' => $status], ['id' => $id]);
- $this->success('操作成功!');
- }
- /**
- * 记录列表
- */
- public function log()
- {
- //搜索条件
- $param = $this->request->param();
- $where = [];
- if (!empty($param['mobile'])) {
- $user = UserModel::where('mobile', $param['mobile'])->find();
- if (empty($user)) {
- $where[] = ['id', '=', 0];
- } else {
- $where[] = ['user_id', '=', $user['id']];
- }
- }
- if (!empty($param['status'])) {
- $where[] = ['status', '=', $param['status']];
- }
- //列表
- $list = LotteryLogModel::with('user')->where($where)->order('id asc')->paginate(10, false, [
- 'query' => $param,//不丢失已存在的url参数
- ]);
- // 获取分页显示
- $page = $list->render();
- $this->assign('list', $list);
- $this->assign('page', $page);
- // 渲染模板输出
- $this->assign('mobile', isset($param['mobile']) ? $param['mobile'] : '');
- $this->assign('status', isset($param['status']) ? $param['status'] : '');
- return $this->fetch();
- }
- /**
- * 领奖
- */
- public function receive()
- {
- $id = input('param.id', 0, 'intval');
- LotteryLogModel::update(['status' => 1,'out_at'=>time()], ['id' => $id]);
- //增加领证次数
- Db::name('config')->where('id',1)->setInc('lottery_num');
- $this->success('操作成功!');
- }
- }
|