AllInventoryService.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. $sql='select * from (select result.*,rownum rn from (';
  26. $sql.=' select customer.descr_c as 货主,storeStatus.CUSTOMERID 客户,storeStatus.LocationID 库位, sku.SKU 产品编码, sku.ALTERNATE_SKU1 产品条码, ';
  27. $sql.=' sku.Descr_C 商品名称, lot.LotAtt05 属性仓, lot.LotAtt08 质量状态, lot.LotAtt02 失效日期, storeStatus.ADDTIME 创建时间, ';
  28. $sql.=' lot.LotAtt04 批号 ';
  29. $sql.=' , storeStatus.QTY 在库数量, storeStatus.QtyAllocated 占用数量,count(1) over () as sum from ';
  30. $sql.=' INV_LOT_LOC_ID storeStatus';
  31. $sql.=' left join BAS_Customer customer on customer.CustomerID=storeStatus.CUSTOMERID ';
  32. $sql.=' left join BAS_SKU sku on sku.SKU=storeStatus.SKU and sku.CUSTOMERID=storeStatus.CUSTOMERID ';
  33. $sql.=' left join INV_LOT_ATT lot on lot.LOTNUM = storeStatus.LOTNUM AND lot.CUSTOMERID = storeStatus.CUSTOMERID ';
  34. if ($customerid){
  35. $sql .= ' where storeStatus.CUSTOMERID in (';
  36. $arr = explode(',',$customerid);
  37. foreach ($arr as $index => $data){
  38. if ($index != 0)$sql .= ',';
  39. $sql .= "'".$data."'";
  40. }
  41. $sql .= ') ';
  42. }
  43. if (!$customerid&&$ownerCodes){
  44. $sql .= ' where storeStatus.CUSTOMERID in (';
  45. foreach ($ownerCodes as $index => $data){
  46. if ($index != 0)$sql .= ',';
  47. $sql .= "'".$data."'";
  48. }
  49. $sql .= ') ';
  50. }
  51. $sql.=' group by storeStatus.LocationID,customer.Descr_C,sku.SKU,sku.ALTERNATE_SKU1 ';
  52. $sql.=' ,sku.Descr_C,lot.LotAtt05,lot.LotAtt08,lot.LotAtt02,lot.LotAtt04 ';
  53. $sql.=' , storeStatus.QTY, storeStatus.QtyAllocated,storeStatus.CUSTOMERID,storeStatus.ADDTIME ';
  54. $sql.=' )result where 1=1 ';
  55. // if ($TOLocation)$sql .= " and 库位 like '".$TOLocation."' ";
  56. // if ($SKU)$sql.=" and 产品编码 like '".$SKU."' ";
  57. // if ($LotAtt05)$sql .=" and 属性仓 like '".$LotAtt05."' ";
  58. if ($TOLocation)$sql=$this->sqlSearchWay($sql,$TOLocation,"库位");
  59. if ($SKU)$sql=$this->sqlSearchWay($sql,$SKU,"产品编码");
  60. if ($LotAtt05)$sql=$this->sqlSearchWay($sql,$LotAtt05,"属性仓");
  61. if ($date_start)$sql.=" and 创建时间 > to_date('".$date_start." 00:00:00','yyyy-mm-dd hh24:mi:ss') ";
  62. if ($date_end)$sql.=" and 创建时间 < to_date('".$date_end." 23:59:59','yyyy-mm-dd hh24:mi:ss') ";
  63. if ($LotAtt02_start)$sql.=" and 失效日期 >='".$LotAtt02_start." 00:00:00' ";
  64. if ($LotAtt02_end)$sql.=" and 失效日期 <='".$LotAtt02_end." 23:59:59' ";
  65. // if ($ALTERNATE_SKU1)$sql.=" and 产品条码 like '".$ALTERNATE_SKU1."' ";
  66. if ($ALTERNATE_SKU1)$sql=$this->sqlSearchWay($sql,$ALTERNATE_SKU1,"产品条码");
  67. if ($page&&$paginate)$sql.=" and ROWNUM<='".$page*$paginate."'";
  68. $sql.=' ) ';
  69. if ($page&&$paginate)$sql.=" where rn>'".($page-1)*$paginate."'";
  70. return $sql;
  71. }
  72. public function paginate(array $params){
  73. return DB::connection('oracle')->select(DB::raw($this->getSql($params,$params['page'] ?? 1, $params['paginate'] ?? 50)));
  74. }
  75. }