123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- <?php
- namespace app\common\model\lottery;
- use think\Model;
- use app\common\Enum\LotteryEnum;
- /**
- * 中奖记录模型
- */
- class LotteryWinRecord extends Model
- {
- // 表名
- protected $table = 'shop_lottery_win_record';
-
- // 开启自动写入时间戳字段
- protected $autoWriteTimestamp = 'int';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = 'updatetime';
- protected $deleteTime = false;
- // 追加属性
- protected $append = [
- 'deliver_status_text',
- 'prize_value_data',
- 'deliver_info_data'
- ];
- /**
- * 关联抽奖记录
- */
- public function drawRecord()
- {
- return $this->belongsTo('LotteryDrawRecord', 'draw_record_id');
- }
- /**
- * 关联活动
- */
- public function activity()
- {
- return $this->belongsTo('LotteryActivity', 'activity_id');
- }
- /**
- * 关联用户
- */
- public function user()
- {
- return $this->belongsTo('app\common\model\User', 'user_id');
- }
- /**
- * 关联奖品
- */
- public function prize()
- {
- return $this->belongsTo('LotteryPrize', 'prize_id');
- }
- /**
- * 获取发放状态文本
- */
- public function getDeliverStatusTextAttr($value, $data)
- {
- $status = LotteryEnum::getDeliverStatusMap();
- return isset($status[$data['deliver_status']]) ? $status[$data['deliver_status']] : '未知';
- }
- /**
- * 获取奖品信息数据
- */
- public function getPrizeValueDataAttr($value, $data)
- {
- return !empty($data['prize_value']) ? json_decode($data['prize_value'], true) : [];
- }
- /**
- * 设置奖品信息
- */
- public function setPrizeValueAttr($value)
- {
- return is_array($value) ? json_encode($value) : $value;
- }
- /**
- * 获取发放信息数据
- */
- public function getDeliverInfoDataAttr($value, $data)
- {
- return !empty($data['deliver_info']) ? json_decode($data['deliver_info'], true) : [];
- }
- /**
- * 设置发放信息
- */
- public function setDeliverInfoAttr($value)
- {
- return is_array($value) ? json_encode($value) : $value;
- }
- }
|