| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- <?php
- namespace addons\Community\common\models;
- use addons\Community\common\enums\ConfigEnum;
- use common\enums\StatusEnum;
- use common\models\common\Region;
- use common\models\user\User;
- use Yii;
- use yii\db\ActiveQuery;
- use yii\helpers\Json;
- /**
- * This is the model class for table "qimall_addons_community_head_apply".
- *
- * @property int $id 主键
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at 创建时间
- * @property int $updated_at 修改时间
- * @property int $mall_id 所属商城
- * @property int $user_id 用户ID
- * @property string $name 自提点名称
- * @property string $intro 自提点简介
- * @property string $logo logo
- * @property string $license_pic 营业执照
- * @property string $id_card_pic 身份证照
- * @property string $contact_name 联系人姓名
- * @property string $contact_phone 联系人姓名
- * @property int $province_id 省份id
- * @property int $city_id 城市ID
- * @property int $district_id 地区id
- * @property string $street 详细地址
- * @property float $lng 经度
- * @property float $lat 纬度
- * @property string $area 省市区
- * @property int $submit_count 提交次数
- * @property int $check_count 审核次数
- * @property int $apply_status 审核次数
- * @property int $step 审核次数
- * @property int $is_home_delivery 是否提供送货上门服务
- */
- class CommunityHeadApply extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return 'qimall_addons_community_head_apply';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['status', 'created_at', 'updated_at', 'mall_id', 'user_id', 'province_id', 'city_id',
- 'district_id', 'submit_count', 'check_count', 'apply_status', 'step', 'is_home_delivery'], 'integer'],
- [['lng', 'lat'], 'number'],
- [['name', 'contact_name'], 'string', 'max' => 10],
- [['contact_phone'], 'string', 'max' => 11],
- [['intro', 'logo', 'license_pic', 'id_card_pic', 'street', 'area'], 'string', 'max' => 255],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'status' => 'Status',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- 'mall_id' => 'Mall ID',
- 'user_id' => 'User ID',
- 'name' => 'Name',
- 'intro' => 'Intro',
- 'logo' => 'Logo',
- 'license_pic' => 'License Pic',
- 'id_card_pic' => 'Id Card Pic',
- 'contact_name' => 'Contact Name',
- 'province_id' => 'Province ID',
- 'city_id' => 'City ID',
- 'district_id' => 'District ID',
- 'street' => 'Street',
- 'lng' => 'Lng',
- 'lat' => 'Lat',
- 'area' => 'Area',
- 'submit_count' => 'Submit Count',
- 'check_count' => 'Check Count',
- ];
- }
- /**
- * @return ActiveQuery
- */
- public function getUser(): ActiveQuery
- {
- return $this->hasOne(User::class, ['id' => 'user_id']);
- }
- /**
- * @return ActiveQuery
- */
- public function getCheck(): ActiveQuery
- {
- return $this->hasOne(CommunityHeadCheck::class, ['apply_id' => 'id']);
- }
- /**
- * @param CommunityHead $head
- * @param int $admin_id
- * @return void
- * @throws \Exception
- */
- public static function create(CommunityHead $head, int $admin_id)
- {
- $model = new CommunityHeadApply();
- $model->user_id = $head->user_id;
- $model->mall_id = $head->mall_id;
- $model->submit_count = 1;
- $district_name = Region::find()->where(['id' => $head->district_id])->select('name')->scalar();
- $area = $head->address;
- $street = $head->address;
- if (!empty($district_name)) {
- $index = strpos($head->address, $district_name);
- $d_len = strlen($district_name);
- $area = substr($area, 0, $index + $d_len);
- $street = substr($street, $index + $d_len);
- }
- $model->name = $head->name;
- $model->intro = $head->desc;
- $model->logo = $head->logo;
- $model->license_pic = $head->license_img;
- $model->id_card_pic = $head->idcard_img;
- $model->contact_name = $head->contacts;
- $model->contact_phone = $head->mobile;
- $model->province_id = $head->province_id;
- $model->city_id = $head->city_id;
- $model->district_id = $head->district_id;
- $model->street = $street; // 这里有问题
- $model->area = $area; // 这里有问题
- $model->lng = $head->longitude;
- $model->lat = $head->latitude;
- $model->is_home_delivery = $head->is_home_delivery;
- $model->apply_status = ConfigEnum::COMMUNITY_CHECK_STATUS_AGREE; // 修改为待审核
- if (!$model->save()) throw new \Exception($model->getErrorMessage());
- $checkModel = new CommunityHeadCheck();
- $checkModel->mall_id = $head->mall_id;
- $checkModel->apply_id = $model->id;
- $checkModel->admin_id = $admin_id;
- $checkModel->remark = "由后台管理员 [{$admin_id}] 直接创建";
- $checkModel->check_status = ConfigEnum::COMMUNITY_CHECK_STATUS_AGREE;
- if (!$checkModel->save()) throw new \Exception($checkModel->getErrorMessage());
- }
- }
|