From 1a18218bd8d9a7f1ea78cd4476ab60119bd06e35 Mon Sep 17 00:00:00 2001 From: lqmac Date: Tue, 9 Apr 2024 01:33:16 +0800 Subject: [PATCH] 1 --- .../controller/order/MarkingPaperOrder.php | 233 +++++++++++ .../order/marking_paper_order/order_info.php | 71 ++++ .../marking_paper_order/test_paper_order.php | 372 ++++++++++++++++++ 3 files changed, 676 insertions(+) create mode 100644 application/admin/controller/order/MarkingPaperOrder.php create mode 100755 application/admin/view/order/marking_paper_order/order_info.php create mode 100755 application/admin/view/order/marking_paper_order/test_paper_order.php diff --git a/application/admin/controller/order/MarkingPaperOrder.php b/application/admin/controller/order/MarkingPaperOrder.php new file mode 100644 index 00000000..029610f1 --- /dev/null +++ b/application/admin/controller/order/MarkingPaperOrder.php @@ -0,0 +1,233 @@ +assign([ + 'year' => getMonth('y'), + 'real_name' => $this->request->get('real_name', ''), + 'orderCount' => TestPaperOrderModel::orderCount(), + ]); + return $this->fetch('test_paper_order'); + } + + /** + * 获取头部订单金额等信息 + * return json + * + */ + public function getBadge() + { + $where = parent::postMore([ + ['status', ''], + ['real_name', ''], + ['is_del', 0], + ['data', ''], + ['type', ''], + ['order', ''] + ]); + return Json::successful(TestPaperOrderModel::getBadge($where)); + } + + /** + * 获取订单列表 + * return json + */ + public function test_paper_order_list() + { + $where = parent::getMore([ + ['status', ''], + ['real_name', $this->request->param('real_name', '')], + ['is_del', 0], + ['data', ''], + ['type', ''], + ['order', ''], + ['page', 1], + ['limit', 20], + ['excel', 0] + ]); + return Json::successlayui(TestPaperOrderModel::OrderList($where)); + } + + /** + * 修改退款状态 + * @param $id + * @return \think\response\Json|void + */ + public function refund_y($id) + { + if (!$id) return $this->failed('数据不存在'); + $product = TestPaperOrderModel::get($id); + if (!$product) return Json::fail('数据不存在!'); + if ($product['paid'] == 1) { + $f = array(); + $f[] = Form::input('order_id', '退款单号', $product->getData('order_id'))->disabled(1); + $f[] = Form::number('refund_price', '退款金额', $product->getData('pay_price'))->precision(2)->min(0.01); + $f[] = Form::radio('type', '状态', 1)->options([['label' => '直接退款', 'value' => 1]]); + $form = Form::make_post_form('退款处理', $f, Url::build('updateRefundY', array('id' => $id)), 4); + $this->assign(compact('form')); + return $this->fetch('public/form-builder'); + } else return Json::fail('数据不存在!'); + } + + /**退款处理 + * @param Request $request + * @param $id + */ + public function updateRefundY(Request $request, $id) + { + $data = parent::postMore([ + 'refund_price', + ['type', 1], + ], $request); + if (!$id) return $this->failed('数据不存在'); + $product = TestPaperOrderModel::get($id); + if (!$product) return Json::fail('数据不存在!'); + if ($product['pay_price'] == $product['refund_price']) return Json::fail('已退完支付金额!不能再退款了'); + if (!$data['refund_price']) return Json::fail('请输入退款金额'); + $refund_price = $data['refund_price']; + $data['refund_price'] = bcadd($data['refund_price'], $product['refund_price'], 2); + $bj = bccomp((float)$product['pay_price'], (float)$data['refund_price'], 2); + if ($bj < 0) return Json::fail('退款金额大于支付金额,请修改退款金额'); + if ($data['type'] == 1) { + $data['refund_status'] = 2; + } else if ($data['type'] == 2) { + $data['refund_status'] = 0; + } + $type = $data['type']; + unset($data['type']); + $refund_data['pay_price'] = $product['pay_price']; + $refund_data['refund_price'] = $refund_price; + switch ($product['pay_type']) { + case 'weixin': + try { + HookService::listen('wechat_pay_order_refund', $product['order_id'], $refund_data, true, PaymentBehavior::class); + } catch (\Exception $e) { + return Json::fail($e->getMessage()); + } + break; + case 'yue': + ModelBasic::beginTrans(); + $res = User::bcInc($product['uid'], 'now_money', $refund_price, 'uid'); + ModelBasic::checkTrans($res); + if (!$res) return Json::fail('余额退款失败!'); + break; + case 'zhifubao': + $res = AlipayTradeWapService::init()->AliPayRefund($product['order_id'], $product['trade_no'], $refund_price, '试卷退款', 'refund'); + if (empty($res) || $res != 10000) { + return Json::fail('支付宝退款失败!'); + } + break; + case 'toutiao': + try { + $refund_data['order_id'] = $product['order_id']; + $refund_data['refund_reason_wap_explain'] = $product['refund_reason_wap_explain'] ?? '协商商户主动退款'; + $res = (new TouMiniProgramService())->createRefund($refund_data); + if (empty($res) || $res['err_no'] != 0) { + return Json::fail('抖音退款失败!'); + } + } catch (\Exception $e) { + return Json::fail($e->getMessage()); + } + break; + case 'kuaishou': + try { + $refund_data['order_id'] = $product['order_id']; + $refund_data['refund_reason_wap_explain'] = '协商商户主动退款'; + $res = (new KuaiMiniProgramService())->createRefund($refund_data); + if (empty($res) || $res['result'] != 1) { + return Json::fail('快手退款失败!'); + } + } catch (\Exception $e) { + return Json::fail($e->getMessage()); + } + break; + default: + return Json::fail('退款失败!'); + break; + } + $data['refund_reason_time'] = time(); + $resEdit = TestPaperOrderModel::edit($data, $id); + if ($resEdit) { + $data['type'] = $type; + TestPaperObtain::where('order_id', $product['order_id'])->delete(); + $pay_type = $product['pay_type'] == 'yue' ? 'now_money' : $product['pay_type']; + if ($product['pay_type'] == 'yue') { + $balance = User::where(['uid' => $product['uid']])->value('now_money'); + } else { + $balance = 0; + } + UserBill::income('试卷退款', $product['uid'], $pay_type, 'pay_test_paper_refund', $refund_price, $product['id'], $balance, '订单退款' . floatval($refund_price) . '元'); + return Json::successful('修改成功!'); + } else { + return Json::successful('修改失败!'); + } + } + + /**订单详情 + * @param string $oid + * @return mixed|void + * @throws \think\exception\DbException + */ + public function order_info($oid = '') + { + if (!$oid || !($orderInfo = TestPaperOrderModel::get($oid))) + return $this->failed('订单不存在!'); + $userInfo = User::getAllUserinfo($orderInfo['uid']); + $this->assign(compact('orderInfo', 'userInfo')); + return $this->fetch(); + } + + /**订单删除 + * @param int $id + */ + public function delete($id = 0) + { + if (!$id) return Json::fail('参数错误!'); + $data['is_del'] = 1; + $data['is_system_del'] = 1; + TestPaperOrderModel::edit($data, $id); + return Json::successful('删除成功!'); + } +} diff --git a/application/admin/view/order/marking_paper_order/order_info.php b/application/admin/view/order/marking_paper_order/order_info.php new file mode 100755 index 00000000..d17eee80 --- /dev/null +++ b/application/admin/view/order/marking_paper_order/order_info.php @@ -0,0 +1,71 @@ +{extend name="public/container"} +{block name="content"} +
+ +
+
+
+
+ 用户信息 +
+
+
+
用户昵称: {$userInfo.nickname}
+
联系电话: {$userInfo.phone}
+
+
+
+
+
+
+
+ 订单信息 +
+
+
+
订单编号: {$orderInfo.order_id}
+
订单状态: + {if condition="$orderInfo['paid'] eq 0 && $orderInfo['status'] eq 0"} + 未支付 + {elseif condition="$orderInfo['paid'] eq 1 && $orderInfo['status'] eq 0 && $orderInfo['refund_status'] eq 0"/} + 已支付 + {elseif condition="$orderInfo['paid'] eq 1 && $orderInfo['refund_status'] eq 2"/} + 已退款 + {/if} +
+
试卷总数: {$orderInfo.total_num}
+
订单总价: ¥{$orderInfo.total_price}
+
实际支付: ¥{$orderInfo.pay_price}
+ {if condition="$orderInfo['refund_price'] GT 0"} +
退款金额: ¥{$orderInfo.refund_price}
+ {/if} +
创建时间: {$orderInfo.add_time|date="Y/m/d H:i",###}
+
支付方式: + {if condition="$orderInfo['paid'] eq 1"} + {if condition="$orderInfo['pay_type'] eq 'weixin'"} + 微信支付 + {elseif condition="$orderInfo['pay_type'] eq 'yue'"} + 余额支付 + {elseif condition="$orderInfo['pay_type'] eq 'zhifubao'"} + 支付宝支付 + {else/} + 其他支付 + {/if} + {else/} + 未支付 + {/if} +
+ {notempty name="orderInfo.pay_time"} +
支付时间: {$orderInfo.pay_time|date="Y/m/d H:i",###}
+ {/notempty} +
+
+
+
+
+
+ +{/block} +{block name="script"} + +{/block} diff --git a/application/admin/view/order/marking_paper_order/test_paper_order.php b/application/admin/view/order/marking_paper_order/test_paper_order.php new file mode 100755 index 00000000..38c2f5ea --- /dev/null +++ b/application/admin/view/order/marking_paper_order/test_paper_order.php @@ -0,0 +1,372 @@ +{extend name="public/container"} +{block name="head"} + +{/block} +{block name="content"} +
+
+ +
+
+
考试订单
+
+
+
+ +
+
+ +
+
+
+
+ +
+
+ +
+
+
+ +
+
+
+ +
+ +
+
+
+
+ + + +
+
+
+
+
+
+ + +
+
+
+ {{item.name}} + {{item.field}} +
+
+

{{item.count}}

+

+ {{item.content}} + {{item.sum}} +

+
+
+
+ + +
+
+
+
+
+
+
+ +
+
+ + + + + + + + + + + + +{/block} +{block name="script"} + +{/block}