zhangxiaobin 1 年之前
父节点
当前提交
bc5dcd7fbc
共有 3 个文件被更改,包括 73 次插入3 次删除
  1. 10 0
      addons/epay/library/Service.php
  2. 6 2
      application/api/controller/Money.php
  3. 57 1
      application/api/controller/Notify.php

+ 10 - 0
addons/epay/library/Service.php

@@ -7,6 +7,7 @@ use app\common\library\Auth;
 use Exception;
 use think\Session;
 use Yansongda\Pay\Pay;
+use Yansongda\Supports\Str;
 
 /**
  * 订单服务类
@@ -245,6 +246,15 @@ class Service
         if (isset($config['cert_key']) && substr($config['cert_key'], 0, 8) == '/addons/') {
             $config['cert_key'] = ROOT_PATH . str_replace('/', DS, substr($config['cert_key'], 1));
         }
+        if (isset($config['app_cert_public_key']) && substr($config['app_cert_public_key'], 0, 8) == '/addons/') {
+            $config['app_cert_public_key'] = ROOT_PATH . str_replace('/', DS, substr($config['app_cert_public_key'], 1));
+        }
+        if (isset($config['alipay_root_cert']) && substr($config['alipay_root_cert'], 0, 8) == '/addons/') {
+            $config['alipay_root_cert'] = ROOT_PATH . str_replace('/', DS, substr($config['alipay_root_cert'], 1));
+        }
+        if (isset($config['ali_public_key']) && (Str::endsWith($config['ali_public_key'], '.crt') || Str::endsWith($config['ali_public_key'], '.pem'))) {
+            $config['ali_public_key'] = ROOT_PATH . str_replace('/', DS, substr($config['ali_public_key'], 1));
+        }
         // 可选
         $config['http'] = [
             'timeout'         => 10,

+ 6 - 2
application/api/controller/Money.php

@@ -133,12 +133,16 @@ class Money extends Common
         // 查询新人礼包
         $this->addBagGift($user_id, $amount);
 
-        if ($method == "app") {
+        /*if ($method == "app") {
             $this->success("", json_decode($result, true));
         } else {
             $this->success("", $result);
+        }*/
+        if($type == 'wechat'){
+            $this->success('success',json_decode($result,true));
+        }else{
+            $this->success('success',$result);
         }
-
     }
 
 

+ 57 - 1
application/api/controller/Notify.php

@@ -44,7 +44,63 @@ class Notify extends Api
                 // 修改用户钻石余额
                 $res2 = $userModel->where(["id" => $orderInfo["user_id"]])->setInc("jewel", $orderInfo["jewel"]);
                 // 添加钻石流水记录
-                $detail = "砖石充值";
+                $detail = "钻石充值";
+                $res3 = $jewellogModel->addUserJewelLog($userInfo["id"], $orderInfo["jewel"], "+", $userInfo["jewel"], $detail, 1);
+                // 添加充值记录
+                $res4 = $rechargelogModel->addRecord($userInfo["id"], $orderInfo["jewel"], $payamount, bcadd($userInfo["jewel"], $orderInfo["jewel"], 2), $userInfo["money"], $orderInfo["platform"], 1);
+                if ($res1 && $res2 && $res3 && $res4) {
+                    // 添加统计
+                    $userInfo->chargecount = $userInfo->chargecount + $payamount;
+                    $userInfo->chargetime = time();
+                    $userInfo->save();
+                    Db::commit();
+                }
+            } catch (ValidateException $e) {
+                Db::rollback();
+                $this->error($e->getMessage());
+            } catch (PDOException $e) {
+                Db::rollback();
+                $this->error($e->getMessage());
+            } catch (Exception $e) {
+                Db::rollback();
+                $this->error($e->getMessage());
+            }
+
+            //你可以在此编写订单逻辑
+        } catch (Exception $e) {
+        }
+        echo $pay->success();
+    }
+
+    /**
+     * 支付回调
+     */
+    public function alipaynotify()
+    {
+        $paytype = "alipay";
+        $pay = Service::checkNotify($paytype);
+        if (!$pay) {
+            echo '签名错误';
+            return;
+        }
+        $data = $pay->verify();
+        try {
+            $payamount = $data['total_fee'] / 100;
+            $out_trade_no = $data['out_trade_no'];
+            Db::startTrans();
+            try {
+                $orderModel = new \app\common\model\RecharOrder();
+                $userModel = new \app\common\model\User();
+                $jewellogModel = new \app\common\model\UserJewelLog();
+                $rechargelogModel = new \app\common\model\UserRechargeLog();
+                $orderInfo = $orderModel->where(["order_no" => $out_trade_no])->find();
+                $userInfo = $userModel->where(["id" => $orderInfo["user_id"]])->find();
+                // 修改订单状态
+                $res1 = $orderModel->update(["status" => 1], ["order_no" => $out_trade_no]);
+                // 修改用户钻石余额
+                $res2 = $userModel->where(["id" => $orderInfo["user_id"]])->setInc("jewel", $orderInfo["jewel"]);
+                // 添加钻石流水记录
+                $detail = "钻石充值";
                 $res3 = $jewellogModel->addUserJewelLog($userInfo["id"], $orderInfo["jewel"], "+", $userInfo["jewel"], $detail, 1);
                 // 添加充值记录
                 $res4 = $rechargelogModel->addRecord($userInfo["id"], $orderInfo["jewel"], $payamount, bcadd($userInfo["jewel"], $orderInfo["jewel"], 2), $userInfo["money"], $orderInfo["platform"], 1);