Lottery.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace app\api\controller\plus\lottery;
  3. use app\api\controller\Controller;
  4. use app\api\model\plus\lottery\Lottery as LotteryModel;
  5. use app\api\model\plus\lottery\Record as RecordModel;
  6. use app\shop\model\plus\lottery\LotteryPrize as LotteryPrizeModel;
  7. /**
  8. * 转盘控制器
  9. */
  10. class Lottery extends Controller
  11. {
  12. /**
  13. * 获取数据
  14. * @param null $id
  15. */
  16. public function getLottery()
  17. {
  18. $model = new LotteryModel();
  19. $data = $model->getDetail();
  20. $data['prize'] = $data ? LotteryPrizeModel::detail($data['lottery_id']) : [];
  21. //剩余抽奖次数
  22. $num = $model->getNum($this->getUser());
  23. $nums = $data['times'] - $num;
  24. //抽奖播放数据
  25. $recordModel = new RecordModel();
  26. $recordList = $recordModel->getLimitList(60);
  27. $data['user_points'] = $this->getUser()['points'];
  28. return $this->renderSuccess('', compact('data', 'nums', 'recordList'));
  29. }
  30. /*
  31. * 转盘记录列表
  32. */
  33. public function record()
  34. {
  35. $model = new RecordModel();
  36. $list = $model->getList($this->postData(), $this->getUser());
  37. return $this->renderSuccess('', compact('list'));
  38. }
  39. /*
  40. * 开始抽奖
  41. */
  42. public function draw()
  43. {
  44. $model = new LotteryModel();
  45. $result = $model->getdraw($this->getUser());
  46. if ($result) {
  47. return $this->renderSuccess('', compact('result'));
  48. }
  49. return $this->renderError($model->getError() ?: '抽奖失败');
  50. }
  51. }