Manage.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 上海牛之云网络科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
  9. * 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
  10. * =========================================================
  11. */
  12. namespace addon\stock\storeapi\controller;
  13. use addon\stock\model\stock\Document;
  14. use addon\stock\model\stock\Stock as StockModel;
  15. use app\storeapi\controller\BaseStoreApi;
  16. /**
  17. * 库存管理
  18. */
  19. class Manage extends BaseStoreApi
  20. {
  21. /**
  22. * 库存管理
  23. */
  24. public function lists()
  25. {
  26. $page = isset($this->params[ 'page' ]) ? $this->params[ 'page' ] : 1;
  27. $page_size = isset($this->params[ 'page_size' ]) ? $this->params[ 'page_size' ] : PAGE_LIST_ROWS;
  28. $search = isset($this->params[ 'search' ]) ? $this->params[ 'search' ] : '';
  29. $category_id = isset($this->params[ 'category_id' ]) ? $this->params[ 'category_id' ] : '';
  30. $min_stock = isset($this->params[ 'min_stock' ]) ? $this->params[ 'min_stock' ] : 0;
  31. $max_stock = isset($this->params[ 'max_stock' ]) ? $this->params[ 'max_stock' ] : 0;
  32. $store_id = $this->store_id;
  33. $condition = [];
  34. $condition[] = [ 'gs.site_id', '=', $this->site_id ];
  35. $condition[] = [ 'g.is_delete', '=', 0 ];
  36. $condition[] = [ 'g.goods_class', 'in', [ 1, 6 ] ];
  37. if (!empty($search)) {
  38. $condition[] = [ 'gs.sku_name|sku_no', 'like', '%' . $search . '%' ];
  39. }
  40. if (!empty($category_id)) {
  41. $condition[] = [ 'g.category_id', 'like', '%,' . $category_id . ',%' ];
  42. }
  43. if ($min_stock > 0 && $max_stock > 0) {
  44. $condition[] = [ 'sgs.real_stock', 'between', [ $min_stock, $max_stock ] ];
  45. } else if ($min_stock > 0 && $max_stock == 0) {
  46. $condition[] = [ 'sgs.real_stock', '>', $min_stock ];
  47. } else if ($min_stock == 0 && $max_stock > 0) {
  48. $condition[] = [ 'sgs.real_stock', '<', $max_stock ];
  49. }
  50. $field = 'gs.stock,gs.*,g.unit';
  51. $join = array (
  52. [ 'goods g', 'g.goods_id = gs.goods_id', 'left' ],
  53. );
  54. // dump($store_id);
  55. if ($store_id > 0) {
  56. $join[] = [
  57. 'store_goods_sku sgs',
  58. 'sgs.sku_id = gs.sku_id and (sgs.store_id is null or sgs.store_id = ' . $store_id . ')',
  59. 'left'
  60. ];
  61. $field .= ',sgs.stock, sgs.real_stock';
  62. }
  63. $gwhere = "(g.sale_store = 'all' or FIND_IN_SET(".$store_id.",g.sale_store))";
  64. $goods_model = new \app\model\goods\Goods();
  65. $list = $goods_model->getGoodsSkuPageList($condition, $page, $page_size, 'g.create_time desc', $field, 'gs', $join,null,$gwhere);
  66. return $this->response($list);
  67. }
  68. /**
  69. * 库存流水
  70. */
  71. public function records()
  72. {
  73. $document_model = new Document();
  74. $sku_id = isset($this->params[ 'sku_id' ]) ? $this->params[ 'sku_id' ] : 0;
  75. $goods_id = isset($this->params[ 'goods_id' ]) ? $this->params[ 'goods_id' ] : 0;
  76. $page = isset($this->params[ 'page' ]) ? $this->params[ 'page' ] : 1;
  77. $page_size = isset($this->params[ 'page_size' ]) ? $this->params[ 'page_size' ] : PAGE_LIST_ROWS;
  78. $start_time = isset($this->params[ 'start_time' ]) ? $this->params[ 'start_time' ] : 0;
  79. $end_time = isset($this->params[ 'end_time' ]) ? $this->params[ 'end_time' ] : 0;
  80. $type = isset($this->params[ 'type' ]) ? $this->params[ 'type' ] : '';
  81. $condition = array (
  82. [ 'dg.site_id', '=', $this->site_id ],
  83. [ 'd.store_id', '=', $this->store_id ],
  84. );
  85. if ($sku_id > 0) {
  86. $condition[] = [ 'dg.goods_sku_id', '=', $sku_id ];
  87. }
  88. if (!empty($type)) {
  89. $condition[] = [ 'dt.key', '=', $type ];
  90. }
  91. //注册时间
  92. if ($start_time != '' && $end_time != '') {
  93. $condition[] = [ 'dg.create_time', 'between', [ strtotime($start_time), strtotime($end_time) ] ];
  94. } else if ($start_time != '' && $end_time == '') {
  95. $condition[] = [ 'dg.create_time', '>=', strtotime($start_time) ];
  96. } else if ($start_time == '' && $end_time != '') {
  97. $condition[] = [ 'dg.create_time', '<=', strtotime($end_time) ];
  98. }
  99. if ($sku_id > 0) {
  100. $condition[] = [ 'dg.goods_sku_id', '=', $sku_id ];
  101. }
  102. if ($goods_id > 0) {
  103. $condition[] = [ 'dg.goods_id', '=', $goods_id ];
  104. }
  105. $result = $document_model->getDocumentGoodsPageList($condition, $page, $page_size, 'dg.create_time desc');
  106. return $this->response($result);
  107. }
  108. /**
  109. * 商品规格列表(仅作临时用)
  110. */
  111. public function getSkuList()
  112. {
  113. $goods_id = isset($this->params[ 'goods_id' ]) ? $this->params[ 'goods_id' ] : 0;
  114. $search = isset($this->params[ 'search' ]) ? $this->params[ 'search' ] : '';
  115. $temp_store_id = $this->params[ 'temp_store_id' ] ?? 0;
  116. $store_id = $temp_store_id > 0 ? $temp_store_id : $this->store_id;
  117. $stock_model = new StockModel();
  118. $condition = array (
  119. [ 'gs.site_id', '=', $this->site_id ],
  120. [ 'g.goods_class', 'in', [ 1, 6 ] ],
  121. [ 'g.is_delete', '=', 0 ]
  122. );
  123. if (!empty($search)) {
  124. $condition[] = [ 'gs.sku_name|gs.spec_name|g.goods_name|gs.sku_no', 'like', '%' . $search . '%' ];
  125. }
  126. if (!empty($goods_id)) {
  127. $condition[] = [ 'g.goods_id', '=', $goods_id ];
  128. }
  129. if ($store_id > 0) {
  130. //查询商品支持门店(支持当前门店或全部)
  131. $condition[] = [ 'g.sale_store', 'like', [ "%," . $store_id . ",%", "%all%" ], 'or' ];
  132. }
  133. $sku_list = $stock_model->getStoreGoodsSkuList($condition, 'gs.*,sgs.stock,sgs.real_stock,sgs.price,sgs.cost_price', 'gs.create_time desc', $store_id);
  134. return $this->response($sku_list);
  135. }
  136. public function getDocumentType()
  137. {
  138. $document_model = new Document();
  139. $type_list = $document_model->getDocumentTypeList();
  140. return $this->response($type_list);
  141. }
  142. }