| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?php
- namespace addons\MembersCard\common\models;
- use common\enums\StatusEnum;
- use Yii;
- /**
- * This is the model class for table "{{%addons_members_card}}".
- *
- * @property int $id
- * @property int $mall_id 商城ID
- * @property string $name 会员卡名称
- * @property int $is_enable 是否启用 0 否 1 是
- * @property float $discount 折扣
- * @property int|null $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at 创建时间
- * @property int $updated_at 修改时间
- * @property float $child_discount 子卡折扣
- * @property int $child_num 子卡数量
- * @property int $child_expired_days 子卡有效期
- * @property string $background_url 会员卡背景图
- * @property string $member_limit 会员权限
- */
- class MembersCardGive extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_members_card_give}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id','status', 'created_at', 'updated_at', 'child_num', 'user_id','parent_card_id','expired_at','card_id','is_recycle','recycle_at','receive_at','child_expired_days','card_no'], 'integer'],
- [['discount','child_discount'], 'number'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'discount' => 'Discount',
- 'status' => 'Status',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- 'child_num' => 'Child Num',
- 'user_id' => 'user id',
- 'parent_card_id' => 'parent card id',
- 'expired_at' => 'expired at',
- 'card_id' => 'card id',
- 'is_recycle' => 'is recycle',
- 'recycle_at' => 'recycle at',
- 'receive_at' => 'receive at',
- 'child_discount' => 'child discount',
- 'child_expired_days' => 'child expired days',
- 'card_no' => 'card no',
- ];
- }
- public static function setData(array $params)
- {
- try {
- if (!empty($params['id'])) {
- $model = self::findOne(['mall_id' => $params['mall_id'], 'id' => $params['id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
- if (empty($model)) throw new \Exception('数据不存在或已删除');
- } else {
- $model = new self();
- $model->loadDefaultValues();
- }
- if (!$model->load($params, '')) throw new \Exception($model->getErrorMessage());
- if (!$model->save()) throw new \Exception($model->getErrorMessage());
- return $model;
- } catch (\Exception $e) {
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- }
|