Check.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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\Inventory;
  14. use app\storeapi\controller\BaseStoreApi;
  15. /**
  16. * 库存盘点
  17. */
  18. class Check extends BaseStoreApi
  19. {
  20. /**
  21. * 库存盘点
  22. * @return mixed
  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. $inventory_no = isset($this->params[ 'inventory_no' ]) ? $this->params[ 'inventory_no' ] : '';
  29. $store_id = $this->store_id;
  30. $condition = array (
  31. [ 'site_id', '=', $this->site_id ],
  32. );
  33. if ($store_id > 0) {
  34. $condition[] = [ 'store_id', '=', $store_id ];
  35. }
  36. if (!empty($inventory_no)) {
  37. $condition[] = [ 'inventory_no', 'like', '%' . $inventory_no . '%' ];
  38. }
  39. $inventory_model = new Inventory();
  40. $list = $inventory_model->getInventoryPageList($condition, $page, $page_size, 'create_time desc');
  41. return $this->response($list);
  42. }
  43. /**
  44. * 库存盘点详情
  45. */
  46. public function detail()
  47. {
  48. $inventory_no = isset($this->params[ 'inventory_no' ]) ? $this->params[ 'inventory_no' ] : 0;
  49. $inventory_model = new Inventory();
  50. $condition = array (
  51. [ 'site_id', '=', $this->site_id ],
  52. [ 'inventory_no', '=', $inventory_no ],
  53. [ 'store_id', '=', $this->store_id ],
  54. );
  55. $inventory_detail = $inventory_model->getInventoryInfo($condition);
  56. if (empty($inventory_detail)) {
  57. return $this->response($this->error("盘点单不存在"));
  58. }
  59. return $this->response($inventory_detail);
  60. }
  61. /**
  62. *新增盘点记录
  63. * @return mixed
  64. */
  65. public function add()
  66. {
  67. $inventory_model = new Inventory();
  68. $store_id = $this->store_id;
  69. $stock_list = isset($this->params[ 'stock_json' ]) ? $this->params[ 'stock_json' ] : '';//商品库存映照json {{'sku_id':1, 'stock' : 10, 'cost_price':10,'source':'来源'}}
  70. $stock_list = json_decode($stock_list, true);
  71. $params = array (
  72. 'site_id' => $this->site_id,
  73. 'store_id' => $store_id,
  74. 'sku_list' => $stock_list,
  75. 'user_info' => $this->user_info,
  76. );
  77. $result = $inventory_model->addInventory($params);
  78. return $this->response($result);
  79. }
  80. }