| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291 |
- <?php
- namespace App\Http\Controllers\Api\thirdPart\flux;
- use App\Http\Controllers\Controller;
- use App\Store;
- use App\WMSReflectReceive;
- use App\WMSReflectReceiveSku;
- use Carbon\Carbon;
- use Illuminate\Support\Facades\Auth;
- use Illuminate\Support\Facades\DB;
- use Zttp\Zttp;
- class StoreController extends Controller
- {
- /**
- * 入库回传给WMS
- * @param Store $store
- * @return bool
- */
- public function accomplishToWMS(Store $store, array $inputs)
- {
- $METHOD = __METHOD__;
- $FUNCTION = __FUNCTION__;
- Controller::logS(__METHOD__, __FUNCTION__, '快递入库进入WMS接口:' . $store['asn_code']);
- $wmsReceiveds = WMSReflectReceive::query()->where('ASNNO', $store['asn_code'])->get();
- if ($wmsReceiveds->isEmpty()) {
- (new Controller())->log(__METHOD__, 'error_' . __FUNCTION__, '没有本地WMS入库单');
- return false;
- }
- $success = true;
- $wmsReceiveds->each(function ($wmsReceived) use (&$store, &$amountsItem, &$success, &$inputs, $METHOD, $FUNCTION) {
- $wmsSkus = $wmsReceived->skus()->get();
- $orderNumberCode = $wmsReceived['ASNREFERENCE1'] ?? $store['order_number'];
- $amountsSku = (function () use ($wmsSkus) {
- $result = [];
- $wmsSkus->each(function ($sku) use (&$result) {
- $result[$sku['id']] = $sku['EXPECTEDQTY_EACH'];
- });
- return $result;
- })();
- $skuStrList = [];
- $customerCode = $store->owner()->first()['code'];
- $wmsSkus->each(function (WMSReflectReceiveSku $sku) use (&$skuList, &$amountsItem, &$amountsSku, &$skuStrList, $wmsReceived, $customerCode, &$inputs) {
- $STATUS = 'ZP';
- if (isset($inputs['quality']) && $inputs['quality']
- && $inputs['quality'] != '正品') {
- $STATUS = 'CC';
- }
- $repositoryCode = $sku['LOTATT05'];
- if (isset($inputs['depository_code']) && $inputs['depository_code']) {
- $repositoryCode = $inputs['depository_code'];
- }
- $skuStr = "
- {
- \"ORDERNUMBERCODE\": \"{$wmsReceived['ASNNO']}\",
- \"ASNLINENO\": \"{$sku['ASNLINENO']}\",
- \"SKUCODE\": \"{$sku['SKU']}\",
- \"QUANTITY\": \"{$sku['EXPECTEDQTY_EACH']}\",
- \"LOTATT04\": \"{$sku['LOTATT04']}\",
- \"LOTATT05\": \"{$repositoryCode}\",
- \"STATUS\": \"{$STATUS}\",
- \"USERDEFINE1\": \"{$inputs['follow_code']}\",
- \"USERDEFINE2\": \"\",
- \"USERDEFINE3\": \"\",
- \"UNIQUE_CODE_LIST\": [" .
- "]
- }
- ";
- $skuStrList[] = $skuStr;
- });
- $skuStrList = implode(',', $skuStrList);
- $json = "
- {
- \"request\": [
- {
- \"ORDERNUMBERCODE\": \"{$wmsReceived['ASNNO']}\",
- \"CUSTOMERID\": \"{$wmsReceived['CUSTOMERID']}\",
- \"ASNTYPE\": \"{$wmsReceived['ASNTYPE']}\",
- \"ASNREFERENCE1\": \"{$wmsReceived['ASNREFERENCE1']}\",
- \"ADDWHO\": \"WCS\",
- \"USERDEFINE1\": \"\",
- \"USERDEFINE2\": \"\",
- \"USERDEFINE3\": \"\",
- \"SKU_LIST\": [{$skuStrList}]
- }
- ]
- }
- ";
- $sendingJson = json_decode($json, true);
- $url = url(config('api.flux.receive.new'));
- // (new Controller())->log($METHOD,$FUNCTION,$store['asn_code'].'||' .json_encode($sendingJson));
- Controller::logS(__METHOD__, __FUNCTION__, '快递入库请求WMS接口开始:' . $store['asn_code']);
- $response = Zttp::post($url, $sendingJson);
- Controller::logS(__METHOD__, __FUNCTION__, '快递入库请求WMS接口结束:' . $store['asn_code'] . '||' . $response->body());
- $noIssues = true;
- $json = $response->json();
- if (!$json || !isset($json['Response']) || !$json['Response']['return']['returnFlag'] == '1') {
- $noIssues = false;
- }
- if ($json && isset($json['Response'])) {
- if ($json['Response']['return']['returnFlag'] == '2') {
- (new Controller())->log($METHOD, 'error_' . $FUNCTION, $store['asn_code'] . '||' . $response->body());
- return true;
- }
- // if(isset($json['Response']['return']['returnDesc'])&&strpos($json['Response']['return']['returnDesc'],'唯一约束')!==false){
- // (new Controller())->log($METHOD,'error_'.$FUNCTION,$response->body());
- // return true;
- // }
- if (isset($json['Response']['return']['errordescr']) && strpos($json['Response']['return']['errordescr'], '已完成') !== false) {
- (new Controller())->log($METHOD, 'error_' . $FUNCTION, $store['asn_code'] . '||' . $response->body());
- return true;
- }
- }
- if ($noIssues && $json['Response']['return']['returnFlag'] == '1') {
- $wmsReceived['is_uploaded'] = 1;
- $wmsReceived->save();
- (new Controller())->log($METHOD, 'success_' . $FUNCTION, $store['asn_code'] . '||' . $response->body());
- return true;
- } else {
- $success = false;
- (new Controller())->log($METHOD, 'error_' . $FUNCTION, $store['asn_code'] . '||' . $response->body());
- }
- });
- return $success;
- }
- public function quickStorage_temp($docno)
- {
- $db = DB::connection('oracle');
- //判断单据有效性
- $cus_bs_asnheader = $db->select(DB::raw("SELECT t.addwho FROM CUS_BS_ASNHEADER t WHERE t.ASNREFERENCE1 = '" . $docno . "'"));
- if (!$cus_bs_asnheader) return ['success' => false, 'data' => '单据不存在'];
- $addwho = $cus_bs_asnheader[0]->addwho;
- if ($addwho == "WCS") {
- //判断单据状态
- $cus_bs_asnheader = $db->select(
- 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'"));
- if (!$cus_bs_asnheader) return ['success' => false, 'data' => "该单据已完成收货"];
- $sql = "select a.warehouseid,a.asnno as docno,a1.asnlineno,a.customerid,t1.sku,a1.packid,t1.receivedqty_each,t1.lotatt01,t1.lotatt02,";
- $sql .= " t1.lotatt04,t1.lotatt05,t1.lotatt08,t1.userdefine1 as new_traceid,a.userdefine1,a.userdefine2,a.userdefine3,a.userdefine4,a.userdefine5,t.addwho";
- $sql .= " from doc_asn_details a1";
- $sql .= " inner join doc_asn_header a on a.asnno = a1.asnno";
- $sql .= " inner join cus_bs_asndetails t1 on t1.asnno = a.asnno and t1.asnlineno = a1.asnlineno";
- $sql .= " inner join cus_bs_asnheader t on t.asnno = a1.asnno";
- $sql .= " where t.asnreference1 = '" . $docno . "' and nvl(t1.rcvflag,'N') = 'N'";
- $doc_asn_details = $db->select(DB::raw($sql));
- $db->beginTransaction();
- try {
- $username = config('database.connections.oracle.username');
- $password = config('database.connections.oracle.password');
- $host = config('database.connections.oracle.host');
- $service_name = config('database.connections.oracle.service_name');
- $conn = oci_connect($username, $password, $host . '/' . $service_name);
- $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," .
- ":In_ProductStatus_Descr, :In_HoldRejectCode_C, :In_HoldRejectReason_C, :In_PONo_C, :In_CustomerID, :In_SKU, :In_ReceivedQty, :In_RejectedQty,:In_UOM, :In_PackID," .
- " :In_ContainerID, :In_LotAtt01_C, :In_LotAtt02_C, :In_LotAtt03_C, :In_LotAtt04_C, :In_LotAtt05_C, :In_LotAtt06_C," .
- ":In_LotAtt07_C, :In_LotAtt08_C, :In_LotAtt09_C, :In_LotAtt10_C, :In_LotAtt11_C, :In_LotAtt12_C," .
- ":In_TotalCubic, :In_TotalGrossWeight, :In_TotalNetWeight, :In_TotalPrice, :In_UserDefine1, :In_UserDefine2,:In_UserDefine3, :In_UserDefine4, :In_UserDefine5, :In_FMLocation," .
- ":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;";
- foreach ($doc_asn_details as $doc_asn_detail) {
- $IN_Warehouse = $doc_asn_detail->warehouseid ?? '';
- $In_Process_Action = '3';
- $In_ASNNo_C = $doc_asn_detail->docno ?? '';
- $In_ASNLineNo_C = $doc_asn_detail->asnlineno ?? '';
- $In_FMTraceID_C = '';
- $In_New_TraceID_C = $doc_asn_detail->new_traceid ?? '';
- $In_ProductStatus = '00';
- $In_ProductStatus_Descr = '正常';
- $In_HoldRejectCode_C = 'OK';
- $In_HoldRejectReason_C = '正常';
- $In_PONo_C = '';
- $In_CustomerID = $doc_asn_detail->customerid ?? '';
- $In_SKU = $doc_asn_detail->sku ?? '';
- $In_ReceivedQty = $doc_asn_detail->receivedqty_each ?? '';
- $In_RejectedQty = '';
- $In_UOM = 'EA';
- $In_PackID = $doc_asn_detail->packid ?? '';
- $In_ContainerID = '';
- $In_LotAtt01_C = $doc_asn_detail->lotatt01 ?? '';
- $In_LotAtt02_C = $doc_asn_detail->lotatt02 ?? '';
- $In_LotAtt03_C = '';
- $In_LotAtt04_C = $doc_asn_detail->lotatt04 ?? '';
- $In_LotAtt05_C = $doc_asn_detail->lotatt05 ?? '';
- $In_LotAtt06_C = '';
- $In_LotAtt07_C = '';
- $In_LotAtt08_C = $doc_asn_detail->lotatt08 ?? '';
- $In_LotAtt09_C = '';
- $In_LotAtt10_C = '';
- $In_LotAtt11_C = '';
- $In_LotAtt12_C = '';
- $In_TotalCubic = '0.00';
- $In_TotalGrossWeight = '0.00';
- $In_TotalNetWeight = '0.00';
- $In_TotalPrice = '0.00';
- $In_UserDefine1 = $doc_asn_detail->userdefine1 ?? '';
- $In_UserDefine2 = $doc_asn_detail->userdefine2 ?? '';
- $In_UserDefine3 = $doc_asn_detail->userdefine3 ?? '';
- $In_UserDefine4 = $doc_asn_detail->userdefine4 ?? '';
- $In_UserDefine5 = $doc_asn_detail->userdefine5 ?? '';
- $In_FMLocation = 'STAGE' . $doc_asn_detail->warehouseid;
- $In_TOLocation_C = 'STAGE' . $doc_asn_detail->warehouseid;
- $In_QC_Type_C = 'OK';
- $In_PlanToLoc_C = '';
- $In_ReceivingTime = '';
- $In_LPN = '*';
- $In_Operator = $doc_asn_detail->addwho ?? '';
- $IN_RCVModule = '';
- $IN_RCVStation = '';
- $In_Language = 'cn';
- $In_UserID = $doc_asn_detail->addwho ?? '';
- $result = '';
- $stmt = oci_parse($conn, $sql_sp);
- oci_bind_by_name($stmt, ':IN_Warehouse', $IN_Warehouse);
- oci_bind_by_name($stmt, ':In_Process_Action', $In_Process_Action);
- oci_bind_by_name($stmt, ':In_ASNNo_C', $In_ASNNo_C);
- oci_bind_by_name($stmt, ':In_ASNLineNo_C', $In_ASNLineNo_C);
- oci_bind_by_name($stmt, ':In_FMTraceID_C', $In_FMTraceID_C);
- oci_bind_by_name($stmt, ':In_New_TraceID_C', $In_New_TraceID_C);
- oci_bind_by_name($stmt, ':In_ProductStatus', $In_ProductStatus);
- oci_bind_by_name($stmt, ':In_ProductStatus_Descr', $In_ProductStatus_Descr);
- oci_bind_by_name($stmt, ':In_HoldRejectCode_C', $In_HoldRejectCode_C);
- oci_bind_by_name($stmt, ':In_HoldRejectReason_C', $In_HoldRejectReason_C);
- oci_bind_by_name($stmt, ':In_PONo_C', $In_PONo_C);
- oci_bind_by_name($stmt, ':In_CustomerID', $In_CustomerID);
- oci_bind_by_name($stmt, ':In_SKU', $In_SKU);
- oci_bind_by_name($stmt, ':In_ReceivedQty', $In_ReceivedQty);
- oci_bind_by_name($stmt, ':In_RejectedQty', $In_RejectedQty);
- oci_bind_by_name($stmt, ':In_UOM', $In_UOM);
- oci_bind_by_name($stmt, ':In_PackID', $In_PackID);
- oci_bind_by_name($stmt, ':In_ContainerID', $In_ContainerID);
- oci_bind_by_name($stmt, ':In_LotAtt01_C', $In_LotAtt01_C);
- oci_bind_by_name($stmt, ':In_LotAtt02_C', $In_LotAtt02_C);
- oci_bind_by_name($stmt, ':In_LotAtt03_C', $In_LotAtt03_C);
- oci_bind_by_name($stmt, ':In_LotAtt04_C', $In_LotAtt04_C);
- oci_bind_by_name($stmt, ':In_LotAtt05_C', $In_LotAtt05_C);
- oci_bind_by_name($stmt, ':In_LotAtt06_C', $In_LotAtt06_C);
- oci_bind_by_name($stmt, ':In_LotAtt07_C', $In_LotAtt07_C);
- oci_bind_by_name($stmt, ':In_LotAtt08_C', $In_LotAtt08_C);
- oci_bind_by_name($stmt, ':In_LotAtt09_C', $In_LotAtt09_C);
- oci_bind_by_name($stmt, ':In_LotAtt10_C', $In_LotAtt10_C);
- oci_bind_by_name($stmt, ':In_LotAtt11_C', $In_LotAtt11_C);
- oci_bind_by_name($stmt, ':In_LotAtt12_C', $In_LotAtt12_C);
- oci_bind_by_name($stmt, ':In_TotalCubic', $In_TotalCubic);
- oci_bind_by_name($stmt, ':In_TotalGrossWeight', $In_TotalGrossWeight);
- oci_bind_by_name($stmt, ':In_TotalNetWeight', $In_TotalNetWeight);
- oci_bind_by_name($stmt, ':In_TotalPrice', $In_TotalPrice);
- oci_bind_by_name($stmt, ':In_UserDefine1', $In_UserDefine1);
- oci_bind_by_name($stmt, ':In_UserDefine2', $In_UserDefine2);
- oci_bind_by_name($stmt, ':In_UserDefine3', $In_UserDefine3);
- oci_bind_by_name($stmt, ':In_UserDefine4', $In_UserDefine4);
- oci_bind_by_name($stmt, ':In_UserDefine5', $In_UserDefine5);
- oci_bind_by_name($stmt, ':In_FMLocation', $In_FMLocation);
- oci_bind_by_name($stmt, ':In_TOLocation_C', $In_TOLocation_C);
- oci_bind_by_name($stmt, ':In_QC_Type_C', $In_QC_Type_C);
- oci_bind_by_name($stmt, ':In_PlanToLoc_C', $In_PlanToLoc_C);
- oci_bind_by_name($stmt, ':In_ReceivingTime', $In_ReceivingTime);
- oci_bind_by_name($stmt, ':In_LPN', $In_LPN);
- oci_bind_by_name($stmt, ':In_Operator', $In_Operator);
- oci_bind_by_name($stmt, ':IN_RCVModule', $IN_RCVModule);
- oci_bind_by_name($stmt, ':IN_RCVStation', $IN_RCVStation);
- oci_bind_by_name($stmt, ':In_Language', $In_Language);
- oci_bind_by_name($stmt, ':In_UserID', $In_UserID);
- oci_bind_by_name($stmt, ':OUT_Return_Code', $result);
- oci_execute($stmt);
- oci_close($conn);
- if (substr($result, 0, 3) == '000') {
- $query = DB::raw("update cus_bs_asndetails t set t.rcvflag = 'Y' where t.asnno = ? and t.asnlineno = ?");
- $db->update($query, [$doc_asn_detail->docno, $doc_asn_detail->asnlineno]);
- } else {
- $query = DB::raw("update cus_bs_asndetails t set t.rcvflag = 'W' where t.asnno = ? and t.asnlineno = ?");
- $db->update($query, [$doc_asn_detail->docno, $doc_asn_detail->asnlineno]);
- $db->rollBack();
- return ['success' => false, 'data' => '收货失败', 'code' => $result];
- }
- }
- $db->commit();
- return ['success' => true];
- } catch (\Exception $e) {
- $db->rollBack();
- return ['success' => false, 'data' => $e->getMessage()];
- }
- }
- }
- }
|