调整物流订阅推送
parent
8135c6942e
commit
fb366523f4
|
|
@ -5,6 +5,8 @@ namespace App\Endpoint\Callback\Http\Controllers;
|
|||
use App\Services\Kuaidi100Service;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Throwable;
|
||||
|
||||
class Kuaidi100Controller extends Controller
|
||||
{
|
||||
|
|
@ -13,14 +15,21 @@ class Kuaidi100Controller extends Controller
|
|||
* @param \Illuminate\Http\Request $request
|
||||
* @return void
|
||||
*/
|
||||
public function callback(Request $request, Kuaidi100Service $kuaidi100Service)
|
||||
public function notify(Request $request, Kuaidi100Service $kuaidi100Service)
|
||||
{
|
||||
$data = $request->all();
|
||||
|
||||
//校验回调签名
|
||||
if ($kuaidi100Service->unPollSign(Arr::get($data, 'sign', ''), Arr::get($data, 'param', []))) {
|
||||
dd(132465);
|
||||
// if ($kuaidi100Service->unPollSign(Arr::get($data, 'sign', ''), Arr::get($data, 'param', []))) {
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
$kuaidi100Service->callback($request->input('param', []));
|
||||
DB::commit();
|
||||
} catch (Throwable $th) {
|
||||
DB::rollBack();
|
||||
report($th);
|
||||
}
|
||||
// }
|
||||
return response()->json([
|
||||
'result'=>true,
|
||||
'returnCode'=>'200',
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ use App\Endpoint\Callback\Http\Controllers\Kuaidi100Controller;
|
|||
use App\Endpoint\Callback\Http\Controllers\WeChatPayController;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
Route::post('kuaidi100', [Kuaidi100Controller::class, 'callback']);
|
||||
//快递100物流推送
|
||||
Route::post('kuaidi100', [Kuaidi100Controller::class, 'notify']);
|
||||
// 微信支付通知
|
||||
Route::post('wxpay/paid-notify', [WeChatPayController::class, 'paidNotify'])->name('wxpay.paid_notify');
|
||||
|
|
|
|||
|
|
@ -2,10 +2,24 @@
|
|||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Casts\JsonArray;
|
||||
use Dcat\Admin\Traits\HasDateTimeFormatter;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class KuaidiLog extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use HasDateTimeFormatter;
|
||||
|
||||
protected $casts = [
|
||||
'info'=>JsonArray::class,
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'number',
|
||||
'company',
|
||||
'code',
|
||||
'info',
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Dcat\Admin\Traits\HasDateTimeFormatter;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
|
@ -11,10 +12,39 @@ class OrderPackage extends Model
|
|||
use HasFactory;
|
||||
use HasDateTimeFormatter;
|
||||
|
||||
public const STATUS_WAIT = 1;//揽收
|
||||
public const STATUS_ONTHEWAY = 0;//途中
|
||||
public const STATUS_DISTRIBUTE = 5;//派送
|
||||
public const STATUS_CHECK = 3;//签收
|
||||
public const STATUS_QUESTION = 2;//疑难:问题包裹
|
||||
public const STATUS_REFUND = 4;//退签
|
||||
public const STATUS_REFUSE = 6;//拒签
|
||||
public const STATUS_OTHER = 10;//其他
|
||||
public const STATUS_AUTOCHECK = 11;//自动签收
|
||||
|
||||
public static $kuaidi100StatusMap = [
|
||||
'wait' => self::STATUS_WAIT,
|
||||
'on_the_way' => self::STATUS_ONTHEWAY,
|
||||
'distribute' => self::STATUS_DISTRIBUTE,
|
||||
'check' => self::STATUS_CHECK,
|
||||
'refund' => self::STATUS_REFUND,
|
||||
'refuse' => self::STATUS_REFUSE,
|
||||
'questions'=> self::STATUS_QUESTION,
|
||||
];
|
||||
|
||||
protected $attributes = [
|
||||
'status' => self::STATUS_WAIT,
|
||||
'is_failed'=> false,
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'is_failed' => 'bool',
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'remarks', 'status', 'is_failed', 'checked_at',
|
||||
];
|
||||
|
||||
/**
|
||||
* 订单
|
||||
*
|
||||
|
|
@ -33,4 +63,26 @@ class OrderPackage extends Model
|
|||
{
|
||||
return $this->hasMany(OrderPackageProduct::class, 'order_package_id');
|
||||
}
|
||||
|
||||
public function orderProducts()
|
||||
{
|
||||
return $this->belongsToMany(OrderProduct::class, 'order_package_products', 'order_package_id', 'order_product_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新包裹物流状态
|
||||
*/
|
||||
public function updatePackageStatus(int $status, ?Carbon $time = null)
|
||||
{
|
||||
//如果是签收或者自动签收,填入签收时间; 并填入包裹商品里面的售后有效期;
|
||||
$this->status = $status;
|
||||
|
||||
if ($status == self::STATUS_CHECK || $status == self::STATUS_AUTOCHECK) {
|
||||
$this->checked_at = $time ?? now();
|
||||
$this->orderProducts()->update([
|
||||
'after_expire_at'=>$this->checked_at->addDays(7),
|
||||
]);
|
||||
}
|
||||
$this->save();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -18,6 +18,7 @@ use App\Models\ProductSku;
|
|||
use App\Models\ShippingAddress;
|
||||
use App\Models\User;
|
||||
use App\Models\UserCoupon;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class OrderService
|
||||
|
|
@ -697,13 +698,23 @@ class OrderService
|
|||
$package->consignee_address = $order->consignee_address;
|
||||
|
||||
$package->shipping_company = $params['shipping_company'];
|
||||
$package->shipping_code = Arr::get(Kuaidi100Service::$codeArr, $package->shipping_company, '');
|
||||
$package->shipping_number = $params['shipping_number'];
|
||||
|
||||
//保存发货单
|
||||
$package->save();
|
||||
//保存发货单商品
|
||||
$package->packageProducts()->saveMany(array_map(function ($value) {
|
||||
return new OrderPackageProduct($value);
|
||||
OrderPackageProduct::insert(array_map(function ($value) use ($package) {
|
||||
return array_merge($value, [
|
||||
'order_package_id' => $package->id,
|
||||
'created_at' => $package->created_at,
|
||||
'updated_at' => $package->created_at,
|
||||
]);
|
||||
}, $packageProducts));
|
||||
if (config('settings.kuaidi100_is_use')) {
|
||||
$kuaidi100Service = new Kuaidi100Service();
|
||||
$kuaidi100Service->poll($package->shipping_number, $package->shipping_code, $package->consignee_telephone);
|
||||
}
|
||||
|
||||
//更新订单状态
|
||||
if (!OrderProduct::where('order_id', $order->id)->where('remain_quantity', '>', 0)->exists()) {
|
||||
|
|
|
|||
|
|
@ -22,11 +22,10 @@ return [
|
|||
|
||||
// 快递100是否开启
|
||||
'kuaidi100_is_use' => true,
|
||||
'kuaidi100_callback'=> '',
|
||||
'kuaidi100_callback'=> env('APP_URL', '').'/callback/kuaidi100',
|
||||
'kuaidi100_app_key'=> 'BTvgbjti4727',
|
||||
'kuaidi100_customer'=> '064109188EC4D85DA655DFC342144C6A',
|
||||
'kuaidi100_secret'=> '1bd287d1981749f2a30ea74cac0ab99c',
|
||||
'kuaidi100_userid'=> 'ec0b6ec7729d4f22824cfd3c519dd45b',
|
||||
|
||||
|
||||
];
|
||||
|
|
|
|||
|
|
@ -21,12 +21,15 @@ class CreateOrderPackagesTable extends Migration
|
|||
$table->string('consignee_zone')->nullable()->comment('收货人所在地区');
|
||||
$table->string('consignee_address')->nullable()->comment('收货人详细地址');
|
||||
$table->string('shipping_company')->nullable()->comment('快递公司');
|
||||
$table->string('shipping_code')->nullable()->comment('快递编码');
|
||||
$table->string('shipping_number')->nullable()->comment('快递单号');
|
||||
$table->unsignedTinyInteger('is_failed')->default(0)->comment('是否作废');
|
||||
$table->unsignedTinyInteger('status')->default(0)->comment('快递状态:0在途,1揽收,2疑难,3签收,4退签,5派件,6退回');
|
||||
$table->timestamp('inspected_at')->nullable()->comment('签收时间');
|
||||
$table->unsignedTinyInteger('status')->default(0)->comment('快递状态:0在途,1揽收,2疑难,3签收,4退签,5派件,14拒签');
|
||||
$table->timestamp('checked_at')->nullable()->comment('签收时间');
|
||||
$table->string('remarks')->nullable()->comment('备注');
|
||||
$table->timestamps();
|
||||
|
||||
$table->index('shipping_number');
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,13 +15,12 @@ class CreateKuaidiLogsTable extends Migration
|
|||
{
|
||||
Schema::create('kuaidi_logs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('shipping_number')->comment('快递单号');
|
||||
$table->string('shipping_company')->comment('快递公司');
|
||||
$table->string('shipping_code')->nullable()->comment('快递公司编号');
|
||||
$table->json('shipping_info')->nullable()->comment('物流情况明细');
|
||||
$table->string('number')->comment('快递单号');
|
||||
$table->string('code')->nullable()->comment('快递编码');
|
||||
$table->json('info')->nullable()->comment('物流情况明细');
|
||||
$table->timestamps();
|
||||
|
||||
$table->index('shipping_number');
|
||||
$table->index('number');
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue