Commit 45af5d90 authored by wwccw0591's avatar wwccw0591

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

parents 9b912976 a5675b44
......@@ -1020,6 +1020,45 @@ class GoodsCommonServiceModel extends \Business\AbstractModel
}
/**
* 店铺在售商品分类定时器
*/
public function storeOnlineGoodsClass(){
$storeOnlineGoodsClassDao = \DAO\GoodsClass\StoreOnlineGoodsClassModel::getInstance();
$addGoodsClassList = $storeOnlineGoodsClassDao->getChangedGoodsClass(0,2000,\Our\ApiConst::plus);
if($addGoodsClassList){
foreach($addGoodsClassList as $goodsClassStr){
$goodsClass = unserialize($goodsClassStr);
$this->checkExistOnlineGoodsClass($goodsClass);
}
}
$minusGoodsClassList = $storeOnlineGoodsClassDao->getChangedGoodsClass(0,2000,\Our\ApiConst::minus);
if($minusGoodsClassList){
foreach($minusGoodsClassList as $goodsClassStr){
$goodsClass = unserialize($goodsClassStr);
$this->checkRemoveOnlineGoodsClass($goodsClass);
}
}
}
/**
* 获取新增商品对应的商品分类是否在店铺在售商品分类表,如果在则忽略,不在将分类增加到在售商品分类表
* @param $goodsClass
* @return bool
*/
public function checkExistOnlineGoodsClass($goodsClass){
$storeOnlineGoodsClassDao = \DAO\GoodsClass\StoreOnlineGoodsClassModel::getInstance();
$oldTemp = $storeOnlineGoodsClassDao->find($goodsClass);
if(!$oldTemp){
$storeOnlineGoodsClassDao->insert($goodsClass);
}
return true;
}
public function checkRemoveOnlineGoodsClass($goodsClass){
}
private static $_instance = null;
......
......@@ -313,7 +313,7 @@ class GoodsModel extends \DAO\AbstractModel {
$updateAllSql = $baseSql;
$dataIds = array();
for ($i = 0; $i < count($datas); $i++) {
$updateSql = \Our\Common::format(" WHEN {0} THEN goods_storage{2}{1} ", $datas[$i]['goodsId'], $datas[$i]['goodsNum'],\Our\ArrayConst::ops[$op]);
$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'];
$updateAllSql .= $updateSql;
if ($i % 1000 == 0 && $i != 0) {
......
......@@ -25,6 +25,25 @@ class StoreOnlineGoodsClassModel extends \DAO\AbstractModel{
}
public function findByWhere($where){
$this->setDb(\Our\DbNameConst::salveDBConnectName);
$address = $this->db->from($this->_tableName)->where($where)->fetchOne();
return $address;
}
public function insert($data){
$this->setDb(\Our\DbNameConst::masterDBConnectName);
$data['gmt_create'] = TIMESTAMP;
$result = $this->db->insert($this->_tableName)->rows($data)->execute();
if($result){
$storeId = $data['store_id'];
\Our\RedisHelper::delCachedFunction(\Redis\Db6\StoreOnlineGoodsClassRedisModel::getInstance(),array(&$this, 'getList'),array(),array($storeId));
}
return $result ;
}
public function getList($where,$field = \Our\NameConst::allField){
$this->setDb($this->dbName);
$result = $this->db->select($field)->from($this->_tableName)->where($where)->fetchAll();
......@@ -82,6 +101,41 @@ class StoreOnlineGoodsClassModel extends \DAO\AbstractModel{
\Error\ErrorModel::throwException(\Error\CodeConfigModel::emtpyGcIdForOnlineChildrenClass);
}
}
public function addChangedGoodsClass($goodsClass,$type = \Our\ApiConst::plus){
$key='changedAddGoodsClass';
if($type==\Our\ApiConst::minus){
$key = 'changedMinusGoodsClass';
}
$storeOnlineClassRedisModel = \Redis\Db6\StoreOnlineGoodsClassRedisModel::getInstance();
$storeOnlineClassRedisModel->tableLPush($key,$goodsClass);
}
public function getChangedGoodsClass($type = \Our\ApiConst::plus){
$key='changedAddGoodsClass';
if($type==\Our\ApiConst::minus){
$key = 'changedMinusGoodsClass';
}
$storeOnlineClassRedisModel = \Redis\Db6\StoreOnlineGoodsClassRedisModel::getInstance();
return $storeOnlineClassRedisModel->tableLPop($key);
}
/**
* 获取更改商品
* @param $start 记录开始条数
* @param $end 记录结束条数
* @return \Redis\mix
*/
public function getChangedGoodsClasses($start,$end,$type = \Our\ApiConst::plus){
$key='changedAddGoodsClass';
if($type==\Our\ApiConst::minus){
$key = 'changedMinusGoodsClass';
}
$storeOnlineClassRedisModel = \Redis\Db6\StoreOnlineGoodsClassRedisModel::getInstance();
return $storeOnlineClassRedisModel->tableLRange($key,$start,$end);
}
/**
* 类实例
*/
......
......@@ -214,26 +214,43 @@ class GoodsCommonModel extends \DAO\AbstractModel {
if($updateSaleNumFlag&&$op!=\Our\ApiConst::set){
$updateSaleNumOp = $op==\Our\ApiConst::minus?'+':'-';
}
$goodsCommonSql = 'goods_storage = case goods_commonid ';
if($updateSaleNumFlag){
$saleNumSql = 'sale_num = case goods_commonid ';
}
for ($i = 0; $i < count($datas); $i++) {
$updateSql = \Our\Common::format(" goods_storage = case goods_commonid WHEN {0} THEN goods_storage{1}{2}, ", $datas[$i]['goodsCommonId'],\Our\ArrayConst::ops[$op], $datas[$i]['goodsNum']);
$goodsCommonSql .= \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(" goods_storage = case goods_commonid 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);
$saleNumSql .= \Our\Common::format(" when {0} THEN sale_num {1}{2},", $datas[$i]['goodsCommonId'],$updateSaleNumOp, $datas[$i]['goodsNum']);
}
$dataIds[] = $datas[$i]['goodsCommonId'];
$updateAllSql .= $updateSql;;
if ($i % 1000 == 0 && $i != 0) {
$updateAllSql = trim($updateAllSql,',');
$goodsCommonSql = trim($goodsCommonSql,',').' END';
$updateAllSql .= $goodsCommonSql;
if($updateSaleNumFlag){
$saleNumSql = ','.trim($saleNumSql,',').' END ';
$updateAllSql .= $saleNumSql;
}
$updateAllSql .= \Our\Common::format(' where goods_commonid in ({0})',implode(',',$dataIds));
$one = $this->db->update($this->_tableName)->query($updateAllSql);
if (!$one) {
$error++;
}
$updateAllSql = $baseSql;
$goodsCommonSql = 'goods_storage = case goods_commonid ';
if($updateSaleNumFlag){
$saleNumSql = 'sale_num = case goods_commonid ';
}
$dataIds = array();
}
}
if ($updateAllSql != $baseSql) {
$updateAllSql = trim($updateAllSql,',');
$goodsCommonSql = trim($goodsCommonSql,',').' END ';
$updateAllSql .= $goodsCommonSql;
if($updateSaleNumFlag){
$saleNumSql = ','.trim($saleNumSql,',').' END ';
$updateAllSql .= $saleNumSql;
}
$updateAllSql .= \Our\Common::format(' where goods_commonid in ({0})',implode(',',$dataIds));
$one = $this->db->update($this->_tableName)->query($updateAllSql);
......
......@@ -70,4 +70,20 @@ class AbstractModel extends \Redis\AbstractModel {
public function tableDecr($h) {
return $this->decr($this->calcKey($h));
}
public function tableLPush($id,$data){
$res=$this->lpush($this->calcKey($id), $data);
return $res;
}
public function tableLPop($id){
$res=$this->lpop($this->calcKey($id));
return $res;
}
public function tableLRange($key,$start,$end){
$res = $this->lrange($this->calcKey($key),$start,$end);
return $res;
}
}
......@@ -25,7 +25,6 @@ class StoreOnlineGoodsClassRedisModel extends \Redis\Db6\AbstractModel {
return $res;
}
/**
* 类实例
*
......
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