wesmiler 2 months ago
parent
commit
7f7c140fa4

+ 1 - 1
app/Http/Controllers/Admin/Backend.php

@@ -63,7 +63,7 @@ class Backend extends BaseController
             $token = $request->headers->get('Authorization');
             $token = str_replace("Bearer ", null, $token);
             // JWT解密token
-            $jwt = new Jwt('jwt_admin');
+            $jwt = new Jwt();
             $userId = $jwt->verifyToken($token);
 
             // 登录验证

+ 1 - 1
app/Services/Common/LoginService.php

@@ -147,7 +147,7 @@ class LoginService extends BaseService
         ActionLogModel::record();
 
         // JWT生成token
-        $jwt = new Jwt('jwt_admin');
+        $jwt = new Jwt();
         $token = $jwt->getToken($info['id']);
 
         // 结果返回

+ 62 - 0
app/Services/Common/PayOrdersService.php

@@ -221,6 +221,68 @@ class PayOrdersService extends BaseService
     }
 
     /**
+     * 已支付充值失败退款失败订单
+     * @return array|mixed
+     */
+    public function getFailedOrderList()
+    {
+        $cacheKey = "caches:orders:failedList";
+        $datas = RedisService::get($cacheKey);
+        if ($datas) {
+            return $datas;
+        }
+
+        $datas = $this->model->where(['refund_status'=>3,'status'=>5,'mark' => 1])
+            ->select(['id', 'order_no', 'transaction_id', 'pay_total as money', 'status'])
+            ->orderBy('id', 'desc')
+            ->limit(500)
+            ->get()
+            ->keyBy('order_no');
+        $datas = $datas ? $datas->toArray() : [];
+        if ($datas) {
+            $datas = array_chunk($datas, 100);
+            RedisService::set($cacheKey, $datas, rand(20, 30));
+        }
+
+        return $datas;
+    }
+
+    /**
+     * 充值订单退款(补充处理)
+     * @param $orders
+     * @return array
+     * @throws \Yansongda\Pay\Exception\ContainerException
+     * @throws \Yansongda\Pay\Exception\InvalidParamsException
+     * @throws \Yansongda\Pay\Exception\ServiceNotFoundException
+     */
+    public function failedOrderRefund($orders)
+    {
+        $success = [];
+        if ($orders) {
+            foreach ($orders as $order) {
+                $total = isset($order['money']) ? $order['money'] : 0;
+                $refundStatus = PaymentService::make()->refund($order, 'pay');
+                $updateData = ['refund_status' => $refundStatus ? 1 : 3, 'status' => 5, 'failed_remark' => '充值失败原路退款','refund_remark'=>PaymentService::make()->getError(), 'refund_money' => $refundStatus ? $total : 0,'refund_at'=>date('Y-m-d H:i:s'), 'update_time' => time()];
+                if (!PayOrdersModel::where(['id' => $order['id']])->update($updateData)) {
+                    $errors[$order['order_no']] = '充值失败退款处理失败';
+                } else {
+                    $success[$order['order_no']] = "退款{$total}成功";
+                    $errors[$order['order_no']] = $refundStatus ? '充值失败原路退款' : '充值失败退款失败';
+                }
+
+                sleep(2);
+            }
+        }
+
+        if($success){
+            RedisService::clear("caches:orders:failedList");
+        }
+
+        $this->error = '充值订单退款处理成功';
+        return ['success' => $success, 'errors' => $errors];
+    }
+
+    /**
      * 验证订单状态
      * @param $orders
      * @return array

+ 0 - 169
app/Services/DyrPayService.php

@@ -1,169 +0,0 @@
-<?php
-// +----------------------------------------------------------------------
-// | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
-// +----------------------------------------------------------------------
-// | 版权所有 2017~2021 LARAVEL研发中心
-// +----------------------------------------------------------------------
-// | 官方网站: http://www.laravel.cn
-// +----------------------------------------------------------------------
-// | Author: laravel开发员 <laravel.qq.com>
-// +----------------------------------------------------------------------
-
-namespace App\Services;
-
-/**
- * 生活充值接口管理-服务类
- * @author laravel开发员
- * @since 2020/11/11
- * @package App\Services
- */
-class DyrPayService extends BaseService
-{
-    // 静态对象
-    protected static $instance = null;
-    protected $apiUrl = 'http://1.huichikeji.cn/yrapi.php';
-    protected $apiKey = '';
-    protected $apiClientId = '';
-    protected $apiUrls = [
-        'recharge' => '/index/recharge',
-        'query' => '/index/check',
-    ];
-
-    public function __construct()
-    {
-        $apiUrl = ConfigService::make()->getConfigByCode('pay_api_url');
-        $this->apiUrl = $apiUrl ? $apiUrl : $this->apiUrl;
-        $this->apiKey = ConfigService::make()->getConfigByCode('pay_api_key');
-        $this->apiClientId = ConfigService::make()->getConfigByCode('pay_ userid');
-    }
-
-    /**
-     * 静态入口
-     */
-    public static function make()
-    {
-        if (!self::$instance) {
-            self::$instance = new static();
-        }
-
-        return self::$instance;
-    }
-
-
-    /**
-     * 充值
-     * @param $no 单号
-     * @param string $account // 充值账号
-     * @param string $productId 产品 ID
-     * @param string $amount 充值面值
-     * @return bool
-     */
-    public function recharge($no, $account, $productId, $amount, $params=[])
-    {
-        if (empty($this->apiUrl) || empty($this->apiKey) || empty($this->apiClientId)) {
-            $this->error = '接口参数未配置';
-            return false;
-        }
-
-        $cacheKey = "caches:dryPay:{$no}_{$productId}_{$account}";
-        if (RedisService::get($cacheKey . '_lock')) {
-            $this->error = '充值处理中~';
-            return false;
-        }
-
-        $param = [
-            'userid' => $this->apiClientId,             // 商户ID
-            'product_id' => trim($productId),          // 产品ID
-            'out_trade_num' => $no,     // 单号
-            'amount' => $amount,                // 金额
-            'mobile' => $account,                // 手机号或账号
-            'notify_url' => url('/api/dry/notify/' . $productId),            // 回调地址
-        ];
-        if(isset($params['price']) && $params['price']){
-            $param['price'] = floatval($params['price']);
-        }
-        if(isset($params['ytype']) && $params['ytype']){
-            $param['ytype'] = intval($params['ytype']);
-        }
-
-        if(isset($params['id_card_no']) && $params['id_card_no']){
-            $param['id_card_no'] = $params['id_card_no'];
-        }
-
-        if(isset($params['area']) && $params['area']){
-            $param['area'] = $params['area'];
-        }
-
-        if(isset($params['city']) && $params['city']){
-            $param['city'] = $params['city'];
-        }
-
-        //请求参数
-        $param['sign'] = $this->makeSign($param);
-        $url = $this->apiUrl.$this->apiUrls['recharge'];
-        $result = httpRequest($url, $param, 'post', '', 5);
-        $this->saveLog($cacheKey,  ['url'=>$url,'param'=>$param,'result'=>$result]);
-        return $result;
-    }
-
-    /**
-     * 查询订单
-     * @param $nos 查询单号
-     * @return bool
-     */
-    public function query($nos)
-    {
-        if (empty($this->apiUrl) || empty($this->apiKey) || empty($this->apiClientId)) {
-            $this->error = '接口参数未配置';
-            return false;
-        }
-
-        $cacheKey = "caches:dryPay:queryOrder:".md5($nos);
-        if (RedisService::get($cacheKey . '_lock')) {
-            $this->error = '充值处理中~';
-            return false;
-        }
-
-        $param = [
-            'userid' => $this->apiClientId,             // 商户ID
-            'out_trade_nums' => $nos,     // 单号
-        ];
-
-        //请求参数
-        $param['sign'] = $this->makeSign($param);
-        $url = $this->apiUrl.$this->apiUrls['query'];
-        $result = httpRequest($url, $param, 'post', '', 5);
-        $this->saveLog($cacheKey,  ['url'=>$url,'param'=>$param,'result'=>$result]);
-        return $result;
-    }
-
-    /**
-     * 日志
-     * @param $key
-     * @param $data
-     */
-    public function saveLog($key, $data)
-    {
-        if(env('APP_DEBUG')){
-            RedisService::set($key,$data, 7200);
-        }
-    }
-
-    /**
-     * 生成签名
-     * @param $param
-     * @return string
-     */
-    public function makeSign($param,$type=1)
-    {
-        // 字典排序
-        ksort($param);
-
-        // 拼接签名串
-        $param = $type==2?urldecode(http_build_query($param)) : http_build_query($param);
-        $sign_str =  $param . '&apikey=' . $this->apiKey;
-        // 签名
-        $sign = strtoupper(md5($type==2? $sign_str : urldecode($sign_str)));
-        return $sign;
-    }
-}

