Active.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace app\common\model\plus\assemble;
  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 = 'assemble_activity';
  12. protected $pk = 'assemble_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. public static function detail($assemble_activity_id)
  51. {
  52. return (new static())->with(['file'])->where('assemble_activity_id', '=', $assemble_activity_id)->find($assemble_activity_id);
  53. }
  54. /**
  55. * 处理过的详情数据
  56. */
  57. public static function detailWithTrans($assemble_activity_id)
  58. {
  59. $model = (new static())->with(['file'])->where('assemble_activity_id', '=', $assemble_activity_id)->find();
  60. return [
  61. 'title' => $model['title'],
  62. 'image_id' => $model['image_id'],
  63. 'file_path' => $model['file']['file_path'],
  64. 'status' => $model['status'],
  65. 'fail_type' => $model['fail_type'],
  66. 'is_single' => $model['is_single'],
  67. 'sort' => $model['sort'],
  68. 'is_delete' => $model['is_delete'],
  69. 'together_time' => $model['together_time'],
  70. 'start_time' => date('Y-m-d H:i:s', $model['start_time']),
  71. 'end_time' => date('Y-m-d H:i:s', $model['end_time']),
  72. ];
  73. }
  74. public function file()
  75. {
  76. return $this->belongsTo('app\\common\\model\\file\\UploadFile', 'image_id', 'file_id');
  77. }
  78. public function assembleProduct()
  79. {
  80. return $this->hasMany('Product', 'assemble_activity_id', 'assemble_activity_id');
  81. }
  82. }