public function to_pay() { if (($_GET['pay_type'] != 'Daofu') && ($_GET['pay_type'] != 'Dianfu')) { $orderid = (isset($_GET['orderid']) ? $_GET['orderid'] : $_GET['single_orderid']); $payHandel = new payHandle($this->token, $_GET['from']); $orderInfo = $payHandel->beforePay($orderid); $price = $orderInfo['old_price']; $coupon_id = (isset($_REQUEST['coupon_id']) ? intval($_REQUEST['coupon_id']) : 0); if ($coupon_id) { $obj = new Member_card_coupon_recordModel(); $coupon = $obj->check_coupon($coupon_id, $this->wecha_id, $this->token, $price); if ($coupon['error']) { $this->error($coupon['msg']); exit(); } else { $coupon = $coupon['data']; $cpr = D('Coupon_pay_record')->where(array('orderid' => $_GET['orderid'], 'token' => $this->token, 'from' => $_GET['from'], 'wechat_id' => $this->wecha_id, 'coupon_id' => $coupon_id))->find(); if (empty($cpr)) { D('Coupon_pay_record')->add(array('orderid' => $_GET['orderid'], 'token' => $this->token, 'from' => $_GET['from'], 'wechat_id' => $this->wecha_id, 'coupon_id' => $coupon_id, 'least_cost' => $coupon['least_cost'], 'reduce_cost' => $coupon['reduce_cost'])); } if ($price <= $coupon['reduce_cost']) { $payHandel = new payHandle($_GET['token'], $_GET['from'], 'coupon'); $orderInfo = $payHandel->afterPay($orderid, $orderid, $orderid); $className = 'ThirdPay' . $_GET['from']; if (class_exists('ThirdPay' . $_GET['from'])) { $className::index($orderid, 'coupon', $orderid); } exit(); } } } } if ($_GET['pay_type'] == 'Weixin') { if (strpos(CONF_PATH, 'DataPig')) { $fileName = 'index_datapig.php'; } else if (strpos(CONF_PATH, 'PigData')) { $fileName = 'index_pigdata.php'; } else { $fileName = 'index.php'; } header('Location:/wxpay/' . $fileName . '?g=Wap&m=Weixin&a=pay&price=' . $_GET['price'] . '&orderName=' . $_GET['orderName'] . '&single_orderid=' . $_GET['orderid'] . '&showwxpaytitle=1&from=' . $_GET['from'] . '&token=' . $_GET['token'] . '&wecha_id=' . $_GET['wecha_id'] . '&platform=' . intval($_GET['platform'])); } else { header('Location:/index.php?g=Wap&m=' . $_GET['pay_type'] . '&a=pay&price=' . $_GET['price'] . '&orderName=' . $_GET['orderName'] . '&single_orderid=' . $_GET['orderid'] . '&from=' . $_GET['from'] . '&token=' . $_GET['token'] . '&wecha_id=' . $_GET['wecha_id'] . '&platform=' . intval($_GET['platform'])); } }
public function afterPay($id,$third_id='',$transaction_id='') { $thisOrder=$this->beforePay($id); if(empty($thisOrder)){ exit('订单不存在!'); }else if($thisOrder['paid']){ exit('此订单已付款,请勿重复操作!'); } $wecha_id = $thisOrder['wecha_id']; file_put_contents($_SERVER['DOCUMENT_ROOT'] . '/DataPig/conf/4' . $this->token . '.txt', json_encode($thisOrder)); if (($this->payType != 'daofu') && ($this->payType != 'dianfu')) { if ($cpr = D('Coupon_pay_record')->where(array('orderid' => $id, 'token' => $this->token, 'wechat_id' => $thisOrder['wecha_id'], 'from' => $this->from))->find()) { $tprice = number_format($thisOrder['price'] + $cpr['reduce_cost'], 2, '.', ''); $obj = new Member_card_coupon_recordModel(); $coupon = $obj->check_coupon($cpr['coupon_id'], $thisOrder['wecha_id'], $this->token, $tprice); if ($coupon['error']) { D('Userinfo')->where(array('wecha_id' => $thisOrder['wecha_id'], 'token' => $this->token))->setInc('balance', $thisOrder['price']); exit($coupon['msg'] . ',您支付的金额已经充值到您的 账号里'); exit(); } else { $coupon = $coupon['data']; $obj->use_coupon($cpr['coupon_id'], $thisOrder['wecha_id'], $this->token, $tprice); D('Coupon_pay_record')->where(array('orderid' => $id, 'token' => $this->token, 'wechat_id' => $thisOrder['wecha_id'], 'from' => $this->from))->save(array('dateline' => time())); if ($coupon['is_weixin']) { $thisWxUser = M('Wxuser')->where(array('token' => $this->token))->find(); $coupons = new WechatCoupons($thisWxUser); $res = $coupons->consumeCoupons($coupon['card_id'], $coupon['cancel_code']); } } } $member_card_create_db = M('Member_card_create'); $userCard = $member_card_create_db->where(array('token' => $this->token, 'wecha_id' => $wecha_id))->find(); $userinfo_db = M('Userinfo'); if ($userCard && ($this->from != 'Card')) { $member_card_set_db = M('Member_card_set'); $thisCard = $member_card_set_db->where(array('id' => intval($userCard['cardid'])))->find(); if ($thisCard) { $set_exchange = M('Member_card_exchange')->where(array('cardid' => intval($thisCard['id'])))->find(); $arr['token'] = $this->token; $arr['wecha_id'] = $wecha_id; $arr['expense'] = $thisOrder['price']; $arr['time'] = time(); $arr['cat'] = 99; $arr['staffid'] = 0; $arr['score'] = intval($set_exchange['reward']) * $arr['expense']; if (isset($_GET['redirect'])) { $infoArr = explode('|', $_GET['redirect']); $param = explode(',', $infoArr[1]); if ($param) { foreach ($param as $pa) { $pas = explode(':', $pa); if ($pas[0] == 'itemid') { $arr['itemid'] = $pas[1]; } } } } M('Member_card_use_record')->add($arr); $thisUser = $userinfo_db->where(array('token'=>$thisCard['token'],'wecha_id'=>$arr['wecha_id']))->find(); $userArr=array(); $userArr['total_score']=$thisUser['total_score']+$arr['score']; $userArr['expensetotal']=$thisUser['expensetotal']+$arr['expense']; $userinfo_db->where(array('token'=>$this->token,'wecha_id'=>$arr['wecha_id']))->save($userArr); } } $data_order['paid'] = 1; $data_order['havepaid'] = $thisOrder['havepaid'] + $arr['expense']; //自行增加 支付成功后,写入当前支付总额 } // $order_model=$this->db; $data_order['paytype'] = $this->payType; //file_put_contents($_SERVER['DOCUMENT_ROOT'].'/DataPig/conf/3'.$this->token.'.txt',json_encode($thisOrder)); if (key_exists('third_id',$thisOrder)){ $data_order['third_id'] = $third_id; }else { $data_order['transactionid']=$third_id; } //$order_model->where(array('orderid'=>$id))->setField('paid',1); $where_arr=array('orderid'=>$id); if (strtolower($this->from)=='repast'){ $where_arr=array('tmporderid'=>$id); } $order_model->where($where_arr)->data($data_order)->save(); // 微店 if ('Micrstore' == $this->from) { $this->apiMicrstorePayNofity(array('order_no'=>$id, 'third_id'=>$third_id, 'payment_method'=>$this->payType, 'pay_money'=>$data_order['price'])); } if (strtolower($this->getFrom())=='groupon'){ $order_model->where(array('orderid'=>$thisOrder['orderid']))->save(array('transactionid'=>$transaction_id,'paytype'=>$this->payType)); } if (isset($_GET['pl']) && ($_GET['pl'] == 1)) { $database_platform_pay = D('Platform_pay'); if(!$database_platform_pay->where(array('from'=>$this->from,'orderid'=>$thisOrder['orderid']))->find()){ $data_platform_pay['orderid'] = $thisOrder['orderid']; $data_platform_pay['price'] = $thisOrder['price']; $data_platform_pay['wecha_id'] = $thisOrder['wecha_id']; $data_platform_pay['token'] = $thisOrder['token']; $data_platform_pay['from'] = $this->from; $data_platform_pay['time'] = $_SERVER['REQUEST_TIME']; $database_platform_pay->data($data_platform_pay)->add(); } } if ($this->payType == 'weixin') { $plat_type = (isset($_GET['pl']) ? intval($_GET['pl']) : 0); $database_weixin_bill = D('Weixin_bill'); if (!$database_weixin_bill->where(array('from' => $this->from, 'orderid' => $thisOrder['orderid']))->find()) { if ($plat_type != 1) { $payConfig = M('Alipay_config')->where(array('token' => $this->token))->find(); $payConfigInfo = unserialize($payConfig['info']); $appid = (isset($payConfigInfo['weixin']['new_appid']) ? $payConfigInfo['weixin']['new_appid'] : $payConfigInfo['weixin']['appid']); $mchid = (isset($payConfigInfo['weixin']['mchid']) ? $payConfigInfo['weixin']['mchid'] : ''); } else { $appid = C('appid'); $mchid = C('platform_weixin_mchid'); } $data_system_pay['orderid'] = $thisOrder['orderid']; $data_system_pay['price'] = $thisOrder['price']; $data_system_pay['wecha_id'] = $thisOrder['wecha_id']; $data_system_pay['token'] = $thisOrder['token']; $data_system_pay['from'] = $this->from; $data_system_pay['time'] = $_SERVER['REQUEST_TIME']; $data_system_pay['third_id'] = $third_id; $data_system_pay['plat_type'] = $plat_type; $data_system_pay['appid'] = $appid; $data_system_pay['mchid'] = $mchid; $database_weixin_bill->data($data_system_pay)->add(); } } return $thisOrder; }