+ 0 - 150
app/Services/SmsService.php

@@ -1,150 +0,0 @@
-<?php
-// +----------------------------------------------------------------------
-// | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
-// +----------------------------------------------------------------------
-// | 版权所有 2017~2021 LARAVEL研发中心
-// +----------------------------------------------------------------------
-// | 官方网站: http://www.laravel.cn
-// +----------------------------------------------------------------------
-// | Author: laravel开发员 <laravel.qq.com>
-// +----------------------------------------------------------------------
-
-namespace App\Services;
-
-use AlibabaCloud\Tea\Exception\TeaUnableRetryError;
-use AlibabaCloud\SDK\Dysmsapi\V20170525\Dysmsapi;
-use Darabonba\OpenApi\Models\Config;
-use AlibabaCloud\SDK\Dysmsapi\V20170525\Models\SendSmsRequest;
-use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
-
-/**
- * 阿里云短信管理-服务类
- * @author laravel开发员
- * @since 2020/11/11
- * Class SmsService
- * @package App\Services
- */
-class SmsService extends BaseService
-{
-    // 静态对象
-    protected static $instance = null;
-
-    /**
-     * 静态入口
-     * @return SmsService|static|null
-     */
-    public static function make(){
-        if(!self::$instance){
-            self::$instance = new static();
-        }
-
-        return self::$instance;
-    }
-
-    /**
-     * @param $accessKeyId
-     * @param $accessKeySecret
-     * @return mixed
-     */
-    public function createClient($accessKeyId, $accessKeySecret, $endpoint){
-        $config = new Config([
-            // 必填,您的 AccessKey ID
-            "accessKeyId" => $accessKeyId,
-            // 必填,您的 AccessKey Secret
-            "accessKeySecret" => $accessKeySecret
-        ]);
-        // 访问的域名
-        $config->endpoint = $endpoint;
-        return new Dysmsapi($config);
-    }
-
-    /**
-     * 发送短信验证码
-     * @param $mobile
-     * @param string $type
-     * @return bool
-     */
-    public function send($mobile, $type='login')
-    {
-        $cacheKey = "caches:sms:{$mobile}:{$type}";
-        if(RedisService::get($cacheKey.'_lock')){
-            $this->error = '2011';
-            return false;
-        }
-
-        $config = ConfigService::make()->getConfigOptionByGroup(2);
-        $accessKey = isset($config['ali_sms_access_key'])? trim($config['ali_sms_access_key']) : '';
-        $accessSecret = isset($config['ali_sms_access_secret'])? trim($config['ali_sms_access_secret']) : '';
-        $smsTemplateCode = isset($config['ali_sms_template_code'])? trim($config['ali_sms_template_code']) : '';
-        $smsSignName = isset($config['ali_sms_sign_name'])? trim($config['ali_sms_sign_name']) : '';
-        $endpoint = isset($config['sms_endpoint'])? trim($config['sms_endpoint']) : '';
-        if(empty($accessKey) || empty($accessSecret) || empty($smsTemplateCode) || empty($smsSignName) || empty($endpoint)){
-            $this->error = 2012;
-            return false;
-        }
-
-        // 发送逻辑
-        $code = rand(1000,9999);
-        $client = $this->createClient($accessKey, $accessSecret, $endpoint);
-        $request = new SendSmsRequest();
-        $request->phoneNumbers = $mobile;
-        $request->signName = $smsSignName;
-        $request->templateCode = $smsTemplateCode;
-        $request->templateParam = json_encode(['code'=> $code], 256);
-        $runtime = new RuntimeOptions();
-        $runtime->maxIdleConns = 5;
-        $runtime->connectTimeout = 10000;
-        $runtime->readTimeout = 10000;
-        try {
-            // 复制代码运行请自行打印 API 的返回值
-            $response = $client->sendSms($request, $runtime);
-            $resultCode = $response->body->code;
-            if($resultCode == 'OK'){
-                $this->error = 2005;
-                RedisService::set($cacheKey,['code'=> $code,'mobile'=>$mobile,'bizId'=>$response->body->bizId,'date'=> date('Y-m-d H:i:s')], 600);
-                return true;
-            }else{
-                $this->error = '发送失败:'.$response->body->message;
-                RedisService::set($cacheKey.'_fail', ['mobile'=> $mobile,'config'=>$config,'error'=>$this->error,'date'=> date('Y-m-d H:i:s')], 6 * 3600);
-                return false;
-            }
-        } catch (TeaUnableRetryError  $e){
-            //$date = date('Y-m-d H:i:s');
-            //logger()->error("【{$date} SMS短信验证码】发送失败:".$e->getMessage());
-            RedisService::set($cacheKey.'_error', ['mobile'=> $mobile,'config'=>$config,'error'=>$e->getMessage()], 6 * 3600);
-        }
-
-        $this->error = 2006;
-        return false;
-    }
-
-    /**
-     * 短信验证码验证
-     * @param string $mobile 手机号
-     * @param string $code 当前验证码
-     * @param string $type 验证码场景类型,login-登录,reg-注册
-     * @return bool
-     */
-    public function check($mobile, $code, $type='login')
-    {
-        // 测试
-        if(env('SMS_DEBUG') && $code == env('SMS_CODE','1100')){
-            return true;
-        }
-
-        $cacheKey = "caches:sms:{$mobile}:{$type}";
-        $data = RedisService::get($cacheKey);
-        $smsCode = isset($data['code'])? $data['code'] : '';
-        if(empty($data) || empty($smsCode)){
-            $this->error = '2012';
-            return false;
-        }
-
-        if($smsCode != $code){
-            $this->error = '2013';
-            return false;
-        }
-
-        return true;
-    }
-}

