diff --git a/app/api/controller/Pay.php b/app/api/controller/Pay.php index d181b8ad..63d9fd5a 100755 --- a/app/api/controller/Pay.php +++ b/app/api/controller/Pay.php @@ -13,6 +13,7 @@ use app\common\model\order\OrderLog; use app\common\server\AliPayServer; use app\common\server\JsonServer; use app\common\model\Test; +use app\common\logic\Billions; use app\common\server\WeChatPayServer; use app\common\server\WeChatServer; use app\common\model\integral\IntegralOrder; @@ -29,7 +30,7 @@ use think\facade\Log; */ class Pay extends Api { - public $like_not_need_login = ['huifuNotify','notifyMnp1','notifyMnp', 'notifyOa', 'notifyApp', 'aliNotify', 'localPay', 'localBalance']; + public $like_not_need_login = ['huifuyueFz','checkFz','huifuFz','huifuzfNotify','huifuNotify','notifyMnp1','notifyMnp', 'notifyOa', 'notifyApp', 'aliNotify', 'localPay', 'localBalance']; /** * @notes 支付入口 @@ -122,6 +123,264 @@ class Pay extends Api return $result; } + public function huifuzf($user_id,$post) + { + $data['order_sn'] = time().$user_id; + $data['order_source'] = 1; + $data['pay_way'] = 1; + $data['pay_status'] = 0; + $data['local_id'] = $post['lid']; + $data['user_id'] = $user_id; + $data['order_amount'] = $post['money']; + $data['pay_type'] = 2; + $data['create_time'] = date("Y-m-d H:i:s"); + $r = Db::name("local_pay")->save($data); + + $company = Db::name("local_store")->where("lstore_id",$post['lid'])->where("is_delete",0)->find(); + $dt['lstore_id'] = $post['lid']; + $dt['payment_type'] = $company['bankType']; + $dt['total_amount'] = $post['money']; + $dt['account_name'] = $company['shopName']; + $dt['bank_name'] = $company['bankName']; + $dt['bank_card'] = $company['bankCard']; + $dt['large_number'] = $company['largeNumber']; + $dt['separate_account'] = round($post['money'],2); + $dt['create_time'] = date("Y-m-d H:i:s"); + $dt['user_id'] = $user_id; + $dt['order_no'] = $data['order_sn']; + $dt['pay_shop_type'] = 1; + $r = Db::name("local_store_order")->save($dt); + $user = Db::name("user_auth")->where("user_id",$user_id)->find(); + // $out = "dlh".time().$user_id; + $config = new BsPay(); + $merConfig = $config->getConfig(); + // 2.组装请求参数 + $paramsInfo = array(); + // 请求日期 + $paramsInfo["req_date"] = date("Ymd"); + // 请求流水号 + $paramsInfo["req_seq_id"] = $data['order_sn']; + // 商户号 + $paramsInfo["huifu_id"] = "6666000158818881"; + // 商品描述 + $paramsInfo["goods_desc"] = "支付"; + // 交易类型 + $paramsInfo["trade_type"] = "T_MINIAPP"; + // 交易金额 + $money =(string)number_format(floatval($post['money']), 2,'.',''); + $paramsInfo["trans_amt"] = $money; + // 交易有效期 + $paramsInfo["time_expire"] = "20250518235959"; + // 分账对象 + // $acct_split_bunch =array( + // "wacct_infos"=>array( + // "div_amt"=>$money-0.5, + // "huifu_id"=>$company['huifu_id'] + // ) + // ); + // $paramsInfo["acct_split_bunch"] = json_encode($acct_split_bunch,true); + // 微信参数集合 + $arr = array( + "sub_appid"=>"wx586d77b9edb0636d", + "sub_openid"=>$user['openid'] + ); + $paramsInfo["wx_data"] = json_encode($arr,true); +// $paramsInfo["wx_data"] = +// "{\"sub_appid\":\"wx586d77b9edb0636d\",\"sub_openid\":\"ouOMm4zEGaZbvNhq9PyoYN53902c\", +// \"detail\":{\"cost_price\":\"43.00\",\"receipt_id\":\"20220628132043853798\",\"goods_detail\": +// [{\"goods_id\":\"6934572310301\",\"goods_name\":\"太龙双黄连口服液\",\"price\":\"43.00\" +// ,\"quantity\":\"1\",\"wxpay_goods_id\":\"12235413214070356458058\"}]}}"; + // 是否延迟交易 + $paramsInfo["delay_acct_flag"] = "N"; + // // 分账对象 + // $paramsInfo["acct_split_bunch"] = "{\"acct_infos\":[{\"div_amt\":\"0.10\",\"huifu_id\":\"6666000156739560\"}]}"; + // 传入分账遇到优惠的处理规则 + $paramsInfo["term_div_coupon_type"] = "0"; + // 禁用信用卡标记 + $paramsInfo["limit_pay_type"] = "NO_CREDIT"; + // 场景类型 + $paramsInfo["pay_scene"] = "02"; + // 备注 + $paramsInfo["remark"] = "string"; + // 异步通知地址 + $paramsInfo["notify_url"] = "https://dlh.hainings.com/api/pay/huifuzfNotify"; + // print_r("
");
+        // var_dump($paramsInfo);
+        // 3. 发起API调用
+        $bspay = new BsPay();
+        $result = $bspay->post("v2.trade.payment.jspay", $paramsInfo, '', 'default');
+        // var_dump($result);
+        $result = $this->objectToArray($result);
+        $rspDatas =  $result['rspDatas']['data'];
+        return JsonServer::success('操作成功', json_decode($rspDatas['pay_info'], true));
+    }
+
+    public function checkFz(){
+        $config = new BsPay();
+        $merConfig = $config->getConfig();
+        // 2.组装请求参数
+        $paramsInfo = array();
+
+        // 请求日期
+        $paramsInfo["org_req_date"] = date("Ymd");
+        // 请求流水号
+        $paramsInfo["org_req_seq_id"] = "org_req_seq_id";
+        // 商户号
+        $paramsInfo["huifu_id"] = "6666000158818881";
+
+        print_r("
");
+        var_dump($paramsInfo);
+        // 3. 发起API调用
+        $bspay = new BsPay();
+        $result = $bspay->post("v2.trade.payment.scanpay.query", $paramsInfo, '', 'default');
+        var_dump($result);
+        $result = $this->objectToArray($result);
+        $rspDatas =  $result['rspDatas']['data'];
+        return JsonServer::success('操作成功', json_decode($rspDatas['pay_info'], true));
+    }
+
+    public function huifuzfNotify(){
+        $result = $_REQUEST;
+        //  Log::write($result, '回调信息');
+        //  $resp_data['req_seq_id'] = "17349345377";
+        // $result['out_trans_id'] = "17349345377";
+        // $result['resp_code'] = "00000000";
+        // $result['req_seq_id'] = "17349345377";
+        if(isset($result['resp_code'])&&$result['resp_code']=="00000000"){
+            $resp_data = json_decode($result['resp_data'],true);
+            $pay = Db::name("local_pay")
+                ->where("order_sn", $resp_data['req_seq_id'])
+                ->find();
+            if($pay['pay_status'] == 1){
+                return true;
+            }
+            // var_dump(111);die;
+            $d['pay_status'] = 1;
+            $d['pay_time'] = date("Y-m-d H:i:s");
+            $d['transaction_id'] = $resp_data['out_trans_id'];
+            $pay = Db::name("local_pay")
+                ->where("order_sn", $resp_data['req_seq_id'])
+                ->update($d);
+
+            $this->huifuFz($resp_data['req_seq_id']);
+        }else{
+            Log::write($result, '回调信息');
+        }
+    }
+    public function huifuFz($order_sn)
+    {
+        $msg = Db::name("local_pay")
+            ->where("order_sn", $order_sn)
+            ->find();
+        $company = Db::name("local_store")
+            ->where("lstore_id", $msg['local_id'])
+            ->find();
+        $out = "dlh".time().$msg['user_id'];
+        $config = new BsPay();
+        $merConfig = $config->getConfig();
+        // 2.组装请求参数
+        $paramsInfo = array();
+        // 请求日期
+        $paramsInfo["req_date"] = date("Ymd");
+        // 请求流水号
+        $paramsInfo["req_seq_id"] = $out;
+        // 商户号
+        $paramsInfo["out_huifu_id"] = "6666000158818881";
+        // 交易金额
+        $money =(string)number_format(floatval($msg['order_amount']*0.6967), 2);
+        $paramsInfo["ord_amt"] = $money;
+        // 交易有效期
+        $paramsInfo["risk_check_data"] = "{\"transfer_type\":\"04\",\"sub_product\":\"1\"}";
+        // 分账对象
+        $acct_split_bunch =array(
+            "acct_infos"=>array(
+                "div_amt"=>$paramsInfo["ord_amt"],
+                "huifu_id"=>$company['huifu_id']
+            )
+        );
+        $paramsInfo["acct_split_bunch"] = json_encode($acct_split_bunch,true);
+        // $paramsInfo["acct_split_bunch"] = "{\"acct_infos\":[{\"div_amt\":\"1.00\",\"huifu_id\":\"6666000159235336\"},{\"div_amt\":\"0.40\",\"huifu_id\":\"6666000159235170\"}]}";
+        print_r("
");
+        var_dump($paramsInfo);
+        // 3. 发起API调用
+        $bspay = new BsPay();
+        $result = $bspay->post("v2.trade.acctpayment.pay", $paramsInfo, '', 'default');
+        var_dump($result);
+        $result = $this->objectToArray($result);
+        $rspDatas =  $result['rspDatas']['data'];
+
+        var_dump($result);
+
+        $da['pay_type'] = 1;
+        $da['state'] = 1;
+        $da['huifu_fz_orderno'] = $out;
+        $local_order = Db::name("local_store_order")
+            ->where("order_no", $order_sn)
+            ->update($da);
+        $local_order_msg = Db::name("local_store_order")
+            ->where("order_no", $order_sn)
+            ->find();
+        // if (!$result || $result->isError()) {  //失败处理
+        //     var_dump($result->getErrorInfo());
+        // } else {    //成功处理
+        //     var_dump($result);
+        // }
+        $billions = new Billions();
+        $order['order_amount'] = round($msg['order_amount'],2);
+        $order['id'] = $msg['id'];
+        $order['lstore_id'] = $local_order_msg['lstore_id'];
+        $order['type'] = 3;
+        $type = "local_pay";
+        $billions_result = $billions->billions($order,$msg['user_id'],$type);
+        return true;
+    }
+    // 余额分账
+    public function huifuyueFz($price=100,$lstore_id=10)
+    {die;
+        $company = Db::name("local_store")->where("lstore_id",$lstore_id)->find();
+        $out = "dlh".time();
+        $config = new BsPay();
+        $merConfig = $config->getConfig();
+        // 2.组装请求参数
+        $paramsInfo = array();
+        // 请求日期
+        $paramsInfo["req_date"] = date("Ymd");
+        // 请求流水号
+        $paramsInfo["req_seq_id"] = $out;
+        // 商户号
+        $paramsInfo["out_huifu_id"] = "6666000158818881";
+        // 交易金额
+        $money =(string)number_format(floatval($price*99.67*0.7/100-0.51), 2);
+        $paramsInfo["ord_amt"] = $money;
+        // 交易有效期
+        $paramsInfo["risk_check_data"] = "{\"transfer_type\":\"04\",\"sub_product\":\"1\"}";
+        // 分账对象
+        $acct_split_bunch =array(
+            "acct_infos"=>array(
+                "div_amt"=>$paramsInfo["ord_amt"],
+                "huifu_id"=>$company['huifu_id']
+            )
+        );
+        $paramsInfo["acct_split_bunch"] = json_encode($acct_split_bunch,true);
+        // $paramsInfo["acct_split_bunch"] = "{\"acct_infos\":[{\"div_amt\":\"1.00\",\"huifu_id\":\"6666000159235336\"},{\"div_amt\":\"0.40\",\"huifu_id\":\"6666000159235170\"}]}";
+        print_r("
");
+        var_dump($paramsInfo);
+        // 3. 发起API调用
+        $bspay = new BsPay();
+        $result = $bspay->post("v2.trade.acctpayment.pay", $paramsInfo, '', 'default');
+        var_dump($result);
+        $result = $this->objectToArray($result);
+        $rspDatas =  $result['rspDatas']['data'];
+
+        var_dump($result);
+        // $da['huifu_fz_orderno'] = $out;
+        // $local_order = Db::name("local_store_order")
+        //     ->where("order_no", $order_sn)
+        //     ->update($da);
+
+        return true;
+    }
+
     public function huifuCz($user_id,$post)
     {
         $order = RechargeOrder::where([
@@ -177,7 +436,7 @@ class Pay extends Api
         // 3. 发起API调用
         $bspay = new BsPay();
         $result = $bspay->post("v2.trade.payment.jspay", $paramsInfo, '', 'default');
-        // var_dump($result);
+
         $result = $this->objectToArray($result);
         $rspDatas =  $result['rspDatas']['data'];
         return JsonServer::success('操作成功', json_decode($rspDatas['pay_info'], true));
@@ -194,6 +453,7 @@ class Pay extends Api
             $order = RechargeOrder::where([
                 ['order_sn', '=', $resp_data['req_seq_id']]
             ])->update($d);
+
         }else{
             Log::write($result, '回调信息');
         }
@@ -222,9 +482,14 @@ class Pay extends Api
         }else{
             $client = 1;
         }
-        if($post['lid'] != 138){
-            return JsonServer::error('因银行及第三方系统维护中,该功能暂时无法适用,请等待通知');
+
+        $store_msg = Db::name("local_store")->where("lstore_id",$post['lid'])->find();
+        if($store_msg['huifu_id'] != 0){
+            return $this->huifuzf($user_id,$post);
         }
+        //   if($post['lid'] != 138){
+        return JsonServer::error('因银行及第三方系统更换,请联系客服更新资料');
+        // }
         $result = PayLogic::localWxPay($user_id,$post, $client);
         return $result;
     }
@@ -251,9 +516,9 @@ class Pay extends Api
     {
         $user_id = $this->user_id;
         $post = $this->request->post();
-        if($post['lid'] != 138){
-            return JsonServer::error('因银行及第三方系统维护中,该功能暂时无法适用,请等待通知');
-        }
+        // if($post['lid'] != 138){
+        //     return JsonServer::error('因银行及第三方系统维护中,该功能暂时无法适用,请等待通知');
+        // }
         $result = PayLogic::localBalance($user_id,$post);
         return $result;