2022-08-06 15:25:13 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Services\Business\MiaoXuan;
|
|
|
|
|
|
2022-08-16 21:02:31 +08:00
|
|
|
use App\Models\BusinessGoodsSku;
|
2024-12-05 18:47:51 +08:00
|
|
|
use App\Models\BusinessOrderItem;
|
|
|
|
|
use App\Models\GoodsSku;
|
2022-08-06 15:25:13 +08:00
|
|
|
use App\Services\Business\BusinessClient;
|
2025-01-25 15:30:10 +08:00
|
|
|
use Carbon\Carbon;
|
|
|
|
|
use Illuminate\Support\Facades\Log;
|
2022-08-06 15:25:13 +08:00
|
|
|
|
|
|
|
|
class MiaoXuan extends BusinessClient
|
|
|
|
|
{
|
2025-01-25 15:30:10 +08:00
|
|
|
public $domain = "http://shop.dev.chutang66.com";
|
2022-08-06 15:25:13 +08:00
|
|
|
|
|
|
|
|
public function auth()
|
|
|
|
|
{
|
|
|
|
|
// TODO: Implement auth() method.
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-29 11:29:48 +08:00
|
|
|
public function downloadGoodsListAndBind($activityNo)
|
2022-08-06 15:25:13 +08:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-06 16:38:04 +08:00
|
|
|
public function bindGoods($goods)
|
|
|
|
|
{
|
|
|
|
|
Goods::bindGoods($goods, $this->shop->id);
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-16 21:02:31 +08:00
|
|
|
public function incrQuantity($businessGoodsSku, $num, $incremental)
|
2022-08-06 15:25:13 +08:00
|
|
|
{
|
2022-08-16 21:02:31 +08:00
|
|
|
$appendParams = Goods::incrQuantity($this->shop->id, $num, $businessGoodsSku);
|
2022-08-08 15:05:17 +08:00
|
|
|
$url = 'http://shop.chutang66.com/miaoxuan/stock';
|
2022-08-06 16:38:04 +08:00
|
|
|
$this->formDataPostRequest($url, $appendParams);
|
2022-08-06 15:25:13 +08:00
|
|
|
}
|
|
|
|
|
|
2022-08-11 02:13:19 +08:00
|
|
|
public function downloadOrdersAndSave($beginTime, $endTime, $downloadType = 'default', $page = 1)
|
2022-08-06 15:25:13 +08:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-04 13:49:28 +08:00
|
|
|
public function downloadAfterSaleOrdersAndSave($beginTime, $endTime, $page = 1)
|
|
|
|
|
{
|
2024-09-02 17:36:43 +08:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-04 13:49:28 +08:00
|
|
|
public function queryStatusAndSync($order)
|
|
|
|
|
{
|
|
|
|
|
$appendParams = ["order_sn" => $order->order_sn, "type" => "erpQuery"];
|
2024-12-05 19:31:20 +08:00
|
|
|
$url = 'http://shop.chutang66.com/miaoxuan/queryOrder';
|
2024-12-05 18:47:51 +08:00
|
|
|
$queryOrder = $this->formDataPostRequest($url, $appendParams);
|
|
|
|
|
$needUpdate = false;
|
|
|
|
|
if ($order->shipping_status != $queryOrder['shipping_status']) {
|
|
|
|
|
$order->shipping_status = $queryOrder['shipping_status'];
|
|
|
|
|
$needUpdate = true;
|
|
|
|
|
}
|
|
|
|
|
if ($order->cancel_status != $queryOrder['cancel_status']) {
|
|
|
|
|
$order->cancel_status = $queryOrder['cancel_status'];
|
|
|
|
|
$needUpdate = true;
|
|
|
|
|
}
|
2025-01-25 15:30:10 +08:00
|
|
|
if ($order->after_sales_status != $queryOrder['after_sales_status']) {
|
2024-12-05 18:47:51 +08:00
|
|
|
//售后状态更新
|
|
|
|
|
$order->after_sales_status = $queryOrder['after_sales_status'];
|
|
|
|
|
$needUpdate = true;
|
|
|
|
|
}
|
|
|
|
|
if ($needUpdate) {
|
|
|
|
|
$goodsSkuNum = 0;
|
|
|
|
|
foreach ($queryOrder['sub_order_list'] as $item) {
|
|
|
|
|
$orderItem = BusinessOrderItem::firstOrNew(['shop_id' => $order->shop_id, 'business_order_id' => $order->id, 'goods_id' => $item['goods_id'], 'sku_id' => $item['sku_id']], $item);
|
|
|
|
|
if ($item['external_sku_id']) {
|
|
|
|
|
$goodsSku = GoodsSku::query()
|
|
|
|
|
->with('combinationGoods')
|
|
|
|
|
->where('external_sku_id', $item['external_sku_id'])
|
|
|
|
|
->first('external_sku_id');
|
|
|
|
|
$combinationNum = $goodsSku ? ($goodsSku->combinationGoods->count() ?: 1) : 1;
|
|
|
|
|
$goodsSkuNum += $combinationNum;
|
|
|
|
|
} else {
|
|
|
|
|
$goodsSkuNum++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!empty($orderItem->id)) {
|
|
|
|
|
$orderItem->update($item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$order->goods_sku_num = $goodsSkuNum;
|
|
|
|
|
$order->save();
|
|
|
|
|
}
|
2024-11-25 13:51:50 +08:00
|
|
|
}
|
|
|
|
|
|
2022-11-04 15:01:55 +08:00
|
|
|
public function batchIncrQuantity($businessGoodsSkus, $num, $incremental)
|
|
|
|
|
{
|
2022-11-04 15:11:43 +08:00
|
|
|
$batchAppendParams = [];
|
|
|
|
|
foreach ($businessGoodsSkus as $businessGoodsSku) {
|
|
|
|
|
$appendParams = Goods::incrQuantity($this->shop->id, $num, $businessGoodsSku);
|
|
|
|
|
$batchAppendParams[] = $appendParams;
|
|
|
|
|
}
|
|
|
|
|
$this->batchAsyncPostRequest('http://shop.chutang66.com/miaoxuan/stock', $batchAppendParams);
|
2022-11-04 15:01:55 +08:00
|
|
|
}
|
|
|
|
|
|
2022-08-08 18:53:38 +08:00
|
|
|
public function downloadGoods($skuId)
|
|
|
|
|
{
|
|
|
|
|
// TODO: Implement downloadGoods() method.
|
|
|
|
|
}
|
2023-08-28 13:42:27 +08:00
|
|
|
|
|
|
|
|
public function createLogistic($orderSn, $waybillNo)
|
|
|
|
|
{
|
2025-01-25 15:30:10 +08:00
|
|
|
$path = "/miaoxuan/ship";
|
|
|
|
|
$url = $this->domain . $path;
|
|
|
|
|
$appendParams = [
|
|
|
|
|
"data" => [
|
|
|
|
|
"order_sn" => $orderSn,
|
|
|
|
|
"ship_sn" => $waybillNo,
|
|
|
|
|
"ship_time" => Carbon::now()->toDateTimeString(),
|
|
|
|
|
"company_code" => "JD",
|
|
|
|
|
],
|
|
|
|
|
"type"=>"miaoxuan.ship"
|
|
|
|
|
];
|
|
|
|
|
$res =$this->formDataPostRequest($url, $appendParams);
|
|
|
|
|
Log::info("同步物流发货信息".$orderSn,[$res,$appendParams]);
|
2023-08-28 13:42:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function cancelLogistic($orderSn, $waybillNo)
|
|
|
|
|
{
|
|
|
|
|
// TODO: Implement cancelLogistic() method.
|
|
|
|
|
}
|
2022-08-06 15:25:13 +08:00
|
|
|
}
|