DefaultController.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. namespace addons\Dianqian\api\modules\v1\controllers;
  3. use addons\Dianqian\common\models\DianqianApply;
  4. use common\enums\StatusEnum;
  5. use common\helpers\sms\Sms;
  6. use Yii;
  7. use api\controllers\OnAuthController;
  8. /**
  9. * 默认控制器
  10. *
  11. * Class DefaultController
  12. * @package addons\Dianqian\api\modules\v1\controllers
  13. */
  14. class DefaultController extends OnAuthController
  15. {
  16. public $modelClass = '';
  17. /**
  18. * 不用进行登录验证的方法
  19. *
  20. * 例如: ['index', 'update', 'create', 'view', 'delete']
  21. * 默认全部需要验证
  22. *
  23. * @var array
  24. */
  25. protected $authOptional = ['help'];
  26. /**
  27. * 首页
  28. *
  29. * @return string
  30. */
  31. public function actionIndex()
  32. {
  33. return 'Hello world';
  34. }
  35. /**
  36. * 签约申请
  37. * @Author: lun
  38. * @DateTime: 2023/5/12 0012 17:33
  39. * @Copyright: copyright (c) 2021 广东七件事集团
  40. * @return mixed|void
  41. * @throws \Exception
  42. */
  43. public function actionApply()
  44. {
  45. $request = Yii::$app->request;
  46. if ($request->isPost) {
  47. $params = $request->post();
  48. // 检查提交的参数
  49. $res = Yii::$app->services->validate->validate($params,[
  50. [['name','mobile','code'], 'required'],
  51. [['mobile','code'], 'integer'],
  52. [['name'], 'string'],
  53. ]);
  54. if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  55. // 检查验证码是否正确
  56. if (YII_ENV == 'prod') {
  57. if (!Sms::checkValidateCode($params['mobile'], $params['code'],'dianqian')) return $this->error('验证码不正确');
  58. }
  59. $params['mall_id'] = $this->mall_id;
  60. $params['user_id'] = $this->user_id;
  61. $res = DianqianApply::apply($params);
  62. if ($res == false) return $this->error('提交失败:'.DianqianApply::getStaticError());
  63. return $this->success('提交成功');
  64. } else {
  65. // 获取用户申请记录
  66. $select = 'id,user_id,name,mobile,reason,remark,sign_status';
  67. $data = DianqianApply::find()->select($select)->where(['mall_id' => $this->mall_id, 'user_id' => $this->user_id, 'status' => StatusEnum::ENABLED])->asArray()->one();
  68. if (empty($data)) {
  69. $data = [
  70. 'name' => '',
  71. 'mobile' => '',
  72. 'sign_status' => 0,
  73. ];
  74. }
  75. // 获取配置内容
  76. $agreement_id = Yii::$app->services->setting->addons->get($this->mall_id, 'Dianqian', 'basic.agreement_id') ?? 0;
  77. $bg_img = Yii::$app->services->setting->addons->get($this->mall_id, 'Dianqian', 'basic.bg_img') ?? '';
  78. $sign_name = Yii::$app->services->setting->addons->get($this->mall_id, 'Dianqian', 'basic.sign_name') ?? '电子签约';
  79. // 获取服务协议
  80. $data['agreement_id'] = $agreement_id;
  81. $data['bg_img'] = $bg_img;
  82. $data['sign_name'] = $sign_name;
  83. return $this->success('获取成功', $data);
  84. }
  85. }
  86. /**
  87. * 帮助内容
  88. * @Author: lun
  89. * @DateTime: 2023/5/12 0012 19:08
  90. * @Copyright: copyright (c) 2021 广东七件事集团
  91. * @return mixed|void
  92. */
  93. public function actionHelp()
  94. {
  95. $request = Yii::$app->request;
  96. if ($request->isPost) {
  97. $help = Yii::$app->services->setting->addons->get($this->mall_id, 'Dianqian', 'basic.help') ?? '';
  98. return $this->success('获取成功', $help);
  99. }
  100. }
  101. /**
  102. * 禁止行为额口
  103. * @Author: lun
  104. * @DateTime: 2023/5/13 0013 11:54
  105. * @Copyright: copyright (c) 2021 广东七件事集团
  106. * @return mixed|void
  107. */
  108. public function actionCheckLimit()
  109. {
  110. $request = Yii::$app->request;
  111. if ($request->isPost) {
  112. $params = $request->post();
  113. // 检查提交的参数
  114. $res = Yii::$app->services->validate->validate($params,[
  115. [['source',], 'required'],
  116. [['source'], 'string'],
  117. ]);
  118. if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  119. // 初始化参数
  120. $data = [
  121. 'title' => '',// 标题
  122. 'reason' => '',// 被拒原因
  123. 'sign_status' => 0,// 状态[0=未签约,1=待审核,-1=审核被拒]
  124. 'is_pop' => 0,// 是否弹窗[0=否,1=是]
  125. 'left_txt' => '取消',// 左按钮文字
  126. 'right_txt' => '去签约',// 右按钮文字
  127. ];
  128. // 获取禁止操作配置
  129. $checkList = Yii::$app->services->setting->addons->get($this->mall_id, 'Dianqian', 'basic.checkList') ?? [];
  130. if (!empty($checkList)) {
  131. $checkList = json_decode($checkList, true);
  132. if (is_array($checkList) && in_array($params['source'], $checkList)) {
  133. // 获取用户申请内容
  134. $apply = DianqianApply::find()->where(['mall_id' => $this->mall_id, 'user_id' => $this->user_id, 'status' => StatusEnum::ENABLED])->asArray()->one();
  135. if (empty($apply)) {
  136. $data['title'] = $params['source'] == 'promotion' ? '尚未签约,签约后可使用该功能!' : '尚未签约,签约后可提现!';
  137. $data['is_pop'] = 1;// 弹窗
  138. } elseif ($apply['sign_status'] == 1) {
  139. $data['title'] = '您的申请正在审核中!';
  140. $data['sign_status'] = $apply['sign_status'];
  141. $data['left_txt'] = '重新提交';
  142. $data['right_txt'] = '知道了';
  143. $data['is_pop'] = 1;// 弹窗
  144. } elseif ($apply['sign_status'] == -1) {
  145. $data['title'] = '您的申请被拒绝了!';
  146. $data['reason'] = $apply['reason'];
  147. $data['sign_status'] = $apply['sign_status'];
  148. $data['left_txt'] = '重新申请';
  149. $data['right_txt'] = '知道了';
  150. $data['is_pop'] = 1;// 弹窗
  151. }
  152. }
  153. }
  154. return $this->success('获取成功', $data);
  155. }
  156. }
  157. }