diff --git a/app/Http/Controllers/Business/BusinessOrderController.php b/app/Http/Controllers/Business/BusinessOrderController.php index fcf0bfc..9bb56cc 100644 --- a/app/Http/Controllers/Business/BusinessOrderController.php +++ b/app/Http/Controllers/Business/BusinessOrderController.php @@ -9,6 +9,7 @@ use App\Models\BusinessOrder; use App\Models\BusinessOrderItem; use App\Models\GoodsSku; use App\Models\Shop; +use App\Models\Waybill; use App\Services\WayBill\JingDong\WayBillService; use App\Utils\DateTimeUtils; use Carbon\Carbon; @@ -37,7 +38,7 @@ class BusinessOrderController extends Controller $builder->whereIn('id', $ids); } - if($request->get("is_export")){ + if ($request->get("is_export")) { $params = $request->validate([ 'confirm_at_start' => 'required', 'confirm_at_end' => 'required', @@ -52,7 +53,7 @@ class BusinessOrderController extends Controller throw new \Exception("导出时间超出一个月"); } - return Excel::download(new BusinessOrderExport($builder->get()->toArray()), $startDate . '~' . $endDate."订单数据" . '.xlsx'); + return Excel::download(new BusinessOrderExport($builder->get()->toArray()), $startDate . '~' . $endDate . "订单数据" . '.xlsx'); } $businessOrders = $builder->orderByDesc('confirm_at') ->paginate($request->get('per_page')); @@ -248,9 +249,11 @@ class BusinessOrderController extends Controller $orderIds = $request->input('order_ids'); $orderIds = explode(',', $orderIds); BusinessOrder::query() - ->where('id', $orderIds) + ->whereIn('id', $orderIds) ->increment('print_status'); - + Waybill::query() + ->where('order', $orderIds) + ->update(['status' => Waybill::$STATUS_PRINT_SUCCESS]); return response(['message' => 'success']); } } diff --git a/app/Http/Controllers/Shop/ShopSendsController.php b/app/Http/Controllers/Shop/ShopSendsController.php index e038ff9..1cefc0b 100644 --- a/app/Http/Controllers/Shop/ShopSendsController.php +++ b/app/Http/Controllers/Shop/ShopSendsController.php @@ -50,7 +50,7 @@ class ShopSendsController extends Controller 'district.required' => '请选择地区', 'detail.required' => '请填写详细地址', ]); - $params['wp_code'] = $params['wp_code'] ?? 'jd'; + $params['wp_code'] = $params['wp_code'] ?? 'JD'; $params['country'] = $params['country'] ?? '中国'; if (empty($params['id'])) { $shopSender = new ShopSender(); diff --git a/app/Models/ShopSender.php b/app/Models/ShopSender.php index da9826a..dafe573 100644 --- a/app/Models/ShopSender.php +++ b/app/Models/ShopSender.php @@ -2,10 +2,12 @@ namespace App\Models; +use App\Models\traits\Filter; use Illuminate\Database\Eloquent\Model; class ShopSender extends Model { + use Filter; protected $guarded = []; //查询字段 diff --git a/app/Models/Waybill.php b/app/Models/Waybill.php index e32a169..b920338 100644 --- a/app/Models/Waybill.php +++ b/app/Models/Waybill.php @@ -10,4 +10,8 @@ class Waybill extends Model public static $BUSINESS_EXPRESS_CODE = 247; public static $AIR_FREIGHT_CODE = 266; + + public static $STATUS_CREATE_WAYBILL_CODE = 1; + public static $STATUS_CREATE_WAYBILL_ENCRYPTED_DATA = 2; + public static $STATUS_PRINT_SUCCESS = 3; } diff --git a/app/Services/Business/KuaiTuanTuan/KuaiTuanTuan.php b/app/Services/Business/KuaiTuanTuan/KuaiTuanTuan.php index d13c07d..1d8af29 100644 --- a/app/Services/Business/KuaiTuanTuan/KuaiTuanTuan.php +++ b/app/Services/Business/KuaiTuanTuan/KuaiTuanTuan.php @@ -374,7 +374,6 @@ class KuaiTuanTuan extends BusinessClient public function createLogistic($orderSn, $waybillNo) { [$type, $appendParams] = Order::createOrderLogistic($orderSn, $waybillNo); - return $this->doRequest($type, $appendParams); } diff --git a/app/Services/WayBill/JingDong/JingDongService.php b/app/Services/WayBill/JingDong/JingDongService.php index da1bde0..44b35ea 100644 --- a/app/Services/WayBill/JingDong/JingDongService.php +++ b/app/Services/WayBill/JingDong/JingDongService.php @@ -136,8 +136,8 @@ class JingDongService "channelOrderId" => $pickupData['order_sn'], "promiseTimeType" => 26,//22:医药冷链 26:冷链专送,29医药专送 "goodsType" => 7,//1:普通,2:生鲜常温,5:鲜活,6:控温,7:冷藏,8:冷冻,9:深冷;21:医药冷藏,23:医药控温,24:医药常温,25:医药冷冻,27:医药深冷 - //"pickUpStartTime" => Carbon::today()->startOfDay()->addHours(19)->toDateTimeString(), - //"pickUpEndTime" => Carbon::today()->startOfDay()->addHours(21)->toDateTimeString(), + //"pickUpStartTime" => Carbon::today()->startOfDay()->addDays(2)->addHours(19)->toDateTimeString(), + //"pickUpEndTime" => Carbon::today()->startOfDay()->addDays(2)->addHours(21)->toDateTimeString(), ]; $response = $this->request($body, $path); diff --git a/app/Services/WayBill/JingDong/WayBillService.php b/app/Services/WayBill/JingDong/WayBillService.php index 7f591e5..c4e5ecb 100644 --- a/app/Services/WayBill/JingDong/WayBillService.php +++ b/app/Services/WayBill/JingDong/WayBillService.php @@ -3,6 +3,8 @@ namespace App\Services\WayBill\JingDong; use App\Events\CreateLogisticEvent; +use App\Http\Enum\BusinessOrderShippingStatus; +use App\Models\BusinessOrder; use App\Models\GoodsSku; use App\Models\ShopSender; use App\Models\ShopShip; @@ -38,6 +40,7 @@ class WayBillService if (empty($waybill->waybill_code)) { $resp = $jingDongService->createOrder($waybill); if (isset($resp['waybillNo'])) { + $waybill->status = Waybill::$STATUS_CREATE_WAYBILL_CODE; $waybill->waybill_code = $resp['waybillNo']; $waybill->save(); //物流发货 @@ -50,6 +53,7 @@ class WayBillService usleep(0.5 * 1000000); $resp = $jingDongService->pullData($waybill); if (!empty($resp[0]['perPrintData'])) { + $waybill->status = Waybill::$STATUS_CREATE_WAYBILL_ENCRYPTED_DATA; $waybill->templateUrl = $this->templateUrl; $waybill->encryptedData = $resp[0]['perPrintData']; $waybill->save(); @@ -215,6 +219,12 @@ class WayBillService $orders = $orders->toArray(); // 订单拆分组合 foreach ($orders as $order) { + if ($order['shipping_status'] != BusinessOrderShippingStatus::UNSHIP) { + continue; + } + if ($order['cancel_status'] == 1) { + continue; + } $info = [ 'id' => $order['id'], 'shop_id' => $order['shop_id'], diff --git a/database/migrations/2024_12_27_093407_add_field_to_waybills_table.php b/database/migrations/2024_12_27_093407_add_field_to_waybills_table.php new file mode 100644 index 0000000..e966ec0 --- /dev/null +++ b/database/migrations/2024_12_27_093407_add_field_to_waybills_table.php @@ -0,0 +1,42 @@ +integer('status')->default(0)->comment('状态 0待申请物流单 1已申请物流 2已申请面单 3已打印'); + $table->index('order_id'); + $table->index('order_sn'); + $table->index('waybill_code'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('waybills', function (Blueprint $table) { + // + $table->dropColumn('status'); + $table->dropIndex('order_id'); + $table->dropIndex('order_sn'); + $table->dropIndex('waybill_code'); + }); + } +}