GoodsSpecPriceLists.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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\goods;
  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. use app\common\model\GoodsItem;
  25. /**
  26. * 商品规格价格列表
  27. * Class GoodsSpecPriceLists
  28. * @package app\adminapi\lists\goods
  29. */
  30. class GoodsSpecPriceLists extends BaseAdminDataLists implements ListsSearchInterface, ListsExcelInterface
  31. {
  32. /**
  33. * @notes 搜索条件
  34. * @return array
  35. * @author
  36. * @date 2024/01/01 00:00
  37. */
  38. public function setSearch(): array
  39. {
  40. $searchWhere = [];
  41. // 条形码搜索
  42. if (!empty($this->params['bar_code'])) {
  43. $goodsIds = GoodsItem::where('bar_code', $this->params['bar_code'])->column('goods_id');
  44. if ($goodsIds) {
  45. $searchWhere[] = ['g.id', 'in', $goodsIds];
  46. } else {
  47. $searchWhere[] = ['g.id', '=', 0]; // 没有匹配的商品
  48. }
  49. }
  50. // 关键词搜索
  51. if (!empty($this->params['keyword'])) {
  52. $searchWhere[] = ['g.code|g.name', 'like', '%' . $this->params['keyword'] . '%'];
  53. }
  54. // 分类搜索
  55. if (!empty($this->params['category_id'])) {
  56. $searchWhere[] = ['g.category_id', '=', $this->params['category_id']];
  57. }
  58. // 供应商搜索
  59. if (!empty($this->params['supplier_id'])) {
  60. $searchWhere[] = ['g.supplier_id', '=', $this->params['supplier_id']];
  61. }
  62. // 商品类型搜索
  63. if (!empty($this->params['goods_type'])) {
  64. $searchWhere[] = ['g.goods_type', '=', $this->params['goods_type']];
  65. }
  66. // 状态搜索
  67. if (isset($this->params['status']) && $this->params['status'] !== '') {
  68. $searchWhere[] = ['g.status', '=', $this->params['status']];
  69. }
  70. return $searchWhere;
  71. }
  72. /**
  73. * @notes 获取商品规格价格列表
  74. * @return array
  75. * @author
  76. * @date 2024/01/01 00:00
  77. */
  78. public function lists(): array
  79. {
  80. $searchWhere = $this->setSearch();
  81. $lists = Goods::alias('g')
  82. ->leftJoin('goods_item gi', 'g.id = gi.goods_id')
  83. ->where($searchWhere)
  84. ->where('g.delete_time', null)
  85. ->field([
  86. 'g.id as goods_id',
  87. 'g.code as goods_code',
  88. 'g.name as goods_name',
  89. 'gi.id as item_id',
  90. 'gi.spec_value_str',
  91. 'gi.sell_price',
  92. 'gi.lineation_price',
  93. 'gi.cost_price',
  94. 'gi.stock',
  95. 'gi.weight',
  96. 'gi.volume'
  97. ])
  98. ->limit($this->limitOffset, $this->limitLength)
  99. ->order('g.id desc, gi.id asc')
  100. ->select()
  101. ->toArray();
  102. return $lists;
  103. }
  104. /**
  105. * @notes 获取数量
  106. * @return int
  107. * @author
  108. * @date 2024/01/01 00:00
  109. */
  110. public function count(): int
  111. {
  112. $searchWhere = $this->setSearch();
  113. return Goods::alias('g')
  114. ->leftJoin('goods_item gi', 'g.id = gi.goods_id')
  115. ->where($searchWhere)
  116. ->where('g.delete_time', null)
  117. ->count();
  118. }
  119. /**
  120. * @notes 设置导出字段
  121. * @return array
  122. * @author
  123. * @date 2024/01/01 00:00
  124. */
  125. public function setExcelFields(): array
  126. {
  127. return [
  128. 'goods_id' => '商品ID',
  129. 'goods_code' => '商品编码',
  130. 'goods_name' => '商品名称',
  131. 'item_id' => '规格ID',
  132. 'spec_value_str' => '规格名称',
  133. 'sell_price' => '销售价格',
  134. 'lineation_price' => '划线价格',
  135. 'cost_price' => '成本价格',
  136. 'stock' => '库存数量',
  137. 'weight' => '重量(kg)',
  138. 'volume' => '体积(m³)'
  139. ];
  140. }
  141. /**
  142. * @notes 设置文件名
  143. * @return string
  144. * @author
  145. * @date 2024/01/01 00:00
  146. */
  147. public function setFileName(): string
  148. {
  149. return '商品规格价格';
  150. }
  151. }