Commit 1202b8c2 authored by wwccw0591's avatar wwccw0591

pc

parent 49c4b5c5
......@@ -2,7 +2,9 @@
namespace Alipay\aop;
require_once 'AopEncrypt.php';
require_once 'SignData.php';
$libaryUrl=\Bootstrap::getUrlIniConfig('libary');
require_once ($libaryUrl.'/Alipay/lotusphp_runtime/Logger/LtLogger.php');
class AopClient {
//应用ID
public $appId;
......@@ -230,14 +232,12 @@ class AopClient {
$reponse = curl_exec($ch);
if (curl_errno($ch)) {
throw new Exception(curl_error($ch), 0);
throw new \Exception(curl_error($ch), 0);
} else {
$httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (200 !== $httpStatusCode) {
throw new Exception($reponse, $httpStatusCode);
throw new \Exception($reponse, $httpStatusCode);
}
}
......@@ -253,7 +253,7 @@ class AopClient {
protected function logCommunicationError($apiName, $requestUrl, $errorCode, $responseTxt) {
$localIp = isset ($_SERVER["SERVER_ADDR"]) ? $_SERVER["SERVER_ADDR"] : "CLI";
$logger = new LtLogger;
$logger = new \LtLogger();
$logger->conf["log_file"] = rtrim(AOP_SDK_WORK_DIR, '\\/') . '/' . "logs/aop_comm_err_" . $this->appId . "_" . date("Y-m-d") . ".log";
$logger->conf["separator"] = "^_^";
$logData = array(
......@@ -464,7 +464,7 @@ class AopClient {
$sysParams["notify_url"] = $request->getNotifyUrl();
$sysParams["charset"] = $this->postCharset;
$sysParams["app_auth_token"] = $appInfoAuthtoken;
//获取业务参数
$apiParams = $request->getApiParas();
......@@ -475,17 +475,17 @@ class AopClient {
if ($this->checkEmpty($apiParams['biz_content'])) {
throw new Exception(" api request Fail! The reason : encrypt request is not supperted!");
throw new \Exception(" api request Fail! The reason : encrypt request is not supperted!");
}
if ($this->checkEmpty($this->encryptKey) || $this->checkEmpty($this->encryptType)) {
throw new Exception(" encryptType and encryptKey must not null! ");
throw new \Exception(" encryptType and encryptKey must not null! ");
}
if ("AES" != $this->encryptType) {
throw new Exception("加密类型只支持AES");
throw new \Exception("加密类型只支持AES");
}
// 执行加密
......@@ -510,7 +510,7 @@ class AopClient {
//发起HTTP请求
try {
$resp = $this->curl($requestUrl, $apiParams);
} catch (Exception $e) {
} catch (\Exception $e) {
$this->logCommunicationError($sysParams["method"], $requestUrl, "HTTP_ERROR_" . $e->getCode(), $e->getMessage());
return false;
......@@ -1014,7 +1014,7 @@ class AopClient {
* @param $signData
* @param $resp
* @param $respObject
* @throws Exception
* @throws \Exception
*/
public function checkResponseSign($request, $signData, $resp, $respObject) {
......@@ -1023,7 +1023,7 @@ class AopClient {
if ($signData == null || $this->checkEmpty($signData->sign) || $this->checkEmpty($signData->signSourceData)) {
throw new Exception(" check sign Fail! The reason : signData is Empty");
throw new \Exception(" check sign Fail! The reason : signData is Empty");
}
......@@ -1045,12 +1045,12 @@ class AopClient {
$checkResult = $this->verify($signData->signSourceData, $signData->sign, $this->alipayPublicKey, $this->signType);
if (!$checkResult) {
throw new Exception("check sign Fail! [sign=" . $signData->sign . ", signSourceData=" . $signData->signSourceData . "]");
throw new \Exception("check sign Fail! [sign=" . $signData->sign . ", signSourceData=" . $signData->signSourceData . "]");
}
} else {
throw new Exception("check sign Fail! [sign=" . $signData->sign . ", signSourceData=" . $signData->signSourceData . "]");
throw new \Exception("check sign Fail! [sign=" . $signData->sign . ", signSourceData=" . $signData->signSourceData . "]");
}
}
......
<?php
namespace Alipay\aop;
/**
* Created by PhpStorm.
* User: jiehua
......
......@@ -207,12 +207,21 @@ class Push
public function sendTcpMessage()
{
$push = \Yaf\Registry::get('config')->get('push');
$conf = \Yaf\Registry::get('config')->get('redis.database.params');
if ($push['open']) {
if(!empty($this->data)){
$redis=new \Redis();
$redis->connect($conf['host'], $conf['port']);
if(!empty($conf['password'])){
$redis->auth($conf['password']);
}
$message['data'] = $this->data;
$message['uid'] = !empty($this->uid)?$this->uid:ApiConst::zero;
// $message['data']=array_slice($message['data'],2,14);
$message = json_encode($message);
$key=md5($message);
$redis->set($key,$message);
$message=$key;
$message = $message . "\r\n";
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if (!@socket_connect($socket, $push['host'], $push['port'])) {
......@@ -239,6 +248,7 @@ class Push
return true;
}
unset($this->data);
unset($redis);
}
} else {
$this->errorCode = CodeConfigModel::pushIsNotOpen;
......
......@@ -62,7 +62,7 @@ class Alipay {
}
public function refund($order){
$refundAmount = round($order['refundAmount']/\Our\ApiConst::hundred,\Our\ApiConst::two);
if(APP_ENV == 'develop'||APP_ENV == 'test'||APP_ENV == 'pre'){
if(APP_ENV == 'develop'||APP_ENV == 'test'||APP_ENV == 'pre' || APP_ENV=='ccwdevelop'){
$refundAmount = 0.01;
}
$aop = new \Alipay\aop\AopClient();
......@@ -77,7 +77,7 @@ class Alipay {
$outRequestNo=$this->getRandomString(ApiConst::nine);
// require_once BASE_ROOT_PATH.'/core/payment/alipay/aop/request/AlipayTradeRefundRequest.php';
// //require_once 'aop/request/AlipayTradeRefundRequest.php';
$request = new \Alipay\aop\request\AlipayTradeAppPayRequest();
$request = new \Alipay\aop\request\AlipayTradeRefundRequest();
$request->setBizContent("{" .
"\"out_trade_no\":\"{$order['outTradeNo']}\"," .
"\"refund_amount\":{$refundAmount}," .
......
......@@ -68,15 +68,15 @@ class WxPay extends \Payment\TencentPay
{
$total_fee = intval($param['totalFee']);
$refund_fee = intval($param['refundFee']);
if (APP_ENV == 'develop' || APP_ENV == 'test' || APP_ENV == 'pre') {
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['refund_order_no'];
$this->parameters['out_trade_no'] = $param['out_trade_no'];
$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::wxPayAppId;
......
......@@ -397,79 +397,69 @@ class OrderServiceModel extends \Business\AbstractModel
public function changeOrderStateCancelUnconditional($orderInfo)
{
echo 234234;exit;
$orderDao = \DAO\Order\OrderModel::getInstance(DbNameConst::masterDBConnectName);
$refundReturnDao = \DAO\Order\RefundReturnModel::getInstance(DbNameConst::masterDBConnectName);
//$orderGoodsDao=\DAO\Order\OrderGoodsModel::getInstance();
$orderGoodsDao=\DAO\Order\OrderGoodsModel::getInstance(DbNameConst::masterDBConnectName);
// $orderGoods=$orderGoodsDao->getOrderGoodsByOrderIds($orderInfo['orderId']);
try {
$orderId = $orderInfo['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";
$update=array();
$refundSn = $refundReturnDao->getRefundsn($orderInfo['storeId']);
//生成退款记录
$update['order_id'] = $orderInfo['orderId'];
$update['order_sn'] = $orderInfo['orderSn'];
$update['refund_sn'] = $refundSn;
$update['store_id'] = $orderInfo['storeId'];
$update['store_name'] = $orderInfo['storeName'];
$update['buyer_id'] = $orderInfo['buyerId'];
$update['buyer_name'] = $orderInfo['buyerName'];
$update['goods_id'] = ApiConst::zero;
$update['goods_name'] = '订单商品全部退款';
$update['refund_amount'] = $orderInfo['orderAmount'];
$update['seller_state'] = 2;
$update['refund_state'] = 3;
$update['goods_state'] = 5;
$update['add_time'] = time();
$waitDiff=(ApiConst::orderStateWaitConfirmBeyond/ApiConst::oneMinSecond);
$update['reason_info'] = '用户付款' . $waitDiff . '分钟内,店铺未接单,自动取消订单';
$update['buyer_message'] = '用户付款' . $waitDiff. '分钟内,店铺未接单,自动取消订单';
$update['is_suc_refund'] = 1;
$res = $refundReturnDao->addRefundReturn($update);
if (!$res) {
echo '退款记录:' . json_encode($orderInfo) . '写入失败!!' . "\r\n";
}else{
echo 2134234;exit;
$refundSn = $refundReturnDao->getRefundsn($orderInfo['storeId']);
//生成退款记录
$update['order_id'] = $orderInfo['orderId'];
$update['order_sn'] = $orderInfo['orderSn'];
$update['refund_sn'] = $refundSn;
$update['store_id'] = $orderInfo['storeId'];
$update['store_name'] = $orderInfo['storeName'];
$update['buyer_id'] = $orderInfo['buyerId'];
$update['buyer_name'] = $orderInfo['buyerName'];
$update['goods_id'] = ApiConst::zero;
$update['goods_name'] = '订单商品全部退款';
$update['refund_amount'] = $orderInfo['orderAmount'];
$update['seller_state'] = 2;
$update['refund_state'] = 3;
$update['goods_state'] = 5;
$update['add_time'] = time();
$waitDiff=(ApiConst::orderStateWaitConfirmBeyond/ApiConst::oneMinSecond);
$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{
$param['refundOrderNo'] = $refundSn;
$param['outTradeNo'] = $orderInfo['paySn'];
$param['totalFee'] = $orderInfo['orderAmount'];
$param['refundFee'] = $orderInfo['orderAmount'];//全额退款
$param['storeId']=$orderInfo['storeId'];
if (intval($orderInfo['paymentType']) == ApiConst::wxAppPayType) {
$wxpay = \Payment\WxPay::getInstance();
$refund_return = $wxpay->refund($param);
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;
}
if (!($resultCode && $resultCode == 10000)) {
throw new Exception('支付宝退款操作执行失败!');
}
$param['refundOrderNo'] = $refundSn;
//这个有可能多次退款的时候要变
$param['outTradeNo'] = $orderInfo['paySn'];
$param['totalFee'] = $orderInfo['orderAmount'];
$param['refundFee'] = $orderInfo['orderAmount'];//全额退款
$param['storeId']=$orderInfo['storeId'];
$param['buyerId']=$orderInfo['buyerId'];
if (intval($orderInfo['paymentType']) == ApiConst::wxAppPayType) {
$wxpay = \Payment\WxPay::getInstance();
$refund_return = $wxpay->refund($param);
if (!($refund_return['return_code'] == 'SUCCESS' && $refund_return['result_code'] == 'SUCCESS')) {
echo '微信退款操作执行失败!'.$orderInfo['orderId']."\r\n";
return false;
}
} else if (intval($orderInfo['paymentType']) == ApiConst::alipay) {
$aliPay=\Payment\Alipay::getInstance();
$return = $aliPay->refund($param);
$resultCode = $return->code;
if(!empty($resultCode)&&$resultCode == 10000){
return true;
} else {
echo '支付宝退款操作执行失败:'.$orderInfo['orderId']."\r\n";
return false;
}
$orderDao->deleteOrderCache($orderInfo['buyerId']);
echo $orderId." 退款操作操作成功";
}
$where['order_id']=$orderInfo['orderId'];
$orderGoodsUpdateData['refund_state_name']='退款成功';
$orderGoodsUpdateData['refund_id']=1;
$orderGoodsDao->update($where,$orderGoodsUpdateData);
echo " 退款操作操作成功:".$orderId;
return true;
}
......@@ -490,37 +480,46 @@ class OrderServiceModel extends \Business\AbstractModel
$beginTime = $beginTime ? $beginTime : ApiConst::zero;
$endTime = TIMESTAMP - ApiConst::orderStateWaitConfirmBeyond;
$orders = $orderDao->getMustCecelRecieveOrders($beginTime, $endTime, $orderDao->getOrderDetailField());
if (!empty($orders)) {
$orderIds = array_column($orders, 'orderId');
$orderGoods = $orderGoodsDao->getOrderGoodsByOrderIds($orderIds, $this->getGoodsDetailField());
// $orderGoods = $orderGoodsDao->getOrderGoodsByOrderIds($orderIds, $this->getGoodsDetailField());
// $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);
// }
// // $orderDao->updateNotRecieveOrders(ApiConst::orderStateWaitConfirm, ApiConst::orderStateClose, 'add_time', ApiConst::orderStateWaitConfirmBeyond, $this->orderMessageField);
// try{
// $orderConfirmUtilDao->updateGoodsStorage($storeCartsList);
// }catch(\Exception $ex){
// throw new \Exception('商品库存更新失败:'.$ex->getMessage(),$ex->getCode());
// }
// exit;
foreach ($orders as $order) {
$orderDao->deleteOrderCache($order['buyerId'], $order['orderId'], $order['storeId']);
if ($order['paymentTime'] > ApiConst::zero && in_array($orders['paymentType'], ArrayConst::orderPayTypeOnlines)) {
$this->changeOrderStateCancelUnconditional($order);
//更新订单信息
$updateData = array('order_state' => ApiConst::orderStateClose,'refund_amount'=>$order['orderAmount']);
$update = $orderDao->update(array('order_id' => $order['orderId']),$updateData);
if($update){
if ($order['paymentTime'] > ApiConst::zero && in_array($order['paymentType'], ArrayConst::orderPayTypeOnlines)) {
$this->changeOrderStateCancelUnconditional($order);
}
}
$orderDao->deleteOrderCache($order['buyerId'],$order['orderId'],$order['storeId']);
}
$push = Push::getInstance();
$push->pushOrderCloseMessage($orders);
$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);
}
// $orderDao->updateNotRecieveOrders(ApiConst::orderStateWaitConfirm, ApiConst::orderStateClose, 'add_time', ApiConst::orderStateWaitConfirmBeyond, $this->orderMessageField);
try{
$orderConfirmUtilDao->updateGoodsStorage($storeCartsList);
}catch(\Exception $ex){
throw new \Exception('商品库存更新失败:'.$ex->getMessage(),$ex->getCode());
}
}
file_put_contents($this->baseDir . \Our\PathConst::orderCloseWaitRecieveOrder, $endTime);
}
//订单任务脚本自动确认收货
......
......@@ -188,20 +188,30 @@ $tcp_server->on('connect', function($serv, $fd) use($conf){
*/
$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'])){
//$data = json_decode($data, true);
// if(empty($data['data']) && !isset($data['data'])){
// $serv->send($fd, responseJson(1,"fail", ['method' => 'receive', 'error_code' => 1, 'status' => 0]));
// $serv->close($fd);
// return;
// }
if(empty($data) && !isset($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;
// $s = json_encode($data['data']);
echo $data;
// 推送 存入redis、最后入库(MySQL)
$redis=new Redis();
$redis->connect($conf['host'], $conf['port']);
if(!empty($conf['password'])){
$redis->auth($conf['password']);
}
$key=trim($data,"\r\n");
$data=$redis->get($key);
$redis->delete($key);
$data=json_decode($data,true);
if(true) {
$serv->send($fd, responseJson(1,"success", ['method' => 'receive', 'error_code' => 0, 'status' => 1]));
$serv->close($fd);
......@@ -234,6 +244,7 @@ $tcp_server->on('receive', function($serv, $fd, $from_id, $data) use($conf) {
} else {
$serv->send($fd, responseJson(1,'fromMsg',"fail", ['method' => 'receive', 'error_code' => 110,'status' => 0]));
}
unset($redis);
});
......
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