LotteryWinRecord.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace app\common\model\lottery;
  3. use think\Model;
  4. use app\common\Enum\LotteryEnum;
  5. /**
  6. * 中奖记录模型
  7. */
  8. class LotteryWinRecord extends Model
  9. {
  10. // 表名
  11. protected $table = 'shop_lottery_win_record';
  12. // 开启自动写入时间戳字段
  13. protected $autoWriteTimestamp = 'int';
  14. // 定义时间戳字段名
  15. protected $createTime = 'createtime';
  16. protected $updateTime = 'updatetime';
  17. protected $deleteTime = false;
  18. // 追加属性
  19. protected $append = [
  20. 'deliver_status_text',
  21. 'prize_value_data',
  22. 'deliver_info_data'
  23. ];
  24. /**
  25. * 关联抽奖记录
  26. */
  27. public function drawRecord()
  28. {
  29. return $this->belongsTo('LotteryDrawRecord', 'draw_record_id');
  30. }
  31. /**
  32. * 关联活动
  33. */
  34. public function activity()
  35. {
  36. return $this->belongsTo('LotteryActivity', 'activity_id');
  37. }
  38. /**
  39. * 关联用户
  40. */
  41. public function user()
  42. {
  43. return $this->belongsTo('app\common\model\User', 'user_id');
  44. }
  45. /**
  46. * 关联奖品
  47. */
  48. public function prize()
  49. {
  50. return $this->belongsTo('LotteryPrize', 'prize_id');
  51. }
  52. /**
  53. * 获取发放状态文本
  54. */
  55. public function getDeliverStatusTextAttr($value, $data)
  56. {
  57. $status = LotteryEnum::getDeliverStatusMap();
  58. return isset($status[$data['deliver_status']]) ? $status[$data['deliver_status']] : '未知';
  59. }
  60. /**
  61. * 获取奖品信息数据
  62. */
  63. public function getPrizeValueDataAttr($value, $data)
  64. {
  65. return !empty($data['prize_value']) ? json_decode($data['prize_value'], true) : [];
  66. }
  67. /**
  68. * 设置奖品信息
  69. */
  70. public function setPrizeValueAttr($value)
  71. {
  72. return is_array($value) ? json_encode($value) : $value;
  73. }
  74. /**
  75. * 获取发放信息数据
  76. */
  77. public function getDeliverInfoDataAttr($value, $data)
  78. {
  79. return !empty($data['deliver_info']) ? json_decode($data['deliver_info'], true) : [];
  80. }
  81. /**
  82. * 设置发放信息
  83. */
  84. public function setDeliverInfoAttr($value)
  85. {
  86. return is_array($value) ? json_encode($value) : $value;
  87. }
  88. }