| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- namespace addons\ElectronCoupon\common\models;
- use Yii;
- /**
- * This is the model class for table "{{%addons_electron_coupon_give_log}}".
- *
- * @property int $id
- * @property int $mall_id 商城id
- * @property int $e_coupon_id 电子券id
- * @property int $user_id 接收者id
- * @property int $give_user_id 赠送者id
- * @property string $e_coupon_name 电子券名称
- * @property int $amount 赠送数量
- * @property int $is_proper 是否专有者
- * @property int $proper_id 专有者id
- * @property int $created_at
- * @property int $updated_at
- * @property int|null $status 状态[-1:删除;0:禁用;1启用]
- */
- class ElectronCouponGiveLog extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_electron_coupon_give_log}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'e_coupon_id', 'user_id', 'give_user_id'], 'required'],
- [['mall_id', 'e_coupon_id', 'user_id', 'give_user_id', 'amount', 'is_proper', 'proper_id', 'created_at', 'updated_at', 'status'], 'integer'],
- [['e_coupon_name'], 'string', 'max' => 255],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城id',
- 'e_coupon_id' => '电子券id',
- 'user_id' => '接收者id',
- 'give_user_id' => '赠送者id',
- 'e_coupon_name' => '电子券名称',
- 'amount' => '赠送数量',
- 'is_proper' => '是否专有者',
- 'proper_id' => '专有者id',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- 'status' => '状态[-1:删除;0:禁用;1启用]',
- ];
- }
- /**
- * 数据设置
- */
- public static function setData(array $params)
- {
- try{
- if (!isset($params['mall_id']) || empty($params['mall_id'])) throw new Exception('缺少商城ID');
- $mall_id = $params['mall_id'];
- if (isset($params['id']) && !empty($params['id'])) {
- $model = self::findOne(['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){
- self::setStaticError($e->getMessage());
- return false;
- }
- }
- }
|