ApplyController.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <?php
  2. namespace addons\Happiness\api\modules\v1\controllers;
  3. use addons\Happiness\common\enums\HappinessEnum;
  4. use addons\Happiness\common\models\HappinessBusiness;
  5. use addons\Happiness\common\models\HappinessStore;
  6. use api\controllers\OnAuthController;
  7. use common\enums\StatusEnum;
  8. use common\helpers\sms\Sms;
  9. use common\models\common\Region;
  10. use common\models\goods\Goods;
  11. use common\enums\ApiStatusEnum;
  12. use common\globals\GlobalInvoke;
  13. use common\models\user\User;
  14. class ApplyController extends OnAuthController
  15. {
  16. public $modelClass = '';
  17. /**
  18. * 不用进行登录验证的方法
  19. *
  20. * 例如: ['index', 'update', 'create', 'view', 'delete']
  21. * 默认全部需要验证
  22. *
  23. * @var array
  24. */
  25. protected $authOptional = ['index'];
  26. public function actionRecruit()
  27. {
  28. if (!\Yii::$app->request->isGet) {
  29. return $this->error('请求方式错误');
  30. }
  31. $settings = \Yii::$app->services->setting->addons->get($this->mall_id, HappinessEnum::ADDONS_NAME, 'basic');
  32. if (0 == $settings['is_enable']) {
  33. return $this->error('小店入驻未开启');
  34. }
  35. $store = HappinessStore::find()
  36. ->select('id,mall_id,user_id,shop_owner,shop_mobile,store_name,store_desc,city_id,district_id,province_id,
  37. logo_img,license_img,address,longitude,latitude,check_status,check_remark')
  38. ->where(['mall_id' => $this->mall_id, 'user_id' => $this->user_id, 'status' => StatusEnum::ENABLED])
  39. ->asArray()
  40. ->one();
  41. // 入驻申请进度,0:未申请;1:审核中;2:审核通过;3:审核未通过
  42. $apply_step = 0;
  43. $store_account = [];
  44. if (!empty($store)) {
  45. //省市区ID
  46. $where[] = ['in', 'id', [$store['province_id'], $store['city_id'], $store['district_id']]];
  47. $region = Region::getRegionList($where);
  48. if (!empty($region)) {
  49. $region = array_column($region, null, 'id');
  50. }
  51. $store['province_name'] = $region[$store['province_id']]['name'] ?? '';
  52. $store['city_name'] = $region[$store['city_id']]['name'] ?? '';
  53. $store['district_name'] = $region[$store['district_id']]['name'] ?? '';
  54. $store['detail_address'] = $store['address'];
  55. if (HappinessEnum::CHECK_WAITING == $store['check_status']) {
  56. $apply_step = 1;
  57. } elseif (HappinessEnum::CHECK_ADOPT == $store['check_status']) {
  58. $apply_step = 2;
  59. $backend_domain = \Yii::$app->services->setting->platform->get('system.backend_url');
  60. $backend_domain = empty($backend_domain) ? '' : (string)$backend_domain;
  61. $store_account = [
  62. 'store_login_url' => trim($backend_domain, '/') . '?r=happiness/client/auth/login&sign=' .
  63. $this->mall['mall_sign'],
  64. 'account' => $store['shop_mobile'],
  65. 'login_pwd' => substr($store['shop_mobile'], -6),
  66. ];
  67. } else if (HappinessEnum::CHECK_FAILED == $store['check_status']) {
  68. $apply_step = 3;
  69. }
  70. }
  71. $result = [
  72. 'settings' => $settings,
  73. 'apply_step' => $apply_step,
  74. 'store' => $store,
  75. 'store_account' => $store_account,
  76. ];
  77. return $this->success('success', $result);
  78. }
  79. /**
  80. * @name:
  81. * @msg: 提交入驻申请
  82. * @param {*}
  83. * @return {*}
  84. */
  85. public function actionEnterApply()
  86. {
  87. if (!\Yii::$app->request->isPost) {
  88. return $this->error('请求方式错误');
  89. }
  90. $settings = \Yii::$app->services->setting->addons->get($this->mall_id, HappinessEnum::ADDONS_NAME, 'basic');
  91. $upload_license_image = 1;
  92. $post = \Yii::$app->request->post();
  93. $rules = [
  94. [['shop_owner', 'shop_mobile', 'store_name', 'logo_img'], 'required'],
  95. [['shop_owner', 'store_name', 'store_desc', 'logo_img', 'license_img', 'longitude', 'latitude'], 'string', 'max' => 255],
  96. [[ 'province_id', 'city_id', 'district_id'], 'integer'],
  97. [['business_id'],'safe'],
  98. ['license_img', 'required', 'when' => function ($model) use ($upload_license_image) {
  99. return $upload_license_image == 1;
  100. }],
  101. [['id'], 'safe'],
  102. // 小店入驻新增参数
  103. [['card_type', 'card_name', 'card_no', 'prov_id', 'area_id', 'branch_code', 'cert_type', 'cert_no', 'cert_validity_type', 'cert_begin_date', 'cert_end_date', 'mp', 'is_settle_default'], 'required']
  104. ];
  105. $res = \Yii::$app->services->validate->validate($post, $rules);
  106. if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  107. $post['address'] .= $post['detail_address'];
  108. $post['mall_id'] = $this->mall_id;
  109. $post['user_id'] = $this->user_id;
  110. unset($post['detail_address']);
  111. $post['shop_mobile'] = (string)$post['shop_mobile'];
  112. $query = HappinessStore::find()->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'shop_mobile' => $post['shop_mobile'], 'shop_owner' => $post['shop_owner']]);
  113. if (!empty($post['id'])) {
  114. $query->andWhere(['id' => $post['id']]);
  115. } else {
  116. unset($post['id']);
  117. }
  118. $clinic = $query->one();
  119. if (!empty($clinic)) {
  120. if (empty($post['id'])) {
  121. // 新提交的申请
  122. return $this->error('您已经申请过请勿重复申请');
  123. } else {
  124. // 审核失败后重新提交的申请
  125. if ($clinic->check_status != HappinessEnum::CHECK_FAILED) {
  126. return $this->error('商户状态异常');
  127. }
  128. $clinic->attributes = $post;
  129. $clinic->check_status = HappinessEnum::CHECK_WAITING;
  130. //查询业务员
  131. $business = User::find()
  132. ->andWhere(['mall_id' => $this->mall_id])
  133. ->andWhere([
  134. 'or',
  135. ['id' => $post['business_id']],
  136. ['mobile' => $post['business_id']]
  137. ])
  138. ->one();
  139. if(empty($business))
  140. {
  141. return $this->error( '推广员不存在');
  142. }
  143. $business=HappinessBusiness::find()->where(['mall_id' =>$this->mall_id, 'user_id' => $business->id])
  144. ->one();
  145. if(empty($business))
  146. {
  147. return $this->error('用户'.$business->id.'不是推广员');
  148. }
  149. $clinic->business_id = $business->user_id;
  150. $res = $clinic->save();
  151. if (!$res) {
  152. return $this->error($clinic->getErrorMessage());
  153. }
  154. return $this->success('提交成功');
  155. }
  156. }
  157. if ($settings['store_audit'] == 1) {
  158. $post['check_status'] = HappinessEnum::CHECK_WAITING;
  159. } else {
  160. $post['check_status'] = HappinessEnum::CHECK_ADOPT;
  161. }
  162. $res = HappinessStore::addStore($post);
  163. if (false === $res) {
  164. return $this->error(HappinessStore::getStaticError());
  165. }
  166. return $this->success('提交成功');
  167. }
  168. public function actionAgreement()
  169. {
  170. $setting = \Yii::$app->services->setting->addons->get($this->mall_id, HappinessEnum::ADDONS_NAME, 'basic');
  171. $data = [
  172. 'recruit_title' => $setting['recruit_title'] ?? '',
  173. 'recruit_content' => $setting['recruit_content'] ?? '',
  174. ];
  175. return $this->success('获取成功', $data);
  176. }
  177. }