| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <?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 MembersCard extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_members_card}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'is_enable', 'status', 'created_at', 'updated_at', 'child_num', 'child_expired_days','is_enable_virtual'], 'integer'],
- [['discount', 'child_discount'], 'number'],
- [['name'], 'string', 'max' => 100],
- [['background_url', 'member_limit','child_upgrade_links'], 'string', 'max' => 255],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'name' => 'Name',
- 'is_enable' => 'Is Enable',
- 'discount' => 'Discount',
- 'status' => 'Status',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- 'child_discount' => 'Child Discount',
- 'child_num' => 'Child Num',
- 'child_expired_days' => 'Child Expired Days',
- 'background_url' => 'Background Url',
- 'member_limit' => 'Member Limit',
- 'child_upgrade_links' => 'Child Upgrade Links',
- 'is_enable_virtual' => 'Is Enable Virtual',
- ];
- }
- 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;
- }
- }
- public static function search($params)
- {
- $query = self::find()
- ->where(['status' => StatusEnum::ENABLED, 'mall_id' => $params['mall_id'],'is_enable'=>1]);
- if (isset($params['keyword']) && !empty($params['keyword'])) {
- $query->andWhere(['or', ['like', 'name', $params['keyword']]]);
- }
- $list = $query->limit(20)->select('id,name')->asArray()->all();
- return $list;
- }
- }
|