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\Services\Business\BusinessFactory;
use App\Services\Business\KuaiTuanTuan\FaceSheet;
use App\Services\Ship\WayBillService;
use App\Utils\DateTimeUtils;
use Carbon\Carbon;
use Illuminate\Console\Command;

View File

@ -8,6 +8,7 @@ use App\Models\BusinessOrder;
use App\Models\BusinessOrderItem;
use App\Models\GoodsSku;
use App\Models\Shop;
use App\Services\Ship\WayBillService;
use App\Utils\DateTimeUtils;
use Carbon\Carbon;
use Illuminate\Http\Request;
@ -186,4 +187,24 @@ class BusinessOrderController extends Controller
->get(['activity_title', 'activity_no'])
->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);
}
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\ShopShip;
use App\Models\Waybill;
use App\Services\Business\KuaiTuanTuan\FaceSheet;
class WayBill
class WayBillService
{
public $orders;
public $objectId;
@ -15,6 +16,7 @@ class WayBill
public function get()
{
foreach ($this->orders as $shopId => $order) {
// 订单取消的情况暂不处理
$shop = $this->getShop($shopId);
$faceSheet = new FaceSheet();
$faceSheet->setShop($shop);
@ -24,12 +26,12 @@ class WayBill
$resp = $faceSheet->getWayBill($sender, $orderInfo, $wpCode);
if (isset($resp['pdd_waybill_get_response'])) {
$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->encryptedData = $data['encryptedData'];
$waybill->signature = $data['signature'];
$waybill->templateUrl = $data['templateUrl'];
$waybill->ver = $data['ver'];
$waybill->encryptedData = $printData['encryptedData'];
$waybill->signature = $printData['signature'];
$waybill->templateUrl = $printData['templateUrl'];
$waybill->ver = $printData['ver'];
$waybill->waybill_code = $data['waybill_code'];
$waybill->save();
}
@ -41,7 +43,7 @@ class WayBill
{
$senderConfig = $shop->senders[0];
$waybill = new Waybill();
$waybill->shop_id = $shop->id;
$waybill->shop_id = $shop->shop_id;
$waybill->object_id = $this->objectId;
$waybill->sender_country = $senderConfig['country'];
@ -149,7 +151,8 @@ class WayBill
'combinationGoods.goodsSkuItem:id,external_sku_id',
])
->whereIn('external_sku_id', $combinationExternalIds)
->get();
->get()
->toArray();
foreach ($goodsSkus as $goodsSku) {
foreach ($goodsSku['combination_goods'] as $item) {
$combinations[$goodsSku['external_sku_id']][] = [
@ -215,6 +218,6 @@ class WayBill
$query->orderBy('sort')->first();
}
])
->get();
->first();
}
}

View File

@ -42,14 +42,15 @@ class CreateWaybillsTable extends Migration
$table->string('recipient_district');
$table->string('recipient_detail');
$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('order_channels_type')->default('PDD');
$table->string('order_sn');
$table->text('items');
$table->tinyInteger('cancel')->default(0);
$table->timestamps();