+ 0 - 129
app/Services/WechatService.php

@@ -1,129 +0,0 @@
-<?php
-// +----------------------------------------------------------------------
-// | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
-// +----------------------------------------------------------------------
-// | 版权所有 2017~2021 LARAVEL研发中心
-// +----------------------------------------------------------------------
-// | 官方网站: http://www.laravel.cn
-// +----------------------------------------------------------------------
-// | Author: laravel开发员 <laravel.qq.com>
-// +----------------------------------------------------------------------
-
-namespace App\Services;
-
-use App\Services\Api\MemberService;
-use Dotenv\Dotenv;
-use Laravel\Socialite\Facades\Socialite;
-use SocialiteProviders\WeixinWeb\Provider;
-
-/**
- * 微信服务管理-服务类
- * @author laravel开发员
- * @since 2020/11/11
- * Class WechatService
- * @package App\Services
- */
-class WechatService extends BaseService
-{
-    // 静态对象
-    protected static $instance = null;
-
-
-    public function __construct()
-    {
-        $wxAppid = ConfigService::make()->getConfigByCode('wechat_appid');
-        $wxAppSecret = ConfigService::make()->getConfigByCode('wechat_appsecret');
-        // 配置更新
-        if($wxAppid != env('WEIXIN_APP_ID') || $wxAppSecret != env('WEIXIN_SECRET')){
-            $env = Dotenv::createArrayBacked(base_path())->load();
-            $env['WEIXIN_APP_ID'] = $wxAppid;
-            $env['WEIXIN_SECRET'] = $wxAppSecret;
-            $envStr = '';
-            foreach($env as $k => $v){
-                $envStr .= $k.'='.$v."\n";
-            }
-
-            file_put_contents(base_path().'/.env', $envStr);
-        }
-    }
-
-    /**
-     * 静态入口
-     * @return WechatService|static|null
-     */
-    public static function make()
-    {
-        if (!self::$instance) {
-            self::$instance = new static();
-        }
-
-        return self::$instance;
-    }
-
-    /**
-     * 微信授权登录
-     * @param array $params
-     * @return mixed
-     */
-    public function auth($params=[])
-    {
-        $openid = isset($params['openid'])? $params['openid'] : '';
-        $referrer = isset($params['invite_code'])? $params['invite_code'] : '';
-        $accessToken = isset($params['access_token'])? $params['access_token'] : '';
-        if(empty($openid) || empty($accessToken)){
-            $this->error = '2016';
-            return false;
-        }
-
-        // 获取微信用户信息
-        $wechatInfo = $this->getUserInfo($openid, $accessToken);
-        RedisService::set("caches:wechat:{$openid}:temp", ['params'=> $params,'user'=>$wechatInfo], 7200);
-
-        // 注册
-        $appSources = isset($params['app_sources'])? $params['app_sources'] : '';
-        $wechatInfo['openid'] = $openid;
-        $wechatInfo['mobile'] = isset($params['mobile'])? trim($params['mobile']) : '';
-        $wechatInfo['device'] = $appSources=='android'? 2 : 1;
-        $wechatInfo['invite_code'] = $referrer;
-        if(!$result = MemberService::make()->loginByWechat($wechatInfo)){
-            $this->error = MemberService::make()->getError();
-            return false;
-        }else{
-            return $result;
-        }
-    }
-
-    /**
-     * 微信用户信息
-     * @param $openid
-     * @param $accessToken
-     * @param false $refresh 是否强制刷新
-     * @return array|mixed
-     */
-    public function getUserInfo($openid, $accessToken, $refresh = false)
-    {
-        // 获取授权信息
-        $cacheKey = "caches:wechat:{$openid}:info_".md5($accessToken);
-        $data = RedisService::get($cacheKey);
-        $info = isset($data['info'])? $data['info'] : [];
-        if($info && !$refresh){
-            return $info;
-        }
-
-        try {
-            $driver = Socialite::with('weixin');
-            $driver->setOpenId($openid);
-            $wechatInfo = $driver->userFromToken($accessToken);
-            if ($wechatInfo) {
-                RedisService::set($cacheKey, ['openid' => $openid, 'access_token' => $accessToken, 'info' => $wechatInfo], rand(3600, 7200));
-            }
-            return $wechatInfo;
-        }catch (\Exception $exception){
-            RedisService::set($cacheKey.'_error', ['openid' => $openid, 'access_token' => $accessToken, 'error' => $exception->getMessage()], rand(3600, 7200));
-            return [];
-        }
-
-    }
-
-
-}