From 389b3dc61b5c9f2c09571058887902464ac36524 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Tue, 30 Apr 2024 14:14:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../retail/CashierclassController.php | 4 +- app/admin/lists/retail/CashierclassLists.php | 2 +- app/admin/logic/order/CartLogic.php | 6 +- app/admin/logic/retail/CashierclassLogic.php | 9 +- .../logic/setting/pay/PayConfigLogic.php | 2 +- app/api/controller/PayController.php | 63 +++++ .../order/RetailOrderController.php | 19 ++ app/api/lists/merchant/MerchantLists.php | 37 ++- app/api/logic/order/OrderLogic.php | 4 +- app/api/validate/PayValidate.php | 54 ++++ app/common/logic/PayNotifyLogic.php | 74 +++++ app/common/logic/order/RetailOrderLogic.php | 9 +- app/common/model/order/Cart.php | 1 + app/common/model/retail/Cashierinfo.php | 6 +- app/common/service/pay/BasePayService.php | 83 ++++++ app/common/service/pay/WeChatPayService.php | 267 ++++++++++++++++++ .../service/wechat/WeChatConfigService.php | 48 ++++ app/functions.php | 19 +- 18 files changed, 681 insertions(+), 26 deletions(-) create mode 100644 app/api/controller/PayController.php create mode 100644 app/api/validate/PayValidate.php create mode 100644 app/common/logic/PayNotifyLogic.php create mode 100644 app/common/service/pay/BasePayService.php create mode 100644 app/common/service/pay/WeChatPayService.php diff --git a/app/admin/controller/retail/CashierclassController.php b/app/admin/controller/retail/CashierclassController.php index 559be7f..021aa87 100644 --- a/app/admin/controller/retail/CashierclassController.php +++ b/app/admin/controller/retail/CashierclassController.php @@ -26,9 +26,7 @@ class CashierclassController extends BaseAdminController */ public function lists() { - $lists=new CashierclassLists(); - $lists->setSearch(['merchant'=>222]); - return $this->dataLists($lists); + return $this->dataLists(new CashierclassLists()); } diff --git a/app/admin/lists/retail/CashierclassLists.php b/app/admin/lists/retail/CashierclassLists.php index 0598a6e..18794db 100644 --- a/app/admin/lists/retail/CashierclassLists.php +++ b/app/admin/lists/retail/CashierclassLists.php @@ -49,7 +49,7 @@ class CashierclassLists extends BaseAdminDataLists implements ListsSearchInterfa public function lists(): array { return Cashierclass::where($this->searchWhere) - ->field(['id', 'merchant', 'store_id', 'number', 'total', 'deduction_price', 'actual', 'money', 'user', 'pay_type', 'type', 'auditinguser', 'auditingtime']) + ->field(['id', 'merchant', 'store_id', 'number', 'total', 'deduction_price', 'actual', 'money', 'pay_type', 'type', 'auditinguser', 'auditingtime']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select() diff --git a/app/admin/logic/order/CartLogic.php b/app/admin/logic/order/CartLogic.php index f14804c..cf99bbf 100644 --- a/app/admin/logic/order/CartLogic.php +++ b/app/admin/logic/order/CartLogic.php @@ -58,11 +58,7 @@ class CartLogic extends BaseLogic { Db::startTrans(); try { - if($type=='inc'){ - Cart::where(['uid'=>$params['uid'],'goods_id'=>$params['goods_id']])->inc('cart_num',$params['cart_num'])->update(); - }else{ - Cart::where(['uid'=>$params['uid'],'goods_id'=>$params['goods_id']])->dec('cart_num',$params['cart_num'])->update(); - } + Cart::where(['uid'=>$params['uid'],'goods_id'=>$params['goods_id']])->update(['cart_num'=>$params['cart_num']]); Db::commit(); return true; } catch (\Exception $e) { diff --git a/app/admin/logic/retail/CashierclassLogic.php b/app/admin/logic/retail/CashierclassLogic.php index 90d0b31..1baa2bf 100644 --- a/app/admin/logic/retail/CashierclassLogic.php +++ b/app/admin/logic/retail/CashierclassLogic.php @@ -5,6 +5,7 @@ namespace app\admin\logic\retail; use app\common\model\retail\Cashierclass; use app\common\logic\BaseLogic; +use app\common\model\retail\Cashierinfo; use think\facade\Db; @@ -111,6 +112,12 @@ class CashierclassLogic extends BaseLogic */ public static function detail($params): array { - return Cashierclass::findOrEmpty($params['id'])->toArray(); + $find=Cashierclass::where($params)->find(); + if($find){ + $find['goods_list']= Cashierinfo::where('pid',$params['id']) + ->with('goodsName') + ->field('goods,price sell,nums')->select(); + } + return $find->toArray(); } } \ No newline at end of file diff --git a/app/admin/logic/setting/pay/PayConfigLogic.php b/app/admin/logic/setting/pay/PayConfigLogic.php index 40a4b92..be1e0cb 100644 --- a/app/admin/logic/setting/pay/PayConfigLogic.php +++ b/app/admin/logic/setting/pay/PayConfigLogic.php @@ -84,7 +84,7 @@ class PayConfigLogic extends BaseLogic public static function getConfig($params) { $payConfig = PayConfig::find($params['id'])->toArray(); - $payConfig['domain'] = '//'.request()->host();; + $payConfig['domain'] = '//'.request()->host(); return $payConfig; } diff --git a/app/api/controller/PayController.php b/app/api/controller/PayController.php new file mode 100644 index 0000000..a7bcb07 --- /dev/null +++ b/app/api/controller/PayController.php @@ -0,0 +1,63 @@ +post()->goCheck(); + // //订单信息 + // $order = PaymentLogic::getPayOrderInfo($params); + // if (false === $order) { + // return $this->fail(PaymentLogic::getError(), $params); + // } + // //支付流程 + // $redirectUrl = $params['redirect'] ?? '/pages/payment/payment'; + // $result = PaymentLogic::pay($params['pay_way'], $params['from'], $order, $this->userInfo['terminal'], $redirectUrl); + // if (false === $result) { + // return $this->fail(PaymentLogic::getError(), $params); + // } + // return $this->success('', $result); + // } + + + /** + * @notes 小程序支付回调 + * @return \Psr\Http\Message\ResponseInterface + * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException + * @throws \EasyWeChat\Kernel\Exceptions\RuntimeException + * @throws \ReflectionException + * @throws \Throwable + * @author 段誉 + * @date 2023/2/28 14:21 + */ + public function notifyMnp() + { + return (new WeChatPayService(UserTerminalEnum::WECHAT_MMP))->notify(); + } + + + + +} diff --git a/app/api/controller/order/RetailOrderController.php b/app/api/controller/order/RetailOrderController.php index ea42abe..ebbb1a8 100644 --- a/app/api/controller/order/RetailOrderController.php +++ b/app/api/controller/order/RetailOrderController.php @@ -3,6 +3,7 @@ namespace app\api\controller\order; use app\admin\logic\order\CartLogic; +use app\admin\logic\retail\CashierclassLogic; use app\api\logic\order\OrderLogic; use app\api\controller\BaseApiController; use app\api\lists\order\RetailOrderList; @@ -49,6 +50,10 @@ class RetailOrderController extends BaseApiController $user=User::where('id',$this->request->userId)->find(); $cartId = (Array)$this->request->post('cart_id', []); + $mer_id = (Array)$this->request->post('mer_id', 0); + if($mer_id<=0){ + return $this->fail('自提点不能为空'); + } if(count($cartId)>100){ return $this->fail('购物车商品不能超过100个'); } @@ -106,6 +111,20 @@ class RetailOrderController extends BaseApiController } + public function detail(){ + $order_id = (int)$this->request->get('order_id'); + $where=[ + 'id'=>$order_id, + 'uid'=>$this->userId, + ]; + $order=CashierclassLogic::detail($where); + if($order){ + return $this->data($order); + }else{ + return $this->fail('订单不存在'); + } + } + /** * 获取用户常用购买记录 */ diff --git a/app/api/lists/merchant/MerchantLists.php b/app/api/lists/merchant/MerchantLists.php index 216bbde..3ed8b52 100644 --- a/app/api/lists/merchant/MerchantLists.php +++ b/app/api/lists/merchant/MerchantLists.php @@ -7,6 +7,7 @@ use app\admin\lists\BaseAdminDataLists; use app\common\lists\ListsSearchInterface; use app\common\model\merchat\Merchant; use app\common\model\opurchase\OpurchaseGoodsOffer; +use think\facade\Db; /** * 商户列表 @@ -25,6 +26,7 @@ class MerchantLists extends BaseAdminDataLists implements ListsSearchInterface public function setSearch(): array { return [ + '%like%' => ['mer_name'], ]; } @@ -39,12 +41,39 @@ class MerchantLists extends BaseAdminDataLists implements ListsSearchInterface */ public function lists(): array { - + $long=$this->request->get('long'); + $lat=$this->request->get('lat'); + $order=['mer_id' => 'desc']; + if($long&&$lat){ + $order=Db::raw("(2 * 6378.137 * ASIN( + SQRT( + POW( SIN( PI( ) * ( $long- `long` ) / 360 ), 2 ) + COS( PI( ) * $lat / 180 ) * COS( `lat` * PI( ) / 180 ) * POW( SIN( PI( ) * ( $lat- `lat` ) / 360 ), 2 ) + ) + ) + ) ASC "); + } return Merchant::where($this->searchWhere) - ->field('mer_id,mer_name') + ->field('mer_id,mer_name,long,lat,service_phone') ->limit($this->limitOffset, $this->limitLength) - ->order(['mer_id' => 'desc']) + ->order($order) ->select() + ->each(function ($item) use($long,$lat){ + if($long&&$lat){ + $distance = getDistance($lat, $long, $item['lat'], $item['long']); + if ($distance < 0.9) { + $distance = max(bcmul($distance, 1000, 0), 1).'m'; + if ($distance == '1m') { + $distance = '100m以内'; + } + } else { + $distance .= 'km'; + } + $item['distance']=$distance; + }else{ + $item['distance']=''; + } + + }) ->toArray(); } @@ -56,7 +85,7 @@ class MerchantLists extends BaseAdminDataLists implements ListsSearchInterface */ public function count(): int { - return OpurchaseGoodsOffer::where($this->searchWhere)->count(); + return Merchant::where($this->searchWhere)->count(); } } \ No newline at end of file diff --git a/app/api/logic/order/OrderLogic.php b/app/api/logic/order/OrderLogic.php index beff21b..2a58a72 100644 --- a/app/api/logic/order/OrderLogic.php +++ b/app/api/logic/order/OrderLogic.php @@ -71,7 +71,7 @@ class OrderLogic extends BaseLogic $orderInfo = self::cartIdByOrderInfo($cartId, $addressId, $user, $params); $_order = $orderInfo['order']; $_order['deduction_price'] = 0; - $_order['merchant'] = 0; + $_order['merchant'] = $params['mer_id']; $_order['uid'] = request()->userId; $_order['money'] = 0; $_order['user'] = request()->userId; @@ -85,7 +85,7 @@ class OrderLogic extends BaseLogic $goods_list = $orderInfo['cart_list']; foreach ($goods_list as $k => $v) { $goods_list[$k]['pid'] = $order->id; - $goods_list[$k]['merchant'] = 0; + $goods_list[$k]['merchant'] = $params['mer_id']; $goods_list[$k]['uid'] = request()->userId; $goods_list[$k]['room'] = 0; $goods_list[$k]['discount'] = 0; diff --git a/app/api/validate/PayValidate.php b/app/api/validate/PayValidate.php new file mode 100644 index 0000000..87d2c40 --- /dev/null +++ b/app/api/validate/PayValidate.php @@ -0,0 +1,54 @@ + 'require', + 'pay_way' => 'require|in:' . PayEnum::BALANCE_PAY . ',' . PayEnum::WECHAT_PAY . ',' . PayEnum::ALIPAY, + 'order_id' => 'require' + ]; + + + protected $message = [ + 'from.require' => '参数缺失', + 'pay_way.require' => '支付方式参数缺失', + 'pay_way.in' => '支付方式参数错误', + 'order_id.require' => '订单参数缺失' + ]; + + + /** + * @notes 支付方式场景 + * @return PayValidate + * @author 段誉 + * @date 2023/2/24 17:43 + */ + public function scenePayway() + { + return $this->only(['from', 'order_id']); + } + + + /** + * @notes 支付状态 + * @return PayValidate + * @author 段誉 + * @date 2023/3/1 16:17 + */ + public function sceneStatus() + { + return $this->only(['from', 'order_id']); + } + + + +} \ No newline at end of file diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php new file mode 100644 index 0000000..d538f17 --- /dev/null +++ b/app/common/logic/PayNotifyLogic.php @@ -0,0 +1,74 @@ +getFile(), + $e->getLine(), + $e->getMessage() + ])); + self::setError($e->getMessage()); + return $e->getMessage(); + } + } + + + /** + * @notes 零售回调 + * @param $orderSn + * @param array $extra + * @author 段誉 + * @date 2023/2/27 15:28 + */ + public static function cashierclass($orderSn, $extra = []) + { + + $order = Cashierclass::where('number', $orderSn)->findOrEmpty(); + $order->money = bcdiv($extra['amount']['payer_total'],100,2); + $order->paid = 1; + $order->save(); + if ($order['cart_id']) { + if (!is_array($order['cart_id'])) { + $cart_arr = explode(',', $order['cart_id']); + Cart::whereIn('cart_id', $cart_arr)->update(['is_pay' => 1]); + } else { + Cart::whereIn('cart_id', $order['cart_id'])->update(['is_pay' => 1]); + } + } + + // 更新充值订单状态 + // $order->transaction_id = $extra['transaction_id']; + $order->paid = PayEnum::ISPAID; + $order->save(); + } + + +} diff --git a/app/common/logic/order/RetailOrderLogic.php b/app/common/logic/order/RetailOrderLogic.php index cddb812..3540136 100644 --- a/app/common/logic/order/RetailOrderLogic.php +++ b/app/common/logic/order/RetailOrderLogic.php @@ -116,10 +116,13 @@ class RetailOrderLogic extends BaseLogic public static function frequentlyPurchase($params) { try { - $goods_id = Cashierinfo::where('uid', Request()->uid)->page($params['page'])->limit(50)->column('goods_id'); + $goods_id = Cashierinfo::where('uid', Request()->userId)->page($params['page_no'])->limit(50)->column('goods'); + if(!$goods_id){ + return []; + } $goods_arr = array_unique($goods_id); - $select = Goods::where('id', 'in', $goods_arr)->field('id,name,sell,imgs')->select(); - return $select; + $select = Goods::where('id', 'in', $goods_arr)->with('unitName')->field('id,name,sell,imgs,unit')->select(); + return $select->toArray(); } catch (\Exception $e) { self::setError($e->getMessage()); return false; diff --git a/app/common/model/order/Cart.php b/app/common/model/order/Cart.php index b67ba78..59b12b4 100644 --- a/app/common/model/order/Cart.php +++ b/app/common/model/order/Cart.php @@ -15,6 +15,7 @@ use think\model\concern\SoftDelete; class Cart extends BaseModel { use SoftDelete; + protected $pk = 'cart_id'; protected $name = 'cart'; protected $deleteTime = 'delete_time'; diff --git a/app/common/model/retail/Cashierinfo.php b/app/common/model/retail/Cashierinfo.php index a4fe97d..ae47ad0 100644 --- a/app/common/model/retail/Cashierinfo.php +++ b/app/common/model/retail/Cashierinfo.php @@ -4,6 +4,7 @@ namespace app\common\model\retail; use app\common\model\BaseModel; +use app\common\model\goods\Goods; use think\model\concern\SoftDelete; @@ -18,5 +19,8 @@ class Cashierinfo extends BaseModel protected $name = 'cashierinfo'; protected $deleteTime = 'delete_time'; - + public function goodsName() + { + return $this->hasOne(Goods::class,'id','goods')->bind(['class_name'=>'name']); + } } \ No newline at end of file diff --git a/app/common/service/pay/BasePayService.php b/app/common/service/pay/BasePayService.php new file mode 100644 index 0000000..95260fa --- /dev/null +++ b/app/common/service/pay/BasePayService.php @@ -0,0 +1,83 @@ +error; + } + + + /** + * @notes 设置错误信息 + * @param $error + * @author 段誉 + * @date 2021/7/21 18:20 + */ + public function setError($error) + { + $this->error = $error; + } + + + /** + * @notes 是否存在错误 + * @return bool + * @author 段誉 + * @date 2021/7/21 18:32 + */ + public function hasError() + { + return !empty($this->error); + } + + + /** + * @notes 设置状态码 + * @param $code + * @author 段誉 + * @date 2021/7/28 17:05 + */ + public function setReturnCode($code) + { + $this->returnCode = $code; + } + + + /** + * @notes 特殊场景返回指定状态码,默认为0 + * @return int + * @author 段誉 + * @date 2021/7/28 15:14 + */ + public function getReturnCode() + { + return $this->returnCode; + } + +} \ No newline at end of file diff --git a/app/common/service/pay/WeChatPayService.php b/app/common/service/pay/WeChatPayService.php new file mode 100644 index 0000000..33c124b --- /dev/null +++ b/app/common/service/pay/WeChatPayService.php @@ -0,0 +1,267 @@ +terminal = $terminal; + $this->config = WeChatConfigService::getPayConfigByTerminal($terminal); + $this->app = new Application($this->config); + if ($userId !== null) { + $this->auth = UserAuth::where(['user_id' => $userId, 'terminal' => $terminal])->findOrEmpty(); + } + } + + + /** + * @notes 发起微信支付统一下单 + * @param $from + * @param $order + * @return array|false|string + * @author 段誉 + * @date 2021/8/4 15:05 + */ + public function pay($from, $order) + { + try { + switch ($this->terminal) { + case UserTerminalEnum::WECHAT_MMP: + $config = WeChatConfigService::getMnpConfig(); + $result = $this->jsapiPay($from, $order, $config['app_id']); + break; + default: + throw new \Exception('支付方式错误'); + } + + return [ + 'config' => $result, + 'pay_way' => PayEnum::WECHAT_PAY + ]; + } catch (\Exception $e) { + $this->setError($e->getMessage()); + return false; + } + } + + + /** + * @notes jsapiPay + * @param $from + * @param $order + * @param $appId + * @return mixed + * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException + * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException + * @author 段誉 + * @date 2023/2/28 12:12 + */ + public function jsapiPay($from, $order, $appId) + { + $response = $this->app->getClient()->postJson("v3/pay/transactions/jsapi", [ + "appid" => $appId, + "mchid" => $this->config['mch_id'], + "description" => $this->payDesc($from), + "out_trade_no" => $order['pay_sn'], + "notify_url" => $this->config['notify_url'], + "amount" => [ + "total" => intval($order['order_amount'] * 100), + ], + "payer" => [ + "openid" => $this->auth['openid'] + ], + 'attach' => $from + ]); + + $result = $response->toArray(false); + $this->checkResultFail($result); + return $this->getPrepayConfig($result['prepay_id'], $appId); + } + + + + /** + * @notes 退款 + * @param array $refundData + * @return mixed + * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException + * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException + * @author 段誉 + * @date 2023/2/28 16:53 + */ + public function refund(array $refundData) + { + $response = $this->app->getClient()->postJson('v3/refund/domestic/refunds', [ + 'transaction_id' => $refundData['transaction_id'], + 'out_refund_no' => $refundData['refund_sn'], + 'amount' => [ + 'refund' => intval($refundData['refund_amount'] * 100), + 'total' => intval($refundData['total_amount'] * 100), + 'currency' => 'CNY', + ] + ]); + $result = $response->toArray(false); + $this->checkResultFail($result); + return $result; + } + + + /** + * @notes 查询退款 + * @param $refundSn + * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException + * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException + * @author 段誉 + * @date 2023/3/1 11:16 + */ + public function queryRefund($refundSn) + { + $response = $this->app->getClient()->get("v3/refund/domestic/refunds/{$refundSn}"); + return $response->toArray(false); + } + + + /** + * @notes 支付描述 + * @param $from + * @return string + * @author 段誉 + * @date 2023/2/27 17:54 + */ + public function payDesc($from) + { + $desc = [ + 'order' => '商品', + 'recharge' => '充值', + ]; + return $desc[$from] ?? '商品'; + } + + + /** + * @notes 捕获错误 + * @param $result + * @throws \Exception + * @author 段誉 + * @date 2023/2/28 12:09 + */ + public function checkResultFail($result) + { + if (!empty($result['code']) || !empty($result['message'])) { + throw new \Exception('微信:'. $result['code'] . '-' . $result['message']); + } + } + + + /** + * @notes 预支付配置 + * @param $prepayId + * @param $appId + * @return mixed[] + * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException + * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException + * @author 段誉 + * @date 2023/2/28 17:38 + */ + public function getPrepayConfig($prepayId, $appId) + { + return $this->app->getUtils()->buildBridgeConfig($prepayId, $appId); + } + + + /** + * @notes 支付回调 + * @return \Psr\Http\Message\ResponseInterface + * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException + * @throws \EasyWeChat\Kernel\Exceptions\RuntimeException + * @throws \ReflectionException + * @throws \Throwable + * @author 段誉 + * @date 2023/2/28 14:20 + */ + public function notify() + { + $server = $this->app->getServer(); + // 支付通知 + $server->handlePaid(function (Message $message) { + if ($message['trade_state'] === 'SUCCESS') { + $extra['transaction_id'] = $message['transaction_id']; + $attach = $message['attach']; + $message['out_trade_no'] = mb_substr($message['out_trade_no'], 0, 18); + switch ($attach) { + case 'cashierclass': + $order = Cashierclass::where(['number' => $message['out_trade_no']])->findOrEmpty(); + if($order->isEmpty() || $order->paid == PayEnum::ISPAID) { + return true; + } + PayNotifyLogic::handle('cashierclass', $message['out_trade_no'], $extra); + break; + } + } + return true; + }); + + // 退款通知 + $server->handleRefunded(function (Message $message) { + return true; + }); + return $server->serve(); + } + + + + + +} \ No newline at end of file diff --git a/app/common/service/wechat/WeChatConfigService.php b/app/common/service/wechat/WeChatConfigService.php index f4598a7..bc40813 100644 --- a/app/common/service/wechat/WeChatConfigService.php +++ b/app/common/service/wechat/WeChatConfigService.php @@ -75,6 +75,54 @@ class WeChatConfigService ]; } + + /** + * @notes 根据终端获取支付配置 + * @param $terminal + * @return array + * @author 段誉 + * @date 2023/2/27 15:45 + */ + public static function getPayConfigByTerminal($terminal) + { + $notifyUrl ='//'.request()->host().'/pay/notifyMnp'; + + + $pay = PayConfig::where(['pay_way' => PayEnum::WECHAT_PAY])->findOrEmpty()->toArray(); + //判断是否已经存在证书文件夹,不存在则新建 + if (!file_exists(runtime_path() . '/cert')) { + mkdir(runtime_path() . '/cert', 0775, true); + } + //写入文件 + $apiclientCert = $pay['config']['apiclient_cert'] ?? ''; + $apiclientKey = $pay['config']['apiclient_key'] ?? ''; + + $certPath = runtime_path(). '/cert/' . md5($apiclientCert) . '.pem'; + $keyPath =runtime_path() . '/cert/' . md5($apiclientKey) . '.pem'; + + if (!empty($apiclientCert) && !file_exists($certPath)) { + static::setCert($certPath, trim($apiclientCert)); + } + if (!empty($apiclientKey) && !file_exists($keyPath)) { + static::setCert($keyPath, trim($apiclientKey)); + } + + return [ + // 商户号 + 'mch_id' => $pay['config']['mch_id'] ?? '', + // 商户证书 + 'private_key' => $keyPath, + 'certificate' => $certPath, + // v3 API 秘钥 + 'secret_key' => $pay['config']['pay_sign_key'] ?? '', + 'notify_url' => $notifyUrl, + 'http' => [ + 'throw' => true, // 状态码非 200、300 时是否抛出异常,默认为开启 + 'timeout' => 5.0, + ] + ]; + } + /** * @notes 临时写入证书 * @param $path diff --git a/app/functions.php b/app/functions.php index adb1293..3640f33 100644 --- a/app/functions.php +++ b/app/functions.php @@ -240,9 +240,18 @@ function download_file($url, $saveDir, $fileName) return $fileSrc; } -function halt(String|Array|Float|Int $trage) -{ - $str = is_array($trage) ? var_export($trage,1) : trim($trage); - $hears = ['Content-Type' => 'text/html;charset=utf-8']; - return new \support\Response('200',$hears,'
'.$str);
+if (!function_exists('getDistance')) {
+
+    function getDistance($lat1, $lng1, $lat2, $lng2)
+    {
+        //将角度转为狐度
+        $radLat1 = deg2rad($lat1); //deg2rad()函数将角度转换为弧度
+        $radLat2 = deg2rad($lat2);
+        $radLng1 = deg2rad($lng1);
+        $radLng2 = deg2rad($lng2);
+        $a = $radLat1 - $radLat2;
+        $b = $radLng1 - $radLng2;
+        $s = 2 * asin(sqrt(pow(sin($a / 2), 2) + cos($radLat1) * cos($radLat2) * pow(sin($b / 2), 2))) * 6371;
+        return round($s, 1);
+    }
 }
\ No newline at end of file