pay_code = $pay_radio['pay_code']; // 支付 code } else // 第三方 支付商返回 { //$_GET = I('get.'); //file_put_contents('./a.html',$_GET,FILE_APPEND); $this->pay_code = I('get.pay_code'); unset($_GET['pay_code']); // 用完之后删除, 以免进入签名判断里面去 导致错误 } $this->pay_code = 'weixin'; //获取通知的数据 $xml = $GLOBALS['HTTP_RAW_POST_DATA']; if (empty($this->pay_code)) exit('pay_code 不能为空'); // 导入具体的支付类文件 include_once "plugins/payment/{$this->pay_code}/{$this->pay_code}.class.php"; // D:\wamp\www\svn_tpshop\www\plugins\payment\alipay\alipayPayment.class.php $code = '\\' . $this->pay_code; // \alipay $this->payment = new $code(); $this->user = session('user'); } /** * tpshop 提交支付方式 */ public function getCode() { $stoid = getMobileStoId(); //C('TOKEN_ON',false); // 关闭 TOKEN_ON header("Content-type:text/html;charset=utf-8"); $orderno = I('orderno'); // 订单id // 修改订单的支付方式 $payment_arr = M('Plugin')->where("`type` = 'payment'")->getField("code,name"); $isgift=I('is_gift/d'); //当是送礼情况下的支付 if($isgift==1){ M('giftuser_order')->where("parent_sn", $orderno) ->save(array('pay_code' => $this->pay_code, 'pay_name' => $payment_arr[$this->pay_code])); $order = M('giftuser_order')->where("parent_sn", $orderno)->select(); if ($order[0]['pay_status'] == 1) { $this->error2('此订单,已完成支付!');} if ($order[0]['pay_status'] == 1) { $this->error2('此订单,已完成支付!');} /*--如果订单中有用积分,判断积分是否足够--*/ if ($order[0]['integral'] > 0) { //$tk = M("store")->where("store_id", getMobileStoId())->field("api_token")->find(); $tk = tpCache("shop_info",getMobileStoId()); $userd = M("users")->where('user_id', $order[0]['user_id'])->find(); //$map['Id'] = array('=', $userd['erpvipid']); //$rs = getApiData('wxd.vip.vipinfo.list.get', $tk['api_token'], null, $map); //$d = json_decode($rs, true); //$integ = $d['data'][0]['Integral']; if(empty($userd['erpvipid'])) $this->gopayerr2("您非线下会员", $stoid); $d=get_erpvipinfo($userd['erpvipid'],$tk['ERPId']); if(!$d) $this->gopayerr2("您的积分不足【01】", $stoid); $integ=$d['Integral']; if ($order[0]['integral'] > $integ) { $this->gopayerr2("您的积分不足【02】", $stoid);} } $garr = ord_goods_he($orderno); if (empty($garr)) { $this->gopayerr2("订单获取异常", $stoid);} //$srule = M('store_config')->where('store_id', $stoid)->find(); //销售规则 $sales_rules = tpCache('basic.sales_rules', $stoid); /*----如果是线下库存,获取线下库存,预出库库存----*/ $ddd = []; if ($sales_rules == 2) { $count_arr = getcountarr($garr, $stoid); /*--预出库库存--*/ $gidarr=get_arr_column($garr,'goods_id'); $fgid0=implode(',',$gidarr); $strq = 'select pickup_id,goods_id,sum(out_qty) as sum0 from __PREFIX__erp_yqty where goods_id in(' . $fgid0 . ') and store_id='.$stoid.' GROUP BY pickup_id,goods_id'; $dd = Db::query($strq); //---组装数组--- if ($dd){ foreach ($dd as $ku => $vu) { $ypkid=$vu['pickup_id']; $ypgid=$vu['goods_id']; $ddd[$ypkid.$ypgid]=$vu['sum0']; } } } $now=time(); $obj = M('activitylist')->where(['is_end' => 0, 'good_object' => 0, 'prom_type'=>3, 'store_id' => getMobileStoId()]) ->where('s_time<'.$now.' and e_time>'.$now) ->field('act_id as id,goods_listid,prom_type')->find(); $user = $this->user; $mz_switch = tpCache('shopping.is_beauty',$stoid);//美妆开关 $rank_switch = tpCache('shopping.rank_switch',$stoid);//等级开关 /*--库存判断和活动判断--*/ foreach ($garr as $k => $value) { /*--商品的库存和活动不能过期--*/ $ginfo = M("goods")->where("goods_id", $value['goods_id'])->find(); if ($value['prom_type']==3){ $pro = M("prom_goods")->where("id", $value['prom_id']) ->where('store_id',$stoid)->where('is_end',0) ->field("good_object") ->find(); if(empty($pro)) { $this->gopayerr("{$ginfo['goods_name']} 此商品活动已经变化", $stoid); } if($pro['good_object']>0){ //如果不是普通购买 if($value['is_integral_normal']!=1 && $value['is_pd_normal']!=1){ if($value['prom_type']!=$ginfo['prom_type'] && $value['prom_id']!=$ginfo['prom_id'] && $value['is_gift']==0 ) { $this->gopayerr("{$ginfo['goods_name']} 此商品活动已经变化", $stoid); } } } }else{ //如果不是普通购买 if($value['is_integral_normal']!=1 && $value['is_pd_normal']!=1) { if ($value['prom_type'] != 5 && $value['prom_type'] != $ginfo['prom_type'] && $value['prom_id'] != $ginfo['prom_id'] && $value['is_gift']==0) { $this->gopayerr("{$ginfo['goods_name']} 此商品活动已经变化", $stoid); } } } if ($ginfo['prom_type'] == 0 && empty($obj)){ if (!empty($mz_switch) && $user['is_mzvip'] == 1 && $ginfo['mz_price'] > 0){ $ginfo['shop_price'] = $ginfo['mz_price']; } if (!empty($rank_switch)){ if (!empty($user['card_field']) && $ginfo[$user['card_field']] > 0 && strtotime($user['card_expiredate'])>time()){ $ginfo['shop_price'] = $ginfo[$user['card_field']]; } } } /*--线下库存的序列key--*/ $bkey = $value['pick_id'] . $value['goods_id']; //商品参与活动查看 if ($value['prom_type'] > 0 && $value['member_goods_price'] > 0 && $value['is_collocation'] == 0 && $value['is_integral_normal']!=1 && $value['is_pd_normal']!=1 && $value['is_gift']==0) { if (!empty($obj) && empty($ginfo['prom_type'])){ $ginfo['prom_type']=3; $ginfo['prom_id']=$obj['id']; } $ginfo['prom_type']=$value['prom_type']; $ginfo['prom_id']=$value['prom_id']; $prom = get_goods_promotion1($ginfo, null, $this->user_id); if ($prom['is_end'] == 1) { //return array('status' => -4, 'msg' => "{$ginfo['goods_name']} 此商品活动已经结束", 'result' => ''); $this->gopayerr2("{$ginfo['goods_name']} 此商品活动已经结束", $stoid); } if ($prom['is_end'] == 2) { //return array('status' => -4, 'msg' => "{$ginfo['goods_name']} 此商品已经售完", 'result' => ''); $this->gopayerr2("{$ginfo['goods_name']} 此商品已经售完", $stoid); } if ($prom['is_end'] == 3) { //return array('status' => -4, 'msg' => "{$ginfo['goods_name']} 此活动商品超出限购数量", 'result' => ''); $this->gopayerr2("{$ginfo['goods_name']} 此活动商品超出限购数量", $stoid); } if ($value['prom_type'] == 1) { if ($value['goods_num'] > $prom['buy_limit']) { //return array('status' => -4, 'msg' => "{$ginfo['goods_name']} 此活动商品超出限购数量",'result' => ''); $this->gopayerr2("{$ginfo['goods_name']} 此活动商品超出限购数量", $stoid); } } if ($value['member_goods_price'] != $prom['price'] && $value['prom_type'] != 3 && $value['prom_type'] != 5) { //return array('status' => -4, 'msg' => "商品价格已经变化", 'result' => ''); $this->gopayerr2("{$ginfo['goods_name']} 商品价格已经变化1", $stoid); } if ($value['prom_type'] == 1 || $value['prom_type'] == 2 || $value['prom_type'] == 4 || $value['prom_type'] == 6) { if ($value['goods_num'] > $ginfo['store_count']) { //return array('status' => -4, 'msg' => "库存不足", 'result' => ''); $this->gopayerr2("{$ginfo['goods_name']} 库存不足", $stoid); } } else { if ($sales_rules == 1) { if ($value['goods_num'] > $ginfo['store_count']) { //return array('status' => -4, 'msg' => "库存不足", 'result' => ''); $this->gopayerr2("{$ginfo['goods_name']} 库存不足", $stoid); } } else if ($sales_rules == 2) { if ($value['goods_num']+$ddd[$bkey]> $count_arr[$bkey]) { //return array('status' => -4, 'msg' => "线下库存不足", 'result' => ''); $this->gopayerr2("{$ginfo['goods_name']} 库存不足", $stoid); } } } } else { if ($value['member_goods_price'] > 0) { if ($sales_rules == 1) { if ($value['goods_num'] > $ginfo['store_count']) { //return array('status' => -4, 'msg' => "库存不足", 'result' => ''); $this->gopayerr2("{$ginfo['goods_name']} 库存不足", $stoid); } } else if ($sales_rules == 2) { if ($value['goods_num']+$ddd[$bkey] > $count_arr[$bkey]) { //return array('status' => -4, 'msg' => "线下库存不足", 'result' => ''); $this->gopayerr2("{$ginfo['goods_name']} 库存不足", $stoid); } } /*--判断价格是否发生变化---*/ if ($value['member_goods_price'] != $ginfo['shop_price'] && $value['is_collocation'] == 0 && $value['is_gift']==0) { $curprice=$ginfo['shop_price']; //如果有美妆价和启用,大于0 if ($ginfo['mz_price'] > 0 && !empty($user['is_mzvip']) && !empty($mz_switch)) { $curprice = $ginfo['mz_price']; } //如果有等级价和启用,大于0 if ($rank_switch) { if ($user['card_field'] && strtotime($user['card_expiredate']) > time() && $ginfo[$user['card_field']] > 0) { $curprice = $ginfo[$user['card_field']]; } } if($curprice!=$value['member_goods_price'] && $value['is_integral_normal']!=1 && $value['is_pd_normal']!=1) { //return array('status' => -4, 'msg' => "商品价格已经变化", 'result' => ''); $this->gopayerr2("{$ginfo['goods_name']} 商品价格已经变化2", $stoid); } } } } } //tpshop 订单支付提交 $pay_radio = $_REQUEST['pay_radio']; $config_value = parse_url_param($pay_radio); // 类似于 pay_code=alipay&bank_code=CCB-DEBIT 参数 //微信JS支付 if ($this->pay_code == 'weixin' && $_SESSION['openid'] && strstr($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger')) { $code_str = $this->payment->getJSAPI2($orderno); if (!empty($code_str['code'])) { $text = $code_str['msg']; $url = U("mobile/payment/pay_error2", array("stoid" => getMobileStoId(), 'err' => $text, 'ordno' => $orderno)); $this->redirect($url); } else { exit($code_str); } } else { //$code_str = $this->payment->get_code($order,$config_value); $this->error('暂时只支持微信支付!', U("Mobile/index/index", array('stoid' => getMobileStoId()))); } }else{ M('order')->where("parent_sn", $orderno) ->save(array('pay_code' => $this->pay_code, 'pay_name' => $payment_arr[$this->pay_code])); $order = M('order')->where("parent_sn", $orderno)->select(); if ($order[0]['pay_status'] == 1) { $this->error('此订单,已完成支付!'); } if ($order[0]['order_status'] == 3) { $this->error('此订单已经取消!'); } /*--如果订单中有用积分,判断积分是否足够--*/ if ($order[0]['integral'] > 0) { //$tk = M("store")->where("store_id", getMobileStoId())->field("api_token")->find(); $tk = tpCache("shop_info",getMobileStoId()); $userd = M("users")->where('user_id', $order[0]['user_id'])->find(); //$map['Id'] = array('=', $userd['erpvipid']); //$rs = getApiData('wxd.vip.vipinfo.list.get', $tk['api_token'], null, $map); //$d = json_decode($rs, true); //$integ = $d['data'][0]['Integral']; if(empty($userd['erpvipid'])) $this->gopayerr2("您非线下会员", $stoid); $d=get_erpvipinfo($userd['erpvipid'],$tk['ERPId']); if(!$d) $this->gopayerr2("您的积分不足【01】", $stoid); $integ=$d['Integral']; if ($order[0]['integral'] > $integ) { $this->gopayerr("您的积分不足", $stoid); } } $garr = ord_goods_he($orderno); if (empty($garr)) { $this->gopayerr("订单获取异常", $stoid); } //$srule = M('store_config')->where('store_id', $stoid)->find(); //销售规则 $sales_rules = tpCache('basic.sales_rules', $stoid); /*----如果是线下库存,获取线下库存,预出库库存----*/ $ddd = []; if ($sales_rules == 2) { $count_arr = getcountarr($garr, $stoid); /*--预出库库存--*/ $gidarr=get_arr_column($garr,'goods_id'); $fgid0=implode(',',$gidarr); $strq = 'select pickup_id,goods_id,sum(out_qty) as sum0 from __PREFIX__erp_yqty where goods_id in(' . $fgid0 . ') and store_id='.$stoid.' GROUP BY pickup_id,goods_id'; $dd = Db::query($strq); //---组装数组--- if ($dd){ foreach ($dd as $ku => $vu) { $ypkid=$vu['pickup_id']; $ypgid=$vu['goods_id']; $ddd[$ypkid.$ypgid]=$vu['sum0']; } } } $obj = M('prom_goods')->where(['is_end' => 0, 'good_object' => 0, 'store_id' => $stoid])->field('id')->find(); $user = $this->user; $mz_switch = tpCache('shopping.is_beauty',$stoid);//美妆开关 $rank_switch = tpCache('shopping.rank_switch',$stoid);//等级开关 /*--库存判断和活动判断--*/ foreach ($garr as $k => $value) { /*--商品的库存和活动不能过期--*/ $ginfo = M("goods")->where("goods_id", $value['goods_id'])->find(); if ($ginfo['prom_type'] == 0 && empty($obj)){ if (!empty($mz_switch) && $user['is_mzvip'] == 1 && $ginfo['mz_price'] > 0){ $ginfo['shop_price'] = $ginfo['mz_price']; } if (!empty($rank_switch)){ if (!empty($user['card_field']) && $ginfo[$user['card_field']] > 0 && strtotime($user['card_expiredate']) > time()){ $ginfo['shop_price'] = $ginfo[$user['card_field']]; } } } /*--线下库存的序列key--*/ $bkey = $value['pick_id'] . $value['goods_id']; //商品参与活动查看 if ($value['prom_type'] > 0 && $value['member_goods_price'] > 0 && $value['is_collocation'] == 0) { if (!empty($obj) && empty($ginfo['prom_type'])){ $ginfo['prom_type']=3; $ginfo['prom_id']=$obj['id']; } $ginfo['prom_type']=$value['prom_type']; $ginfo['prom_id']=$value['prom_id']; $prom=null; if($order[0]['is_pt_tz']=0 && $order[0]['pt_prom_id']>0) $prom = get_pt_promotion1($ginfo, null, $user['user_id'],$order[0]['pt_listno']); else $prom = get_goods_promotion1($ginfo, null, $user['user_id']); mlog(json_encode($prom),"getCode/".$stoid); mlog(json_encode($ginfo),"getCode/".$stoid); if ($prom['is_end'] == 1) { //return array('status' => -4, 'msg' => "{$ginfo['goods_name']} 此商品活动已经结束", 'result' => ''); $this->gopayerr("{$ginfo['goods_name']} 此商品活动已经结束", $stoid); } if ($prom['is_end'] == 2) { //return array('status' => -4, 'msg' => "{$ginfo['goods_name']} 此商品已经售完", 'result' => ''); $this->gopayerr("{$ginfo['goods_name']} 此商品已经售完", $stoid); } if ($prom['is_end'] == 3) { //return array('status' => -4, 'msg' => "{$ginfo['goods_name']} 此活动商品超出限购数量", 'result' => ''); $this->gopayerr("{$ginfo['goods_name']} 此活动商品超出限购数量", $stoid); } if ($value['prom_type'] == 1) { if ($value['goods_num'] > $prom['buy_limit'] && $prom['buy_limit0']>0) { //return array('status' => -4, 'msg' => "{$ginfo['goods_name']} 此活动商品超出限购数量",'result' => ''); $this->gopayerr("{$ginfo['goods_name']} 此活动商品超出限购数量", $stoid); } } if ($value['member_goods_price'] != $prom['price'] && $value['prom_type'] != 3) { //return array('status' => -4, 'msg' => "商品价格已经变化", 'result' => ''); $this->gopayerr("{$ginfo['goods_name']} 商品价格已经变化", $stoid); } if ($value['prom_type'] == 1 || $value['prom_type'] == 2 || $value['prom_type'] == 4 || $value['prom_type'] == 6) { if ($value['goods_num'] > $ginfo['store_count']) { //return array('status' => -4, 'msg' => "库存不足", 'result' => ''); $this->gopayerr("{$ginfo['goods_name']} 库存不足", $stoid); } } else { if ($sales_rules == 1) { if ($value['goods_num'] > $ginfo['store_count']) { //return array('status' => -4, 'msg' => "库存不足", 'result' => ''); $this->gopayerr("{$ginfo['goods_name']} 库存不足", $stoid); } } else if ($sales_rules == 2) { if ($value['goods_num']+$ddd[$bkey]> $count_arr[$bkey]) { //return array('status' => -4, 'msg' => "线下库存不足", 'result' => ''); $this->gopayerr("{$ginfo['goods_name']} 库存不足", $stoid); } } } } else { if ($value['member_goods_price'] > 0) { if ($sales_rules == 1) { if ($value['goods_num'] > $ginfo['store_count']) { //return array('status' => -4, 'msg' => "库存不足", 'result' => ''); $this->gopayerr("{$ginfo['goods_name']} 库存不足", $stoid); } } else if ($sales_rules == 2) { if ($value['goods_num']+$ddd[$bkey] > $count_arr[$bkey]) { //return array('status' => -4, 'msg' => "线下库存不足", 'result' => ''); $this->gopayerr("{$ginfo['goods_name']} 库存不足", $stoid); } } /*--判断价格是否发生变化---*/ if ($value['member_goods_price'] != $ginfo['shop_price'] && $value['is_collocation'] == 0) { $curprice=$ginfo['shop_price']; //如果有美妆价和启用,大于0 if ($ginfo['mz_price'] > 0 && !empty($user['is_mzvip']) && !empty($mz_switch)) { $curprice = $ginfo['mz_price']; } //如果有等级价和启用,大于0 if ($rank_switch) { if ($user['card_field'] && strtotime($user['card_expiredate']) > time() && $ginfo[$user['card_field']] > 0) { $curprice = $ginfo[$user['card_field']]; } } if($curprice!=$value['member_goods_price']) { //return array('status' => -4, 'msg' => "商品价格已经变化", 'result' => ''); $this->gopayerr("{$ginfo['goods_name']} 商品价格已经变化", $stoid); } } } } } //tpshop 订单支付提交 $pay_radio = $_REQUEST['pay_radio']; $config_value = parse_url_param($pay_radio); // 类似于 pay_code=alipay&bank_code=CCB-DEBIT 参数 //微信JS支付 if ($this->pay_code == 'weixin' && $_SESSION['openid'] && strstr($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger')) { //如果是拼单的订单 if ($order[0]['pt_prom_id']) { mlog('pt_1','getCode',$order[0]['store_id']); $code_str = $this->payment->getJSAPI3($orderno); mlog('pt_2','getCode',$order[0]['store_id']); if (!empty($code_str['code'])) { mlog('pt_3','getCode',$order[0]['store_id']); $text = $code_str['msg']; mlog('pt_4'.$text,'getCode',$order[0]['store_id']); $url = U("mobile/team/team_success/payfail/1", array("stoid" => getMobileStoId(),'orderno' => $orderno)); $this->redirect($url); } else { exit($code_str); } }else{ $code_str = $this->payment->getJSAPI($orderno); if (!empty($code_str['code'])) { $text = $code_str['msg']; $url = U("mobile/payment/pay_error", array("stoid" => getMobileStoId(), 'err' => $text, 'ordno' => $orderno)); $this->redirect($url); } else { exit($code_str); } } } else { //$code_str = $this->payment->get_code($order,$config_value); $this->error('暂时只支持微信支付!', U("Mobile/index/index", array('stoid' => getMobileStoId()))); } } $this->assign('code_str', $code_str); $this->assign('order_id', $orderno); return $this->fetch('payment', getMobileStoId()); // 分跳转 和不 跳转 } /** * tpshop 提交支付方式 */ public function getCode_pt() { $stoid = getMobileStoId(); //C('TOKEN_ON',false); // 关闭 TOKEN_ON header("Content-type:text/html;charset=utf-8"); $orderno = I('orderno'); // 订单id // 修改订单的支付方式 $order = M('order')->where("order_sn", $orderno)->select(); if ($order[0]['pay_status'] == 1) { $this->error('此订单,已完成支付!'); } if($order[0]['pt_tail_money']<=0) { update_pt_wk($orderno, $stoid, $order[0], 1); $go_url = U('Mobile/team/team_success',array('stoid'=>$order[0]['store_id'],'orderno'=>$order[0]['order_sn'])); $this->redirect($go_url); } $user = $this->user; //主要是要判断付尾款的时间是否到期 $wda['team_id']=$order[0]['pt_prom_id']; $wda['listno']=$order[0]['pt_listno']; $uu = M("teamgroup")->where($wda)->where('store_id',$stoid)->find(); if($uu){ $v=$order[0]; /*------ //如果付尾款的时间也过期了 $stoid=$stoid; $refund_type=tpCache('basic.refund_type',$stoid); //退到余额 if($refund_type==0){ $user_money=$v['order_amount']+$v['user_money']+$v['pt_tail_money']; $sql = "update wxd_users set user_money=user_money+" . $user_money . " where user_id=" . $v['user_id']; $rs1 = Db::execute($sql); if($rs1) { if ($user_money > 0) { $odata['user_id'] = $v['user_id']; $odata['create_time'] = time(); $odata['money'] = $user_money; $odata['remark'] = "退款"; $odata['store_id'] = $v['store_id']; $odata['order_sn'] = $v['order_sn']; $odata['status'] = 1; $odata['type'] = 1; M('withdrawals')->save($odata); } }else{ mlog("退款到余额失败,",'refund/'.$stoid); } } //原路返回 else if($refund_type==1) { $wxmoney=0; $usrmoney=0; if($v['tail_pay_type']){ $wxmoney=$v['order_amount']; $usrmoney=$v['order_amount']+$v['pt_tail_money']; }else{ $wxmoney=$v['order_amount']+$v['pt_tail_money']; $usrmoney=$v['order_amount']; } if($v['order_amount']) { include_once "plugins/payment/weixin/weixin.class.php"; $wx=new \weixin(); $ordno = $v['order_sn']; $total_fee = $wxmoney; $refund_fee = $total_fee; //$erpid = tpCache('shop_info.ERPId', $stoid); $path = BASE_PATH . 'public/cert/' . $stoid . '/'; try { $wx->setCong($v['store_id']); $rs = $wx->refund($ordno, $total_fee, $refund_fee, $path); if ($rs['return_code'] == 'FAIL') { mlog("退款失败," . $rs['return_msg'], 'refund/' . $stoid); } } catch (\Exception $e) { mlog("退款签名失败," . $rs['return_msg'], 'refund/' . $stoid); } } //退到余额 if($v['user_money']){ $user_money=$usrmoney; $sql = "update wxd_users set user_money=user_money+" . $user_money . " where user_id=" . $v['user_id']; $rs1 = Db::execute($sql); if($rs1) { if ($user_money > 0) { $odata['user_id'] = $v['user_id']; $odata['create_time'] = time(); $odata['money'] = $user_money; $odata['remark'] = "退款"; $odata['store_id'] = $v['store_id']; $odata['order_sn'] = $v['order_sn']; $odata['status'] = 1; $odata['type'] = 1; M('withdrawals')->save($odata); } }else{ mlog("退款到余额失败,",'refund/'.$stoid); } } } ----*/ if($uu['wk_end_time'] getMobileStoId())); $this->error('尾款时间已到期',$url); } }else{ $url = U("mobile/user/order_list", array("stoid" => getMobileStoId())); $this->error('未找到拼团',$url); } //tpshop 订单支付提交 $pay_radio = $_REQUEST['pay_radio']; $config_value = parse_url_param($pay_radio); // 类似于 pay_code=alipay&bank_code=CCB-DEBIT 参数 //微信JS支付 if ($this->pay_code == 'weixin' && $_SESSION['openid'] && strstr($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger')) { //如果是拼单的订单 if ($order[0]['pt_prom_id']) { mlog('1','getCode_pt/'.$stoid); $code_str = $this->payment->getJSAPI_pt_wk($orderno); if (!empty($code_str['code'])) { $text = $code_str['msg']; mlog('2'.$text,'getCode_pt/'.$stoid); $url = U("mobile/user/order_list", array("stoid" => getMobileStoId())); $this->redirect($url); } else { exit($code_str); } } } else { //$code_str = $this->payment->get_code($order,$config_value); $this->error('暂时只支持微信支付!', U("Mobile/index/index", array('stoid' => getMobileStoId()))); } $this->assign('code_str', $code_str); $this->assign('order_id', $orderno); return $this->fetch('payment', getMobileStoId()); // 分跳转 和不 跳转 } public function getPay() { //手机端在线充值 //C('TOKEN_ON',false); // 关闭 TOKEN_ON header("Content-type:text/html;charset=utf-8"); $order_id = I('order_id'); //订单id $recharge_type = I('recharge_type/d'); //充值类型,0余额充值 1积分充值 $jid = I('seleid'); //购买的积分充值id $num = I('buynum/d'); //购买的积分充值数量 $user = session('user'); $getaccdb=strtoupper($this->pm_erpid);//账套 switch ($recharge_type) { //余额充值 case 0: $data['recharge_type'] = $recharge_type; if ($order_id > 0) { M('recharge')->where(array('order_id' => $order_id, 'user_id' => $user['user_id']))->save($data); } else { $where['Id'] = array('=', $jid); $tk['api_token']=tpCache('shop_info.api_token',getMobileStoId()); $aa = getApiData("wxd.vip.addactlist", $tk['api_token'], null, $where); mlog($aa . ':' . $jid . ':' . getMobileStoId() . ':' . $tk['api_token'], "777ttt"); $aa = json_decode($aa, true); if ($aa["data"][0]["sQty"]) { $getbuy_num = $aa["data"][0]["sQty"]; } else { $getbuy_num =$aa["data"][0]["Qty"]; } if ($getbuy_num && $getbuy_num>0) { $user_buy_count = M('recharge')->where(array('store_id' => getMobileStoId(), 'user_id' => $user['user_id'], 'yucun_id' => $aa["data"][0]['Id'], 'pay_status' => 1))->count(); if ($user_buy_count >= $getbuy_num) { $this->error('提交失败,已超过限制充值次数!', U("Mobile/User/pre_deposit", array('stoid' => getMobileStoId()))); exit; } } $str=number_format($aa["data"][0]["BeginSum"], 2);//保留俩位小数 $str0=str_replace(',','',$str); $data["price"] =$str0; $data["integral_remark"] = "线上会员充值ERP预存款"; $data["yucun_id"] = $aa["data"][0]["Id"]; $data["yucun_Advance_Id"] = $aa["data"][0]["AdvanceItemId"]; $data["account"] = $aa["data"][0]["BeginSum"] * $num; $data["order_sn"] = $getaccdb.'_vop' . date("YmdHis") . rand(1000, 9999);//"vop" . date("YmdHis") . rand(1000, 9999); . get_rand_str(10, 0, 1) $this->pay_code = 'weixin'; $data['user_id'] = $user['user_id']; $data['nickname'] = $user['nickname']; $data['ctime'] = time(); $data['store_id'] = getMobileStoId(); $data['num'] = $num; $order_id = M('recharge')->add($data); } break; //积分充值 case 1: $mon = I("selemon"); $integ = I("seleinteg"); $num = I("buynum/d", 1); $integ=str_replace(",","",$integ); $mon=str_replace(",","",$mon); $integ = number_format($integ,2,".",""); $mon =number_format($mon,2,".",""); /*--规则检验--*/ $istrue = 0; if ($this->pm_erpid)//账套 { $tk['api_token'] = tpCache("shop_info.api_token", getMobileStoId()); $rs = getApiData("wxd.vip.intertosum", $tk['api_token']); if ($rs) { $d = json_decode($rs, true); foreach ($d['data'] as $k => $v) { if ($mon == number_format($v['ToSum'], 2, ".", "") && $integ == number_format($v['Integral'], 2, ".", "")) { $istrue = 1; break; } } } } else { $point_rate=json_decode(tpCache('shopping.point_rate',getMobileStoId()),true); $getIntegral=0; $getToSum=0; if ($point_rate['money']) { $getToSum=$point_rate['money']; } if ($point_rate['integral']) { $getIntegral=$point_rate['integral']; } if ($mon == number_format($getToSum, 2, ".", "") && $integ == number_format($getIntegral, 2, ".", "")) { $istrue = 1; } } if ($istrue == 0) { $this->error('提交失败,参数有误!', U("Mobile/User/points", array('stoid' => getMobileStoId()))); exit; } $ramark = '积分充值'; $account = $mon * $num; $data['account'] = $account; $this->pay_code = 'weixin'; if ($order_id > 0) { M('recharge')->where(array('order_id' => $order_id, 'user_id' => $user['user_id']))->save($data); } else { $data['user_id'] = $user['user_id']; $data['nickname'] = $user['nickname']; $data['order_sn'] = $getaccdb.'_voi' . date("YmdHis") . rand(1000, 9999); $data['ctime'] = time(); $data['recharge_type'] = $recharge_type; $data['store_id'] = getMobileStoId(); $data['price'] = $mon; $data['integral_remark'] = $ramark; $data['integral'] = $integ; $data['num'] = $num; $order_id = M('recharge')->add($data); } break; //购买服务卡 case 2: $data['recharge_type'] = $recharge_type; if ($order_id > 0) { M('recharge')->where(array('order_id' => $order_id, 'user_id' => $user['user_id']))->save($data); } else { $where['SM_ItemManage.Id'] = array('=', $jid); $tk['api_token']=tpCache('shop_info.api_token',getMobileStoId()); $aa = getApiData("wxd.pos.smitemanage.list.get", $tk['api_token'], null, $where); mlog($aa . ':' . $jid . ':' . getMobileStoId() . ':' . $tk['api_token'], "777ttt"); $aa = json_decode($aa, true); if ($aa && $aa["code"] == 1) { $data["price"] = number_format($aa["data"][0]["Price"], 2); //金额 $data["integral_remark"] = "线上会员购买服务卡"; $data["yucun_id"] = $aa["data"][0]["Id"]; $data["account"] = $aa["data"][0]["Price"] * 1; $data["num"] = $aa["data"][0]["EndDate"]; $data['integral'] = $aa["data"][0]["Qty"]; $data["order_sn"] = $getaccdb.'_ser' . date("YmdHis") . rand(1000, 9999);//"vop" . date("YmdHis") . rand(1000, 9999); $this->pay_code = 'weixin'; $data['user_id'] = $user['user_id']; $data['nickname'] = $user['nickname']; $data['ctime'] = time(); $data['store_id'] = getMobileStoId(); $order_id = M('recharge')->add($data); } } break; //等级卡 3:购买 case 3: $data['recharge_type'] = $recharge_type; if ($order_id > 0) { M('recharge')->where(array('order_id' => $order_id, 'user_id' => $user['user_id']))->save($data); } else { $param=I('post.'); $tt=strtotime("-10 minute"); /*--- 判断是不是有购买一次,十分钟前---*/ $is_buy=M("recharge") ->where("cardid",$param["cardid"]) ->where("user_id",$user['user_id']) ->where("recharge_type",3) ->where("ctime>".$tt) ->where("pay_status",1) ->find(); if($is_buy){ $this->error('为避免您重复购买,请稍后再买!', U("Mobile/index/index", array('stoid' => getMobileStoId()))); } $fileds_key = md5($param["cardid"] . $param['fee'] . $param["ex_days"] . getErpKey()); if ($param['keys'] != $fileds_key) $this->error('参数错误', U("Mobile/index/index", array('stoid' => getMobileStoId()))); if($param['code']) { //检验邀请人 $recommon = M("users")->where("mobile", $param['code'])->where('store_id', getMobileStoId())->find(); if (empty($recommon)) $this->error('邀请人没有绑定会员', U("Mobile/index/index", array('stoid' => getMobileStoId()))); if (empty($recommon['card_field'])) $this->error('邀请人不是plus会员', U("Mobile/index/index", array('stoid' => getMobileStoId()))); $end = strtotime($recommon['card_expiredate']); if ($end < time()) { $this->error('邀请人plus会员已经过期', U("Mobile/index/index", array('stoid' => getMobileStoId()))); } } //填充有效期 $data["days"] = $param["ex_days"]; //填充有效期 $data["days"] = $param["ex_days"]; $data["integral_remark"] = strtolower($param["newcorrprice"]); $data["cardid"] = $param["cardid"]; $data["account"] = $param['fee']; $data["recommon"]=$param['code']; $data['serviceman']=$param['staff']; $data["order_sn"] = $getaccdb.'_vlc' . date("YmdHis") . rand(1000, 9999);//"vop" . date("YmdHis") . rand(1000, 9999); . get_rand_str(10, 0, 1) $this->pay_code = 'weixin'; $data['user_id'] = $user['user_id']; $data['nickname'] = $user['nickname']; $data['ctime'] = time(); $data['store_id'] = getMobileStoId(); $order_id = M('recharge')->add($data); } break; //等级卡 4:续费 case 4: $data['recharge_type'] = $recharge_type; if ($order_id > 0) { M('recharge')->where(array('order_id' => $order_id, 'user_id' => $user['user_id']))->save($data); } else { $param = I('post.'); $fileds_key = md5($param["cardid"] . $param['fee'] . getErpKey()); if ($param['keys'] != $fileds_key) $this->error('参数错误', U("Mobile/index/index", array('stoid' => getMobileStoId()))); $data["integral_remark"] = strtolower($param["newcorrprice"]); $data["cardid"] = $param["cardid"]; $data["account"] = $param['fee']; $data["recommon"] = $param['code']; $data['serviceman'] = $param['staff']; $data["order_sn"] = $getaccdb.'_vlc' . date("YmdHis") . rand(1000, 9999);//"vop" . date("YmdHis") . rand(1000, 9999); . get_rand_str(10, 0, 1) $this->pay_code = 'weixin'; $data['user_id'] = $user['user_id']; $data['nickname'] = $user['nickname']; $data['ctime'] = time(); $data['store_id'] = getMobileStoId(); $order_id = M('recharge')->add($data); } break; //购买礼包 case 5: $lbid=I('lbid'); $storeid=getMobileStoId(); $libao=M('libao_form')->where('store_id='.$storeid.' and startime<='.time().' and endtime>='.time().' and id='.$lbid)->select(); $lbnumber=$getaccdb.'_lb'. date("YmdHis") . rand(1000, 9999); $data['user_id']= $user['user_id']; $data['store_id']=getMobileStoId(); $data['lbid']=$lbid; $data['expdate']=strtotime('+'.$libao[0]['expday'].' day',time()); $data['number']=$lbnumber; $data['paytype']=2; $data['fbillstate']=0; $data['add_time']=time(); $order_id=M('libao_formvip')->add($data); $list=M('libao_list')->where(array('store_id'=>$storeid,'lbid'=>$lbid))->select(); if($list) { for ($i=0;$iadd($data); } } break; case 6: $order_sn=I("order_sn"); $ord=M('marketing_user_buyreceive_form')->where("order_sn", $order_sn)->find(); if(empty($ord)){ $this->error('未找到订单!'); } if($ord['pay_state']==1){ $this->error('订单已经支付!'); } if($ord['pay_state']==-1){ $this->error('订单已经取消!');} $code_str = $this->payment->getJSAPI_new_lb($ord); exit($code_str); break; default: break; } if ($order_id) { if($recharge_type==5) { $order=M('libao_formvip')->alias('a')->where('a.id',$order_id)->field('a.*,a.fbillstate as pay_status,number as order_sn')->find(); } else { $order = M('recharge')->where("order_id", $order_id)->find(); } if (is_array($order) && $order['pay_status'] == 0) { $order['order_amount'] = $order['account']; $pay_radio = $_REQUEST['pay_radio']; $config_value = parse_url_param($pay_radio); // 类似于 pay_code=alipay&bank_code=CCB-DEBIT 参数 if($recharge_type!=5) { $payment_arr = M('Plugin')->where("`type` = 'payment'")->getField("code,name"); M('recharge')->where("order_id", $order_id)->save(array('pay_code' => $this->pay_code, 'pay_name' => $payment_arr[$this->pay_code])); } //微信JS支付 if ($this->pay_code == 'weixin' && $_SESSION['openid'] && strstr($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger')) { switch ($recharge_type) { //余额充值 case 0: $code_str = $this->payment->getJSAPI_VOP($order['order_sn']); exit($code_str); break; //积分充值 case 1: $code_str = $this->payment->getJSAPI_VOI($order['order_sn']); exit($code_str); break; //购买服务卡 case 2: $code_str = $this->payment->getJSAPI_SER($order['order_sn']); exit($code_str); break; //等级卡 3:购买 case 3: $code_str = $this->payment->getJSAPI_VLC($order['order_sn']); exit($code_str); break; //等级卡 4:续费 case 4: $code_str = $this->payment->getJSAPI_VLC($order['order_sn']); exit($code_str); break; //购买礼包 case 5: $code_str = $this->payment->getJSAPI_LB($order['order_sn']); exit($code_str); break; default: $code_str = $this->payment->getJSAPI($order['order_sn']); exit($code_str); break; } } else { if ($recharge_type == 2) { $this->error('暂时只支持微信支付!', U("Mobile/User/shopping_card", array('stoid' => getMobileStoId()))); } else if($recharge_type==5) { $this->error('暂时只支持微信支付!', U("Mobile/Libao/index", array('stoid' => getMobileStoId()))); } else { $this->error('暂时只支持微信支付!', U("Mobile/User/points", array('stoid' => getMobileStoId()))); } } } else { // mlog('订单ID:'.json_encode($order).' 支付状态:'.$order['pay_status'].' ID:'.$order_id,'libaolog'); $this->error('此充值订单,已完成支付!', U("Mobile/index/index", array('stoid' => getMobileStoId()))); } } else { $this->error('提交失败,参数有误!', U("Mobile/index/index", array('stoid' => getMobileStoId()))); } //$this->assign('code_str', $code_str); $this->assign('order_id', $order_id); return $this->fetch('recharge', getMobileStoId()); //分跳转 和不 跳转 } // 服务器点对点 // http://www.tp-shop.cn/index.php/Home/Payment/notifyUrl public function notifyUrl() { $this->payment->response(); exit(); } // 页面跳转 // http://www.tp-shop.cn/index.php/Home/Payment/returnUrl public function returnUrl() { $result = $this->payment->respond2(); // $result['order_sn'] = '201512241425288593'; if (stripos($result['order_sn'], 'recharge') !== false || stripos($result['order_sn'], 'vop') !== false || stripos($result['order_sn'], 'vlc') !== false) { $order = M('recharge')->where("order_sn", $result['order_sn'])->find(); $this->assign('order', $order); if ($result['status'] == 1) return $this->fetch('recharge_success', getMobileStoId()); else return $this->fetch('recharge_error', getMobileStoId()); exit(); } $order = M('order')->where("order_sn", $result['order_sn'])->find(); $this->assign('order', $order); if ($result['status'] == 1) return $this->fetch('success', getMobileStoId()); else return $this->fetch('error', getMobileStoId()); } //支付成功 public function payment_success() { //判断会员是否有绑定线下,没有的话进行线下 $getopenid = $_SESSION['openid']; $stoid = I('stoid'); $paytype=I('ptype'); //循环更新订单状态,以及库存 $pno=I('orderno'); $odr_arr=M('order')->where('parent_sn',$pno)->where('store_id',$stoid) ->where('pay_status',0) ->where('order_status=0 or order_status=1') ->field('order_amount,order_sn,pickup_id')->select(); foreach ($odr_arr as $k=>$v) { if ($v['order_amount'] <= 0) { mlog("payment_success:".$pno,"update_pay_status2/".getMobileStoId()); update_pay_status2($v['order_sn'], 1); } } //结算的数据 $order=M('order')->where('order_sn',$pno)->where('store_id',$stoid)->select(); $order_amount=0; $user_money=0; //判断是不是单个商品的订单 if(!empty($order)) { //单个的商品结算的 $order = $order[0]; //获取余额及微信的价格 计算总价 $total_price=$order["order_amount"]+$order["user_money"]; $this->assign('order', $order); $this->assign('total_price', $total_price); if ($order['exp_type'] == 1) { $pick_up = M('pick_up')->where('pickup_id', $order['pickup_id'])->where('store_id', $stoid)->select(); $pick_up = $pick_up[0]; $this->assign('pick_up', $pick_up); } }else{ //多个商品的时候 $order_parent=M('order')->where('parent_sn',$pno)->where('store_id',$stoid)->select(); //php创建数组 $pick_arr=array(); //获取余额及微信的价格 foreach ($order_parent as $kl => $vl) { $order_amount+=$vl['order_amount']; $user_money+=$vl['user_money']; if ( $vl['exp_type'] == 1) { $pick_up = M('pick_up')->where('pickup_id', $vl['pickup_id'])->where('store_id', $stoid)->select(); $pick_up = $pick_up[0]; $pick_arr['pickup_name']=$pick_up['pickup_name']; $pick_arr['fulladdress']=$pick_up['fulladdress']; //添加数组参数 $order_parent[$kl]['pick_arr']=$pick_arr; } } //获取余额及微信的价格 计算总价 $total_price=$order_amount+$user_money; $this->assign('order_parent',$order_parent); $this->assign('total_price', $total_price); } if($paytype) { $this->assign('type', $paytype); } else{ if ($stoid && $getopenid) { $user_info = M('users')->alias('a') ->join(' store b', 'a.store_id=b.store_id', 'left') ->field("a.user_id,a.openid,a.mobile,a.erpvipid,a.erpvipno,b.api_token") ->where(array('a.openid' => $getopenid, 'a.store_id' => $stoid))->find(); if ($user_info && $user_info['mobile'] && empty($user_info['erpvipid'])) { $user_data = array(); $user_data['MobileTel'] = $user_info['mobile']; $getpickup_id=0; if ($odr_arr && $odr_arr[0]['pickup_id']) { $getpickup_id=$odr_arr[0]['pickup_id']; $pick = M("pick_up")->where("pickup_id", $odr_arr[0]['pickup_id'])->find(); if ($pick) { $user_data['StoragesId'] = $pick['keyid']; } } $rs = getApiData("wxd.vip.mshop.register", $user_info['api_token'], array($user_data)); if ($rs) { $rs = json_decode($rs, true); if ($rs['code'] && $rs['data']) { $new_user_info = $rs['data']; $map['erpvipid'] = $new_user_info['Id']; $map['erpvipno'] = $new_user_info['VIPNo']; if ($getpickup_id) { $map['pickup_id'] = $getpickup_id; } $falg = M('users')->where('user_id', $user_info['user_id'])->save($map); } } } } } return $this->fetch("", getMobileStoId()); } //支付成功 public function recharge_success() { $ordid = I('order_id'); $order = $ord = M('recharge')->where("order_id", $ordid)->find(); $this->assign('order', $order); $this->assign('type', $ord['recharge_type']); return $this->fetch("", getMobileStoId()); } //支付失败 public function pay_error() { //判断会员是否有绑定线下,没有的话进行线下 $getopenid = $_SESSION['openid']; $stoid = I('stoid'); if ($stoid && $getopenid) { $ord = I("ordno"); if ($ord) { $odr_arr=M('order')->where('parent_sn',$ord)->where('store_id',getMobileStoId()) ->field('order_amount,order_sn,pickup_id')->select(); } $user_info = M('users')->alias('a') ->join(' store b', 'a.store_id=b.store_id', 'left') ->field("a.user_id,a.openid,a.mobile,a.erpvipid,a.erpvipno,b.api_token") ->where(array('a.openid' => $getopenid, 'a.store_id' => $stoid))->find(); if ($user_info && $user_info['mobile'] && empty($user_info['erpvipid'])) { $getpickup_id=0; $user_data = array(); $user_data['MobileTel'] = $user_info['mobile']; if ($odr_arr && $odr_arr[0]['pickup_id']) { $getpickup_id=$odr_arr[0]['pickup_id']; $pick = M("pick_up")->where("pickup_id", $odr_arr[0]['pickup_id'])->find(); if ($pick) { $user_data['StoragesId'] = $pick['keyid']; } } $rs = getApiData("wxd.vip.mshop.register", $user_info['api_token'], array($user_data)); if ($rs) { $rs = json_decode($rs, true); if ($rs['code'] && $rs['data']) { $new_user_info = $rs['data']; $map['erpvipid'] = $new_user_info['Id']; $map['erpvipno'] = $new_user_info['VIPNo']; if ($getpickup_id) { $map['pickup_id'] = $getpickup_id; } $falg = M('users')->where('user_id', $user_info['user_id'])->save($map); } } } } $err = urldecode(urldecode(I('err'))); $this->assign('err', $err); $this->assign('ordno', $ord); return $this->fetch("payment_error", getMobileStoId()); } /*--跳转支付失败页--*/ public function gopayerr($msg, $stoid) { $url = U("mobile/payment/pay_error", array("stoid" => $stoid, 'err' => $msg, 'ordno' =>'')); $this->redirect($url); } /*--跳转支付失败页--*/ public function gopayerr2($msg, $stoid) { $url = U("mobile/payment/pay_error2", array("stoid" => $stoid, 'err' => $msg, 'ordno' =>'')); $this->redirect($url); } public function pay_lb_success(){ $stoid=I("stoid"); $orderno=I("orderno"); $ord=M("marketing_user_buyreceive_form")->where("order_sn",$orderno)->find(); $this->assign("order",$ord); $user=session("user"); $back_url=WXD_LB_URL.'MyGiftPack/MyGiftPack?stoid='.$stoid.'&userid='.$user['user_id']; $this->assign("back_url",$back_url); return $this->fetch("",$stoid); } public function pay_lb_error(){ $stoid=I("stoid"); $orderno=I("orderno"); $this->assign("orderno",$orderno); $user=session("user"); $back_url=WXD_LB_URL.'MyGiftPack/MyGiftPack?stoid='.$stoid.'&userid='.$user['user_id']; $this->assign("back_url",$back_url); return $this->fetch("",$stoid); } }