| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- <?php
- namespace addons\Dianqian\api\modules\v1\controllers;
- use addons\Dianqian\common\models\DianqianApply;
- use common\enums\StatusEnum;
- use common\helpers\sms\Sms;
- use Yii;
- use api\controllers\OnAuthController;
- /**
- * 默认控制器
- *
- * Class DefaultController
- * @package addons\Dianqian\api\modules\v1\controllers
- */
- class DefaultController extends OnAuthController
- {
- public $modelClass = '';
- /**
- * 不用进行登录验证的方法
- *
- * 例如: ['index', 'update', 'create', 'view', 'delete']
- * 默认全部需要验证
- *
- * @var array
- */
- protected $authOptional = ['help'];
- /**
- * 首页
- *
- * @return string
- */
- public function actionIndex()
- {
- return 'Hello world';
- }
- /**
- * 签约申请
- * @Author: lun
- * @DateTime: 2023/5/12 0012 17:33
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|void
- * @throws \Exception
- */
- public function actionApply()
- {
- $request = Yii::$app->request;
- if ($request->isPost) {
- $params = $request->post();
- // 检查提交的参数
- $res = Yii::$app->services->validate->validate($params,[
- [['name','mobile','code'], 'required'],
- [['mobile','code'], 'integer'],
- [['name'], 'string'],
- ]);
- if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- // 检查验证码是否正确
- if (YII_ENV == 'prod') {
- if (!Sms::checkValidateCode($params['mobile'], $params['code'],'dianqian')) return $this->error('验证码不正确');
- }
- $params['mall_id'] = $this->mall_id;
- $params['user_id'] = $this->user_id;
- $res = DianqianApply::apply($params);
- if ($res == false) return $this->error('提交失败:'.DianqianApply::getStaticError());
- return $this->success('提交成功');
- } else {
- // 获取用户申请记录
- $select = 'id,user_id,name,mobile,reason,remark,sign_status';
- $data = DianqianApply::find()->select($select)->where(['mall_id' => $this->mall_id, 'user_id' => $this->user_id, 'status' => StatusEnum::ENABLED])->asArray()->one();
- if (empty($data)) {
- $data = [
- 'name' => '',
- 'mobile' => '',
- 'sign_status' => 0,
- ];
- }
- // 获取配置内容
- $agreement_id = Yii::$app->services->setting->addons->get($this->mall_id, 'Dianqian', 'basic.agreement_id') ?? 0;
- $bg_img = Yii::$app->services->setting->addons->get($this->mall_id, 'Dianqian', 'basic.bg_img') ?? '';
- $sign_name = Yii::$app->services->setting->addons->get($this->mall_id, 'Dianqian', 'basic.sign_name') ?? '电子签约';
- // 获取服务协议
- $data['agreement_id'] = $agreement_id;
- $data['bg_img'] = $bg_img;
- $data['sign_name'] = $sign_name;
- return $this->success('获取成功', $data);
- }
- }
- /**
- * 帮助内容
- * @Author: lun
- * @DateTime: 2023/5/12 0012 19:08
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|void
- */
- public function actionHelp()
- {
- $request = Yii::$app->request;
- if ($request->isPost) {
- $help = Yii::$app->services->setting->addons->get($this->mall_id, 'Dianqian', 'basic.help') ?? '';
- return $this->success('获取成功', $help);
- }
- }
- /**
- * 禁止行为额口
- * @Author: lun
- * @DateTime: 2023/5/13 0013 11:54
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|void
- */
- public function actionCheckLimit()
- {
- $request = Yii::$app->request;
- if ($request->isPost) {
- $params = $request->post();
- // 检查提交的参数
- $res = Yii::$app->services->validate->validate($params,[
- [['source',], 'required'],
- [['source'], 'string'],
- ]);
- if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- // 初始化参数
- $data = [
- 'title' => '',// 标题
- 'reason' => '',// 被拒原因
- 'sign_status' => 0,// 状态[0=未签约,1=待审核,-1=审核被拒]
- 'is_pop' => 0,// 是否弹窗[0=否,1=是]
- 'left_txt' => '取消',// 左按钮文字
- 'right_txt' => '去签约',// 右按钮文字
- ];
- // 获取禁止操作配置
- $checkList = Yii::$app->services->setting->addons->get($this->mall_id, 'Dianqian', 'basic.checkList') ?? [];
- if (!empty($checkList)) {
- $checkList = json_decode($checkList, true);
- if (is_array($checkList) && in_array($params['source'], $checkList)) {
- // 获取用户申请内容
- $apply = DianqianApply::find()->where(['mall_id' => $this->mall_id, 'user_id' => $this->user_id, 'status' => StatusEnum::ENABLED])->asArray()->one();
- if (empty($apply)) {
- $data['title'] = $params['source'] == 'promotion' ? '尚未签约,签约后可使用该功能!' : '尚未签约,签约后可提现!';
- $data['is_pop'] = 1;// 弹窗
- } elseif ($apply['sign_status'] == 1) {
- $data['title'] = '您的申请正在审核中!';
- $data['sign_status'] = $apply['sign_status'];
- $data['left_txt'] = '重新提交';
- $data['right_txt'] = '知道了';
- $data['is_pop'] = 1;// 弹窗
- } elseif ($apply['sign_status'] == -1) {
- $data['title'] = '您的申请被拒绝了!';
- $data['reason'] = $apply['reason'];
- $data['sign_status'] = $apply['sign_status'];
- $data['left_txt'] = '重新申请';
- $data['right_txt'] = '知道了';
- $data['is_pop'] = 1;// 弹窗
- }
- }
- }
- return $this->success('获取成功', $data);
- }
- }
- }
|