添加订单部分接口
parent
72ecc15f66
commit
adb4c9f5ba
|
|
@ -32,6 +32,7 @@ class DealerProductController extends AdminController
|
||||||
// $grid->column('images');
|
// $grid->column('images');
|
||||||
// $grid->column('description');
|
// $grid->column('description');
|
||||||
$grid->column('price')->prepend('¥');
|
$grid->column('price')->prepend('¥');
|
||||||
|
$grid->column('manager_subsidy')->prepend('¥');
|
||||||
// $grid->column('stock');
|
// $grid->column('stock');
|
||||||
// $grid->column('sales_count');
|
// $grid->column('sales_count');
|
||||||
$grid->column('is_sale')->if(function () {
|
$grid->column('is_sale')->if(function () {
|
||||||
|
|
@ -123,7 +124,8 @@ class DealerProductController extends AdminController
|
||||||
->retainable()
|
->retainable()
|
||||||
->autoUpload();
|
->autoUpload();
|
||||||
$form->editor('description');
|
$form->editor('description');
|
||||||
$form->currency('price')->symbol('¥');
|
$form->currency('price')->symbol('¥')->required();
|
||||||
|
$form->currency('manager_subsidy')->symbol('¥')->required();
|
||||||
// $form->text('stock');
|
// $form->text('stock');
|
||||||
// $form->text('sales_count');
|
// $form->text('sales_count');
|
||||||
$form->switch('is_sale');
|
$form->switch('is_sale');
|
||||||
|
|
|
||||||
|
|
@ -209,7 +209,7 @@ class WalletController extends Controller
|
||||||
throw new BizException('可提账户已被限制提现');
|
throw new BizException('可提账户已被限制提现');
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo-校验提现门槛
|
// 校验提现门槛
|
||||||
if (bcdiv($amount, 100, 2) < app_settings('withdraw.threshold_amount', 0)) {
|
if (bcdiv($amount, 100, 2) < app_settings('withdraw.threshold_amount', 0)) {
|
||||||
throw new BizException('提现金额需大于'.app_settings('withdraw.threshold_amount', 0).'元');
|
throw new BizException('提现金额需大于'.app_settings('withdraw.threshold_amount', 0).'元');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -100,4 +100,77 @@ class OrderController extends Controller
|
||||||
'total_amount'=> $orderService->totalAmount($request->user(), $product, $input['num']),
|
'total_amount'=> $orderService->totalAmount($request->user(), $product, $input['num']),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 确认接单
|
||||||
|
*
|
||||||
|
* @param [type] $id
|
||||||
|
* @param Request $request
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function confirmOrder($id, Request $request, OrderService $orderService)
|
||||||
|
{
|
||||||
|
$order = DealerOrder::findOrFail($id);
|
||||||
|
$userId = $request->user()->id;
|
||||||
|
//不是发货人
|
||||||
|
if (!$order->isConsignor($userId)) {
|
||||||
|
throw new BizException('订单未找到');
|
||||||
|
}
|
||||||
|
|
||||||
|
$orderService->confirmOrder($order);
|
||||||
|
return response()->noContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 确认打款
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function payOrder($id, Request $request, OrderService $orderService)
|
||||||
|
{
|
||||||
|
$order = DealerOrder::findOrFail($id);
|
||||||
|
$userId = $request->user()->id;
|
||||||
|
//不是发货人
|
||||||
|
if (!$order->isUser($userId)) {
|
||||||
|
throw new BizException('订单未找到');
|
||||||
|
}
|
||||||
|
|
||||||
|
$input = $request->validate([
|
||||||
|
'pay_image' => ['bail', 'required', 'string'],
|
||||||
|
]);
|
||||||
|
$orderService->payOrder($order, $input['pay_image']);
|
||||||
|
return response()->noContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 确认收款+发货
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function paidOrder($id, Request $request, OrderService $orderService)
|
||||||
|
{
|
||||||
|
return response()->noContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 确认收货
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function shippingedOrder($id, Request $request)
|
||||||
|
{
|
||||||
|
return response()->noContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取消订单
|
||||||
|
*
|
||||||
|
* @param [type] $id
|
||||||
|
* @param Request $request
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function cancelOrder($id, Request $request)
|
||||||
|
{
|
||||||
|
return response()->noContent();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,14 +15,19 @@ class OrderResource extends JsonResource
|
||||||
public function toArray($request)
|
public function toArray($request)
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
'id' => $this->id,
|
||||||
'sn' =>$this->sn,
|
'sn' =>$this->sn,
|
||||||
'product'=>OrderProductResource::collection($this->products),
|
'product'=>OrderProductResource::collection($this->products),
|
||||||
'total_amount' => $this->total_amount,
|
'total_amount' => $this->total_amount,
|
||||||
'created_at' => $this->created_at->toDateTimeString(),
|
'created_at' => $this->created_at->toDateTimeString(),
|
||||||
'status' => $this->status,
|
'status' => $this->status,
|
||||||
'pay_info' => $this->pay_info??$this->consignor->dealer->pay_info,
|
'pay_info' => $this->getConsignorPayInfo(),
|
||||||
'pay_image'=> $this->pay_image,
|
'pay_image'=> $this->pay_image,
|
||||||
'is_consignor' => $request->user()->id == $this->consignor_id, //是否发货人身份
|
'is_consignor' => $request->user()->id == $this->consignor_id, //是否发货人身份
|
||||||
|
'consignee_name'=>$this->consignee_name,
|
||||||
|
'consignee_telephone'=>$this->consignee_telephone,
|
||||||
|
'consignee_zone' => $this->consignee_zone,
|
||||||
|
'consignee_address' => $this->consignee_address,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ class OrderSimpleResource extends JsonResource
|
||||||
public function toArray($request)
|
public function toArray($request)
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
'id' => $this->id,
|
||||||
'sn' =>$this->sn,
|
'sn' =>$this->sn,
|
||||||
'total_amount' => $this->total_amount,
|
'total_amount' => $this->total_amount,
|
||||||
'created_at' => $this->created_at->toDateTimeString(),
|
'created_at' => $this->created_at->toDateTimeString(),
|
||||||
|
|
|
||||||
|
|
@ -231,5 +231,14 @@ Route::group([
|
||||||
Route::post('orders', [Dealer\OrderController::class, 'store']);
|
Route::post('orders', [Dealer\OrderController::class, 'store']);
|
||||||
//订单详情
|
//订单详情
|
||||||
Route::get('orders/{order}', [Dealer\OrderController::class, 'show']);
|
Route::get('orders/{order}', [Dealer\OrderController::class, 'show']);
|
||||||
|
|
||||||
|
//确认接单
|
||||||
|
Route::post('orders/{order}/confirm', [Dealer\OrderController::class, 'confirmOrder']);
|
||||||
|
//确认打款
|
||||||
|
Route::post('orders/{order}/pay', [Dealer\OrderController::class, 'payOrder']);
|
||||||
|
//确认收款
|
||||||
|
Route::post('orders/{order}/paid', [Dealer\OrderController::class, 'paidOrder']);
|
||||||
|
//确认收货
|
||||||
|
Route::post('orders/{order}/shippinged', [Dealer\OrderController::class, 'shippingedOrder']);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,11 @@
|
||||||
namespace App\Enums;
|
namespace App\Enums;
|
||||||
|
|
||||||
enum DealerOrderStatus: int {
|
enum DealerOrderStatus: int {
|
||||||
case Pending = 0;
|
case Pending = 0; // 待确认
|
||||||
case Paying = 1;
|
case Paying = 1; // 已确认 待付款
|
||||||
case Confirming = 2;
|
case Confirming = 2; // 已付款 待收款
|
||||||
case Paid = 3;
|
case Paid = 3; // 已收款 待发货
|
||||||
case Shipped = 4;
|
case Shipped = 4; // 已发货 待收货
|
||||||
case Completed = 5;
|
case Completed = 9; // 已完成
|
||||||
case Cancelled = 9;
|
case Cancelled = 10; // 已取消
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,17 +14,6 @@ class DealerOrder extends Model
|
||||||
use Filterable;
|
use Filterable;
|
||||||
use HasDateTimeFormatter;
|
use HasDateTimeFormatter;
|
||||||
|
|
||||||
/**
|
|
||||||
* 订单状态
|
|
||||||
*/
|
|
||||||
public const STATUS_PENDING = 0; // 待确认
|
|
||||||
public const STATUS_PENDINGED = 1; // 已确认 待付款
|
|
||||||
public const STATUS_PAY = 2; // 已付款 待收款
|
|
||||||
public const STATUS_PAID = 3; // 已收款 待发货
|
|
||||||
public const STATUS_SHIPPING = 4; // 已发货 待收货
|
|
||||||
public const STATUS_COMPLETED = 9; // 已完成
|
|
||||||
public const STATUS_CANCELLED = 10; // 已取消
|
|
||||||
|
|
||||||
protected $attributes = [
|
protected $attributes = [
|
||||||
'status' => DealerOrderStatus::Pending,
|
'status' => DealerOrderStatus::Pending,
|
||||||
'settle_state' => DealerOrderSettleState::Pending,
|
'settle_state' => DealerOrderSettleState::Pending,
|
||||||
|
|
@ -34,6 +23,26 @@ class DealerOrder extends Model
|
||||||
'status' => DealerOrderStatus::class,
|
'status' => DealerOrderStatus::class,
|
||||||
'settle_state' => DealerOrderSettleState::class,
|
'settle_state' => DealerOrderSettleState::class,
|
||||||
'pay_info'=>JsonArray::class,
|
'pay_info'=>JsonArray::class,
|
||||||
|
'pay_time'=> 'datetime',
|
||||||
|
'paied_time'=>'datetime',
|
||||||
|
'shipping_time'=>'datetime',
|
||||||
|
'shippinged_time'=>'datetime',
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'status',
|
||||||
|
'pay_info',
|
||||||
|
'pay_image',
|
||||||
|
'consignor_id',
|
||||||
|
'settle_state',
|
||||||
|
'consignee_name',
|
||||||
|
'consignee_telephone',
|
||||||
|
'consignee_zone',
|
||||||
|
'consignee_address',
|
||||||
|
'pay_time',
|
||||||
|
'paied_time',
|
||||||
|
'shipping_time',
|
||||||
|
'shippinged_time',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -41,7 +50,7 @@ class DealerOrder extends Model
|
||||||
*/
|
*/
|
||||||
public function scopeOnlyPending($query)
|
public function scopeOnlyPending($query)
|
||||||
{
|
{
|
||||||
return $query->where('status', static::STATUS_PENDING);
|
return $query->where('status', DealerOrderStatus::Pending);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -49,15 +58,15 @@ class DealerOrder extends Model
|
||||||
*/
|
*/
|
||||||
public function scopeOnlyPendinged($query)
|
public function scopeOnlyPendinged($query)
|
||||||
{
|
{
|
||||||
return $query->where('status', static::STATUS_PENDINGED);
|
return $query->where('status', DealerOrderStatus::Paying);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 已收款/待发货
|
* 待收款+待发货
|
||||||
*/
|
*/
|
||||||
public function scopeOnlyPaid($query)
|
public function scopeOnlyPaid($query)
|
||||||
{
|
{
|
||||||
return $query->where('status', static::STATUS_PAID);
|
return $query->where('status', DealerOrderStatus::Confirming);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -65,7 +74,7 @@ class DealerOrder extends Model
|
||||||
*/
|
*/
|
||||||
public function scopeOnlyShipping($query)
|
public function scopeOnlyShipping($query)
|
||||||
{
|
{
|
||||||
return $query->where('status', static::STATUS_SHIPPING);
|
return $query->where('status', DealerOrderStatus::Shipped);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -73,7 +82,7 @@ class DealerOrder extends Model
|
||||||
*/
|
*/
|
||||||
public function scopeOnlyCompleted($query)
|
public function scopeOnlyCompleted($query)
|
||||||
{
|
{
|
||||||
return $query->where('status', static::STATUS_COMPLETED);
|
return $query->where('status', DealerOrderStatus::Completed);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -81,7 +90,7 @@ class DealerOrder extends Model
|
||||||
*/
|
*/
|
||||||
public function scopeOnlyCancelled($query)
|
public function scopeOnlyCancelled($query)
|
||||||
{
|
{
|
||||||
return $query->where('status', static::STATUS_CANCELLED);
|
return $query->where('status', DealerOrderStatus::Cancelled);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -120,8 +129,81 @@ class DealerOrder extends Model
|
||||||
return $this->consignor_id == $userId;
|
return $this->consignor_id == $userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否待确认订单
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function isPending()
|
||||||
|
{
|
||||||
|
return $this->status == DealerOrderStatus::Pending;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否待打款订单
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function isPendinged()
|
||||||
|
{
|
||||||
|
return $this->status == DealerOrderStatus::Paying;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是待确认打款订单
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function isPay()
|
||||||
|
{
|
||||||
|
return $this->status == DealerOrderStatus::Confirming;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否待收货订单
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function isShipping()
|
||||||
|
{
|
||||||
|
return $this->status == DealerOrderStatus::Shipped;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否已取消
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function isCancelled()
|
||||||
|
{
|
||||||
|
return $this->status == DealerOrderStatus::Cancelled;
|
||||||
|
}
|
||||||
|
|
||||||
public function canCurd($userId)
|
public function canCurd($userId)
|
||||||
{
|
{
|
||||||
return $this->isUser($userId) || $this->isConsignor($userId);
|
return $this->isUser($userId) || $this->isConsignor($userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取发货人的打款信息
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function getConsignorPayInfo()
|
||||||
|
{
|
||||||
|
if ($this->isPendinged()) {//待打款订单显示发货人收款信息
|
||||||
|
if ($this->consignor?->dealer) {
|
||||||
|
$payInfo = $this->consignor->dealer->pay_info;
|
||||||
|
} else {
|
||||||
|
$payInfo = [
|
||||||
|
//todo-公司的收款信息
|
||||||
|
];
|
||||||
|
}
|
||||||
|
} elseif ($this->isPending() || $this->isCancelled()) {//如果是已取消订单或者待确认订单不显示收款信息
|
||||||
|
$payInfo = [];
|
||||||
|
} else {
|
||||||
|
$payInfo = $this->pay_info;
|
||||||
|
}
|
||||||
|
return $payInfo;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
namespace App\Services\Dealer;
|
namespace App\Services\Dealer;
|
||||||
|
|
||||||
use App\Enums\DealerLvl;
|
use App\Enums\DealerLvl;
|
||||||
|
use App\Enums\DealerOrderStatus;
|
||||||
use App\Exceptions\BizException;
|
use App\Exceptions\BizException;
|
||||||
use App\Models\DealerOrder;
|
use App\Models\DealerOrder;
|
||||||
use App\Models\DealerProduct;
|
use App\Models\DealerProduct;
|
||||||
|
|
@ -47,6 +48,15 @@ class OrderService
|
||||||
return bcmul($salePrice, $number, 2);
|
return bcmul($salePrice, $number, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建订单
|
||||||
|
*
|
||||||
|
* @param User $user
|
||||||
|
* @param DealerProduct $product
|
||||||
|
* @param integer $number
|
||||||
|
* @param integer $shippingAddressId
|
||||||
|
* @return DealerOrder $order
|
||||||
|
*/
|
||||||
public function createOrder(User $user, DealerProduct $product, int $number = 0, int $shippingAddressId)
|
public function createOrder(User $user, DealerProduct $product, int $number = 0, int $shippingAddressId)
|
||||||
{
|
{
|
||||||
//判断是否满足当前等级最低补货价
|
//判断是否满足当前等级最低补货价
|
||||||
|
|
@ -99,6 +109,40 @@ class OrderService
|
||||||
return $order;
|
return $order;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 确认接单
|
||||||
|
*
|
||||||
|
* @param DealerOrder $order
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function confirmOrder(DealerOrder $order)
|
||||||
|
{
|
||||||
|
if (!$order->isPending()) {
|
||||||
|
throw new BizException('订单状态异常,请刷新后再试');
|
||||||
|
}
|
||||||
|
$order->update([
|
||||||
|
'status' => DealerOrderStatus::Paying,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 确认打款
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function payOrder(DealerOrder $order, string $payImage)
|
||||||
|
{
|
||||||
|
if (!$order->isPendinged()) {
|
||||||
|
throw new BizException('订单状态异常,请刷新后再试');
|
||||||
|
}
|
||||||
|
$order->update([
|
||||||
|
'status' => DealerOrderStatus::Confirming,
|
||||||
|
'pay_image' => $payImage,
|
||||||
|
'pay_info' => $order->getConsignorPayInfo()??null,
|
||||||
|
'pay_time' => now(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新订单发货人
|
* 更新订单发货人
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class AddManagerSubsidyToDealerProductsTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('dealer_products', function (Blueprint $table) {
|
||||||
|
//
|
||||||
|
$table->unsignedDecimal('manager_subsidy')->default(0.00)->comment('管理者津贴');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('dealer_products', function (Blueprint $table) {
|
||||||
|
//
|
||||||
|
$table->dropColumn(['manager_subsidy']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -12,6 +12,7 @@ return [
|
||||||
'images' => '商品图片',
|
'images' => '商品图片',
|
||||||
'description' => '商品详情',
|
'description' => '商品详情',
|
||||||
'price' => '销售价格',
|
'price' => '销售价格',
|
||||||
|
'manager_subsidy'=>'管理者津贴',
|
||||||
'stock' => '库存',
|
'stock' => '库存',
|
||||||
'sales_count' => '销量',
|
'sales_count' => '销量',
|
||||||
'is_sale' => '是否在售',
|
'is_sale' => '是否在售',
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue