From 43d69baf9698c480d804c8c9d55bf2be2282b946 Mon Sep 17 00:00:00 2001 From: "1213317725@qq.com" <1213317725@qq.com> Date: Wed, 2 Jul 2025 13:14:23 +0800 Subject: [PATCH] 1 --- .../customer_resources/customer_resources.vue | 2 +- niucloud/app/common.php | 62 ++++++++++++++++++- .../admin/order_table/OrderTableService.php | 15 +++-- niucloud/app/service/admin/pay/PayService.php | 23 +++++++ niucloud/app/service/api/pay/PayService.php | 5 ++ 5 files changed, 100 insertions(+), 7 deletions(-) diff --git a/admin/src/app/views/customer_resources/customer_resources.vue b/admin/src/app/views/customer_resources/customer_resources.vue index 1d0eda23..148fb0b1 100644 --- a/admin/src/app/views/customer_resources/customer_resources.vue +++ b/admin/src/app/views/customer_resources/customer_resources.vue @@ -335,7 +335,7 @@ const addOrder = (row : any) => { console.log(row); - editOrderTableDialog.value.setFormData(row) + editOrderTableDialog.value.setFormData({'resource_id' : row.id}) editOrderTableDialog.value.showDialog = true } diff --git a/niucloud/app/common.php b/niucloud/app/common.php index b755957a..cd425171 100644 --- a/niucloud/app/common.php +++ b/niucloud/app/common.php @@ -1108,7 +1108,7 @@ function return_pay_config($campus_id, $order_id) // 必填-商户公钥证书路径 'mch_public_cert_path' => $pay_config['apiclient_key'], // 必填 - 'notify_url' => 'https://zh.hnhbty.cn/api/pay/qrcodenotify/order_id/' . $order_id, + 'notify_url' => 'https://api.hnhbty.cn/api/pay/qrcodenotify/order_id/' . $order_id, // 选填-公众号 的 app_id 'mp_app_id' => $vx_config['app_id'], // 选填-小程序 的 app_id @@ -1361,3 +1361,63 @@ function get_staff_performance_total(int $staffId, string $performanceType = '', } } +function httpGet($url) { + $curl = curl_init(); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); + curl_setopt($curl, CURLOPT_TIMEOUT, 500); + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); + curl_setopt($curl, CURLOPT_URL, $url); + + $res = curl_exec($curl); + curl_close($curl); + + return $res; +} + + +function getAccessToken() { + $appId = 'wxaee2df4a4b31df05'; + $appSecret = '06284bac15b25775293690765a6be4d9'; + $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appId&secret=$appSecret"; + $res = json_decode(httpGet($url)); + $access_token = $res->access_token; + return $access_token; +} + +//$touser 用户的openid +//$template_id 模板id +//$value 发送的 消息 数组 +function sendMessage($touser,$template_id,$value) { + // 构建请求参数 + $accessToken = getAccessToken(); + $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" .$accessToken; + + + if($template_id == 'ogmlvTC-Q2gLMBbRHAUKCSWpwyQIOrLBA30HyAKkEXg'){ + $data = [ + 'touser' => $touser, + 'template_id' => $template_id, + 'data' => [ + 'thing3' => ['value' => $value['thing3'], 'color' => '#173177'], //课程名称 + 'time4' => ['value' => $value['time4'], 'color' => '#173177'],//课程周期 例子 2023年10月11日~2023年11月30日 + 'character_string7' => ['value' => $value['character_string7'], 'color' => '#173177'],//课程数量 + 'character_string9' => ['value' => $value['character_string9'], 'color' => '#173177'],//课程码 课程金额 + 'time5' => ['value' => $value['time5'], 'color' => '#173177']//上课时间 + ], + 'miniprogram' => [ + "appid" => "wxaee2df4a4b31df05", + "pagepath" => $value['pagepath'] + ] + ]; + } + + // 发送 POST 请求 + $ch = curl_init($url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); + $response = curl_exec($ch); + curl_close($ch); + +} diff --git a/niucloud/app/service/admin/order_table/OrderTableService.php b/niucloud/app/service/admin/order_table/OrderTableService.php index 2454d7b5..3eb91986 100644 --- a/niucloud/app/service/admin/order_table/OrderTableService.php +++ b/niucloud/app/service/admin/order_table/OrderTableService.php @@ -87,12 +87,15 @@ class OrderTableService extends BaseAdminService public function add(array $data) { $personnel = new Personnel(); -// $data['staff_id'] = $personnel->where(['sys_user_id' => $this->uid])->value("id"); -// if(!$data['staff_id']){ -// return fail("操作失败"); -// } + $data['staff_id'] = $personnel->where(['sys_user_id' => $this->uid])->value("id"); + if(!$data['staff_id']){ + return fail("操作失败"); + } + $cr = new CustomerResources(); + $data['campus_id'] = $cr->where(['id' => $data['resource_id']])->value("campus"); + - $data['staff_id'] = 1; +// $data['staff_id'] = 1; $res = $this->model->create($data); return success("操作成功"); @@ -107,6 +110,8 @@ class OrderTableService extends BaseAdminService */ public function edit(int $id, array $data) { + $cr = new CustomerResources(); + $data['campus_id'] = $cr->where(['id' => $data['resource_id']])->value("campus"); $this->model->where([['id', '=', $id]])->update($data); return true; diff --git a/niucloud/app/service/admin/pay/PayService.php b/niucloud/app/service/admin/pay/PayService.php index d41e816c..636bd42e 100644 --- a/niucloud/app/service/admin/pay/PayService.php +++ b/niucloud/app/service/admin/pay/PayService.php @@ -14,6 +14,7 @@ namespace app\service\admin\pay; use app\dict\common\ChannelDict; use app\dict\pay\PayDict; use app\dict\pay\PaySceneDict; +use app\model\campus_pay\CampusPay; use app\model\customer_resources\CustomerResources; use app\model\member\Member; use app\model\order_table\OrderTable; @@ -245,12 +246,34 @@ class PayService extends BaseAdminService $path = qrcode($url['code_url'],'',[],'upload/qrcode/pay/'); $order->where(['id' => $data['order_id']])->update(['payment_id' => $out_trade_no,'ipv3' => $config['mch_secret_key']]); + + $payModel = new Pay(); + $campus_pay = new CampusPay(); + $campus_pay_info = $campus_pay->where(['campus_id' => $order_info['campus_id']])->findOrEmpty()->toArray(); + $payModel->insert([ + 'main_id' => $resource_info['member_id'], + 'from_main_id' => $resource_info['member_id'], + 'out_trade_no' => $out_trade_no, + 'trade_type' => '', + 'trade_id' => $data['order_id'], + 'trade_no' => $out_trade_no, + 'body' => '扫码支付', + 'money' => $order_info['order_amount'], + 'status' => 0, + 'create_time' => time(), + 'type' => $order_info['payment_type'], + 'mch_id' => $campus_pay_info['mchid'], + 'main_type' => $order_info['payment_type'], + 'channel' => '微信扫码支付' + ]); + return ['qrcode_url' => getCurrentDomain().$path,'out_trade_no'=>$out_trade_no]; } public function check_payment_status($data){ $order = new OrderTable(); $order_status = $order->where(['payment_id' => $data['out_trade_no']])->value("order_status"); + return ['order_status'=>$order_status]; } } diff --git a/niucloud/app/service/api/pay/PayService.php b/niucloud/app/service/api/pay/PayService.php index 52e53909..2cc7f606 100644 --- a/niucloud/app/service/api/pay/PayService.php +++ b/niucloud/app/service/api/pay/PayService.php @@ -180,6 +180,11 @@ class PayService extends BaseApiService $order->where(['payment_id' => $info['out_trade_no']])->update(['order_status' => 'paid','payment_time' => date("Y-m-d H:i:s")]); + $payModel = new Pay(); + $payModel->where(['trade_id' => $order_id])->update([ + 'status' => 2, + 'pay_time' => time() + ]); event('Student', ['event_type' => 'add','data' => $order_info]); }