Commit bba1fbae authored by zhz's avatar zhz

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

parents ec983d5c 4a284a4b
......@@ -13,9 +13,16 @@ class PayConst {
const wxPayMchId = '1507388351';
const wxPaySecret = 'appSecret';
const wxPayKey = 'kt4gh9FzzlaoPBY074iuF4ZbNmMKc3mS';
const wxSslcertPath = '/application/library/Payment/cert/wx/apiclient_cert.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 qPayAppId = 'qPayAppId';
......
......@@ -87,7 +87,11 @@ class RedisHelper
$cache_key = (is_array($function)
? (str_replace('\\', ':', get_class($function[0])) . '_')
: '') . $function_key . $extent_key.'_';
$res = $cache_instance->tableDelAll($cache_instance->tableKeys($cache_key));
if($_POST['data']['debug']){
echo $cache_key."\r\n";
}
$res
= $cache_instance->tableDelAll($cache_instance->tableKeys($cache_key));
} else {
$cache_key = (is_array($function)
? (str_replace('\\', ':', get_class($function[0])) . '_')
......
......@@ -14,7 +14,7 @@ class Pay {
private $order;
private $paySn;
private $member;
private $orderField = 'order_amount,order_sn';
private $orderField = 'order_amount,order_sn,store_id';
private $requestData ;
private $orderAmount= \Our\ApiConst::zero;
......@@ -26,15 +26,21 @@ class Pay {
$this->requestData = $data;
$this->member = \DAO\MemberModel::getInstance()->getInfo($this->memberId);
$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){
$wxpay = WxPay::getInstance();
unset($orderInfo['subMchId']);
$return = $wxpay->doPay($orderInfo);
}else if($data['channel'] == \Our\NameConst::aliApiChannel){
$alipay= Alipay::getInstance();
$return = $alipay->doPay($orderInfo);
}else if($data['channel'] == \Our\NameConst::wxLiteChannel){
$sess = \Yaf\Session::getInstance();
//$orderInfo['subMchId'] = '1517943841';
$authInfo = $sess->get('wxAuthInfo');
$orderInfo['openid'] = $authInfo['openid'];
$wxLitePay = WxLitePay::getInstance();
......@@ -50,7 +56,7 @@ class Pay {
/**
* 获取待支付订单内容
*/
public function getOrder(){
public function getOrder($wxFlag){
$dbName = \Our\DbNameConst::masterDBConnectName;
$orderDao = \DAO\Order\OrderModel::getInstance($dbName);
$orderPayDao = \DAO\Order\OrderPayModel::getInstance($dbName);
......@@ -62,9 +68,18 @@ class Pay {
if(!$orderList){
\Error\ErrorModel::throwException(\Error\CodeConfigModel::noOrderListForPay);
}
foreach($orderList as $tempOrder){
$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){
\Error\ErrorModel::throwException(\Error\CodeConfigModel::emptyOrderAmountForPay);
......
......@@ -18,6 +18,9 @@ class TencentPay {
protected $result ='';
protected $key = '';
protected $mch_id ='';
protected $s_appid ='';
protected $s_key = '';
protected $s_mch_id ='';
protected $prepay_id ='';
protected $tradeType = '';
public $data;//接收到的数据,类型为关联数组
......@@ -51,6 +54,35 @@ class TencentPay {
$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
......@@ -98,11 +130,14 @@ class TencentPay {
/**
* 作用:设置标配的请求参数,生成签名,生成接口参数xml
*/
function createXml()
function createXml($signType='MD5')
{
$this->parameters["sign"] = $this->getSign($this->parameters);//签名
if($signType=='MD5'){
//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);
}
......@@ -228,8 +263,9 @@ class TencentPay {
//签名步骤一:按字典序排序参数
ksort($Parameters);
$String = $this->formatBizQueryParaMap($Parameters, false);
$String = $String."&key=".$this->key;
//签名步骤三:MD5加密
$String = str_replace(array("\r\n", "\r", "\n"," "), "", $String);
$String = md5($String);
$result_ = strtoupper($String);
return $result_;
......@@ -239,7 +275,7 @@ class TencentPay {
/**
* 作用:生成签名(按照HMAC-SHA1规则签名)
*/
public function getHMACSHA1Sign($Obj)
public function getHMACSHA1Sign($Obj,$signType ='sha1')
{
foreach ($Obj as $k => $v)
{
......@@ -250,7 +286,7 @@ class TencentPay {
$String = $this->formatBizQueryParaMap($Parameters, false);
//$String = $String."&key=".$this->key;
//签名步骤三:HMAC-SHA1加密
$String = hash_hmac('sha1',$String,$this->key);
$String = hash_hmac($signType,$String,$this->key);
$result_ = base64_encode($String);
return $result_;
}
......@@ -307,7 +343,7 @@ class TencentPay {
$verify = true;
$this->setReturnParameter("return_code","SUCCESS");//设置返回码
}
$returnXml = $this->returnXml();;
$returnXml = $this->returnXml();
if($verify) {
return array(
'out_trade_no' => $this->data['out_trade_no'],
......@@ -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数据返回微信
*/
......
......@@ -8,21 +8,30 @@ namespace Payment;
*/
class WxLitePay extends \Payment\TencentPay{
private $refundUrl="https://api.mch.weixin.qq.com/secapi/pay/refund";
public function __construct()
{
$this->appid = \Our\PayConst::wxLiteAppId;
$this->notify_url = \Our\NameConst::httpPrefix.$_SERVER['SERVER_NAME'].\Our\PayConst::wxLiteNotifyUrl;
$this->mch_id = \Our\PayConst::wxPayMchId;
$this->key = \Our\PayConst::wxPayKey;
$this->key = \Our\PayConst::wxSPayKey;
$this->sslcert_path = \Our\PayConst::wxSslcertPath;
$this->sslkey_path = \Our\PayConst::wxSslkeyPath;
$this->pay_url = \Our\PayConst::wxPayUrl;
$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){
$this->setRequestParams($orderInfo);
if(isset($orderInfo['subMchId'])){
$this->setServiceRequestParams($orderInfo);
}else{
$this->setRequestParams($orderInfo);
}
//$this->setRequestParams($orderInfo);
$wxAppParameters = $this->getParameters();
$returnData = array(
'credential'=>array(\Our\NameConst::wxLiteChannel=>$wxAppParameters),
......@@ -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
$this->sslkey_path = \Our\PayConst::wxSslkeyPath;
$this->pay_url = \Our\PayConst::wxPayUrl;
$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)
{
$this->setRequestParams($orderInfo);
if(isset($orderInfo['subMchId'])){
$this->setServiceRequestParams($orderInfo);
}else{
$this->setRequestParams($orderInfo);
}
$wxAppParameters = $this->getParameters();
$returnData = array(
'credential' => array(\Our\NameConst::wxAppChannel => $wxAppParameters),
......@@ -51,21 +58,19 @@ class WxPay extends \Payment\TencentPay
return $wxApiObj;
}
/**
* 作用:产生随机字符串,不长于32位
*/
private function createNoncestr($length = 32)
{
$chars = "abcdefghijklmnopqrstuvwxyz0123456789";
$str = "";
for ($i = 0; $i < $length; $i++) {
$str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
public function refund($param){
if($param['subMchId']){
$this->serviceRefund($param);
}else{
$this->commonRefund($param);
}
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']);
$refund_fee = intval($param['refundFee']);
if(APP_ENV == 'develop'||APP_ENV == 'test'||APP_ENV == 'pre' || APP_ENV=='ccwdevelop'){
......@@ -81,8 +86,10 @@ class WxPay extends \Payment\TencentPay
$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::wxPayAppId;
$this->parameters['mch_id'] = \Our\PayConst::wxPayMchId;
$this->parameters['appid'] = \Our\PayConst::wxSPayAppId;
$this->parameters['mch_id'] = \Our\PayConst::wxSPayMchId;
$this->parameters['sub_appid'] = \Our\PayConst::wxSPayAppId;
$this->parameters['sub_mch_id '] = $param['subMchId'];
$xml = $this->createXml();
$response = $this->postXmlSSLCurl($xml, $this->refundUrl, 6);
$values = $this->xmlToArray($response);
......@@ -92,11 +99,12 @@ class WxPay extends \Payment\TencentPay
$this->checkSign($values);
return $values;
}
public function refundWxProgram($param)
public function commonRefund($param)
{
$total_fee = intval($param['totalFee']);
$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'|| APP_ENV=='lyztest'){
$this->parameters['total_fee'] = 1;
$this->parameters['refund_fee'] = 1;
} else {
......@@ -107,7 +115,7 @@ class WxPay extends \Payment\TencentPay
$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['appid'] = \Our\PayConst::wxPayAppId;
$this->parameters['mch_id'] = \Our\PayConst::wxPayMchId;
$xml = $this->createXml();
$response = $this->postXmlSSLCurl($xml, $this->refundUrl, 6);
......
-----BEGIN CERTIFICATE-----
MIID/jCCAuagAwIBAgIUP4Etbcyczm2HU2J+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A1ez0cEnigagsCHuw
twbG3xvFgzj8V1tidjySPIF4f1Mpj+vXkBJUH/SM47DXGb8e7ZsMtdkC4Lw2GhgM
iGBg4mMTzt3civSsHbn1vVBB/ndalccHx33408R4SOWkSv0R1fBqnEP173wfmJSA
Ge94y2E+63MtFdy5YjTl8MwtGVECgYEAzAp299e/bIoge1uGoCL7+L9+axmk2Uu1
k5/pVXI3pWY4ID7jtIZbidiiSYALFWuNdS3PadgjRy4g3rR1Vgr99+c8PJUWJtYv
SASguu0zBN6gI2ZsDXC5UlzI+xqzZGGbfA7EN0uqLXyh8tRN6OD1s1iSe7tcbqsl
ZUbCdJJ7T9cCgYEAnl2gR1ArAlkA3/bRR20Y5Cmm+hHBnNnl9im5CFnAXmGuLwEk
v18SL+XWNui/FCxMNRHHQwe3/a7XTlHnVT4j+vPlwgq0LZoboJX9uXwknsC0qpSA
ycoT3pFfineWPH1EKuCjy7Lz6ao1qbqlao3BGq6O6baF9d1Ez9LhNnWwHUECgYEA
m5v7gSbkEWYCQbHaqTQlEF8SjaGADExmDVDuhcDW2Whss4Li6+Fv3F//3KgvS8W7
mzs1rNYuiXGPlejwd49ogvCyCs30l+fPJVCKOCUAPN2AKZ9KFrH6U+r5SC/j0lFy
YBlu4XDuN0SOyf/J7ynpmD6bcIvCgZA6s9NUJ80zB/8CgYAR+YDo47AEBL/7rRR7
a7L+7h9kMSyggo31ODNt9sw5IuxMIRWaAi98jF4z2uAxjo2PSqhbiWQZ/xOd5hw2
nyXxdlFCsZYZQi8SgA8XuV3Bopk2IZzq6vHIsh+JtMZGi0wE2iCCjjVTC/Zc3NiE
MUgDT0wW7zFc7d6JGuHKzfZTDA==
-----END PRIVATE KEY-----
......@@ -5,6 +5,7 @@ namespace Business\Goods;
use Our\ApiConst;
use Our\Common;
use Our\DbNameConst;
use Zend\Json\Server\Exception\ErrorException;
class GoodsCommonServiceModel extends \Business\AbstractModel
......@@ -29,7 +30,7 @@ class GoodsCommonServiceModel extends \Business\AbstractModel
if($goodsId === 0){
\Error\ErrorModel::throwException(\Error\CodeConfigModel::commonError);
}
$goodsDao=\DAO\GoodsModel::getInstance();
$goodsDao=\DAO\GoodsModel::getInstance(DbNameConst::masterDBConnectName);
$commonDao = \DAO\GoodsCommonModel::getInstance();
$where = array();
$where['store_id'] = $storeId;
......@@ -39,6 +40,7 @@ class GoodsCommonServiceModel extends \Business\AbstractModel
\Error\ErrorModel::throwException(\Error\CodeConfigModel::goodsNotExist);
}
$op = isset($this->setStorageType[$type]) ? $this->setStorageType[$type] : 1; //默认增加库存
$goodsDao->setDb($goodsDao->dbName);
$goodsDao->db->doTransaction();
$ret1 = $goodsDao->updateStorage($goodsId, $num, $op);
$ret2 = $commonDao->updateStorage($data['goods_commonid'], $op);
......
......@@ -330,6 +330,7 @@ class OrderServiceModel extends \Business\AbstractModel
$storeDao=\DAO\StoreModel::getInstance();
//判断订单目前状态是否允许取消
$isAllowCancel = $orderDao->isAllowCancel($order);
$isAllowCance = true;
if ($isAllowCancel) {
$res = $orderDao->updateStatusByOrderId($orderId, ApiConst::orderStateCancel);
if ($res) {
......@@ -373,12 +374,23 @@ 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)
{
$orderDao = \DAO\Order\OrderModel::getInstance(DbNameConst::masterDBConnectName);
// $orderDao->deleteOrderCache($memberId, $orderId);
$order = $orderDao->findByOrderId($orderId);
$storeDao=\DAO\StoreModel::getInstance();
//$orderDao->deleteOrderCache($memberId, $orderId, $order['store_id'],true,true);
//判断订单目前状态是否允许取消
$isAllowConfirm = $orderDao->isAllowConfirm($order);
......@@ -408,6 +420,7 @@ class OrderServiceModel extends \Business\AbstractModel
$push->sendTcpMessage();
// \Our\RedisHelper::rpush('client_push',array('storeId'=>$order['storeId'],'type'=>$type,'op'=>NameConst::reduce,'num'=>ApiConst::one,'params'=>array('c'=>'shopkeeper','m'=>'orderDetail','orderId'=>$order['orderId'])));
$orderDao->deleteOrderCache($memberId, $orderId, $order['store_id'],true,true);
$storeDao->deleteStoreCache($order['storeId'],$order['orderId']);
return true;
} else {
ErrorModel::throwException(CodeConfigModel::receiveError);
......@@ -723,7 +736,7 @@ class OrderServiceModel extends \Business\AbstractModel
$orderDao->deleteOrderCache($order['buyerId'],(string)$order['orderId'],$order['storeId'],true);
$storeDao->deleteStoreCache($order['storeId'],$order['orderId']);
$push=\Our\Push::getInstance();
$pushData=array('storeId'=>$order['store_id'],
$pushData=array('storeId'=>$order['storeId'],
'type'=>ApiConst::messageWaitReceive,
'waitReceiveCount'=>ApiConst::reduceOne,
'waitDeliveryCount'=>0,
......@@ -735,7 +748,7 @@ class OrderServiceModel extends \Business\AbstractModel
'alertCount'=>ApiConst::zero,
'params'=>array('c'=>'shopkeeper',
'm'=>'orderDetail',
'orderId'=>$order['order_id']));
'orderId'=>$order['orderId']));
$push->addOneToClient($pushData);
}
......
......@@ -223,6 +223,7 @@ class RefundServiceModel extends \Business\AbstractModel
$refund_array['seller_state'] = $seller_state;//卖家处理状态:1为待审核,2为同意,3为不同意
$refund_array['seller_message'] = $text;
$refund_array['refund_amount'] = $refundAmount;
$refundReturnDao->db->setDb($refundReturnDao->dbName);
$refundReturnDao->db->doTransaction();
if($seller_state!=2){ //拒绝退款
$result= $orderGoodsDao->update(array('rec_id'=>$refund['order_goods_id']), array('is_refund'=>0, 'refund_state_name'=>'卖家拒绝退货', 'gmt_update'=>TIMESTAMP));
......@@ -313,10 +314,27 @@ class RefundServiceModel extends \Business\AbstractModel
return false;
}
}
$refundReturnDao->db->doCommit();
$refundReturnDao->deleteRefundCache($refund['buyer_id'], $refund['refund_id']);
$orderDao->deleteOrderCache($refund['buyer_id'],$refund['order_id'],$refund['store_id']);
\Our\RedisHelper::delCachedFunction(\Redis\Db5\OrderRedisModel::getInstance(), array(&$refundReturnDao, 'getList'), array(), array($refund['store_id']));
$refundReturnDao->db->doCommit();
$push=\Our\Push::getInstance();
$pushData=array('storeId'=>$storeId,
'type'=>ApiConst::messageRefund,
'waitReceiveCount'=>ApiConst::zero,
'waitDeliveryCount'=>0,
'waitGetCount'=>0,
'orderCount'=>ApiConst::zero,
'waitRefundProccessCount'=>ApiConst::reduceOne,
'waitRefundReceiveCount'=>ApiConst::zero,
'refundCount'=>ApiConst::reduceOne,
'alertCount'=>ApiConst::zero,
'params'=>array('c'=>'shopkeeper',
'm'=>'orderDetail',
'refundId'=>$order_id));
$push->addOneToClient($pushData);
$push->sendTcpMessage();
return true;
}
$refundReturnDao->db->doRollback();
......@@ -864,8 +882,8 @@ class RefundServiceModel extends \Business\AbstractModel
$refundArrayUnLine=Common::convertUnderline($refundArray);
$state = $refundReturnDao->addRefundReturn($refundArray,$orderInfo,$orderGoods);
$orderDao->deleteOrderCache($memberId,$orderInfo['orderId'],$orderInfo['storeId'],true);
$storeDao->deleteStoreCache($orderInfo['storeId'],$orderInfo['orderId']);
$storeDao->deleteStoreRefundCache($orderInfo['storeId'],$orderInfo['orderId']);
if ($state) {
$refundStateName=$refundReturnDao->getRefundTextStatus($refundArrayUnLine);
$orderGoodsDao->update(array('rec_id'=>$orderGoods['recId']),array('refund_state_name'=>$refundStateName,'refund_id'=>$state));
......
......@@ -34,27 +34,32 @@ class DeliveryServiceModel extends \Business\AbstractModel
$orderDao = \DAO\Order\OrderModel::getInstance(DbNameConst::masterDBConnectName);
$storeDao=\DAO\StoreModel::getInstance();
$qmDeliveryManLog = \DAO\Order\QmDeliverymanLogModel::getInstance(DbNameConst::masterDBConnectName);
$messageService=\Business\Message\MessageServiceModel::getInstance();
$deliveryManDao=\DAO\Order\DiliverymanModel::getInstance();
$orderDao->setDb($orderDao->dbName);
$orderD= $orderDao->find($data['order_id'],$orderDao->getOrderDetailField());
$orderD= $orderDao->find($data['orderId'],$orderDao->getOrderDetailField());
// if( $orderD['diliveryman_id']== $data['id']){
// ErrorModel::throwException(CodeConfigModel::alreadyExsitQmDeliveryLog);
// }
if(!$data['distributionFee']){
ErrorModel::throwException(CodeConfigModel::paramsError);
}
// if(!$data['distributionFee']){
// ErrorModel::throwException(CodeConfigModel::paramsError);
// }
$orderDao->db->doTransaction();
$orderData['diliveryman_id'] = $data['id'];
$orderData['order_state']=ApiConst::orderStateWaitRecieve;
$orderRes = $orderDao->updateByOrderId($orderData, $data['orderId']);
if (!$orderRes) {
$orderDao->db->doRollback();
ErrorModel::throwException(CodeConfigModel::updateOrderFail);
}
// if (!$orderRes) {
// $orderDao->db->doRollback();
// ErrorModel::throwException(CodeConfigModel::updateOrderFail);
// }
$qmDeliveryManLogData['diliveryman_id'] = $data['id'];
$qmDeliveryManLogData['store_id'] = $data['storeId'];
$qmDeliveryManLogData['order_id'] = $data['orderId'];
$qmDeliveryManLogData['delivery_state'] = ApiConst::deliveryStateWait;
$qmDeliveryManLogData['distribution_fee'] =$data['distributionFee'];
$qmDeliveryManLogData['order_type'] = $data['orderType'];
$qmDeliveryManLogData['shipping_fee'] = $orderD['shippingFee'];
$qmDeliveryManLogData['order_sn'] = $orderD['orderSn'];
$qmDeliveryManLogData['get_time'] = TIMESTAMP;
// $qmDeliveryWhere['diliveryman_id']= $qmDeliveryManLogData['diliveryman_id'];
$qmDeliveryWhere['order_id']=$qmDeliveryManLogData['order_id'];
......@@ -69,10 +74,18 @@ class DeliveryServiceModel extends \Business\AbstractModel
$orderDao->db->doRollback();
ErrorModel::throwException(CodeConfigModel::selectDeliveryFail);
}
$orderDao->deleteOrderCache(null, $data['orderId'], $data['storeId'], true,false,$orderD['buyerId']);
$storeDao->deleteStoreCache($data['storeId'],$data['orderId']);
$orderDao->db->doCommit();
$deliveryMan=$deliveryManDao->findById($orderD['diliverymanId']);
$deliveryManMemberId=$deliveryMan['memberId'];
$deliveryMan=$deliveryManDao->findById($data['id']);
$oringeDeliveryManMemberId=$deliveryMan['memberId'];
$deliveryManMemberIds=array($deliveryManMemberId,$oringeDeliveryManMemberId);
$orderDao->deleteOrderCache(null, $data['orderId'], $data['storeId'], true,false,$deliveryManMemberIds);
$storeDao->deleteStoreCache($data['storeId'],$data['orderId']);
//配送员推送
$push=\Our\Push::getInstance();
$push->sendDelivery($oringeDeliveryManMemberId,$data['orderId']);
$messageService->addMessageCenterToDb();
return $res;
}
......
......@@ -246,7 +246,12 @@ class ShopkeeperServiceModel extends \Business\AbstractModel
ErrorModel::throwException(CodeConfigModel::orderNotExist);
}
} else {
$update_data['order_state'] = ApiConst::orderStateWaitSend;
if($order['shipping_type']==ApiConst::bySeller){
$update_data['order_state'] = ApiConst::orderStateWaitSend;
}else{
$update_data['order_state']=ApiConst::orderStateWaitRecieve;
}
$update_data['accept_time'] = TIMESTAMP;
$result = $orderDao->update($where, $update_data);
if($order['shipping_type']==ApiConst::bySelf){
......
......@@ -44,6 +44,7 @@ class GoodsModel extends \DAO\AbstractModel {
} else { //调整库存预警为不需要预警
$updateSql = 'goods_storage_alarm =0';
}
$updateSql=$updateSql.",goods_edittime=".TIMESTAMP;
$updateAllSql = "UPDATE {$this->_tableName} set {$updateSql} where {$whereSql}";
return $this->db->update($this->_tableName)->query($updateAllSql);
}
......
......@@ -43,6 +43,7 @@ class GoodsCommonModel extends \DAO\AbstractModel {
} else {
$updateSql = 'goods_storage_alarm = 0';
}
$updateSql=$updateSql . ",goods_edittime=".TIMESTAMP;
$updateAllSql = "UPDATE {$this->_tableName} set {$updateSql} where {$whereSql}";
return $this->db->update($this->_tableName)->query($updateAllSql);
}
......
......@@ -848,7 +848,8 @@ class OrderModel extends \DAO\AbstractModel
return \Our\RedisHelper::delCachedFunction(\Redis\Db5\OrderRedisModel::getInstance(), array(&$this, 'getShopKeeperCountByStoreId'), array(),array($storeId));
}
public function deleteDeliveryLogCache($memberId){
\Our\RedisHelper::delCachedFunction(\Redis\Db5\OrderRedisModel::getInstance(), array(&$this, 'getListByDeliverymanIdAndType'), array(), array($memberId));
$qmDiliveryManLog=\DAO\Order\QmDeliverymanLogModel::getInstance();
\Our\RedisHelper::delCachedFunction(\Redis\Db5\OrderRedisModel::getInstance(), array(&$qmDiliveryManLog, 'getListByDeliverymanIdAndType'), array(), array($memberId));
}
//删除订单列表缓存
public function deleteGetListByMemberId($storeId)
......@@ -886,7 +887,13 @@ class OrderModel extends \DAO\AbstractModel
}
if(!empty($diliverymanId)){
$this->deleteGetListByMemberId($diliverymanId);
if(is_array($diliverymanId)){
foreach($diliverymanId as $memberId){
$this->deleteDeliveryLogCache($memberId);
}
}else{
$this->deleteDeliveryLogCache($diliverymanId);
}
$orderGoodsDao = \DAO\Order\OrderGoodsModel::getInstance(DbNameConst::masterDBConnectName);
$orderGoodsDao->deleteOrderGoodsCache($diliverymanId, $orderId);
$QmDeliveryLogDao = \DAO\Order\QmDeliverymanLogModel::getInstance(DbNameConst::salveDBConnectName);
......
......@@ -141,6 +141,8 @@ class QmDeliverymanLogModel extends \DAO\AbstractModel
return \Our\RedisHelper::cachedFunction(\Redis\Db5\OrderRedisModel::getInstance(), array(&$this, 'getListByDeliverymanIdAndType'), array($diliveryId, $type, $pageIndex, $pageSize, $order), ApiConst::oneDaySecond, array($memberId));
}
/**
* 获取单条数据
* @param $where
......
......@@ -334,8 +334,17 @@ class RefundReturnModel extends \DAO\AbstractModel {
$param['refundFee'] = $orderInfo['refund_amount'];//退款金额
$param['storeId'] = $orderInfo['store_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) {
$wxpay = \Payment\WxPay::getInstance();
unset($param['subMchId']);
$refund_return = $wxpay->refund($param);
$this->errorMessage= "微信返回:".json_encode($refund_return);
if (!($refund_return['return_code'] == 'SUCCESS' && $refund_return['result_code'] == 'SUCCESS')) {
......@@ -379,8 +388,17 @@ class RefundReturnModel extends \DAO\AbstractModel {
$param['refundFee'] = $orderInfo['orderAmount'];//全额退款
$param['storeId']=$orderInfo['storeId'];
$param['buyerId']=$orderInfo['buyerId'];
if (intval($orderInfo['paymentType']) == ApiConst::wxAppPayType) {
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||intval($orderInfo['paymentType']) == 3) {
$wxpay = \Payment\WxPay::getInstance();
unset($param['subMchId']);
$refund_return = $wxpay->refund($param);
$this->errorMessage= "微信返回:".json_encode($refund_return);
if (!($refund_return['return_code'] == 'SUCCESS' && $refund_return['result_code'] == 'SUCCESS')) {
......@@ -399,9 +417,9 @@ class RefundReturnModel extends \DAO\AbstractModel {
return false;
}
}else if(intval($orderInfo['paymentType']) == ApiConst::wxProgram){
$wxpay = \Payment\WxPay::getInstance();
$refund_return = $wxpay->refundWxProgram($param);
$this->errorMessage= "微信小程序返回:".json_encode($refund_return);
$wxpay = \Payment\WxLitePay::getInstance();
$refund_return = $wxpay->refund($param);
if (!($refund_return['return_code'] == 'SUCCESS' && $refund_return['result_code'] == 'SUCCESS')) {
$this->errorMessage=date('Y-m-d').'微信退款操作执行失败!'.$orderInfo['orderId']."\r\n";
return false;
......
......@@ -28,6 +28,8 @@ class StoreModel extends \DAO\AbstractModel
*/
protected $_tableName = 'han_store';
protected $_tableNameFull = 'han_store_full';
/**
* 主键
*
......@@ -75,7 +77,7 @@ class StoreModel extends \DAO\AbstractModel
{
$this->setDb($this->dbName);
$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) {
return $store[$isField];
} else {
......@@ -544,4 +546,26 @@ class StoreModel extends \DAO\AbstractModel
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
const noOrderWaitToPay = 30130;
const wrongEvaluation = 30131;
const selfGoodsForStoreOrder = 3032;
const selfGoodsForStoreOrder = 30132;
const refundAddPointsLogError = 30133;
const wrongDeliveryTime = 300134;
const wrongBuyerTimeRangeForOrder =300135;
const emptyBuyerMobile = 300136;
const orderWxPayError = 30137;
const orderWxPaySignError = 30138;
//店铺相关错误码
//商品分类
......@@ -802,6 +807,8 @@ class CodeConfigModel
self::notAllowUpdataOrderAmount=>'当前状态不允许修改订单金额',
self::wrongEvaluation => '商品评论应在6-500字之间',
self::selfGoodsForStoreOrder => '店主不能购买自己的商品',
self::orderWxPayError => '微信支付尚未开通',
self::orderWxPaySignError => '微信支付签名错误',
//销售员
self::emptySaleGoodsId => '商品id不能为空',
self::emptySaleGoods => '销售商品不存在',
......
......@@ -224,6 +224,8 @@ push.open=1
push.user.service.id=293
push.user.service.type=7
password.key='~!@#$`1234qwertasdfgzxcvb'
[develop : common]
; 数据库配置
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