SeckillLists.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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\adminapi\lists\marketing;
  20. use app\adminapi\lists\BaseAdminDataLists;
  21. use app\common\enum\SeckillEnum;
  22. use app\common\lists\ListsExcelInterface;
  23. use app\common\lists\ListsExtendInterface;
  24. use app\common\model\SeckillActivity;
  25. use app\common\model\SeckillGoods;
  26. use app\common\model\SeckillGoodsItem;
  27. class SeckillLists extends BaseAdminDataLists implements ListsExtendInterface, ListsExcelInterface
  28. {
  29. /**
  30. * @notes 设置导出字段
  31. * @return array
  32. * @author 张无忌
  33. * @date 2021/7/31 16:28
  34. */
  35. public function setExcelFields(): array
  36. {
  37. return [
  38. 'sn' => '秒杀编号',
  39. 'name' => '秒杀名称',
  40. 'goods_num' => '活动商品',
  41. 'activity_time' => '活动时间',
  42. 'browse_volume' => '浏览量',
  43. 'sales_amount' => '销售金额',
  44. 'sales_volume' => '销售量',
  45. 'closing_order' => '成交订单数',
  46. 'status_text' => '活动状态',
  47. 'create_time' => '创建时间'
  48. ];
  49. }
  50. /**
  51. * @notes 设置导出文件名
  52. * @return string
  53. * @author 张无忌
  54. * @date 2021/7/31 16:28
  55. */
  56. public function setFileName(): string
  57. {
  58. return '秒杀列表';
  59. }
  60. /**
  61. * @notes 秒杀活动搜索条件
  62. * @return array
  63. * @author 张无忌
  64. * @date 2021/7/29 18:08
  65. */
  66. public function queryWhere()
  67. {
  68. $where = [];
  69. if (!empty($this->params['status']) and $this->params['status']) {
  70. $where[] = ['SA.status', '=', $this->params['status']];
  71. }
  72. if (!empty($this->params['activity']) and $this->params['activity']) {
  73. $where[] = ['SA.name|SA.sn', 'like', '%' . $this->params['activity'] . '%'];
  74. }
  75. if (!empty($this->params['start_time']) and $this->params['start_time']) {
  76. $where[] = ['SA.start_time', '>=', strtotime($this->params['start_time'])];
  77. }
  78. if (!empty($this->params['end_time']) and $this->params['end_time']) {
  79. $where[] = ['SA.end_time', '<=', strtotime($this->params['end_time'])];
  80. }
  81. return $where;
  82. }
  83. /**
  84. * @notes 秒杀活动数量统计
  85. * @return mixed
  86. * @author 张无忌
  87. * @date 2021/7/29 18:09
  88. */
  89. public function extend()
  90. {
  91. $detail['all'] = (new SeckillActivity())->alias('SA')->withSearch(['goods'], $this->params)->count();
  92. $detail['not'] = (new SeckillActivity())->alias('SA')->where(['status' => SeckillEnum::SECKILL_STATUS_NOT])->withSearch(['goods'], $this->params)->count();
  93. $detail['conduct'] = (new SeckillActivity())->alias('SA')->where(['status' => SeckillEnum::SECKILL_STATUS_CONDUCT])->withSearch(['goods'], $this->params)->count();
  94. $detail['end'] = (new SeckillActivity())->alias('SA')->where(['status' => SeckillEnum::SECKILL_STATUS_END])->withSearch(['goods'], $this->params)->count();
  95. return $detail;
  96. }
  97. /**
  98. * @notes 获取秒杀活动列表
  99. * @return array
  100. * @throws @\think\db\exception\DataNotFoundException
  101. * @throws @\think\db\exception\DbException
  102. * @throws @\think\db\exception\ModelNotFoundException
  103. * @author 张无忌
  104. * @date 2021/7/29 18:09
  105. */
  106. public function lists(): array
  107. {
  108. $lists = (new SeckillActivity())->alias('SA')
  109. ->field(['SA.id,SA.sn,SA.name,SA.start_time,SA.end_time,SA.status,SA.create_time'])
  110. ->where($this->queryWhere())
  111. ->withSearch(['goods'], $this->params)
  112. ->order('SA.id desc')
  113. ->limit($this->limitOffset, $this->limitLength)
  114. ->select()
  115. ->toArray();
  116. foreach ($lists as &$item) {
  117. $item['status_text'] = SeckillEnum::getSeckillStatusDesc($item['status']);
  118. $item['activity_time'] = date('Y-m-d H:i:s', $item['start_time']) . ' ~ ' . date('Y-m-d H:i:s', $item['end_time']);
  119. $item['goods_num'] = SeckillGoods::where(['seckill_id' => $item['id']])->count() . '件';
  120. $item['browse_volume'] = SeckillGoods::where(['seckill_id' => $item['id']])->sum('browse_volume');
  121. $item['sales_amount'] = SeckillGoodsItem::where(['seckill_id' => $item['id']])->sum('sales_amount');
  122. $item['sales_volume'] = SeckillGoodsItem::where(['seckill_id' => $item['id']])->sum('sales_volume');
  123. $item['closing_order'] = SeckillGoodsItem::where(['seckill_id' => $item['id']])->sum('closing_order');
  124. unset($item['start_time']);
  125. unset($item['end_time']);
  126. }
  127. return $lists;
  128. }
  129. /**
  130. * @notes 获取秒杀活动数量
  131. * @return int
  132. * @author 张无忌
  133. * @date 2021/7/29 18:10
  134. */
  135. public function count(): int
  136. {
  137. return (new SeckillActivity())->alias('SA')
  138. ->field(['SA.id,SA.sn,SA.name,SA.start_time,SA.end_time,SA.status,SA.create_time'])
  139. ->where($this->queryWhere())
  140. ->withSearch(['goods'], $this->params)
  141. ->count();
  142. }
  143. }