ReplenishmentService.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. namespace App\Services;
  3. use App\Traits\ServiceAppAop;
  4. use Carbon\Carbon;
  5. use Illuminate\Support\Facades\DB;
  6. class ReplenishmentService
  7. {
  8. use ServiceAppAop;
  9. /**
  10. * @param $customer
  11. * @return array
  12. * 根据货主,订单状态为拣货完成之前的
  13. * 订单信息
  14. */
  15. public function getOrderInfoRecentMonthByCustomer($customer): array
  16. {
  17. $db = DB::connection("oracle");
  18. $sql = <<<sql
  19. select orders.customerid, orders.sku,orders.amount,BAS_SKU.ALTERNATE_SKU1,BAS_SKU.ALTERNATE_SKU2,BAS_SKU.ALTERNATE_SKU3
  20. from (
  21. select customerid, sku, sum(QTYORDERED_EACH) amount
  22. from DOC_ORDER_DETAILS
  23. where ORDERNO in (select ORDERNO
  24. from DOC_ORDER_HEADER
  25. where SOSTATUS IN ('00', '10', '20', '30', '40', '50')
  26. AND customerid = ?
  27. AND ADDTIME >= TO_DATE(?, 'yyyy-mm-dd hh24:mi:ss')
  28. AND ADDTIME <= TO_DATE(?, 'yyyy-mm-dd hh24:mi:ss'))
  29. group by customerid, sku
  30. ) orders
  31. left join BAS_SKU on orders.customerid=BAS_SKU.customerid and orders.sku = BAS_SKU.SKU
  32. order by orders.amount desc
  33. sql;
  34. $res= $db->select(DB::raw($sql),[$customer,Carbon::now()->subDays(30)->toDateTimeString(),Carbon::now()->toDateTimeString()]);
  35. $orders=array();
  36. foreach ($res as $item){
  37. $orders[]=json_decode( json_encode( $item),true);
  38. }
  39. return $orders;
  40. }
  41. /**
  42. * @param $customer
  43. * @param array $skuArr
  44. * @return array
  45. * 根据货主和发货sku 获取库存拣货位及拣货位商品数量
  46. * 并整合为sku 为key的数组
  47. */
  48. public function getEaInventoryByCustomerAndSku($customer,array $skuArr): array
  49. {
  50. $db = DB::connection("oracle");
  51. $sql = <<<sql
  52. select INV_LOT_LOC_ID.CUSTOMERID,INV_LOT_LOC_ID.SKU,INV_LOT_LOC_ID.LOCATIONID,sum(INV_LOT_LOC_ID.QTY) qty
  53. from INV_LOT_LOC_ID
  54. left join BAS_LOCATION on BAS_LOCATION.LOCATIONID = INV_LOT_LOC_ID.LOCATIONID
  55. where BAS_LOCATION.LOCATIONUSAGE = 'EA'
  56. AND customerid = ?
  57. sql;
  58. if (count($skuArr) > 0) {
  59. $sql .= " and sku in (";
  60. foreach ($skuArr as $index => $str) {
  61. if ($index == 0) {
  62. $sql .= "'" . $str . "'";
  63. continue;
  64. }
  65. $sql .= ",'" . $str . "'";
  66. }
  67. $sql .= ")";
  68. }
  69. $sql.= ' group by INV_LOT_LOC_ID.CUSTOMERID,INV_LOT_LOC_ID.SKU,INV_LOT_LOC_ID.LOCATIONID';
  70. $info= $db->select(DB::raw($sql),[$customer]);
  71. //整合同sku下的拣货库位
  72. $tmpArray = array();
  73. foreach ($info as $row) {
  74. $key = $row->sku;
  75. if (array_key_exists($key, $tmpArray)) {
  76. if (is_array($tmpArray[$key]['locationid'])) {
  77. $tmpArray[$key]['locationid'][] = $row->locationid;
  78. } else {
  79. $tmpArray[$key]['locationid'] = array($tmpArray[$key]['locationid'], $row->locationid);
  80. }
  81. if ($tmpArray[$key]['qty']) {
  82. $tmpArray[$key]['qty'] += $row->qty;
  83. } else {
  84. $tmpArray[$key]['qty'] = $row->qty;
  85. }
  86. } else {
  87. $tmpArray[$key] = array('sku'=>$row->sku,'locationid'=>array($row->locationid),'qty'=>$row->qty);
  88. }
  89. }
  90. return $tmpArray;
  91. }
  92. /**
  93. * @param $customer
  94. * @param array $skuArr
  95. * @return array
  96. * 根据货主和发货sku 获取库存存储位及存储位商品数量
  97. * 并整合为sku 为key的数组
  98. */
  99. public function getRsInventoryByCustomerAndSku($customer,array $skuArr): array
  100. {
  101. $db = DB::connection("oracle");
  102. $sql = <<<sql
  103. select INV_LOT_LOC_ID.CUSTOMERID,INV_LOT_LOC_ID.SKU,INV_LOT_LOC_ID.LOCATIONID,sum(INV_LOT_LOC_ID.QTY) qty
  104. from INV_LOT_LOC_ID
  105. left join BAS_LOCATION on BAS_LOCATION.LOCATIONID = INV_LOT_LOC_ID.LOCATIONID
  106. where BAS_LOCATION.LOCATIONUSAGE = 'RS'
  107. AND customerid = ?
  108. sql;
  109. if (count($skuArr) > 0) {
  110. $sql .= " and sku in (";
  111. foreach ($skuArr as $index => $str) {
  112. if ($index == 0) {
  113. $sql .= "'" . $str . "'";
  114. continue;
  115. }
  116. $sql .= ",'" . $str . "'";
  117. }
  118. $sql .= ")";
  119. }
  120. $sql.= ' group by INV_LOT_LOC_ID.CUSTOMERID,INV_LOT_LOC_ID.SKU,INV_LOT_LOC_ID.LOCATIONID order by qty desc';
  121. $info= $db->select(DB::raw($sql),[$customer]);
  122. //整合同sku下的存储库位
  123. $tmpArray = array();
  124. foreach ($info as $row) {
  125. $key = $row->sku;
  126. if (array_key_exists($key, $tmpArray)) {
  127. if (is_array($tmpArray[$key]['locationid'])) {
  128. if (count($tmpArray[$key]['locationid'])<5){
  129. $tmpArray[$key]['locationid'][] = $row->locationid;
  130. }
  131. } else {
  132. $tmpArray[$key]['locationid'] = array($tmpArray[$key]['locationid'], $row->locationid);
  133. }
  134. } else {
  135. $tmpArray[$key] = array('sku'=>$row->sku,'locationid'=>array($row->locationid));
  136. }
  137. }
  138. return $tmpArray;
  139. }
  140. }