From 8fb1bce067e4bc981a14a5cff90657723eaf5bb3 Mon Sep 17 00:00:00 2001 From: liapples Date: Mon, 30 Aug 2021 10:24:10 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=B8=B8=E9=87=8F?= =?UTF-8?q?=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Common/PayType.php | 8 ++++---- app/Http/Controllers/Api/OrderController.php | 2 +- app/Http/Controllers/Api/WxpayController.php | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/Common/PayType.php b/app/Common/PayType.php index 132ee54..b9b7c7b 100644 --- a/app/Common/PayType.php +++ b/app/Common/PayType.php @@ -16,10 +16,10 @@ class PayType const OFFLINE = 1; /** @var int 订金支付 */ - const SUBSCRIPTION = 2; + const DEPOSIT_PAY = 2; /** @var int 定金支付 */ - const DEPOSIT = 3; + const EARNEST_PAY = 3; /** @var int 尾款/多加支付 */ const DOWN_PAYMENT = 4; @@ -32,8 +32,8 @@ class PayType return [ self::ONLINE => '在线支付', self::OFFLINE => '线下支付', - self::SUBSCRIPTION => '订金支付', - self::DEPOSIT => '定金支付', + self::DEPOSIT_PAY => '订金支付', + self::EARNEST_PAY => '定金支付', self::DOWN_PAYMENT => '首款支付', self::BALANCE_PAY => '尾款/多加支付', ]; diff --git a/app/Http/Controllers/Api/OrderController.php b/app/Http/Controllers/Api/OrderController.php index fd84711..0c8adfb 100644 --- a/app/Http/Controllers/Api/OrderController.php +++ b/app/Http/Controllers/Api/OrderController.php @@ -379,7 +379,7 @@ class OrderController extends Controller private function calc($price, $coupon, $num, $pay_type) { //根据支付方式计算价格 - if (in_array($pay_type, [PayType::SUBSCRIPTION, PayType::DEPOSIT, PayType::DOWN_PAYMENT])) { + if (in_array($pay_type, [PayType::DEPOSIT_PAY, PayType::EARNEST_PAY, PayType::DOWN_PAYMENT])) { return $this->earnest; } //TODO 还要计算尾款支付金额 diff --git a/app/Http/Controllers/Api/WxpayController.php b/app/Http/Controllers/Api/WxpayController.php index 766da12..938c0a2 100644 --- a/app/Http/Controllers/Api/WxpayController.php +++ b/app/Http/Controllers/Api/WxpayController.php @@ -66,7 +66,7 @@ class WxpayController $pay_type = $order->pay_type; $money = $message['total_fee'] / 100; //定金支付和首付款支付 - if (in_array($pay_type, [PayType::SUBSCRIPTION, PayType::DEPOSIT, PayType::DOWN_PAYMENT])) { + if (in_array($pay_type, [PayType::DEPOSIT_PAY, PayType::EARNEST_PAY, PayType::DOWN_PAYMENT])) { if ($status == OrderStatus::UNPAID) { $order->status = OrderStatus::PAY_EARNEST; } else if ($status == OrderStatus::PAY_EARNEST) { From 192e9c1408408353d0ca7d707948a0d38ff0ddf3 Mon Sep 17 00:00:00 2001 From: liapples Date: Mon, 30 Aug 2021 10:45:23 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E8=AE=A2=E9=87=91=E5=92=8C=E5=AE=9A?= =?UTF-8?q?=E9=87=91=E6=A0=B9=E6=8D=AE=E4=BA=A7=E5=93=81=E6=9D=A5=E8=AE=BE?= =?UTF-8?q?=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MySQL_change.sql | 7 +++++ .../Controllers/AgentProductController.php | 21 +++++++++++-- app/Http/Controllers/Api/OrderController.php | 31 +++++++++++-------- resources/lang/zh_CN/agent-product.php | 4 +++ 4 files changed, 48 insertions(+), 15 deletions(-) diff --git a/MySQL_change.sql b/MySQL_change.sql index 32611e9..771a575 100644 --- a/MySQL_change.sql +++ b/MySQL_change.sql @@ -210,3 +210,10 @@ ALTER TABLE `notices` ADD COLUMN `author` VARCHAR(20) NOT NULL DEFAULT '' COMMENT '作者' COLLATE 'utf8_general_ci' AFTER `sort`; ALTER TABLE `articles` ADD COLUMN `agent_product_ids` TEXT NULL DEFAULT NULL COMMENT '绑定产品' AFTER `sort`; + +# 9:28 2021/8/30 +ALTER TABLE `agent_products` + ADD COLUMN `earnest` DECIMAL(20,2) NOT NULL DEFAULT '0' COMMENT '定金' AFTER `content`, + ADD COLUMN `earnest_timeout` INT NOT NULL DEFAULT 0 COMMENT '定金支付超时时间,单位:分钟' AFTER `earnest`, + ADD COLUMN `deposit` DECIMAL(20,2) NOT NULL DEFAULT 0 COMMENT '订金' AFTER `earnest_timeout`, + ADD COLUMN `deposit_timeout` INT NOT NULL DEFAULT 0 COMMENT '订金支付超时时间,单位:分钟' AFTER `deposit`; diff --git a/app/AdminAgent/Controllers/AgentProductController.php b/app/AdminAgent/Controllers/AgentProductController.php index c0e0727..2f1b258 100644 --- a/app/AdminAgent/Controllers/AgentProductController.php +++ b/app/AdminAgent/Controllers/AgentProductController.php @@ -125,6 +125,10 @@ class AgentProductController extends AdminController $show->field('pictures')->image('', 80, 80); $show->field('know')->unescape(); $show->field('content')->unescape(); + $show->field('earnest'); + $show->field('earnest_timeout'); + $show->field('deposit'); + $show->field('deposit_timeout'); $show->field('created_at'); $show->field('updated_at'); @@ -223,6 +227,11 @@ class AgentProductController extends AdminController ->from(SelectGuide::make()) ->model(Guide::class, 'id', 'name'); } + + $form->text('earnest')->default(0)->help('单位:元。不输入或输入 0 则不支持定金支付,必须和定金超时时间同时设置才会生效'); + $form->text('earnest_timeout')->default(0)->help('单位:分钟。超过这个时间未支付,订单将自动关闭'); + $form->text('deposit')->default(0)->help('单位:元。不输入或输入 0 则不支持订金支付,必须和订金超时时间同时设置才会生效'); + $form->text('deposit_timeout')->default(0)->help('单位:分钟。超过这个时间未支付,订单将自动关闭'); })->saving(function (Form $form) { //不允许修改非自己的数据 if ($form->isEditing() && $form->model()->agent_id != Admin::user()->id) { @@ -303,12 +312,20 @@ class AgentProductController extends AdminController //处理特殊字段 $form->hidden(['agent_id', 'status']); //表单没有的字段,必须加这句才能够重写 $form->agent_id = $agent_id; - if (array_key_exists($form->status, $form->input())) { + if (array_key_exists('status', $form->input())) { $form->status = $form->status == ProductStatus::ON_SALE ? ProductStatus::ON_SALE : ProductStatus::SOLD_OUT; } - if (array_key_exists($form->guide_id, $form->input())) { + if (array_key_exists('guide_id', $form->input())) { $form->guide_id = $form->guide_id ?? 0; } + if ($form->earnest <= 0 || $form->earnest_timeout <= 0) { + $form->earnest = 0; + $form->earnest_timeout = 0; + } + if ($form->deposit <= 0 || $form->deposit_timeout <= 0) { + $form->deposit = 0; + $form->deposit_timeout = 0; + } //不允许编辑的字段 $form->ignore(['id', 'agent_id', 'status', 'created_at', 'updated_at', 'deleted_at']); diff --git a/app/Http/Controllers/Api/OrderController.php b/app/Http/Controllers/Api/OrderController.php index 0c8adfb..acc7fbd 100644 --- a/app/Http/Controllers/Api/OrderController.php +++ b/app/Http/Controllers/Api/OrderController.php @@ -14,6 +14,7 @@ use EasyWeChat\Factory; use EasyWeChat\Kernel\Exceptions\InvalidArgumentException; use EasyWeChat\Kernel\Exceptions\InvalidConfigException; use GuzzleHttp\Exception\GuzzleException; +use Illuminate\Database\Eloquent\Model; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use App\Common\OrderStatus as Status; @@ -144,7 +145,7 @@ class OrderController extends Controller DB::beginTransaction(); try { - $price = $this->calc($ap->price, $ap->coupon, $formData['num'], $formData['pay_type']); + $price = $this->calc($ap->price, $formData['num'], $formData['pay_type'], $ap); $title = $ap->title; //产品标题 //供应商产品表减库存 @@ -252,7 +253,7 @@ class OrderController extends Controller $ap = AgentProduct::query() ->has('product') ->with('coupon:agent_product_id,type,detail,agent_id,tag,start_at,end_at') - ->find($formData['id'], ['id', 'price', 'original_price', 'product_id', 'title', 'pictures']); + ->find($formData['id'], ['id', 'price', 'original_price', 'product_id', 'title', 'pictures', 'earnest', 'earnest_timeout', 'deposit', 'deposit_timeout']); if (!$ap) { return $this->error('产品信息不存在'); @@ -266,7 +267,7 @@ class OrderController extends Controller $formData['pay_type'] = PayType::ONLINE; } - $ap->final_price = $this->calc($ap->price, $ap->coupon, $formData['num'], $formData['pay_type']); + $ap->final_price = $this->calc($ap->price, $formData['num'], $formData['pay_type'], $ap); $ap->num = $formData['num']; return $this->success($ap); } @@ -286,13 +287,13 @@ class OrderController extends Controller return $this->error('订单不存在或已支付'); } - $coupon = Coupon::whereIn('id', $order['coupon_id'])->get(); + $ap = AgentProduct::with('coupon')->find($order->agent_product_id); //如果已经付定金或首付款,则仅支付尾款 if ($order->status == Status::PAY_EARNEST) { $price = $order->price - $order->paid_money; } else { - $price = $this->calc($order->price, $coupon, $order->num, $order->pay_type); + $price = $this->calc($order->price, $order->num, $order->pay_type, $ap); } $config = $this->payConfig($order, $price); @@ -371,21 +372,25 @@ class OrderController extends Controller * 计算最终价格(扣除优惠券之后的价格) * $price:原价;$coupon:优惠券;$num:产品数量;$pay_type:支付方式 * @param float $price - * @param Coupon $coupon * @param int $num * @param int $pay_type + * @param Model $agent_product * @return float */ - private function calc($price, $coupon, $num, $pay_type) + private function calc($price, $num, $pay_type, $agent_product) { //根据支付方式计算价格 if (in_array($pay_type, [PayType::DEPOSIT_PAY, PayType::EARNEST_PAY, PayType::DOWN_PAYMENT])) { - return $this->earnest; + if ($pay_type == PayType::DEPOSIT_PAY && $agent_product->deposit && $agent_product->deposit_timeout) { + return $agent_product->deposit; + } + if ($pay_type == PayType::EARNEST_PAY && $agent_product->earnest && $agent_product->earnest_timeout) { + return $agent_product->earnest; + } } - //TODO 还要计算尾款支付金额 $total_price = $price * $num; - //没有任何优惠券时直接返回最终价 + /*//没有任何优惠券时直接返回最终价 if ($coupon && $coupon->isEmpty()) { return $total_price; } @@ -393,14 +398,14 @@ class OrderController extends Controller $coupon = $coupon->toArray(); foreach ($coupon as $v) { // TODO 未判断优惠券有效期 - /*if ($v['type'] == 1 && !empty($v['detail']['full']) && !empty($v['detail']['reduction'])) { //满减 + if ($v['type'] == 1 && !empty($v['detail']['full']) && !empty($v['detail']['reduction'])) { //满减 if ($total_price >= $v['detail']['full']) { $total_price -= $v['detail']['reduction']; } } else if ($v['type'] == 2 && !empty($v['detail']['discount'])) { //打折 $total_price *= $v['detail']['discount']; - }*/ - } + } + }*/ return round($total_price, 2); } diff --git a/resources/lang/zh_CN/agent-product.php b/resources/lang/zh_CN/agent-product.php index 2d914c6..28ab890 100644 --- a/resources/lang/zh_CN/agent-product.php +++ b/resources/lang/zh_CN/agent-product.php @@ -21,6 +21,10 @@ return [ 'know' => '旅游须知', 'pictures' => '产品图片', 'picture' => '产品图片', + 'earnest' => '定金', + 'earnest_timeout' => '定金超时时间', + 'deposit' => '订金', + 'deposit_timeout' => '订金超时时间', 'product' => trans('product.fields'), ], 'options' => [