| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- <?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".
- *
- * @property int $id
- * @property int $mall_id
- * @property string $name 次卡名称
- * @property int $background_type 次卡背景类型,0:默认背景,1:自定义
- * @property string $background 次卡背景
- * @property string $font_color 字体颜色
- * @property int $total_redemption 累计兑卡张数
- * @property int $total_sales 累计售卡数
- * @property float $total_sales_price 累计售卡金额
- * @property int $sell_time_start 售卖开始时间
- * @property int $sell_time_end 售卖结束时间
- * @property int $expire_type 次卡有效期类型:1=购买时起N天内有效,2=指定有效期
- * @property string $begin_at 有效期开始时间
- * @property string $end_at 有效期结束时间
- * @property int $expire_day 有效天数,expire_type=1时
- * @property float|null $price 售价
- * @property float|null $original_price 原价
- * @property int|null $verifiable_times 可核销次数
- * @property int|null $max_times 最大开卡数
- * @property int|null $virtual_sales 虚拟销量
- * @property string|null $service 卡服务设置
- * @property int $reservation_type 是否需要预约,0:不需要,1:需要
- * @property int $reservation_model 预约模式:1:预约门店;2:预约服务人
- * @property int $reservation_service_type 服务方式:1:上门服务;2:到店服务;3:上门/到店
- * @property string $reservation_day 可预约日期:1-7对应周一至周日
- * @property int $reservation_time_type 可预约时间段类型:1:指定时间段;2:整天
- * @property string $reservation_time 可预约时间段
- * @property int $appointment_interval_duration 项目时间
- * @property int $reservation_cancel_type 预约取消:1:不允许取消;2:服务开始前N小时,取消并扣除m次可服务数
- * @property int $reservation_cancel_hour 服务开始前N小时
- * @property int $reservation_cancel_deduct 取消并扣除m次可服务数
- * @property int $reservation_limit_people 同时段可预约N人
- * @property int $reservation_limit_repeat 反复预约限制N次
- * @property int $refund_type 退款类型,0:未使用到期自动退,1:不允许退款,2:允许退款
- * @property int $limit_type 限购类型,0:不限开卡次数(用户可重复开卡,不限制领卡次数),1:有效期内限开卡次数
- * @property int $limit_times limit_type==1,次数,领取次数仅统计用户领卡的次数,不统计商家发卡
- * @property int $create_source_type 创建来源类型:0:平台;1:门店
- * @property int $create_source_id 创建来源id
- * @property int $is_on_sales 卡次状态:0:下架;1:正常
- * @property string|null $rule 使用规则
- * @property int $store_type 店铺类型:1:o2o门店
- * @property int $use_type 使用范围:0:全部店铺;1:指定店铺
- * @property int|null $status 状态[-1:删除;0:禁用;1启用;]
- * @property int $created_at 创建时间
- * @property int $updated_at
- * @property string $applet_code 微信小程序推广码
- */
- class SecondaryCard extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_secondary_card}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id'], 'required'],
- [['mall_id', 'background_type', 'total_redemption', 'total_sales', 'expire_type', 'expire_day', 'verifiable_times', 'max_times', 'virtual_sales', 'reservation_type', 'reservation_model',
- 'reservation_service_type', 'reservation_time_type', 'appointment_interval_duration', 'reservation_cancel_type', 'reservation_cancel_hour', 'reservation_cancel_deduct',
- 'reservation_limit_people', 'reservation_limit_repeat', 'refund_type', 'limit_type', 'limit_times', 'create_source_type', 'create_source_id', 'is_on_sales',
- 'store_type', 'use_type', 'status', 'created_at', 'updated_at',
- 'sell_time_start', 'sell_time_end',
- ], 'integer'],
- [['total_sales_price', 'price', 'original_price'], 'number'],
- [['service', 'rule'], 'string'],
- [['name', 'begin_at', 'end_at'], 'string', 'max' => 150],
- [['background', 'font_color', 'reservation_day', 'applet_code'], 'string', 'max' => 255],
- [['reservation_time'], 'string',],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'name' => '次卡名称',
- 'background_type' => '次卡背景类型,0:默认背景,1:自定义',
- 'font_color' => '字体颜色',
- 'background' => '次卡背景',
- 'total_redemption' => '累计兑卡张数',
- 'total_sales' => '累计售卡数',
- 'total_sales_price' => '累计售卡金额',
- 'sell_time_start' => '售卖开始时间',
- 'sell_time_end' => '售卖结束时间',
- 'expire_type' => '次卡有效期类型:1=购买时起N天内有效,2=指定有效期',
- 'begin_at' => '有效期开始时间',
- 'end_at' => '有效期结束时间',
- 'expire_day' => '有效天数,expire_type=1时',
- 'price' => '售价',
- 'original_price' => '原价',
- 'verifiable_times' => '可核销次数',
- 'max_times' => '最大开卡数',
- 'virtual_sales' => '虚拟销量',
- 'service' => '卡服务设置',
- 'reservation_type' => '是否需要预约,0:不需要,1:需要',
- 'reservation_model' => '预约模式:1:预约门店;2:预约服务人',
- 'reservation_service_type' => '服务方式:1:上门服务;2:到店服务;3:上门/到店',
- 'reservation_day' => '可预约日期:1-7对应周一至周日',
- 'reservation_time_type' => '可预约时间段类型:1:指定时间段;2:整天',
- 'reservation_time' => '可预约时间段',
- 'appointment_interval_duration' => '项目时间',
- 'reservation_cancel_type' => '预约取消:1:不允许取消;2:服务开始前N小时,取消并扣除m次可服务数',
- 'reservation_cancel_hour' => '服务开始前N小时',
- 'reservation_cancel_deduct' => '取消并扣除m次可服务数',
- 'reservation_limit_people' => '同时段可预约N人',
- 'reservation_limit_repeat' => '反复预约限制N次',
- 'refund_type' => '退款类型,0:未使用到期自动退,1:不允许退款,2:允许退款',
- 'limit_type' => '限购类型,0:不限开卡次数(用户可重复开卡,不限制领卡次数),1:有效期内限开卡次数',
- 'limit_times' => 'limit_type==1,次数,领取次数仅统计用户领卡的次数,不统计商家发卡',
- 'create_source_type' => '创建来源类型:0:平台;1:门店',
- 'create_source_id' => '创建来源id',
- 'is_on_sales' => '卡次状态:0:下架;1:正常',
- 'rule' => '使用规则',
- 'store_type' => '店铺类型:1:o2o门店',
- 'use_type' => '使用范围:0:全部店铺;1:指定店铺',
- 'status' => '状态[-1:删除;0:禁用;1启用;]',
- 'created_at' => '创建时间',
- 'updated_at' => 'Updated At',
- 'applet_code' => '微信小程序推广码',
- ];
- }
- 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('服务不存在或已删除');
- if ($model->create_source_type != $params['create_source_type']) {
- throw new \Exception('创建来源不一致,无法编辑');
- }
- } else {
- $model = new self();
- $model->loadDefaultValues();
- }
- if (empty($params['expire_day'])) $params['expire_day'] = 0;
- if (empty($params['sell_time_start'])) $params['sell_time_start'] = 0;
- if (empty($params['sell_time_end'])) $params['sell_time_end'] = 0;
- if (empty($params['limit_times'])) $params['limit_times'] = 0;
- 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;
- }
- }
- }
|