Commit 4f8ce777 authored by zhz's avatar zhz

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

parents 0ccb8b51 d02fddf0
...@@ -2,7 +2,9 @@ ...@@ -2,7 +2,9 @@
namespace Alipay\aop; namespace Alipay\aop;
require_once 'AopEncrypt.php'; require_once 'AopEncrypt.php';
require_once 'SignData.php';
$libaryUrl=\Bootstrap::getUrlIniConfig('libary');
require_once ($libaryUrl.'/Alipay/lotusphp_runtime/Logger/LtLogger.php');
class AopClient { class AopClient {
//应用ID //应用ID
public $appId; public $appId;
...@@ -230,14 +232,12 @@ class AopClient { ...@@ -230,14 +232,12 @@ class AopClient {
$reponse = curl_exec($ch); $reponse = curl_exec($ch);
if (curl_errno($ch)) { if (curl_errno($ch)) {
throw new \Exception(curl_error($ch), 0);
throw new Exception(curl_error($ch), 0);
} else { } else {
$httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (200 !== $httpStatusCode) { if (200 !== $httpStatusCode) {
throw new Exception($reponse, $httpStatusCode); throw new \Exception($reponse, $httpStatusCode);
} }
} }
...@@ -253,7 +253,7 @@ class AopClient { ...@@ -253,7 +253,7 @@ class AopClient {
protected function logCommunicationError($apiName, $requestUrl, $errorCode, $responseTxt) { protected function logCommunicationError($apiName, $requestUrl, $errorCode, $responseTxt) {
$localIp = isset ($_SERVER["SERVER_ADDR"]) ? $_SERVER["SERVER_ADDR"] : "CLI"; $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["log_file"] = rtrim(AOP_SDK_WORK_DIR, '\\/') . '/' . "logs/aop_comm_err_" . $this->appId . "_" . date("Y-m-d") . ".log";
$logger->conf["separator"] = "^_^"; $logger->conf["separator"] = "^_^";
$logData = array( $logData = array(
...@@ -464,7 +464,7 @@ class AopClient { ...@@ -464,7 +464,7 @@ class AopClient {
$sysParams["notify_url"] = $request->getNotifyUrl(); $sysParams["notify_url"] = $request->getNotifyUrl();
$sysParams["charset"] = $this->postCharset; $sysParams["charset"] = $this->postCharset;
$sysParams["app_auth_token"] = $appInfoAuthtoken; $sysParams["app_auth_token"] = $appInfoAuthtoken;
//获取业务参数 //获取业务参数
$apiParams = $request->getApiParas(); $apiParams = $request->getApiParas();
...@@ -475,17 +475,17 @@ class AopClient { ...@@ -475,17 +475,17 @@ class AopClient {
if ($this->checkEmpty($apiParams['biz_content'])) { 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)) { 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) { if ("AES" != $this->encryptType) {
throw new Exception("加密类型只支持AES"); throw new \Exception("加密类型只支持AES");
} }
// 执行加密 // 执行加密
...@@ -510,7 +510,7 @@ class AopClient { ...@@ -510,7 +510,7 @@ class AopClient {
//发起HTTP请求 //发起HTTP请求
try { try {
$resp = $this->curl($requestUrl, $apiParams); $resp = $this->curl($requestUrl, $apiParams);
} catch (Exception $e) { } catch (\Exception $e) {
$this->logCommunicationError($sysParams["method"], $requestUrl, "HTTP_ERROR_" . $e->getCode(), $e->getMessage()); $this->logCommunicationError($sysParams["method"], $requestUrl, "HTTP_ERROR_" . $e->getCode(), $e->getMessage());
return false; return false;
...@@ -1014,7 +1014,7 @@ class AopClient { ...@@ -1014,7 +1014,7 @@ class AopClient {
* @param $signData * @param $signData
* @param $resp * @param $resp
* @param $respObject * @param $respObject
* @throws Exception * @throws \Exception
*/ */
public function checkResponseSign($request, $signData, $resp, $respObject) { public function checkResponseSign($request, $signData, $resp, $respObject) {
...@@ -1023,7 +1023,7 @@ class AopClient { ...@@ -1023,7 +1023,7 @@ class AopClient {
if ($signData == null || $this->checkEmpty($signData->sign) || $this->checkEmpty($signData->signSourceData)) { 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 { ...@@ -1045,12 +1045,12 @@ class AopClient {
$checkResult = $this->verify($signData->signSourceData, $signData->sign, $this->alipayPublicKey, $this->signType); $checkResult = $this->verify($signData->signSourceData, $signData->sign, $this->alipayPublicKey, $this->signType);
if (!$checkResult) { 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 { } 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 <?php
namespace Alipay\aop;
/** /**
* Created by PhpStorm. * Created by PhpStorm.
* User: jiehua * User: jiehua
......
...@@ -580,7 +580,7 @@ class OrderConfirmUtil { ...@@ -580,7 +580,7 @@ class OrderConfirmUtil {
* *
* @param $storeCarts * @param $storeCarts
*/ */
public function updateGoodsStorage($storeCartsList){ public function updateGoodsStorage($storeCartsList,$op = \Our\ApiConst::minus,$updateSaleNumFlag= true ){
$goodsCommonIds = array(); $goodsCommonIds = array();
$goodsIds = array(); $goodsIds = array();
$blIds = array(); $blIds = array();
...@@ -626,12 +626,23 @@ class OrderConfirmUtil { ...@@ -626,12 +626,23 @@ class OrderConfirmUtil {
} }
} }
} }
$this->updateGoodsStorageToDBAndCache($goodsCommonIds,$goodsIds,$blIds,$goodsNewList); $this->updateGoodsStorageToDBAndCache($goodsCommonIds,$goodsIds,$blIds,$goodsNewList,$op,$updateSaleNumFlag);
//$goodsStorages = $goodsDao->getOnlineStorageGoodsByGoodsCommonIds(array_keys($goodsCommonIds)); //$goodsStorages = $goodsDao->getOnlineStorageGoodsByGoodsCommonIds(array_keys($goodsCommonIds));
return true; return true;
} }
public function updateGoodsStorageToDBAndCache($goodsCommons,$goodsList,$blGoodsList,$goodsNewList){ /**
* @param $goodsCommons
* @param $goodsList
* @param $blGoodsList
* @param $goodsNewList
* @param int $op
* @param bool $updateSaleNumFlag
* @return bool
* @throws \Error\OurExceptionModel
* @throws \Exception
*/
public function updateGoodsStorageToDBAndCache($goodsCommons,$goodsList,$blGoodsList,$goodsNewList,$op=\Our\ApiConst::minus,$updateSaleNumFlag=true){
if($blGoodsList){ if($blGoodsList){
$dbName = \Our\DbNameConst::masterDBConnectName; $dbName = \Our\DbNameConst::masterDBConnectName;
$pBundlingDao = \DAO\PBundlingModel::getInstance($dbName); $pBundlingDao = \DAO\PBundlingModel::getInstance($dbName);
...@@ -644,8 +655,8 @@ class OrderConfirmUtil { ...@@ -644,8 +655,8 @@ class OrderConfirmUtil {
$dbName = \Our\DbNameConst::masterDBConnectName; $dbName = \Our\DbNameConst::masterDBConnectName;
$goodsDao = \DAO\GoodsModel::getInstance($dbName); $goodsDao = \DAO\GoodsModel::getInstance($dbName);
$goodsCommonDao = \DAO\GoodsCommonModel::getInstance($dbName); $goodsCommonDao = \DAO\GoodsCommonModel::getInstance($dbName);
$resultGoodsCommon = $goodsCommonDao->updateGoodsStorage($goodsCommons); $resultGoodsCommon = $goodsCommonDao->updateGoodsStorage($goodsCommons,$op,$updateSaleNumFlag);
$resultGoods = $goodsDao->updateGoodsStorage($goodsNewList); $resultGoods = $goodsDao->updateGoodsStorage($goodsNewList,$op);
if(!($resultGoodsCommon&&$resultGoods)){ if(!($resultGoodsCommon&&$resultGoods)){
\Error\ErrorModel::throwException(\Error\CodeConfigModel::goodsStorageToDBFailedForOrder); \Error\ErrorModel::throwException(\Error\CodeConfigModel::goodsStorageToDBFailedForOrder);
} }
...@@ -659,7 +670,7 @@ class OrderConfirmUtil { ...@@ -659,7 +670,7 @@ class OrderConfirmUtil {
} }
} }
if($goodsCommons&&$goodsList){ if($goodsCommons&&$goodsList){
$resultGoodsCache = $goodsDao->opOnlineStorageGoodsByGoodsCommonIds($goodsList); $resultGoodsCache = $goodsDao->opOnlineStorageGoodsByGoodsCommonIds($goodsList,$op,$updateSaleNumFlag);
if(!$resultGoodsCache){ if(!$resultGoodsCache){
\Error\ErrorModel::throwException(\Error\CodeConfigModel::goodsStorageToCacheFailedForOrder); \Error\ErrorModel::throwException(\Error\CodeConfigModel::goodsStorageToCacheFailedForOrder);
} }
......
...@@ -145,4 +145,10 @@ class ArrayConst ...@@ -145,4 +145,10 @@ class ArrayConst
const messageOrderButtonsType=array( const messageOrderButtonsType=array(
0,1,2 0,1,2
); );
const ops = array(
\Our\ApiConst::minus => '-',
\Our\ApiConst::plus => '+',
\Our\ApiConst::set => '='
);
} }
\ No newline at end of file
...@@ -125,6 +125,8 @@ class NameConst { ...@@ -125,6 +125,8 @@ class NameConst {
const onlineStorageGoodsPrefix = 'onlineStorageGoods_'; const onlineStorageGoodsPrefix = 'onlineStorageGoods_';
const onlineGoodsCommonSaleNumPrefix = 'onlineGoodsCommonSaleNum';
const onlineStorageBlGoodsPrefix = 'onlineStorageBlGoods';//组合销售库存前缀 const onlineStorageBlGoodsPrefix = 'onlineStorageBlGoods';//组合销售库存前缀
const storeCoverPrefix = 'storeCover_'; const storeCoverPrefix = 'storeCover_';
......
...@@ -207,12 +207,21 @@ class Push ...@@ -207,12 +207,21 @@ class Push
public function sendTcpMessage() public function sendTcpMessage()
{ {
$push = \Yaf\Registry::get('config')->get('push'); $push = \Yaf\Registry::get('config')->get('push');
$conf = \Yaf\Registry::get('config')->get('redis.database.params');
if ($push['open']) { if ($push['open']) {
if(!empty($this->data)){ 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['data'] = $this->data;
$message['uid'] = !empty($this->uid)?$this->uid:ApiConst::zero; $message['uid'] = !empty($this->uid)?$this->uid:ApiConst::zero;
// $message['data']=array_slice($message['data'],2,14); // $message['data']=array_slice($message['data'],2,14);
$message = json_encode($message); $message = json_encode($message);
$key=md5($message);
$redis->set($key,$message);
$message=$key;
$message = $message . "\r\n"; $message = $message . "\r\n";
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if (!@socket_connect($socket, $push['host'], $push['port'])) { if (!@socket_connect($socket, $push['host'], $push['port'])) {
...@@ -239,6 +248,7 @@ class Push ...@@ -239,6 +248,7 @@ class Push
return true; return true;
} }
unset($this->data); unset($this->data);
unset($redis);
} }
} else { } else {
$this->errorCode = CodeConfigModel::pushIsNotOpen; $this->errorCode = CodeConfigModel::pushIsNotOpen;
......
...@@ -62,7 +62,7 @@ class Alipay { ...@@ -62,7 +62,7 @@ class Alipay {
} }
public function refund($order){ public function refund($order){
$refundAmount = round($order['refundAmount']/\Our\ApiConst::hundred,\Our\ApiConst::two); $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; $refundAmount = 0.01;
} }
$aop = new \Alipay\aop\AopClient(); $aop = new \Alipay\aop\AopClient();
...@@ -77,7 +77,7 @@ class Alipay { ...@@ -77,7 +77,7 @@ class Alipay {
$outRequestNo=$this->getRandomString(ApiConst::nine); $outRequestNo=$this->getRandomString(ApiConst::nine);
// require_once BASE_ROOT_PATH.'/core/payment/alipay/aop/request/AlipayTradeRefundRequest.php'; // require_once BASE_ROOT_PATH.'/core/payment/alipay/aop/request/AlipayTradeRefundRequest.php';
// //require_once 'aop/request/AlipayTradeRefundRequest.php'; // //require_once 'aop/request/AlipayTradeRefundRequest.php';
$request = new \Alipay\aop\request\AlipayTradeAppPayRequest(); $request = new \Alipay\aop\request\AlipayTradeRefundRequest();
$request->setBizContent("{" . $request->setBizContent("{" .
"\"out_trade_no\":\"{$order['outTradeNo']}\"," . "\"out_trade_no\":\"{$order['outTradeNo']}\"," .
"\"refund_amount\":{$refundAmount}," . "\"refund_amount\":{$refundAmount}," .
......
...@@ -68,15 +68,15 @@ class WxPay extends \Payment\TencentPay ...@@ -68,15 +68,15 @@ class WxPay extends \Payment\TencentPay
{ {
$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') { if(APP_ENV == 'develop'||APP_ENV == 'test'||APP_ENV == 'pre' || APP_ENV=='ccwdevelop'){
$this->parameters['total_fee'] = 1; $this->parameters['total_fee'] = 1;
$this->parameters['refund_fee'] = 1; $this->parameters['refund_fee'] = 1;
} else { } else {
$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['out_refund_no'] = $param['refund_order_no']; $this->parameters['out_refund_no'] = $param['refundOrderNo'];
$this->parameters['out_trade_no'] = $param['out_trade_no']; $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::wxPayAppId;
......
...@@ -25,6 +25,8 @@ class GoodsCommonServiceModel extends \Business\AbstractModel ...@@ -25,6 +25,8 @@ class GoodsCommonServiceModel extends \Business\AbstractModel
} }
$commonGoodsInstance = \DAO\GoodsCommonModel::getInstance(); $commonGoodsInstance = \DAO\GoodsCommonModel::getInstance();
$commonInfo = \Our\RedisHelper::cachedFunction(\Redis\Db4\GoodsCommonRedisModel::getInstance(),array(&$commonGoodsInstance, 'getOneById'),array($goodsCommonId),0,array($goodsCommonId)); $commonInfo = \Our\RedisHelper::cachedFunction(\Redis\Db4\GoodsCommonRedisModel::getInstance(),array(&$commonGoodsInstance, 'getOneById'),array($goodsCommonId),0,array($goodsCommonId));
$saleNum = $commonGoodsInstance->getGoodsSaleNumFromCache($goodsCommonId);
$commonInfo['sale_num'] = $saleNum;
if(!$commonInfo){ if(!$commonInfo){
\Error\ErrorModel::throwException(\Error\CodeConfigModel::goodsNotExist); \Error\ErrorModel::throwException(\Error\CodeConfigModel::goodsNotExist);
} }
......
...@@ -140,16 +140,21 @@ class GoodsModel extends \DAO\AbstractModel { ...@@ -140,16 +140,21 @@ class GoodsModel extends \DAO\AbstractModel {
} }
/** /**
* 更新商品缓存 * 更新商品库存缓存以及更新销量
* @param $goodsList 商品列表 * @param $goodsList 商品列表
* @param int $op 删减标识符(1:增加,0:减少,2:直接设置) * @param int $op 删减标识符(1:增加,0:减少,2:直接设置)
* @return bool * @return bool
*/ */
public function opOnlineStorageGoodsByGoodsCommonIds($goodsList,$op = \Our\ApiConst::minus){ public function opOnlineStorageGoodsByGoodsCommonIds($goodsList,$op = \Our\ApiConst::minus,$updateSaleNumFalg = true){
$goodsRedis = \Redis\Db4\GoodsRedisModel::getInstance(); $goodsRedis = \Redis\Db4\GoodsRedisModel::getInstance();
if($updateSaleNumFalg){
$goodsCommonRedis = \Redis\Db4\GoodsCommonRedisModel::getInstance();
$onlineGoodsCommonSaleNumKey = \Our\NameConst::onlineGoodsCommonSaleNumPrefix;
}
$goodsCommonList = $this->getOnlineStorageGoodsByGoodsCommonIds(array_keys($goodsList)); $goodsCommonList = $this->getOnlineStorageGoodsByGoodsCommonIds(array_keys($goodsList));
foreach($goodsCommonList as $goodsCommonId=>$goodsCommonsTemp){ foreach($goodsCommonList as $goodsCommonId=>$goodsCommonsTemp){
$newGoodsList = array(); $newGoodsList = array();
$totalGoodsNum = \Our\ApiConst::zero;
foreach($goodsCommonsTemp as $goodsId=>$temp){ foreach($goodsCommonsTemp as $goodsId=>$temp){
if($goodsList[$goodsCommonId][$goodsId]&&$goodsList[$goodsCommonId][$goodsId]['goodsNum']>\Our\ApiConst::zero){ if($goodsList[$goodsCommonId][$goodsId]&&$goodsList[$goodsCommonId][$goodsId]['goodsNum']>\Our\ApiConst::zero){
if($op == \Our\ApiConst::minus&&$temp['goodsStorage']>=$goodsList[$goodsCommonId][$goodsId]['goodsNum']){ if($op == \Our\ApiConst::minus&&$temp['goodsStorage']>=$goodsList[$goodsCommonId][$goodsId]['goodsNum']){
...@@ -161,6 +166,7 @@ class GoodsModel extends \DAO\AbstractModel { ...@@ -161,6 +166,7 @@ class GoodsModel extends \DAO\AbstractModel {
}else{ }else{
return false; return false;
} }
$totalGoodsNum += $goodsList[$goodsCommonId][$goodsId]['goodsNum'];
} }
$newGoodsList[$goodsId]= serialize($temp); $newGoodsList[$goodsId]= serialize($temp);
} }
...@@ -170,6 +176,19 @@ class GoodsModel extends \DAO\AbstractModel { ...@@ -170,6 +176,19 @@ class GoodsModel extends \DAO\AbstractModel {
if(!$result){ if(!$result){
return false; return false;
} }
}
/**
* 需要更新销量时 ,如果已经存在销量对应缓存,对销量对应缓存进行加减操作
*/
if($updateSaleNumFalg&&$op!=\Our\ApiConst::set&&$totalGoodsNum>\Our\ApiConst::zero){
$updateGoodsNum = $totalGoodsNum;
if($op==\Our\ApiConst::plus){
$updateGoodsNum = -$updateGoodsNum;
}
if($goodsCommonRedis->tableHExists($onlineGoodsCommonSaleNumKey,$goodsCommonId)){
$goodsCommonRedis->tableHIncrBy($onlineGoodsCommonSaleNumKey,$goodsCommonId,$updateGoodsNum);
}
} }
} }
return true; return true;
...@@ -286,7 +305,7 @@ class GoodsModel extends \DAO\AbstractModel { ...@@ -286,7 +305,7 @@ class GoodsModel extends \DAO\AbstractModel {
} }
public function updateGoodsStorage($dataList){ public function updateGoodsStorage($dataList,$op=\Our\ApiConst::zero){
$datas = array_values($dataList); $datas = array_values($dataList);
$this->setDb(\Our\DbNameConst::masterDBConnectName); $this->setDb(\Our\DbNameConst::masterDBConnectName);
$error = 0; $error = 0;
...@@ -294,7 +313,7 @@ class GoodsModel extends \DAO\AbstractModel { ...@@ -294,7 +313,7 @@ class GoodsModel extends \DAO\AbstractModel {
$updateAllSql = $baseSql; $updateAllSql = $baseSql;
$dataIds = array(); $dataIds = array();
for ($i = 0; $i < count($datas); $i++) { for ($i = 0; $i < count($datas); $i++) {
$updateSql = \Our\Common::format(" WHEN {0} THEN goods_storage-{1} ", $datas[$i]['goodsId'], $datas[$i]['goodsNum']); $updateSql = \Our\Common::format(" WHEN {0} THEN goods_storage{2}{1} ", $datas[$i]['goodsId'], $datas[$i]['goodsNum'],\Our\ArrayConst::ops[$op]);
$dataIds[] = $datas[$i]['goodsId']; $dataIds[] = $datas[$i]['goodsId'];
$updateAllSql .= $updateSql; $updateAllSql .= $updateSql;
if ($i % 1000 == 0 && $i != 0) { if ($i % 1000 == 0 && $i != 0) {
......
...@@ -25,9 +25,32 @@ class GoodsCommonModel extends \DAO\AbstractModel { ...@@ -25,9 +25,32 @@ class GoodsCommonModel extends \DAO\AbstractModel {
public function init(){ public function init(){
} }
public function getOneById($goodsCommonId){ public function getOneById($goodsCommonId,$field = \Our\NameConst::allField){
$this->setDb(); $this->setDb($this->dbName);
return $this->db->select('*')->from($this->_tableName)->where(array('goods_commonid'=>$goodsCommonId))->fetchOne(); return $this->db->select($field)->from($this->_tableName)->where(array('goods_commonid'=>$goodsCommonId))->fetchOne();
}
public function getGoodsSaleNumFromCache($goodsCommonId){
$goodsCommonRedis = \Redis\Db4\GoodsCommonRedisModel::getInstance();
$onlineGoodsCommonSaleNumKey = \Our\NameConst::onlineGoodsCommonSaleNumPrefix;
if($goodsCommonRedis->tableHExists($onlineGoodsCommonSaleNumKey,$goodsCommonId)){
$saleNum = $goodsCommonRedis->tableHGet($onlineGoodsCommonSaleNumKey,$goodsCommonId);
}else{
$goodsCommon = $this->getOneById($goodsCommonId,'sale_num');
$saleNum = $goodsCommon['sale_num'];
$goodsCommonRedis->tableHIncrBy($onlineGoodsCommonSaleNumKey,$goodsCommonId,$saleNum);
}
return $saleNum;
}
/**
* 删除销量缓存
* @param $goodsCommonId
*/
public function deleteGoodsSaleNumFromCache($goodsCommonId){
$goodsCommonRedis = \Redis\Db4\GoodsCommonRedisModel::getInstance();
$onlineGoodsCommonSaleNumKey = \Our\NameConst::onlineGoodsCommonSaleNumPrefix;
$goodsCommonRedis->tableHDel($onlineGoodsCommonSaleNumKey,$goodsCommonId);
} }
/** /**
...@@ -39,7 +62,7 @@ class GoodsCommonModel extends \DAO\AbstractModel { ...@@ -39,7 +62,7 @@ class GoodsCommonModel extends \DAO\AbstractModel {
* @return mixed * @return mixed
*/ */
public function getGoodsList($where,$field,$limit=array(),$order=array(),$attrStr=''){ public function getGoodsList($where,$field,$limit=array(),$order=array(),$attrStr=''){
$this->setDb(); $this->setDb($this->dbName);
$str = '$data = $this->db->select($field)->from($this->_tableName)'; $str = '$data = $this->db->select($field)->from($this->_tableName)';
if($attrStr){ if($attrStr){
$str .="->join('han_goods_attribute_value','han_goods_attribute_value.goods_commonid = han_goods_common.goods_commonid')"; $str .="->join('han_goods_attribute_value','han_goods_attribute_value.goods_commonid = han_goods_common.goods_commonid')";
...@@ -71,7 +94,7 @@ class GoodsCommonModel extends \DAO\AbstractModel { ...@@ -71,7 +94,7 @@ class GoodsCommonModel extends \DAO\AbstractModel {
* @return mixed * @return mixed
*/ */
public function getListWithSale($where,$field,$actIds,$limit=array(),$order=array(),$attrStr='',$online = true){ public function getListWithSale($where,$field,$actIds,$limit=array(),$order=array(),$attrStr='',$online = true){
$this->setDb(); $this->setDb($this->dbName);
$str = "select ".$field." FROM ".$this->_tableName." LEFT JOIN (SELECT MIN(discount_price) discount_price,goods_commonid,goods_id FROM han_sale_goods where sale_act_id in(".implode(',',$actIds).") GROUP BY goods_commonid) a on (han_goods_common.goods_commonid = a.goods_commonid)"; $str = "select ".$field." FROM ".$this->_tableName." LEFT JOIN (SELECT MIN(discount_price) discount_price,goods_commonid,goods_id FROM han_sale_goods where sale_act_id in(".implode(',',$actIds).") GROUP BY goods_commonid) a on (han_goods_common.goods_commonid = a.goods_commonid)";
if($attrStr){ if($attrStr){
$str .= "INNER JOIN han_goods_attribute_value ON han_goods_attribute_value.goods_commonid = han_goods_common.goods_commonid "; $str .= "INNER JOIN han_goods_attribute_value ON han_goods_attribute_value.goods_commonid = han_goods_common.goods_commonid ";
...@@ -147,7 +170,7 @@ class GoodsCommonModel extends \DAO\AbstractModel { ...@@ -147,7 +170,7 @@ class GoodsCommonModel extends \DAO\AbstractModel {
} }
public function getCount($where,$attrStr=''){ public function getCount($where,$attrStr=''){
$this->setDb(); $this->setDb($this->dbName);
if($attrStr){ if($attrStr){
return $this->db->from($this->_tableName)->join('han_goods_attribute_value','han_goods_attribute_value.goods_commonid = han_goods_common.goods_commonid')->where($where)->where($attrStr)->fetchNum(); return $this->db->from($this->_tableName)->join('han_goods_attribute_value','han_goods_attribute_value.goods_commonid = han_goods_common.goods_commonid')->where($where)->where($attrStr)->fetchNum();
} }
...@@ -181,19 +204,25 @@ class GoodsCommonModel extends \DAO\AbstractModel { ...@@ -181,19 +204,25 @@ class GoodsCommonModel extends \DAO\AbstractModel {
} }
public function updateGoodsStorage($dataList){ public function updateGoodsStorage($dataList , $op = \Our\ApiConst::minus,$updateSaleNumFlag = false){
$datas = array_values($dataList); $datas = array_values($dataList);
$this->setDb(\Our\DbNameConst::masterDBConnectName); $this->setDb(\Our\DbNameConst::masterDBConnectName);
$error = 0; $error = 0;
$baseSql = "UPDATE {$this->_tableName} set goods_storage = case goods_commonid "; $baseSql = "UPDATE {$this->_tableName} set goods_storage = case goods_commonid ";
$updateAllSql = $baseSql; $updateAllSql = $baseSql;
$dataIds = array(); $dataIds = array();
if($updateSaleNumFlag&&$op!=\Our\ApiConst::set){
$updateSaleNumOp = $op==\Our\ApiConst::minus?'+':'-';
}
for ($i = 0; $i < count($datas); $i++) { for ($i = 0; $i < count($datas); $i++) {
$updateSql = \Our\Common::format(" WHEN {0} THEN goods_storage-{1} ", $datas[$i]['goodsCommonId'], $datas[$i]['goodsNum']); $updateSql = \Our\Common::format(" WHEN {0} THEN goods_storage{1}{2} ", $datas[$i]['goodsCommonId'],\Our\ArrayConst::ops[$op], $datas[$i]['goodsNum']);
if($updateSaleNumFlag){
$updateSql = \Our\Common::format(" WHEN {0} THEN goods_storage{1}{2} END,sale_num = case goods_commonid when {0} THEN sale_num {3}{2} END", $datas[$i]['goodsCommonId'],\Our\ArrayConst::ops[$op], $datas[$i]['goodsNum'],$updateSaleNumOp);
}
$dataIds[] = $datas[$i]['goodsCommonId']; $dataIds[] = $datas[$i]['goodsCommonId'];
$updateAllSql .= $updateSql; $updateAllSql .= $updateSql;;
if ($i % 1000 == 0 && $i != 0) { if ($i % 1000 == 0 && $i != 0) {
$updateAllSql .= \Our\Common::format('END where goods_commonid in ({0})',implode(',',$dataIds)); $updateAllSql .= \Our\Common::format(' where goods_commonid in ({0})',implode(',',$dataIds));
$one = $this->db->update($this->_tableName)->query($updateAllSql); $one = $this->db->update($this->_tableName)->query($updateAllSql);
if (!$one) { if (!$one) {
$error++; $error++;
...@@ -203,7 +232,7 @@ class GoodsCommonModel extends \DAO\AbstractModel { ...@@ -203,7 +232,7 @@ class GoodsCommonModel extends \DAO\AbstractModel {
} }
} }
if ($updateAllSql != $baseSql) { if ($updateAllSql != $baseSql) {
$updateAllSql .= \Our\Common::format('END where goods_commonid in ({0})',implode(',',$dataIds)); $updateAllSql .= \Our\Common::format(' where goods_commonid in ({0})',implode(',',$dataIds));
$one = $this->db->update($this->_tableName)->query($updateAllSql); $one = $this->db->update($this->_tableName)->query($updateAllSql);
if (!$one) { if (!$one) {
...@@ -228,9 +257,9 @@ class GoodsCommonModel extends \DAO\AbstractModel { ...@@ -228,9 +257,9 @@ class GoodsCommonModel extends \DAO\AbstractModel {
* *
* @return \DAO\UserModel * @return \DAO\UserModel
*/ */
public static function getInstance() { public static function getInstance($dbName =\Our\DbNameConst::salveDBConnectName) {
if (!(self::$_instance instanceof self)) { if (!(self::$_instance instanceof self)) {
self::$_instance = new self(); self::$_instance = new self($dbName);
} }
return self::$_instance; return self::$_instance;
......
...@@ -99,4 +99,14 @@ class AbstractModel extends \Redis\AbstractModel { ...@@ -99,4 +99,14 @@ class AbstractModel extends \Redis\AbstractModel {
public function tableSRandMember($h,$count = null){ public function tableSRandMember($h,$count = null){
return $this->sRandMember($this->calcKey($h),$count); return $this->sRandMember($this->calcKey($h),$count);
} }
public function tableHIncrBy($h,$key,$keysvalue){
return $this->hIncrBy($this->calcKey($h),$key,$keysvalue);
}
public function tableHExists($h,$key){
return $this->hExists($this->calcKey($h),$key);
}
public function tableHDel($h,$key){
return $this->hDel($this->calcKey($h),$key);
}
} }
...@@ -188,20 +188,30 @@ $tcp_server->on('connect', function($serv, $fd) use($conf){ ...@@ -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) { $tcp_server->on('receive', function($serv, $fd, $from_id, $data) use($conf) {
// echo $data; // echo $data;
$data = json_decode($data, true); //$data = json_decode($data, true);
if(empty($data['data']) && !isset($data['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;
// }
if(empty($data) && !isset($data)){
$serv->send($fd, responseJson(1,"fail", ['method' => 'receive', 'error_code' => 1, 'status' => 0])); $serv->send($fd, responseJson(1,"fail", ['method' => 'receive', 'error_code' => 1, 'status' => 0]));
$serv->close($fd); $serv->close($fd);
return; return;
} }
$s = json_encode($data['data']); // $s = json_encode($data['data']);
echo $s; echo $data;
// 推送 存入redis、最后入库(MySQL) // 推送 存入redis、最后入库(MySQL)
$redis=new Redis(); $redis=new Redis();
$redis->connect($conf['host'], $conf['port']); $redis->connect($conf['host'], $conf['port']);
if(!empty($conf['password'])){ if(!empty($conf['password'])){
$redis->auth($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) { if(true) {
$serv->send($fd, responseJson(1,"success", ['method' => 'receive', 'error_code' => 0, 'status' => 1])); $serv->send($fd, responseJson(1,"success", ['method' => 'receive', 'error_code' => 0, 'status' => 1]));
$serv->close($fd); $serv->close($fd);
...@@ -234,6 +244,7 @@ $tcp_server->on('receive', function($serv, $fd, $from_id, $data) use($conf) { ...@@ -234,6 +244,7 @@ $tcp_server->on('receive', function($serv, $fd, $from_id, $data) use($conf) {
} else { } else {
$serv->send($fd, responseJson(1,'fromMsg',"fail", ['method' => 'receive', 'error_code' => 110,'status' => 0])); $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