Active.php 3.4 KB

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