255], [['realname'], 'string', 'max' => 45], [['mobile'], 'string', 'max' => 11], [['pay_price'], 'number'], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'mall_id' => '商城id', 'user_id' => '会员id', 'address' => '地址', 'realname' => '真实姓名', 'mobile' => '手机号码', 'level' => '区域等级;1镇级;2区级;3市级;4省级;', 'province_id' => '省id', 'city_id' => '市id', 'district_id' => '区id', 'town_id' => '镇id', 'marks' => '备注', 'check_status' => '0未审核;1审核通过;2不通过', 'status' => '状态[-1:删除;0:禁用;1启用]', 'created_at' => '创建时间', 'updated_at' => '修改时间', ]; } public function getUser() { return $this->hasOne(User::class, ['id' => 'user_id']); } public static function setData(array $params) { try { if (!empty($params['id'])) { $model = self::findOne(['mall_id' => $params['mall_id'], 'id' => $params['id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]); if (empty($model)) throw new \Exception('服务不存在或已删除'); } else { $model = new self(); $model->loadDefaultValues(); } $region_id_arr = []; if (!empty($params['province_id'])) $region_id_arr[] = $params['province_id']; if (!empty($params['city_id'])) $region_id_arr[] = $params['city_id']; if (!empty($params['district_id'])) $region_id_arr[] = $params['district_id']; $address = ''; $region_list = Region::lists(['where' => [['id' => $region_id_arr]], 'select' => 'id,name', 'order' => 'id asc']); foreach ($region_list as $item) { $address .= $item['name']; } if (!empty($params['town_id'])) { $town = Town::getOne([['id' => $params['town_id']]], true, [], false, 'id,name'); if (!empty($town['name'])) $address .= $town['name']; } if (!empty($params['community_id'])) { $community_name = AreaCommunity::find()->where(['id' => $params['community_id']]) ->andWhere(['status' => StatusEnum::ENABLED])->select('community_name')->scalar(); if (!empty($community_name)) $address .= $community_name; } $params['address'] = $address; if (!$model->load($params, '')) throw new \Exception($model->getErrorMessage()); if (!$model->save()) throw new \Exception($model->getErrorMessage()); return $model; } catch (\Exception $e) { self::$static_error = $e->getMessage(); return false; } } /** * @desc:审核 * @Author: hua * @Date: 2022/1/21 * @Time: 14:40 * @Copyright: copyright (c) 2021 广东七件事集团 * @param $params * @return bool */ public static function apply($params) { $t = Yii::$app->db->beginTransaction(); try { $apply_model = AreaApply::findOne(['id' => $params['id']]); if ($params['check_status'] == 1) { $apply_arr = $apply_model->toArray(); unset($apply_arr['id']); unset($params['id']); $new_params = array_merge($params, $apply_arr); $new_params['status'] = StatusEnum::ENABLED; $res = AreaAgent::setData($new_params); if ($res == false) throw new \Exception(AreaAgent::getStaticError()); } $apply_model->check_status = $params['check_status']; $apply_model->marks = $params['marks']; $res = $apply_model->save(); if ($res == false) throw new \Exception($apply_model::getStaticError()); $t->commit(); return true; } catch (\Exception $e) { $t->rollBack(); self::$static_error = $e->getMessage(); return false; } } }