159 lines
6.2 KiB
PHP
159 lines
6.2 KiB
PHP
<?php
|
|
/**
|
|
* ThinkShop商城系统 - 团队十年电商经验汇集巨献!
|
|
* =========================================================
|
|
* Copy right 2019-2029 上海牛之云网络科技有限公司, 保留所有权利。
|
|
* ----------------------------------------------
|
|
* 官方网址: https://www.cdcloudshop.com
|
|
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
|
|
* 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
|
|
* =========================================================
|
|
*/
|
|
|
|
namespace addon\stock\storeapi\controller;
|
|
|
|
use addon\stock\model\stock\Document;
|
|
use addon\stock\model\stock\Stock as StockModel;
|
|
use app\storeapi\controller\BaseStoreApi;
|
|
|
|
/**
|
|
* 库存管理
|
|
*/
|
|
class Manage extends BaseStoreApi
|
|
{
|
|
|
|
/**
|
|
* 库存管理
|
|
*/
|
|
public function lists()
|
|
{
|
|
$page = isset($this->params[ 'page' ]) ? $this->params[ 'page' ] : 1;
|
|
$page_size = isset($this->params[ 'page_size' ]) ? $this->params[ 'page_size' ] : PAGE_LIST_ROWS;
|
|
$search = isset($this->params[ 'search' ]) ? $this->params[ 'search' ] : '';
|
|
$category_id = isset($this->params[ 'category_id' ]) ? $this->params[ 'category_id' ] : '';
|
|
$min_stock = isset($this->params[ 'min_stock' ]) ? $this->params[ 'min_stock' ] : 0;
|
|
$max_stock = isset($this->params[ 'max_stock' ]) ? $this->params[ 'max_stock' ] : 0;
|
|
|
|
$store_id = $this->store_id;
|
|
|
|
$condition = [];
|
|
$condition[] = [ 'gs.site_id', '=', $this->site_id ];
|
|
$condition[] = [ 'g.is_delete', '=', 0 ];
|
|
|
|
$condition[] = [ 'g.goods_class', '=', 1 ];
|
|
if (!empty($search)) {
|
|
$condition[] = [ 'gs.sku_name|sku_no', 'like', '%' . $search . '%' ];
|
|
}
|
|
|
|
if (!empty($category_id)) {
|
|
$condition[] = [ 'g.category_id', 'like', '%,' . $category_id . ',%' ];
|
|
}
|
|
if ($min_stock > 0 && $max_stock > 0) {
|
|
$condition[] = [ 'sgs.real_stock', 'between', [ $min_stock, $max_stock ] ];
|
|
} else if ($min_stock > 0 && $max_stock == 0) {
|
|
$condition[] = [ 'sgs.real_stock', '>', $min_stock ];
|
|
} else if ($min_stock == 0 && $max_stock > 0) {
|
|
$condition[] = [ 'sgs.real_stock', '<', $max_stock ];
|
|
}
|
|
|
|
$field = 'gs.stock,gs.*,g.unit';
|
|
$join = array (
|
|
[ 'goods g', 'g.goods_id = gs.goods_id', 'left' ],
|
|
);
|
|
|
|
if ($store_id > 0) {
|
|
$join[] = [
|
|
'store_goods_sku sgs',
|
|
'sgs.sku_id = gs.sku_id and (sgs.store_id is null or sgs.store_id = ' . $store_id . ')',
|
|
'left'
|
|
];
|
|
$field .= ',sgs.stock, sgs.real_stock';
|
|
}
|
|
|
|
$goods_model = new \app\model\goods\Goods();
|
|
$list = $goods_model->getGoodsSkuPageList($condition, $page, $page_size, 'g.create_time desc', $field, 'gs', $join);
|
|
return $this->response($list);
|
|
}
|
|
|
|
/**
|
|
* 库存流水
|
|
*/
|
|
public function records()
|
|
{
|
|
$document_model = new Document();
|
|
$sku_id = isset($this->params[ 'sku_id' ]) ? $this->params[ 'sku_id' ] : 0;
|
|
$goods_id = isset($this->params[ 'goods_id' ]) ? $this->params[ 'goods_id' ] : 0;
|
|
$page = isset($this->params[ 'page' ]) ? $this->params[ 'page' ] : 1;
|
|
$page_size = isset($this->params[ 'page_size' ]) ? $this->params[ 'page_size' ] : PAGE_LIST_ROWS;
|
|
$start_time = isset($this->params[ 'start_time' ]) ? $this->params[ 'start_time' ] : 0;
|
|
$end_time = isset($this->params[ 'end_time' ]) ? $this->params[ 'end_time' ] : 0;
|
|
$type = isset($this->params[ 'type' ]) ? $this->params[ 'type' ] : '';
|
|
|
|
$condition = array (
|
|
[ 'dg.site_id', '=', $this->site_id ],
|
|
[ 'd.store_id', '=', $this->store_id ],
|
|
);
|
|
if ($sku_id > 0) {
|
|
$condition[] = [ 'dg.goods_sku_id', '=', $sku_id ];
|
|
}
|
|
if (!empty($type)) {
|
|
$condition[] = [ 'dt.key', '=', $type ];
|
|
}
|
|
//注册时间
|
|
if ($start_time != '' && $end_time != '') {
|
|
$condition[] = [ 'dg.create_time', 'between', [ strtotime($start_time), strtotime($end_time) ] ];
|
|
} else if ($start_time != '' && $end_time == '') {
|
|
$condition[] = [ 'dg.create_time', '>=', strtotime($start_time) ];
|
|
} else if ($start_time == '' && $end_time != '') {
|
|
$condition[] = [ 'dg.create_time', '<=', strtotime($end_time) ];
|
|
}
|
|
|
|
if ($sku_id > 0) {
|
|
$condition[] = [ 'dg.goods_sku_id', '=', $sku_id ];
|
|
}
|
|
if ($goods_id > 0) {
|
|
$condition[] = [ 'dg.goods_id', '=', $goods_id ];
|
|
}
|
|
$result = $document_model->getDocumentGoodsPageList($condition, $page, $page_size, 'dg.create_time desc');
|
|
return $this->response($result);
|
|
}
|
|
|
|
/**
|
|
* 商品规格列表(仅作临时用)
|
|
*/
|
|
public function getSkuList()
|
|
{
|
|
$goods_id = isset($this->params[ 'goods_id' ]) ? $this->params[ 'goods_id' ] : 0;
|
|
$search = isset($this->params[ 'search' ]) ? $this->params[ 'search' ] : '';
|
|
|
|
$temp_store_id = $this->params['temp_store_id'] ?? 0;
|
|
|
|
$store_id = $temp_store_id > 0 ? $temp_store_id : $this->store_id;
|
|
$stock_model = new StockModel();
|
|
$condition = array (
|
|
[ 'gs.site_id', '=', $this->site_id ],
|
|
[ 'g.goods_class', '=', 1 ],
|
|
[ 'g.is_delete', '=', 0 ]
|
|
);
|
|
if (!empty($search)) {
|
|
$condition[] = [ 'gs.sku_name|gs.spec_name|g.goods_name|gs.sku_no', 'like', '%' . $search . '%' ];
|
|
}
|
|
if (!empty($goods_id)) {
|
|
$condition[] = [ 'g.goods_id', '=', $goods_id ];
|
|
}
|
|
if ($store_id > 0) {
|
|
//查询商品支持门店(支持当前门店或全部)
|
|
$condition[] = ['g.sale_store', 'like', ["%,".$store_id.",%", "%all%"], 'or'];
|
|
}
|
|
$sku_list = $stock_model->getStoreGoodsSkuList($condition, 'gs.*,sgs.stock,sgs.real_stock,sgs.price,sgs.cost_price', 'gs.create_time desc', $store_id);
|
|
return $this->response($sku_list);
|
|
}
|
|
|
|
public function getDocumentType()
|
|
{
|
|
$document_model = new Document();
|
|
$type_list = $document_model->getDocumentTypeList();
|
|
return $this->response($type_list);
|
|
}
|
|
|
|
} |