Commit 38e42329 authored by christ's avatar christ

Merge branch 'master_dev' of git.shenbd.com:qm-develop/shenbd into ccw

parents 4ee48f63 877e6453
...@@ -13,9 +13,16 @@ class PayConst { ...@@ -13,9 +13,16 @@ class PayConst {
const wxPayMchId = '1507388351'; const wxPayMchId = '1507388351';
const wxPaySecret = 'appSecret'; const wxPaySecret = 'appSecret';
const wxPayKey = 'kt4gh9FzzlaoPBY074iuF4ZbNmMKc3mS'; const wxPayKey = 'kt4gh9FzzlaoPBY074iuF4ZbNmMKc3mS';
const wxSslcertPath = '/application/library/Payment/cert/wx/apiclient_cert.pem'; const wxSslcertPath = '/application/library/Payment/cert/wx/apiclient_cert.pem';
const wxSslkeyPath = '/application/library/Payment/cert/wx/apiclient_key.pem'; const wxSslkeyPath = '/application/library/Payment/cert/wx/apiclient_key.pem';
//服务商appId和服务商payKey
const wxSPayAppId = 'wxd89203f7621015b7';
const wxSPayMchId = '1517411161';
const wxSPayKey = 'z6o0aQ4Gbceaymj6BKm9PYPjHaUJGokJ';
const wxServiceSslcertPath = '/application/library/Payment/cert/wxservice/1517411161_20181102_cert.pem';
const wxServiceSslkeyPath = '/application/library/Payment/cert/wxservice/1517411161_20181102_key.pem';
const wxPayUrl = 'https://api.mch.weixin.qq.com/pay/unifiedorder'; const wxPayUrl = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
const qPayAppId = 'qPayAppId'; const qPayAppId = 'qPayAppId';
......
...@@ -14,7 +14,7 @@ class Pay { ...@@ -14,7 +14,7 @@ class Pay {
private $order; private $order;
private $paySn; private $paySn;
private $member; private $member;
private $orderField = 'order_amount,order_sn'; private $orderField = 'order_amount,order_sn,store_id';
private $requestData ; private $requestData ;
private $orderAmount= \Our\ApiConst::zero; private $orderAmount= \Our\ApiConst::zero;
...@@ -26,15 +26,21 @@ class Pay { ...@@ -26,15 +26,21 @@ class Pay {
$this->requestData = $data; $this->requestData = $data;
$this->member = \DAO\MemberModel::getInstance()->getInfo($this->memberId); $this->member = \DAO\MemberModel::getInstance()->getInfo($this->memberId);
$return = array(); $return = array();
$orderInfo = $this->getOrder(); $wxFlag = false;
if(CURRENTVERSION==\Our\NameConst::versionOne&&($data['channel']==\Our\NameConst::wxAppChannel||$data['channel']==\Our\NameConst::wxLiteChannel)){
$wxFlag = true;
}
$orderInfo = $this->getOrder($wxFlag);
if($data['channel'] == \Our\NameConst::wxAppChannel){ if($data['channel'] == \Our\NameConst::wxAppChannel){
$wxpay = WxPay::getInstance(); $wxpay = WxPay::getInstance();
unset($orderInfo['subMchId']);
$return = $wxpay->doPay($orderInfo); $return = $wxpay->doPay($orderInfo);
}else if($data['channel'] == \Our\NameConst::aliApiChannel){ }else if($data['channel'] == \Our\NameConst::aliApiChannel){
$alipay= Alipay::getInstance(); $alipay= Alipay::getInstance();
$return = $alipay->doPay($orderInfo); $return = $alipay->doPay($orderInfo);
}else if($data['channel'] == \Our\NameConst::wxLiteChannel){ }else if($data['channel'] == \Our\NameConst::wxLiteChannel){
$sess = \Yaf\Session::getInstance(); $sess = \Yaf\Session::getInstance();
//$orderInfo['subMchId'] = '1517943841';
$authInfo = $sess->get('wxAuthInfo'); $authInfo = $sess->get('wxAuthInfo');
$orderInfo['openid'] = $authInfo['openid']; $orderInfo['openid'] = $authInfo['openid'];
$wxLitePay = WxLitePay::getInstance(); $wxLitePay = WxLitePay::getInstance();
...@@ -50,7 +56,7 @@ class Pay { ...@@ -50,7 +56,7 @@ class Pay {
/** /**
* 获取待支付订单内容 * 获取待支付订单内容
*/ */
public function getOrder(){ public function getOrder($wxFlag){
$dbName = \Our\DbNameConst::masterDBConnectName; $dbName = \Our\DbNameConst::masterDBConnectName;
$orderDao = \DAO\Order\OrderModel::getInstance($dbName); $orderDao = \DAO\Order\OrderModel::getInstance($dbName);
$orderPayDao = \DAO\Order\OrderPayModel::getInstance($dbName); $orderPayDao = \DAO\Order\OrderPayModel::getInstance($dbName);
...@@ -62,9 +68,18 @@ class Pay { ...@@ -62,9 +68,18 @@ class Pay {
if(!$orderList){ if(!$orderList){
\Error\ErrorModel::throwException(\Error\CodeConfigModel::noOrderListForPay); \Error\ErrorModel::throwException(\Error\CodeConfigModel::noOrderListForPay);
} }
foreach($orderList as $tempOrder){ foreach($orderList as $tempOrder){
$this->orderAmount += $tempOrder['order_amount']; $this->orderAmount += $tempOrder['order_amount'];
} }
if($wxFlag){
$storeId = $orderList[0]['store_id'];
$mchIdArray = \DAO\StoreModel::getInstance($dbName)->getStoreWxMchId($storeId);
if($mchIdArray['errorCode']>0){
\Error\ErrorModel::throwException($mchIdArray['errorCode']);
}
$orderInfo['subMchId'] = $mchIdArray['mchId'];
}
if($this->orderAmount == \Our\ApiConst::zero){ if($this->orderAmount == \Our\ApiConst::zero){
\Error\ErrorModel::throwException(\Error\CodeConfigModel::emptyOrderAmountForPay); \Error\ErrorModel::throwException(\Error\CodeConfigModel::emptyOrderAmountForPay);
......
...@@ -18,6 +18,9 @@ class TencentPay { ...@@ -18,6 +18,9 @@ class TencentPay {
protected $result =''; protected $result ='';
protected $key = ''; protected $key = '';
protected $mch_id =''; protected $mch_id ='';
protected $s_appid ='';
protected $s_key = '';
protected $s_mch_id ='';
protected $prepay_id =''; protected $prepay_id ='';
protected $tradeType = ''; protected $tradeType = '';
public $data;//接收到的数据,类型为关联数组 public $data;//接收到的数据,类型为关联数组
...@@ -51,6 +54,35 @@ class TencentPay { ...@@ -51,6 +54,35 @@ class TencentPay {
$this->setPrepayId($prepay_id); $this->setPrepayId($prepay_id);
} }
public function setServiceRequestParams($orderInfo){
$this->key = $this->s_key;
$pay_sn = $orderInfo['paySn'];
$total_fee = $orderInfo['orderAmount'];
$this->parameters['appid']=$this->s_appid;
$this->parameters['mch_id']=$this->s_mch_id;
$this->parameters['sub_appid']=$this->appid;
$this->parameters['sub_mch_id']=$orderInfo['subMchId'];
$this->parameters['nonce_str']=\Our\CommonExtension::createNoncestr(32);
$this->parameters['body']='订单号:'.implode(',',$orderInfo['orderSns']);
$this->parameters['attach']='r|'.$pay_sn;
$this->parameters['out_trade_no']=$pay_sn;
$this->parameters['fee_type']= \Our\NameConst::currentCNY;
if(APP_ENV == 'develop'||APP_ENV == 'test'||APP_ENV == 'pre'){
$this->parameters['total_fee'] = 1;
}else{
$this->parameters['total_fee'] = $total_fee;
}
if(isset($orderInfo['openid'])&&$orderInfo['openid']){
$this->parameters['sub_openid'] = $orderInfo['openid'];
}
$this->parameters['spbill_create_ip']=\Our\Common::getClientIp();
$this->parameters['notify_url']=$this->notify_url;
$this->parameters['trade_type']= $this->tradeType;
//$this->parameters['openid']=$_SESSION['openid'];
//print_r($this->parameters);exit;
$prepay_id = $this->getPrepayId();
$this->setPrepayId($prepay_id);
}
/** /**
* 作用:设置prepay_id * 作用:设置prepay_id
...@@ -98,11 +130,14 @@ class TencentPay { ...@@ -98,11 +130,14 @@ class TencentPay {
/** /**
* 作用:设置标配的请求参数,生成签名,生成接口参数xml * 作用:设置标配的请求参数,生成签名,生成接口参数xml
*/ */
function createXml() function createXml($signType='MD5')
{ {
if($signType=='MD5'){
$this->parameters["sign"] = $this->getSign($this->parameters);//签名 //echo '加签参数:'.json_encode($this->parameters)."\n";
$this->parameters["sign"] = $this->getSign($this->parameters);//签名
}else{
$this->parameters["sign"] = $this->getHMACSHA1Sign($this->parameters,'sha256');
}
return $this->arrayToXml($this->parameters); return $this->arrayToXml($this->parameters);
} }
...@@ -228,8 +263,9 @@ class TencentPay { ...@@ -228,8 +263,9 @@ class TencentPay {
//签名步骤一:按字典序排序参数 //签名步骤一:按字典序排序参数
ksort($Parameters); ksort($Parameters);
$String = $this->formatBizQueryParaMap($Parameters, false); $String = $this->formatBizQueryParaMap($Parameters, false);
$String = $String."&key=".$this->key; $String = $String."&key=".$this->key;
//签名步骤三:MD5加密 $String = str_replace(array("\r\n", "\r", "\n"," "), "", $String);
$String = md5($String); $String = md5($String);
$result_ = strtoupper($String); $result_ = strtoupper($String);
return $result_; return $result_;
...@@ -239,7 +275,7 @@ class TencentPay { ...@@ -239,7 +275,7 @@ class TencentPay {
/** /**
* 作用:生成签名(按照HMAC-SHA1规则签名) * 作用:生成签名(按照HMAC-SHA1规则签名)
*/ */
public function getHMACSHA1Sign($Obj) public function getHMACSHA1Sign($Obj,$signType ='sha1')
{ {
foreach ($Obj as $k => $v) foreach ($Obj as $k => $v)
{ {
...@@ -250,7 +286,7 @@ class TencentPay { ...@@ -250,7 +286,7 @@ class TencentPay {
$String = $this->formatBizQueryParaMap($Parameters, false); $String = $this->formatBizQueryParaMap($Parameters, false);
//$String = $String."&key=".$this->key; //$String = $String."&key=".$this->key;
//签名步骤三:HMAC-SHA1加密 //签名步骤三:HMAC-SHA1加密
$String = hash_hmac('sha1',$String,$this->key); $String = hash_hmac($signType,$String,$this->key);
$result_ = base64_encode($String); $result_ = base64_encode($String);
return $result_; return $result_;
} }
...@@ -307,7 +343,7 @@ class TencentPay { ...@@ -307,7 +343,7 @@ class TencentPay {
$verify = true; $verify = true;
$this->setReturnParameter("return_code","SUCCESS");//设置返回码 $this->setReturnParameter("return_code","SUCCESS");//设置返回码
} }
$returnXml = $this->returnXml();; $returnXml = $this->returnXml();
if($verify) { if($verify) {
return array( return array(
'out_trade_no' => $this->data['out_trade_no'], 'out_trade_no' => $this->data['out_trade_no'],
...@@ -319,6 +355,19 @@ class TencentPay { ...@@ -319,6 +355,19 @@ class TencentPay {
} }
/**
* 作用:产生随机字符串,不长于32位
*/
public function createNoncestr($length = 32)
{
$chars = "abcdefghijklmnopqrstuvwxyz0123456789";
$str = "";
for ($i = 0; $i < $length; $i++) {
$str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
}
return $str;
}
/** /**
* 将xml数据返回微信 * 将xml数据返回微信
*/ */
......
...@@ -8,21 +8,30 @@ namespace Payment; ...@@ -8,21 +8,30 @@ namespace Payment;
*/ */
class WxLitePay extends \Payment\TencentPay{ class WxLitePay extends \Payment\TencentPay{
private $refundUrl="https://api.mch.weixin.qq.com/secapi/pay/refund";
public function __construct() public function __construct()
{ {
$this->appid = \Our\PayConst::wxLiteAppId; $this->appid = \Our\PayConst::wxLiteAppId;
$this->notify_url = \Our\NameConst::httpPrefix.$_SERVER['SERVER_NAME'].\Our\PayConst::wxLiteNotifyUrl; $this->notify_url = \Our\NameConst::httpPrefix.$_SERVER['SERVER_NAME'].\Our\PayConst::wxLiteNotifyUrl;
$this->mch_id = \Our\PayConst::wxPayMchId; $this->mch_id = \Our\PayConst::wxPayMchId;
$this->key = \Our\PayConst::wxPayKey; $this->key = \Our\PayConst::wxSPayKey;
$this->sslcert_path = \Our\PayConst::wxSslcertPath; $this->sslcert_path = \Our\PayConst::wxSslcertPath;
$this->sslkey_path = \Our\PayConst::wxSslkeyPath; $this->sslkey_path = \Our\PayConst::wxSslkeyPath;
$this->pay_url = \Our\PayConst::wxPayUrl; $this->pay_url = \Our\PayConst::wxPayUrl;
$this->tradeType = \Our\PayConst::wxLiteTradeType; $this->tradeType = \Our\PayConst::wxLiteTradeType;
$this->s_mch_id = \Our\PayConst::wxSPayMchId;
$this->s_key = \Our\PayConst::wxSPayKey;
$this->s_appid = \Our\PayConst::wxSPayAppId;
} }
public function doPay($orderInfo){ public function doPay($orderInfo){
$this->setRequestParams($orderInfo); if(isset($orderInfo['subMchId'])){
$this->setServiceRequestParams($orderInfo);
}else{
$this->setRequestParams($orderInfo);
}
//$this->setRequestParams($orderInfo);
$wxAppParameters = $this->getParameters(); $wxAppParameters = $this->getParameters();
$returnData = array( $returnData = array(
'credential'=>array(\Our\NameConst::wxLiteChannel=>$wxAppParameters), 'credential'=>array(\Our\NameConst::wxLiteChannel=>$wxAppParameters),
...@@ -43,6 +52,76 @@ class WxLitePay extends \Payment\TencentPay{ ...@@ -43,6 +52,76 @@ class WxLitePay extends \Payment\TencentPay{
} }
public function refund($param){
if($param['subMchId']){
$this->refundService($param);
}else{
$this->refundCommon($param);
}
}
public function refundService($param){
$this->key = $this->s_key;
$this->sslcert_path = \Our\PayConst::wxServiceSslcertPath;
$this->sslkey_path = \Our\PayConst::wxServiceSslkeyPath;
$total_fee = intval($param['totalFee']);
$refund_fee = intval($param['refundFee']);
if(APP_ENV == 'develop'||APP_ENV == 'test'||APP_ENV == 'pre' || APP_ENV=='ccwdevelop'|| APP_ENV=='lyztest'){
$this->parameters['total_fee'] = 1;
$this->parameters['refund_fee'] = 1;
} else {
$this->parameters['total_fee'] = $total_fee;
$this->parameters['refund_fee'] = $refund_fee;
}
$this->parameters['appid']=$this->s_appid;
$this->parameters['mch_id']=$this->s_mch_id;
$this->parameters['sub_appid']=$this->appid;
$this->parameters['sub_mch_id'] = $param['subMchId'];
$this->parameters['nonce_str'] = $this->createNoncestr(32);
//$this->parameters['transaction_id'] = $param['transactionId'];
$this->parameters['out_trade_no'] = $param['outTradeNo'];
$this->parameters['out_refund_no'] = $param['refundOrderNo'];
$xml = $this->createXml();
$response = $this->postXmlSSLCurl($xml, $this->refundUrl, 6);
$values = $this->xmlToArray($response);
if ($values['return_code'] != 'SUCCESS') {
return $values;
}
$this->checkSign($values);
return $values;
}
public function refundCommon($param){
$total_fee = intval($param['totalFee']);
$refund_fee = intval($param['refundFee']);
if(APP_ENV == 'develop'||APP_ENV == 'test'||APP_ENV == 'pre' || APP_ENV=='ccwdevelop'){
$this->parameters['total_fee'] = 1;
$this->parameters['refund_fee'] = 1;
} else {
$this->parameters['total_fee'] = $total_fee;
$this->parameters['refund_fee'] = $refund_fee;
}
$this->parameters['out_refund_no'] = $param['refundOrderNo'];
$this->parameters['out_trade_no'] = $param['outTradeNo'];
$this->parameters['op_user_id'] = $this->mch_id;
$this->parameters['nonce_str'] = $this->createNoncestr(32);
$this->parameters['appid'] = \Our\PayConst::wxLiteAppId;
$this->parameters['mch_id'] = \Our\PayConst::wxPayMchId;
$xml = $this->createXml();
$response = $this->postXmlSSLCurl($xml, $this->refundUrl, 6);
$values = $this->xmlToArray($response);
if ($values['return_code'] != 'SUCCESS') {
return $values;
}
$this->checkSign($values);
return $values;
}
/** /**
* 类实例 * 类实例
* *
......
...@@ -22,11 +22,18 @@ class WxPay extends \Payment\TencentPay ...@@ -22,11 +22,18 @@ class WxPay extends \Payment\TencentPay
$this->sslkey_path = \Our\PayConst::wxSslkeyPath; $this->sslkey_path = \Our\PayConst::wxSslkeyPath;
$this->pay_url = \Our\PayConst::wxPayUrl; $this->pay_url = \Our\PayConst::wxPayUrl;
$this->tradeType = \Our\PayConst::wxAppTradeType; $this->tradeType = \Our\PayConst::wxAppTradeType;
$this->s_mch_id = \Our\PayConst::wxSPayMchId;
$this->s_key = \Our\PayConst::wxSPayKey;
$this->s_appid = \Our\PayConst::wxSPayAppId;
} }
public function doPay($orderInfo) public function doPay($orderInfo)
{ {
$this->setRequestParams($orderInfo); if(isset($orderInfo['subMchId'])){
$this->setServiceRequestParams($orderInfo);
}else{
$this->setRequestParams($orderInfo);
}
$wxAppParameters = $this->getParameters(); $wxAppParameters = $this->getParameters();
$returnData = array( $returnData = array(
'credential' => array(\Our\NameConst::wxAppChannel => $wxAppParameters), 'credential' => array(\Our\NameConst::wxAppChannel => $wxAppParameters),
...@@ -51,21 +58,19 @@ class WxPay extends \Payment\TencentPay ...@@ -51,21 +58,19 @@ class WxPay extends \Payment\TencentPay
return $wxApiObj; return $wxApiObj;
} }
/**
* 作用:产生随机字符串,不长于32位 public function refund($param){
*/ if($param['subMchId']){
private function createNoncestr($length = 32) $this->serviceRefund($param);
{ }else{
$chars = "abcdefghijklmnopqrstuvwxyz0123456789"; $this->commonRefund($param);
$str = "";
for ($i = 0; $i < $length; $i++) {
$str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
} }
return $str;
} }
public function refund($param) public function serviceRefund($param){
{ $this->key = $this->s_key;
$this->sslcert_path = \Our\PayConst::wxServiceSslcertPath;
$this->sslkey_path = \Our\PayConst::wxServiceSslkeyPath;
$total_fee = intval($param['totalFee']); $total_fee = intval($param['totalFee']);
$refund_fee = intval($param['refundFee']); $refund_fee = intval($param['refundFee']);
if(APP_ENV == 'develop'||APP_ENV == 'test'||APP_ENV == 'pre' || APP_ENV=='ccwdevelop'){ if(APP_ENV == 'develop'||APP_ENV == 'test'||APP_ENV == 'pre' || APP_ENV=='ccwdevelop'){
...@@ -81,8 +86,10 @@ class WxPay extends \Payment\TencentPay ...@@ -81,8 +86,10 @@ class WxPay extends \Payment\TencentPay
$this->parameters['out_trade_no'] = $param['outTradeNo']; $this->parameters['out_trade_no'] = $param['outTradeNo'];
$this->parameters['op_user_id'] = $this->mch_id; $this->parameters['op_user_id'] = $this->mch_id;
$this->parameters['nonce_str'] = $this->createNoncestr(32); $this->parameters['nonce_str'] = $this->createNoncestr(32);
$this->parameters['appid'] = \Our\PayConst::wxPayAppId; $this->parameters['appid'] = \Our\PayConst::wxSPayAppId;
$this->parameters['mch_id'] = \Our\PayConst::wxPayMchId; $this->parameters['mch_id'] = \Our\PayConst::wxSPayMchId;
$this->parameters['sub_appid'] = \Our\PayConst::wxSPayAppId;
$this->parameters['sub_mch_id '] = $param['subMchId'];
$xml = $this->createXml(); $xml = $this->createXml();
$response = $this->postXmlSSLCurl($xml, $this->refundUrl, 6); $response = $this->postXmlSSLCurl($xml, $this->refundUrl, 6);
$values = $this->xmlToArray($response); $values = $this->xmlToArray($response);
...@@ -92,7 +99,8 @@ class WxPay extends \Payment\TencentPay ...@@ -92,7 +99,8 @@ class WxPay extends \Payment\TencentPay
$this->checkSign($values); $this->checkSign($values);
return $values; return $values;
} }
public function refundWxProgram($param)
public function commonRefund($param)
{ {
$total_fee = intval($param['totalFee']); $total_fee = intval($param['totalFee']);
$refund_fee = intval($param['refundFee']); $refund_fee = intval($param['refundFee']);
...@@ -103,11 +111,13 @@ class WxPay extends \Payment\TencentPay ...@@ -103,11 +111,13 @@ class WxPay extends \Payment\TencentPay
$this->parameters['total_fee'] = $total_fee; $this->parameters['total_fee'] = $total_fee;
$this->parameters['refund_fee'] = $refund_fee; $this->parameters['refund_fee'] = $refund_fee;
} }
$this->parameters['total_fee'] = $total_fee;
$this->parameters['refund_fee'] =$refund_fee;
$this->parameters['out_refund_no'] = $param['refundOrderNo']; $this->parameters['out_refund_no'] = $param['refundOrderNo'];
$this->parameters['out_trade_no'] = $param['outTradeNo']; $this->parameters['out_trade_no'] = $param['outTradeNo'];
$this->parameters['op_user_id'] = $this->mch_id; $this->parameters['op_user_id'] = $this->mch_id;
$this->parameters['nonce_str'] = $this->createNoncestr(32); $this->parameters['nonce_str'] = $this->createNoncestr(32);
$this->parameters['appid'] = \Our\PayConst::wxLiteAppId; $this->parameters['appid'] = \Our\PayConst::wxPayAppId;
$this->parameters['mch_id'] = \Our\PayConst::wxPayMchId; $this->parameters['mch_id'] = \Our\PayConst::wxPayMchId;
$xml = $this->createXml(); $xml = $this->createXml();
$response = $this->postXmlSSLCurl($xml, $this->refundUrl, 6); $response = $this->postXmlSSLCurl($xml, $this->refundUrl, 6);
......
-----BEGIN CERTIFICATE-----
MIID/jCCAuagAwIBAgIUP4Etbcyczm2HU2J+c0XtQfxm7zUwDQYJKoZIhvcNAQEL
BQAwXjELMAkGA1UEBhMCQ04xEzARBgNVBAoTClRlbnBheS5jb20xHTAbBgNVBAsT
FFRlbnBheS5jb20gQ0EgQ2VudGVyMRswGQYDVQQDExJUZW5wYXkuY29tIFJvb3Qg
Q0EwHhcNMTgxMTAyMDIzMzEyWhcNMjMxMTAxMDIzMzEyWjCBjzETMBEGA1UEAwwK
MTUxNzQxMTE2MTEbMBkGA1UECgwS5b6u5L+h5ZWG5oi357O757ufMScwJQYDVQQL
DB7npo/lt57ljYPnm5/nu4/otLjmnInpmZDlhazlj7gxCzAJBgNVBAYMAkNOMRIw
EAYDVQQIDAlHdWFuZ0RvbmcxETAPBgNVBAcMCFNoZW5aaGVuMIIBIjANBgkqhkiG
9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqoGRdVvY9FjWy0rtniEr7aGmPfTFwc8QyvkI
MpUAthEKjgAmyScgSQolsQPUhdjOCGShk0U0yrJGkdNGGi8utt8LI2jQWqRiaG3r
11u9m4TZGgIrGs+F9CCk6kT7dHsK7HNehzTKqSZ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3F//3KgvS8W7
mzs1rNYuiXGPlejwd49ogvCyCs30l+fPJVCKOCUAPN2AKZ9KFrH6U+r5SC/j0lFy
YBlu4XDuN0SOyf/J7ynpmD6bcIvCgZA6s9NUJ80zB/8CgYAR+YDo47AEBL/7rRR7
a7L+7h9kMSyggo31ODNt9sw5IuxMIRWaAi98jF4z2uAxjo2PSqhbiWQZ/xOd5hw2
nyXxdlFCsZYZQi8SgA8XuV3Bopk2IZzq6vHIsh+JtMZGi0wE2iCCjjVTC/Zc3NiE
MUgDT0wW7zFc7d6JGuHKzfZTDA==
-----END PRIVATE KEY-----
...@@ -330,6 +330,7 @@ class OrderServiceModel extends \Business\AbstractModel ...@@ -330,6 +330,7 @@ class OrderServiceModel extends \Business\AbstractModel
$storeDao=\DAO\StoreModel::getInstance(); $storeDao=\DAO\StoreModel::getInstance();
//判断订单目前状态是否允许取消 //判断订单目前状态是否允许取消
$isAllowCancel = $orderDao->isAllowCancel($order); $isAllowCancel = $orderDao->isAllowCancel($order);
$isAllowCance = true;
if ($isAllowCancel) { if ($isAllowCancel) {
$res = $orderDao->updateStatusByOrderId($orderId, ApiConst::orderStateCancel); $res = $orderDao->updateStatusByOrderId($orderId, ApiConst::orderStateCancel);
if ($res) { if ($res) {
...@@ -373,6 +374,16 @@ class OrderServiceModel extends \Business\AbstractModel ...@@ -373,6 +374,16 @@ class OrderServiceModel extends \Business\AbstractModel
} }
public function cancelOne(){
$refundReturnDao = \DAO\Order\RefundReturnModel::getInstance(DbNameConst::masterDBConnectName);
$orderData['storeId']=11;
$orderData['subMchId'] = '1517943841';
$orderData['paySn'] = '280595075137008428';
$orderData['transactionId'] = '4200000191201811099414332980';
$orderData['buyerId'] = 428;
$resultRefund=$refundReturnDao->refundMoney($orderData);
}
//确认收货 //确认收货
public function confirmRecieve($orderId, $memberId) public function confirmRecieve($orderId, $memberId)
{ {
......
...@@ -334,8 +334,17 @@ class RefundReturnModel extends \DAO\AbstractModel { ...@@ -334,8 +334,17 @@ class RefundReturnModel extends \DAO\AbstractModel {
$param['refundFee'] = $orderInfo['refund_amount'];//退款金额 $param['refundFee'] = $orderInfo['refund_amount'];//退款金额
$param['storeId'] = $orderInfo['store_id']; $param['storeId'] = $orderInfo['store_id'];
$param['buyerId'] = $orderInfo['buyer_id']; $param['buyerId'] = $orderInfo['buyer_id'];
if(CURRENTVERSION==\Our\NameConst::versionOne&&in_array(intval($orderInfo['payment_type']),array(ApiConst::wxAppPayType,ApiConst::wxProgram))){
$mchIdArray = \DAO\StoreModel::getInstance()->getStoreWxMchId($param['storeId']);
if($mchIdArray['errorCode']>0){
$this->errorMessage = '微信支付商户错误或者签名错误';
return false;
}
$param['subMchId'] = $mchIdArray['mchId'];
}
if (intval($orderInfo['payment_type']) == ApiConst::wxAppPayType) { if (intval($orderInfo['payment_type']) == ApiConst::wxAppPayType) {
$wxpay = \Payment\WxPay::getInstance(); $wxpay = \Payment\WxPay::getInstance();
unset($param['subMchId']);
$refund_return = $wxpay->refund($param); $refund_return = $wxpay->refund($param);
$this->errorMessage= "微信返回:".json_encode($refund_return); $this->errorMessage= "微信返回:".json_encode($refund_return);
if (!($refund_return['return_code'] == 'SUCCESS' && $refund_return['result_code'] == 'SUCCESS')) { if (!($refund_return['return_code'] == 'SUCCESS' && $refund_return['result_code'] == 'SUCCESS')) {
...@@ -379,8 +388,17 @@ class RefundReturnModel extends \DAO\AbstractModel { ...@@ -379,8 +388,17 @@ class RefundReturnModel extends \DAO\AbstractModel {
$param['refundFee'] = $orderInfo['orderAmount'];//全额退款 $param['refundFee'] = $orderInfo['orderAmount'];//全额退款
$param['storeId']=$orderInfo['storeId']; $param['storeId']=$orderInfo['storeId'];
$param['buyerId']=$orderInfo['buyerId']; $param['buyerId']=$orderInfo['buyerId'];
if(CURRENTVERSION==\Our\NameConst::versionOne&&in_array(intval($orderInfo['paymentType']),array(\Our\ApiConst::wxAppPayType,\Our\ApiConst::wxProgram))){
$mchIdArray = \DAO\StoreModel::getInstance()->getStoreWxMchId($param['storeId']);
if($mchIdArray['errorCode']>0){
$this->errorMessage = '微信支付商户错误或者签名错误';
return false;
}
$param['subMchId'] = $mchIdArray['mchId'];
}
if (intval($orderInfo['paymentType']) == ApiConst::wxAppPayType) { if (intval($orderInfo['paymentType']) == ApiConst::wxAppPayType) {
$wxpay = \Payment\WxPay::getInstance(); $wxpay = \Payment\WxPay::getInstance();
unset($param['subMchId']);
$refund_return = $wxpay->refund($param); $refund_return = $wxpay->refund($param);
$this->errorMessage= "微信返回:".json_encode($refund_return); $this->errorMessage= "微信返回:".json_encode($refund_return);
if (!($refund_return['return_code'] == 'SUCCESS' && $refund_return['result_code'] == 'SUCCESS')) { if (!($refund_return['return_code'] == 'SUCCESS' && $refund_return['result_code'] == 'SUCCESS')) {
...@@ -399,9 +417,9 @@ class RefundReturnModel extends \DAO\AbstractModel { ...@@ -399,9 +417,9 @@ class RefundReturnModel extends \DAO\AbstractModel {
return false; return false;
} }
}else if(intval($orderInfo['paymentType']) == ApiConst::wxProgram){ }else if(intval($orderInfo['paymentType']) == ApiConst::wxProgram){
$wxpay = \Payment\WxPay::getInstance(); $wxpay = \Payment\WxLitePay::getInstance();
$refund_return = $wxpay->refundWxProgram($param); $refund_return = $wxpay->refund($param);
$this->errorMessage= "微信小程序返回:".json_encode($refund_return);
if (!($refund_return['return_code'] == 'SUCCESS' && $refund_return['result_code'] == 'SUCCESS')) { if (!($refund_return['return_code'] == 'SUCCESS' && $refund_return['result_code'] == 'SUCCESS')) {
$this->errorMessage=date('Y-m-d').'微信退款操作执行失败!'.$orderInfo['orderId']."\r\n"; $this->errorMessage=date('Y-m-d').'微信退款操作执行失败!'.$orderInfo['orderId']."\r\n";
return false; return false;
......
...@@ -28,6 +28,8 @@ class StoreModel extends \DAO\AbstractModel ...@@ -28,6 +28,8 @@ class StoreModel extends \DAO\AbstractModel
*/ */
protected $_tableName = 'han_store'; protected $_tableName = 'han_store';
protected $_tableNameFull = 'han_store_full';
/** /**
* 主键 * 主键
* *
...@@ -75,7 +77,7 @@ class StoreModel extends \DAO\AbstractModel ...@@ -75,7 +77,7 @@ class StoreModel extends \DAO\AbstractModel
{ {
$this->setDb($this->dbName); $this->setDb($this->dbName);
$where[$this->_primaryKey] = $id; $where[$this->_primaryKey] = $id;
$store = $this->db->from($this->_tableName)->select($field)->where($where)->fetchOne(); $store = $this->db->from($this->_tableNameFull)->select($field)->where($where)->fetchOne();
if ($isField) { if ($isField) {
return $store[$isField]; return $store[$isField];
} else { } else {
...@@ -544,4 +546,26 @@ class StoreModel extends \DAO\AbstractModel ...@@ -544,4 +546,26 @@ class StoreModel extends \DAO\AbstractModel
return $result; return $result;
} }
/**
* 获取当前店铺对应的微信支付服务商号
* @param $storeId
* @return array
*/
public function getStoreWxMchId($storeId){
$store = $this->get($storeId,false);
$errorCode = 0;
$mchId = '';
if($store['wx_pay']){
if(!($store['wxpay_mchid']&&$store['onlinepay_flag'])){
$errorCode = \Error\CodeConfigModel::orderWxPayError;;
}
$addKey=\Our\Common::getConfig('password.key');
if ($store['wxpay_mchid_sign'] == md5($store['gmt_create'].$store['wxpay_mchid'].$addKey)) {
$mchId = $store['wxpay_mchid'];
}else{
$errorCode = \Error\CodeConfigModel::orderWxPaySignError;
}
}
return array('mchId'=>$mchId,'errorCode'=>$errorCode);
}
} }
...@@ -305,11 +305,16 @@ class CodeConfigModel ...@@ -305,11 +305,16 @@ class CodeConfigModel
const noOrderWaitToPay = 30130; const noOrderWaitToPay = 30130;
const wrongEvaluation = 30131; const wrongEvaluation = 30131;
const selfGoodsForStoreOrder = 3032;
const selfGoodsForStoreOrder = 30132;
const refundAddPointsLogError = 30133; const refundAddPointsLogError = 30133;
const wrongDeliveryTime = 300134; const wrongDeliveryTime = 300134;
const wrongBuyerTimeRangeForOrder =300135; const wrongBuyerTimeRangeForOrder =300135;
const emptyBuyerMobile = 300136; const emptyBuyerMobile = 300136;
const orderWxPayError = 30137;
const orderWxPaySignError = 30138;
//店铺相关错误码 //店铺相关错误码
//商品分类 //商品分类
...@@ -802,6 +807,8 @@ class CodeConfigModel ...@@ -802,6 +807,8 @@ class CodeConfigModel
self::notAllowUpdataOrderAmount=>'当前状态不允许修改订单金额', self::notAllowUpdataOrderAmount=>'当前状态不允许修改订单金额',
self::wrongEvaluation => '商品评论应在6-500字之间', self::wrongEvaluation => '商品评论应在6-500字之间',
self::selfGoodsForStoreOrder => '店主不能购买自己的商品', self::selfGoodsForStoreOrder => '店主不能购买自己的商品',
self::orderWxPayError => '微信支付尚未开通',
self::orderWxPaySignError => '微信支付签名错误',
//销售员 //销售员
self::emptySaleGoodsId => '商品id不能为空', self::emptySaleGoodsId => '商品id不能为空',
self::emptySaleGoods => '销售商品不存在', self::emptySaleGoods => '销售商品不存在',
......
...@@ -224,6 +224,8 @@ push.open=1 ...@@ -224,6 +224,8 @@ push.open=1
push.user.service.id=293 push.user.service.id=293
push.user.service.type=7 push.user.service.type=7
password.key='~!@#$`1234qwertasdfgzxcvb'
[develop : common] [develop : common]
; 数据库配置 ; 数据库配置
resources.database.params.driver = "pdo_mysql" resources.database.params.driver = "pdo_mysql"
......
<?php
/**
* User: liuyuzhen
* Date: 2018/11/9
* Time: 11:04
* Description:
*/
define("APPLICATION_PATH", realpath(dirname(__FILE__) . '/../../../')); //指向public的上一级
require APPLICATION_PATH . '/scripts/crontab/baseCli.php';
require APPLICATION_PATH . '/scripts/crontab/common.php';
error_reporting(E_ALL ^ E_NOTICE);
class cliOrderCancel extends basecli
{
const CLI_ADMIN_ID = 255;
private $bDoUnLock = FALSE; // 是否允许释放 LOCK 文件
private $_debug = 0;
private $lockFileName;
private $fromState;
private function mkdirs($dir, $mode = 0777)
{
if (is_dir($dir) || @mkdir($dir, $mode)){
return TRUE;
}
if (!$this->mkdirs(dirname($dir), $mode)){
return FALSE;
}
return @mkdir($dir, $mode);
}
/**
* 析构
*/
public function __destruct()
{
parent::__destruct();
if ($this->bDoUnLock)
{
@unlink($this->lockFileName);
}
}
protected function autoCancelOrder(){
$orderService=\Business\Order\OrderServiceModel::getInstance(\Our\DbNameConst::masterDBConnectName);
$orderService->cancelOne();
}
protected function _runCli()
{
$this->_debug = isset($this->aArgv[1]) ? intval($this->aArgv[1]) : 0;
if ($this->_debug)
{
echo "*** Debug mode ***\n";
}
// Step: 02 检查是否已有相同CLI在运行中
$lockDir=$this->_getBaseFileName('order');
if(!$this->mkdirs($lockDir)){
echo '****create dir fail ****';
exit;
}
$this->lockFileName = $lockDir .DS.'cancel.locks';
if( file_exists( $this->lockFileName ) )
{
$stat = stat($this->lockFileName);
if( (TIMESTAMP - $stat['mtime']) > 1800 )
{
echo "文件被锁超过1800秒,被强制删除";
@unlink($this->lockFileName);
}
else
{
$this->halt( '[' . date('Y-m-d H:i:s') .'] The CLI is running'."\n");
}
}
$this->bDoUnLock = true;
if(APP_ENV =='pre' || APP_ENV=='product'){
file_put_contents($this->lockFileName ,"running" ); // CLI 独占锁
}
$this->autoCancelOrder();
echo '定单取消成功'."\r\n";
}
}
$oCli = new cliOrderCancel(TRUE);
EXIT;
?>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment