Presell.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. namespace app\common\model;
  3. use app\common\enum\PresellEnum;
  4. use app\common\model\search\SearchPresell;
  5. use think\model\concern\SoftDelete;
  6. class Presell extends BaseModel
  7. {
  8. use SoftDelete;
  9. use SearchPresell;
  10. protected $autoWriteTimestamp = true;
  11. protected $defaultSoftDelete = 0;
  12. protected $type = [
  13. 'start_time' => 'timestamp',
  14. 'end_time' => 'timestamp',
  15. ];
  16. // 多条
  17. function goods()
  18. {
  19. return $this->hasMany(PresellGoods::class, 'presell_id', 'id');
  20. }
  21. // 单条
  22. function goodsDetail()
  23. {
  24. return $this->hasOne(PresellGoods::class, 'presell_id', 'id');
  25. }
  26. function goodsItems()
  27. {
  28. return $this->hasMany(PresellGoodsItem::class, 'presell_id', 'id');
  29. }
  30. /**
  31. * @notes type_text
  32. * @param $fieldValue
  33. * @param $data
  34. * @return string|string[]
  35. * @author lbzy
  36. * @datetime 2024-04-24 14:43:51
  37. */
  38. function getTypeTextAttr($fieldValue, $data)
  39. {
  40. return PresellEnum::getTypeDesc($data['type']);
  41. }
  42. /**
  43. * @notes status_text
  44. * @param $fieldValue
  45. * @param $data
  46. * @return string|string[]
  47. * @author lbzy
  48. * @datetime 2024-04-24 14:44:02
  49. */
  50. function getStatusTextAttr($fieldValue, $data)
  51. {
  52. return PresellEnum::getStatusDesc($data['status']);
  53. }
  54. /**
  55. * @notes send_type_text
  56. * @param $fieldValue
  57. * @param $data
  58. * @return array|string
  59. * @author lbzy
  60. * @datetime 2024-04-24 15:10:06
  61. */
  62. function getSendTypeTextAttr($fieldValue, $data)
  63. {
  64. return PresellEnum::getSendTypeDesc($data['send_type']);
  65. }
  66. /**
  67. * @notes end_time_remain 结束倒计时
  68. * @return mixed
  69. * @author lbzy
  70. * @datetime 2024-04-30 14:23:59
  71. */
  72. function getEndTimeRemainAttr($fieldValue, $data)
  73. {
  74. if ($data['status'] != PresellEnum::STATUS_START) {
  75. return null;
  76. }
  77. return $this->getOrigin('end_time') - time();
  78. }
  79. /**
  80. * @notes goods_num 商品数量
  81. * @return int
  82. * @author lbzy
  83. * @datetime 2024-06-14 18:44:32
  84. */
  85. function getGoodsNumAttr($fieldValue, $data)
  86. {
  87. return PresellGoods::where('presell_id', $data['id'])->count();
  88. }
  89. }