SecondaryCard.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <?php
  2. namespace addons\SecondaryCard\common\models;
  3. use common\enums\StatusEnum;
  4. use common\models\base\BaseActiveRecord;
  5. use Yii;
  6. /**
  7. * This is the model class for table "qimall_addons_secondary_card".
  8. *
  9. * @property int $id
  10. * @property int $mall_id
  11. * @property string $name 次卡名称
  12. * @property int $background_type 次卡背景类型,0:默认背景,1:自定义
  13. * @property string $background 次卡背景
  14. * @property string $font_color 字体颜色
  15. * @property int $total_redemption 累计兑卡张数
  16. * @property int $total_sales 累计售卡数
  17. * @property float $total_sales_price 累计售卡金额
  18. * @property int $sell_time_start 售卖开始时间
  19. * @property int $sell_time_end 售卖结束时间
  20. * @property int $expire_type 次卡有效期类型:1=购买时起N天内有效,2=指定有效期
  21. * @property string $begin_at 有效期开始时间
  22. * @property string $end_at 有效期结束时间
  23. * @property int $expire_day 有效天数,expire_type=1时
  24. * @property float|null $price 售价
  25. * @property float|null $original_price 原价
  26. * @property int|null $verifiable_times 可核销次数
  27. * @property int|null $max_times 最大开卡数
  28. * @property int|null $virtual_sales 虚拟销量
  29. * @property string|null $service 卡服务设置
  30. * @property int $reservation_type 是否需要预约,0:不需要,1:需要
  31. * @property int $reservation_model 预约模式:1:预约门店;2:预约服务人
  32. * @property int $reservation_service_type 服务方式:1:上门服务;2:到店服务;3:上门/到店
  33. * @property string $reservation_day 可预约日期:1-7对应周一至周日
  34. * @property int $reservation_time_type 可预约时间段类型:1:指定时间段;2:整天
  35. * @property string $reservation_time 可预约时间段
  36. * @property int $appointment_interval_duration 项目时间
  37. * @property int $reservation_cancel_type 预约取消:1:不允许取消;2:服务开始前N小时,取消并扣除m次可服务数
  38. * @property int $reservation_cancel_hour 服务开始前N小时
  39. * @property int $reservation_cancel_deduct 取消并扣除m次可服务数
  40. * @property int $reservation_limit_people 同时段可预约N人
  41. * @property int $reservation_limit_repeat 反复预约限制N次
  42. * @property int $refund_type 退款类型,0:未使用到期自动退,1:不允许退款,2:允许退款
  43. * @property int $limit_type 限购类型,0:不限开卡次数(用户可重复开卡,不限制领卡次数),1:有效期内限开卡次数
  44. * @property int $limit_times limit_type==1,次数,领取次数仅统计用户领卡的次数,不统计商家发卡
  45. * @property int $create_source_type 创建来源类型:0:平台;1:门店
  46. * @property int $create_source_id 创建来源id
  47. * @property int $is_on_sales 卡次状态:0:下架;1:正常
  48. * @property string|null $rule 使用规则
  49. * @property int $store_type 店铺类型:1:o2o门店
  50. * @property int $use_type 使用范围:0:全部店铺;1:指定店铺
  51. * @property int|null $status 状态[-1:删除;0:禁用;1启用;]
  52. * @property int $created_at 创建时间
  53. * @property int $updated_at
  54. * @property string $applet_code 微信小程序推广码
  55. */
  56. class SecondaryCard extends BaseActiveRecord
  57. {
  58. /**
  59. * {@inheritdoc}
  60. */
  61. public static function tableName()
  62. {
  63. return '{{%addons_secondary_card}}';
  64. }
  65. /**
  66. * {@inheritdoc}
  67. */
  68. public function rules()
  69. {
  70. return [
  71. [['mall_id'], 'required'],
  72. [['mall_id', 'background_type', 'total_redemption', 'total_sales', 'expire_type', 'expire_day', 'verifiable_times', 'max_times', 'virtual_sales', 'reservation_type', 'reservation_model',
  73. 'reservation_service_type', 'reservation_time_type', 'appointment_interval_duration', 'reservation_cancel_type', 'reservation_cancel_hour', 'reservation_cancel_deduct',
  74. 'reservation_limit_people', 'reservation_limit_repeat', 'refund_type', 'limit_type', 'limit_times', 'create_source_type', 'create_source_id', 'is_on_sales',
  75. 'store_type', 'use_type', 'status', 'created_at', 'updated_at',
  76. 'sell_time_start', 'sell_time_end',
  77. ], 'integer'],
  78. [['total_sales_price', 'price', 'original_price'], 'number'],
  79. [['service', 'rule'], 'string'],
  80. [['name', 'begin_at', 'end_at'], 'string', 'max' => 150],
  81. [['background', 'font_color', 'reservation_day', 'applet_code'], 'string', 'max' => 255],
  82. [['reservation_time'], 'string',],
  83. ];
  84. }
  85. /**
  86. * {@inheritdoc}
  87. */
  88. public function attributeLabels()
  89. {
  90. return [
  91. 'id' => 'ID',
  92. 'mall_id' => 'Mall ID',
  93. 'name' => '次卡名称',
  94. 'background_type' => '次卡背景类型,0:默认背景,1:自定义',
  95. 'font_color' => '字体颜色',
  96. 'background' => '次卡背景',
  97. 'total_redemption' => '累计兑卡张数',
  98. 'total_sales' => '累计售卡数',
  99. 'total_sales_price' => '累计售卡金额',
  100. 'sell_time_start' => '售卖开始时间',
  101. 'sell_time_end' => '售卖结束时间',
  102. 'expire_type' => '次卡有效期类型:1=购买时起N天内有效,2=指定有效期',
  103. 'begin_at' => '有效期开始时间',
  104. 'end_at' => '有效期结束时间',
  105. 'expire_day' => '有效天数,expire_type=1时',
  106. 'price' => '售价',
  107. 'original_price' => '原价',
  108. 'verifiable_times' => '可核销次数',
  109. 'max_times' => '最大开卡数',
  110. 'virtual_sales' => '虚拟销量',
  111. 'service' => '卡服务设置',
  112. 'reservation_type' => '是否需要预约,0:不需要,1:需要',
  113. 'reservation_model' => '预约模式:1:预约门店;2:预约服务人',
  114. 'reservation_service_type' => '服务方式:1:上门服务;2:到店服务;3:上门/到店',
  115. 'reservation_day' => '可预约日期:1-7对应周一至周日',
  116. 'reservation_time_type' => '可预约时间段类型:1:指定时间段;2:整天',
  117. 'reservation_time' => '可预约时间段',
  118. 'appointment_interval_duration' => '项目时间',
  119. 'reservation_cancel_type' => '预约取消:1:不允许取消;2:服务开始前N小时,取消并扣除m次可服务数',
  120. 'reservation_cancel_hour' => '服务开始前N小时',
  121. 'reservation_cancel_deduct' => '取消并扣除m次可服务数',
  122. 'reservation_limit_people' => '同时段可预约N人',
  123. 'reservation_limit_repeat' => '反复预约限制N次',
  124. 'refund_type' => '退款类型,0:未使用到期自动退,1:不允许退款,2:允许退款',
  125. 'limit_type' => '限购类型,0:不限开卡次数(用户可重复开卡,不限制领卡次数),1:有效期内限开卡次数',
  126. 'limit_times' => 'limit_type==1,次数,领取次数仅统计用户领卡的次数,不统计商家发卡',
  127. 'create_source_type' => '创建来源类型:0:平台;1:门店',
  128. 'create_source_id' => '创建来源id',
  129. 'is_on_sales' => '卡次状态:0:下架;1:正常',
  130. 'rule' => '使用规则',
  131. 'store_type' => '店铺类型:1:o2o门店',
  132. 'use_type' => '使用范围:0:全部店铺;1:指定店铺',
  133. 'status' => '状态[-1:删除;0:禁用;1启用;]',
  134. 'created_at' => '创建时间',
  135. 'updated_at' => 'Updated At',
  136. 'applet_code' => '微信小程序推广码',
  137. ];
  138. }
  139. public static function setData(array $params)
  140. {
  141. try {
  142. if (!empty($params['id'])) {
  143. $model = self::findOne(['mall_id' => $params['mall_id'], 'id' => $params['id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
  144. if (empty($model)) throw new \Exception('服务不存在或已删除');
  145. if ($model->create_source_type != $params['create_source_type']) {
  146. throw new \Exception('创建来源不一致,无法编辑');
  147. }
  148. } else {
  149. $model = new self();
  150. $model->loadDefaultValues();
  151. }
  152. if (empty($params['expire_day'])) $params['expire_day'] = 0;
  153. if (empty($params['sell_time_start'])) $params['sell_time_start'] = 0;
  154. if (empty($params['sell_time_end'])) $params['sell_time_end'] = 0;
  155. if (empty($params['limit_times'])) $params['limit_times'] = 0;
  156. if (!$model->load($params, '')) throw new \Exception($model->getErrorMessage());
  157. if (!$model->save()) throw new \Exception($model->getErrorMessage());
  158. return $model;
  159. } catch (\Exception $e) {
  160. self::$static_error = $e->getMessage();
  161. return false;
  162. }
  163. }
  164. }