| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <?php
- namespace addons\Recommen\common\models;
- use common\models\user\User;
- use Yii;
- use yii\db\Exception;
- /**
- * This is the model class for table "{{%addons_recommen_reward}}".
- *
- * @property int $id
- * @property int|null $active_id 活动ID
- * @property int|null $mall_id 商城ID
- * @property int|null $user_id 会员ID
- * @property string|null $be_reward 被推荐人奖励
- * @property string|null $reward 推荐人奖励内容
- * @property int|null $status 状态[-1:删除;0:禁用;1启用]
- * @property int|null $created_at
- * @property int|null $updated_at
- * @property int $index
- */
- class RecommenReward extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_recommen_reward}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['active_id','be_reward', 'mall_id', 'user_id', 'status', 'created_at', 'updated_at', 'index'], 'integer'],
- [['reward'], 'string'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'active_id' => '活动ID',
- 'mall_id' => '商城ID',
- 'user_id' => '会员ID',
- 'be_reward' => '被推荐人奖励',
- 'reward' => '推荐人奖励内容',
- 'status' => '状态[-1:删除;0:禁用;1启用]',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- /**
- * 保存数据
- * @Author: ltm
- * @DateTime: 2022/5/16 0022 17:13
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param array $params
- * @return string
- */
- public static function setData(array $params){
- try{
- $model = new self();
- $model->loadDefaultValues();
- $model->mall_id = $params['mall_id'];
- $params['reward'] = json_encode($params['reward'], JSON_UNESCAPED_UNICODE);
- if(!$model->load($params,'') || !$model->save()){
- throw new Exception($model->getErrorMessage());
- }
- return $model;
- }catch(\Exception $e){
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- /**
- * 关联用户信息
- * @Author:ltm
- * @DateTime: 2022/5/6 0022 17:13
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return \yii\db\ActiveQuery
- */
- public function getUser()
- {
- return $this->hasOne(User::class, ['id' => 'user_id'])->select('id,nickname,username,mobile,avatar_url');
- }
- /**
- * 关联活动信息
- * @Author:ltm
- * @DateTime: 2022/5/6 0022 17:13
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return \yii\db\ActiveQuery
- */
- public function getRecommen()
- {
- return $this->hasOne(Recommen::class, ['id' => 'active_id']);
- }
- }
|