| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- <?php
- namespace addons\Happiness\common\models;
- use addons\Happiness\common\enums\HappinessEnum;
- use common\enums\StatusEnum;
- use common\models\user\User;
- use Yii;
- /**
- * This is the model class for table "qimall_addons_happiness_agent".
- *
- * @property int $id
- * @property int $user_id 用户ID
- * @property int $mall_id 商城ID
- * @property int $level 权重
- * @property int $status 状态
- * @property int $role 代理等级:1 省,2市,3区
- * @property int $district_id 区
- * @property int $province 省
- * @property int $city_id 市
- * @property int $parent_id 推广用户
- * @property string $region_name 区名称
- * @property int $created_at
- * @property int $updated_at
- */
- class HappinessAgent extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return 'qimall_addons_happiness_agent';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['user_id', 'mall_id', 'level', 'status', 'role', 'district_id', 'province_id', 'city_id', 'parent_id', 'created_at', 'updated_at'], 'integer'],
- [['level'], 'required'],
- [['region_name'], 'string', 'max' => 255],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'user_id' => 'User ID',
- 'mall_id' => 'Mall ID',
- 'level' => 'Level',
- 'status' => 'Status',
- 'role' => 'Role',
- 'district_id' => 'District_id ID',
- 'province_id' => 'Province ID',
- 'city_id' => 'City ID',
- 'parent_id' => 'Parent ID',
- 'region_name' => 'Region Name',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- public static function setData($params)
- {
- try {
- if (!empty($params['user_id'] && !empty($params['city_id']) && !empty($params['role'])&& $params['role']==HappinessEnum::AGENT_CITY)) {
- $model = self::findOne(['user_id' => $params['user_id'],'role'=>HappinessEnum::AGENT_CITY,'city_id'=>$params['city_id'], 'mall_id' => $params['mall_id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
- }
- else if(!empty($params['user_id']) && !empty($params['district_id']) && !empty($params['role'])&& $params['role']==HappinessEnum::AGENT_DISTRICT) {
- $model = self::findOne(['user_id' => $params['user_id'],'role'=>HappinessEnum::AGENT_DISTRICT, 'district_id' => $params['district_id'], 'mall_id' => $params['mall_id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
- }
- else if(!empty($params['id']))
- $model = self::findOne($params['id']);
- else {
- $model = new self();
- $model->loadDefaultValues();
- }
- if(!$model)
- {
- $model = new self();
- $model->loadDefaultValues();
- }
- if (!$model->load($params, '') || !$model->save()) {
- throw new \Exception($model->getErrorMessage());
- }
- return $model;
- } catch (\Exception $e) {
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- public function getUser()
- {
- return $this->hasOne(User::class, ['id' => 'user_id']);
- }
- public function getParent()
- {
- return $this->hasOne(User::class, ['id' => 'parent_id']);
- }
- }
|