| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <?php
- namespace addons\Pk\common\models;
- use common\enums\StatusEnum;
- use common\models\user\User;
- use Yii;
- /**
- * This is the model class for table "%addons_pk_invite_log".
- *
- * @property int $id
- * @property int $activity_id 活动ID
- * @property int $share_user_id 分享者用户ID
- * @property int $mall_id 商城ID
- * @property int $team_id 战队ID
- * @property int $invitee_id 被邀请者ID
- * @property int $activity_type 类型【1 个人PK 2战队PK】
- * @property string $year 年
- * @property string $month 月
- * @property string $date 日
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at 创建时间
- * @property int $updated_at 更新时间
- */
- class PkInviteLog extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_pk_invite_log}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['activity_id', 'share_user_id', 'mall_id', 'team_id', 'invitee_id', 'activity_type', 'status', 'created_at', 'updated_at'], 'integer'],
- [['year', 'month', 'date'], 'required'],
- [['year'], 'string', 'max' => 4],
- [['month', 'date'], 'string', 'max' => 2],
- ];
- }
- public function getUser()
- {
- return $this->hasOne(User::class, ['id' => 'invitee_id'])->select('id,mobile,nickname,avatar_url,parent_id,username');
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'activity_id' => 'Activity ID',
- 'share_user_id' => 'Share User ID',
- 'mall_id' => 'Mall ID',
- 'team_id' => 'Team ID',
- 'invitee_id' => 'Invitee ID',
- 'activity_type' => 'Activity Type',
- 'year' => 'Year',
- 'month' => 'Month',
- 'date' => 'Date',
- 'status' => 'Status',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- /**
- * 保存数据
- * @Author: ltm
- * @DateTime: 2022/6/8 0015 9:26
- * @Copyright: copyright (c) 2021
- * @param $mall_id
- * @param array $params
- * @return Rebate|bool
- */
- public static function setData(array $params){
- try{
- $mall_id = $params['mall_id'];
- if(!empty($params['id'])){
- $model = self::findOne(['and',['id' => $params['id'],'mall_id' => $mall_id],['<>','status', StatusEnum::ENABLED]]);
- if(empty($model)) throw new \Exception('活动不存在或已删除');
- }else{
- $model = new self();
- $model->loadDefaultValues();
- $model->mall_id = $mall_id;
- }
- if(!$model->load($params,'') || !$model->save()) throw new Exception($model->getErrorMessage());
- return $model;
- }catch(\Exception $e){ var_dump($e->getMessage());
- self::setStaticError($e->getMessage());
- return false;
- }
- }
- }
|