Commit 52185337 authored by wwccw0591's avatar wwccw0591

pc

parent 6dd4bcf4
......@@ -57,7 +57,28 @@ class Common
return isset($httpStatusCodes[$num]) ? $httpStatusCodes[$num] : '';
}
public static function isSerialized( $data ) {
$data = trim( $data );
if ( 'N;' == $data )
return true;
if ( !preg_match( '/^([adObis]):/', $data, $badions ) )
return false;
switch ( $badions[1] ) {
case 'a' :
case 'O' :
case 's' :
if ( preg_match( "/^{$badions[1]}:[0-9]+:.*[;}]\$/s", $data ) )
return true;
break;
case 'b' :
case 'i' :
case 'd' :
if ( preg_match( "/^{$badions[1]}:[0-9.E-]+;\$/", $data ) )
return true;
break;
}
return false;
}
/**
* 获取客户端IP
*
......
......@@ -210,7 +210,8 @@ class Push
if ($push['open']) {
if(!empty($this->data)){
$message['data'] = $this->data;
$message['uid'] = $this->uid;
$message['uid'] = !empty($this->uid)?$this->uid:ApiConst::zero;
$message['data']=array_slice($message['data'],2,14);
$message = json_encode($message);
$message = $message . "\r\n";
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
......
......@@ -8,32 +8,35 @@ namespace Payment;
* Description:
*/
class WxPay extends \Payment\TencentPay{
class WxPay extends \Payment\TencentPay
{
public function __construct()
{
$this->appid = \Our\PayConst::wxPayAppId;
$this->notify_url = \Our\NameConst::httpPrefix.$_SERVER['SERVER_NAME'].\Our\PayConst::wxAppNotifyUrl;
$this->mch_id = \Our\PayConst::wxPayMchId;
$this->key = \Our\PayConst::wxPayKey;
$this->sslcert_path = \Our\PayConst::wxSslcertPath;
$this->sslkey_path = \Our\PayConst::wxSslkeyPath;
$this->pay_url = \Our\PayConst::wxPayUrl;
$this->tradeType = \Our\PayConst::wxAppTradeType;
}
private $refundUrl="https://api.mch.weixin.qq.com/secapi/pay/refund";
public function __construct()
{
$this->appid = \Our\PayConst::wxPayAppId;
$this->notify_url = \Our\NameConst::httpPrefix . $_SERVER['SERVER_NAME'] . \Our\PayConst::wxAppNotifyUrl;
$this->mch_id = \Our\PayConst::wxPayMchId;
$this->key = \Our\PayConst::wxPayKey;
$this->sslcert_path = \Our\PayConst::wxSslcertPath;
$this->sslkey_path = \Our\PayConst::wxSslkeyPath;
$this->pay_url = \Our\PayConst::wxPayUrl;
$this->tradeType = \Our\PayConst::wxAppTradeType;
}
public function doPay($orderInfo){
public function doPay($orderInfo)
{
$this->setRequestParams($orderInfo);
$wxAppParameters = $this->getParameters();
$returnData = array(
'credential'=>array(\Our\NameConst::wxAppChannel=>$wxAppParameters),
'app_id'=>$this->appid
);
'credential' => array(\Our\NameConst::wxAppChannel => $wxAppParameters),
'app_id' => $this->appid
);
return $returnData;
}
/**
* 作用:设置APP支付的参数
* 作用:设置APP支付的参数
*/
public function getParameters()
{
......@@ -48,6 +51,45 @@ 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);
}
return $str;
}
public function refund($param)
{
$total_fee = intval($param['totalFee']);
$refund_fee = intval($param['refundFee']);
if (APP_ENV == 'develop' || APP_ENV == 'test' || APP_ENV == 'pre') {
$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['refund_order_no'];
$this->parameters['out_trade_no'] = $param['out_trade_no'];
$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;
$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;
}
/**
* 类实例
......
......@@ -2,6 +2,7 @@
namespace Business\Order;
use DAO\Order\OrderCommonModel;
use Error\CodeConfigModel;
use Error\ErrorModel;
use Order\OrderConfirmUtil;
......@@ -30,7 +31,7 @@ class OrderServiceModel extends \Business\AbstractModel
private $storeField = "offline_payway as offlinePayway";
private $orderMessageField = "order_id as orderId,order_sn as orderSn,order_pay as orderPay,store_name as storeName,add_time as addTime,store_id as storeId,goods_amount as goodsAmount,shipping_fee as shippingFee,order_amount as orderAmount,shipping_type as shippingType,payment_type as paymentType,order_state as orderState,shipping_fee as shippingFee,refund_state as refundState,order_type as orderType,is_receive_payment as isReceivePayment,buyer_id as buyerId,buyer_name as buyerName,accept_time as acceptTime";
private $orderMessageField = "order_id as orderId,order_sn as orderSn,store_name as storeName,add_time as addTime,store_id as storeId,goods_amount as goodsAmount,shipping_fee as shippingFee,order_amount as orderAmount,shipping_type as shippingType,payment_type as paymentType,order_state as orderState,shipping_fee as shippingFee,refund_state as refundState,order_type as orderType,is_receive_payment as isReceivePayment,buyer_id as buyerId,buyer_name as buyerName,accept_time as acceptTime";
private $order;
......@@ -395,8 +396,9 @@ class OrderServiceModel extends \Business\AbstractModel
file_put_contents($savePath, TIMESTAMP);
}
public function changeOrderStateCancelUnconditional($orderInfo, $role, $user = '', $msg = '', $if_update_account = true, $if_quque = true)
public function changeOrderStateCancelUnconditional($orderInfo)
{
echo json_encode($orderInfo);exit;
$orderDao = \DAO\Order\OrderModel::getInstance(DbNameConst::masterDBConnectName);
$refundReturnDao = \DAO\Order\RefundReturnModel::getInstance(DbNameConst::masterDBConnectName);
//$orderGoodsDao=\DAO\Order\OrderGoodsModel::getInstance();
......@@ -404,8 +406,9 @@ class OrderServiceModel extends \Business\AbstractModel
try {
$orderId = $orderInfo['orderId'];
//更新订单信息
$updateData = array('order_state' => ORDER_STATE_CANCEL,'refund_amount'=>$orderInfo['orderAmount']);
$update = $orderDao->update($updateData, array('order_id' => $orderId));
// $updateData = array('order_state' => ORDER_STATE_CANCEL,'refund_amount'=>$orderInfo['orderAmount']);
// $update = $orderDao->update($updateData, array('order_id' => $orderId));
$update=true;
if (!$update) {
echo '订单:' . json_encode($orderInfo) . '关闭失败!!' . "\r\n";
......@@ -430,7 +433,9 @@ class OrderServiceModel extends \Business\AbstractModel
$update['reason_info'] = '用户付款' . $waitDiff . '分钟内,店铺未接单,自动取消订单';
$update['buyer_message'] = '用户付款' . $waitDiff. '分钟内,店铺未接单,自动取消订单';
$update['is_suc_refund'] = 1;
echo json_encode($update);exit;
$res = $refundReturnDao->add($update);
if (!$res) {
echo '退款记录:' . json_encode($orderInfo) . '写入失败!!' . "\r\n";
}else{
......@@ -439,28 +444,24 @@ class OrderServiceModel extends \Business\AbstractModel
$param['totalFee'] = $orderInfo['orderAmount'];
$param['refundFee'] = $orderInfo['orderAmount'];//全额退款
$param['storeId']=$orderInfo['storeId'];
if (intval($orderInfo['paymentType']) == ApiConst::wxAppPayType) {
require_once(BASE_ROOT_PATH . '/qmmobile/api/payment/wxpay/wxpay.php'); //加载 退款模块
$wxpay = new wxpay();
$wxpay = \Payment\WxPay::getInstance();
$refund_return = $wxpay->refund($param);
Log::record(json_encode($refund_return));
echo json_encode($refund_return);
if (!($refund_return['return_code'] == 'SUCCESS' && $refund_return['result_code'] == 'SUCCESS')) {
throw new Exception('微信退款操作执行失败!');
}
} else if (intval($orderInfo['paymentType']) == ApiConst::aliPayType) {
$aliPay=\Payment\Alipay::getInstance();
$return = $aliPay->refund($param);
echo json_encode($return);
$resultCode = $return->code;
if(!empty($resultCode)&&$resultCode == 10000){
return true;
} else {
return false;
}
$param['store_id'] = $orderInfo['storeId'];
include(BASE_ROOT_PATH . '/core/payment/alipay/alipay.php');
$payment_api = new alipay();
$return = $payment_api->refund($param);
$resultCode = $return->code;
if (!($resultCode && $resultCode == 10000)) {
throw new Exception('支付宝退款操作执行失败!');
}
......@@ -484,25 +485,42 @@ class OrderServiceModel extends \Business\AbstractModel
{
$orderDao = \DAO\Order\OrderModel::getInstance(DbNameConst::masterDBConnectName);
$orderGoodsDao = \DAO\Order\OrderGoodsModel::getInstance(DbNameConst::masterDBConnectName);
$orderGoodsCommon = \DAO\Order\OrderCommonModel::getInstance(DbNameConst::masterDBConnectName);
$orderConfirmUtilDao=OrderConfirmUtil::getInstance(DbNameConst::masterDBConnectName);
$beginTime = file_get_contents($this->baseDir . \Our\PathConst::orderCloseWaitRecieveOrder, TIMESTAMP);
$beginTime = $beginTime ? $beginTime : ApiConst::zero;
$endTime = TIMESTAMP - ApiConst::orderStateWaitConfirmBeyond;
$orders = $orderDao->getMustCecelRecieveOrders(ApiConst::orderStateWaitConfirm, $beginTime, $endTime, $this->orderMessageField);
$orders = $orderDao->getMustCecelRecieveOrders($beginTime, $endTime, $orderDao->getOrderDetailField());
if (!empty($orders)) {
$orderIds = array_column($orders, 'orderId');
$orderGoods = $orderGoodsDao->getOrderGoodsByOrderIds($orderIds, $this->getGoodsDetailField());
$orderGoodsCommon->updateGoodsStorage($orderGoods);
$storeCartsList=array();
$storeCarts=array();
$storeCarts['storeCarts']=array();
foreach($orderGoods as $orderGood){
$orderGood['type']=!empty($orderGood['goodsGroup'])? \Our\ApiConst::addBundingToCart:\Our\ApiConst::addGoodsToCart;
$orderGood['goodsNum']=-$orderGood['goodsNum'];
$orderGood['goodsList']=\Our\Common::isSerialized($orderGood['goodsGroup'])?unserialize($orderGood['goodsGroup']):array();
array_push($storeCarts['storeCarts'],$orderGood);
}
if(!empty($storeCarts['storeCarts'])){
array_push($storeCartsList,$storeCarts);
}
//$res = $orderDao->updateNotRecieveOrders(ApiConst::orderStateWaitConfirm, ApiConst::orderStateClose, 'add_time', ApiConst::orderStateWaitConfirmBeyond, $this->orderMessageField);
foreach ($orders as $order) {
$orderDao->deleteOrderCache($order['buyerId'], $order['orderId'], $order['storeId']);
if ($orders['paymentTime'] > ApiConst::zero && in_array($orders['paymentType'], ArrayConst::payTypeOnlines)) {
$this->changeOrderStateCancelUnconditional($order);
if(!empty($orders)){
foreach ($orders as $order) {
$orderDao->deleteOrderCache($order['buyerId'], $order['orderId'], $order['storeId']);
// if ($order['paymentTime'] > ApiConst::zero && in_array($orders['paymentType'], ArrayConst::payTypeOnlines)) {
// $this->changeOrderStateCancelUnconditional($order);
// }
}
$orderDao->deleteOrderCache($order['buyerId'],$order['orderId'],$order['storeId']);
}
$push = Push::getInstance();
$push->pushOrderCloseMessage($orders);
// try{
// $orderConfirmUtilDao->updateGoodsStorage($storeCartsList);
// }catch(\Exception $ex){
// throw new \Exception('商品库存更新失败:'.$ex->getMessage(),$ex->getCode());
// }
}
}
......
......@@ -45,7 +45,7 @@ class OrderModel extends \DAO\AbstractModel
public function getOrderDetailField()
{
return 'order_id as orderId,coupon_id as couponId,refund_amount as refundAmount,order_sn as orderSn,store_name as storeName,add_time as addTime,store_id as storeId,goods_amount as goodsAmount,shipping_fee as shippingFee,order_amount as orderAmount,shipping_type as shippingType,payment_type as paymentType,order_state as orderState,shipping_fee as shippingFee,refund_state as refundState,order_type as orderType,is_receive_payment as isReceivePayment,payment_time as paymentTime,finnshed_time as finnshedTime,need_shipping_fee as needShippingFee,payment_code as paymentCode,buyer_id as buyerId,buyer_name as buyerName,refund_condition as refundCondition';
return 'order_id as orderId,coupon_id as couponId,refund_amount as refundAmount,order_sn as orderSn,pay_sn as paySn,store_name as storeName,add_time as addTime,store_id as storeId,goods_amount as goodsAmount,shipping_fee as shippingFee,order_amount as orderAmount,shipping_type as shippingType,payment_type as paymentType,order_state as orderState,shipping_fee as shippingFee,refund_state as refundState,order_type as orderType,is_receive_payment as isReceivePayment,payment_time as paymentTime,finnshed_time as finnshedTime,need_shipping_fee as needShippingFee,payment_code as paymentCode,buyer_id as buyerId,buyer_name as buyerName,refund_condition as refundCondition';
}
public function getOrderShippingField()
......
......@@ -162,7 +162,8 @@ abstract class BaseCli
protected function _getBaseFileName($path)
{
return dirname(__FILE__).DS.$path.DS.'locks';
$locksPath=\Our\Common::getConfig('out.locks');
return $locksPath.DS.$path.DS.'locks';
}
......
......@@ -56,12 +56,12 @@ class cliOrderClose extends basecli
echo "*** Debug mode ***\n";
}
// Step: 02 检查是否已有相同CLI在运行中
$lockDir=$this->_getBaseFileName('orderClose');
$lockDir=$this->_getBaseFileName('order');
if(!$this->mkdirs($lockDir)){
echo '****create dir fail ****';
exit;
}
$this->lockFileName = $lockDir .'.locks';
$this->lockFileName = $lockDir .DS.'close.locks';
if( file_exists( $this->lockFileName ) )
{
$stat = stat($this->lockFileName);
......@@ -76,7 +76,9 @@ class cliOrderClose extends basecli
}
}
$this->bDoUnLock = true;
file_put_contents($this->lockFileName ,"running" ); // CLI 独占锁
if(APP_ENV =='pre' || APP_ENV=='product'){
file_put_contents($this->lockFileName ,"running" ); // CLI 独占锁
}
$this->autoCloseOrder();
echo '定单关闭消息发送成功'."\r\n";
......
......@@ -187,8 +187,14 @@ $tcp_server->on('connect', function($serv, $fd) use($conf){
* 4. 按照用户类型(channel)推送
*/
$tcp_server->on('receive', function($serv, $fd, $from_id, $data) use($conf) {
echo $data;
$data = json_decode($data, true);
if(empty($data['data']) && !isset($data['data'])) return;
var_dump($data);
if(empty($data['data']) && !isset($data['data'])){
$serv->send($fd, responseJson(1,"fail", ['method' => 'receive', 'error_code' => 1, 'status' => 0]));
$serv->close($fd);
return;
}
$s = json_encode($data['data']);
echo $s;
// 推送 存入redis、最后入库(MySQL)
......
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