Activity.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. namespace app\admin\model\lottery;
  3. use think\Model;
  4. use traits\model\SoftDelete;
  5. use app\common\Enum\LotteryEnum;
  6. class Activity extends Model
  7. {
  8. use SoftDelete;
  9. // 表名
  10. protected $table = 'shop_lottery_activity';
  11. // 自动写入时间戳字段
  12. protected $autoWriteTimestamp = 'integer';
  13. // 定义时间戳字段名
  14. protected $createTime = 'createtime';
  15. protected $updateTime = 'updatetime';
  16. protected $deleteTime = 'deletetime';
  17. // 追加属性
  18. protected $append = [
  19. 'type_text',
  20. 'status_text',
  21. 'lottery_type_text',
  22. 'user_limit_type_text',
  23. 'guide_style_text',
  24. 'start_time_text',
  25. 'end_time_text',
  26. 'lottery_time_text'
  27. ];
  28. // 获取器
  29. public function getTypeTextAttr($value, $data)
  30. {
  31. $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
  32. $list = LotteryEnum::getActivityTypeMap();
  33. return isset($list[$value]) ? $list[$value] : '';
  34. }
  35. public function getStatusTextAttr($value, $data)
  36. {
  37. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  38. $list = LotteryEnum::getActivityStatusMap();
  39. return isset($list[$value]) ? $list[$value] : '';
  40. }
  41. public function getLotteryTypeTextAttr($value, $data)
  42. {
  43. $value = $value ? $value : (isset($data['lottery_type']) ? $data['lottery_type'] : '');
  44. $list = LotteryEnum::getLotteryTypeMap();
  45. return isset($list[$value]) ? $list[$value] : '';
  46. }
  47. public function getUserLimitTypeTextAttr($value, $data)
  48. {
  49. $value = $value ? $value : (isset($data['user_limit_type']) ? $data['user_limit_type'] : '');
  50. $list = LotteryEnum::getUserLimitTypeMap();
  51. return isset($list[$value]) ? $list[$value] : '';
  52. }
  53. public function getGuideStyleTextAttr($value, $data)
  54. {
  55. $value = $value ? $value : (isset($data['guide_style']) ? $data['guide_style'] : '');
  56. $list = LotteryEnum::getGuideStyleMap();
  57. return isset($list[$value]) ? $list[$value] : '';
  58. }
  59. public function getStartTimeTextAttr($value, $data)
  60. {
  61. $value = $value ? $value : (isset($data['start_time']) ? $data['start_time'] : '');
  62. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  63. }
  64. public function getEndTimeTextAttr($value, $data)
  65. {
  66. $value = $value ? $value : (isset($data['end_time']) ? $data['end_time'] : '');
  67. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  68. }
  69. public function getLotteryTimeTextAttr($value, $data)
  70. {
  71. $value = $value ? $value : (isset($data['lottery_time']) ? $data['lottery_time'] : '');
  72. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  73. }
  74. // 关联关系
  75. public function prize()
  76. {
  77. return $this->hasMany('LotteryPrize', 'activity_id', 'id');
  78. }
  79. public function condition()
  80. {
  81. return $this->hasMany('Condition', 'activity_id', 'id');
  82. }
  83. public function drawRecord()
  84. {
  85. return $this->hasMany('DrawRecord', 'activity_id', 'id');
  86. }
  87. public function winRecord()
  88. {
  89. return $this->hasMany('WinRecord', 'activity_id', 'id');
  90. }
  91. public function userChance()
  92. {
  93. return $this->hasMany('UserChance', 'activity_id', 'id');
  94. }
  95. public function statistics()
  96. {
  97. return $this->hasMany('Statistics', 'activity_id', 'id');
  98. }
  99. }