ReviewService.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <?php
  2. namespace App\Services;
  3. use App\OracleActAllocationDetails;
  4. use App\OracleDOCOrderHeader;
  5. use App\OracleDOCOrderPackings;
  6. use App\Traits\ServiceAppAop;
  7. use Doctrine\DBAL\Driver\PDOConnection;
  8. use Illuminate\Support\Collection;
  9. use Illuminate\Support\Facades\DB;
  10. use PDO;
  11. class ReviewService
  12. {
  13. use ServiceAppAop;
  14. //单品复核
  15. /**
  16. * @param $IN_Warehouse
  17. * @param $IN_CustomerID
  18. * @param $IN_WaveNo
  19. * @param $IN_SKU
  20. * @param $IN_CheckModule
  21. * @param $IN_WorkStation
  22. * @param $IN_Language
  23. * @param $IN_UserID
  24. * @param $OUT_AllocationDetailsID
  25. * @param $OUT_TOID
  26. * @param $OUT_OrderNo
  27. * @param $OUT_Return_Code
  28. */
  29. public function single($IN_Warehouse, $IN_CustomerID, $IN_WaveNo, $IN_SKU, $IN_CheckModule, $IN_WorkStation, $IN_Language, $IN_UserID, $OUT_AllocationDetailsID, $OUT_TOID, $OUT_OrderNo, $OUT_Return_Code)
  30. {
  31. DB::beginTransaction();
  32. try {
  33. $r_CurrentTime = now()->toDateTimeString();
  34. $r_SGL_ORD_PCK = $this->getsys_configuration($IN_Warehouse, '*', '*', 'SGL_ORD_PCK');//防止并发错误
  35. $sql = <<<sql
  36. Select a.OrderNo,AllocationDetailsID,a.SKU,PickToTraceID
  37. ,c.CarrierID, requiredeliveryno, nvl(c.channel,' * ')
  38. ,c.Erpcancelflag
  39. From ACT_Allocation_Details a inner join
  40. DOC_Order_Details b on a.OrderNo=b.OrderNo and a.OrderLineNo=b.OrderLineNo inner join
  41. DOC_Order_Header c on b.OrderNo=c.OrderNo
  42. sql;
  43. if ((!empty($IN_WaveNo)) && $IN_WaveNo !== '*') {
  44. $sql .= " inner join DOC_Wave_Details d on d.OrderNo=c.OrderNo and d.WaveNo=:WaveNo and a.WaveNo=:WaveNo ";
  45. }
  46. $sql .= " Where a.CustomerID=:CustomerID and a.SKU=:SKU and c.SingleMatch='Y'
  47. and b.CommingleSKU='N' and a.PackFlag='N'
  48. and c.releasestatus <> 'H'
  49. and c.Warehouseid = :Warehouse
  50. AND c.Sostatus < '80' ";
  51. if ($r_SGL_ORD_PCK === 'N' || $r_SGL_ORD_PCK === 'NO') {
  52. $sql .= " and a.status <'80' ";
  53. } else {
  54. $sql .= " and a.status <'60' ";
  55. }
  56. $sql .= " and not exists(select 1 from SYS_Check_Exception where AllocationDetailsID = a.AllocationDetailsID and taskprocess<>'99' )
  57. and rownum = 1 for update";
  58. $result = DB::connection('oracle')->selectOne(DB::raw($sql), [
  59. 'WaveNo' => $IN_WaveNo,
  60. 'CustomerID' => $IN_CustomerID,
  61. 'Warehouse' => $IN_Warehouse,
  62. ]);
  63. $OUT_OrderNo = $result->OrderNo;
  64. $OUT_AllocationDetailsID = $result->AllocationDetailsID;
  65. $r_SKU = $result->SKU;
  66. $r_PickToTraceID = $result->PickToTraceID;
  67. $r_CarrierID = $result->CarrierID;
  68. $r_requiredeliveryno = $result->requiredeliveryno;
  69. $r_channel = $result->channel;
  70. $r_Erpcancelflag = $result->Erpcancelflag;
  71. //更新分配详情
  72. OracleActAllocationDetails::query()
  73. ->where('allocationdetailsid', $OUT_AllocationDetailsID)
  74. ->update([
  75. 'CheckModule' => $IN_CheckModule,
  76. ]);
  77. if ($r_Erpcancelflag === 'Y') {
  78. $OUT_Return_Code = '000CANCEL';
  79. }
  80. //如果复核时没有使用新的ID,则取分配明细的ID
  81. if (empty($OUT_TOID) || $OUT_TOID === '*') {
  82. $r_DEL_DOC_SN = $this->lock($IN_Warehouse, $IN_CustomerID, '*', 'DEL_DOC_SN#');
  83. if ($r_DEL_DOC_SN === 'C' && $r_requiredeliveryno === 'Y') {
  84. $OUT_Return_Code = '*_*';
  85. $r_ParaTemp = 'DELIVERYNO' . $OUT_OrderNo;
  86. // 获取数据表的ID(PO, ASN, SO...)
  87. list($IN_Warehouse, $IN_Language, $r_ParaTemp, $OUT_TOID, $OUT_Return_Code) = $this->SPCOM_GetIDSequence($IN_Warehouse, $IN_Language, $r_ParaTemp, $OUT_TOID, $OUT_Return_Code);
  88. if (substr($OUT_Return_Code, 0, 3) !== '000') {
  89. return;
  90. }
  91. } else {
  92. $OUT_TOID = $r_PickToTraceID;
  93. }
  94. }
  95. //取消装箱确认
  96. OracleDOCOrderPackings::query()
  97. ->where('TraceID', $OUT_TOID)
  98. ->delete();
  99. OracleDOCOrderPackings::query()->create([
  100. 'TraceID' => $OUT_TOID,
  101. 'SKU' => $IN_SKU,
  102. 'OrderNo' => $OUT_OrderNo,
  103. 'Qty' => 1,
  104. 'AddTime' => $r_CurrentTime,
  105. 'AddWho' => $IN_UserID,
  106. 'EditTime' => $r_CurrentTime,
  107. 'EditWho' => $IN_UserID,
  108. 'AllocationDetailsID' => $OUT_AllocationDetailsID,
  109. 'FROMTRACEID' => $OUT_TOID,
  110. ]);
  111. DB::commit();
  112. $OUT_Return_Code = '*_*SINGLE';
  113. list ($IN_Warehouse, $IN_CHK_TYP, $IN_TraceID, $IN_CheckModule, $IN_WorkStation, $IN_Language, $IN_UserID, $OUT_Return_Code) =
  114. $this->SPSO_Cartonization_Process($IN_Warehouse, 'ORDER', $OUT_TOID, $IN_CheckModule, $IN_WorkStation, $IN_Language, $IN_UserID, $OUT_Return_Code);
  115. if (substr($OUT_Return_Code, 1, 3) !== '000') {
  116. DB::rollBack();
  117. return;
  118. }
  119. if (!OracleActAllocationDetails::query()->where('orderno', $OUT_OrderNo)->where('PackFlag', 'N')->where('rownum', 1)->exists()) {
  120. OracleDOCOrderHeader::query()
  121. ->where('orderno', $OUT_OrderNo)
  122. ->update([
  123. 'ReleaseStatus' => 'Y',
  124. ]);
  125. }
  126. DB::commit();
  127. $OUT_Return_Code = '000';
  128. } catch (\Exception $e) {
  129. DB::rollBack();
  130. }
  131. }
  132. public function getsys_configuration($IN_WarehouseID, $IN_CustomerID, $IN_OrderType, $IN_ConfigID, $IN_DefaultValue = 'N', $IN_ValueType = 'C')
  133. {
  134. $conn = $this->getOciConnection();
  135. $sql_sp = "begin GETSYS_configuration(
  136. :IN_WarehouseID,
  137. :IN_CustomerID,
  138. :IN_OrderType,
  139. :IN_ConfigID,
  140. :IN_DefaultValue,
  141. :IN_ValueType
  142. ); end;";
  143. $stmt = oci_parse($conn, $sql_sp);
  144. oci_bind_by_name($stmt, ':IN_WarehouseID', $IN_WarehouseID);
  145. oci_bind_by_name($stmt, ':IN_CustomerID', $IN_CustomerID);
  146. oci_bind_by_name($stmt, ':IN_OrderType', $IN_OrderType);
  147. oci_bind_by_name($stmt, ':IN_ConfigID', $IN_ConfigID);
  148. oci_bind_by_name($stmt, ':IN_DefaultValue', $IN_DefaultValue);
  149. oci_bind_by_name($stmt, ':IN_ValueType', $IN_ValueType);
  150. $r_SGL_ORD_PCK = oci_execute($stmt);
  151. oci_close($conn);
  152. return $r_SGL_ORD_PCK;
  153. }
  154. public function SPSO_Cartonization_Process($IN_Warehouse, $IN_CHK_TYP, $IN_TraceID, $IN_CheckModule, $IN_WorkStation, $IN_Language, $IN_UserID, $OUT_Return_Code): array
  155. {
  156. $conn = $this->getOciConnection();
  157. $sql_sp = "begin SPCOM_GetIDSequence(
  158. :IN_Warehouse,
  159. :IN_CHK_TYP,
  160. :IN_TraceID,
  161. :IN_CheckModule,
  162. :IN_WorkStation
  163. :IN_Language
  164. :IN_UserID
  165. :OUT_Return_Code
  166. ); end;";
  167. $stmt = oci_parse($conn, $sql_sp);
  168. oci_bind_by_name($stmt, ':IN_Warehouse', $IN_Warehouse);
  169. oci_bind_by_name($stmt, ':IN_CHK_TYP', $IN_CHK_TYP);
  170. oci_bind_by_name($stmt, ':IN_TraceID', $IN_TraceID);
  171. oci_bind_by_name($stmt, ':IN_CheckModule', $IN_CheckModule);
  172. oci_bind_by_name($stmt, ':IN_WorkStation', $IN_WorkStation);
  173. oci_bind_by_name($stmt, ':IN_Language', $IN_Language);
  174. oci_bind_by_name($stmt, ':IN_UserID', $IN_UserID);
  175. oci_bind_by_name($stmt, ':OUT_Return_Code', $OUT_Return_Code);
  176. oci_execute($stmt);
  177. oci_close($conn);
  178. return array($IN_Warehouse, $IN_CHK_TYP, $IN_TraceID, $IN_CheckModule, $IN_WorkStation, $IN_Language, $IN_UserID, $OUT_Return_Code);
  179. }
  180. /**
  181. * 获取数据表的ID(PO, ASN, SO...)
  182. * @param $IN_Warehouse
  183. * @param $IN_Language
  184. * @param $r_ParaTemp
  185. * @param $OUT_TOID
  186. * @param $OUT_Return_Code
  187. * @return array
  188. */
  189. public function SPCOM_GetIDSequence($IN_Warehouse, $IN_Language, $r_ParaTemp, $OUT_TOID, $OUT_Return_Code): array
  190. {
  191. $conn = $this->getOciConnection();
  192. $sql_sp = "begin SPCOM_GetIDSequence(
  193. :IN_Warehouse,
  194. :IN_Language,
  195. :r_ParaTemp,
  196. :OUT_TOID,
  197. :OUT_Return_Code
  198. ); end;";
  199. $stmt = oci_parse($conn, $sql_sp);
  200. oci_bind_by_name($stmt, ':IN_Warehouse', $IN_Warehouse);
  201. oci_bind_by_name($stmt, ':IN_Language', $IN_Language);
  202. oci_bind_by_name($stmt, ':r_ParaTemp', $r_ParaTemp);
  203. oci_bind_by_name($stmt, ':OUT_TOID', $OUT_TOID);
  204. oci_bind_by_name($stmt, ':OUT_Return_Code', $OUT_Return_Code);
  205. oci_execute($stmt);
  206. oci_close($conn);
  207. return array($IN_Warehouse, $IN_Language, $r_ParaTemp, $OUT_TOID, $OUT_Return_Code);
  208. }
  209. /**
  210. * @return false|resource
  211. */
  212. private function getOciConnection()
  213. {
  214. $username = config('database.connections.oracle.username');
  215. $password = config('database.connections.oracle.password');
  216. $host = config('database.connections.oracle.host');
  217. $service_name = config('database.connections.oracle.service_name');
  218. return oci_connect($username, $password, $host . '/' . $service_name, 'utf8'); //连接oracle数据库
  219. }
  220. }