处理售后接口
parent
a02fce3f3a
commit
cabcf27d7e
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Endpoint\Api\Http\Controllers;
|
||||
|
||||
use App\Endpoint\Api\Http\Resources\AfterSaleLogResource;
|
||||
use App\Endpoint\Api\Http\Resources\AfterSaleResource;
|
||||
use App\Endpoint\Api\Http\Resources\AfterSaleSimpleResource;
|
||||
use App\Exceptions\BizException;
|
||||
|
|
@ -57,10 +58,10 @@ class AfterSaleController extends Controller
|
|||
'description' => ['bail', 'required', 'string', 'max:255'],
|
||||
'images' => ['bail', 'required', 'array', 'max:6'],
|
||||
]);
|
||||
$orderProduct = OrderProduct::where('user_id', $request->user()->id)->findOrFail($input['order_product_id']);
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
$orderProduct = OrderProduct::where('user_id', $request->user()->id)->findOrFail($input['order_product_id']);
|
||||
$afterSale = $afterSaleService->create($request->user(), $orderProduct, $input['type'], $input['num'], $input);
|
||||
|
||||
DB::commit();
|
||||
|
|
@ -89,6 +90,19 @@ class AfterSaleController extends Controller
|
|||
return AfterSaleResource::make($afterSale);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取售后单的售后日志
|
||||
*
|
||||
* @param [type] $id
|
||||
* @param Request $request
|
||||
* @return void
|
||||
*/
|
||||
public function logs($id, Request $request)
|
||||
{
|
||||
$afterSale = $request->user()->afterSales()->findOrFail($id);
|
||||
return AfterSaleLogResource::collection($afterSale->logs->sortByDesc('created_at'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 补充资料
|
||||
*
|
||||
|
|
|
|||
|
|
@ -15,9 +15,10 @@ class AfterSaleLogResource extends JsonResource
|
|||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
// 'id' => $this->id,
|
||||
'name' =>$this->name,
|
||||
'desc' => $this->desc,
|
||||
'images' => $this->images,
|
||||
'created_at' => $this->created_at->toDateTimeString(),
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ class AfterSaleResource extends JsonResource
|
|||
return [
|
||||
'id' => $this->id,
|
||||
'order_sn' => $this->order->sn,
|
||||
'order_product'=>'',
|
||||
'order_product'=> OrderProductResource::make($this->orderProduct),
|
||||
'state' => $this->state,
|
||||
'type' => $this->type,
|
||||
'images' => $this->images,
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ class AfterSaleSimpleResource extends JsonResource
|
|||
return [
|
||||
'id' => $this->id,
|
||||
'order_sn' => $this->whenLoaded('order')?->sn,
|
||||
'order_product'=>'',
|
||||
'order_product'=> OrderProductResource::make($this->whenLoaded('orderProduct')),
|
||||
'state' => $this->state,
|
||||
'remarks' => $this->remarks,
|
||||
];
|
||||
|
|
|
|||
|
|
@ -87,6 +87,7 @@ Route::group([
|
|||
Route::get('after-sales', [AfterSaleController::class, 'index']);
|
||||
Route::post('after-sales', [AfterSaleController::class, 'store']);
|
||||
Route::get('after-sales/{after_sale}', [AfterSaleController::class, 'show']);
|
||||
Route::get('after-sales/{after_sale}/logs', [AfterSaleController::class, 'logs']);
|
||||
Route::put('after-sales/{after_sale}', [AfterSaleController::class, 'update']);
|
||||
Route::put('after-sales/{after_sale}/agree', [AfterSaleController::class, 'agree']);
|
||||
Route::delete('after-sales/{after_sale}', [AfterSaleController::class, 'cancel']);
|
||||
|
|
|
|||
|
|
@ -40,6 +40,25 @@ class OrderProduct extends Model
|
|||
return $this->hasMany(OrderPackageProduct::class, 'order_product_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 此订单商品的售后单
|
||||
*
|
||||
*/
|
||||
public function afterSales()
|
||||
{
|
||||
return $this->hasMany(AfterSale::class, 'order_product_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取订单商品是否能发起售后
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getCanAfterSaleAttribute()
|
||||
{
|
||||
return !is_null($this->after_expire_at) && $this->after_expire_at < now() && $this->after_sale_state == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取订单商品销售价格
|
||||
*
|
||||
|
|
|
|||
|
|
@ -22,15 +22,23 @@ class AfterSaleService
|
|||
*/
|
||||
public function create(User $user, OrderProduct $orderProduct, int $type, int $num, array $params): AfterSale
|
||||
{
|
||||
// todo 校验这个订单商品是否还能发起售后-待完成
|
||||
// if (1) {
|
||||
// if (is_null($orderProduct->after_expire_at)) {
|
||||
// throw new BizException('该订单商品还未签收无法发起售后');
|
||||
// }
|
||||
|
||||
// // 校验这个订单商品是否还能发起售后-待完成
|
||||
// if ($orderProduct->after_expire_at < now()) {
|
||||
// throw new BizException('该订单商品已过售后时间');
|
||||
// }
|
||||
|
||||
//校验该订单商品不能有已完成、处理中的售后记录
|
||||
if (AfterSale::where('order_product_id', $orderProduct->id)->where('state', '<', AfterSale::STATE_CANCEL)->exists()) {
|
||||
throw new BizException('该订单商品已申请售后');
|
||||
// //校验该订单商品不能有已完成、处理中的售后记录
|
||||
// if ($orderProduct->after_sale_state > 0) {
|
||||
// throw new BizException('该订单商品已申请售后');
|
||||
// }
|
||||
if (!$orderProduct->can_after_sale) {
|
||||
throw new BizException('该订单商品无法发起售后');
|
||||
}
|
||||
|
||||
//校验申请数量不能超过订单商品数量
|
||||
if ($num > $orderProduct->quantity) {
|
||||
throw new BizException('申请售后的数量不能大于订单商品数量');
|
||||
|
|
@ -44,6 +52,9 @@ class AfterSaleService
|
|||
'amount' => $amount,
|
||||
'state' => AfterSale::STATE_VERIFY,
|
||||
]));
|
||||
|
||||
$orderProduct->after_sale_state = 1;
|
||||
|
||||
return $afterSale;
|
||||
}
|
||||
|
||||
|
|
@ -217,7 +228,6 @@ class AfterSaleService
|
|||
|
||||
public function agree(AfterSale $afterSale, array $params, $remarks = '用户已同意客服审核结果')
|
||||
{
|
||||
dd($params);
|
||||
if ($this->isWaitAgree($afterSale)) {
|
||||
switch ($afterSale->type) {
|
||||
case AfterSale::TYPE_REFUND_AND_RETURN:
|
||||
|
|
|
|||
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddAfterSaleStateAndAfterExpireAtToOrderProductsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('order_products', function (Blueprint $table) {
|
||||
//
|
||||
$table->unsignedTinyInteger('after_sale_state')->default(0)->comment('0无售后,1售后中,2已售后');
|
||||
$table->timestamp('after_expire_at')->nullable()->comment('售后截至时间');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('order_products', function (Blueprint $table) {
|
||||
//
|
||||
$table->dropColumn('after_expire_at');
|
||||
$table->dropColumn('after_sale_state');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,9 @@
|
|||
<?php
|
||||
|
||||
use App\Models\AfterSale;
|
||||
use App\Models\Article;
|
||||
use App\Models\Order;
|
||||
use App\Models\OrderProduct;
|
||||
use App\Models\ProductSku;
|
||||
use App\Models\ProductSpu;
|
||||
use App\Models\ShippingAddress;
|
||||
|
|
@ -16,4 +19,7 @@ return [
|
|||
ShoppingCartItem::class => '商品',
|
||||
UserCoupon::class => '优惠券',
|
||||
Zone::class => '地区',
|
||||
OrderProduct::class => '订单商品',
|
||||
AfterSale::class => '售后订单',
|
||||
Article::class => '文章',
|
||||
];
|
||||
|
|
|
|||
Loading…
Reference in New Issue