TeamLists.php 5.8 KB

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