| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- <?php
- namespace addons\Certificate\api\modules\v1\controllers;
- use addons\Certificate\common\enums\CertificateEnum;
- use addons\Certificate\common\models\Certificate;
- use addons\Certificate\common\models\CertificateClaim;
- use common\enums\StatusEnum;
- use common\models\user\UserLevel;
- use common\enums\DiyEnum;
- use Yii;
- use yii\db\Exception;
- use api\controllers\OnAuthController;
- use yii\db\Expression;
- /**
- * 默认控制器
- *
- * Class DefaultController
- * @package addons\Certificate\api\modules\v1\controllers
- */
- class DefaultController extends OnAuthController
- {
- public $modelClass = '';
- /**
- * 不用进行登录验证的方法
- *
- * 例如: ['index', 'update', 'create', 'view', 'delete']
- * 默认全部需要验证
- *
- * @var array
- */
- protected $authOptional = ['index'];
- /**
- * 首页
- *
- * @return string
- */
- public function actionIndex()
- {
- return 'Hello world';
- }
- /**
- * 获取证书列表
- * @Author: ltm
- * @DateTime: 2022/5/8 0021 11:29
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|string|void
- */
- public function actionList()
- {
- $retuest = Yii::$app->request;
- if ($retuest->isGet) {
- $where = [];
- $where[] = ['=', 'mall_id', $this->mall_id];
- $where[] = ['=', 'status', StatusEnum::ENABLED];
- $countWhere = compact('where');
- $where[] = new Expression("FIND_IN_SET({$this->user['level']}, member_level)");
- $order = 'id desc';
- $params = array('where' => $where, 'order'=>$order, 'limit' => 5);
- $list = Certificate::listPage($params, false, true);
- // 如果后台有新建证书,但是用户的等级一个都看不了,则给提示。如果后台没证书则不理
- if($list['row_count'] == 0) {
- $countQuery = Certificate::find();
- Certificate::paramPack($countWhere, $countQuery);
- if ($countQuery->count() > 0) {
- return $this->error('授权证书目前仅对指定等级开放,请升级后重试');
- }
- }
- $user['number'] = $this->user_id.substr($this->user['mobile'],-4);
- $level = UserLevel::getOne([['mall_id' => $this->mall_id,'status' =>StatusEnum::ENABLED,'level'=>$this->user['level'] ]],true);
- $user['level'] = $level['name'];
- $list['user'] = $user;
- $sign = $this->mall['mall_sign'];
- if($list['list']){
- foreach($list['list'] as $k => $v){
- $list['list'][$k]['qrcode_url'] = DiyEnum::HOME_PAGE_PATH . "?sign={$sign}&pid=".$this->user_id;
- }
- }
- $list['qrcode_id'] = CertificateEnum::SHARE_TYPE;
- $this->success('获取成功', $list);
- }
- }
- /**
- * 认领证书
- * @Author: ltm
- * @DateTime: 2022/5/8 0021 11:29
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|string|void
- */
- public function actionCodeDetail()
- {
- $retuest = Yii::$app->request;
- if ($retuest->isGet) {
- $params = Yii::$app->request->get();
- // 检查提交的参数
- $res = Yii::$app->services->validate->validate($params,[
- [['id'], 'safe']
- ]);
- if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $params['user_id'] = $this->user_id;
- $params['mall_id'] = $this->mall_id;
- $params['mobile'] = $this->user['mobile'];
- $res = CertificateClaim::setData($params);
- if ($res === false) throw new Exception(CertificateClaim::getStaticError());
- return $this->success('操作成功');
- }
- }
- /**
- * 认领证书
- * @Author: ltm
- * @DateTime: 2022/5/8 0021 11:29
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|string|void
- */
- public function actionClaim()
- {
- $retuest = Yii::$app->request;
- if ($retuest->isGet) {
- $params = Yii::$app->request->get();
- // 检查提交的参数
- $res = Yii::$app->services->validate->validate($params,[
- [['id'], 'safe']
- ]);
- if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $params['user_id'] = $this->user_id;
- $params['mall_id'] = $this->mall_id;
- $params['mobile'] = $this->user['mobile'];
- $res = CertificateClaim::setData($params);
- if ($res === false) throw new Exception(CertificateClaim::getStaticError());
- return $this->success('操作成功');
- }
- }
- }
|