| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- <?php
- namespace addons\SecondaryCard\common\models;
- use common\enums\StatusEnum;
- use common\models\base\BaseActiveRecord;
- use Yii;
- /**
- * This is the model class for table "qimall_addons_secondary_card_redemption_code".
- *
- * @property int $id
- * @property int $mall_id
- * @property int $user_id 会员id
- * @property string $code 兑换码
- * @property string $remarks 备注
- * @property int $secondary_card_id 次卡id
- * @property int $use_type 使用范围:0:全部店铺;1:指定店铺
- * @property int|null $is_use 状态:0:未使用;1:已使用
- * @property int $use_time 使用时间
- * @property string $order_no 兑换次卡号
- * @property int|null $status 状态[-1:删除;0:禁用;1启用;]
- * @property int $create_source_type 创建来源类型:0:平台;1:门店
- * @property int $create_source_id 创建来源id
- * @property int $created_at 创建时间
- * @property int $updated_at
- */
- class SecondaryCardRedemptionCode extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_secondary_card_redemption_code}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id'], 'required'],
- [['mall_id', 'user_id', 'secondary_card_id', 'use_type', 'is_use', 'use_time', 'status', 'created_at', 'updated_at',
- 'create_source_type', 'create_source_id',], 'integer'],
- [['code', 'remarks', 'order_no'], 'string', 'max' => 255],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'user_id' => '会员id',
- 'code' => '兑换码',
- 'remarks' => '备注',
- 'secondary_card_id' => '次卡id',
- 'use_type' => '使用范围:0:全部店铺;1:指定店铺',
- 'is_use' => '状态:0:未使用;1:已使用',
- 'use_time' => '使用时间',
- 'order_no' => '兑换次卡号',
- 'status' => '状态[-1:删除;0:禁用;1启用;]',
- 'create_source_type' => '创建来源类型:0:平台;1:门店',
- 'create_source_id' => '创建来源id',
- 'created_at' => '创建时间',
- 'updated_at' => 'Updated At',
- ];
- }
- public static function getExportFields()
- {
- return [
- 'code' => '兑换码',
- 'remarks' => '批次备注',
- 'is_use' => '状态',
- 'created_at' => '创建时间',
- 'use_time' => '使用时间',
- 'order_no' => '兑换次卡号',
- 'source' => '创建来源',
- ];
- }
- public function getSecondaryCard()
- {
- return $this->hasOne(SecondaryCard::class, ['id' => 'secondary_card_id']);
- }
- public function getSecondaryCardOrder()
- {
- return $this->hasOne(SecondaryCardOrder::class, ['order_no' => 'order_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;
- }
- }
- }
|