Active.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. namespace app\common\model\plus\seckill;
  3. use app\common\model\BaseModel;
  4. /**
  5. * 参与记录模型
  6. */
  7. class Active extends BaseModel
  8. {
  9. protected $name = 'seckill_activity';
  10. protected $pk = 'seckill_activity_id';
  11. //附加字段
  12. protected $append = ['status_text', 'start_time_text','end_time_text', 'join_status', 'join_end_time_text'];
  13. /**
  14. * 有效期-开始时间
  15. * @param $value
  16. * @return array
  17. */
  18. public function getStartTimeTextAttr($value, $data)
  19. {
  20. return date('Y-m-d H:i:s', $data['start_time']);
  21. }
  22. /**
  23. * 有效期-开始时间
  24. * @param $value
  25. * @return array
  26. */
  27. public function getEndTimeTextAttr($value, $data)
  28. {
  29. return date('Y-m-d H:i:s', $data['end_time']);
  30. }
  31. /**
  32. * 有效期-开始时间
  33. * @param $value
  34. * @return array
  35. */
  36. public function getJoinEndTimeTextAttr($value, $data)
  37. {
  38. return date('Y-m-d H:i:s', $data['join_end_time']);
  39. }
  40. /**
  41. * 状态
  42. * @param $val
  43. * @return string
  44. */
  45. public function getStatusTextAttr($value, $data)
  46. {
  47. if($data['status'] == 0){
  48. return '未生效';
  49. }
  50. if ($data['start_time'] > time()) {
  51. return '未开始';
  52. }
  53. if ($data['end_time'] < time()) {
  54. return '已结束';
  55. }
  56. if ($data['start_time'] < time() && $data['end_time'] > time()) {
  57. return '生效-进行中';
  58. }
  59. return '';
  60. }
  61. /**
  62. * 状态
  63. * @param $val
  64. * @return string
  65. */
  66. public function getJoinStatusAttr($value, $data)
  67. {
  68. if($data['status'] == 0){
  69. return 0;
  70. }
  71. if ($data['end_time'] < time()) {
  72. return 0;
  73. }
  74. if ($data['join_end_time'] < time()) {
  75. return 0;
  76. }
  77. return 1;
  78. }
  79. /**
  80. * 处理过的详情数据
  81. */
  82. public static function detailWithTrans($seckill_activity_id)
  83. {
  84. $model = (new static())->with(['file'])->where('seckill_activity_id', '=', $seckill_activity_id)->find();
  85. $detail = [
  86. 'title' => $model['title'],
  87. 'image_id' => $model['image_id'],
  88. 'status' => $model['status'],
  89. 'sort' => $model['sort'],
  90. 'start_time' => $model['start_time'],
  91. 'end_time' => $model['end_time'],
  92. 'file_path' => $model['file']['file_path'],
  93. 'join_end_time' => date('Y-m-d H:i:s', $model['join_end_time']),
  94. 'active_date' => [
  95. date('Y-m-d H:i:s', $model['start_time']),
  96. date('Y-m-d H:i:s', $model['end_time']),
  97. ],
  98. 'active_time' => [
  99. $model['day_start_time'],
  100. $model['day_end_time'],
  101. ]
  102. ];
  103. return $detail;
  104. }
  105. public static function detail($seckill_activity_id)
  106. {
  107. return (new static())->find($seckill_activity_id);
  108. }
  109. public function file()
  110. {
  111. return $this->belongsTo('app\\common\\model\\file\\UploadFile', 'image_id', 'file_id');
  112. }
  113. public function seckillProduct()
  114. {
  115. return $this->hasMany('app\\common\\model\\plus\\seckill\\Product', 'seckill_activity_id', 'seckill_activity_id');
  116. }
  117. }