AfterSaleLists.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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\after_sale;
  20. use app\adminapi\lists\BaseAdminDataLists;
  21. use app\common\enum\AfterSaleEnum;
  22. use app\common\lists\ListsExcelInterface;
  23. use app\common\lists\ListsExtendInterface;
  24. use app\common\model\AfterSale;
  25. use app\common\service\FileService;
  26. /**
  27. * 售后列表类
  28. * Class AfterSaleLists
  29. * @package app\adminapi\lists\after_sale
  30. */
  31. class AfterSaleLists extends BaseAdminDataLists implements ListsExtendInterface,ListsExcelInterface
  32. {
  33. /**
  34. * @notes 导出字段
  35. * @return string[]
  36. * @author Tab
  37. * @date 2021/9/22 17:41
  38. */
  39. public function setExcelFields(): array
  40. {
  41. return [
  42. 'sn' => '售后单号',
  43. 'nickname' => '用户昵称',
  44. 'order_sn' => '订单编号',
  45. 'refund_type_desc' => '售后类型',
  46. 'refund_method_desc' => '售后方式',
  47. 'refund_total_amount' => '售后金额',
  48. 'sub_status_desc' => '售后状态',
  49. 'create_time' => '申请时间',
  50. ];
  51. }
  52. /**
  53. * @notes 导出表名
  54. * @return string
  55. * @author Tab
  56. * @date 2021/9/22 17:40
  57. */
  58. public function setFileName(): string
  59. {
  60. return '售后列表';
  61. }
  62. /**
  63. * @notes 统计信息
  64. * @return mixed|void
  65. * @author Tab
  66. * @date 2021/8/18 19:24
  67. */
  68. public function extend()
  69. {
  70. $all = AfterSale::count();
  71. $ing = AfterSale::where('status', AfterSaleEnum::STATUS_ING)->count();
  72. $success = AfterSale::where('status', AfterSaleEnum::STATUS_SUCCESS)->count();
  73. $fail = AfterSale::where('status', AfterSaleEnum::STATUS_FAIL)->count();
  74. return [
  75. 'all' => $all,
  76. 'ing' => $ing,
  77. 'success' => $success,
  78. 'fail' => $fail
  79. ];
  80. }
  81. /**
  82. * @notes 设置搜索
  83. * @author Tab
  84. * @date 2021/8/2 16:25
  85. */
  86. public function setSearch()
  87. {
  88. // 售后编号
  89. if(isset($this->params['after_sale_sn']) && $this->params['after_sale_sn']) {
  90. $this->searchWhere[] = ['as.sn', 'like', '%'.$this->params['after_sale_sn'].'%'];
  91. }
  92. // 订单编号
  93. if(isset($this->params['order_sn']) && $this->params['order_sn']) {
  94. $this->searchWhere[] = ['o.sn', 'like', '%'.$this->params['order_sn'].'%'];
  95. }
  96. // 用户信息
  97. if(isset($this->params['user_info']) && $this->params['user_info']) {
  98. $this->searchWhere[] = ['u.sn|u.nickname|u.mobile', 'like', '%'.$this->params['user_info'].'%'];
  99. }
  100. // 售后类型
  101. if(isset($this->params['refund_type']) && $this->params['refund_type']) {
  102. $this->searchWhere[] = ['as.refund_type', '=', $this->params['refund_type']];
  103. }
  104. // 售后方式
  105. if(isset($this->params['refund_method']) && $this->params['refund_method']) {
  106. $this->searchWhere[] = ['as.refund_method', '=', $this->params['refund_method']];
  107. }
  108. // 申请时间
  109. if(isset($this->params['start_time']) && $this->params['start_time']) {
  110. $this->searchWhere[] = ['as.create_time', '>=', strtotime($this->params['start_time'])];
  111. }
  112. if(isset($this->params['end_time']) && $this->params['end_time']) {
  113. $this->searchWhere[] = ['as.create_time', '<=', strtotime($this->params['end_time'])];
  114. }
  115. // 售后主状态
  116. if(isset($this->params['status']) && $this->params['status']) {
  117. $this->searchWhere[] = ['as.status', '=', $this->params['status']];
  118. }
  119. // 快递单号
  120. if(isset($this->params['invoice_no']) && $this->params['invoice_no']) {
  121. $this->searchWhere[] = ['as.invoice_no', 'like', '%'.$this->params['invoice_no'].'%'];
  122. }
  123. }
  124. /**
  125. * @notes 售后列表
  126. * @return array
  127. * @throws \think\db\exception\DataNotFoundException
  128. * @throws \think\db\exception\DbException
  129. * @throws \think\db\exception\ModelNotFoundException
  130. * @author Tab
  131. * @date 2021/8/2 16:13
  132. */
  133. public function lists() : array
  134. {
  135. // 设置搜索
  136. $this->setSearch();
  137. $field = 'as.id,as.user_id,as.order_id,as.sn,as.refund_type,as.refund_method,as.refund_total_amount,as.status,as.sub_status,as.create_time';
  138. $field .= ',as.refund_type as refund_type_desc,as.refund_method as refund_method_desc,as.status as status_desc,as.sub_status as sub_status_desc';
  139. $field .= ',o.sn as order_sn';
  140. $field .= ',u.nickname,u.avatar,u.sn as user_sn';
  141. $lists = AfterSale::with(['after_sale_goods'])
  142. ->alias('as')
  143. ->leftJoin('order o', 'o.id = as.order_id')
  144. ->leftJoin('user u', 'u.id = as.user_id')
  145. ->field($field)
  146. ->where($this->searchWhere)
  147. ->withSearch(['goods_info'], $this->params)
  148. ->limit($this->limitOffset, $this->limitLength)
  149. ->order('id', 'desc')
  150. ->select()
  151. ->toArray();
  152. foreach($lists as &$item) {
  153. $item['avatar'] = FileService::getFileUrl($item['avatar']);
  154. }
  155. return $lists;
  156. }
  157. /**
  158. * @notes 售后记录数
  159. * @return int
  160. * @author Tab
  161. * @date 2021/8/2 15:44
  162. */
  163. public function count() : int
  164. {
  165. // 设置搜索
  166. $this->setSearch();
  167. $count = AfterSale::alias('as')
  168. ->leftJoin('order o', 'o.id = as.order_id')
  169. ->leftJoin('user u', 'u.id = as.user_id')
  170. ->where($this->searchWhere)->count();
  171. return $count;
  172. }
  173. }