DistributionGoodsLists.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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\Goods;
  24. /**
  25. * 分销商品列表
  26. * Class DistributionGoodsLists
  27. * @package app\adminapi\lists\distribution
  28. */
  29. class DistributionGoodsLists extends BaseAdminDataLists implements ListsSearchInterface,ListsExcelInterface
  30. {
  31. /**
  32. * @notes 导出字段
  33. * @return array
  34. * @author Tab
  35. * @date 2021/9/22 15:30
  36. */
  37. public function setExcelFields(): array
  38. {
  39. return [
  40. 'name' => '商品信息',
  41. 'min_price' => '最小价格',
  42. 'max_price' => '最大价格',
  43. 'is_distribution_desc' => '分销状态',
  44. ];
  45. }
  46. /**
  47. * @notes 导出表名
  48. * @return string
  49. * @author Tab
  50. * @date 2021/9/22 15:30
  51. */
  52. public function setFileName(): string
  53. {
  54. return '分销商品表';
  55. }
  56. /**
  57. * @notes 设置搜索条件
  58. * @return \string[][]
  59. * @author Tab
  60. * @date 2021/7/23 16:15
  61. */
  62. public function setSearch(): array
  63. {
  64. return [
  65. '=' => ['supplier_id'],
  66. ];
  67. }
  68. /**
  69. * @notes 附加搜索
  70. * @author Tab
  71. * @date 2021/9/16 19:30
  72. */
  73. public function attachSearch()
  74. {
  75. if (isset($this->params['name']) && !empty($this->params['name'])) {
  76. $this->searchWhere[] = ['name|code', 'like', '%'. $this->params['name'] . '%'];
  77. }
  78. if(isset($this->params['status']) && '' != $this->params['status']){
  79. if('-1' == $this->params['status']){
  80. $this->searchWhere[] = ['total_stock','=',0];
  81. }else{
  82. $this->searchWhere[] = ['status', '=', $this->params['status']];
  83. }
  84. }
  85. }
  86. /**
  87. * @notes 分销商品列表
  88. * @return array
  89. * @throws \think\db\exception\DataNotFoundException
  90. * @throws \think\db\exception\DbException
  91. * @throws \think\db\exception\ModelNotFoundException
  92. * @author Tab
  93. * @date 2021/7/23 16:15
  94. */
  95. public function lists(): array
  96. {
  97. $this->attachSearch();
  98. $field = 'id,name,image,min_price,max_price,status,id as is_distribution,id as commission,total_stock,spec_type';
  99. $lists = Goods::field($field)
  100. ->with('goods_category_index.category_name')
  101. ->withSearch(['category_id', 'is_distribution'], $this->params)
  102. ->where($this->searchWhere)
  103. ->limit($this->limitOffset, $this->limitLength)
  104. ->order('id', 'desc')
  105. ->select()
  106. ->toArray();
  107. foreach ($lists as &$item) {
  108. $item['is_distribution_desc'] = $item['is_distribution'] ? '参与' : '不参与';
  109. $item['status'] == 1 ? $item['status_desc'] = '销售中' : $item['status_desc'] = '仓库中';
  110. if($item['total_stock'] <= 0){
  111. $item['status_desc'] = '已售罄';
  112. }
  113. //商品价格
  114. $item['price'] = '¥' . $item['min_price'];
  115. if ($item['min_price'] != $item['max_price']) {
  116. $item['price'] = '¥' . $item['min_price'] . '~' . '¥' . $item['max_price'];
  117. }
  118. }
  119. return $lists;
  120. }
  121. /**
  122. * @notes 分销商品记录数
  123. * @return int
  124. * @author Tab
  125. * @date 2021/7/23 16:16
  126. */
  127. public function count(): int
  128. {
  129. $this->attachSearch();
  130. $count = Goods::withSearch(['category_id', 'is_distribution'], $this->params)
  131. ->where($this->searchWhere)
  132. ->count();
  133. return $count;
  134. }
  135. }