Active.php 2.5 KB

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