BargainActivity.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop100%开源免费商用商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | 商业版本务必购买商业授权,以免引起法律纠纷
  8. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  9. // | gitee下载:https://gitee.com/likeshop_gitee
  10. // | github下载:https://github.com/likeshop-github
  11. // | 访问官网:https://www.likeshop.cn
  12. // | 访问社区:https://home.likeshop.cn
  13. // | 访问手册:http://doc.likeshop.cn
  14. // | 微信公众号:likeshop技术社区
  15. // | likeshop团队 版权所有 拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshopTeam
  18. // +----------------------------------------------------------------------
  19. namespace app\common\model;
  20. use app\common\enum\BargainEnum;
  21. use think\model\concern\SoftDelete;
  22. class BargainActivity extends BaseModel
  23. {
  24. use SoftDelete;
  25. protected $deleteTime = 'delete_time';
  26. /**
  27. * @notes 开始时间修改器
  28. * @param $time
  29. * @return false|int
  30. * @author Tab
  31. * @date 2021/8/27 11:32
  32. */
  33. public function setStartTimeAttr($time)
  34. {
  35. return strtotime($time);
  36. }
  37. /**
  38. * @notes 结束时间修改器
  39. * @param $time
  40. * @return false|int
  41. * @author Tab
  42. * @date 2021/8/27 11:32
  43. */
  44. public function setEndTimeAttr($time)
  45. {
  46. return strtotime($time);
  47. }
  48. /**
  49. * @notes 开始时间获取器
  50. * @param $time
  51. * @return string
  52. * @author Tab
  53. * @date 2021/8/27 14:33
  54. */
  55. public function getStartTimeAttr($time)
  56. {
  57. return date('Y-m-d H:i:s', $time);
  58. }
  59. public function getStartTimeDescAttr($time)
  60. {
  61. return date('Y-m-d H:i:s', $time);
  62. }
  63. /**
  64. * @notes 结束时间获取器
  65. * @param $time
  66. * @return string
  67. * @author Tab
  68. * @date 2021/8/27 14:33
  69. */
  70. public function getEndTimeAttr($time)
  71. {
  72. return date('Y-m-d H:i:s', $time);
  73. }
  74. public function getEndTimeDescAttr($time)
  75. {
  76. return date('Y-m-d H:i:s', $time);
  77. }
  78. /**
  79. * @notes 手动结束活动时间
  80. * @param $time
  81. * @author Tab
  82. * @date 2021/9/24 11:23
  83. */
  84. public function getCloseTimeAttr($time)
  85. {
  86. return is_null($time) ? '' : date('Y-m-d H:i:s', $time);
  87. }
  88. /**
  89. * @notes 活动状态获取器
  90. * @param $value
  91. * @return string|string[]
  92. * @author Tab
  93. * @date 2021/8/27 14:42
  94. */
  95. public function getStatusDescAttr($value, $data)
  96. {
  97. return BargainEnum::getActivityStatusDesc($data['status']);
  98. }
  99. /**
  100. * @notes 活动时间搜索器
  101. * @author Tab
  102. * @date 2021/8/28 11:23
  103. */
  104. public function searchActivityTimeAttr($query, $value, $data)
  105. {
  106. if (isset($data['start_time']) && isset($data['end_time']) && !empty($data['start_time']) && !empty($data['end_time'])) {
  107. $startTime = strtotime($data['start_time']);
  108. $endTime = strtotime($data['end_time']);
  109. $leftIds = self::where([
  110. ['start_time', '<=', $startTime],
  111. ['end_time', '<=', $startTime],
  112. ])->column('id');
  113. $rightIds = self::where([
  114. ['start_time', '>=', $endTime],
  115. ['end_time', '>=', $endTime],
  116. ])->column('id');
  117. $allIds = array_merge($leftIds, $rightIds);
  118. $query->where('id', 'not in', $allIds);
  119. } else if (isset($data['start_time']) && !empty($data['start_time'])) {
  120. $startTime = strtotime($data['start_time']);
  121. $query->where('start_time', '<=', $startTime);
  122. } else if (isset($data['end_time']) && !empty($data['end_time'])) {
  123. $endTime = strtotime($data['end_time']);
  124. $query->where('end_time', '<=', $endTime);
  125. }
  126. }
  127. /**
  128. * @notes 商品信息搜索器
  129. * @param $query
  130. * @param $value
  131. * @param $data
  132. * @author Tab
  133. * @date 2021/8/28 11:39
  134. */
  135. public function searchGoodsInfoAttr($query, $value, $data)
  136. {
  137. if (isset($data['goods_info']) && !empty($data['goods_info'])) {
  138. $activityIds = BargainGoods::alias('bg')
  139. ->leftJoin('goods g', 'g.id = bg.goods_id')
  140. ->where('g.name|g.code', 'like', '%' . $data['goods_info'] . '%')
  141. ->column('bg.activity_id');
  142. $query->where('id', 'in', $activityIds);
  143. }
  144. }
  145. }