Active.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace app\common\model\plus\bargain;
  3. use app\common\model\BaseModel;
  4. /**
  5. * 砍价模型
  6. */
  7. class Active extends BaseModel
  8. {
  9. protected $name = 'bargain_activity';
  10. protected $pk = 'bargain_activity_id';
  11. protected $append = ['status_text', 'start_time_text','end_time_text'];
  12. /**
  13. * 有效期-开始时间
  14. */
  15. public function getStartTimeTextAttr($value, $data)
  16. {
  17. return date('Y-m-d H:i:s', $data['start_time']);
  18. }
  19. /**
  20. * 有效期-开始时间
  21. */
  22. public function getEndTimeTextAttr($value, $data)
  23. {
  24. return date('Y-m-d H:i:s', $data['end_time']);
  25. }
  26. /**
  27. * 状态
  28. */
  29. public function getStatusTextAttr($value, $data)
  30. {
  31. if($data['status'] == 0){
  32. return '未生效';
  33. }
  34. if ($data['start_time'] > time()) {
  35. return '未开始';
  36. }
  37. if ($data['end_time'] < time()) {
  38. return '已结束';
  39. }
  40. if ($data['start_time'] < time() && $data['end_time'] > time()) {
  41. return '生效-进行中';
  42. }
  43. return '';
  44. }
  45. /**
  46. *关联商品表
  47. */
  48. public function product()
  49. {
  50. return $this->hasMany('app\\common\\model\\plus\\bargain\\BargainProduct', 'bargain_id', 'bargain_id');
  51. }
  52. /**
  53. *关联图片
  54. */
  55. public function file()
  56. {
  57. return $this->hasOne('app\\common\\model\\file\\UploadFile', 'file_id', 'image_id');
  58. }
  59. /**
  60. * 砍价活动详情
  61. */
  62. public static function detail($bargain_activity_id, $with = [])
  63. {
  64. return (new static())->with($with)->find($bargain_activity_id);
  65. }
  66. /**
  67. * 处理过的详情数据
  68. */
  69. public static function detailWithTrans($bargain_activity_id)
  70. {
  71. $model = (new static())->with(['file'])->where('bargain_activity_id', '=', $bargain_activity_id)->find();
  72. return [
  73. 'title' => $model['title'],
  74. 'image_id' => $model['image_id'],
  75. 'file_path' => $model['file']['file_path'],
  76. 'sort' => $model['sort'],
  77. 'is_delete' => $model['is_delete'],
  78. 'conditions' => $model['conditions'],
  79. 'together_time' => $model['together_time'],
  80. 'status' => $model['status'],
  81. 'start_time' => date('Y-m-d H:i:s', $model['start_time']),
  82. 'end_time' => date('Y-m-d H:i:s', $model['end_time']),
  83. ];
  84. }
  85. }