Browse Source

核销功能改为按产品/订单核销

dev
李可松 4 years ago
parent
commit
40fa28cc0d
  1. 3
      MySQL_change.sql
  2. 7
      app/Http/Controllers/Api/OrderController.php
  3. 25
      app/Http/Controllers/Api/VerificationController.php
  4. 5
      app/Http/Controllers/Api/WxpayController.php

3
MySQL_change.sql

@ -89,3 +89,6 @@ ALTER TABLE `agent_products`
# 10:42 ‎2021/‎08/‎21 # 10:42 ‎2021/‎08/‎21
ALTER TABLE `orders` ALTER TABLE `orders`
CHANGE COLUMN `order_no` `order_no` CHAR(22) NOT NULL COMMENT '订单号' COLLATE 'utf8_general_ci' AFTER `agent_id`; CHANGE COLUMN `order_no` `order_no` CHAR(22) NOT NULL COMMENT '订单号' COLLATE 'utf8_general_ci' AFTER `agent_id`;
ALTER TABLE `orders`
ADD COLUMN verify_code CHAR(13) NOT NULL DEFAULT '' COMMENT '核销码' AFTER `guide_id`;

7
app/Http/Controllers/Api/OrderController.php

@ -327,8 +327,8 @@ class OrderController extends Controller
{ {
$id = (int)request()->input('id'); $id = (int)request()->input('id');
$fields = ['id', 'order_no', 'agent_product_id', 'num', 'price', 'title', 'picture',
'status', 'pay_type', 'coupon_id', 'paid_money', 'paid_at', 'refund_info', 'created_at'];
$fields = ['id', 'order_no', 'agent_product_id', 'num', 'price', 'title', 'picture', 'status',
'pay_type', 'coupon_id', 'paid_money', 'paid_at', 'refund_info', 'verify_code', 'created_at'];
$order = Order::query() $order = Order::query()
->where('user_id', $this->user_id) ->where('user_id', $this->user_id)
->find($id, $fields); ->find($id, $fields);
@ -337,6 +337,9 @@ class OrderController extends Controller
return $this->error('订单不存在'); return $this->error('订单不存在');
} }
//订单ID和核销码拼接,查询时通过订单ID和核销码来查询,这样核销码不用建索引
$order->verify_code = $order->id . '-' . $order->verify_code;
$order->coupon = Coupon::query() $order->coupon = Coupon::query()
->whereIn('id', $order->coupon_id) ->whereIn('id', $order->coupon_id)
->where(['agent_id' => $this->agent_id, 'agent_product_id' => $order->agent_product_id,]) ->where(['agent_id' => $this->agent_id, 'agent_product_id' => $order->agent_product_id,])

25
app/Http/Controllers/Api/VerificationController.php

@ -11,21 +11,28 @@ class VerificationController extends Controller
//核销订单 //核销订单
public function verify() public function verify()
{ {
$id = (int)request()->input('id'); //订单ID
$input_verify_code = request()->input('verify_code'); //订单ID
$user = User::firstWhere(['id' => $this->user_id, 'status' => 1]);
if (!$user || $user->verifier != 1) {
return $this->error('对不起,你没有核销权限,请联系管理员');
$code_arr = explode('-', $input_verify_code);
if (count($code_arr) != 2) {
$this->error('参数错误');
} }
list($id, $verify_code) = $code_arr;
$order = Order::query()->where('agent_id', $this->agent_id)->find($id);
$order = Order::with('agentProduct:id,verifier')
->where(['agent_id' => $this->agent_id, 'verify_code' => $verify_code])
->whereIn('status', [OrderStatus::PAID, OrderStatus::PAID_RETAINAGE, OrderStatus::OFFLINE_PAID])
->find($id);
if (!$order) { if (!$order) {
return $this->error('订单不存在或无权限');
return $this->error('订单不存在或订单状态不允许核销');
} }
if (!in_array($order->status, [OrderStatus::PAID, OrderStatus::PAID_RETAINAGE, OrderStatus::OFFLINE_UNPAID])) {
return $this->error('当前订单状态不允许核销');
$user = User::firstWhere(['id' => $this->user_id, 'status' => 1]);
if (!$user || $user->id != $order->agentProduct->verifier) {
return $this->error('对不起,你没有核销权限,请联系管理员');
} }
$order->status = 16;
$order->status = OrderStatus::SUCCESS;
$order->save(); $order->save();
return $this->success(); return $this->success();

5
app/Http/Controllers/Api/WxpayController.php

@ -76,6 +76,11 @@ class WxpayController
$order->status = OrderStatus::PAID; $order->status = OrderStatus::PAID;
} }
//支付金额>=订单金额之后生成核销码
if ($order->paid_money + $money >= $order->price) {
$order->verify_code = uniqid(); //生成核销码
}
$order->paid_at = now(); $order->paid_at = now();
$order->paid_money = DB::raw('`paid_money` + ' . $money); $order->paid_money = DB::raw('`paid_money` + ' . $money);
$order->save(); $order->save();

Loading…
Cancel
Save