From 941910a5286adb3fdc0899ffb6232bfb8515bde8 Mon Sep 17 00:00:00 2001 From: zhangxingye <892562066@qq.com> Date: Sat, 22 Feb 2025 17:21:18 +0800 Subject: [PATCH] 1.5.0 --- niucloud/config/version.php | 4 +- niucloud/core/dict/AdvPosition.php | 2 +- niucloud/core/dict/DiyFormComponent.php | 38 ++++++++++ niucloud/core/dict/DiyFormTemplate.php | 38 ++++++++++ niucloud/core/dict/DiyFormType.php | 38 ++++++++++ niucloud/core/dict/RechargeGift.php | 2 +- niucloud/core/dict/WebLink.php | 2 +- niucloud/core/pay/Wechatpay.php | 95 +++++++++++++++++-------- 8 files changed, 185 insertions(+), 34 deletions(-) create mode 100644 niucloud/core/dict/DiyFormComponent.php create mode 100644 niucloud/core/dict/DiyFormTemplate.php create mode 100644 niucloud/core/dict/DiyFormType.php diff --git a/niucloud/config/version.php b/niucloud/config/version.php index 7d5129234..67c29f73b 100644 --- a/niucloud/config/version.php +++ b/niucloud/config/version.php @@ -1,6 +1,6 @@ '1.4.4', - 'code' => '202501030001' + 'version' => '1.5.1', + 'code' => '2025022201' ]; diff --git a/niucloud/core/dict/AdvPosition.php b/niucloud/core/dict/AdvPosition.php index a4a1fc305..188726bb2 100644 --- a/niucloud/core/dict/AdvPosition.php +++ b/niucloud/core/dict/AdvPosition.php @@ -1,6 +1,6 @@ getLocalAddons(); + $components_files = []; + + foreach ($addons as $v) { + $components_path = $this->getAddonDictPath($v) . "diy_form" . DIRECTORY_SEPARATOR . "components.php"; + if (is_file($components_path)) { + $components_files[] = $components_path; + } + } + $components_files_data = $this->loadFiles($components_files); + $components = $data; + foreach ($components_files_data as $file_data) { + $components = empty($components) ? $file_data : array_merge2($components, $file_data); + } + return $components; + } +} diff --git a/niucloud/core/dict/DiyFormTemplate.php b/niucloud/core/dict/DiyFormTemplate.php new file mode 100644 index 000000000..5ac2e1308 --- /dev/null +++ b/niucloud/core/dict/DiyFormTemplate.php @@ -0,0 +1,38 @@ +getLocalAddons(); + $components_files = []; + + foreach ($addons as $v) { + $components_path = $this->getAddonDictPath($v) . "diy_form" . DIRECTORY_SEPARATOR . "template.php"; + if (is_file($components_path)) { + $components_files[] = $components_path; + } + } + $components_files_data = $this->loadFiles($components_files); + $components = $data; + foreach ($components_files_data as $file_data) { + $components = empty($components) ? $file_data : array_merge2($components, $file_data); + } + return $components; + } +} diff --git a/niucloud/core/dict/DiyFormType.php b/niucloud/core/dict/DiyFormType.php new file mode 100644 index 000000000..7b0caab5c --- /dev/null +++ b/niucloud/core/dict/DiyFormType.php @@ -0,0 +1,38 @@ +getLocalAddons(); + $components_files = []; + + foreach ($addons as $v) { + $components_path = $this->getAddonDictPath($v) . "diy_form" . DIRECTORY_SEPARATOR . "type.php"; + if (is_file($components_path)) { + $components_files[] = $components_path; + } + } + $components_files_data = $this->loadFiles($components_files); + $components = $data; + foreach ($components_files_data as $file_data) { + $components = empty($components) ? $file_data : array_merge2($components, $file_data); + } + return $components; + } +} diff --git a/niucloud/core/dict/RechargeGift.php b/niucloud/core/dict/RechargeGift.php index ed9ca7942..f3f1a78b5 100644 --- a/niucloud/core/dict/RechargeGift.php +++ b/niucloud/core/dict/RechargeGift.php @@ -1,6 +1,6 @@ config['mch_id']) || empty($this->config['mch_secret_key']) || empty($this->config['mch_secret_cert']) || empty($this->config['mch_public_cert_path'])){ + throw new PayException('WECHAT_TRANSFER_CONFIG_NOT_EXIST'); + } //这儿的批次信息可能是这儿生成的,但依然需要记录 $order = [ - 'out_batch_no' => $params['transfer_no'] . '',// - 'batch_name' => $params['remark'], - 'batch_remark' => $params['remark'], + 'out_batch_no' => ($to_data['out_batch_no'] ?? '') . '',// + 'batch_name' => $params['remark'] ?? '', + 'batch_remark' => $params['remark'] ?? '', ]; + if($channel == ChannelDict::WEAPP){ + $order['_type'] = 'mini'; + } $transfer_list = $params['transfer_list']; //单笔转账 if (empty($transfer_list)) { $transfer_list = [ [ - 'transfer_no' => $params['transfer_no'] . '1', + 'transfer_no' => $params['transfer_no'], 'money' => (int)$params['money'], 'remark' => $params['remark'], - 'openid' => $params['to_no'] + 'openid' => $open_id ] ]; } @@ -247,7 +259,7 @@ class Wechatpay extends BasePay foreach ($transfer_list as $k => $v) { $item_transfer = [ - 'out_detail_no' => $params['transfer_no'] . $k, + 'out_detail_no' => $params['transfer_no'], 'transfer_amount' => (int)$v['money'], 'transfer_remark' => $v['remark'], 'openid' => $v['openid'], @@ -261,20 +273,38 @@ class Wechatpay extends BasePay } $order['total_amount'] = $total_amount; $order['total_num'] = $total_num; - $result = $this->returnFormat(Pay::wechat()->transfer($order)); - - if (!empty($result['code'])) { + $tran_status_list = [ + 'PROCESSING' => TransferDict::DEALING, + 'ACCEPTED' => TransferDict::DEALING, + 'CLOSED' => TransferDict::FAIL, + 'FINISHED' => TransferDict::SUCCESS, + ]; + try { + $result = $this->returnFormat(Pay::wechat()->transfer($order)); + if (!empty($result['code'])) { // if($result['code'] == 'PARAM_ERROR'){ // throw new PayException(); // }else if($result['code'] == 'INVALID_REQUEST'){ // throw new PayException(); // } - if ($result['code'] == 'INVALID_REQUEST') { - throw new PayException(700010); + if ($result['code'] == 'INVALID_REQUEST') { + throw new PayException(700010); + } + throw new PayException($result['message']); } - throw new PayException($result['message']); + + + return ['batch_id' => $result['batch_id'], 'out_batch_no' => $result['out_batch_no'], 'status' => $tran_status_list[$result['batch_status']]]; + } catch (\Exception $e) { + if($e->getCode() == 9402){ + return ['batch_id' => '', 'out_batch_no' => $order['out_batch_no'], 'status' => TransferDict::DEALING]; + } + if ($e instanceof InvalidResponseException) { + throw new PayException($e->response->all()['message'] ?? ''); + } + throw new PayException($e->getMessage()); } - return ['batch_id' => $result['batch_id'], 'out_batch_no' => $result['out_batch_no'], 'status' => TransferDict::SUCCESS]; + } /** @@ -465,28 +495,35 @@ class Wechatpay extends BasePay * @throws ContainerException * @throws InvalidParamsException */ - public function getTransfer(string $transfer_no, $out_transfer_no = '') + public function getTransfer(string $transfer_no, $out_batch_no = '') { $order = [ - 'out_batch_no' => $out_transfer_no, + 'out_batch_no' => $out_batch_no, 'out_detail_no' => $transfer_no, '_action' => 'transfer', ]; - $result = Pay::wechat()->query($order); - $result = $this->returnFormat($result); - //微信转账状态 - $transfer_status_array = [ - 'INIT' => TransferDict::DEALING,//初始态。 系统转账校验中 - 'WAIT_PAY' => TransferDict::DEALING, - 'PROCESSING' => TransferDict::DEALING, - 'FAIL' => TransferDict::FAIL, - 'SUCCESS' => TransferDict::SUCCESS, - ]; - return [ - 'status' => $transfer_status_array[$result['status']], - 'transfer_no' => $transfer_no - ]; + try { + $result = Pay::wechat()->query($order); + $result = $this->returnFormat($result); + //微信转账状态 + $transfer_status_array = [ + 'INIT' => TransferDict::DEALING,//初始态。 系统转账校验中 + 'WAIT_PAY' => TransferDict::DEALING, + 'PROCESSING' => TransferDict::DEALING, + 'FAIL' => TransferDict::FAIL, + 'SUCCESS' => TransferDict::SUCCESS, + ]; + return [ + 'status' => $transfer_status_array[$result['detail_status']], + 'transfer_no' => $transfer_no + ]; + }catch(Throwable $e){ + return [ + 'status' => TransferDict::DEALING, + 'transfer_no' => $transfer_no + ]; + } }