| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- <?php
- namespace addons\Community\common\models;
- use common\enums\StatusEnum;
- use common\models\base\BaseActiveRecord;
- use common\models\user\User;
- use Yii;
- /**
- * This is the model class for table "qimall_addons_community_head".
- *
- * @property int $id
- * @property int $mall_id
- * @property int $user_id 绑定会员id
- * @property string $contacts 联系人姓名
- * @property string $mobile 联系人手机号
- * @property string $name 名称
- * @property string $desc 简介
- * @property string $logo logo
- * @property string $license_img 营业执照
- * @property string $idcard_img 身份证
- * @property int|null $province_id 省
- * @property int|null $city_id 市
- * @property int|null $district_id 区
- * @property string $address 详细地址
- * @property string $longitude 经度
- * @property string $latitude 维度
- * @property int $check_status 审核状态:0:待审核;1:已通过;2:未通过
- * @property string $check_remark 审核备注
- * @property int $status 状态[0禁用 1启用 -1删除]
- * @property int $created_at 创建时间
- * @property int $updated_at 修改时间
- * @property int $is_home_delivery 是否提供送货上门服务
- * @property User $user
- */
- class CommunityHead extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_community_head}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [[
- 'mall_id', 'user_id', 'province_id', 'city_id', 'district_id', 'check_status',
- 'status', 'created_at', 'updated_at', 'is_home_delivery'
- ], 'integer'],
- [['contacts', 'name', 'desc', 'logo', 'address', 'longitude', 'latitude', 'check_remark', 'idcard_img', 'license_img'], 'string', 'max' => 255],
- [['setting'], 'string'],
- [['mobile'], 'string', 'max' => 11],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'user_id' => '绑定会员id',
- 'contacts' => '联系人姓名',
- 'mobile' => '联系人手机号',
- 'name' => '名称',
- 'desc' => '简介',
- 'logo' => 'logo',
- 'license_img' => '营业执照',
- 'province_id' => '省',
- 'city_id' => '市',
- 'district_id' => '区',
- 'address' => '详细地址',
- 'longitude' => '经度',
- 'latitude' => '维度',
- 'check_status' => '审核状态:0:待审核;1:已通过;2:未通过',
- 'check_remark' => '审核备注',
- 'status' => '状态[0禁用 1启用 -1删除]',
- 'created_at' => '创建时间',
- 'updated_at' => '修改时间',
- ];
- }
- public function getUser()
- {
- return $this->hasOne(User::class, ['id' => 'user_id']);
- }
- public static function setData(array $params, int $admin_id = 0, bool $is_from_apply_check = false)
- {
- if (!$is_from_apply_check) {
- $transaction = Yii::$app->db->beginTransaction();
- }
- try {
- $is_new = true;
- 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('自提点不存在或已删除');
- // 判断是否需要修改用户
- if ($model->user_id != $params['user_id']) {
- CommunityHeadApply::updateAll(['user_id' => $params['user_id']],
- ['user_id' => $model->user_id, 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
- }
- $is_new = false;
- } else {
- $model = new self();
- $model->loadDefaultValues();
- }
- if (!$model->load($params, '') || !$model->save()) {
- throw new \Exception($model->getErrorMessage());
- }
- // 查询是否有记录
- $has = CommunityHeadApply::find()
- ->select('id')
- ->where(['user_id' => $model->user_id, 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]])
- ->one();
- if ($is_new || empty($has)) {
- CommunityGoods::setGoodsSetting($params['mall_id'], $model->id);
- if (!$is_from_apply_check) { // 如果不是从审核过来的,且是新的数据那么就需要同步至申请表
- // 需要将数据存储到申请表
- CommunityHeadApply::create($model, $admin_id);
- }
- }
- if (!empty($transaction)) $transaction->commit();
- return $model;
- } catch (\Exception $e) {
- if (!empty($transaction)) $transaction->rollBack();
- self::$static_error = $e->getMessage() . $e->getLine() . $e->getFile();
- return false;
- }
- }
- public static function getDataOne($params)
- {
- return self::find()->where($params)->asArray()->one();
- }
- }
|