GuaController.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace mobile\controllers;
  3. use biz\tool\services\GuaGuaAttendService;
  4. use biz\tool\services\GuaGuaPrizeService;
  5. use biz\tool\services\GuaGuaService;
  6. use biz\tool\services\GuaGuaWinService;
  7. use common\components\util;
  8. use Yii;
  9. use yii\helpers\Json;
  10. class GuaController extends MobileendController
  11. {
  12. public $withoutLogin = ['index'];
  13. public $layout = false;
  14. public function beforeAction($action)
  15. {
  16. return parent::beforeAction($action);
  17. }
  18. public function actionIndex()
  19. {
  20. $id = Yii::$app->request->get('id');
  21. $card = GuaGuaService::getById($id);
  22. if (empty($card) || $card['merchantId'] != $this->merchantId) {
  23. echo '非法访问';
  24. Yii::$app->end();
  25. }
  26. $remainNum = 0;
  27. //增加访问次数和访问用户数
  28. GuaGuaService::addVisit($id);
  29. $winUser = GuaGuaWinService::getWinUser($card);
  30. $userInfo = [];
  31. if ($this->isLogin) {
  32. //创建更新用户的参与信息并获取剩余次数
  33. $remainNum = GuaGuaAttendService::getRemainNum($card);
  34. $userInfo = $this->user;
  35. }
  36. return $this->render('index', ['card' => $card, 'remainNum' => $remainNum, 'userInfo' => $userInfo, 'winUser' => $winUser]);
  37. }
  38. /*
  39. * 刮一次的时候确认奖品
  40. */
  41. public function actionGua()
  42. {
  43. $id = Yii::$app->request->get('id');
  44. $data = GuaGuaPrizeService::getPrize($id);
  45. if ($this->error->hasError) {
  46. util::failInfo($this->error->getError());
  47. }
  48. util::successInfo('success', 'A0001', $data);
  49. }
  50. //我的奖品 shish 2019.8.10
  51. public function actionMyPrize()
  52. {
  53. $id = Yii::$app->request->get('id');
  54. $prize = GuaGuaWinService::getMyPrize($id);
  55. return $this->render('myPrize', ['prize' => $prize, 'userInfo' => $this->user]);
  56. }
  57. }