| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285 |
- <?php
- namespace addons\OperationCenter\common\models;
- use Yii;
- /**
- * This is the model class for table "{{%addons_operation_center_apply_list}}".
- *
- * @property int $id
- * @property int $mall_id 商城ID
- * @property int $user_id 用户ID
- * @property int $level 申请等级
- * @property string|null $name 姓名
- * @property string|null $mobile 手机号
- * @property string|null $center_name 运营中心名称
- * @property string|null $idcard_front 身份证正面
- * @property string|null $idcard_reverse 身份证反面
- * @property string|null $operation_license 运营执照
- * @property string|null $logo logo
- * @property int|null $province_id 省份ID
- * @property string|null $province 省份
- * @property int|null $city_id 城市ID
- * @property string|null $city 城市
- * @property int|null $district_id 县区ID
- * @property string|null $district 县区
- * @property int|null $town_id 街镇ID
- * @property string|null $town 街镇
- * @property string|null $operation_address 详细地址
- * @property int $status 状态
- * @property string|null $reject_content 驳回理由
- * @property int $apply_at 审核时间
- * @property int $deleted_at
- * @property int $updated_at
- * @property int $created_at
- */
- class ApplyList extends BaseActiveRecord
- {
- /**
- * 申请中
- */
- const APPLYING = 1;
- /**
- * 已通过
- */
- const PASSED = 2;
- /**
- * 已驳回
- */
- const REJECTED = 3;
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_operation_center_apply_list}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'user_id', 'level'], 'required'],
- [['mall_id', 'user_id', 'level', 'province_id', 'city_id', 'district_id', 'town_id', 'status', 'apply_at', 'deleted_at', 'updated_at', 'created_at'], 'integer'],
- [['name', 'mobile', 'center_name'], 'string', 'max' => 32],
- [['idcard_front', 'idcard_reverse', 'operation_license', 'logo', 'province', 'city', 'district', 'town', 'operation_address', 'reject_content'], 'string', 'max' => 255],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'user_id' => 'User ID',
- 'level' => 'Level',
- 'name' => 'Name',
- 'mobile' => 'Mobile',
- 'center_name' => 'Center Name',
- 'idcard_front' => 'Idcard Front',
- 'idcard_reverse' => 'Idcard Reverse',
- 'operation_license' => 'Operation License',
- 'logo' => 'Logo',
- 'province_id' => 'Province ID',
- 'province' => 'Province',
- 'city_id' => 'City ID',
- 'city' => 'City',
- 'district_id' => 'District ID',
- 'district' => 'District',
- 'town_id' => 'Town ID',
- 'town' => 'Town',
- 'operation_address' => 'Operation Address',
- 'status' => 'Status',
- 'reject_content' => 'Reject Content',
- 'apply_at' => 'Apply At',
- 'deleted_at' => 'Deleted At',
- 'updated_at' => 'Updated At',
- 'created_at' => 'Created At',
- ];
- }
- /**
- * @return ActiveQueryInterface the relational query object.
- */
- public function getUser()
- {
- return $this->hasOne(MallUser::class, ['id' => 'user_id']);
- }
- /**
- * @return ActiveQueryInterface the relational query object.
- */
- public function getCenter()
- {
- return $this->hasOne(UserCenter::class, ['user_id' => 'user_id']);
- }
- /**
- * 添加申请记录
- *
- * @param integer $user_id
- * @param integer $mall_id
- * @param array $array
- * @return true|static
- */
- public static function addApplyList(
- int $user_id,
- int $mall_id,
- array $data
- )
- {
- $model = new static;
- $data = array_merge($data, compact('user_id', 'mall_id'), [
- 'status' => static::APPLYING, 'level' => 0
- ]);
- $model->load($data, '');
- return $model->save();
- }
- /**
- * 是否已经申请或者已经通过
- *
- * @param integer $user_id
- * @return boolean|static
- */
- public static function hasApplyOrPassByUserId(int $user_id)
- {
- $one = static::find()
- ->andWhere(
- [
- 'user_id' => $user_id,
- 'status' => [
- static::APPLYING, static::PASSED
- ]
- ]
- )
- ->select(['id', 'status', 'user_id'])
- ->orderBy('id desc')
- ->one();
- return empty($one) ? false : $one;
- }
- /**
- * 获取申请状态
- *
- * @param integer $user_id
- * @return static|int
- */
- public static function getApplyStatus(int $user_id)
- {
- return static::find()
- ->select(['id', 'user_id', 'status', 'reject_content'])
- ->andWhere(['user_id' => $user_id])
- ->orderBy('id desc')
- ->one() ?? 0;
- }
- /**
- * 通过名称搜索ID
- *
- * @param integer $mall_id
- * @param string $name
- * @return array
- */
- public static function getUserIdByName(int $mall_id, string $name)
- {
- return static::find()
- ->andWhere(['mall_id' => $mall_id])
- ->andWhere(['like', 'name', $name])
- ->select(['user_id'])
- ->column();
- }
- /**
- * 通过名称搜索ID
- *
- * @param integer $mall_id
- * @param string $mobile
- * @return array
- */
- public static function getUserIdByMobile(int $mall_id, string $mobile)
- {
- return static::find()
- ->andWhere(['mall_id' => $mall_id])
- ->andWhere(['like', 'mobile', $mobile])
- ->select(['user_id'])
- ->column();
- }
- /**
- * 通过申请中详情
- *
- * @param integer $mall_id
- * @param integer $id
- * @return static|null
- */
- public static function getApplyingById(int $mall_id, int $id)
- {
- return static::find()
- ->andWhere(['mall_id' => $mall_id, 'id' => $id, 'status' => static::APPLYING])
- ->one();
- }
-
- /**
- * 通过
- *
- * @param Level $level
- * @return boolean
- */
- public function pass(Level $level)
- {
- $this->level = $level->id;
- $this->apply_at = time();
- $this->status = static::PASSED;
- return $this->save();
- }
- /**
- * 驳回
- *
- * @param string $content
- * @return boolean
- */
- public function reject(string $content = '')
- {
- $this->status = static::REJECTED;
- $this->reject_content = $content;
- return $this->save();
- }
- /**
- * 获取地址
- *
- * @return string
- */
- public function getOperationAddress()
- {
- return $this->province
- . $this->city
- . $this->district
- . $this->town
- . $this->operation_address;
- }
- /**
- * 是否通过后被删除运营中心
- *
- * @return boolean
- */
- public function isPassedButDelete()
- {
- return ($this->status == static::PASSED && empty($this->center));
- }
- }
|