"ID", "mall_id" => "Mall ID", "user_id" => "User ID", "auth_type" => "Auth Type", "created_at" => "Created At", "updated_at" => "Updated At", "detail" => "Detail", "auth_id"=> "Auth Id", "check_at" => "Check At", "check_status" => "Check Status", "remark" => 'Remark', ]; } public function getAuth() { return $this->hasOne(RealAuthUser::class, ['id' => 'auth_id']); } /** * @param array $data * @return int * @throws \Exception */ public static function setData(array $data) { $data = self::paramsValidate($data); if(isset($data["id"]) && $data["id"] > 0 ){ $model = self::findOne([ "id" => $data["id"]]); if(!$model){ throw new \Exception("记录不存在"); } }else{ //认证详情每个用户只有一条记录,当个人认证升级为企业认证,个人认证记录不存在 $model = self::findOne(["mall_id" => $data["mall_id"], "user_id" => $data["user_id"],"status"=>StatusEnum::ENABLED,'auth_type'=>$data['auth_type']]); if(!$model){ $model = new self(); } } $model->attributes = $data; if (!$model->save()) { throw new \Exception($model->getErrorMessage()); } return $model->id; } public static function paramsValidate($data){ $mall_id = $data["mall_id"]; $params = $data["detail"]; $config = Yii::$app->services->setting->addons->get($mall_id, AddonsEnum::ADDONS_NAME_REAL_AUTH, "basic"); if(!empty($config["setting_status"])){ if(empty($params["province_id"])&&!empty($params["province"])){ $region = Region::findOne(["name"=>$params["province"],"level"=>1]); if(empty($region)) throw new \Exception("查无该省份"); $params["province_id"] = $region["id"]; } if(empty($params["province_id"]) || empty($params["province"])){ throw new \Exception("省份不能为空"); } if(empty($params["city_id"])){ if(empty($params["city"])) throw new \Exception("请填写城市"); $region = Region::findOne(["name"=>$params["city"],"level"=>2]); if(empty($region)) throw new \Exception("查无该城市"); $parent_region = Region::findOne(["id"=> $region["parent_id"]]); $params["province"] = $parent_region["name"]; $params["province_id"] = $region["parent_id"]; $params["city_id"] = $region["id"]; } if(empty($params["city_id"])){ throw new \Exception("城市不能为空"); } if(empty($params["district_id"])&&!empty($params["district"])){ $region = Region::findOne(["name"=>$params["district"],"level"=>3,"parent_id"=>$params["city_id"]]); if(empty($region)) throw new \Exception("查无该区"); $params["district_id"] = $region["id"]; } if(empty($params["district_id"]) || empty($params["district"])){ throw new \Exception("区不能为空"); } $town_exist = Town::findOne(['district_id'=>$params["district_id"]]); if(!empty($town_exist)){ if(empty($params["town_id"]) || empty($params["town"])){ throw new \Exception("乡/镇/街道不能为空"); } } //企业认证 if($data["auth_type"] == 2){ if(empty($params["mobile"])){ throw new \Exception("联系电话不能为空"); } if(empty($params["business_name"])){ throw new \Exception("企业名称不能为空"); } if(empty($params["business_code"])){ throw new \Exception("社会信用代码不能为空"); } if(empty($params["id_card_front"])){ throw new \Exception("请上传法人身份证人像面"); } if(empty($params["id_card_back"])){ throw new \Exception("请上传法人身份证国徽面"); } if(empty($params["business_license_url"])){ throw new \Exception("请上传营业执照正面"); } if(empty($params["business_license_held"])){ throw new \Exception("请上传上传手持营业执照照片"); } } } // $data["detail"] = json_encode($params,JSON_UNESCAPED_UNICODE); return $data; } }