jwt->getPayload(); $store_admin_id = $payload['store_admin_id']; if ($store_admin_id > 0) { $StoreMiniAdmin = \app\models\StoreAdmin::findOne(['id' => $store_admin_id, 'status' => 1, 'is_delete' => 0]); $store_id = $StoreMiniAdmin->store_id; } else { $admin = \app\models\Admin::findOne(['id' => $payload['admin_id']]); $store_id = $admin->type_id; } } catch (\Exception $e) { return $this->asJson([ 'code' => 1, 'msg' => '需要重新登录商城' ]); } $item = Purchase::findOne(['store_id' => $store_id, 'is_delete' => 0, 'status' => [0, 1]]); return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'item' => $item ?: [ 'mobile' => get_saas_user()->mobile ], 'cloud_apply_banner' => $cloud_apply_banner ? json_decode($cloud_apply_banner) : [], 'cloud_apply_agreement' => $cloud_apply_agreement, 'custom_list' => $item && $item->custom_data ? json_decode($item->custom_data) : json_decode($custom_list['value']), ] ]); } /** * 提交申请 * @return \yii\web\Response * @throws \yii\base\InvalidConfigException * @throws \yii\base\NotSupportedException * @throws \yii\db\Exception * @throws \yii\base\InvalidArgumentException * @throws \Exception * @throws \yii\db\StaleObjectException * @author Syan mzsongyan@gmail.com * @date 2022-06-18 */ public function actionSubmitApply() { $saas_user_id = get_saas_user_id(); $name = post_params('name'); $mobile = post_params('mobile'); $custom_data = post_params('custom_data'); $district_id = post_params('district_id'); $city_id = post_params('city_id'); $province_id = post_params('province_id'); if (strlen($name) < 2) { return $this->asJson([ 'code' => 1, 'msg' => '名称长度不能小于两位' ]); } //当前接口由商城管理员打开 直接获取商城管理员的商城id try { $payload = \Yii::$app->jwt->getPayload(); $store_admin_id = $payload['store_admin_id']; if ($store_admin_id > 0) { $StoreMiniAdmin = \app\models\StoreAdmin::findOne(['id' => $store_admin_id, 'status' => 1, 'is_delete' => 0]); $store_id = $StoreMiniAdmin->store_id; } else { $admin = \app\models\Admin::findOne(['id' => $payload['admin_id']]); $store_id = $admin->type_id; } } catch (\Exception $e) { return $this->asJson([ 'code' => 1, 'msg' => '需要重新登录商城' ]); } $model = Purchase::findOne(['store_id' => $store_id, 'is_delete' => 0, 'status' => [0, 1]]); $store_cloud_model = StoreCloud::findOne(['store_id' => $store_id, 'is_delete' => 0]); if ($model || $store_cloud_model) { return $this->asJson([ 'code' => 1, 'msg' => '当前商城提交过申请 或 云仓账户已经存在', ]); } $model = Purchase::findOne(['saas_user_id' => $saas_user_id, 'is_delete' => 0, 'status' => [0, 1]]); $store_cloud_model = StoreCloud::findOne(['saas_user_id' => $saas_user_id, 'is_delete' => 0]); if ($model || $store_cloud_model) { return $this->asJson([ 'code' => 1, 'msg' => '当前用户提交过申请了, 请其他用户或管理员', ]); } $is = Purchase::findOne(['name' => $name, 'is_delete' => 0, 'status' => [0, 1]]); $is_store_cloud = StoreCloud::findOne(['name' => $name, 'is_delete' => 0]); if ($is || $is_store_cloud) { return $this->asJson([ 'code' => 1, 'msg' => '姓名已经存在,请更换', ]); } $is = Purchase::findOne(['mobile' => $mobile, 'is_delete' => 0, 'status' => [0, 1]]); $is_store_cloud = StoreCloud::findOne(['tel' => $mobile, 'is_delete' => 0]); if ($is || $is_store_cloud) { return $this->asJson([ 'code' => 1, 'msg' => '手机号已经存在,请更换', ]); } $model = new Purchase(); $model->district_id = $district_id; $model->city_id = $city_id; $model->province_id = $province_id; $model->name = $name; $model->mobile = $mobile; $model->saas_user_id = $saas_user_id; $model->custom_data = $custom_data; $model->status = 0; $model->store_id = $store_id; if ($model->save()) { return $this->asJson([ 'code' => 0, 'msg' => '提交成功', ]); } return $this->asJson([ 'code' => 1, 'msg' => '提交失败', ]); } public function actionGetDistrict() { $data = District::find()->select('id, parent_id, name')->asArray()->all(); $data = $this->getmenu($data); return $this->asJson([ 'code' => 0, 'msg' => '获取成功', 'data' => $data ]); } public function getmenu($menu, $id=0){ $arr = []; foreach ($menu as $k => $v) { if($v['parent_id'] == $id){ $v['children'] = $this -> getmenu($menu, $v['id']); $arr[] = $v; } } return $arr; } }