Active.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. /**
  3. *
  4. * @copyright ©2020 点小铺
  5. * @author hanj
  6. * @link: https://dyuit.com
  7. * Created by VSCode
  8. */
  9. namespace app\common\model\bargain;
  10. use app\common\model\BaseModel;
  11. /**
  12. * 砍价活动模型
  13. * Class Active
  14. * @package app\common\model\bargain
  15. */
  16. class Active extends BaseModel
  17. {
  18. protected $name = 'bargain_active';
  19. protected $alias = 'active';
  20. protected $type = [
  21. 'is_self_cut' => 'integer',
  22. 'is_floor_buy' => 'integer',
  23. 'status' => 'integer',
  24. ];
  25. /**
  26. * 追加的字段
  27. * @var array $append
  28. */
  29. protected $append = [
  30. 'is_start', // 活动已开启
  31. 'is_end', // 活动已结束
  32. 'active_sales', // 活动销量
  33. ];
  34. /**
  35. * 获取器:活动开始时间
  36. * @param $value
  37. * @return false|string
  38. */
  39. public function getStartTimeAttr($value)
  40. {
  41. return \format_time($value);
  42. }
  43. /**
  44. * 获取器:活动结束时间
  45. * @param $value
  46. * @return false|string
  47. */
  48. public function getEndTimeAttr($value)
  49. {
  50. return \format_time($value);
  51. }
  52. /**
  53. * 获取器:活动是否已开启
  54. * @param $value
  55. * @param $data
  56. * @return false|string
  57. */
  58. public function getIsStartAttr($value, $data)
  59. {
  60. return $value ?: $data['start_time'] <= time();
  61. }
  62. /**
  63. * 获取器:活动是否已结束
  64. * @param $value
  65. * @param $data
  66. * @return false|string
  67. */
  68. public function getIsEndAttr($value, $data)
  69. {
  70. return $value ?: $data['end_time'] <= time();
  71. }
  72. /**
  73. * 获取器:显示销量
  74. * @param $value
  75. * @param $data
  76. * @return false|string
  77. */
  78. public function getActiveSalesAttr($value, $data)
  79. {
  80. return $value ?: $data['actual_sales'] + $data['initial_sales'];
  81. }
  82. /**
  83. * 砍价活动详情
  84. * @param $activeId
  85. * @param array $with
  86. * @return static|null
  87. * @throws \think\exception\DbException
  88. */
  89. public static function detail($activeId, $with = [])
  90. {
  91. return static::get($activeId, $with);
  92. }
  93. }