hrjy 2 years ago
parent
commit
5a0cdef53b

+ 1 - 1
app/admin/controller/setting/SystemConfig.php

@@ -368,7 +368,7 @@ class SystemConfig extends AuthController
     public function file_upload()
     {
         $upload = new Upload('local');
-        $res = $upload->to('config/file')->validate()->move($this->request->param('file', 'file'));
+        $res = $upload->to('config/file')->move($this->request->param('file', 'file'));
         if ($res === false) return Json::fail($upload->getError());
         return Json::successful('上传成功!', ['filePath' => $res->filePath]);
     }

+ 33 - 0
app/api/controller/AlipayController.php

@@ -0,0 +1,33 @@
+<?php
+
+namespace app\api\controller;
+
+use app\Request;
+use crmeb\repositories\PaymentRepositories;
+use crmeb\services\AlipayService;
+use crmeb\services\SystemConfigService;
+use crmeb\utils\Hook;
+
+class AlipayController
+{
+    public function Notify()
+    {
+        $alipay = SystemConfigService::more(['alipay_app_id', 'alipay_pub_key', 'alipay_private_key', 'alipay_key']);
+        $Pay = new AlipayService();
+        $Pay->setAlipayPublicKey($alipay['alipay_key']);
+        $result = $Pay->rsaCheck($_POST, $_POST['sign_type']);
+        if ($result === true && $_POST['trade_status'] == 'TRADE_SUCCESS') {
+            $out_trade_no = input('out_trade_no', '');
+            if (($count = strpos(input('out_trade_no'), '_')) !== false) {
+                $out_trade_no = substr(input('out_trade_no'), $count + 1);
+            }
+            parse_str(input('passback_params'), $attach);
+            (new Hook(PaymentRepositories::class, 'wechat'))->listen($attach['attach'], $out_trade_no);
+            echo 'success';
+            exit();
+        } else {
+            echo 'error';
+            exit();
+        }
+    }
+}

+ 22 - 0
app/api/controller/PublicController.php

@@ -16,6 +16,7 @@ use app\models\user\UserLevel;
 use app\models\user\WechatUser;
 use app\Request;
 use crmeb\services\CacheService;
+use crmeb\services\SystemConfigService;
 use crmeb\services\UtilService;
 use crmeb\services\workerman\ChannelService;
 use think\db\exception\DataNotFoundException;
@@ -337,4 +338,25 @@ class PublicController
         return app('json')->successful($list);
     }
 
+    /**
+     * 版本更新
+     * @param Request $request
+     * @return void
+     */
+    public function version(Request $request)
+    {
+        $config = SystemConfigService::more(['version', 'apk']);
+        $data = [
+            'version' => $config['version'],
+            'url' =>   $request->domain().'/'.$config['apk'],
+        ];
+        $msg = [
+            'status' => 200,
+            'msg' => 'ok',
+            'data' => $data
+        ];
+        return app('json')->successful($data);
+
+    }
+
 }

+ 47 - 0
app/api/controller/order/StoreOrderController.php

@@ -228,6 +228,30 @@ class StoreOrderController
                         }
                     }
                     break;
+
+                case "ali":
+                    $orderInfo = StoreOrder::where('order_id', $orderId)->find();
+                    if (!$orderInfo || !isset($orderInfo['paid'])) return app('json')->fail('支付订单不存在!');
+                    $orderInfo = $orderInfo->toArray();
+                    if ($orderInfo['paid']) return app('json')->fail('支付已支付!');
+                    //支付金额为0
+                    if (bcsub((float)$orderInfo['pay_price'], 0, 2) <= 0) {
+                        //创建订单jspay支付
+                        $payPriceStatus = StoreOrder::jsPayPrice($orderId, $request->uid());
+                        if ($payPriceStatus)//0元支付成功
+                            return app('json')->status('success', '支付成功');
+                        else
+                            return app('json')->status('pay_error', StoreOrder::getErrorInfo());
+                    } else {
+                        try {
+                            $jsConfig = OrderRepository::aliPay($orderId); //创建订单jspay
+                        } catch (\Exception $e) {
+                            return app('json')->status('pay_error', $e->getMessage());
+                        }
+                        $info['jsConfig'] = $jsConfig;
+                        return app('json')->status('ali_pay', '订单创建成功', $info);
+                    }
+                    break;
                 case 'yue':
                     if (StoreOrder::yuePay($orderId, $request->uid(), $formId))
                         return app('json')->status('success', '余额支付成功', $info);
@@ -360,6 +384,29 @@ class StoreOrderController
                 else
                     return app('json')->status('success', '支付失败');
                 break;
