songxingwei 2 gadi atpakaļ
vecāks
revīzija
755090164c
2 mainītis faili ar 63 papildinājumiem un 5 dzēšanām
  1. 62 0
      application/api/controller/Pay.php
  2. 1 5
      config/apidoc.php

+ 62 - 0
application/api/controller/Pay.php

@@ -128,6 +128,68 @@ class Pay extends Controller
     }
 
 
+    /**
+     * 微信支付--充值盲盒成功回调订单
+     */
+    public function BlindRechargeNotify(){
+        $payXml = file_get_contents("php://input");
+        //将xml格式转化为json格式
+        $jsonXml = json_encode(simplexml_load_string($payXml, 'SimpleXMLElement', LIBXML_NOCDATA));
+        //将json格式转成数组格式 $result['out_trade_no']
+        $result = json_decode($jsonXml, true);
+        if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS') {
+            $return = $this->dealBox($result);
+            if ($return){
+                $arr = array(
+                    'return_code' => 'SUCCESS',
+                    'return_msg'  => 'OK',
+                );
+                return $this->arrayToXml($arr);
+            }else{
+                file_put_contents("order_pay_error.txt", file_get_contents("php://input") . "\n" . json_encode($result) . "\n" . "\n", FILE_APPEND);
+            }
+        }
+    }
+
+    /**
+     * 支付宝支付--充值盲盒回调订单
+     */
+    public function alipayBlindRechargeNotify(){
+        $result    = input('post.');
+        if ($result['trade_status'] == 'TRADE_SUCCESS' || $result['trade_status'] == 'TRADE_FINISHED') {
+            $return = $this->dealBox($result);
+            if ($return){
+                echo 'success';
+            }else{
+                file_put_contents("order_alipay_error.txt", file_get_contents("php://input") . "\n" . json_encode($result) . "\n" . "\n", FILE_APPEND);
+            }
+        }
+    }
+
+
+    /**
+     * 盲盒充值次数处理数据库信息
+     * @param $result
+     * @return bool
+     */
+    function dealBox($result){
+        Db::startTrans();
+        try {
+            $order = Db::name('store_blind_recharge')->where('order_no',$result['out_trade_no'])->find();
+            if ($order['status']==1) return true;
+            Db::name('store_blind_recharge')
+                ->where('order_no',$result['out_trade_no'])
+                ->update(['status'=>1,'pay_at'=>date('Y-m-d H:i:s'),'return_success_info'=>json_encode($result,true)]);
+            //用户加次数
+            Db::name('store_member')->where('id',$order['m_id'])->setInc('lottery_number',$order['num']);
+            Db::commit();
+            return true;
+        } catch (\Exception $e){
+            Db::rollback();
+            return false;
+        }
+    }
+
 
 
     /**

+ 1 - 5
config/apidoc.php

@@ -12,11 +12,7 @@ return [
         'api\\controller\\Publics',
         'api\\controller\\Index',
         'api\\controller\\Order',
-//        'api\\controller\\Expedite',
-//        'api\\controller\\General',
-//        'api\\controller\\Crystal',
-//        'api\\controller\\GoodsOrder',
-//        'api\\controller\\Timedtask',
+        'api\\controller\\Box',
     ],
     // 指定公共注释定义的文件地址
     'definitions'=>"app\controller\Definitions",