| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- <?php
- namespace addons\IssueCoupons\common\models;
- use common\models\user\User;
- use Yii;
- use yii\db\Exception;
- /**
- * This is the model class for table "{{%addons_issue_coupons_user}}".
- *
- * @property int $id
- * @property int|null $rule_id 规则ID
- * @property int $user_id 会员ID
- * @property int $mall_id 商城id
- * @property int $created_at
- * @property int $updated_at
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property float|null $number 金额
- * @property int $grant_object 发放对象:1:全部会员 2:会员等级 3:会员标签 4:会员id 5:指定区域
- * @property string $grant_object_content 对象内容
- */
- class IssueCouponsUser extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_issue_coupons_user}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['rule_id', 'user_id', 'mall_id', 'created_at', 'updated_at', 'status', 'grant_object'], 'integer'],
- [['user_id', 'mall_id'], 'required'],
- [['number'], 'number'],
- [['grant_object_content'], 'string'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'rule_id' => '规则ID',
- 'user_id' => '会员ID',
- 'mall_id' => '商城id',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- 'status' => '状态[-1:删除;0:禁用;1启用]',
- 'number' => '金额',
- 'grant_object' => '发放对象:1:全部会员 2:会员等级 3:会员标签 4:会员id 5:指定区域',
- 'grant_object_content' => '对象内容',
- ];
- }
- /**
- * 保存数据
- * @Author: ltm
- * @DateTime: 2022/6/28 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'];
- $model = new self();
- $model->loadDefaultValues();
- $model->mall_id = $mall_id; //var_dump($params);
- // 将内容转为json字符串
- if(!$model->load($params,'') || !$model->save()) throw new Exception($model->getErrorMessage());
- return $model;
- }catch(\Exception $e){
- self::setStaticError($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');
- }
- public function getRule()
- {
- return $this->hasOne(IssueCouponsRule::class, ['id' => 'rule_id']);
- }
- }
|