123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <?php
- namespace app\common\model\lottery;
- use think\Model;
- use traits\model\SoftDelete;
- use app\common\Enum\LotteryEnum;
- /**
- * 抽奖奖品模型
- */
- class LotteryPrize extends Model
- {
- use SoftDelete;
- // 表名
- protected $table = 'shop_lottery_prize';
-
- // 开启自动写入时间戳字段
- protected $autoWriteTimestamp = 'int';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = 'updatetime';
- protected $deleteTime = 'deletetime';
- // 追加属性
- protected $append = [
- 'type_text',
- 'deliver_type_text',
- 'exchange_codes_list',
- 'used_codes_list'
- ];
- /**
- * 关联活动
- */
- public function activity()
- {
- return $this->belongsTo('LotteryActivity', 'activity_id');
- }
- /**
- * 关联商品
- */
- public function goods()
- {
- return $this->belongsTo('app\common\model\Goods', 'goods_id');
- }
- /**
- * 关联商品SKU
- */
- public function goodsSku()
- {
- return $this->belongsTo('app\common\model\Sku', 'goods_sku_id');
- }
- /**
- * 关联优惠券
- */
- public function coupon()
- {
- return $this->belongsTo('app\common\model\Coupon', 'coupon_id');
- }
- /**
- * 获取奖品类型文本
- */
- public function getTypeTextAttr($value, $data)
- {
- return LotteryEnum::getPrizeTypeText($data['type']);
- }
- /**
- * 获取发放方式文本
- */
- public function getDeliverTypeTextAttr($value, $data)
- {
- $types = LotteryEnum::getDeliverTypeMap();
- return isset($types[$value]) ? $types[$value] : '未知';
- }
- /**
- * 获取兑换码列表
- */
- public function getExchangeCodesListAttr($value, $data)
- {
- return !empty( $value ) ? json_decode( $value, true) : [];
- }
- /**
- * 设置兑换码列表
- */
- public function setExchangeCodesAttr($value)
- {
- return is_array($value) ? json_encode($value) : $value;
- }
- /**
- * 获取已使用兑换码列表
- */
- public function getUsedCodesListAttr($value, $data)
- {
- return !empty( $value ) ? json_decode( $value, true) : [];
- }
- /**
- * 设置已使用兑换码列表
- */
- public function setUsedCodesAttr($value)
- {
- return is_array($value) ? json_encode($value) : $value;
- }
- }
|