AllInventoryService.php 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace App\Services;
  3. use App\Owner;
  4. use App\Traits\ModelSearchWay;
  5. use Illuminate\Support\Facades\DB;
  6. use App\Traits\ServiceAppAop;
  7. class AllInventoryService
  8. {
  9. use ServiceAppAop;
  10. use ModelSearchWay;
  11. protected $modelClass=AllInventory::class;
  12. public function getSql(array $params, $page=null, $paginate=null){
  13. $ownerCodes = app("OwnerService")->getCodeArr();
  14. $date_start=$params['date_start'] ?? null;
  15. $range = $params['range'] ?? null;
  16. if ($range)$date_start=date('Y-m-d',strtotime('-'.$range." day"));
  17. $date_end=$params['date_end'] ?? null;
  18. $TOLocation=$params['TOLocation'] ?? null;
  19. $LotAtt05=$params['LotAtt05'] ?? null;
  20. $LotAtt02_start=$params['LotAtt02_start'] ?? null;
  21. $customerid=$params['customerid'] ?? null;
  22. $SKU=$params['SKU'] ?? null;
  23. $ALTERNATE_SKU1=$params['ALTERNATE_SKU1'] ?? null;
  24. $LotAtt02_end=$params['LotAtt02_end'] ?? null;
  25. $commodityName=$params['commodity_name'] ?? null;
  26. $sql='select * from (select result.*,rownum rn from (';
  27. $sql.=' select customer.descr_c as 货主,storeStatus.CUSTOMERID 客户,storeStatus.LocationID 库位, sku.SKU 产品编码, sku.ALTERNATE_SKU1 产品条码, ';
  28. $sql.=' sku.Descr_C 商品名称, lot.LotAtt05 属性仓, lot.LotAtt08 质量状态, lot.LotAtt02 失效日期, storeStatus.ADDTIME 创建时间, ';
  29. $sql.=' lot.LotAtt04 批号 ';
  30. $sql.=' , storeStatus.QTY 在库数量, storeStatus.QtyAllocated 占用数量,count(1) over () as sum from ';
  31. $sql.=' INV_LOT_LOC_ID storeStatus';
  32. $sql.=' left join BAS_Customer customer on customer.CustomerID=storeStatus.CUSTOMERID ';
  33. $sql.=' left join BAS_SKU sku on sku.SKU=storeStatus.SKU and sku.CUSTOMERID=storeStatus.CUSTOMERID ';
  34. $sql.=' left join INV_LOT_ATT lot on lot.LOTNUM = storeStatus.LOTNUM AND lot.CUSTOMERID = storeStatus.CUSTOMERID ';
  35. if ($customerid){
  36. $sql .= ' where storeStatus.CUSTOMERID in (';
  37. $arr = explode(',',$customerid);
  38. foreach ($arr as $index => $data){
  39. if ($index != 0)$sql .= ',';
  40. $sql .= "'".$data."'";
  41. }
  42. $sql .= ') ';
  43. }
  44. if (!$customerid&&$ownerCodes){
  45. $sql .= ' where storeStatus.CUSTOMERID in (';
  46. foreach ($ownerCodes as $index => $data){
  47. if ($index != 0)$sql .= ',';
  48. $sql .= "'".$data."'";
  49. }
  50. $sql .= ') ';
  51. }
  52. $sql.=' group by storeStatus.LocationID,customer.Descr_C,sku.SKU,sku.ALTERNATE_SKU1 ';
  53. $sql.=' ,sku.Descr_C,lot.LotAtt05,lot.LotAtt08,lot.LotAtt02,lot.LotAtt04 ';
  54. $sql.=' , storeStatus.QTY, storeStatus.QtyAllocated,storeStatus.CUSTOMERID,storeStatus.ADDTIME ';
  55. $sql.=' )result where 1=1 ';
  56. if ($TOLocation)$sql=$this->sqlSearchWay($sql,$TOLocation,"库位");
  57. if ($commodityName)$sql=$this->sqlSearchWay($sql,$commodityName,"商品名称");
  58. if ($SKU)$sql=$this->sqlSearchWay($sql,$SKU,"产品编码");
  59. if ($LotAtt05)$sql=$this->sqlSearchWay($sql,$LotAtt05,"属性仓");
  60. if ($date_start)$sql.=" and 创建时间 > to_date('".$date_start." 00:00:00','yyyy-mm-dd hh24:mi:ss') ";
  61. if ($date_end)$sql.=" and 创建时间 < to_date('".$date_end." 23:59:59','yyyy-mm-dd hh24:mi:ss') ";
  62. if ($LotAtt02_start)$sql.=" and 失效日期 >='".$LotAtt02_start." 00:00:00' ";
  63. if ($LotAtt02_end)$sql.=" and 失效日期 <='".$LotAtt02_end." 23:59:59' ";
  64. if ($ALTERNATE_SKU1)$sql=$this->sqlSearchWay($sql,$ALTERNATE_SKU1,"产品条码");
  65. if ($page&&$paginate)$sql.=" and ROWNUM<='".$page*$paginate."'";
  66. $sql.=' ) ';
  67. if ($page&&$paginate)$sql.=" where rn>'".($page-1)*$paginate."'";
  68. return $sql;
  69. }
  70. public function paginate(array $params){
  71. return DB::connection('oracle')->select(DB::raw($this->getSql($params,$params['page'] ?? 1, $params['paginate'] ?? 50)));
  72. }
  73. }