DefaultController.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace addons\UpgradeGift\api\modules\v1\controllers;
  3. use addons\UpgradeGift\common\services\UpgradeGiftGoodsService;
  4. use api\controllers\OnAuthController;
  5. use common\models\user\UserLevel;
  6. /**
  7. * 默认控制器
  8. *
  9. * Class DefaultController
  10. * @package addons\UpgradeGift\api\modules\v1\controllers
  11. */
  12. class DefaultController extends OnAuthController
  13. {
  14. public $modelClass = '';
  15. /**
  16. * 不用进行登录验证的方法
  17. *
  18. * 例如: ['index', 'update', 'create', 'view', 'delete']
  19. * 默认全部需要验证
  20. *
  21. * @var array
  22. */
  23. protected $authOptional = ['index', 'get-unclaimed-gift'];
  24. /**
  25. * 首页
  26. *
  27. * @return string
  28. */
  29. public function actionIndex()
  30. {
  31. return 'Hello world';
  32. }
  33. /**
  34. * 返回待领取的礼品
  35. *
  36. * @return void
  37. */
  38. public function actionGetUnclaimedGift()
  39. {
  40. if (empty($this->user_id)) return $this->success();
  41. $unclaimedGift = (new UpgradeGiftGoodsService(['mall_id' => $this->mall_id, 'user_id' => $this->user_id]))->getUnclaimedGift();
  42. if ($unclaimedGift['is_have']) {
  43. $unclaimedGift['level_text'] = UserLevel::getUserLevelOne([['mall_id' => $this->mall_id], ['level' => $unclaimedGift['level']]], [], true)['name'] ?? '';
  44. }
  45. $this->success('success', [
  46. 'gift_info' => $unclaimedGift
  47. ]);
  48. }
  49. }