Active.php 2.0 KB

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