GiftPackage.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace app\common\model\plus\giftpackage;
  3. use app\common\model\BaseModel;
  4. /**
  5. * Class GiftPackage
  6. * 礼包购模型
  7. * @package app\common\model\plus\giftpackage
  8. */
  9. class GiftPackage extends BaseModel
  10. {
  11. protected $name = 'gift_package';
  12. protected $pk = 'gift_package_id';
  13. /**
  14. * 礼包详情
  15. */
  16. public static function detail($gift_package_id)
  17. {
  18. return (new static())->with(['image'])->find($gift_package_id);
  19. }
  20. /**
  21. * 开始时间
  22. */
  23. public function getStartTimeAttr($value)
  24. {
  25. return ['text' => date('Y-m-d H:i:s', $value), 'value' => $value];
  26. }
  27. /**
  28. * 有效期-结束时间
  29. */
  30. public function getEndTimeAttr($value)
  31. {
  32. return ['text' => date('Y-m-d H:i:s', $value), 'value' => $value];
  33. }
  34. /**
  35. * 状态
  36. */
  37. public function getStatusAttr($value, $data)
  38. {
  39. $text = '';
  40. if($value == 1){
  41. $text = '未生效';
  42. }else{
  43. if ($data['start_time'] > time()) {
  44. $text = '未开始';
  45. }
  46. if ($data['end_time'] < time()) {
  47. $text = '已结束';
  48. }
  49. if ($data['start_time'] < time() && $data['end_time'] > time()) {
  50. $text = '进行中';
  51. }
  52. }
  53. return ['text' => $text, 'value' => $value];
  54. }
  55. /**
  56. * 关联文件库
  57. */
  58. public function image()
  59. {
  60. return $this->belongsTo('app\\common\\model\\file\\UploadFile', 'image_id', 'file_id')
  61. ->bind(['file_path']);
  62. }
  63. }