| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?php
- namespace addons\UpgradeGift\api\modules\v1\controllers;
- use addons\UpgradeGift\common\services\UpgradeGiftGoodsService;
- use api\controllers\OnAuthController;
- use common\models\user\UserLevel;
- /**
- * 默认控制器
- *
- * Class DefaultController
- * @package addons\UpgradeGift\api\modules\v1\controllers
- */
- class DefaultController extends OnAuthController
- {
- public $modelClass = '';
- /**
- * 不用进行登录验证的方法
- *
- * 例如: ['index', 'update', 'create', 'view', 'delete']
- * 默认全部需要验证
- *
- * @var array
- */
- protected $authOptional = ['index', 'get-unclaimed-gift'];
- /**
- * 首页
- *
- * @return string
- */
- public function actionIndex()
- {
- return 'Hello world';
- }
- /**
- * 返回待领取的礼品
- *
- * @return void
- */
- public function actionGetUnclaimedGift()
- {
- if (empty($this->user_id)) return $this->success();
- $unclaimedGift = (new UpgradeGiftGoodsService(['mall_id' => $this->mall_id, 'user_id' => $this->user_id]))->getUnclaimedGift();
- if ($unclaimedGift['is_have']) {
- $unclaimedGift['level_text'] = UserLevel::getUserLevelOne([['mall_id' => $this->mall_id], ['level' => $unclaimedGift['level']]], [], true)['name'] ?? '';
- }
- $this->success('success', [
- 'gift_info' => $unclaimedGift
- ]);
- }
- }
|