|
|
@@ -4,19 +4,24 @@ namespace App\Http\Controllers;
|
|
|
|
|
|
use App\Components\Database;
|
|
|
use App\Http\Requests\OrderDelivering;
|
|
|
+use App\OracleActAllocationDetails;
|
|
|
use App\OracleDOCOrderHeader;
|
|
|
use App\OracleDOCWaveDetails;
|
|
|
use App\OrderIssueType;
|
|
|
+use App\OrderPackage;
|
|
|
use App\Services\LogisticService;
|
|
|
use App\Services\LogService;
|
|
|
+use App\Services\OrderPackageService;
|
|
|
use App\Services\OrderService;
|
|
|
use App\Services\RejectedBillItemService;
|
|
|
use App\Services\RejectedBillService;
|
|
|
+use Illuminate\Database\Eloquent\Builder;
|
|
|
use Illuminate\Http\Request;
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
use Oursdreams\Export\Export;
|
|
|
+use function DeepCopy\deep_copy;
|
|
|
|
|
|
class OrderController extends Controller
|
|
|
{
|
|
|
@@ -424,4 +429,101 @@ sql;
|
|
|
return["status"=>'part',"msg"=>$txt];
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 一键揽收分配
|
|
|
+ * @param Request $request
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function collectUpload(Request $request): array
|
|
|
+ {
|
|
|
+ $inOrderno = $request->orderno;
|
|
|
+ $strict = $request->strict;
|
|
|
+ if (empty($inOrderno)) return ['success' => false, 'message' => '选择为空'];
|
|
|
+ $orderno = deep_copy($inOrderno);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 是否是严格模式
|
|
|
+ * 是
|
|
|
+ * 根据筛选条件
|
|
|
+ * 1. 状态 61 81
|
|
|
+ * 2. 承运商是中通
|
|
|
+ * 3. 有单号
|
|
|
+ * 4. 有复核,
|
|
|
+ * 5. 没揽收
|
|
|
+ * 否
|
|
|
+ * 筛选出快递单号
|
|
|
+ * 将快递单号调用一键揽收
|
|
|
+ * 如果返回异常,记录异常
|
|
|
+ * 调用分配
|
|
|
+ * 将入参与过滤结果取差集合,结果就是不复核的单号,作为错误提示返回
|
|
|
+ */
|
|
|
+ //严格模式,校验订单与包裹状态
|
|
|
+ if ($strict) {
|
|
|
+ $logisticNums = OracleActAllocationDetails::query()
|
|
|
+ ->select('picktotraceid')
|
|
|
+ ->whereIn('orderno', $orderno)
|
|
|
+ ->whereNotNull('picktotraceid')//有单号
|
|
|
+ ->whereNotNull('checktime')//有复核
|
|
|
+ ->whereIn('orderno', function (Builder $query) use ($orderno) {
|
|
|
+ $query->from('doc_order_header')
|
|
|
+ ->select('orderno')
|
|
|
+ ->whereIn('orderno', $orderno)
|
|
|
+ ->whereIn('carriername', ['中通(轻小包裹)', '中通', '中通速递']) // 承运商是中通
|
|
|
+ ->whereBetween('sostatus', [61, 81]); //状态 61 81
|
|
|
+ })
|
|
|
+ ->pluck('picktotraceid');
|
|
|
+ $logisticNums = OrderPackage::query()
|
|
|
+ ->select('logistic_number')
|
|
|
+ ->whereIn('logistic_number', $logisticNums)
|
|
|
+ ->whereNull('transfer_status')
|
|
|
+ ->pluck('logistic_number');
|
|
|
+ }else{
|
|
|
+ //非严格模式 不进行任何校验
|
|
|
+ $logisticNums = OracleActAllocationDetails::query()
|
|
|
+ ->select('picktotraceid')
|
|
|
+ ->whereIn('orderno', $orderno)
|
|
|
+ ->pluck('picktotraceid');
|
|
|
+ }
|
|
|
+
|
|
|
+ //调用一键揽收
|
|
|
+ /** @var OrderPackageService $orderPackageService */
|
|
|
+ $orderPackageService = app('OrderPackageService');
|
|
|
+ $collectUpLoadResult = $orderPackageService->collectUpload($logisticNums->toArray());
|
|
|
+ $error = [];
|
|
|
+ //揽收有异常记录
|
|
|
+ if (!$collectUpLoadResult['success']) {
|
|
|
+ $error['collectUpload'] = $collectUpLoadResult['message'];
|
|
|
+ }
|
|
|
+ /** @var OrderService $orderService */
|
|
|
+ $orderService = app('OrderService');
|
|
|
+ //根据快递单号查询orderno
|
|
|
+ $allocationOrdernos = OrderPackage::query()
|
|
|
+ ->whereIn('logistic_number', $logisticNums)
|
|
|
+ ->leftJoin('orders', 'order_id', '=', 'orders.id')
|
|
|
+ ->select('orders.code')
|
|
|
+ ->pluck('code');
|
|
|
+ //调用分配接口
|
|
|
+ $allocationOrdernos->each(function ($orderno) use ($orderService) {
|
|
|
+ $orderService->allocation($orderno);
|
|
|
+ });
|
|
|
+ if ($strict) {
|
|
|
+ //输入的orderno与最终可以一键揽收的orderno取差集合
|
|
|
+ $errorOrderno = array_diff($inOrderno, $allocationOrdernos->toArray());
|
|
|
+ }
|
|
|
+
|
|
|
+ $result = [];
|
|
|
+ if (!empty($error)) {
|
|
|
+ $result['success'] = false;
|
|
|
+ $result['error_message'] = $error;
|
|
|
+ }else if(!empty($errorOrderno)){
|
|
|
+ $result['success'] = false;
|
|
|
+ $result['error_message'][] = $error;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $result['success']=true;
|
|
|
+ $result['message']='一键揽收分配完成';
|
|
|
+ }
|
|
|
+ return $result;
|
|
|
+ }
|
|
|
+
|
|
|
}
|