StoreController.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. <?php
  2. namespace App\Http\Controllers\Api\thirdPart\flux;
  3. use App\Http\Controllers\Controller;
  4. use App\Store;
  5. use App\WMSReflectReceive;
  6. use App\WMSReflectReceiveSku;
  7. use Carbon\Carbon;
  8. use Illuminate\Support\Facades\Auth;
  9. use Illuminate\Support\Facades\DB;
  10. use Zttp\Zttp;
  11. class StoreController extends Controller
  12. {
  13. /**
  14. * 入库回传给WMS
  15. * @param Store $store
  16. * @return bool
  17. */
  18. public function accomplishToWMS(Store $store, array $inputs)
  19. {
  20. $METHOD = __METHOD__;
  21. $FUNCTION = __FUNCTION__;
  22. Controller::logS(__METHOD__, __FUNCTION__, '快递入库进入WMS接口:' . $store['asn_code']);
  23. $wmsReceiveds = WMSReflectReceive::query()->where('ASNNO', $store['asn_code'])->get();
  24. if ($wmsReceiveds->isEmpty()) {
  25. (new Controller())->log(__METHOD__, 'error_' . __FUNCTION__, '没有本地WMS入库单');
  26. return false;
  27. }
  28. $success = true;
  29. $wmsReceiveds->each(function ($wmsReceived) use (&$store, &$amountsItem, &$success, &$inputs, $METHOD, $FUNCTION) {
  30. $wmsSkus = $wmsReceived->skus()->get();
  31. $orderNumberCode = $wmsReceived['ASNREFERENCE1'] ?? $store['order_number'];
  32. $amountsSku = (function () use ($wmsSkus) {
  33. $result = [];
  34. $wmsSkus->each(function ($sku) use (&$result) {
  35. $result[$sku['id']] = $sku['EXPECTEDQTY_EACH'];
  36. });
  37. return $result;
  38. })();
  39. $skuStrList = [];
  40. $customerCode = $store->owner()->first()['code'];
  41. $wmsSkus->each(function (WMSReflectReceiveSku $sku) use (&$skuList, &$amountsItem, &$amountsSku, &$skuStrList, $wmsReceived, $customerCode, &$inputs) {
  42. $STATUS = 'ZP';
  43. if (isset($inputs['quality']) && $inputs['quality']
  44. && $inputs['quality'] != '正品') {
  45. $STATUS = 'CC';
  46. }
  47. $repositoryCode = $sku['LOTATT05'];
  48. if (isset($inputs['depository_code']) && $inputs['depository_code']) {
  49. $repositoryCode = $inputs['depository_code'];
  50. }
  51. $skuStr = "
  52. {
  53. \"ORDERNUMBERCODE\": \"{$wmsReceived['ASNNO']}\",
  54. \"ASNLINENO\": \"{$sku['ASNLINENO']}\",
  55. \"SKUCODE\": \"{$sku['SKU']}\",
  56. \"QUANTITY\": \"{$sku['EXPECTEDQTY_EACH']}\",
  57. \"LOTATT04\": \"{$sku['LOTATT04']}\",
  58. \"LOTATT05\": \"{$repositoryCode}\",
  59. \"STATUS\": \"{$STATUS}\",
  60. \"USERDEFINE1\": \"{$inputs['follow_code']}\",
  61. \"USERDEFINE2\": \"\",
  62. \"USERDEFINE3\": \"\",
  63. \"UNIQUE_CODE_LIST\": [" .
  64. "]
  65. }
  66. ";
  67. $skuStrList[] = $skuStr;
  68. });
  69. $skuStrList = implode(',', $skuStrList);
  70. $json = "
  71. {
  72. \"request\": [
  73. {
  74. \"ORDERNUMBERCODE\": \"{$wmsReceived['ASNNO']}\",
  75. \"CUSTOMERID\": \"{$wmsReceived['CUSTOMERID']}\",
  76. \"ASNTYPE\": \"{$wmsReceived['ASNTYPE']}\",
  77. \"ASNREFERENCE1\": \"{$wmsReceived['ASNREFERENCE1']}\",
  78. \"ADDWHO\": \"WCS\",
  79. \"USERDEFINE1\": \"\",
  80. \"USERDEFINE2\": \"\",
  81. \"USERDEFINE3\": \"\",
  82. \"SKU_LIST\": [{$skuStrList}]
  83. }
  84. ]
  85. }
  86. ";
  87. $sendingJson = json_decode($json, true);
  88. $url = url(config('api.flux.receive.new'));
  89. // (new Controller())->log($METHOD,$FUNCTION,$store['asn_code'].'||' .json_encode($sendingJson));
  90. Controller::logS(__METHOD__, __FUNCTION__, '快递入库请求WMS接口开始:' . $store['asn_code']);
  91. $response = Zttp::post($url, $sendingJson);
  92. Controller::logS(__METHOD__, __FUNCTION__, '快递入库请求WMS接口结束:' . $store['asn_code'] . '||' . $response->body());
  93. $noIssues = true;
  94. $json = $response->json();
  95. if (!$json || !isset($json['Response']) || !$json['Response']['return']['returnFlag'] == '1') {
  96. $noIssues = false;
  97. }
  98. if ($json && isset($json['Response'])) {
  99. if ($json['Response']['return']['returnFlag'] == '2') {
  100. (new Controller())->log($METHOD, 'error_' . $FUNCTION, $store['asn_code'] . '||' . $response->body());
  101. return true;
  102. }
  103. // if(isset($json['Response']['return']['returnDesc'])&&strpos($json['Response']['return']['returnDesc'],'唯一约束')!==false){
  104. // (new Controller())->log($METHOD,'error_'.$FUNCTION,$response->body());
  105. // return true;
  106. // }
  107. if (isset($json['Response']['return']['errordescr']) && strpos($json['Response']['return']['errordescr'], '已完成') !== false) {
  108. (new Controller())->log($METHOD, 'error_' . $FUNCTION, $store['asn_code'] . '||' . $response->body());
  109. return true;
  110. }
  111. }
  112. if ($noIssues && $json['Response']['return']['returnFlag'] == '1') {
  113. $wmsReceived['is_uploaded'] = 1;
  114. $wmsReceived->save();
  115. (new Controller())->log($METHOD, 'success_' . $FUNCTION, $store['asn_code'] . '||' . $response->body());
  116. return true;
  117. } else {
  118. $success = false;
  119. (new Controller())->log($METHOD, 'error_' . $FUNCTION, $store['asn_code'] . '||' . $response->body());
  120. }
  121. });
  122. return $success;
  123. }
  124. public function quickStorage_temp($docno)
  125. {
  126. $db = DB::connection('oracle');
  127. //判断单据有效性
  128. $cus_bs_asnheader = $db->select(DB::raw("SELECT t.addwho FROM CUS_BS_ASNHEADER t WHERE t.ASNREFERENCE1 = '" . $docno . "'"));
  129. if (!$cus_bs_asnheader) return ['success' => false, 'data' => '单据不存在'];
  130. $addwho = $cus_bs_asnheader[0]->addwho;
  131. if ($addwho == "WCS") {
  132. //判断单据状态
  133. $cus_bs_asnheader = $db->select(
  134. DB::raw("SELECT 1 FROM CUS_BS_ASNHEADER t INNER JOIN DOC_ASN_HEADER a ON a.asnno = t.asnno WHERE t.asnreference1 = '" . $docno . "' AND a.asnstatus < '40'"));
  135. if (!$cus_bs_asnheader) return ['success' => false, 'data' => "该单据已完成收货"];
  136. $sql = "select a.warehouseid,a.asnno as docno,a1.asnlineno,a.customerid,t1.sku,a1.packid,t1.receivedqty_each,t1.lotatt01,t1.lotatt02,";
  137. $sql .= " t1.lotatt04,t1.lotatt05,t1.lotatt08,t1.userdefine1 as new_traceid,a.userdefine1,a.userdefine2,a.userdefine3,a.userdefine4,a.userdefine5,t.addwho";
  138. $sql .= " from doc_asn_details a1";
  139. $sql .= " inner join doc_asn_header a on a.asnno = a1.asnno";
  140. $sql .= " inner join cus_bs_asndetails t1 on t1.asnno = a.asnno and t1.asnlineno = a1.asnlineno";
  141. $sql .= " inner join cus_bs_asnheader t on t.asnno = a1.asnno";
  142. $sql .= " where t.asnreference1 = '" . $docno . "' and nvl(t1.rcvflag,'N') = 'N'";
  143. $doc_asn_details = $db->select(DB::raw($sql));
  144. $db->beginTransaction();
  145. try {
  146. $username = config('database.connections.oracle.username');
  147. $password = config('database.connections.oracle.password');
  148. $host = config('database.connections.oracle.host');
  149. $service_name = config('database.connections.oracle.service_name');
  150. $conn = oci_connect($username, $password, $host . '/' . $service_name);
  151. $sql_sp = "begin SPASN_Receiving_Process(:IN_Warehouse, :In_Process_Action, :In_ASNNo_C, :In_ASNLineNo_C, :In_FMTraceID_C, :In_New_TraceID_C, :In_ProductStatus," .
  152. ":In_ProductStatus_Descr, :In_HoldRejectCode_C, :In_HoldRejectReason_C, :In_PONo_C, :In_CustomerID, :In_SKU, :In_ReceivedQty, :In_RejectedQty,:In_UOM, :In_PackID," .
  153. " :In_ContainerID, :In_LotAtt01_C, :In_LotAtt02_C, :In_LotAtt03_C, :In_LotAtt04_C, :In_LotAtt05_C, :In_LotAtt06_C," .
  154. ":In_LotAtt07_C, :In_LotAtt08_C, :In_LotAtt09_C, :In_LotAtt10_C, :In_LotAtt11_C, :In_LotAtt12_C," .
  155. ":In_TotalCubic, :In_TotalGrossWeight, :In_TotalNetWeight, :In_TotalPrice, :In_UserDefine1, :In_UserDefine2,:In_UserDefine3, :In_UserDefine4, :In_UserDefine5, :In_FMLocation," .
  156. ":In_TOLocation_C,:In_QC_Type_C, :In_PlanToLoc_C,:In_ReceivingTime, :In_LPN, :In_Operator, :IN_RCVModule, :IN_RCVStation, :In_Language, :In_UserID, :OUT_Return_Code); end;";
  157. foreach ($doc_asn_details as $doc_asn_detail) {
  158. $IN_Warehouse = $doc_asn_detail->warehouseid ?? '';
  159. $In_Process_Action = '3';
  160. $In_ASNNo_C = $doc_asn_detail->docno ?? '';
  161. $In_ASNLineNo_C = $doc_asn_detail->asnlineno ?? '';
  162. $In_FMTraceID_C = '';
  163. $In_New_TraceID_C = $doc_asn_detail->new_traceid ?? '';
  164. $In_ProductStatus = '00';
  165. $In_ProductStatus_Descr = '正常';
  166. $In_HoldRejectCode_C = 'OK';
  167. $In_HoldRejectReason_C = '正常';
  168. $In_PONo_C = '';
  169. $In_CustomerID = $doc_asn_detail->customerid ?? '';
  170. $In_SKU = $doc_asn_detail->sku ?? '';
  171. $In_ReceivedQty = $doc_asn_detail->receivedqty_each ?? '';
  172. $In_RejectedQty = '';
  173. $In_UOM = 'EA';
  174. $In_PackID = $doc_asn_detail->packid ?? '';
  175. $In_ContainerID = '';
  176. $In_LotAtt01_C = $doc_asn_detail->lotatt01 ?? '';
  177. $In_LotAtt02_C = $doc_asn_detail->lotatt02 ?? '';
  178. $In_LotAtt03_C = '';
  179. $In_LotAtt04_C = $doc_asn_detail->lotatt04 ?? '';
  180. $In_LotAtt05_C = $doc_asn_detail->lotatt05 ?? '';
  181. $In_LotAtt06_C = '';
  182. $In_LotAtt07_C = '';
  183. $In_LotAtt08_C = $doc_asn_detail->lotatt08 ?? '';
  184. $In_LotAtt09_C = '';
  185. $In_LotAtt10_C = '';
  186. $In_LotAtt11_C = '';
  187. $In_LotAtt12_C = '';
  188. $In_TotalCubic = '0.00';
  189. $In_TotalGrossWeight = '0.00';
  190. $In_TotalNetWeight = '0.00';
  191. $In_TotalPrice = '0.00';
  192. $In_UserDefine1 = $doc_asn_detail->userdefine1 ?? '';
  193. $In_UserDefine2 = $doc_asn_detail->userdefine2 ?? '';
  194. $In_UserDefine3 = $doc_asn_detail->userdefine3 ?? '';
  195. $In_UserDefine4 = $doc_asn_detail->userdefine4 ?? '';
  196. $In_UserDefine5 = $doc_asn_detail->userdefine5 ?? '';
  197. $In_FMLocation = 'STAGE' . $doc_asn_detail->warehouseid;
  198. $In_TOLocation_C = 'STAGE' . $doc_asn_detail->warehouseid;
  199. $In_QC_Type_C = 'OK';
  200. $In_PlanToLoc_C = '';
  201. $In_ReceivingTime = '';
  202. $In_LPN = '*';
  203. $In_Operator = $doc_asn_detail->addwho ?? '';
  204. $IN_RCVModule = '';
  205. $IN_RCVStation = '';
  206. $In_Language = 'cn';
  207. $In_UserID = $doc_asn_detail->addwho ?? '';
  208. $result = '';
  209. $stmt = oci_parse($conn, $sql_sp);
  210. oci_bind_by_name($stmt, ':IN_Warehouse', $IN_Warehouse);
  211. oci_bind_by_name($stmt, ':In_Process_Action', $In_Process_Action);
  212. oci_bind_by_name($stmt, ':In_ASNNo_C', $In_ASNNo_C);
  213. oci_bind_by_name($stmt, ':In_ASNLineNo_C', $In_ASNLineNo_C);
  214. oci_bind_by_name($stmt, ':In_FMTraceID_C', $In_FMTraceID_C);
  215. oci_bind_by_name($stmt, ':In_New_TraceID_C', $In_New_TraceID_C);
  216. oci_bind_by_name($stmt, ':In_ProductStatus', $In_ProductStatus);
  217. oci_bind_by_name($stmt, ':In_ProductStatus_Descr', $In_ProductStatus_Descr);
  218. oci_bind_by_name($stmt, ':In_HoldRejectCode_C', $In_HoldRejectCode_C);
  219. oci_bind_by_name($stmt, ':In_HoldRejectReason_C', $In_HoldRejectReason_C);
  220. oci_bind_by_name($stmt, ':In_PONo_C', $In_PONo_C);
  221. oci_bind_by_name($stmt, ':In_CustomerID', $In_CustomerID);
  222. oci_bind_by_name($stmt, ':In_SKU', $In_SKU);
  223. oci_bind_by_name($stmt, ':In_ReceivedQty', $In_ReceivedQty);
  224. oci_bind_by_name($stmt, ':In_RejectedQty', $In_RejectedQty);
  225. oci_bind_by_name($stmt, ':In_UOM', $In_UOM);
  226. oci_bind_by_name($stmt, ':In_PackID', $In_PackID);
  227. oci_bind_by_name($stmt, ':In_ContainerID', $In_ContainerID);
  228. oci_bind_by_name($stmt, ':In_LotAtt01_C', $In_LotAtt01_C);
  229. oci_bind_by_name($stmt, ':In_LotAtt02_C', $In_LotAtt02_C);
  230. oci_bind_by_name($stmt, ':In_LotAtt03_C', $In_LotAtt03_C);
  231. oci_bind_by_name($stmt, ':In_LotAtt04_C', $In_LotAtt04_C);
  232. oci_bind_by_name($stmt, ':In_LotAtt05_C', $In_LotAtt05_C);
  233. oci_bind_by_name($stmt, ':In_LotAtt06_C', $In_LotAtt06_C);
  234. oci_bind_by_name($stmt, ':In_LotAtt07_C', $In_LotAtt07_C);
  235. oci_bind_by_name($stmt, ':In_LotAtt08_C', $In_LotAtt08_C);
  236. oci_bind_by_name($stmt, ':In_LotAtt09_C', $In_LotAtt09_C);
  237. oci_bind_by_name($stmt, ':In_LotAtt10_C', $In_LotAtt10_C);
  238. oci_bind_by_name($stmt, ':In_LotAtt11_C', $In_LotAtt11_C);
  239. oci_bind_by_name($stmt, ':In_LotAtt12_C', $In_LotAtt12_C);
  240. oci_bind_by_name($stmt, ':In_TotalCubic', $In_TotalCubic);
  241. oci_bind_by_name($stmt, ':In_TotalGrossWeight', $In_TotalGrossWeight);
  242. oci_bind_by_name($stmt, ':In_TotalNetWeight', $In_TotalNetWeight);
  243. oci_bind_by_name($stmt, ':In_TotalPrice', $In_TotalPrice);
  244. oci_bind_by_name($stmt, ':In_UserDefine1', $In_UserDefine1);
  245. oci_bind_by_name($stmt, ':In_UserDefine2', $In_UserDefine2);
  246. oci_bind_by_name($stmt, ':In_UserDefine3', $In_UserDefine3);
  247. oci_bind_by_name($stmt, ':In_UserDefine4', $In_UserDefine4);
  248. oci_bind_by_name($stmt, ':In_UserDefine5', $In_UserDefine5);
  249. oci_bind_by_name($stmt, ':In_FMLocation', $In_FMLocation);
  250. oci_bind_by_name($stmt, ':In_TOLocation_C', $In_TOLocation_C);
  251. oci_bind_by_name($stmt, ':In_QC_Type_C', $In_QC_Type_C);
  252. oci_bind_by_name($stmt, ':In_PlanToLoc_C', $In_PlanToLoc_C);
  253. oci_bind_by_name($stmt, ':In_ReceivingTime', $In_ReceivingTime);
  254. oci_bind_by_name($stmt, ':In_LPN', $In_LPN);
  255. oci_bind_by_name($stmt, ':In_Operator', $In_Operator);
  256. oci_bind_by_name($stmt, ':IN_RCVModule', $IN_RCVModule);
  257. oci_bind_by_name($stmt, ':IN_RCVStation', $IN_RCVStation);
  258. oci_bind_by_name($stmt, ':In_Language', $In_Language);
  259. oci_bind_by_name($stmt, ':In_UserID', $In_UserID);
  260. oci_bind_by_name($stmt, ':OUT_Return_Code', $result);
  261. oci_execute($stmt);
  262. oci_close($conn);
  263. if (substr($result, 0, 3) == '000') {
  264. $query = DB::raw("update cus_bs_asndetails t set t.rcvflag = 'Y' where t.asnno = ? and t.asnlineno = ?");
  265. $db->update($query, [$doc_asn_detail->docno, $doc_asn_detail->asnlineno]);
  266. } else {
  267. $query = DB::raw("update cus_bs_asndetails t set t.rcvflag = 'W' where t.asnno = ? and t.asnlineno = ?");
  268. $db->update($query, [$doc_asn_detail->docno, $doc_asn_detail->asnlineno]);
  269. $db->rollBack();
  270. return ['success' => false, 'data' => '收货失败', 'code' => $result];
  271. }
  272. }
  273. $db->commit();
  274. return ['success' => true];
  275. } catch (\Exception $e) {
  276. $db->rollBack();
  277. return ['success' => false, 'data' => $e->getMessage()];
  278. }
  279. }
  280. }
  281. }