From 056e8f0833d1964057cdc7c286b97be090f8026b Mon Sep 17 00:00:00 2001 From: vine_liutk <961510893@qq.com> Date: Fri, 11 Feb 2022 17:39:21 +0800 Subject: [PATCH 01/30] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=89=B9=E9=9B=B6?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E4=BD=99=E9=A2=9D=E6=94=AF=E4=BB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/DealerOrderController.php | 7 +++ .../Controllers/Dealer/OrderController.php | 48 ++++++++++++++++++- app/Endpoint/Api/routes.php | 4 +- app/Enums/DealerWalletAction.php | 2 + app/Models/DealerOrder.php | 9 ++++ app/Services/Dealer/OrderService.php | 39 ++++++++++++--- ...430_add_pay_way_to_dealer_orders_table.php | 34 +++++++++++++ resources/lang/zh_CN/dealer-order.php | 1 + 8 files changed, 135 insertions(+), 9 deletions(-) create mode 100644 database/migrations/2022_02_11_163430_add_pay_way_to_dealer_orders_table.php diff --git a/app/Admin/Controllers/DealerOrderController.php b/app/Admin/Controllers/DealerOrderController.php index c23a503a..e8b3d784 100644 --- a/app/Admin/Controllers/DealerOrderController.php +++ b/app/Admin/Controllers/DealerOrderController.php @@ -10,6 +10,7 @@ use App\Admin\Actions\Show\DealerOrderRemark; use App\Admin\Repositories\DealerOrder; use App\Enums\DealerOrderStatus; use App\Models\DealerChannelSubsidyLog; +use App\Models\DealerOrder as DealerOrderModel; use App\Models\DealerOrderProduct; use Dcat\Admin\Admin; use Dcat\Admin\Form; @@ -48,6 +49,12 @@ class DealerOrderController extends AdminController $grid->column('total_amount')->prepend('¥'); $statusTexts = DealerOrderStatus::texts(); + $grid->column('pay_way')->using(DealerOrderModel::$payWayText)->label([ + 'wallet'=>'warning', + 'offline'=>'danger', + 'none'=>'#b3b9bf', + ]); + $grid->column('order_status')->display(function ($v) { return $this->order_status; })->using($statusTexts)->dot([ diff --git a/app/Endpoint/Api/Http/Controllers/Dealer/OrderController.php b/app/Endpoint/Api/Http/Controllers/Dealer/OrderController.php index 72f9e5b9..f77b69ad 100644 --- a/app/Endpoint/Api/Http/Controllers/Dealer/OrderController.php +++ b/app/Endpoint/Api/Http/Controllers/Dealer/OrderController.php @@ -138,8 +138,21 @@ class OrderController extends Controller $input = $request->validate([ 'pay_image' => ['bail', 'string'], + 'pay_way' => ['bail', 'string'], ]); - $orderService->payOrder($order, $input['pay_image'] ?? null); + try { + DB::beginTransaction(); + $orderService->payOrder($order, $input['pay_way'] ?? 'offline', $input['pay_image'] ?? null); + DB::commit(); + } catch (BizException $th) { + DB::rollBack(); + throw $th; + } catch (Throwable $th) { + DB::rollBack(); + report($th); + throw new BizException('操作失败,请刷新后再试'); + } + return response()->noContent(); } @@ -166,7 +179,40 @@ class OrderController extends Controller if (strpos($e->getMessage(), 'Numeric value out of range') !== false) { $e = new BizException('当前可发货库存不足'); } + throw $e; + } catch (Throwable $th) { + DB::rollBack(); + report($th); + throw new BizException('操作失败,请刷新后再试'); + } + return response()->noContent(); + } + /** + * 确认发货 + * + * @param [type] $id + * @param Request $request + * @param OrderService $orderService + * @return void + */ + public function shippingOrder($id, Request $request, OrderService $orderService) + { + $order = DealerOrder::findOrFail($id); + $userId = $request->user()->id; + //不是发货人 + if (!$order->isConsignor($userId)) { + throw new BizException('订单未找到'); + } + try { + DB::beginTransaction(); + $orderService->shippingOrder($order);//确认发货 + DB::commit(); + } catch (QueryException $e) { + DB::rollBack(); + if (strpos($e->getMessage(), 'Numeric value out of range') !== false) { + $e = new BizException('当前可发货库存不足'); + } throw $e; } catch (Throwable $th) { DB::rollBack(); diff --git a/app/Endpoint/Api/routes.php b/app/Endpoint/Api/routes.php index 7da84fbf..0f1412c0 100644 --- a/app/Endpoint/Api/routes.php +++ b/app/Endpoint/Api/routes.php @@ -250,8 +250,10 @@ Route::group([ 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}/shipping', [Dealer\OrderController::class, 'shippingOrder']); //确认收货 Route::post('orders/{order}/shippinged', [Dealer\OrderController::class, 'shippingedOrder']); //取消订单 diff --git a/app/Enums/DealerWalletAction.php b/app/Enums/DealerWalletAction.php index 9619f5fc..8ab1f585 100644 --- a/app/Enums/DealerWalletAction.php +++ b/app/Enums/DealerWalletAction.php @@ -9,4 +9,6 @@ enum DealerWalletAction: int { case ChannelSubsidyIn = 4; case WithdrawBank = 5; case WithdrawFiled = 6; + case OrderPaid = 7; + case OrderIncome = 8; } diff --git a/app/Models/DealerOrder.php b/app/Models/DealerOrder.php index 6dd699e3..f53485d2 100644 --- a/app/Models/DealerOrder.php +++ b/app/Models/DealerOrder.php @@ -14,6 +14,9 @@ class DealerOrder extends Model use Filterable; use HasDateTimeFormatter; + public const PAY_WAY_WALLET = 'wallet'; // 余额 + public const PAY_WAY_OFFLINE = 'offline'; // 线下支付 + protected $attributes = [ 'status' => DealerOrderStatus::Pending, 'settle_state' => DealerOrderSettleState::Pending, @@ -40,6 +43,7 @@ class DealerOrder extends Model 'consignee_telephone', 'consignee_zone', 'consignee_address', + 'pay_way', 'pay_time', 'paied_time', 'shipping_time', @@ -48,6 +52,11 @@ class DealerOrder extends Model 'remark', ]; + public static $payWayText = [ + self::PAY_WAY_WALLET => '余额支付', + self::PAY_WAY_OFFLINE => '线下打款', + ]; + /** * 仅获取待结算的已付款订单 */ diff --git a/app/Services/Dealer/OrderService.php b/app/Services/Dealer/OrderService.php index 28e68407..32a8529e 100644 --- a/app/Services/Dealer/OrderService.php +++ b/app/Services/Dealer/OrderService.php @@ -4,6 +4,7 @@ namespace App\Services\Dealer; use App\Enums\DealerLvl; use App\Enums\DealerOrderStatus; +use App\Enums\DealerWalletAction; use App\Exceptions\BizException; use App\Models\DealerOrder; use App\Models\DealerOrderAllocateLog; @@ -136,17 +137,41 @@ class OrderService * * @return void */ - public function payOrder(DealerOrder $order, ?string $payImage) + public function payOrder(DealerOrder $order, string $payWay, ?string $payImage) { + if (empty($payWay)) { + throw new BizException('请选择付款方式'); + } if (!$order->isPendinged()) { throw new BizException('订单状态异常,请刷新后再试'); } - $order->update([ - 'status' => DealerOrderStatus::Confirming, - 'pay_image' => $payImage, - 'pay_info' => $order->getConsignorPayInfo() ?? null, - 'pay_time' => now(), - ]); + switch ($payWay) { + case DealerOrder::PAY_WAY_WALLET: + /** 付款以及完成确认收款动作 **/ + $walletService = new WalletService(); + //付款 + $walletService->changeBalance($order->user, 0 - $order->total_amount, DealerWalletAction::OrderPaid, '订单:'.$order->sn, $order); + $order->update([ + 'status'=>DealerOrderStatus::Confirming, + 'pay_time' => now(), + 'pay_way' => DealerOrder::PAY_WAY_WALLET, + ]); + //收款 + if ($order->consignor) { + $walletService->changeBalance($order->consignor, $order->total_amount, DealerWalletAction::OrderIncome, '订单:'.$order->sn, $order); + } + $this->paidOrder($order); + break; + case DealerOrder::PAY_WAY_OFFLINE: + $order->update([ + 'status' => DealerOrderStatus::Confirming, + 'pay_image' => $payImage, + 'pay_info' => $order->getConsignorPayInfo() ?? null, + 'pay_time' => now(), + 'pay_way' => DealerOrder::PAY_WAY_OFFLINE, + ]); + break; + } } /** diff --git a/database/migrations/2022_02_11_163430_add_pay_way_to_dealer_orders_table.php b/database/migrations/2022_02_11_163430_add_pay_way_to_dealer_orders_table.php new file mode 100644 index 00000000..f4684385 --- /dev/null +++ b/database/migrations/2022_02_11_163430_add_pay_way_to_dealer_orders_table.php @@ -0,0 +1,34 @@ +string('pay_way')->nullable()->comment('1线下打款,2余额'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('dealer_orders', function (Blueprint $table) { + // + $table->dropColumn('pay_way'); + }); + } +} diff --git a/resources/lang/zh_CN/dealer-order.php b/resources/lang/zh_CN/dealer-order.php index 2718e254..c42837db 100644 --- a/resources/lang/zh_CN/dealer-order.php +++ b/resources/lang/zh_CN/dealer-order.php @@ -33,6 +33,7 @@ return [ 'consignee_address' => '收货人详细地址', 'pay_info' => '收款信息', 'pay_image' => '打款凭证', + 'pay_way'=>'支付方式', 'pay_time' => '支付时间', 'paied_time' => '确认收款时间', 'shipping_time' => '发货时间', From b4861ae30e4117365fdbf2646e08fd78bf03997b Mon Sep 17 00:00:00 2001 From: vine_liutk <961510893@qq.com> Date: Fri, 11 Feb 2022 17:45:01 +0800 Subject: [PATCH 02/30] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=89=B9=E9=9B=B6?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E5=BE=85=E5=8F=91=E8=B4=A7=E9=80=89=E9=A1=B9?= =?UTF-8?q?=E5=8D=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Endpoint/Api/Filters/DealerOrderFilter.php | 5 ++++- app/Models/DealerOrder.php | 12 ++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/app/Endpoint/Api/Filters/DealerOrderFilter.php b/app/Endpoint/Api/Filters/DealerOrderFilter.php index df99b425..b77c5f21 100644 --- a/app/Endpoint/Api/Filters/DealerOrderFilter.php +++ b/app/Endpoint/Api/Filters/DealerOrderFilter.php @@ -18,9 +18,12 @@ class DealerOrderFilter extends ModelFilter case 'wait_paid'://待收款 $this->onlyPaid(); break; - case 'wait_shippinged'://待收货 + case 'wait_shipping'://待发货 $this->onlyShipping(); break; + case 'wait_shippinged'://待收货 + $this->onlyShippinged(); + break; case 'completed'://已完成 $this->onlyCompleted(); break; diff --git a/app/Models/DealerOrder.php b/app/Models/DealerOrder.php index f53485d2..d59eb00c 100644 --- a/app/Models/DealerOrder.php +++ b/app/Models/DealerOrder.php @@ -88,17 +88,25 @@ class DealerOrder extends Model } /** - * 待收款+待发货 + * 待收款 */ public function scopeOnlyPaid($query) { return $query->where('status', DealerOrderStatus::Confirming); } + /** + * 待发货 + */ + public function scopenOnliyShipping($query) + { + return $query->where('status', DealerOrderStatus::Paid); + } + /** * 已发货/待收货 */ - public function scopeOnlyShipping($query) + public function scopeOnlyShippinged($query) { // return $query->whereIn('status', [ // DealerOrderStatus::Confirming, DealerOrderStatus::Paid, DealerOrderStatus::Shipped, From 8e1a6251971821664ea586fcdee3638eccd88c34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Mon, 14 Feb 2022 09:45:48 +0800 Subject: [PATCH 03/30] =?UTF-8?q?=E5=BD=93=E5=89=8D=E8=BF=9B=E8=B4=A7?= =?UTF-8?q?=E4=B8=9A=E7=BB=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Api/Http/Controllers/Dealer/UserController.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app/Endpoint/Api/Http/Controllers/Dealer/UserController.php b/app/Endpoint/Api/Http/Controllers/Dealer/UserController.php index cd565d63..a6f93c5e 100644 --- a/app/Endpoint/Api/Http/Controllers/Dealer/UserController.php +++ b/app/Endpoint/Api/Http/Controllers/Dealer/UserController.php @@ -2,6 +2,7 @@ namespace App\Endpoint\Api\Http\Controllers\Dealer; +use App\Actions\Dealer\CalculatePurchaseAmountOfCurrentPeriod; use App\Endpoint\Api\Http\Controllers\Controller; use App\Endpoint\Api\Http\Resources\Dealer\DealerResource; use App\Endpoint\Api\Http\Resources\Dealer\UserInfoResource; @@ -13,15 +14,21 @@ class UserController extends Controller * 个人信息 * * @param \Illuminate\Http\Request $request + * @param \App\Actions\Dealer\CalculatePurchaseAmountOfCurrentPeriod $calculatePurchaseAmountOfCurrentPeriod * @return \Illuminate\Http\JsonResponse */ - public function show(Request $request) - { + public function show( + Request $request, + CalculatePurchaseAmountOfCurrentPeriod $calculatePurchaseAmountOfCurrentPeriod + ) { $user = $request->user(); + $dealer = DealerResource::make($user->dealer)->toArray($request); + $dealer['current_purchase_amount'] = $calculatePurchaseAmountOfCurrentPeriod->handle($user->dealer); + return response()->json([ 'phone' => $user->phone, - 'dealer'=> $user->dealer ? DealerResource::make($user->dealer) : [], + 'dealer'=> $dealer, 'dealer_wallet' => $user->dealerWallet?->balance, 'user_info' => UserInfoResource::make($user->userInfo), ]); From 98c9399e21e332fa06fc8ba1bc3fee00cfb841d9 Mon Sep 17 00:00:00 2001 From: vine_liutk <961510893@qq.com> Date: Mon, 14 Feb 2022 10:25:32 +0800 Subject: [PATCH 04/30] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BD=99=E9=A2=9D?= =?UTF-8?q?=E6=94=AF=E4=BB=98-=E6=94=AF=E4=BB=98=E5=AF=86=E7=A0=81?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Api/Http/Controllers/Dealer/OrderController.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/Endpoint/Api/Http/Controllers/Dealer/OrderController.php b/app/Endpoint/Api/Http/Controllers/Dealer/OrderController.php index f77b69ad..600e010b 100644 --- a/app/Endpoint/Api/Http/Controllers/Dealer/OrderController.php +++ b/app/Endpoint/Api/Http/Controllers/Dealer/OrderController.php @@ -6,6 +6,7 @@ use App\Endpoint\Api\Http\Controllers\Controller; use App\Endpoint\Api\Http\Resources\Dealer\OrderResource; use App\Endpoint\Api\Http\Resources\Dealer\OrderSimpleResource; use App\Exceptions\BizException; +use App\Exceptions\PayPasswordIncorrectException; use App\Helpers\Paginator as PaginatorHelper; use App\Models\DealerOrder; use App\Models\DealerProduct; @@ -139,7 +140,19 @@ class OrderController extends Controller $input = $request->validate([ 'pay_image' => ['bail', 'string'], 'pay_way' => ['bail', 'string'], + 'pay_password' => ['bail', 'string'], + ], [], [ + 'pay_image' => '打款凭证', + 'pay_way' => '支付方式', + 'pay_password' => '支付密码', ]); + $payWay = $input['pay_way'] ?? 'offline'; + if ($payWay == DealerOrder::PAY_WAY_WALLET) { + //验证支付密码 + if (! $request->user()->wallet?->verifyPassword($input['pay_password'] ?? '')) { + throw new PayPasswordIncorrectException(); + } + } try { DB::beginTransaction(); $orderService->payOrder($order, $input['pay_way'] ?? 'offline', $input['pay_image'] ?? null); From aa78727b0b87195921cd4bc03b815d0f507d36e7 Mon Sep 17 00:00:00 2001 From: vine_liutk <961510893@qq.com> Date: Mon, 14 Feb 2022 11:50:41 +0800 Subject: [PATCH 05/30] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=92=A4=E9=94=80?= =?UTF-8?q?=E7=BA=BF=E4=B8=8B=E5=8E=BB=E5=BA=93=E5=AD=98=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Dealer/UserController.php | 1 + .../Dealer/UserProductController.php | 51 ++++++++++++++++++- .../Dealer/UserProductLogResource.php | 9 +++- app/Endpoint/Api/routes.php | 1 + app/Models/DealerUserProductLog.php | 7 +++ ...voke_to_dealer_user_product_logs_table.php | 34 +++++++++++++ resources/lang/zh_CN/models.php | 2 + 7 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 database/migrations/2022_02_14_114040_add_has_revoke_to_dealer_user_product_logs_table.php diff --git a/app/Endpoint/Api/Http/Controllers/Dealer/UserController.php b/app/Endpoint/Api/Http/Controllers/Dealer/UserController.php index a6f93c5e..c0f92605 100644 --- a/app/Endpoint/Api/Http/Controllers/Dealer/UserController.php +++ b/app/Endpoint/Api/Http/Controllers/Dealer/UserController.php @@ -31,6 +31,7 @@ class UserController extends Controller 'dealer'=> $dealer, 'dealer_wallet' => $user->dealerWallet?->balance, 'user_info' => UserInfoResource::make($user->userInfo), + 'has_password' => (bool) $user->wallet?->password, ]); } diff --git a/app/Endpoint/Api/Http/Controllers/Dealer/UserProductController.php b/app/Endpoint/Api/Http/Controllers/Dealer/UserProductController.php index 38665a82..d78396e1 100644 --- a/app/Endpoint/Api/Http/Controllers/Dealer/UserProductController.php +++ b/app/Endpoint/Api/Http/Controllers/Dealer/UserProductController.php @@ -73,7 +73,7 @@ class UserProductController extends Controller 'product_id'=> $input['product_id'], 'type' => DealerUserProductLog::TYPE_OFFLINE_OUT, 'qty'=>$input['num'], - 'remark'=>$input['remark']??null, + 'remark'=>$input['remark'] ?? null, ]); DB::commit(); } catch (Throwable $th) { @@ -83,4 +83,53 @@ class UserProductController extends Controller } return response()->noContent(); } + + /** + * 撤销线下去库存 + * + */ + public function revokeQtyLog(DealerUserProductLog $log, Request $request) + { + //判断是否是自己的日志 + if ($log->user_id != $request->user()->id) { + throw new BizException('日志未找到'); + } + //是否可以撤销 + if (!$log->canRevoke()) { + throw new BizException('该日志无法撤销'); + } + + $product = $request->user()->dealerProducts() + ->where('product_id', $log->product_id) + ->first(); + if (!$product) { + throw new BizException('您还没有该商品'); + } + + try { + DB::beginTransaction(); + + $product->increment('stock', $log->qty); + + $revokeLog = DealerUserProductLog::create([ + 'user_id'=> $request->user()->id, + 'product_id'=> $log->product_id, + 'type' => DealerUserProductLog::TYPE_REVOKE_IN, + 'qty' => $log->qty, + 'remark'=> '撤销回滚', + ]); + + $log->update([ + 'revoke_id' => $revokeLog->id, + ]); + + DB::commit(); + } catch (Throwable $th) { + DB::rollBack(); + report($th); + throw new BizException('系统繁忙,请稍后再试'); + } + + return response()->noContent(); + } } diff --git a/app/Endpoint/Api/Http/Resources/Dealer/UserProductLogResource.php b/app/Endpoint/Api/Http/Resources/Dealer/UserProductLogResource.php index 852b3bbb..e92bedb7 100644 --- a/app/Endpoint/Api/Http/Resources/Dealer/UserProductLogResource.php +++ b/app/Endpoint/Api/Http/Resources/Dealer/UserProductLogResource.php @@ -16,10 +16,17 @@ class UserProductLogResource extends JsonResource public function toArray($request) { return [ + 'id' => $this->id, 'product_name'=> $this->product?->name, + 'type'=> $this->type, 'remark' => $this->remark, - 'qty' => ($this->type == DealerUserProductLog::TYPE_ORDER_IN ? '+' : '-').$this->qty.$this->product?->unit, + 'qty' => (in_array($this->type, [ + DealerUserProductLog::TYPE_ORDER_IN, + DealerUserProductLog::TYPE_ADMIN_IN, + DealerUserProductLog::TYPE_REVOKE_IN, + ]) ? '+' : '-').$this->qty.$this->product?->unit, 'created_at' => $this->created_at->toDateTimeString(), + 'can_revoke' => $this->canRevoke(), ]; } } diff --git a/app/Endpoint/Api/routes.php b/app/Endpoint/Api/routes.php index 0f1412c0..47ea910d 100644 --- a/app/Endpoint/Api/routes.php +++ b/app/Endpoint/Api/routes.php @@ -236,6 +236,7 @@ Route::group([ Route::get('user-products/{product}', [Dealer\UserProductController::class, 'show']); Route::get('user-products-logs', [Dealer\UserProductController::class, 'logs']); Route::post('user-products/offline-out', [Dealer\UserProductController::class, 'offlineOutQty']); + Route::post('user-products/offline-out-revoke/{log}', [Dealer\UserProductController::class, 'revokeQtyLog']); //计算商品下单价格 Route::get('orders/total-amount', [Dealer\OrderController::class, 'totalAmount']); diff --git a/app/Models/DealerUserProductLog.php b/app/Models/DealerUserProductLog.php index 59e5eef8..8805dd81 100644 --- a/app/Models/DealerUserProductLog.php +++ b/app/Models/DealerUserProductLog.php @@ -18,6 +18,7 @@ class DealerUserProductLog extends Model public const TYPE_OFFLINE_OUT = 3;//线下去库存 public const TYPE_ADMIN_IN = 4;//后台添加库存 public const TYPE_ADMIN_OUT = 5;//后台扣减库存 + public const TYPE_REVOKE_IN = 9;//撤销线下去库存 protected $fillable = [ 'user_id', @@ -25,10 +26,16 @@ class DealerUserProductLog extends Model 'type', 'qty', 'remark', + 'revoke_id', ]; public function product() { return $this->belongsTo(DealerProduct::class, 'product_id'); } + + public function canRevoke() + { + return ($this->type == static::TYPE_OFFLINE_OUT) && ($this->revoke_id == 0); + } } diff --git a/database/migrations/2022_02_14_114040_add_has_revoke_to_dealer_user_product_logs_table.php b/database/migrations/2022_02_14_114040_add_has_revoke_to_dealer_user_product_logs_table.php new file mode 100644 index 00000000..8863418e --- /dev/null +++ b/database/migrations/2022_02_14_114040_add_has_revoke_to_dealer_user_product_logs_table.php @@ -0,0 +1,34 @@ +unsignedBigInteger('revoke_id')->default(0)->comment('撤销关联ID'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('dealer_user_product_logs', function (Blueprint $table) { + // + $table->dropColumn('revoke_id'); + }); + } +} diff --git a/resources/lang/zh_CN/models.php b/resources/lang/zh_CN/models.php index f95ae728..17e6248b 100644 --- a/resources/lang/zh_CN/models.php +++ b/resources/lang/zh_CN/models.php @@ -2,6 +2,7 @@ use App\Models\AfterSale; use App\Models\Article; +use App\Models\DealerUserProductLog; use App\Models\Order; use App\Models\OrderProduct; use App\Models\ProductSku; @@ -23,4 +24,5 @@ return [ AfterSale::class => '售后订单', Article::class => '文章', OrderPackage::class => '包裹', + DealerUserProductLog::class => '日志', ]; From 7be71e7a6e7b0d7ffba03b91d9f677bb7948b8cd Mon Sep 17 00:00:00 2001 From: vine_liutk <961510893@qq.com> Date: Mon, 14 Feb 2022 11:52:15 +0800 Subject: [PATCH 06/30] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=89=B9=E9=9B=B6?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=BA=93=E5=AD=98=E5=8F=98=E5=8A=A8=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Api/Http/Resources/Dealer/UserProductLogResource.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/Endpoint/Api/Http/Resources/Dealer/UserProductLogResource.php b/app/Endpoint/Api/Http/Resources/Dealer/UserProductLogResource.php index e92bedb7..e5d39a51 100644 --- a/app/Endpoint/Api/Http/Resources/Dealer/UserProductLogResource.php +++ b/app/Endpoint/Api/Http/Resources/Dealer/UserProductLogResource.php @@ -18,7 +18,6 @@ class UserProductLogResource extends JsonResource return [ 'id' => $this->id, 'product_name'=> $this->product?->name, - 'type'=> $this->type, 'remark' => $this->remark, 'qty' => (in_array($this->type, [ DealerUserProductLog::TYPE_ORDER_IN, From 9a119e311e080bd82a14779d2b5a0c91ea80982f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Mon, 14 Feb 2022 13:59:59 +0800 Subject: [PATCH 07/30] =?UTF-8?q?=E7=A1=AE=E8=AE=A4=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E5=8F=91=E8=B5=B7=E5=94=AE=E5=90=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Console/Commands/OrderSettleCommand.php | 30 +++++++++-------- .../Controllers/Order/OrderController.php | 2 +- .../Resources/OrderProductSimpleResource.php | 30 +++++++++++++++++ .../Api/Http/Resources/OrderResource.php | 6 ++++ .../Resources/OrderResourceCollection.php | 2 +- app/Models/Order.php | 18 +++-------- app/Models/OrderProduct.php | 21 ++++++++++-- app/Services/OrderService.php | 13 ++++++-- ...33323_add_is_settlable_to_orders_table.php | 32 +++++++++++++++++++ 9 files changed, 120 insertions(+), 34 deletions(-) create mode 100644 app/Endpoint/Api/Http/Resources/OrderProductSimpleResource.php create mode 100644 database/migrations/2022_02_14_133323_add_is_settlable_to_orders_table.php diff --git a/app/Console/Commands/OrderSettleCommand.php b/app/Console/Commands/OrderSettleCommand.php index efcbf55c..366ec30e 100644 --- a/app/Console/Commands/OrderSettleCommand.php +++ b/app/Console/Commands/OrderSettleCommand.php @@ -34,15 +34,27 @@ class OrderSettleCommand extends Command public function handle() { while (true) { - $page = 0; + Order::where( + 'completed_at', + '<=', + now()->subDays(app_settings('distribution.settle_days', 7)) + )->where([ + 'status' => Order::STATUS_COMPLETED, + 'is_settlable' => false, + 'is_settle' => false, + ])->chunkById(200, function ($orders) { + foreach ($orders as $order) { + $order->update([ + 'is_settlable' => true, + ]); + } + }); - // 只查询可结算的订单,并且没有处理中的售后单 - // 检查订单是否有未执行的分销任务 Order::whereDoesntHave('afterSales', function ($query) { return $query->processing(); })->whereDoesntHave('distributionPreIncomeJobs', function ($query) { return $query->pending(); - })->settlable()->chunkById(200, function ($orders) use (&$page) { + })->settlable()->chunkById(200, function ($orders) { $orders->load(['user', 'afterSales']); foreach ($orders as $order) { @@ -58,17 +70,9 @@ class OrderSettleCommand extends Command report($e); } } - - $page++; }); - if ($page === 0) { - sleep(60); - } elseif ($page === 1) { - sleep(30); - } else { - sleep(15); - } + sleep(60); } } diff --git a/app/Endpoint/Api/Http/Controllers/Order/OrderController.php b/app/Endpoint/Api/Http/Controllers/Order/OrderController.php index ce4afee6..c270bb6e 100644 --- a/app/Endpoint/Api/Http/Controllers/Order/OrderController.php +++ b/app/Endpoint/Api/Http/Controllers/Order/OrderController.php @@ -136,7 +136,7 @@ class OrderController extends Controller DB::transaction(function () use ($id, $user) { $order = $user->orders()->lockForUpdate()->findOrFail($id); - (new OrderService())->confirm($order); + (new OrderService())->confirm($order, true); }); return response()->noContent(); diff --git a/app/Endpoint/Api/Http/Resources/OrderProductSimpleResource.php b/app/Endpoint/Api/Http/Resources/OrderProductSimpleResource.php new file mode 100644 index 00000000..db6d0f16 --- /dev/null +++ b/app/Endpoint/Api/Http/Resources/OrderProductSimpleResource.php @@ -0,0 +1,30 @@ + $this->id, + 'sku_id' => $this->sku_id, + 'name' => $this->name, + 'cover' => $this->cover, + 'specs' => array_values((array) $this->specs), + 'sell_price' => $this->sell_price_format, + 'vip_price' => $this->vip_price_format, + 'total_amount' => $this->total_amount, + 'quantity' => $this->quantity, + 'is_gift' => $this->isGift(), + ]; + } +} diff --git a/app/Endpoint/Api/Http/Resources/OrderResource.php b/app/Endpoint/Api/Http/Resources/OrderResource.php index b577e27c..ae989e1c 100644 --- a/app/Endpoint/Api/Http/Resources/OrderResource.php +++ b/app/Endpoint/Api/Http/Resources/OrderResource.php @@ -14,6 +14,12 @@ class OrderResource extends JsonResource */ public function toArray($request) { + if ($this->resource->relationLoaded('products')) { + foreach ($this->resource->products as $product) { + $product->setRelation('order', $this->resource); + } + } + return [ 'id' => $this->id, 'sn' => $this->sn, diff --git a/app/Endpoint/Api/Http/Resources/OrderResourceCollection.php b/app/Endpoint/Api/Http/Resources/OrderResourceCollection.php index ac7fd4cf..a6e0088c 100644 --- a/app/Endpoint/Api/Http/Resources/OrderResourceCollection.php +++ b/app/Endpoint/Api/Http/Resources/OrderResourceCollection.php @@ -21,7 +21,7 @@ class OrderResourceCollection extends ResourceCollection 'total_amount' => $item->total_amount_format, 'status' => $item->order_status, 'created_date' => $item->created_at->toDateString(), - 'products' => OrderProductResource::collection($item->whenLoaded('products')), + 'products' => OrderProductSimpleResource::collection($item->whenLoaded('products')), 'expires_at' => $item->expires_at, ]; })->toArray(); diff --git a/app/Models/Order.php b/app/Models/Order.php index 04387e6c..6a0cd238 100644 --- a/app/Models/Order.php +++ b/app/Models/Order.php @@ -44,6 +44,7 @@ class Order extends Model 'is_settle' => false, 'is_change' => false, 'status' => self::STATUS_PENDING, + 'is_settlable' => false, ]; /** @@ -56,6 +57,7 @@ class Order extends Model 'status' => 'int', 'is_settle' => 'bool', 'is_change' => 'bool', + 'is_settlable' => 'bool', ]; /** @@ -88,6 +90,7 @@ class Order extends Model 'is_change', 'is_settle', 'sales_value', + 'is_settlable', ]; public static $payWayText = [ @@ -123,7 +126,7 @@ class Order extends Model public function scopeSettlable($query) { return $query->where('status', static::STATUS_COMPLETED) - ->where('completed_at', '<=', now()->subDays(app_settings('distribution.settle_days', 7))) + ->where('is_settlable', true) ->where('is_settle', false); } @@ -302,19 +305,6 @@ class Order extends Model return $this->status === static::STATUS_CANCELLED; } - /** - * 将订单标记为已完成 - * - * @return void - */ - public function markAsCompleted() - { - $this->update([ - 'status' => static::STATUS_COMPLETED, - 'completed_at' => now(), - ]); - } - /** * 获取订单券优惠金额 * diff --git a/app/Models/OrderProduct.php b/app/Models/OrderProduct.php index 252867f7..e3462798 100644 --- a/app/Models/OrderProduct.php +++ b/app/Models/OrderProduct.php @@ -81,6 +81,15 @@ class OrderProduct extends Model return $this->belongsTo(ProductSku::class, 'sku_id'); } + /** + * 此订单商品所属的SKU + * + */ + public function order() + { + return $this->belongsTo(Order::class, 'order_id'); + } + /** * 确认此订单商品是否是赠品 * @@ -100,11 +109,15 @@ class OrderProduct extends Model { $res = false; - //老判断,有过期时间,且未到过期时间,未发起过售后 + if ($this->order->is_settlable) { + return false; + } + + // 老判断,有过期时间,且未到过期时间,未发起过售后 // $oldJudge = !is_null($this->after_expire_at) && $this->after_expire_at > now() && $this->after_sale_state == 0; //新判断, 有发货单,在售后时间范围内, 当前无售后; - if ($this->packages()->where('is_failed', false)->count() >0) { + if ($this->packages()->where('is_failed', false)->count() > 0) { if ((is_null($this->after_expire_at) || $this->after_expire_at > now()) && $this->after_sale_state == 0) { $res = true; } @@ -121,9 +134,11 @@ class OrderProduct extends Model public function getHasAfterSaleAttribute(): bool { $res = false; + if ($this->afterSales()->count() > 0) { - $res =true; + $res = true; } + return $res; } diff --git a/app/Services/OrderService.php b/app/Services/OrderService.php index fcb19e0c..a015a248 100644 --- a/app/Services/OrderService.php +++ b/app/Services/OrderService.php @@ -819,14 +819,19 @@ class OrderService * 确认订单 * * @param \App\Models\Order $order + * @param bool $isSettlable * @return void */ - public function confirm(Order $order) + public function confirm(Order $order, $isSettlable = false) { if (! $order->isShipped()) { throw new BizException('订单包裹未发完'); } + if ($isSettlable && $order->afterSales()->processing()->count() > 0) { + throw new BizException('订单商品售后中,不能完成此订单'); + } + $orderPackageService = new OrderPackageService(); $order->loadMissing('packages'); @@ -839,7 +844,11 @@ class OrderService $orderPackageService->checkPackage($package, true); } - $order->markAsCompleted(); + $order->update([ + 'is_settlable' => $isSettlable, + 'status' => Order::STATUS_COMPLETED, + 'completed_at' => now(), + ]); } /** diff --git a/database/migrations/2022_02_14_133323_add_is_settlable_to_orders_table.php b/database/migrations/2022_02_14_133323_add_is_settlable_to_orders_table.php new file mode 100644 index 00000000..124384a6 --- /dev/null +++ b/database/migrations/2022_02_14_133323_add_is_settlable_to_orders_table.php @@ -0,0 +1,32 @@ +boolean('is_settlable')->default(false)->comment('是否完成'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('orders', function (Blueprint $table) { + $table->dropColumn(['is_settlable']); + }); + } +} From 4b73ad7570787d92bcb43629c6e719a3a48d557b Mon Sep 17 00:00:00 2001 From: vine_liutk <961510893@qq.com> Date: Mon, 14 Feb 2022 14:39:32 +0800 Subject: [PATCH 08/30] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=89=B9=E9=9B=B6?= =?UTF-8?q?=E7=AB=AF=E8=B4=AD=E7=89=A9=E8=BD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Dealer/OrderController.php | 48 ++++++++- .../Dealer/ShoppingCartItemController.php | 101 ++++++++++++++++++ app/Endpoint/Api/routes.php | 7 ++ app/Models/DealerShoppingCartItem.php | 25 +++++ app/Models/User.php | 9 ++ app/Services/Dealer/OrderService.php | 74 +++++++++---- ...reate_dealer_shopping_cart_items_table.php | 38 +++++++ 7 files changed, 279 insertions(+), 23 deletions(-) create mode 100644 app/Endpoint/Api/Http/Controllers/Dealer/ShoppingCartItemController.php create mode 100644 app/Models/DealerShoppingCartItem.php create mode 100644 database/migrations/2022_02_14_103211_create_dealer_shopping_cart_items_table.php diff --git a/app/Endpoint/Api/Http/Controllers/Dealer/OrderController.php b/app/Endpoint/Api/Http/Controllers/Dealer/OrderController.php index 600e010b..a23af247 100644 --- a/app/Endpoint/Api/Http/Controllers/Dealer/OrderController.php +++ b/app/Endpoint/Api/Http/Controllers/Dealer/OrderController.php @@ -58,7 +58,53 @@ class OrderController extends Controller $product = DealerProduct::online()->findOrFail($input['product_id']); try { DB::beginTransaction(); - $order = $orderService->createOrder($request->user(), $product, $input['num'], $input['shipping_address_id']); + $order = $orderService->quickCreateOrder($request->user(), $product, $input['num'], $input['shipping_address_id']); + DB::commit(); + } catch (BizException $e) { + DB::rollBack(); + throw $e; + } catch (Throwable $th) { + DB::rollBack(); + report($th); + throw new BizException('下单失败,请稍后再试'); + } + + return OrderResource::make($order); + } + + /** + * 新下单接口 + */ + public function newStore(Request $request, OrderService $orderService) + { + $isQuick = $request->filled('product'); + + $rules = $isQuick ? [ + 'product.id' => ['bail', 'required', 'int'], + 'product.quantity' => ['bail', 'required', 'int', 'min:1'], + 'shipping_address_id' => ['bail', 'required', 'int'], + ] : [ + 'shopping_cart' => ['bail', 'required', 'array'], + 'shipping_address_id' => ['bail', 'required', 'int'], + ]; + + $input = $request->validate($rules, [], [ + 'product.id' => '商品', + 'product.quantity' => '数量', + 'shopping_cart' => '购物车商品', + 'shipping_address_id' => '收货地址', + ]); + + try { + DB::beginTransaction(); + + if ($isQuick) { + $product = DealerProduct::online()->findOrFail($input['product']['id']); + $order = $orderService->quickCreateOrder($request->user(), $product, $input['product']['quantity'], $input['shipping_address_id']); + } else { + $order = $orderService->cartCreateOrder($request->user(), $input['shopping_cart'], $input['shipping_address_id']); + } + DB::commit(); } catch (BizException $e) { DB::rollBack(); diff --git a/app/Endpoint/Api/Http/Controllers/Dealer/ShoppingCartItemController.php b/app/Endpoint/Api/Http/Controllers/Dealer/ShoppingCartItemController.php new file mode 100644 index 00000000..085001f3 --- /dev/null +++ b/app/Endpoint/Api/Http/Controllers/Dealer/ShoppingCartItemController.php @@ -0,0 +1,101 @@ +user(); + $items = $user->dealerShoppingCartItems()->latest('id')->get(); + $items->load('product'); + $totalQty = $items->sum('quantity'); + $data = []; + foreach ($items as $item) { + $data[] = [ + 'id'=>$item->id, + 'name' =>$item->name, + 'cover'=>$item->cover, + 'sell_price'=>$item->sell_price, + 'dealer_price' =>$orderService->getSalePrice($user, $item->product, $totalQty), + 'quantity'=>$item->quantity, + ]; + } + + return response()->json(['data'=>$data]); + } + + /** + * 加入购物车 + */ + public function store(Request $request) + { + $input = $request->validate([ + 'product_id' => ['bail', 'required', 'int'], + 'quantity' => ['bail', 'required', 'int', 'min:1'], + ]); + + $product = DealerProduct::online()->findOrFail($input['product_id']); + + $shoppingCartItem = $request->user()->dealerShoppingCartItems()->firstOrCreate([ + 'product_id' => $product->id, + ], [ + 'name' => $product->name, + 'cover' => $product->cover, + 'sell_price' => $product->price, + 'quantity' => $input['quantity'], + ]); + if (!$shoppingCartItem->wasRecentlyCreated) { + $shoppingCartItem->increment('quantity', $input['quantity']); + } + + return response()->noContent(); + } + + /** + * 购物车变动 + */ + public function update($id, Request $request) + { + $input = $request->validate([ + 'quantity' => ['bail', 'required', 'int', 'min:1'], + ]); + + $shoppingCartItem = $request->user()->dealerShoppingCartItems()->findOrFail($id); + + $product = DealerProduct::online()->findOrFail($shoppingCartItem->product_id); + + $shoppingCartItem->update(array_merge($input, [ + 'name' => $product->name, + 'cover' => $product->cover, + 'sell_price' => $product->price, + ])); + + return response()->noContent(); + } + + /** + * 移出购物车 + */ + public function delete(Request $request) + { + $input = $request->validate([ + 'ids' => ['bail', 'required', 'array'], + ]); + + $request->user()->dealerShoppingCartItems()->whereIn('id', $input['ids'])->delete(); + + return response()->noContent(); + } +} diff --git a/app/Endpoint/Api/routes.php b/app/Endpoint/Api/routes.php index 47ea910d..4370afd0 100644 --- a/app/Endpoint/Api/routes.php +++ b/app/Endpoint/Api/routes.php @@ -238,12 +238,19 @@ Route::group([ Route::post('user-products/offline-out', [Dealer\UserProductController::class, 'offlineOutQty']); Route::post('user-products/offline-out-revoke/{log}', [Dealer\UserProductController::class, 'revokeQtyLog']); + //购物车 + Route::apiResource('shopping-cart-items', Dealer\ShoppingCartItemController::class)->only( + ['index', 'store', 'update'] + ); + Route::delete('shopping-cart-items', [Dealer\ShoppingCartItemController::class, 'delete']); + //计算商品下单价格 Route::get('orders/total-amount', [Dealer\OrderController::class, 'totalAmount']); //订单列表 Route::get('orders', [Dealer\OrderController::class, 'index']); //下单 Route::post('orders', [Dealer\OrderController::class, 'store']); + Route::post('orders-new', [Dealer\OrderController::class, 'newStore']); //订单详情 Route::get('orders/{order}', [Dealer\OrderController::class, 'show']); diff --git a/app/Models/DealerShoppingCartItem.php b/app/Models/DealerShoppingCartItem.php new file mode 100644 index 00000000..49c2d434 --- /dev/null +++ b/app/Models/DealerShoppingCartItem.php @@ -0,0 +1,25 @@ +belongsTo(DealerProduct::class, 'product_id'); + } +} diff --git a/app/Models/User.php b/app/Models/User.php index a1f2734d..0a0b16dd 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -104,6 +104,15 @@ class User extends Model implements AuthorizableContract, AuthenticatableContrac return $this->hasMany(ShoppingCartItem::class); } + /** + * 属于此用户的批零购物车商品 + * + */ + public function dealerShoppingCartItems() + { + return $this->hasMany(DealerShoppingCartItem::class); + } + /** * 属于此用户的收货地址 */ diff --git a/app/Services/Dealer/OrderService.php b/app/Services/Dealer/OrderService.php index 32a8529e..3370bf71 100644 --- a/app/Services/Dealer/OrderService.php +++ b/app/Services/Dealer/OrderService.php @@ -18,13 +18,13 @@ use Illuminate\Database\QueryException; class OrderService { /** - * 计算订单价格 + * 获取单个商品实际价格 * + * @param User $user * @param DealerProduct $product * @param integer $number - * @return string */ - public function totalAmount(User $user, DealerProduct $product, int $number = 0) + public function getSalePrice(User $user, DealerProduct $product, int $number = 0) { //获取等级规则,判断当前用户等级是否配置等级价格 $salePrice = $product->price; @@ -45,9 +45,19 @@ class OrderService break; } } - // dd($salePrice, $number); + return $salePrice; + } - return bcmul($salePrice, $number, 2); + /** + * 计算订单价格 + * + * @param DealerProduct $product + * @param integer $number + * @return string + */ + public function totalAmount(User $user, DealerProduct $product, int $number = 0) + { + return bcmul($this->getSalePrice($user, $product, $number), $number, 2); } /** @@ -59,7 +69,7 @@ class OrderService * @param integer $shippingAddressId * @return DealerOrder $order */ - public function createOrder(User $user, DealerProduct $product, int $number = 0, int $shippingAddressId) + public function quickCreateOrder(User $user, DealerProduct $product, int $number = 0, int $shippingAddressId) { //判断是否满足当前等级最低补货价 $totalAmount = $this->totalAmount($user, $product, $number); @@ -69,6 +79,42 @@ class OrderService } } + $order = $this->createOrder($user, $totalAmount, $shippingAddressId); + + //保存订单商品-----一个订单对应一个商品 + $order->products()->create([ + 'order_id' => $order->id, + 'product_id'=> $product->id, + 'name'=> $product->name, + 'subtitle'=> $product->subtitle, + 'cover'=> $product->cover, + 'price' => $product->price, + 'sale_price'=> bcdiv($totalAmount, $number, 2), + 'qty'=> $number, + ]); + + if (!$order->consignor) {//如果订单分配给公司,则直接确认 + $this->confirmOrder($order); + } + + return $order; + } + + public function cartCreateOrder(User $user, $cartIds, int $shippingAddressId) + { + return null; // + } + + /** + * 创建订单 + * + * @param User $user + * @param [type] $totalAmount + * @param integer $shippingAddressId + * @return DealerOrder $order + */ + protected function createOrder(User $user, $totalAmount, int $shippingAddressId) + { //找到发货人 $consignor = $this->getConsignor($user, $totalAmount); @@ -97,22 +143,6 @@ class OrderService } } while (true); - //保存订单商品-----一个订单对应一个商品 - $order->products()->create([ - 'order_id' => $order->id, - 'product_id'=> $product->id, - 'name'=> $product->name, - 'subtitle'=> $product->subtitle, - 'cover'=> $product->cover, - 'price' => $product->price, - 'sale_price'=> bcdiv($totalAmount, $number, 2), - 'qty'=> $number, - ]); - - if (!$order->consignor) {//如果订单分配给公司,则直接确认 - $this->confirmOrder($order); - } - return $order; } diff --git a/database/migrations/2022_02_14_103211_create_dealer_shopping_cart_items_table.php b/database/migrations/2022_02_14_103211_create_dealer_shopping_cart_items_table.php new file mode 100644 index 00000000..fb0c00be --- /dev/null +++ b/database/migrations/2022_02_14_103211_create_dealer_shopping_cart_items_table.php @@ -0,0 +1,38 @@ +id(); + $table->unsignedBigInteger('user_id')->comment('用户ID'); + $table->unsignedBigInteger('product_id')->comment('商品ID'); + $table->string('name')->comment('商品名称'); + $table->string('cover')->nullable()->comment('封面图'); + $table->unsignedDecimal('sell_price', 10, 2)->default(0.00)->comment('销售价格:元'); + $table->unsignedDecimal('dealer_price', 10, 2)->default(0.00)->comment('经销商价格:元'); + $table->unsignedInteger('quantity')->default(0)->comment('购买数量'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('dealer_shopping_cart_items'); + } +} From 830b8131d978436ba285800385817e41dd684082 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Mon, 14 Feb 2022 14:45:32 +0800 Subject: [PATCH 09/30] =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E5=AE=89=E5=85=A8?= =?UTF-8?q?=E5=AF=86=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Account/WalletPasswordController.php | 36 +++++++++++++++++++ .../Http/Controllers/SmsCodeController.php | 33 ++++++++++++----- .../Api/Http/Requests/StoreSmsCodeRequest.php | 32 ----------------- app/Endpoint/Api/routes.php | 1 + app/Models/SmsCode.php | 2 ++ app/Services/SmsCodeService.php | 22 +++++++++--- 6 files changed, 82 insertions(+), 44 deletions(-) delete mode 100644 app/Endpoint/Api/Http/Requests/StoreSmsCodeRequest.php diff --git a/app/Endpoint/Api/Http/Controllers/Account/WalletPasswordController.php b/app/Endpoint/Api/Http/Controllers/Account/WalletPasswordController.php index 3678fd92..ac376310 100644 --- a/app/Endpoint/Api/Http/Controllers/Account/WalletPasswordController.php +++ b/app/Endpoint/Api/Http/Controllers/Account/WalletPasswordController.php @@ -4,12 +4,48 @@ namespace App\Endpoint\Api\Http\Controllers\Account; use App\Endpoint\Api\Http\Controllers\Controller; use App\Exceptions\BizException; +use App\Models\SmsCode; use App\Models\Wallet; +use App\Services\SmsCodeService; use Illuminate\Http\Request; use Illuminate\Support\Arr; class WalletPasswordController extends Controller { + /** + * 设置钱包密码 + * + * @param Request $request + * @param SmsCodeService $smsCodeService + * @return void + */ + public function update(Request $request, SmsCodeService $smsCodeService) + { + $input = $request->validate([ + 'verify_code' => ['bail', 'required'], + 'new_password' => ['bail', 'required', 'size:6'], + ], [ + 'verify_code' => '验证码', + 'new_password' => '新密码', + ]); + + $user = $request->user(); + + $smsCodeService->validate( + $user->phone, + SmsCode::TYPE_SET_WALLET_PASSWORD, + $input['verify_code'] + ); + + Wallet::updateOrCreate([ + 'user_id'=> $user->id, + ], [ + 'password' => $input['new_password'], + ]); + + return response()->noContent(); + } + /** * 设置安全密码 * diff --git a/app/Endpoint/Api/Http/Controllers/SmsCodeController.php b/app/Endpoint/Api/Http/Controllers/SmsCodeController.php index 0cd8fa6d..aa6a1e61 100644 --- a/app/Endpoint/Api/Http/Controllers/SmsCodeController.php +++ b/app/Endpoint/Api/Http/Controllers/SmsCodeController.php @@ -2,9 +2,12 @@ namespace App\Endpoint\Api\Http\Controllers; -use App\Endpoint\Api\Http\Requests\StoreSmsCodeRequest; use App\Exceptions\BizException; +use App\Models\SmsCode; +use App\Rules\PhoneNumber; use App\Services\SmsCodeService; +use Illuminate\Auth\AuthenticationException; +use Illuminate\Http\Request; use Throwable; class SmsCodeController extends Controller @@ -12,22 +15,36 @@ class SmsCodeController extends Controller /** * 发送短信验证码 * - * @param \App\Endpoint\Api\Http\Requests\StoreSmsCodeRequest $request + * @param \Illuminate\Http\Request $request * @param \App\Services\SmsCodeService $smsCodeService * @return \Illuminate\Http\Response * * @throws \App\Exceptions\BizException */ public function store( - StoreSmsCodeRequest $request, + Request $request, SmsCodeService $smsCodeService, ) { + $type = (int) $request->input('type'); + + if (in_array($type, [SmsCode::TYPE_SET_WALLET_PASSWORD])) { + if (is_null($user = $request->user())) { + throw new AuthenticationException('请先登录', ['api']); + } + + $phone = $user->phone; + } else { + $request->validate([ + 'phone' => ['bail', 'required', new PhoneNumber()], + ]); + + $phone = $request->input('phone'); + } + + $code = app()->isProduction() ? mt_rand(100000, 999999) : '666666'; + try { - $smsCodeService->send( - $request->input('phone'), - $request->input('type'), - app()->isProduction() ? mt_rand(100000, 999999) : '666666', - ); + $smsCodeService->send($phone, $type, $code); } catch (BizException $e) { throw $e; } catch (Throwable $e) { diff --git a/app/Endpoint/Api/Http/Requests/StoreSmsCodeRequest.php b/app/Endpoint/Api/Http/Requests/StoreSmsCodeRequest.php deleted file mode 100644 index 1ee9150d..00000000 --- a/app/Endpoint/Api/Http/Requests/StoreSmsCodeRequest.php +++ /dev/null @@ -1,32 +0,0 @@ - ['bail', 'required', new PhoneNumber()], - 'type' => ['bail', 'required', 'int'], - ]; - } -} diff --git a/app/Endpoint/Api/routes.php b/app/Endpoint/Api/routes.php index 4370afd0..66151284 100644 --- a/app/Endpoint/Api/routes.php +++ b/app/Endpoint/Api/routes.php @@ -92,6 +92,7 @@ Route::group([ // 修改密码 Route::post('change-password', ChangePasswordController::class); //安全密码 + Route::put('wallet-password', [WalletPasswordController::class, 'update']); Route::post('wallet-password/reset', [WalletPasswordController::class, 'reset']);//重置或设置安全密码 //我的账户 diff --git a/app/Models/SmsCode.php b/app/Models/SmsCode.php index cf4022cc..73d030ba 100644 --- a/app/Models/SmsCode.php +++ b/app/Models/SmsCode.php @@ -14,6 +14,7 @@ class SmsCode extends Model public const TYPE_REGISTER = 1; public const TYPE_RESET_PASSWORD = 2; + public const TYPE_SET_WALLET_PASSWORD = 3; /** * @var array @@ -51,6 +52,7 @@ class SmsCode extends Model public static $allowedTypes = [ self::TYPE_REGISTER, self::TYPE_RESET_PASSWORD, + self::TYPE_SET_WALLET_PASSWORD, ]; /** diff --git a/app/Services/SmsCodeService.php b/app/Services/SmsCodeService.php index 1fa53d02..3cae4762 100644 --- a/app/Services/SmsCodeService.php +++ b/app/Services/SmsCodeService.php @@ -43,10 +43,23 @@ class SmsCodeService throw new BizException(__('Invalid verification code type')); } - if ($type === SmsCode::TYPE_REGISTER) { - if (User::where('phone', $phone)->exists()) { - throw new BizException(__('The phone number is already registered')); - } + $user = User::where('phone', $phone)->first(); + + switch ($type) { + case SmsCode::TYPE_REGISTER: + if ($user) { + throw new BizException(__('The phone number is already registered')); + } + + break; + + case SmsCode::TYPE_RESET_PASSWORD: + case SmsCode::TYPE_SET_WALLET_PASSWORD: + if ($user === null) { + throw new BizException('手机号未注册'); + } + + break; } if (! $this->cache->add("sms_lock_{$type}_{$phone}", 1, $decaySeconds)) { @@ -58,6 +71,7 @@ class SmsCodeService 'code' => $code, 'type' => $type, 'expires_at' => now()->addSeconds($this->expires), + 'user_id' => $user->id, ]); } From 2f541dccbad2a61aa94bc1515f378a65e2698ccb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Mon, 14 Feb 2022 14:54:00 +0800 Subject: [PATCH 10/30] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=AE=89=E5=85=A8?= =?UTF-8?q?=E5=AF=86=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Account/WalletPasswordController.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/app/Endpoint/Api/Http/Controllers/Account/WalletPasswordController.php b/app/Endpoint/Api/Http/Controllers/Account/WalletPasswordController.php index ac376310..228b946a 100644 --- a/app/Endpoint/Api/Http/Controllers/Account/WalletPasswordController.php +++ b/app/Endpoint/Api/Http/Controllers/Account/WalletPasswordController.php @@ -23,24 +23,26 @@ class WalletPasswordController extends Controller { $input = $request->validate([ 'verify_code' => ['bail', 'required'], - 'new_password' => ['bail', 'required', 'size:6'], + 'password' => ['bail', 'required', 'regex:/^\d{6}$/i'], + ], [ + 'password.regex' => '安全密码 是6位数字', ], [ 'verify_code' => '验证码', - 'new_password' => '新密码', + 'password' => '安全密码', ]); $user = $request->user(); - $smsCodeService->validate( - $user->phone, - SmsCode::TYPE_SET_WALLET_PASSWORD, - $input['verify_code'] - ); + // $smsCodeService->validate( + // $user->phone, + // SmsCode::TYPE_SET_WALLET_PASSWORD, + // $input['verify_code'] + // ); Wallet::updateOrCreate([ 'user_id'=> $user->id, ], [ - 'password' => $input['new_password'], + 'password' => $input['password'], ]); return response()->noContent(); From 6b19b81c908ec8b195bd5bccb1481233acfd4f92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Mon, 14 Feb 2022 15:04:21 +0800 Subject: [PATCH 11/30] Update --- .../Controllers/Account/WalletPasswordController.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/Endpoint/Api/Http/Controllers/Account/WalletPasswordController.php b/app/Endpoint/Api/Http/Controllers/Account/WalletPasswordController.php index 228b946a..e03a450f 100644 --- a/app/Endpoint/Api/Http/Controllers/Account/WalletPasswordController.php +++ b/app/Endpoint/Api/Http/Controllers/Account/WalletPasswordController.php @@ -33,11 +33,11 @@ class WalletPasswordController extends Controller $user = $request->user(); - // $smsCodeService->validate( - // $user->phone, - // SmsCode::TYPE_SET_WALLET_PASSWORD, - // $input['verify_code'] - // ); + $smsCodeService->validate( + $user->phone, + SmsCode::TYPE_SET_WALLET_PASSWORD, + $input['verify_code'] + ); Wallet::updateOrCreate([ 'user_id'=> $user->id, From 24439c851b3345da5abb7e05c3f8e9f87c16c50e Mon Sep 17 00:00:00 2001 From: vine_liutk <961510893@qq.com> Date: Mon, 14 Feb 2022 15:54:32 +0800 Subject: [PATCH 12/30] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=B4=AD=E7=89=A9?= =?UTF-8?q?=E8=BD=A6=E4=B8=8B=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Admin/Forms/DealerProductLvlRule.php | 4 +- app/Admin/Forms/Settings/Dealer.php | 12 ++- .../Dealer/ProductLvlRuleResource.php | 2 +- app/Services/Dealer/OrderService.php | 75 ++++++++++++++++--- database/seeders/AppSettingSeeder.php | 12 +++ 5 files changed, 89 insertions(+), 16 deletions(-) diff --git a/app/Admin/Forms/DealerProductLvlRule.php b/app/Admin/Forms/DealerProductLvlRule.php index 80b9add0..f209ef19 100644 --- a/app/Admin/Forms/DealerProductLvlRule.php +++ b/app/Admin/Forms/DealerProductLvlRule.php @@ -51,7 +51,7 @@ class DealerProductLvlRule extends Form implements LazyRenderable $_rule = DealerProductLvlRuleModel::find($rule['id']); $_rule['lvl'] = $rule['lvl']; $_rule['sale_price'] = $rule['sale_price']; - $_rule['min_order_amount'] = $rule['min_order_amount']; + // $_rule['min_order_amount'] = $rule['min_order_amount']; $lvlRules[] = $_rule; } } @@ -88,7 +88,7 @@ class DealerProductLvlRule extends Form implements LazyRenderable 6 => '一级经销商', ]); $form->currency('sale_price', '等级进货单价')->symbol('¥'); - $form->currency('min_order_amount', '等级单次最低进货价')->symbol('¥'); + // $form->currency('min_order_amount', '等级单次最低进货价')->symbol('¥'); }); } diff --git a/app/Admin/Forms/Settings/Dealer.php b/app/Admin/Forms/Settings/Dealer.php index 29767556..be8d3b73 100644 --- a/app/Admin/Forms/Settings/Dealer.php +++ b/app/Admin/Forms/Settings/Dealer.php @@ -43,9 +43,15 @@ class Dealer extends Form $this->currency('withdraw_fee_rate', '提现费率')->symbol('%'); $this->number('withdraw_days', '提现间隔'); - $this->currency('upgrade_amount_'.DealerLvl::Contracted->value, '签约门槛')->symbol('¥'); - $this->currency('upgrade_amount_'.DealerLvl::Special->value, '特邀门槛')->symbol('¥'); - $this->currency('upgrade_amount_'.DealerLvl::Gold->value, '金牌门槛')->symbol('¥'); + $this->currency('upgrade_amount_'.DealerLvl::Gold->value, '金牌升级门槛')->symbol('¥'); + $this->currency('upgrade_amount_'.DealerLvl::Special->value, '特邀升级门槛')->symbol('¥'); + $this->currency('upgrade_amount_'.DealerLvl::Contracted->value, '签约升级门槛')->symbol('¥'); + + $this->currency('min_order_amount_'.DealerLvl::Gold->value, '金牌单次进货最低金额')->symbol('¥'); + $this->currency('min_order_amount_'.DealerLvl::Special->value, '特邀单次进货最低金额')->symbol('¥'); + $this->currency('min_order_amount_'.DealerLvl::Contracted->value, '签约单次进货最低金额')->symbol('¥'); + $this->currency('min_order_amount_'.DealerLvl::Secondary->value, '二级签约单次进货最低金额')->symbol('¥'); + $this->currency('min_order_amount_'.DealerLvl::Top->value, '一级签约单次进货最低金额')->symbol('¥'); $this->number('order_auto_allocate_times', '订单自动分配时间(分)')->min(1); diff --git a/app/Endpoint/Api/Http/Resources/Dealer/ProductLvlRuleResource.php b/app/Endpoint/Api/Http/Resources/Dealer/ProductLvlRuleResource.php index 9a0be60e..1130756a 100644 --- a/app/Endpoint/Api/Http/Resources/Dealer/ProductLvlRuleResource.php +++ b/app/Endpoint/Api/Http/Resources/Dealer/ProductLvlRuleResource.php @@ -17,7 +17,7 @@ class ProductLvlRuleResource extends JsonResource return [ 'lvl' => $this->lvl, 'sale_price' => $this->sale_price, - 'min_order_amount' => $this->min_order_amount, + 'min_order_amount' => app_settings('dealer.min_order_amount_'.$this->lvl, 0), ]; } } diff --git a/app/Services/Dealer/OrderService.php b/app/Services/Dealer/OrderService.php index 3370bf71..02875609 100644 --- a/app/Services/Dealer/OrderService.php +++ b/app/Services/Dealer/OrderService.php @@ -8,6 +8,7 @@ use App\Enums\DealerWalletAction; use App\Exceptions\BizException; use App\Models\DealerOrder; use App\Models\DealerOrderAllocateLog; +use App\Models\DealerOrderProduct; use App\Models\DealerProduct; use App\Models\DealerUserProductLog; use App\Models\ShippingAddress; @@ -55,13 +56,13 @@ class OrderService * @param integer $number * @return string */ - public function totalAmount(User $user, DealerProduct $product, int $number = 0) + public function totalAmount(User $user, DealerProduct $product, int $number = 0, ?int $allNumber = 0) { - return bcmul($this->getSalePrice($user, $product, $number), $number, 2); + return bcmul($this->getSalePrice($user, $product, $allNumber ?? $number), $number, 2); } /** - * 创建订单 + * 快捷创建订单(单个商品下单) * * @param User $user * @param DealerProduct $product @@ -71,13 +72,13 @@ class OrderService */ public function quickCreateOrder(User $user, DealerProduct $product, int $number = 0, int $shippingAddressId) { - //判断是否满足当前等级最低补货价 $totalAmount = $this->totalAmount($user, $product, $number); - foreach ($product->lvlRules as $rule) { - if ($user->dealer && $rule->lvl == $user->dealer->lvl->value && $totalAmount < $rule->min_order_amount) { - throw new BizException('当前单次补货价格不能低于'.$rule->min_order_amount.'元'); - } - } + // foreach ($product->lvlRules as $rule) { + // $min_order_amount = app_settings('min_order_amount'.$rule->lvl); + // if ($user->dealer && $rule->lvl == $user->dealer->lvl->value && $totalAmount < $min_order_amount) { + // throw new BizException('当前单次补货价格不能低于'.$min_order_amount.'元'); + // } + // } $order = $this->createOrder($user, $totalAmount, $shippingAddressId); @@ -100,9 +101,58 @@ class OrderService return $order; } + /** + * 购物车创建订单 + * + * @param User $user + * @param [type] $cartIds + * @param integer $shippingAddressId + * @return DealerOrder $order + */ public function cartCreateOrder(User $user, $cartIds, int $shippingAddressId) { - return null; // + //获取购物车商品 + $shoppingCartItems = $user->dealerShoppingCartItems()->findMany($cartIds); + if ($shoppingCartItems->count() !== count($cartIds)) { + throw new BizException('购物车商品已丢失'); + } + $shoppingCartItems->load('product'); + $totalQty = $shoppingCartItems->sum('quantity'); + $totalAmount = 0; + $orderProducts = []; + foreach ($shoppingCartItems as $item) { + if (!$item->product->isOnline()) { + throw new BizException('购物车商品已失效'); + } + //计算订单价格 + $totalAmount += $this->totalAmount($user, $item->product, $item->quantity, $totalQty); + //组装订单商品 + $orderProducts[] = [ + 'product_id' => $item->product_id, + 'name'=> $item->name, + 'subtitle' => $item->product->subtitle, + 'cover' => $item->cover, + 'price' => $item->sell_price, + 'sale_price' => $this->getSalePrice($user, $item->product, $totalQty), + 'qty' => $item->quantity, + ]; + } + + $order = $this->createOrder($user, $totalAmount, $shippingAddressId); + + DealerOrderProduct::insert(array_map(function ($product) use ($order) { + return array_merge($product, [ + 'order_id'=>$order->id, + 'created_at'=> $order->created_at, + 'updated_at'=> $order->updated_at, + ]); + }, $orderProducts)); + + if (!$order->consignor) {//如果订单分配给公司,则直接确认 + $this->confirmOrder($order); + } + + return $order; } /** @@ -115,6 +165,11 @@ class OrderService */ protected function createOrder(User $user, $totalAmount, int $shippingAddressId) { + //判断是否满足当前等级最低补货价 + $min_order_amount = app_settings('dealer.min_order_amount_'.$user->dealer?->lvl->value, 0); + if ($user->dealer && $totalAmount < $min_order_amount) { + throw new BizException('当前单次补货价格不能低于'.$min_order_amount.'元'); + } //找到发货人 $consignor = $this->getConsignor($user, $totalAmount); diff --git a/database/seeders/AppSettingSeeder.php b/database/seeders/AppSettingSeeder.php index 4f05c72a..23c85db7 100644 --- a/database/seeders/AppSettingSeeder.php +++ b/database/seeders/AppSettingSeeder.php @@ -190,6 +190,18 @@ class AppSettingSeeder extends Seeder // 合约经销商升级金额 'upgrade_amount_'.DealerLvl::Contracted->value => '26400', + //单次下单最低金额 + // 金牌经销商 + 'min_order_amount_'.DealerLvl::Gold->value => '1260', + // 特邀经销商 + 'min_order_amount_'.DealerLvl::Special->value => '1720', + // 签约约经销商 + 'min_order_amount_'.DealerLvl::Contracted->value => '2640', + // 二级签约约经销商 + 'min_order_amount_'.DealerLvl::Secondary->value => '2640', + // 一级签约约经销商 + 'min_order_amount_'.DealerLvl::Top->value => '2640', + // 渠道补贴规则 'channel_rules' => [ // 签约 -> 签约 ->签约 From 050927ffbc3eb0a7b6be8d7885d57099086923db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Mon, 14 Feb 2022 15:57:59 +0800 Subject: [PATCH 13/30] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E6=B4=A5=E8=B4=B4=E5=88=86=E9=85=8D=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Commands/Dealer/OrderProcessCommand.php | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/app/Console/Commands/Dealer/OrderProcessCommand.php b/app/Console/Commands/Dealer/OrderProcessCommand.php index 59411146..94c606e2 100644 --- a/app/Console/Commands/Dealer/OrderProcessCommand.php +++ b/app/Console/Commands/Dealer/OrderProcessCommand.php @@ -393,6 +393,10 @@ class OrderProcessCommand extends Command $ranking = 0; foreach ($dealers as $dealer) { + if (! in_array($dealer->lvl, [DealerLvl::Secondary, DealerLvl::Top])) { + continue; + } + // 如果当前经销商等级没有对应的管理津贴分配规则,则忽略 if (is_null($rule = $rules->get($dealer->lvl->value))) { continue; @@ -400,6 +404,27 @@ class OrderProcessCommand extends Command // 同等级管理津贴最多给三次 if ($last === null || $dealer->lvl->value > $last->lvl->value) { + if ($ranking < 3 && $dealer->lvl === DealerLvl::Top) { + if ($secondarySubsidyRule = $rules->get(DealerLvl::Secondary)) { + $key = 'price_'.(1 + $ranking).'st'; + + $secondarySubsidy = $secondarySubsidyRule->{$key}; + + if (bccomp($secondarySubsidy, '0') === 1) { + $logs[] = [ + 'user_id' => $dealer->user_id, + 'order_id' => $product->order_id, + 'product_id' => $product->product_id, + 'lvl' => $dealer->lvl, + 'sales_volume' => $product->qty, + 'total_amount' => bcmul($product->qty, $secondarySubsidy, 2), + 'created_at' => $tz, + 'updated_at' => $tz, + ]; + } + } + } + $ranking = 1; } elseif ($ranking < 3 && $dealer->lvl->value === $last->lvl->value) { $ranking++; From 745b6448e57eb9ff9dbf6bd7df1afa2974a17d82 Mon Sep 17 00:00:00 2001 From: vine_liutk <961510893@qq.com> Date: Mon, 14 Feb 2022 15:59:57 +0800 Subject: [PATCH 14/30] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=90=8E=E5=8F=B0?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E9=85=8D=E7=BD=AE=E5=8D=95=E6=AC=A1=E8=BF=9B?= =?UTF-8?q?=E8=B4=A7=E6=9C=80=E4=BD=8E=E4=BB=B7=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Admin/Forms/Settings/Dealer.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/Admin/Forms/Settings/Dealer.php b/app/Admin/Forms/Settings/Dealer.php index be8d3b73..376be254 100644 --- a/app/Admin/Forms/Settings/Dealer.php +++ b/app/Admin/Forms/Settings/Dealer.php @@ -145,6 +145,13 @@ class Dealer extends Form 'upgrade_amount_'.DealerLvl::Contracted->value => $dealerSettings['upgrade_amount_'.DealerLvl::Contracted->value] ?? '', 'upgrade_amount_'.DealerLvl::Special->value => $dealerSettings['upgrade_amount_'.DealerLvl::Special->value] ?? '', 'upgrade_amount_'.DealerLvl::Gold->value => $dealerSettings['upgrade_amount_'.DealerLvl::Gold->value] ?? '', + + 'min_order_amount_'.DealerLvl::Gold->value => $dealerSettings['min_order_amount_'.DealerLvl::Gold->value] ?? '', + 'min_order_amount_'.DealerLvl::Special->value => $dealerSettings['min_order_amount_'.DealerLvl::Special->value] ?? '', + 'min_order_amount_'.DealerLvl::Contracted->value => $dealerSettings['min_order_amount_'.DealerLvl::Contracted->value] ?? '', + 'min_order_amount_'.DealerLvl::Secondary->value => $dealerSettings['min_order_amount_'.DealerLvl::Secondary->value] ?? '', + 'min_order_amount_'.DealerLvl::Top->value => $dealerSettings['min_order_amount_'.DealerLvl::Top->value] ?? '', + 'bank'=>$dealerSettings['bank'] ?? [], 'alipay'=>$dealerSettings['alipay'] ?? [], 'wechat' =>$dealerSettings['wechat'] ?? [], From 123e989907027b17d589dc46572d157e3d177b59 Mon Sep 17 00:00:00 2001 From: vine_liutk <961510893@qq.com> Date: Mon, 14 Feb 2022 16:31:08 +0800 Subject: [PATCH 15/30] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=89=B9=E9=9B=B6?= =?UTF-8?q?=E8=B4=AD=E7=89=A9=E8=BD=A6=E4=B8=8B=E5=8D=95=E6=B8=85=E9=99=A4?= =?UTF-8?q?=E5=AF=B9=E5=BA=94=E5=95=86=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Dealer/OrderController.php | 31 +++++++++++++++++++ app/Endpoint/Api/routes.php | 1 + app/Services/Dealer/OrderService.php | 3 ++ 3 files changed, 35 insertions(+) diff --git a/app/Endpoint/Api/Http/Controllers/Dealer/OrderController.php b/app/Endpoint/Api/Http/Controllers/Dealer/OrderController.php index a23af247..86bffd74 100644 --- a/app/Endpoint/Api/Http/Controllers/Dealer/OrderController.php +++ b/app/Endpoint/Api/Http/Controllers/Dealer/OrderController.php @@ -72,6 +72,37 @@ class OrderController extends Controller return OrderResource::make($order); } + /** + * 确认订单 + * + * @param Request $request + * @param OrderService $orderService + */ + public function checkOrder(Request $request, OrderService $orderService) + { + $input = $request->validate([ + 'shopping_cart' => ['bail', 'required', 'array'], + ], [], [ + 'shopping_cart'=>'购物车商品', + ]); + $user = $request->user(); + $shoppingCartItems = $user->dealerShoppingCartItems()->findMany($input['shopping_cart']); + $shoppingCartItems->load('product'); + $totalQty = $shoppingCartItems->sum('quantity'); + $data = []; + foreach ($shoppingCartItems as $item) { + $data[] = [ + 'id' => $item->id, + 'name' => $item->name, + 'cover' => $item->cover, + 'sell_price' => $item->sell_price, + 'dealer_price' => $orderService->getSalePrice($user, $item->product, $totalQty), + 'quantity' => $item->quantity, + ]; + } + return response()->json(['data'=>$data]); + } + /** * 新下单接口 */ diff --git a/app/Endpoint/Api/routes.php b/app/Endpoint/Api/routes.php index 66151284..ad8c4153 100644 --- a/app/Endpoint/Api/routes.php +++ b/app/Endpoint/Api/routes.php @@ -245,6 +245,7 @@ Route::group([ ); Route::delete('shopping-cart-items', [Dealer\ShoppingCartItemController::class, 'delete']); + Route::get('orders-check', [Dealer\OrderController::class, 'checkOrder']); //计算商品下单价格 Route::get('orders/total-amount', [Dealer\OrderController::class, 'totalAmount']); //订单列表 diff --git a/app/Services/Dealer/OrderService.php b/app/Services/Dealer/OrderService.php index 02875609..e516a8cd 100644 --- a/app/Services/Dealer/OrderService.php +++ b/app/Services/Dealer/OrderService.php @@ -148,6 +148,9 @@ class OrderService ]); }, $orderProducts)); + //清除购物车对应商品 + $user->dealerShoppingCartItems()->whereIn('id', $cartIds)->delete(); + if (!$order->consignor) {//如果订单分配给公司,则直接确认 $this->confirmOrder($order); } From d8c1fe3514951ece344ec1016755b953e1609c02 Mon Sep 17 00:00:00 2001 From: vine_liutk <961510893@qq.com> Date: Mon, 14 Feb 2022 16:43:51 +0800 Subject: [PATCH 16/30] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=89=B9=E9=9B=B6?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E8=AF=A6=E6=83=85=E6=94=AF=E4=BB=98=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Endpoint/Api/Http/Resources/Dealer/OrderResource.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Endpoint/Api/Http/Resources/Dealer/OrderResource.php b/app/Endpoint/Api/Http/Resources/Dealer/OrderResource.php index 1c9265b9..992d508a 100644 --- a/app/Endpoint/Api/Http/Resources/Dealer/OrderResource.php +++ b/app/Endpoint/Api/Http/Resources/Dealer/OrderResource.php @@ -21,6 +21,7 @@ class OrderResource extends JsonResource 'total_amount' => $this->total_amount, 'created_at' => $this->created_at->toDateTimeString(), 'status' => $this->status, + 'pay_way' => $this->pay_way ?? '', 'pay_info' => $this->getConsignorPayInfo(), 'pay_image'=> $this->pay_image, 'is_consignor' => $request->user()->id == $this->consignor_id, //是否发货人身份 From 9ea2f04ac2cbd6eca5eaebe614725243985733ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Tue, 15 Feb 2022 11:19:53 +0800 Subject: [PATCH 17/30] Fix --- app/Console/Commands/Dealer/OrderProcessCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Console/Commands/Dealer/OrderProcessCommand.php b/app/Console/Commands/Dealer/OrderProcessCommand.php index 94c606e2..ff06580a 100644 --- a/app/Console/Commands/Dealer/OrderProcessCommand.php +++ b/app/Console/Commands/Dealer/OrderProcessCommand.php @@ -405,7 +405,7 @@ class OrderProcessCommand extends Command // 同等级管理津贴最多给三次 if ($last === null || $dealer->lvl->value > $last->lvl->value) { if ($ranking < 3 && $dealer->lvl === DealerLvl::Top) { - if ($secondarySubsidyRule = $rules->get(DealerLvl::Secondary)) { + if ($secondarySubsidyRule = $rules->get(DealerLvl::Secondary->value)) { $key = 'price_'.(1 + $ranking).'st'; $secondarySubsidy = $secondarySubsidyRule->{$key}; From 5a269d74e9a47556fbfd54edfc8a38b57cfb2f50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Tue, 15 Feb 2022 11:32:52 +0800 Subject: [PATCH 18/30] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E8=A1=A5=E8=B4=A7?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E8=A1=A5=E5=94=AF=E4=B8=80=E7=B4=A2=E5=BC=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...d_unique_to_dealer_purchase_logs_table.php | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 database/migrations/2022_02_15_113109_del_dealer_user_id_order_id_unique_to_dealer_purchase_logs_table.php diff --git a/database/migrations/2022_02_15_113109_del_dealer_user_id_order_id_unique_to_dealer_purchase_logs_table.php b/database/migrations/2022_02_15_113109_del_dealer_user_id_order_id_unique_to_dealer_purchase_logs_table.php new file mode 100644 index 00000000..08e8f4d3 --- /dev/null +++ b/database/migrations/2022_02_15_113109_del_dealer_user_id_order_id_unique_to_dealer_purchase_logs_table.php @@ -0,0 +1,32 @@ +dropUnique(['user_id', 'order_id']); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('dealer_purchase_logs', function (Blueprint $table) { + $table->unique(['user_id', 'order_id']); + }); + } +} From 85524f5079a7bc4be69b165587ae652a6bd82332 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Tue, 15 Feb 2022 11:38:00 +0800 Subject: [PATCH 19/30] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E6=B4=A5=E8=B4=B4=E5=94=AF=E4=B8=80=E7=B4=A2=E5=BC=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...d_unique_to_dealer_purchase_logs_table.php | 32 ------------------- ...ex_to_dealer_manage_subsidy_logs_table.php | 32 +++++++++++++++++++ 2 files changed, 32 insertions(+), 32 deletions(-) delete mode 100644 database/migrations/2022_02_15_113109_del_dealer_user_id_order_id_unique_to_dealer_purchase_logs_table.php create mode 100644 database/migrations/2022_02_15_113720_del_user_id_order_id_product_id_unique_index_to_dealer_manage_subsidy_logs_table.php diff --git a/database/migrations/2022_02_15_113109_del_dealer_user_id_order_id_unique_to_dealer_purchase_logs_table.php b/database/migrations/2022_02_15_113109_del_dealer_user_id_order_id_unique_to_dealer_purchase_logs_table.php deleted file mode 100644 index 08e8f4d3..00000000 --- a/database/migrations/2022_02_15_113109_del_dealer_user_id_order_id_unique_to_dealer_purchase_logs_table.php +++ /dev/null @@ -1,32 +0,0 @@ -dropUnique(['user_id', 'order_id']); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('dealer_purchase_logs', function (Blueprint $table) { - $table->unique(['user_id', 'order_id']); - }); - } -} diff --git a/database/migrations/2022_02_15_113720_del_user_id_order_id_product_id_unique_index_to_dealer_manage_subsidy_logs_table.php b/database/migrations/2022_02_15_113720_del_user_id_order_id_product_id_unique_index_to_dealer_manage_subsidy_logs_table.php new file mode 100644 index 00000000..fc25f010 --- /dev/null +++ b/database/migrations/2022_02_15_113720_del_user_id_order_id_product_id_unique_index_to_dealer_manage_subsidy_logs_table.php @@ -0,0 +1,32 @@ +dropUnique(['user_id', 'order_id', 'product_id']); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('dealer_manage_subsidy_logs', function (Blueprint $table) { + $table->unique(['user_id', 'order_id', 'product_id']); + }); + } +} From 78333acf970ad7fce94fff9e2a526efb08dd5fe0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Tue, 15 Feb 2022 15:51:48 +0800 Subject: [PATCH 20/30] WIP --- app/Endpoint/Api/Http/Controllers/Dealer/UserController.php | 2 +- app/Endpoint/Api/Http/Resources/Dealer/DealerResource.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Endpoint/Api/Http/Controllers/Dealer/UserController.php b/app/Endpoint/Api/Http/Controllers/Dealer/UserController.php index c0f92605..f7e6eb89 100644 --- a/app/Endpoint/Api/Http/Controllers/Dealer/UserController.php +++ b/app/Endpoint/Api/Http/Controllers/Dealer/UserController.php @@ -24,7 +24,7 @@ class UserController extends Controller $user = $request->user(); $dealer = DealerResource::make($user->dealer)->toArray($request); - $dealer['current_purchase_amount'] = $calculatePurchaseAmountOfCurrentPeriod->handle($user->dealer); + $dealer['current_purchase_amount'] = bcdiv($calculatePurchaseAmountOfCurrentPeriod->handle($user->dealer), '1', 2); return response()->json([ 'phone' => $user->phone, diff --git a/app/Endpoint/Api/Http/Resources/Dealer/DealerResource.php b/app/Endpoint/Api/Http/Resources/Dealer/DealerResource.php index eab3f586..f6c3b74e 100644 --- a/app/Endpoint/Api/Http/Resources/Dealer/DealerResource.php +++ b/app/Endpoint/Api/Http/Resources/Dealer/DealerResource.php @@ -18,11 +18,11 @@ class DealerResource extends JsonResource 'lvl' => $this->lvl, 'lvl_name'=> $this->lvl_text, 'is_sale' => $this->is_sale, - 'guanli_values'=> $this->calculate_total_amount, //预计管理津贴 + 'guanli_values'=> bcdiv($this->calculate_total_amount, '1', 2), //预计管理津贴 'team_sales_value' => $this->team_sales_value, // 团队业绩 'pay_info'=>$this->pay_info ?: null, 'can_withdraw'=> $this->canWithdraw(), - 'total_purchase_amount'=> $this->total_purchase_amount, // 总进货业绩 + 'total_purchase_amount'=> bcdiv($this->total_purchase_amount, '1', 2), // 总进货业绩 ]; } } From 265a1d7d0bf0e5267e9a7292b4dd4da33f58e1a6 Mon Sep 17 00:00:00 2001 From: vine_liutk <961510893@qq.com> Date: Wed, 16 Feb 2022 10:54:44 +0800 Subject: [PATCH 21/30] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=95=86=E5=93=81?= =?UTF-8?q?=E6=95=B0=E4=B8=BA0=E6=97=B6=EF=BC=8C=E5=8E=BB=E5=BA=93?= =?UTF-8?q?=E5=AD=98=E6=8F=90=E7=A4=BA=E7=B3=BB=E7=BB=9F=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Api/Http/Controllers/Dealer/UserProductController.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/Endpoint/Api/Http/Controllers/Dealer/UserProductController.php b/app/Endpoint/Api/Http/Controllers/Dealer/UserProductController.php index d78396e1..702736a9 100644 --- a/app/Endpoint/Api/Http/Controllers/Dealer/UserProductController.php +++ b/app/Endpoint/Api/Http/Controllers/Dealer/UserProductController.php @@ -8,6 +8,7 @@ use App\Endpoint\Api\Http\Resources\Dealer\UserProductResource; use App\Exceptions\BizException; use App\Helpers\Paginator; use App\Models\DealerUserProductLog; +use Illuminate\Database\QueryException; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use Throwable; @@ -76,6 +77,12 @@ class UserProductController extends Controller 'remark'=>$input['remark'] ?? null, ]); DB::commit(); + } catch (QueryException $e) { + DB::rollBack(); + if (strpos($e->getMessage(), 'Numeric value out of range') !== false) { + $e = new BizException('库存不足'); + } + throw $e; } catch (Throwable $th) { DB::rollBack(); report($th); From 1530f779c613cfd59a7a96cba53f37a3c2f360db Mon Sep 17 00:00:00 2001 From: vine_liutk <961510893@qq.com> Date: Wed, 16 Feb 2022 10:56:43 +0800 Subject: [PATCH 22/30] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=B9=BF=E5=91=8A?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- database/seeders/AdAddressSeeder.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/database/seeders/AdAddressSeeder.php b/database/seeders/AdAddressSeeder.php index 6b78053a..9e01f826 100644 --- a/database/seeders/AdAddressSeeder.php +++ b/database/seeders/AdAddressSeeder.php @@ -130,6 +130,11 @@ class AdAddressSeeder extends Seeder 'dimensions'=> '213*246', 'is_show'=> true, ], + 'merchant_top_navigation_banner'=>[ + 'name' =>'商户端首页顶部导航', + 'dimensions'=> '58*58', + 'is_show' =>true, + ], ] as $key => $values) { AdAddress::firstOrCreate(['key' => $key], $values); } From 7defa06bae84d584524f42c5c6fd7dc1fbc17cab Mon Sep 17 00:00:00 2001 From: vine_liutk <961510893@qq.com> Date: Wed, 16 Feb 2022 11:00:19 +0800 Subject: [PATCH 23/30] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=89=B9=E9=9B=B6?= =?UTF-8?q?=E4=BD=99=E9=A2=9D=E6=8F=90=E7=8E=B0=E7=8A=B6=E6=80=81=E7=AD=9B?= =?UTF-8?q?=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DealerWalletToBankLogController.php | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/app/Admin/Controllers/DealerWalletToBankLogController.php b/app/Admin/Controllers/DealerWalletToBankLogController.php index 3910c2ea..60072123 100644 --- a/app/Admin/Controllers/DealerWalletToBankLogController.php +++ b/app/Admin/Controllers/DealerWalletToBankLogController.php @@ -43,7 +43,11 @@ class DealerWalletToBankLogController extends AdminController 0=>'primary', 1=>'success', 2=>'danger', - ]); + ])->filter(Grid\Column\Filter\In::make([ + DealerWalletToBankLogModel::STATUS_PENDING=>'待处理', + DealerWalletToBankLogModel::STATUS_AGREE=>'同意', + DealerWalletToBankLogModel::STATUS_REFUSE=>'拒绝', + ])); $grid->column('remarks'); $grid->column('created_at')->sortable(); // $grid->column('updated_at') @@ -58,11 +62,11 @@ class DealerWalletToBankLogController extends AdminController $grid->filter(function (Grid\Filter $filter) { $filter->panel(); - $filter->equal('status')->select([ - DealerWalletToBankLogModel::STATUS_PENDING=>'待处理', - DealerWalletToBankLogModel::STATUS_AGREE=>'已同意', - DealerWalletToBankLogModel::STATUS_REFUSE=>'已拒绝', - ])->width(3); + // $filter->equal('status')->select([ + // DealerWalletToBankLogModel::STATUS_PENDING=>'待处理', + // DealerWalletToBankLogModel::STATUS_AGREE=>'已同意', + // DealerWalletToBankLogModel::STATUS_REFUSE=>'已拒绝', + // ])->width(3); $filter->equal('user.phone')->width(3); $filter->between('created_at')->dateTime()->width(7); }); @@ -100,45 +104,45 @@ class DealerWalletToBankLogController extends AdminController $show->divider('收款信息-银行'); $show->field('bank_user_name', '银行-收款人')->as(function () { $payInfo = $this->getPayInfo(); - return $payInfo['bank']['user_name']??''; + return $payInfo['bank']['user_name'] ?? ''; }); $show->field('bank_bank_name', '银行-名称')->as(function () { $payInfo = $this->getPayInfo(); - return $payInfo['bank']['bank_name']??''; + return $payInfo['bank']['bank_name'] ?? ''; }); $show->field('bank_bank_number', '银行-卡号')->as(function () { $payInfo = $this->getPayInfo(); - return $payInfo['bank']['bank_number']??''; + return $payInfo['bank']['bank_number'] ?? ''; }); $show->field('bank_bank_description', '银行-开户行')->as(function () { $payInfo = $this->getPayInfo(); - return $payInfo['bank']['bank_description']??''; + return $payInfo['bank']['bank_description'] ?? ''; }); $show->divider('收款信息-支付宝'); $show->field('alipay_user_name', '支付宝-真实名称')->as(function () { $payInfo = $this->getPayInfo(); - return $payInfo['alipay']['user_name']??''; + return $payInfo['alipay']['user_name'] ?? ''; }); $show->field('alipay_ali_name', '支付宝-账户')->as(function () { $payInfo = $this->getPayInfo(); - return $payInfo['alipay']['ali_name']??''; + return $payInfo['alipay']['ali_name'] ?? ''; }); $show->field('alipay_image', '支付宝-收款码')->as(function () { $payInfo = $this->getPayInfo(); - return $payInfo['alipay']['image']??''; + return $payInfo['alipay']['image'] ?? ''; })->image(); $show->divider('收款信息-微信'); $show->field('wechat_user_name', '微信-真实名称')->as(function () { $payInfo = $this->getPayInfo(); - return $payInfo['wechat']['user_name']??''; + return $payInfo['wechat']['user_name'] ?? ''; }); $show->field('wechat_wechat_name', '微信-ID')->as(function () { $payInfo = $this->getPayInfo(); - return $payInfo['wechat']['wechat_name']??''; + return $payInfo['wechat']['wechat_name'] ?? ''; }); $show->field('wechat_image', '微信-收款码')->as(function () { $payInfo = $this->getPayInfo(); - return $payInfo['wechat']['image']??''; + return $payInfo['wechat']['image'] ?? ''; })->image(); $show->field('created_at'); From 0753598747771bc3865277075c6f9e5fac505521 Mon Sep 17 00:00:00 2001 From: vine_liutk <961510893@qq.com> Date: Wed, 16 Feb 2022 11:01:43 +0800 Subject: [PATCH 24/30] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=96=B0=E9=85=8D?= =?UTF-8?q?=E9=A2=9D=E8=B4=A6=E6=88=B7=E6=97=B6=E9=97=B4=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Models/QuotaLog.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/Models/QuotaLog.php b/app/Models/QuotaLog.php index 9fb77e11..0cd751e1 100644 --- a/app/Models/QuotaLog.php +++ b/app/Models/QuotaLog.php @@ -2,10 +2,12 @@ namespace App\Models; +use Dcat\Admin\Traits\HasDateTimeFormatter; use Illuminate\Database\Eloquent\Model; class QuotaLog extends Model { + use HasDateTimeFormatter; /** * @var array */ From fb29ca9389cf160721ef2dca9d3cf1fdfd09c6b5 Mon Sep 17 00:00:00 2001 From: vine_liutk <961510893@qq.com> Date: Wed, 16 Feb 2022 16:24:45 +0800 Subject: [PATCH 25/30] =?UTF-8?q?=E8=B0=83=E6=95=B4=E8=AE=A1=E7=AE=97?= =?UTF-8?q?=E4=BB=B7=E6=A0=BCbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Services/Dealer/OrderService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Services/Dealer/OrderService.php b/app/Services/Dealer/OrderService.php index e516a8cd..8c44bb7d 100644 --- a/app/Services/Dealer/OrderService.php +++ b/app/Services/Dealer/OrderService.php @@ -56,7 +56,7 @@ class OrderService * @param integer $number * @return string */ - public function totalAmount(User $user, DealerProduct $product, int $number = 0, ?int $allNumber = 0) + public function totalAmount(User $user, DealerProduct $product, int $number = 0, ?int $allNumber = null) { return bcmul($this->getSalePrice($user, $product, $allNumber ?? $number), $number, 2); } From 664c28a89cbdd76f8c93df417020a621e6b8c4f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Thu, 17 Feb 2022 10:22:54 +0800 Subject: [PATCH 26/30] WIP --- app/Actions/Dealer/CalculatePurchaseAmountOfCurrentPeriod.php | 2 +- app/Endpoint/Api/Http/Controllers/Dealer/UserController.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Actions/Dealer/CalculatePurchaseAmountOfCurrentPeriod.php b/app/Actions/Dealer/CalculatePurchaseAmountOfCurrentPeriod.php index 7d2cd309..9b132647 100644 --- a/app/Actions/Dealer/CalculatePurchaseAmountOfCurrentPeriod.php +++ b/app/Actions/Dealer/CalculatePurchaseAmountOfCurrentPeriod.php @@ -32,7 +32,7 @@ class CalculatePurchaseAmountOfCurrentPeriod } return Cache::remember($this->prefix($startAt).':'.$dealer->user_id, 3600, function () use ($dealer, $startAt) { - return $this->calculatePurchaseAmount->handle($dealer, $startAt); + return bcdiv($this->calculatePurchaseAmount->handle($dealer, $startAt), '1', 2); }); } diff --git a/app/Endpoint/Api/Http/Controllers/Dealer/UserController.php b/app/Endpoint/Api/Http/Controllers/Dealer/UserController.php index f7e6eb89..c0f92605 100644 --- a/app/Endpoint/Api/Http/Controllers/Dealer/UserController.php +++ b/app/Endpoint/Api/Http/Controllers/Dealer/UserController.php @@ -24,7 +24,7 @@ class UserController extends Controller $user = $request->user(); $dealer = DealerResource::make($user->dealer)->toArray($request); - $dealer['current_purchase_amount'] = bcdiv($calculatePurchaseAmountOfCurrentPeriod->handle($user->dealer), '1', 2); + $dealer['current_purchase_amount'] = $calculatePurchaseAmountOfCurrentPeriod->handle($user->dealer); return response()->json([ 'phone' => $user->phone, From 82ec93852217a93d9d79316e5b16837b7ca2668c Mon Sep 17 00:00:00 2001 From: vine_liutk <961510893@qq.com> Date: Thu, 17 Feb 2022 11:13:34 +0800 Subject: [PATCH 27/30] =?UTF-8?q?=E8=B0=83=E6=95=B4=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E5=88=97=E8=A1=A8wait=5Fshipping?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Models/DealerOrder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Models/DealerOrder.php b/app/Models/DealerOrder.php index d59eb00c..8af27bef 100644 --- a/app/Models/DealerOrder.php +++ b/app/Models/DealerOrder.php @@ -98,7 +98,7 @@ class DealerOrder extends Model /** * 待发货 */ - public function scopenOnliyShipping($query) + public function scopeOnlyShipping($query) { return $query->where('status', DealerOrderStatus::Paid); } From b880420f51a24b79bbafbe24e2968dbb0744c514 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Thu, 17 Feb 2022 11:19:23 +0800 Subject: [PATCH 28/30] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20docker=20=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 7 ------- 1 file changed, 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index be3b90c8..063ef00f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,10 +23,3 @@ COPY ./docker/php/php.ini "$PHP_INI_DIR/" COPY --from=composer:2.1 /usr/bin/composer /usr/bin/composer -ARG PGID -ENV PGID ${PGID:-1000} -ARG PUID -ENV PUID ${PUID:-1000} - -RUN groupmod -g ${PGID} www-data && \ - usermod -u ${PUID} www-data From a91b72a33edee268e03732aae607094e8102a1d4 Mon Sep 17 00:00:00 2001 From: vine_liutk <961510893@qq.com> Date: Thu, 17 Feb 2022 14:29:51 +0800 Subject: [PATCH 29/30] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=90=8E=E5=8F=B0?= =?UTF-8?q?=E6=89=B9=E9=9B=B6=E8=AE=A2=E5=8D=95=E6=97=B6=E9=97=B4=E7=AD=9B?= =?UTF-8?q?=E9=80=89=EF=BC=8C=E6=98=BE=E7=A4=BA=E7=A1=AE=E8=AE=A4=E6=94=B6?= =?UTF-8?q?=E6=AC=BE=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Admin/Controllers/DealerOrderController.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/Admin/Controllers/DealerOrderController.php b/app/Admin/Controllers/DealerOrderController.php index e8b3d784..b3dd8ed3 100644 --- a/app/Admin/Controllers/DealerOrderController.php +++ b/app/Admin/Controllers/DealerOrderController.php @@ -70,7 +70,7 @@ class DealerOrderController extends AdminController // $grid->column('pay_info'); // $grid->column('pay_image'); // $grid->column('pay_time'); - // $grid->column('paied_time'); + $grid->column('paied_time'); // $grid->column('shipping_time'); // $grid->column('shippinged_time'); $grid->column('created_at')->sortable(); @@ -103,6 +103,8 @@ class DealerOrderController extends AdminController $filter->equal('user.phone')->width(3); $filter->equal('consignor.phone')->width(3); $filter->equal('sn')->width(3); + $filter->between('created_at')->dateTime()->width(5); + $filter->between('paied_time')->dateTime()->width(5); // $filter->equal('id'); }); }); From b39f059c0fcbb9d2c2ddb5546d2b246e9d22e5e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Thu, 17 Feb 2022 14:38:22 +0800 Subject: [PATCH 30/30] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E4=B8=8D=E7=94=9F=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Services/SettingService.php | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/app/Services/SettingService.php b/app/Services/SettingService.php index d75724d3..aefc0b5d 100644 --- a/app/Services/SettingService.php +++ b/app/Services/SettingService.php @@ -9,11 +9,6 @@ use Illuminate\Support\Arr; class SettingService { - /** - * @var array - */ - protected $items = []; - /** * @var integer */ @@ -40,19 +35,17 @@ class SettingService $_key = $this->getSettingKey($key); - if (! array_key_exists($_key, $this->items)) { - try { - $this->items[$_key] = $this->cache->remember($this->cacheKey($_key), $this->ttl, function () use ($_key) { - $settings = Setting::where('key', $_key)->firstOrFail(); + try { + $settings[$_key] = $this->cache->remember($this->cacheKey($_key), $this->ttl, function () use ($_key) { + $setting = Setting::where('key', $_key)->firstOrFail(); - return $settings->value; - }); - } catch (ModelNotFoundException $e) { - return $default; - } + return $setting->value; + }); + } catch (ModelNotFoundException $e) { + return $default; } - return Arr::get($this->items, $key, $default); + return Arr::get($settings, $key, $default); } /** @@ -110,7 +103,6 @@ class SettingService public function cleanCache(string $key): void { $_key = $this->getSettingKey($key); - unset($this->items[$_key]); $this->cache->forget($this->cacheKey($_key)); }