| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- <?php
- // +----------------------------------------------------------------------
- // | likeshop100%开源免费商用商城系统
- // +----------------------------------------------------------------------
- // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
- // | 开源版本可自由商用,可去除界面版权logo
- // | 商业版本务必购买商业授权,以免引起法律纠纷
- // | 禁止对系统程序代码以任何目的,任何形式的再发布
- // | gitee下载:https://gitee.com/likeshop_gitee
- // | github下载:https://github.com/likeshop-github
- // | 访问官网:https://www.likeshop.cn
- // | 访问社区:https://home.likeshop.cn
- // | 访问手册:http://doc.likeshop.cn
- // | 微信公众号:likeshop技术社区
- // | likeshop团队 版权所有 拥有最终解释权
- // +----------------------------------------------------------------------
- // | author: likeshopTeam
- // +----------------------------------------------------------------------
- namespace app\adminapi\lists\goods;
- use app\adminapi\lists\BaseAdminDataLists;
- use app\common\lists\ListsExcelInterface;
- use app\common\lists\ListsSearchInterface;
- use app\common\model\Goods;
- use app\common\model\GoodsCategory;
- use app\common\model\GoodsCategoryIndex;
- use app\common\model\GoodsItem;
- /**
- * 商品规格价格列表
- * Class GoodsSpecPriceLists
- * @package app\adminapi\lists\goods
- */
- class GoodsSpecPriceLists extends BaseAdminDataLists implements ListsSearchInterface, ListsExcelInterface
- {
- /**
- * @notes 搜索条件
- * @return array
- * @author
- * @date 2024/01/01 00:00
- */
- public function setSearch(): array
- {
- $searchWhere = [];
-
- // 条形码搜索
- if (!empty($this->params['bar_code'])) {
- $goodsIds = GoodsItem::where('bar_code', $this->params['bar_code'])->column('goods_id');
- if ($goodsIds) {
- $searchWhere[] = ['g.id', 'in', $goodsIds];
- } else {
- $searchWhere[] = ['g.id', '=', 0]; // 没有匹配的商品
- }
- }
-
- // 关键词搜索
- if (!empty($this->params['keyword'])) {
- $searchWhere[] = ['g.code|g.name', 'like', '%' . $this->params['keyword'] . '%'];
- }
-
- // 分类搜索 - 使用GoodsCategoryIndex表
- if (!empty($this->params['category_id'])) {
- $goodsCategory = GoodsCategory::find($this->params['category_id']);
- $level = $goodsCategory['level'] ?? '';
- $categoryIds = [];
- switch ($level) {
- case 1:
- $categoryIds = GoodsCategory::alias('A')
- ->join('goods_category B', 'A.id = B.pid')
- ->where(['A.pid' => $this->params['category_id']])
- ->field('A.id as aid,B.id as bid')
- ->select()->toArray();
- $categoryIds = array_merge(array_column($categoryIds, 'aid'), array_column($categoryIds, 'bid'));
- break;
- case 2:
- $categoryIds = GoodsCategory::where(['pid' => $this->params['category_id']])
- ->column('id');
- break;
- }
- $categoryIds = array_merge([(int)$this->params['category_id']], $categoryIds);
- $goodsIds = GoodsCategoryIndex::where([['category_id', 'in', $categoryIds]])->column('goods_id');
- if ($goodsIds) {
- $searchWhere[] = ['g.id', 'in', $goodsIds];
- } else {
- $searchWhere[] = ['g.id', '=', 0]; // 没有匹配的商品
- }
- }
-
- // 供应商搜索
- if (!empty($this->params['supplier_id'])) {
- $searchWhere[] = ['g.supplier_id', '=', $this->params['supplier_id']];
- }
-
- // 商品类型搜索
- if (!empty($this->params['goods_type'])) {
- $searchWhere[] = ['g.goods_type', '=', $this->params['goods_type']];
- }
-
- // 状态搜索
- if (isset($this->params['status']) && $this->params['status'] !== '') {
- $searchWhere[] = ['g.status', '=', $this->params['status']];
- }
-
- return $searchWhere;
- }
- /**
- * @notes 获取商品规格价格列表
- * @return array
- * @author
- * @date 2024/01/01 00:00
- */
- public function lists(): array
- {
- $searchWhere = $this->setSearch();
- $lists = Goods::alias('g')
- ->leftJoin('goods_item gi', 'g.id = gi.goods_id')
- ->where($searchWhere)
- ->where('g.delete_time', null)
- ->field([
- 'g.id as goods_id',
- 'g.code as goods_code',
- 'g.name as goods_name',
- 'gi.id as item_id',
- 'gi.spec_value_str',
- 'gi.sell_price',
- 'gi.lineation_price',
- 'gi.cost_price',
- 'gi.stock',
- 'gi.weight',
- 'gi.volume'
- ])
- ->limit($this->limitOffset, $this->limitLength)
- ->order('g.id desc, gi.id asc')
- ->select()
- ->toArray();
- return $lists;
- }
- /**
- * @notes 获取数量
- * @return int
- * @author
- * @date 2024/01/01 00:00
- */
- public function count(): int
- {
- $searchWhere = $this->setSearch();
-
- return Goods::alias('g')
- ->leftJoin('goods_item gi', 'g.id = gi.goods_id')
- ->where($searchWhere)
- ->where('g.delete_time', null)
- ->count();
- }
- /**
- * @notes 设置导出字段
- * @return array
- * @author
- * @date 2024/01/01 00:00
- */
- public function setExcelFields(): array
- {
- return [
- 'goods_id' => '商品ID',
- 'goods_code' => '商品编码',
- 'goods_name' => '商品名称',
- 'item_id' => '规格ID',
- 'spec_value_str' => '规格名称',
- 'sell_price' => '销售价格',
- 'lineation_price' => '划线价格',
- 'cost_price' => '成本价格',
- 'stock' => '库存数量',
- 'weight' => '重量(kg)',
- 'volume' => '体积(m³)'
- ];
- }
- /**
- * @notes 设置文件名
- * @return string
- * @author
- * @date 2024/01/01 00:00
- */
- public function setFileName(): string
- {
- return '商品规格价格';
- }
- }
|