Procházet zdrojové kódy

还原支付有关的代码

shaoguo před 7 měsíci
rodič
revize
76d9492df9

+ 493 - 1
Modules/Home/Controller/CarController.class.php

@@ -5214,8 +5214,500 @@ class CarController extends CommonController
 
 	}
 
+    public function wxpay()
+    {
+        $gpc = I('request.');
 
-	public function wxpay()
+        $token = $gpc['token'];
+        $order_id = $gpc['order_id'];
+
+        $scene = $gpc['scene'];
+        $is_need_scene_check = 0;
+
+        if(!empty($scene))
+        {
+            $is_need_scene_check = D('Seller/MpModifyTradeComponts')->sceneCheck( $scene );
+        }
+
+        $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
+
+
+        $member_id = $weprogram_token['member_id'];
+
+
+        if( empty($member_id) )
+        {
+            echo json_encode( array('code' =>1,'msg' =>'未登录') );
+            die();
+        }
+
+
+        $member_info = M('lionfish_comshop_member')->field('we_openid')->where( array('member_id' => $member_id) )->find();
+
+
+        $order = M('lionfish_comshop_order')->where( array('order_id' => $order_id ) )->find();
+
+
+        //order_status_id
+
+        if( $order['order_status_id'] != 3 && $order['order_status_id'] != 15 )
+        {
+            $json = array();
+
+            $json['msg']='商品已下架!';
+            $json['code'] = 2;
+            if($order['order_status_id'] == 1)
+            {
+                $json['msg']='订单已付款,请勿重新付款!';
+            }
+            else if( $order['order_status_id'] == 5){
+                $json['msg']='订单已取消,请重新选择商品下单!';
+            }
+            echo json_encode($json);
+            die();
+        }
+
+
+
+        //检测商品是否下架 begin
+        $sql = "select name,quantity,rela_goodsoption_valueid,goods_id from ".C('DB_PREFIX')."lionfish_comshop_order_goods  
+					where order_id={$order_id} ";
+
+        $order_goods_list = M()->query($sql);
+
+        foreach($order_goods_list as $tp_val)
+        {
+            $tp_gd_info = M('lionfish_comshop_goods')->field('grounding')->where( array('id' => $tp_val['goods_id'] ) )->find();
+
+            if( empty($tp_gd_info) || $tp_gd_info['grounding'] != 1 )
+            {
+                $json['code'] = 2;
+
+                $json['msg']='商品已下架!';
+
+                echo json_encode($json);
+                die();
+            }
+        }
+
+        //检测商品是否下架end
+        //检测是否预售商品。预售商品不需要检测二次支付问题
+        $presale_info = [];
+        $presale_result = D('Home/PresaleGoods')->getOrderPresaleInfo( $order_id );
+        if( $presale_result['code'] == 0 )
+        {
+            $presale_info = $presale_result['data'];
+        }
+        //检测是否已经支付过了begin
+
+        $order_relate_info = M('lionfish_comshop_order_relate')->where( array('order_id' => $order_id ) )->order('id desc')->find();
+
+        if( !empty($order_relate_info) && $order_relate_info['order_all_id'] > 0  && empty($presale_info) )
+        {
+            $order_all_info = M('lionfish_comshop_order_all')->where( array('id' => $order_relate_info['order_all_id'] ) )->find();
+
+            if( !empty($order_all_info) && !empty($order_all_info['out_trade_no']) )
+            {
+
+                $out_trade_no = $order_all_info['out_trade_no'];
+
+                $appid =  D('Home/Front')->get_config_by_name('wepro_appid');
+                $mch_id =      D('Home/Front')->get_config_by_name('wepro_partnerid');
+                $nonce_str =    nonce_str();
+
+                $pay_key = D('Home/Front')->get_config_by_name('wepro_key');
+
+
+                $post = array();
+                $post['appid'] = $appid;
+                $post['mch_id'] = $mch_id;
+                $post['nonce_str'] = $nonce_str;
+                $post['out_trade_no'] = $out_trade_no;
+
+                $sign = sign($post,$pay_key);
+
+                $post_xml = '<xml>
+							   <appid>'.$appid.'</appid>
+							   <mch_id>'.$mch_id.'</mch_id>
+							   <nonce_str>'.$nonce_str.'</nonce_str>
+							   <out_trade_no>'.$out_trade_no.'</out_trade_no>
+							   <sign>'.$sign.'</sign>
+							</xml>';
+
+                $url = "https://api.mch.weixin.qq.com/pay/orderquery";
+
+                $result = http_request($url,$post_xml);
+
+                $array = xml($result);
+
+                if( $array['RETURN_CODE'] == 'SUCCESS' && $array['RETURN_MSG'] == 'OK' )
+                {
+                    if( $array['TRADE_STATE'] == 'SUCCESS' )
+                    {
+                        $json = array();
+
+                        $json['msg']='商品已下架!';
+                        $json['code'] = 2;
+                        $json['msg']='订单已付款,请勿重新付款,请刷新页面!';
+                        echo json_encode($json);
+                        die();
+                    }
+                }
+
+            }
+        }
+
+        //检测是否已经支付过了end
+
+        //支付才减库存,才需要判断
+        $kucun_method = D('Home/Front')->get_config_by_name('kucun_method');
+
+        if( empty($kucun_method) )
+        {
+            $kucun_method = 0;
+        }
+
+        if($kucun_method == 1 && ( empty($presale_info) || $presale_info['state'] != 1 ) )
+        {
+            /*** 检测商品库存begin  **/
+
+            //goods_id
+            foreach($order_goods_list as $val)
+            {
+                $quantity = $val['quantity'];
+
+                $goods_id = $val['goods_id'];
+
+                $can_buy_count = D('Home/Front')->check_goods_user_canbuy_count($member_id, $goods_id);
+
+                $goods_description = D('Home/Front')->get_goods_common_field($goods_id , 'total_limit_count');
+
+                if($can_buy_count == -1)
+                {
+                    $json['code'] = 2;
+
+                    $json['msg']='您还能购买'.$goods_description['total_limit_count'].'个';
+
+                    echo json_encode($json);
+                    die();
+                }else if($can_buy_count >0 && $quantity >$can_buy_count)
+                {
+                    $json['code'] = 2;
+                    $json['msg']='您还能购买'.$can_buy_count.'份';
+                    echo json_encode($json);
+                    die();
+                }
+                //rela_goodsoption_valueid
+                if(!empty($val['rela_goodsoption_valueid']))
+                {
+                    $mul_opt_arr = array();
+
+                    //ims_
+
+                    $goods_option_mult_value = M('lionfish_comshop_goods_option_item_value')->where( array('goods_id' => $goods_id,'option_item_ids' => $val['rela_goodsoption_valueid']) )->find();
+
+
+                    if( !empty($goods_option_mult_value) )
+                    {
+                        if($goods_option_mult_value['stock']<$quantity){
+                            $json['code'] =2;
+                            $json['msg']='商品数量不足,剩余'.$goods_option_mult_value['stock'].'个!!';
+                            echo json_encode($json);
+                            die();
+                        }
+                    }
+                }
+
+            }
+            /*** 检测商品库存end **/
+        }
+
+        $pin_order = array();
+        if( !empty($pin_order) )
+        {
+            /**
+            $pin_model =  load_model_class('pin');
+            $is_pin_over = $pin_model->getNowPinState($pin_order['pin_id']);
+            if($is_pin_over != 0)
+            {
+            pdo_query("delete from ".tablename('lionfish_comshop_pin_order')." where order_id = {$order_id} ");
+
+            pdo_query("delete from ".tablename('lionfish_comshop_pin')." where pin_id = ".$pin_order['pin_id']." and order_id = ".$order_id);
+
+            $order_goods_info = pdo_fetch("select goods_id from ".tablename('lionfish_comshop_order_goods')." where uniacid=:uniacid and order_id=:order_id ", array(':order_id' => $order_id,':uniacid' => $_W['uniacid']));
+
+            //新开团
+
+            $pin_id = $pin_model->openNewTuan($order_id,$order_goods_info['goods_id'],$member_id);
+            //插入拼团订单
+            $pin_model->insertTuanOrder($pin_id,$order_id);
+
+            }
+             **/
+        }
+
+
+        //单独支付一个店铺的订单
+        //M('lionfish_comshop_order_relate')->where( array('order_id' => $order_id) )->delete();
+
+        $order_all_data = array();
+        $order_all_data['member_id'] = $member_id;
+        $order_all_data['order_num_alias'] = build_order_no($member_id);
+        $order_all_data['transaction_id'] = '';
+        $order_all_data['order_status_id'] = 3;
+        $order_all_data['is_pin'] = $order['is_pin'];
+        $order_all_data['paytime'] = 0;
+        $order_all_data['total_money'] = $order['total']+ $order['shipping_fare']-$order['voucher_credit']-$order['fullreduction_money'];
+        $order_all_data['addtime'] = time();
+
+        $order_all_id = M('lionfish_comshop_order_all')->add($order_all_data);
+
+        $order_relate_data = array();
+        $order_relate_data['order_all_id'] = $order_all_id;
+        $order_relate_data['order_id'] = $order_id;
+        $order_relate_data['addtime'] = time();
+
+        M('lionfish_comshop_order_relate')->add($order_relate_data);
+
+        if( $order['delivery'] == 'pickup' )
+        {
+            $fee = $order['total']+ $order['shipping_fare']-$order['voucher_credit']-$order['fullreduction_money'] - $order['score_for_money'] - $order['fare_shipping_free'];
+        }else if($order['delivery'] == 'localtown_delivery'){
+            $fee = $order['total'] + $order['packing_fare'] + $order['shipping_fare']-$order['voucher_credit'] - $order['fullreduction_money'] - $order['score_for_money'] + $order['localtown_add_shipping_fare'] - $order['fare_shipping_free'];
+        }else {
+            $fee = $order['total']+ $order['shipping_fare']-$order['voucher_credit']-$order['fullreduction_money'] - $order['score_for_money'] - $order['fare_shipping_free'];
+        }
+
+        //如果是预售 begin
+
+        if( !empty($presale_info) )
+        {
+            if( $presale_info['state'] == 0 )
+            {
+                //首次支付,
+                $fee = $presale_info['presale_ding_money'];
+            }else if( $presale_info['state'] == 1 )
+            {
+                //第二次支付
+                if( !empty($presale_info['presale_deduction_money']) && false )
+                {
+                    $fee = $fee - $presale_info['presale_deduction_money'];
+                }else{
+                    $fee = $fee - $presale_info['presale_ding_money'];
+                }
+            }
+        }
+        //end
+
+
+        $fee = round($fee , 2);
+
+
+        $appid = D('Home/Front')->get_config_by_name('wepro_appid');
+
+
+        $body =  $pay_goods_name;//'商品购买';
+
+        $body = mb_substr($body,0,32,'utf-8');
+
+        if( empty($body) )
+        {
+            $body =         '商品购买';
+        }
+
+
+        $mch_id =       D('Home/Front')->get_config_by_name('wepro_partnerid');
+        $nonce_str =    nonce_str();
+
+        $shop_domain = D('Home/Front')->get_config_by_name('shop_domain');
+
+        $notify_url =    $shop_domain.'/notify.php';
+
+        $openid =       $member_info['we_openid'];
+        $out_trade_no = $order_all_id.'-'.time();
+        $spbill_create_ip = $_SERVER['REMOTE_ADDR'];
+        $total_fee =    $fee*100;
+        $trade_type = 'JSAPI';
+        $pay_key = D('Home/Front')->get_config_by_name('wepro_key');
+
+
+        $is_open_yinpay = D('Home/Front')->get_config_by_name('is_open_yinpay');
+
+        //begin
+
+        if( isset($is_open_yinpay) && $is_open_yinpay == 3 )
+        {
+            $pay_key = D('Home/Front')->get_config_by_name('wepro_key');
+
+            $body = '商品购买';
+
+            $post = array();
+
+            $post['appid'] = D('Home/Front')->get_config_by_name('wepro_fuwu_appid');
+            $post['body'] = $body;
+            $post['mch_id'] =  D('Home/Front')->get_config_by_name('wepro_fuwu_partnerid');
+            $post['nonce_str'] = $nonce_str;
+            $post['notify_url'] = $notify_url;
+            //$post['openid'] = $openid;
+            $post['out_trade_no'] = $out_trade_no;
+            $post['spbill_create_ip'] = $spbill_create_ip;
+            $post['sub_appid'] = D('Home/Front')->get_config_by_name('wepro_appid');
+            $post['sub_mch_id'] = D('Home/Front')->get_config_by_name('wepro_sub_mch_id');
+            $post['sub_openid'] = $openid;
+
+            $post['total_fee'] = $total_fee;
+            $post['trade_type'] = $trade_type;
+            $sign = sign($post,$pay_key);
+
+            $post_xml = '<xml>
+				   <appid>'.$post['appid'].'</appid>
+				   <body>'.$body.'</body>
+				   <mch_id>'.$post['mch_id'].'</mch_id>
+				   <nonce_str>'.$nonce_str.'</nonce_str>
+				   <notify_url>'.$notify_url.'</notify_url>
+				   
+				   <out_trade_no>'.$out_trade_no.'</out_trade_no>
+				   <spbill_create_ip>'.$spbill_create_ip.'</spbill_create_ip>
+				   <sub_appid>'.$post['sub_appid'].'</sub_appid>
+				   <sub_mch_id>'.$post['sub_mch_id'].'</sub_mch_id>
+				   <sub_openid>'.$openid.'</sub_openid>
+				   <total_fee>'.$total_fee.'</total_fee>
+				   <trade_type>'.$trade_type.'</trade_type>
+				   <sign>'.$sign.'</sign>
+				</xml>';
+
+
+            $url = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
+            $xml = http_request($url,$post_xml);
+            $array = xml($xml);
+
+            if($array['RETURN_CODE'] == 'SUCCESS' && $array['RESULT_CODE'] == 'SUCCESS'){
+                $time = time();
+                $tmp= array();
+                $tmp['appId'] = $appid;
+                $tmp['nonceStr'] = $nonce_str;
+                $tmp['package'] = 'prepay_id='.$array['PREPAY_ID'];
+                $tmp['signType'] = 'MD5';
+                $tmp['timeStamp'] = "$time";
+
+                $prepay_id = (string)$array['PREPAY_ID'];
+
+                M('lionfish_comshop_order')->where( array('order_id' => $order_id) )->save( array('perpay_id' => $prepay_id) );
+
+
+                $data['code'] = 0;
+                $data['timeStamp'] = "$time";
+                $data['nonceStr'] = $nonce_str;
+                $data['signType'] = 'MD5';
+                $data['package'] = 'prepay_id='.$array['PREPAY_ID'];
+                $data['paySign'] = sign($tmp, $pay_key);
+                $data['out_trade_no'] = $out_trade_no;
+                $data['is_pin'] = $order['is_pin'];
+
+                if($order['is_pin'] == 1)
+                {
+                    $data['redirect_url'] = '../groups/group?id='.$order_id.'&is_show=1';
+                } else {
+                    $data['redirect_url'] = '../orders/order?id=' + $order_id;
+                }
+
+            }else{
+                $data['code'] = 1;
+                $data['text'] = "错误";
+                $data['RETURN_CODE'] = $array['RETURN_CODE'];
+                $data['RETURN_MSG'] = $array['RETURN_MSG'];
+            }
+
+
+            echo json_encode($data);
+            die();
+        }
+
+        //end
+
+        $post = array();
+        $post['appid'] = $appid;
+        $post['body'] = $body;
+        $post['mch_id'] = $mch_id;
+        $post['nonce_str'] = $nonce_str;
+        $post['notify_url'] = $notify_url;
+        $post['openid'] = $openid;
+        $post['out_trade_no'] = $out_trade_no;
+        $post['spbill_create_ip'] = $spbill_create_ip;
+        $post['total_fee'] = $total_fee;
+        $post['trade_type'] = $trade_type;
+        $sign = sign($post,$pay_key);
+
+
+        $post_xml = '<xml>
+			   <appid>'.$appid.'</appid>
+			   <body>'.$body.'</body>
+			   <mch_id>'.$mch_id.'</mch_id>
+			   <nonce_str>'.$nonce_str.'</nonce_str>
+			   <notify_url>'.$notify_url.'</notify_url>
+			   <openid>'.$openid.'</openid>
+			   <out_trade_no>'.$out_trade_no.'</out_trade_no>
+			   <spbill_create_ip>'.$spbill_create_ip.'</spbill_create_ip>
+			   <total_fee>'.$total_fee.'</total_fee>
+			   <trade_type>'.$trade_type.'</trade_type>
+			   <sign>'.$sign.'</sign>
+			</xml> ';
+        $url = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
+        $xml = http_request($url,$post_xml);
+        $array = xml($xml);
+        if($array['RETURN_CODE'] == 'SUCCESS' && $array['RESULT_CODE'] == 'SUCCESS'){
+            $time = time();
+            $tmp= array();
+            $tmp['appId'] = $appid;
+            $tmp['nonceStr'] = $nonce_str;
+            $tmp['package'] = 'prepay_id='.$array['PREPAY_ID'];
+            $tmp['signType'] = 'MD5';
+            $tmp['timeStamp'] = "$time";
+
+            $prepay_id = (string)$array['PREPAY_ID'];
+
+            M('lionfish_comshop_order')->where( array('order_id' => $order_id) )->save( array('perpay_id' => $prepay_id) );
+
+
+            $data['code'] = 0;
+            $data['timeStamp'] = "$time";
+            $data['nonceStr'] = $nonce_str;
+            $data['signType'] = 'MD5';
+            $data['package'] = 'prepay_id='.$array['PREPAY_ID'];
+            $data['paySign'] = sign($tmp, $pay_key);
+            $data['out_trade_no'] = $out_trade_no;
+            $data['is_pin'] = $order['is_pin'];
+
+            //如果是微信小程序交易组件begin---新支付方法 wx.requestOrderPayment
+            $data['order_info'] = [];
+            $data['isRequestOrderPayment'] = $is_need_scene_check;
+            if($is_need_scene_check == 1)
+            {
+                $orderPamentResult = D('Seller/MpModifyTradeComponts')->getTradeOrderInfo( $order_id , $time , $fee );
+                //如果是微信小程序交易组件,提供订单信息 end
+                $data['order_info'] = $orderPamentResult['order_info'];
+            }
+
+            if($order['is_pin'] == 1)
+            {
+                $data['redirect_url'] = '../groups/group?id='.$order_id.'&is_show=1';
+            } else {
+                $data['redirect_url'] = '../orders/order?id=' + $order_id;
+            }
+
+        }else{
+            $data['code'] = 1;
+            $data['text'] = "错误";
+            $data['RETURN_CODE'] = $array['RETURN_CODE'];
+            $data['RETURN_MSG'] = $array['RETURN_MSG'];
+        }
+
+
+        echo json_encode($data);
+        die();
+    }
+
+	public function wxpay_back()
 	{
 		$gpc = I('request.');
 

+ 0 - 0
Modules/Lib/Weixin/Wxfy.class.php.back → Modules/Lib/Weixin/Wxfy.class.php