DistributionOrderGoodsLists.php 6.9 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\distribution;
  20. use app\adminapi\lists\BaseAdminDataLists;
  21. use app\common\lists\ListsExcelInterface;
  22. use app\common\lists\ListsSearchInterface;
  23. use app\common\model\DistributionLevel;
  24. use app\common\model\DistributionOrderGoods;
  25. use app\common\model\User;
  26. use app\common\service\FileService;
  27. /**
  28. * 分销订单列表
  29. * Class DistributionOrderGoodsLists
  30. * @package app\adminapi\lists\distribution
  31. */
  32. class DistributionOrderGoodsLists extends BaseAdminDataLists implements ListsSearchInterface,ListsExcelInterface
  33. {
  34. /**
  35. * @notes 设置搜索条件
  36. * @return array
  37. * @author Tab
  38. * @date 2021/7/27 18:54
  39. */
  40. public function setSearch(): array
  41. {
  42. return [
  43. '=' => ['o.sn', 'dog.status'],
  44. 'between_time' => 'o.create_time'
  45. ];
  46. }
  47. /**
  48. * @notes 附加搜索
  49. * @author Tab
  50. * @date 2021/9/22 16:30
  51. */
  52. public function attachSearch()
  53. {
  54. //买家信息
  55. if (isset($this->params['keyword']) && !empty($this->params['keyword']))
  56. {
  57. $this->searchWhere[] = ['du.sn|du.nickname', 'like', '%' . $this->params['keyword'] . '%'];
  58. }
  59. //分销商信息
  60. if (isset($this->params['dkeyword']) && !empty($this->params['dkeyword']))
  61. {
  62. $this->searchWhere[] = ['u.sn|u.nickname', 'like', '%' . $this->params['dkeyword'] . '%'];
  63. }
  64. // 商品信息
  65. if (isset($this->params['name']) && !empty($this->params['name']))
  66. {
  67. $this->searchWhere[] = ['g.name|g.code', 'like', '%' . $this->params['name'] . '%'];
  68. }
  69. }
  70. /**
  71. * @notes 设置导出表名
  72. * @return string
  73. * @author Tab
  74. * @date 2021/8/5 15:29
  75. */
  76. public function setFileName(): string
  77. {
  78. return '分销订单表';
  79. }
  80. /**
  81. * @notes 设置导出字段名
  82. * @return array
  83. * @author Tab
  84. * @date 2021/8/5 15:29
  85. */
  86. public function setExcelFields(): array
  87. {
  88. return [
  89. 'sn' => '订单编号',
  90. 'buyer_sn' => '买家编号',
  91. 'buyer_nickname' => '买家昵称',
  92. 'goods_name' => '商品名称',
  93. 'spec_value_str' => '商品规格',
  94. 'goods_price' => '商品价格',
  95. 'goods_num' => '购买数量',
  96. 'total_pay_price' => '实付金额',
  97. 'distribution_member_sn' => '分销商编号',
  98. 'distribution_member_nickname' => '分销商昵称',
  99. 'level_desc' => '分销等级',
  100. 'ratio' => '佣金比例',
  101. 'earnings' => '佣金金额',
  102. 'status_desc' => '佣金状态',
  103. 'settlement_time' => '结算时间',
  104. 'order_create_time' => '下单时间'
  105. ];
  106. }
  107. /**
  108. * @notes 分销订单列表
  109. * @return array
  110. * @author Tab
  111. * @date 2021/7/28 9:29
  112. */
  113. public function lists(): array
  114. {
  115. $this->attachSearch();
  116. $field = 'dog.id, dog.level_id,dog.level,dog.level as level_desc,dog.ratio, dog.earnings, dog.status, dog.status as status_desc, dog.settlement_time';
  117. $field .= ',og.goods_num, og.goods_price, og.total_pay_price,og.express_price';
  118. $field .= ',o.sn,o.user_id as buyer_id,o.create_time as order_create_time';
  119. $field .= ',g.image as goods_image, g.name as goods_name';
  120. $field .= ',gi.spec_value_str, gi.image as item_image';
  121. $field .= ',u.id as distribution_member_id,u.avatar as distribution_member_avatar, u.nickname as distribution_member_nickname,u.sn as distribution_member_sn';
  122. $this->sortOrder = ['dog.id' => 'desc'];
  123. $lists = DistributionOrderGoods::alias('dog')
  124. ->leftJoin('order_goods og', 'og.id = dog.order_goods_id')
  125. ->leftJoin('order o', 'o.id = og.order_id')
  126. ->leftJoin('goods g', 'g.id = dog.goods_id')
  127. ->leftJoin('goods_item gi', 'gi.id = dog.item_id')
  128. ->leftJoin('user u', 'u.id = dog.user_id')
  129. ->leftJoin('user du','du.id = o.user_id')
  130. ->field($field)
  131. ->withSearch('user_id', $this->params)
  132. ->where($this->searchWhere)
  133. ->order($this->sortOrder)
  134. ->limit($this->limitOffset, $this->limitLength)
  135. ->select()
  136. ->toArray();
  137. foreach ($lists as &$item) {
  138. $buyer = DistributionOrderGoods::getBueyer($item['buyer_id']);
  139. $item['buyer_nickname'] = $buyer['nickname'];
  140. $item['buyer_sn'] = $buyer['sn'];
  141. $item['buyer_avatar'] = $buyer['avatar'];
  142. $item['distribution_level_name'] = DistributionLevel::getLevelName($item['level_id']);
  143. $item['distribution_member_avatar'] = FileService::getFileUrl($item['distribution_member_avatar']);
  144. $item['image'] = $item['item_image'] ? $item['item_image'] : $item['goods_image'];
  145. $item['image'] = FileService::getFileUrl($item['image']);
  146. $item['order_create_time'] = $item['order_create_time'] ? date('Y-m-d H:i:s', $item['order_create_time']) : '';
  147. // 分销订单 实际支付金额使用 total_pay_price - express_price
  148. $item['total_pay_price'] = bcadd(max(0, $item['total_pay_price'] - $item['express_price']), 0, 2);
  149. }
  150. return $lists;
  151. }
  152. /**
  153. * @notes 分销订单总记录数
  154. * @return int
  155. * @author Tab
  156. * @date 2021/7/28 9:29
  157. */
  158. public function count(): int
  159. {
  160. $this->attachSearch();
  161. $count = DistributionOrderGoods::alias('dog')
  162. ->leftJoin('order_goods og', 'og.id = dog.order_goods_id')
  163. ->leftJoin('order o', 'o.id = og.order_id')
  164. ->leftJoin('goods g', 'g.id = dog.goods_id')
  165. ->leftJoin('goods_item gi', 'gi.id = dog.item_id')
  166. ->leftJoin('user u', 'u.id = dog.user_id')
  167. ->leftJoin('user du','du.id = o.user_id')
  168. ->where($this->searchWhere)
  169. ->count();
  170. return $count;
  171. }
  172. }