AdminLotteryController.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: Powerless < wzxaini9@gmail.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\love\controller;
  12. use app\love\model\LotteryLogModel;
  13. use app\love\model\LotteryPrizeModel;
  14. use app\love\model\UserModel;
  15. use cmf\controller\AdminBaseController;
  16. use think\Db;
  17. class AdminLotteryController extends AdminBaseController
  18. {
  19. /**
  20. * 列表
  21. */
  22. public function prize()
  23. {
  24. $status = $this->request->param('status',1);
  25. $where = [];
  26. if (!empty($status)) {
  27. $where[] = ['status', '=', $status];
  28. }
  29. $list = LotteryPrizeModel::where($where)->order('id asc')->paginate(10);
  30. // 获取分页显示
  31. $page = $list->render();
  32. $this->assign('list', $list);
  33. $this->assign('page', $page);
  34. // 渲染模板输出
  35. $this->assign('status', $status);
  36. return $this->fetch();
  37. }
  38. /**
  39. * 添加
  40. */
  41. public function add()
  42. {
  43. return $this->fetch();
  44. }
  45. /**
  46. * 添加提交
  47. */
  48. public function addPost()
  49. {
  50. if ($this->request->isPost()) {
  51. $data = $this->request->param();
  52. $post = $data['post'];
  53. if ($post['odds'] < 0 || $post['odds'] > 100) {
  54. $this->error('中奖概率需要0到100之间');
  55. }
  56. if ($post['number'] < 0) {
  57. $this->error('奖品数量不能小于0');
  58. }
  59. LotteryPrizeModel::create($post);
  60. $this->success('添加成功!', url('prize'));
  61. }
  62. }
  63. /**
  64. * 编辑
  65. */
  66. public function edit()
  67. {
  68. $id = $this->request->param('id', 0, 'intval');
  69. $post = LotteryPrizeModel::get($id);
  70. $this->assign('post', $post);
  71. return $this->fetch();
  72. }
  73. /**
  74. * 编辑提交
  75. */
  76. public function editPost()
  77. {
  78. if ($this->request->isPost()) {
  79. $data = $this->request->param();
  80. $post = $data['post'];
  81. if ($post['odds'] < 0 || $post['odds'] > 100) {
  82. $this->error('中奖概率需要0到100之间');
  83. }
  84. if ($post['number'] < 0) {
  85. $this->error('奖品数量不能小于0');
  86. }
  87. LotteryPrizeModel::update($post, ['id' => $post['id']]);
  88. $this->success('编辑成功!', url('prize'));
  89. }
  90. }
  91. /**
  92. * 调整状态
  93. */
  94. public function setStatus()
  95. {
  96. $id = input('param.id', 0, 'intval');
  97. $status = input('param.status', 0, 'intval');
  98. if (empty($id) || empty($status)) {
  99. $this->error('数据有误');
  100. }
  101. LotteryPrizeModel::update(['status' => $status], ['id' => $id]);
  102. $this->success('操作成功!');
  103. }
  104. /**
  105. * 记录列表
  106. */
  107. public function log()
  108. {
  109. //搜索条件
  110. $param = $this->request->param();
  111. $where = [];
  112. if (!empty($param['mobile'])) {
  113. $user = UserModel::where('mobile', $param['mobile'])->find();
  114. if (empty($user)) {
  115. $where[] = ['id', '=', 0];
  116. } else {
  117. $where[] = ['user_id', '=', $user['id']];
  118. }
  119. }
  120. if (!empty($param['status'])) {
  121. $where[] = ['status', '=', $param['status']];
  122. }
  123. //列表
  124. $list = LotteryLogModel::with('user')->where($where)->order('id asc')->paginate(10, false, [
  125. 'query' => $param,//不丢失已存在的url参数
  126. ]);
  127. // 获取分页显示
  128. $page = $list->render();
  129. $this->assign('list', $list);
  130. $this->assign('page', $page);
  131. // 渲染模板输出
  132. $this->assign('mobile', isset($param['mobile']) ? $param['mobile'] : '');
  133. $this->assign('status', isset($param['status']) ? $param['status'] : '');
  134. return $this->fetch();
  135. }
  136. /**
  137. * 领奖
  138. */
  139. public function receive()
  140. {
  141. $id = input('param.id', 0, 'intval');
  142. LotteryLogModel::update(['status' => 1,'out_at'=>time()], ['id' => $id]);
  143. //增加领证次数
  144. Db::name('config')->where('id',1)->setInc('lottery_num');
  145. $this->success('操作成功!');
  146. }
  147. }