| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- <?php
- /*
- * @Descripttion:
- * @version:
- * @Author: ewgof
- * @Date: 2022-06-09 14:34:20
- * @LastEditors: ewgof
- * @LastEditTime: 2022-06-10 10:42:23
- */
- namespace addons\Mch\api\modules\v1\controllers;
- use addons\Mch\common\enums\MchEnum;
- use addons\Mch\common\models\Mch;
- use addons\Mch\common\models\MchCate;
- use addons\Mch\common\models\MchUserEnterQualification;
- use api\controllers\OnAuthController;
- use common\enums\StatusEnum;
- use common\helpers\sms\Sms;
- use common\models\common\Region;
- use common\models\goods\Goods;
- use common\enums\ApiStatusEnum;
- use common\globals\GlobalInvoke;
- class StoreDowCenterController extends OnAuthController
- {
- public $modelClass = '';
- /**
- * 不用进行登录验证的方法
- *
- * 例如: ['index', 'update', 'create', 'view', 'delete']
- * 默认全部需要验证
- *
- * @var array
- */
- protected $authOptional = ['index'];
- public function actionMchRecruit()
- {
- if (!\Yii::$app->request->isGet) {
- return $this->error('请求方式错误');
- }
- $settings = \Yii::$app->services->setting->addons->get($this->mall_id, MchEnum::ADDONS_NAME, 'enter');
- if (0 == $settings['is_enable']) {
- return $this->error('商家入驻未开启');
- }
- //检测是否需要实名认证
- $need_auth = GlobalInvoke::exec(GlobalInvoke::REAL_AUTH_BUSINESS, $this->mall_id, ['user_id' => $this->user_id, 'mall_id' => $this->mall_id, 'type' => 'store']);
- if ($need_auth === true) {
- //需要先进行实名认证
- return $this->error('请先进行实名认证', [], ApiStatusEnum::CODE_ERROR_NEED_REAL_AUTH);
- }
- if (!empty($settings['goods_ids'])) {
- $settings['goods_ids'] = json_decode($settings['goods_ids'], true);
- $goods = Goods::find()
- ->select('id,goods_name,price,cover_pic')
- ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'id' => $settings['goods_ids']])
- ->asArray()
- ->all();
- $settings['good_list'] = $goods;
- }
- // 是否有资格入驻门店
- $is_can_enter = 0;
- if (2 == $settings['mode']) {
- $qualification = MchUserEnterQualification::findOne(['mall_id' => $this->mall_id, 'user_id' => $this->user_id, 'status' => StatusEnum::ENABLED]);
- if (!empty($qualification)) {
- $is_can_enter = 1;
- }
- } else {
- $is_can_enter = 1;
- }
- $settings['is_can_enter'] = $is_can_enter;
- $mch = Mch::find()
- ->select('id,mall_id,user_id,shop_owner,shop_mobile,store_name,c_id,store_desc,
- logo_img,license_img,address,longitude,latitude,check_status,check_remark, store_background')
- ->where(['mall_id' => $this->mall_id, 'user_id' => $this->user_id, 'status' => StatusEnum::ENABLED])
- ->asArray()
- ->one();
- // 入驻申请进度,0:未申请;1:审核中;2:审核通过;3:审核未通过
- $apply_step = 0;
- $mch_account = [];
- if (!empty($mch)) {
- $mch['detail_address'] = $mch['address'];
- if (MchEnum::CHECK_WAITING == $mch['check_status']) {
- $apply_step = 1;
- } elseif (MchEnum::CHECK_ADOPT == $mch['check_status']) {
- $apply_step = 2;
- $backend_domain = \Yii::$app->services->setting->platform->get('system.backend_url');
- $backend_domain = empty($backend_domain) ? '' : (string)$backend_domain;
- $mch_account = [
- 'mch_login_url' => trim($backend_domain, '/') . '?r=mch/client/auth/login&sign=' . $this->mall['mall_sign'],
- 'account' => $mch['shop_mobile'],
- 'login_pwd' => substr($mch['shop_mobile'], -6),
- ];
- } else if (MchEnum::CHECK_FAILED == $mch['check_status']) {
- $apply_step = 3;
- }
- }
- $categorys = MchCate::find()
- ->select('id,name')
- ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])
- ->asArray()
- ->all();
- $result = [
- 'settings' => $settings,
- 'apply_step' => $apply_step,
- 'mch' => $mch,
- 'categorys' => $categorys,
- 'mch_account' => $mch_account,
- ];
- return $this->success('success', $result);
- }
- /**
- * @name:
- * @msg: 提交商户入驻申请
- * @param {*}
- * @return {*}
- */
- public function actionEnterApply()
- {
- if (!\Yii::$app->request->isPost) {
- return $this->error('请求方式错误');
- }
- $settings = \Yii::$app->services->setting->addons->get($this->mall_id, MchEnum::ADDONS_NAME, 'enter');
- $upload_license_image = $settings['upload_license_image'];
- $post = \Yii::$app->request->post();
- $rules = [
- [['store_desc'], 'required','message'=>'商户介绍不能为空'],
- [['logo_img'], 'required','message'=>'请上传商家logo'],
- [['store_background'], 'required','message'=>'请上传店铺背景图'],
- [['shop_owner', 'shop_mobile', 'store_name', 'c_id', 'vcode'], 'required'],
- [['shop_owner', 'store_name', 'store_desc', 'logo_img', 'license_img', 'longitude', 'latitude','store_background'], 'string', 'max' => 255],
- ['vcode', 'string'],
- [['shop_mobile', 'c_id'], 'integer'],
- ['license_img', 'required', 'when' => function ($model) use ($upload_license_image) {
- return $upload_license_image == 1;
- }],
- [['id'], 'safe'],
- ];
- $res = \Yii::$app->services->validate->validate($post, $rules);
- if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- if (!YII_DEBUG && !Sms::checkValidateCode($post['shop_mobile'], $post['vcode'])) {
- return $this->error('验证码不正确');
- }
- preg_match('/(.*?(?:省|自治区|北京市|天津市|上海市|重庆市))+(.*?(?:市|自治州|地区|区划|县))+(.*?(?:市|区|县|镇|乡|街道))/', $post['address'], $matches);
- // dd($matches);
- if (count($matches) > 1) {
- $query = Region::find();
- $province = $query->where(['name' => $matches[1]])->one();
- $city = $query->where(['name' => $matches[2]])->one();
- $district = $query->where(['name' => $matches[3]])->one();
- // dd($province->name, $city->name, $district->name);
- $post['province_id'] = $province->id ?? 0;
- $post['city_id'] = $city->id ?? 0;
- $post['district_id'] = $district->id ?? 0;
- }
- $post['address'] .= $post['detail_address'];
- $post['mall_id'] = $this->mall_id;
- $post['user_id'] = $this->user_id;
- unset($post['detail_address']);
- $query = Mch::find()->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'shop_mobile' => $post['shop_mobile'], 'shop_owner' => $post['shop_owner']]);
- if (!empty($post['id'])) {
- $query->andWhere(['id' => $post['id']]);
- } else {
- unset($post['id']);
- }
- $mch = $query->one();
- if (!empty($mch)) {
- if (empty($post['id'])) {
- // 新提交的申请
- return $this->error('您已经申请过请勿重复申请');
- } else {
- // 审核失败后重新提交的申请
- if ($mch->check_status != MchEnum::CHECK_FAILED) {
- return $this->error('商户状态异常');
- }
- $mch->attributes = $post;
- $mch->check_status = MchEnum::CHECK_WAITING;
- $res = $mch->save();
- if (!$res) {
- return $this->error($mch->getErrorMessage());
- }
- return $this->success('提交成功');
- }
- }
- if ($settings['store_audit'] == 1) {
- $post['check_status'] = MchEnum::CHECK_WAITING;
- } else {
- $post['check_status'] = MchEnum::CHECK_ADOPT;
- }
- //设置到期时间
- if($settings['time_status'] == 1 && !empty($settings['expired_days'])){
- $post['expire_time'] = time() + ($settings['expired_days'] * 60 * 60 * 24);
- }
- //dd($post);
- $res = Mch::addStore($post);
- if (false === $res) {
- return $this->error(Mch::getStaticError());
- }
- return $this->success('提交成功');
- }
- }
|