| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- <?php
- namespace addons\Area\common\models;
- use common\enums\StatusEnum;
- use common\models\base\BaseActiveRecord;
- use common\models\common\Region;
- use common\models\user\Town;
- use common\models\user\User;
- use Yii;
- /**
- * This is the model class for table "qimall_addons_area_apply".
- *
- * @property int $id
- * @property int $mall_id 商城id
- * @property int $user_id 会员id
- * @property string $address 地址
- * @property string $realname 真实姓名
- * @property string $mobile 手机号码
- * @property int $level 区域等级;1镇级;2区级;3市级;4省级;
- * @property int $province_id 省id
- * @property int $city_id 市id
- * @property int $district_id 区id
- * @property int $town_id 镇id
- * @property int $community_id 小区id
- * @property string $marks 备注
- * @property int $check_status 0未审核;1审核通过;2不通过
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at 创建时间
- * @property int $updated_at 修改时间
- * @property int $agent_id 修改时间
- */
- class AreaApply extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_area_apply}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'user_id', 'level', 'province_id', 'city_id', 'district_id', 'town_id', 'check_status', 'status',
- 'created_at', 'updated_at', 'community_id', 'agent_id', 'is_refund', 'refund_time', 'order_id'], 'integer'],
- [['level'], 'required'],
- [['address', 'marks'], 'string', 'max' => 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;
- }
- }
- }
|