| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- <?php
- /**
- * Niushop商城系统 - 团队十年电商经验汇集巨献!
- * =========================================================
- * Copy right 2019-2029 上海牛之云网络科技有限公司, 保留所有权利。
- * ----------------------------------------------
- * 官方网址: https://www.niushop.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', 'in', [ 1, 6 ] ];
- 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' ],
- );
- // dump($store_id);
- 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';
- }
- $gwhere = "(g.sale_store = 'all' or FIND_IN_SET(".$store_id.",g.sale_store))";
- $goods_model = new \app\model\goods\Goods();
- $list = $goods_model->getGoodsSkuPageList($condition, $page, $page_size, 'g.create_time desc', $field, 'gs', $join,null,$gwhere);
- 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', 'in', [ 1, 6 ] ],
- [ '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);
- }
- }
|