From a4304bf4c8c93060d5ace43a9c2c71cce5e6a43a Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Sun, 17 Oct 2021 23:03:04 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E4=B8=8A=E6=9E=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/AdminAgent/Forms/Setting.php | 2 +- app/Providers/ProductServiceProvider.php | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/AdminAgent/Forms/Setting.php b/app/AdminAgent/Forms/Setting.php index 568eed3..06ad22b 100644 --- a/app/AdminAgent/Forms/Setting.php +++ b/app/AdminAgent/Forms/Setting.php @@ -36,7 +36,7 @@ class Setting extends Form ->help('订单超时时间,单位:分钟。超过该时间未支付,订单将自动关闭'); $this->radio('auto_shelves')->when([1], function (Form $form) { // 值为1和4时显示文本框 - $form->number('profit','利润(%)')->min(0)->max(100)->help('请填写利润百分比 上架商品会自动根据供应商提供的价格 上调设置值的百分比'); + //$form->number('profit','利润(%)')->min(0)->max(100)->help('请填写利润百分比 上架商品会自动根据供应商提供的价格 上调设置值的百分比'); $form->radio('auto_category','自动添加分类')->options([ '否', '是', diff --git a/app/Providers/ProductServiceProvider.php b/app/Providers/ProductServiceProvider.php index f2b0383..3aaba31 100644 --- a/app/Providers/ProductServiceProvider.php +++ b/app/Providers/ProductServiceProvider.php @@ -73,11 +73,11 @@ class ProductServiceProvider extends ServiceProvider $agentProduct->content = $product->content; $agentProduct->know = $product->know; //计算价格 - $profit = AgentSetting::val($v, 'profit') ?? 0; - $price = bcmul($product->price, bcdiv($profit + 100, 100, 6), 6); + // $profit = AgentSetting::val($v, 'profit') ?? 0; + // $price = bcmul($product->price, bcdiv($profit + 100, 100, 6), 6); - $agentProduct->price = $price; - $agentProduct->original_price = $price; + $agentProduct->price = $product->price; + $agentProduct->original_price = $product->original_price; //自动添加分类 $autoCategory = AgentSetting::val($v, 'auto_category') ?? 0; @@ -107,8 +107,8 @@ class ProductServiceProvider extends ServiceProvider 'agent_product_id' => $agentProduct->id, 'product_spec_id' => $spec->id, 'stock' => $spec->stock, - 'original_price' => bcmul($spec->price, bcdiv($profit + 100, 100, 6), 6), - 'price' => bcmul($spec->price, bcdiv($profit + 100, 100, 6), 6), + 'original_price' => $spec->original_price, + 'price' => $spec->price, ]; } From 3abc5d616ba8aecb79f1b3f92f54698912cf9eef Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Mon, 18 Oct 2021 18:12:45 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E7=BA=BF=E4=B8=8B=E5=B7=B2=E4=BB=98?= =?UTF-8?q?=E6=AC=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Extensions/Grid/ChangeOrderStatus.php | 22 +++++++++++++++++++ app/Http/Controllers/Api/OrderController.php | 4 +++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/app/AdminAgent/Extensions/Grid/ChangeOrderStatus.php b/app/AdminAgent/Extensions/Grid/ChangeOrderStatus.php index a26bd9c..2d6b3de 100644 --- a/app/AdminAgent/Extensions/Grid/ChangeOrderStatus.php +++ b/app/AdminAgent/Extensions/Grid/ChangeOrderStatus.php @@ -3,8 +3,12 @@ namespace App\AdminAgent\Extensions\Grid; use App\Common\OrderStatus; use App\Models\Order; +use App\Models\Agent; +use App\Models\OrderProductItem; +use App\Models\Supplier; use Dcat\Admin\Admin; use Dcat\Admin\Grid\RowAction; +use Illuminate\Support\Facades\DB; /** * 改变订单状态 @@ -25,17 +29,35 @@ class ChangeOrderStatus extends RowAction public function handle() { + DB::beginTransaction(); try { $order = Order::firstWhere(['id' => $this->getKey(), 'agent_id' => Admin::user()->id, 'status' => OrderStatus::OFFLINE_UNPAID]); if (!$order) { return $this->response()->error("订单不存在或已处理过了")->refresh(); } + $agent = Agent::query()->where('id', Admin::user()->id)->lockForUpdate()->first(); + if ($agent->balance < $order->price) { + return $this->response()->error("账户余额不足,请先进行充值")->refresh(); + } + $order->status = OrderStatus::OFFLINE_PAID; $order->verify_code = uniqid(); //生成核销码 $order->save(); + //扣供应商余额 + $agent->balance = bcsub($agent->balance,$order->price,6); + $agent->save(); + + $orderItem = OrderProductItem::query()->where('order_id',$order->id)->get(); + foreach ($orderItem as $item) { + $supplier = Supplier::query()->where('id',$item->supplier_id)->lockForUpdate()->first(); + $supplier->balance = bcadd($supplier->balance,$item->price,6); + $supplier->save(); + } + DB::commit(); return $this->response()->success("操作成功,已设置为“线下已付款”")->refresh(); } catch (\Exception $e) { + DB::rollBack(); return $this->response()->error($e->getMessage()); } } diff --git a/app/Http/Controllers/Api/OrderController.php b/app/Http/Controllers/Api/OrderController.php index 4b37509..42c1f05 100644 --- a/app/Http/Controllers/Api/OrderController.php +++ b/app/Http/Controllers/Api/OrderController.php @@ -185,8 +185,10 @@ class OrderController extends Controller //订单总价 $order_price = 0; + $costPrice = 0; foreach ($spec as $v) { $order_price += $v['price'] * $formData['num']; + $costPrice = bcadd($costPrice,bcmul($v->productSpec->cost_price,$formData['num'],6),6); } $order_price = round($order_price, 2); @@ -327,7 +329,7 @@ class OrderController extends Controller 'supplier_id' => $ap->product->supplier_id, 'product_id' => $ap->product->id, 'num' => $formData['num'], - 'price' => $ap->product->price * $formData['num'], + 'price' => $costPrice, 'agent_product_spec_id' => json_encode($agent_product_spec_ids), 'product_type' => $ap->product->type, 'product_spec_id' => json_encode($product_spec_ids),