diff --git a/app/Admin/Controllers/DealerProductController.php b/app/Admin/Controllers/DealerProductController.php index c7ba4a2c..2e3f7f4d 100644 --- a/app/Admin/Controllers/DealerProductController.php +++ b/app/Admin/Controllers/DealerProductController.php @@ -32,6 +32,7 @@ class DealerProductController extends AdminController // $grid->column('images'); // $grid->column('description'); $grid->column('price')->prepend('¥'); + $grid->column('manager_subsidy')->prepend('¥'); // $grid->column('stock'); // $grid->column('sales_count'); $grid->column('is_sale')->if(function () { @@ -123,7 +124,8 @@ class DealerProductController extends AdminController ->retainable() ->autoUpload(); $form->editor('description'); - $form->currency('price')->symbol('¥'); + $form->currency('price')->symbol('¥')->required(); + $form->currency('manager_subsidy')->symbol('¥')->required(); // $form->text('stock'); // $form->text('sales_count'); $form->switch('is_sale'); diff --git a/app/Endpoint/Api/Http/Controllers/Account/WalletController.php b/app/Endpoint/Api/Http/Controllers/Account/WalletController.php index e7e9b7bd..61c40781 100644 --- a/app/Endpoint/Api/Http/Controllers/Account/WalletController.php +++ b/app/Endpoint/Api/Http/Controllers/Account/WalletController.php @@ -209,7 +209,7 @@ class WalletController extends Controller throw new BizException('可提账户已被限制提现'); } - // todo-校验提现门槛 + // 校验提现门槛 if (bcdiv($amount, 100, 2) < app_settings('withdraw.threshold_amount', 0)) { throw new BizException('提现金额需大于'.app_settings('withdraw.threshold_amount', 0).'元'); } diff --git a/app/Endpoint/Api/Http/Controllers/Dealer/OrderController.php b/app/Endpoint/Api/Http/Controllers/Dealer/OrderController.php index e245fbe7..aabe4946 100644 --- a/app/Endpoint/Api/Http/Controllers/Dealer/OrderController.php +++ b/app/Endpoint/Api/Http/Controllers/Dealer/OrderController.php @@ -100,4 +100,77 @@ class OrderController extends Controller '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(); + } } diff --git a/app/Endpoint/Api/Http/Resources/Dealer/OrderResource.php b/app/Endpoint/Api/Http/Resources/Dealer/OrderResource.php index 174a11fe..ea808ec0 100644 --- a/app/Endpoint/Api/Http/Resources/Dealer/OrderResource.php +++ b/app/Endpoint/Api/Http/Resources/Dealer/OrderResource.php @@ -15,14 +15,19 @@ class OrderResource extends JsonResource public function toArray($request) { return [ + 'id' => $this->id, 'sn' =>$this->sn, 'product'=>OrderProductResource::collection($this->products), 'total_amount' => $this->total_amount, 'created_at' => $this->created_at->toDateTimeString(), 'status' => $this->status, - 'pay_info' => $this->pay_info??$this->consignor->dealer->pay_info, + 'pay_info' => $this->getConsignorPayInfo(), 'pay_image'=> $this->pay_image, '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, ]; } } diff --git a/app/Endpoint/Api/Http/Resources/Dealer/OrderSimpleResource.php b/app/Endpoint/Api/Http/Resources/Dealer/OrderSimpleResource.php index 6824d333..0ce8ab51 100644 --- a/app/Endpoint/Api/Http/Resources/Dealer/OrderSimpleResource.php +++ b/app/Endpoint/Api/Http/Resources/Dealer/OrderSimpleResource.php @@ -15,6 +15,7 @@ class OrderSimpleResource extends JsonResource public function toArray($request) { return [ + 'id' => $this->id, 'sn' =>$this->sn, 'total_amount' => $this->total_amount, 'created_at' => $this->created_at->toDateTimeString(), diff --git a/app/Endpoint/Api/routes.php b/app/Endpoint/Api/routes.php index 99353830..93910463 100644 --- a/app/Endpoint/Api/routes.php +++ b/app/Endpoint/Api/routes.php @@ -231,5 +231,14 @@ Route::group([ Route::post('orders', [Dealer\OrderController::class, 'store']); //订单详情 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']); }); }); diff --git a/app/Enums/DealerOrderStatus.php b/app/Enums/DealerOrderStatus.php index 4070107e..89e96c54 100644 --- a/app/Enums/DealerOrderStatus.php +++ b/app/Enums/DealerOrderStatus.php @@ -3,11 +3,11 @@ namespace App\Enums; enum DealerOrderStatus: int { - case Pending = 0; - case Paying = 1; - case Confirming = 2; - case Paid = 3; - case Shipped = 4; - case Completed = 5; - case Cancelled = 9; + case Pending = 0; // 待确认 + case Paying = 1; // 已确认 待付款 + case Confirming = 2; // 已付款 待收款 + case Paid = 3; // 已收款 待发货 + case Shipped = 4; // 已发货 待收货 + case Completed = 9; // 已完成 + case Cancelled = 10; // 已取消 } diff --git a/app/Models/DealerOrder.php b/app/Models/DealerOrder.php index 95cb973e..8d0c3ba2 100644 --- a/app/Models/DealerOrder.php +++ b/app/Models/DealerOrder.php @@ -14,17 +14,6 @@ class DealerOrder extends Model use Filterable; 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 = [ 'status' => DealerOrderStatus::Pending, 'settle_state' => DealerOrderSettleState::Pending, @@ -34,6 +23,26 @@ class DealerOrder extends Model 'status' => DealerOrderStatus::class, 'settle_state' => DealerOrderSettleState::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) { - 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) { - return $query->where('status', static::STATUS_PENDINGED); + return $query->where('status', DealerOrderStatus::Paying); } /** - * 已收款/待发货 + * 待收款+待发货 */ 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) { - 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) { - 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) { - 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 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) { 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; + } } diff --git a/app/Services/Dealer/OrderService.php b/app/Services/Dealer/OrderService.php index e775bcc3..e12c3b8f 100644 --- a/app/Services/Dealer/OrderService.php +++ b/app/Services/Dealer/OrderService.php @@ -3,6 +3,7 @@ namespace App\Services\Dealer; use App\Enums\DealerLvl; +use App\Enums\DealerOrderStatus; use App\Exceptions\BizException; use App\Models\DealerOrder; use App\Models\DealerProduct; @@ -47,6 +48,15 @@ class OrderService 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) { //判断是否满足当前等级最低补货价 @@ -99,6 +109,40 @@ class OrderService 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(), + ]); + } + /** * 更新订单发货人 * diff --git a/database/migrations/2022_01_14_175143_add_manager_subsidy_to_dealer_products_table.php b/database/migrations/2022_01_14_175143_add_manager_subsidy_to_dealer_products_table.php new file mode 100644 index 00000000..dcebf7c0 --- /dev/null +++ b/database/migrations/2022_01_14_175143_add_manager_subsidy_to_dealer_products_table.php @@ -0,0 +1,34 @@ +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']); + }); + } +} diff --git a/resources/lang/zh_CN/dealer-product.php b/resources/lang/zh_CN/dealer-product.php index d307fd69..afd33f8d 100644 --- a/resources/lang/zh_CN/dealer-product.php +++ b/resources/lang/zh_CN/dealer-product.php @@ -12,6 +12,7 @@ return [ 'images' => '商品图片', 'description' => '商品详情', 'price' => '销售价格', + 'manager_subsidy'=>'管理者津贴', 'stock' => '库存', 'sales_count' => '销量', 'is_sale' => '是否在售',