LotteryPrize.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. namespace app\admin\model\lottery;
  3. use think\Model;
  4. use traits\model\SoftDelete;
  5. class LotteryPrize extends Model
  6. {
  7. use SoftDelete;
  8. // 表名
  9. protected $table = 'shop_lottery_prize';
  10. // 自动写入时间戳字段
  11. protected $autoWriteTimestamp = 'integer';
  12. // 定义时间戳字段名
  13. protected $createTime = 'createtime';
  14. protected $updateTime = 'updatetime';
  15. protected $deleteTime = 'deletetime';
  16. // 追加属性
  17. protected $append = [
  18. 'type_text',
  19. 'deliver_type_text',
  20. 'status_text'
  21. ];
  22. /**
  23. * 奖品类型列表
  24. */
  25. public function getTypeList()
  26. {
  27. return [
  28. '1' => __('未中奖'),
  29. '2' => __('实物奖品'),
  30. '3' => __('优惠券'),
  31. '4' => __('红包'),
  32. '5' => __('兑换码'),
  33. '6' => __('商城奖品')
  34. ];
  35. }
  36. /**
  37. * 发放方式列表
  38. */
  39. public function getDeliverTypeList()
  40. {
  41. return [
  42. '1' => __('自动发放'),
  43. '2' => __('手动发放')
  44. ];
  45. }
  46. /**
  47. * 状态列表
  48. */
  49. public function getStatusList()
  50. {
  51. return [
  52. '0' => __('禁用'),
  53. '1' => __('启用')
  54. ];
  55. }
  56. // 获取器
  57. public function getTypeTextAttr($value, $data)
  58. {
  59. $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
  60. $list = $this->getTypeList();
  61. return isset($list[$value]) ? $list[$value] : '';
  62. }
  63. public function getDeliverTypeTextAttr($value, $data)
  64. {
  65. $value = $value ? $value : (isset($data['deliver_type']) ? $data['deliver_type'] : '');
  66. $list = $this->getDeliverTypeList();
  67. return isset($list[$value]) ? $list[$value] : '';
  68. }
  69. public function getStatusTextAttr($value, $data)
  70. {
  71. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  72. $list = $this->getStatusList();
  73. return isset($list[$value]) ? $list[$value] : '';
  74. }
  75. // 关联关系
  76. public function activity()
  77. {
  78. return $this->belongsTo('Activity', 'activity_id', 'id');
  79. }
  80. public function winRecord()
  81. {
  82. return $this->hasMany('WinRecord', 'prize_id', 'id');
  83. }
  84. public function goods()
  85. {
  86. return $this->belongsTo('app\\common\\model\\shop\\Goods', 'goods_id', 'id');
  87. }
  88. public function goodsSku()
  89. {
  90. return $this->belongsTo('app\\common\\model\\shop\\GoodsSku', 'goods_sku_id', 'id');
  91. }
  92. public function coupon()
  93. {
  94. return $this->belongsTo('app\\common\\model\\shop\\Coupon', 'coupon_id', 'id');
  95. }
  96. }