Manage.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. // $condition[] = [ 'g.sale_store', '%like%', [',11,']];
  55. // $condition[] = [ 'g.sale_store', 'like', '%,'.$store_id.',%' ];
  56. if ($store_id > 0) {
  57. $join[] = [
  58. 'store_goods_sku sgs',
  59. 'sgs.sku_id = gs.sku_id and (sgs.store_id is null or sgs.store_id = ' . $store_id . ')',
  60. 'left'
  61. ];
  62. $field .= ',sgs.stock, sgs.real_stock';
  63. }
  64. $gwhere = "(g.sale_store = 'all' or FIND_IN_SET(".$store_id.",g.sale_store))";
  65. $goods_model = new \app\model\goods\Goods();
  66. $list = $goods_model->getGoodsSkuPageList($condition, $page, $page_size, 'g.create_time desc', $field, 'gs', $join,null,$gwhere);
  67. return $this->response($list);
  68. }
  69. /**
  70. * 库存流水
  71. */
  72. public function records()
  73. {
  74. $document_model = new Document();
  75. $sku_id = isset($this->params[ 'sku_id' ]) ? $this->params[ 'sku_id' ] : 0;
  76. $goods_id = isset($this->params[ 'goods_id' ]) ? $this->params[ 'goods_id' ] : 0;
  77. $page = isset($this->params[ 'page' ]) ? $this->params[ 'page' ] : 1;
  78. $page_size = isset($this->params[ 'page_size' ]) ? $this->params[ 'page_size' ] : PAGE_LIST_ROWS;
  79. $start_time = isset($this->params[ 'start_time' ]) ? $this->params[ 'start_time' ] : 0;
  80. $end_time = isset($this->params[ 'end_time' ]) ? $this->params[ 'end_time' ] : 0;
  81. $type = isset($this->params[ 'type' ]) ? $this->params[ 'type' ] : '';
  82. $condition = array (
  83. [ 'dg.site_id', '=', $this->site_id ],
  84. [ 'd.store_id', '=', $this->store_id ],
  85. );
  86. if ($sku_id > 0) {
  87. $condition[] = [ 'dg.goods_sku_id', '=', $sku_id ];
  88. }
  89. if (!empty($type)) {
  90. $condition[] = [ 'dt.key', '=', $type ];
  91. }
  92. //注册时间
  93. if ($start_time != '' && $end_time != '') {
  94. $condition[] = [ 'dg.create_time', 'between', [ strtotime($start_time), strtotime($end_time) ] ];
  95. } else if ($start_time != '' && $end_time == '') {
  96. $condition[] = [ 'dg.create_time', '>=', strtotime($start_time) ];
  97. } else if ($start_time == '' && $end_time != '') {
  98. $condition[] = [ 'dg.create_time', '<=', strtotime($end_time) ];
  99. }
  100. if ($sku_id > 0) {
  101. $condition[] = [ 'dg.goods_sku_id', '=', $sku_id ];
  102. }
  103. if ($goods_id > 0) {
  104. $condition[] = [ 'dg.goods_id', '=', $goods_id ];
  105. }
  106. $result = $document_model->getDocumentGoodsPageList($condition, $page, $page_size, 'dg.create_time desc');
  107. return $this->response($result);
  108. }
  109. /**
  110. * 商品规格列表(仅作临时用)
  111. */
  112. public function getSkuList()
  113. {
  114. $goods_id = isset($this->params[ 'goods_id' ]) ? $this->params[ 'goods_id' ] : 0;
  115. $search = isset($this->params[ 'search' ]) ? $this->params[ 'search' ] : '';
  116. $temp_store_id = $this->params[ 'temp_store_id' ] ?? 0;
  117. $store_id = $temp_store_id > 0 ? $temp_store_id : $this->store_id;
  118. $stock_model = new StockModel();
  119. $condition = array (
  120. [ 'gs.site_id', '=', $this->site_id ],
  121. [ 'g.goods_class', 'in', [ 1, 6 ] ],
  122. [ 'g.is_delete', '=', 0 ]
  123. );
  124. if (!empty($search)) {
  125. $condition[] = [ 'gs.sku_name|gs.spec_name|g.goods_name|gs.sku_no', 'like', '%' . $search . '%' ];
  126. }
  127. if (!empty($goods_id)) {
  128. $condition[] = [ 'g.goods_id', '=', $goods_id ];
  129. }
  130. if ($store_id > 0) {
  131. //查询商品支持门店(支持当前门店或全部)
  132. $condition[] = [ 'g.sale_store', 'like', [ "%," . $store_id . ",%", "%all%" ], 'or' ];
  133. }
  134. $sku_list = $stock_model->getStoreGoodsSkuList($condition, 'gs.*,sgs.stock,sgs.real_stock,sgs.price,sgs.cost_price', 'gs.create_time desc', $store_id);
  135. return $this->response($sku_list);
  136. }
  137. public function getDocumentType()
  138. {
  139. $document_model = new Document();
  140. $type_list = $document_model->getDocumentTypeList();
  141. return $this->response($type_list);
  142. }
  143. }