CouponLists.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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\CouponEnum;
  22. use app\common\lists\ListsExcelInterface;
  23. use app\common\lists\ListsExtendInterface;
  24. use app\common\lists\ListsSearchInterface;
  25. use app\common\model\Coupon;
  26. use app\common\model\CouponList;
  27. class CouponLists extends BaseAdminDataLists implements ListsExtendInterface, ListsExcelInterface, ListsSearchInterface
  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. 'id' => '优惠券ID',
  39. 'sn' => '优惠券编号',
  40. 'name' => '优惠券名称',
  41. 'discount_content' => '优惠券内容',
  42. 'get_method' => '推广方式',
  43. 'use_time_text' => '用卷时间',
  44. 'send_total_text' => '发放总量',
  45. 'receive_number' => '已领取',
  46. 'surplus_number' => '剩余',
  47. 'use_number' => '已使用',
  48. 'status_text' => '优惠券状态',
  49. 'create_time' => '创建时间'
  50. ];
  51. }
  52. /**
  53. * @notes 设置导出文件名
  54. * @return string
  55. * @author 张无忌
  56. * @date 2021/7/31 16:28
  57. */
  58. public function setFileName(): string
  59. {
  60. return '优惠券列表';
  61. }
  62. /**
  63. * @notes 优惠券搜索条件
  64. * @return array
  65. * @author 张无忌
  66. * @date 2021/7/29 18:07
  67. */
  68. public function setSearch(): array
  69. {
  70. return [
  71. '=' => ['status', 'get_type'],
  72. '%like%' => ['name'],
  73. "between_time" => 'create_time'
  74. ];
  75. }
  76. /**
  77. * @notes 优惠券扩展统计
  78. * @return mixed
  79. * @author 张无忌
  80. * @date 2021/7/29 18:07
  81. */
  82. public function extend()
  83. {
  84. $searchwhere = $this->searchWhere;
  85. foreach ($searchwhere as $key => $value) {
  86. if ($value[0] == 'status') {
  87. unset($searchwhere[$key]);
  88. }
  89. }
  90. $searchwhere = array_values($searchwhere);
  91. $model = new Coupon();
  92. $detail['all'] = $model->where($searchwhere)->count();
  93. $detail['not'] = $model->where($searchwhere)
  94. ->where(['status' => CouponEnum::COUPON_STATUS_NOT])->count();
  95. $detail['conduct'] = $model->where($searchwhere)
  96. ->where(['status' => CouponEnum::COUPON_STATUS_CONDUCT])->count();
  97. $detail['end'] = $model->where($searchwhere)
  98. ->where(['status' => CouponEnum::COUPON_STATUS_END])->count();
  99. return $detail;
  100. }
  101. /**
  102. * @notes 获取优惠券列表
  103. * @return array
  104. * @throws @\think\db\exception\DataNotFoundException
  105. * @throws @\think\db\exception\DbException
  106. * @throws @\think\db\exception\ModelNotFoundException
  107. * @author 张无忌
  108. * @date 2021/7/29 18:07
  109. */
  110. public function lists(): array
  111. {
  112. $lists = (new Coupon())->withoutField('update_time,delete_time')
  113. ->where($this->searchWhere)
  114. ->append([ 'discount_content', 'use_time_type', 'use_time_text', 'status_text', 'use_number', 'receive_number', 'surplus_number', 'send_total_text' ])
  115. ->limit($this->limitOffset, $this->limitLength)
  116. ->order('id desc')
  117. ->select()
  118. ->toArray();
  119. foreach ($lists as &$item) {
  120. $item['get_method'] = CouponEnum::getTypeDesc($item['get_type']);
  121. unset($item['condition_type']);
  122. unset($item['condition_money']);
  123. unset($item['send_total_type']);
  124. unset($item['send_total']);
  125. unset($item['use_time_type']);
  126. unset($item['use_time_start']);
  127. unset($item['use_time_end']);
  128. unset($item['use_time']);
  129. unset($item['get_num_type']);
  130. unset($item['get_num']);
  131. unset($item['use_goods_type']);
  132. unset($item['use_goods_ids']);
  133. }
  134. return $lists;
  135. }
  136. /**
  137. * @notes 获取优惠券数量统计
  138. * @return int
  139. * @author 张无忌
  140. * @date 2021/7/29 18:07
  141. */
  142. public function count(): int
  143. {
  144. return (new Coupon())->where($this->searchWhere)->count();
  145. }
  146. }