feat: #10000 订单下单

This commit is contained in:
赵世界 2023-07-28 15:35:47 +08:00
parent 6d8adb0700
commit e35114f842
5 changed files with 48 additions and 11 deletions

View File

@ -15,6 +15,7 @@ use App\Models\ShopShip;
use App\Models\TodayPrice; use App\Models\TodayPrice;
use App\Services\Business\BusinessFactory; use App\Services\Business\BusinessFactory;
use App\Services\Business\KuaiTuanTuan\FaceSheet; use App\Services\Business\KuaiTuanTuan\FaceSheet;
use App\Services\Ship\WayBillService;
use App\Utils\DateTimeUtils; use App\Utils\DateTimeUtils;
use Carbon\Carbon; use Carbon\Carbon;
use Illuminate\Console\Command; use Illuminate\Console\Command;

View File

@ -8,6 +8,7 @@ use App\Models\BusinessOrder;
use App\Models\BusinessOrderItem; use App\Models\BusinessOrderItem;
use App\Models\GoodsSku; use App\Models\GoodsSku;
use App\Models\Shop; use App\Models\Shop;
use App\Services\Ship\WayBillService;
use App\Utils\DateTimeUtils; use App\Utils\DateTimeUtils;
use Carbon\Carbon; use Carbon\Carbon;
use Illuminate\Http\Request; use Illuminate\Http\Request;
@ -186,4 +187,24 @@ class BusinessOrderController extends Controller
->get(['activity_title', 'activity_no']) ->get(['activity_title', 'activity_no'])
->toArray(); ->toArray();
} }
public function print(Request $request)
{
$shopIds = Shop::query()
->where('plat_id', Shop::$PLAT_KTT)
->pluck('id');
$builder = BusinessOrder::query()
->with('items')
->whereIn('shop_id', $shopIds)
->filter();
$externalSkuIds = $request->get('external_sku_ids');
if ($externalSkuIds) {
$ids = BusinessOrderItem::query()->whereIn('external_sku_id', $externalSkuIds)->pluck('business_order_id');
$builder->whereIn('id', $ids);
}
$businessOrders = $builder->get();
$waybill = new WayBillService();
$waybill->setOrders($businessOrders);
$waybill->get();
}
} }

View File

@ -85,5 +85,16 @@ class FaceSheet extends KuaiTuanTuan
return $this->doRequest($type, $appendParams); return $this->doRequest($type, $appendParams);
} }
public function cancel($waybillCode, $wpCode)
{
$type = 'pdd.cloudprint.customares.get';
$appendParams = [
'waybill_code' => $waybillCode,
'wp_code' => $wpCode,
];
return $this->doRequest($type, $appendParams);
}
} }

View File

@ -4,9 +4,10 @@ namespace App\Services\Ship;
use App\Models\GoodsSku; use App\Models\GoodsSku;
use App\Models\ShopShip; use App\Models\ShopShip;
use App\Models\Waybill;
use App\Services\Business\KuaiTuanTuan\FaceSheet; use App\Services\Business\KuaiTuanTuan\FaceSheet;
class WayBill class WayBillService
{ {
public $orders; public $orders;
public $objectId; public $objectId;
@ -15,6 +16,7 @@ class WayBill
public function get() public function get()
{ {
foreach ($this->orders as $shopId => $order) { foreach ($this->orders as $shopId => $order) {
// 订单取消的情况暂不处理
$shop = $this->getShop($shopId); $shop = $this->getShop($shopId);
$faceSheet = new FaceSheet(); $faceSheet = new FaceSheet();
$faceSheet->setShop($shop); $faceSheet->setShop($shop);
@ -24,12 +26,12 @@ class WayBill
$resp = $faceSheet->getWayBill($sender, $orderInfo, $wpCode); $resp = $faceSheet->getWayBill($sender, $orderInfo, $wpCode);
if (isset($resp['pdd_waybill_get_response'])) { if (isset($resp['pdd_waybill_get_response'])) {
$data = $resp['pdd_waybill_get_response']['modules'][0]; $data = $resp['pdd_waybill_get_response']['modules'][0];
$data = json_decode($data['print_data'], true); $printData = json_decode($data['print_data'], true);
$waybill->request_id = $resp['pdd_waybill_get_response']['request_id']; $waybill->request_id = $resp['pdd_waybill_get_response']['request_id'];
$waybill->encryptedData = $data['encryptedData']; $waybill->encryptedData = $printData['encryptedData'];
$waybill->signature = $data['signature']; $waybill->signature = $printData['signature'];
$waybill->templateUrl = $data['templateUrl']; $waybill->templateUrl = $printData['templateUrl'];
$waybill->ver = $data['ver']; $waybill->ver = $printData['ver'];
$waybill->waybill_code = $data['waybill_code']; $waybill->waybill_code = $data['waybill_code'];
$waybill->save(); $waybill->save();
} }
@ -41,7 +43,7 @@ class WayBill
{ {
$senderConfig = $shop->senders[0]; $senderConfig = $shop->senders[0];
$waybill = new Waybill(); $waybill = new Waybill();
$waybill->shop_id = $shop->id; $waybill->shop_id = $shop->shop_id;
$waybill->object_id = $this->objectId; $waybill->object_id = $this->objectId;
$waybill->sender_country = $senderConfig['country']; $waybill->sender_country = $senderConfig['country'];
@ -149,7 +151,8 @@ class WayBill
'combinationGoods.goodsSkuItem:id,external_sku_id', 'combinationGoods.goodsSkuItem:id,external_sku_id',
]) ])
->whereIn('external_sku_id', $combinationExternalIds) ->whereIn('external_sku_id', $combinationExternalIds)
->get(); ->get()
->toArray();
foreach ($goodsSkus as $goodsSku) { foreach ($goodsSkus as $goodsSku) {
foreach ($goodsSku['combination_goods'] as $item) { foreach ($goodsSku['combination_goods'] as $item) {
$combinations[$goodsSku['external_sku_id']][] = [ $combinations[$goodsSku['external_sku_id']][] = [
@ -215,6 +218,6 @@ class WayBill
$query->orderBy('sort')->first(); $query->orderBy('sort')->first();
} }
]) ])
->get(); ->first();
} }
} }

View File

@ -42,14 +42,15 @@ class CreateWaybillsTable extends Migration
$table->string('recipient_district'); $table->string('recipient_district');
$table->string('recipient_detail'); $table->string('recipient_detail');
$table->string('recipient_name'); $table->string('recipient_name');
$table->integer('recipient_mobile'); $table->string('recipient_mobile', 16);
$table->bigInteger('user_id'); $table->string('user_id');
$table->string('wp_code'); $table->string('wp_code');
$table->string('order_channels_type')->default('PDD'); $table->string('order_channels_type')->default('PDD');
$table->string('order_sn'); $table->string('order_sn');
$table->text('items'); $table->text('items');
$table->tinyInteger('cancel')->default(0);
$table->timestamps(); $table->timestamps();