+            case "ali":
+                $orderInfo = StoreOrder::where('order_id', $order['order_id'])->find();
+                if (!$orderInfo || !isset($orderInfo['paid'])) return app('json')->fail('支付订单不存在!');
+                $orderInfo = $orderInfo->toArray();
+                if ($orderInfo['paid']) return app('json')->fail('支付已支付!');
+                //支付金额为0
+                if (bcsub((float)$orderInfo['pay_price'], 0, 2) <= 0) {
+                    //创建订单jspay支付
+                    $payPriceStatus = StoreOrder::jsPayPrice($order['order_id'], $request->uid());
+                    if ($payPriceStatus)//0元支付成功
+                        return app('json')->status('success', '支付成功');
+                    else
+                        return app('json')->status('pay_error', StoreOrder::getErrorInfo());
+                } else {
+                    try {
+                        $jsConfig = OrderRepository::aliPay($order['order_id']); //创建订单jspay
+                    } catch (\Exception $e) {
+                        return app('json')->status('pay_error', $e->getMessage());
+                    }
+                    $info['jsConfig'] = $jsConfig;
+                    return app('json')->status('ali_pay', '订单创建成功', $info);
+                }
+                break;
         }
         return app('json')->fail('支付方式错误');
     }

+ 1 - 1
app/models/store/StoreOrder.php

@@ -50,7 +50,7 @@ class StoreOrder extends BaseModel
 
     protected $insert = ['add_time'];
 
-    protected static $payType = ['weixin' => '微信支付', 'yue' => '余额支付', 'offline' => '线下支付'];
+    protected static $payType = ['weixin' => '微信支付', 'yue' => '余额支付', 'offline' => '线下支付', 'ali' => '支付宝支付'];
 
     protected static $deliveryType = ['send' => '商家配送', 'express' => '快递配送'];
 

+ 28 - 0
crmeb/repositories/OrderRepository.php

@@ -6,7 +6,9 @@ use app\models\store\StoreOrder;
 use app\models\user\User;
 use app\models\user\WechatUser;
 use app\admin\model\order\StoreOrder as AdminStoreOrder;
+use crmeb\services\AlipayService;
 use crmeb\services\MiniProgramService;
+use crmeb\services\SystemConfigService;
 use crmeb\services\WechatService;
 
 /**
@@ -90,6 +92,32 @@ class OrderRepository
         return WechatService::paymentPrepare(null, $orderInfo['order_id'], $orderInfo['pay_price'], 'product', StoreOrder::getSubstrUTf8($site_name . ' - ' . $bodyContent, 30), '', 'MWEB');
     }
 
+    public static function aliPay($orderId, $field = 'order_id')
+    {
+        if (is_string($orderId))
+            $orderInfo = StoreOrder::where($field, $orderId)->where('is_del', 0)->find();
+        else
+            $orderInfo = $orderId;
+        if (!$orderInfo || !isset($orderInfo['paid'])) exception('支付订单不存在!');
+        if ($orderInfo['paid']) exception('支付已支付!');
+        if ($orderInfo['pay_price'] <= 0) exception('该支付无需支付!');
+        $bodyContent = StoreOrder::getProductTitle($orderInfo['cart_id']);
+        $site_name = sys_config('site_name');
+        if (!$site_name || !$bodyContent) exception('支付参数缺少:请前往后台设置->系统设置-> 填写 网站名称');
+        $alipay = SystemConfigService::more(['alipay_app_id', 'alipay_pub_key', 'alipay_private_key', 'alipay_key']);
+        $notifyUrl = sys_config('site_url') . '/api/alipay/notify';
+        $aliPay = new AlipayService();
+        $aliPay->setAppid($alipay['alipay_app_id']);
+        $aliPay->setNotifyUrl($notifyUrl);
+        $aliPay->setRsaPrivateKey($alipay['alipay_private_key']);
+        $aliPay->setTotalFee($orderInfo['pay_price']);
+        $aliPay->setOutTradeNo($orderInfo['order_id']);
+        $aliPay->setOrderName(StoreOrder::getSubstrUTf8($site_name . ' - ' . $bodyContent, 30));
+        $aliPay->setPassbackParams(['attach' => 'product']);
+        $orderStr = $aliPay->getOrderStr();
+        return $orderStr;
+    }
+
     /**
      * 用户确认收货
      * @param $order

+ 2 - 0
route/api/route.php

@@ -32,6 +32,7 @@ Route::any('wechat/serve', 'wechat.WechatController/serve');//公众号服务
 Route::any('wechat/notify', 'wechat.WechatController/notify');//公众号支付回调
 Route::any('routine/notify', 'wechat.AuthController/notify');//小程序支付回调
 Route::any('test', 'PublicController/test');//小程序支付回调
+Route::any('alipay/notify', 'AlipayController/notify');//支付支付回调
 
 Route::get('h5Key', 'AuthController/h5Key');//授权登录Key
 Route::get('h5Token/:key', 'AuthController/h5Token');//授权登录Token
@@ -240,6 +241,7 @@ Route::group(function () {
     //获取城市列表
     Route::get('city_list', 'PublicController/city_list')->name('cityList');
 
+    Route::get('version', 'PublicController/version')->name('version'); // 版本更新
 
 })->middleware(\app\http\middleware\AllowOriginMiddleware::class)->middleware(\app\http\middleware\AuthTokenMiddleware::class, false);