DrawRecord.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace app\admin\model\lottery;
  3. use think\Model;
  4. use app\common\Enum\LotteryEnum;
  5. use app\common\Enum\StatusEnum;
  6. class DrawRecord extends Model
  7. {
  8. // 表名
  9. protected $table = 'shop_lottery_draw_record';
  10. // 自动写入时间戳字段
  11. protected $autoWriteTimestamp = 'integer';
  12. // 定义时间戳字段名
  13. protected $createTime = 'createtime';
  14. protected $updateTime = false;
  15. // 追加属性
  16. protected $append = [
  17. 'trigger_type_text',
  18. 'draw_time_text',
  19. 'is_win_text',
  20. 'status_text',
  21. ];
  22. public function getIsWinList()
  23. {
  24. return LotteryEnum::getIsWinMap();
  25. }
  26. public function getStatusList(){
  27. return StatusEnum::getMap();
  28. }
  29. public function getStatusTextAttr($value, $data)
  30. {
  31. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  32. $list = $this->getStatusList();
  33. return isset($list[$value]) ? $list[$value] : '';
  34. }
  35. public function getIsWinTextAttr($value, $data)
  36. {
  37. $value = $value ? $value : (isset($data['is_win']) ? $data['is_win'] : '');
  38. $list = $this->getIsWinList();
  39. return isset($list[$value]) ? $list[$value] : '';
  40. }
  41. /**
  42. * 触发类型列表
  43. */
  44. public function getTriggerTypeList()
  45. {
  46. return LotteryEnum::getTriggerTypeMap();
  47. }
  48. // 获取器
  49. public function getTriggerTypeTextAttr($value, $data)
  50. {
  51. $value = $value ? $value : (isset($data['trigger_type']) ? $data['trigger_type'] : '');
  52. $list = $this->getTriggerTypeList();
  53. return isset($list[$value]) ? $list[$value] : '';
  54. }
  55. public function getDrawTimeTextAttr($value, $data)
  56. {
  57. $value = $value ? $value : (isset($data['draw_time']) ? $data['draw_time'] : '');
  58. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  59. }
  60. // 关联关系
  61. public function activity()
  62. {
  63. return $this->belongsTo('Activity', 'activity_id', 'id');
  64. }
  65. public function user()
  66. {
  67. return $this->belongsTo('app\\common\\model\\User', 'user_id', 'id');
  68. }
  69. public function prize()
  70. {
  71. return $this->belongsTo('LotteryPrize', 'prize_id', 'id');
  72. }
  73. public function winRecord()
  74. {
  75. return $this->hasOne('WinRecord', 'draw_record_id', 'id');
  76. }
  77. }