| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- <?php
- namespace addons\RealAuth\common\models;
- use common\models\base\BaseActiveRecord;
- use common\enums\AddonsEnum;
- use common\enums\StatusEnum;
- use common\models\common\Region;
- use common\models\user\Town;
- use Yii;
- /**
- * This is the model class for table "{{%addons_real_auth_detail}}".
- *
- * @property int $id
- * @property int $mall_id
- * @property int $user_id 用户ID
- * @property int $auth_type 实名认证类型:0未知,1 个人 2 企业
- * @property int $created_at 添加时间戳
- * @property int $updated_at 更新时间戳
- * @property string $detail 实名认证资料,json格式
- */
- class RealAuthDetail extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return "{{%addons_real_auth_detail}}";
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [["mall_id", "user_id","auth_id", "auth_type", "created_at", "updated_at","check_at","check_status"], "integer"],
- [["detail"], "safe"],
- [["remark"], "string"],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- "id" => "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;
- }
- }
|