Commit a4fee170 authored by testshenbd's avatar testshenbd

applicationConfit

parents e6be3f91 849551af
......@@ -31,6 +31,9 @@ class CommonController extends \Our\Controller_AbstractIndex{
*/
public function setCurrentAddressAction(){
$data = $this->req[\Our\NameConst::data];
if($data['lng']&&$data['lat']&&empty($data['cityCode'])){
$data['cityCode'] = \Our\Common::getCityCodeByLatLng($data['lat'],$data['lng']);
}
$data['choosedFlag'] = \Our\ApiConst::one;
$addressService = \Business\User\AddressServiceModel::getInstance();
$memberId = $this->sess->get('member_id');
......
......@@ -28,6 +28,7 @@ class GoodsController extends \Our\Controller_AbstractIndex {
$this->goodsService->addBrowseRecord($this->req[\Our\NameConst::data],$this->memberId);
$this->success(array_merge($goodsInfo,array('store'=>$store,'recomndGoods'=>$recomndGoods,'evaluation'=>$evaluation,'groups'=>$groups,'share'=>$share),$coupons));
}
/**
* 获取商品列表
*/
......
......@@ -24,6 +24,9 @@ class HomeController extends \Our\Controller_AbstractIndex{
$returnData['currentAddress'] = $currentAddress;
$data = $this->req[\Our\NameConst::data];
if($data['lng']&&$data['lat']&&empty($data['cityCode'])){
$data['cityCode'] = \Our\Common::getCityCodeByLatLng($data['lat'],$data['lng']);
}
$requestAddress = \Business\User\AddressServiceModel::getInstance()->getRequestAddress($data,$currentAddress);
//获取首页推荐分类
$resultClasses = $this->getPlatformGoodsClassAction($requestAddress);
......@@ -193,6 +196,7 @@ class HomeController extends \Our\Controller_AbstractIndex{
$this->success($otherGoods);
}
/*
public function testMemberAction(){
$memberDao = \DAO\MemberModel::getInstance();
$memberList = $memberDao->getAll();
......@@ -201,4 +205,9 @@ class HomeController extends \Our\Controller_AbstractIndex{
}
}
public function writeToFileAction(){
\Business\User\AddressServiceModel::getInstance()->writeToFile();
}*/
}
\ No newline at end of file
......@@ -7,7 +7,7 @@ namespace Lock;
* Description:
*/
interface ILock{
const EXPIRE = 5;
const EXPIRE = 1;
public function getLock($key, $timeout = self::EXPIRE);
......
......@@ -12,22 +12,30 @@ class RedisLock implements \Lock\ILock{
public function __construct()
{
$this->lockRedis = \Redis\Db0\LockRedisModel::getInstance();
$this->lockRedis = \Redis\Db1\LockRedisModel::getInstance();
}
public function getMicrotime(){
list($msec, $sec) = explode(' ', microtime());
$msectime = (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000);
return $msectime;
}
public function getLock($key, $timeout=self::EXPIRE)
{
$waitime = 20000;
$totalWaitime = 0;
$time = $timeout*1000000;
while ($totalWaitime < $time && false == $this->lockRedis->update($key, 1, $timeout)){
usleep($waitime);
$totalWaitime += $waitime;
}
if ($totalWaitime >= $time){
\Our\Log::getInstance()->write($key.' can not get lock for waiting '.$timeout.'s.');
throw new Exception('can not get lock for waiting '.$timeout.'s.');
$currMicroTime = $this->getMicrotime();
$is_lock = $this->lockRedis->tableSetnx($key, $currMicroTime+10);
// 不能获取锁
if(!$is_lock){
//判断锁是否过期
$lock_time = $this->lockRedis->tableCacheGet($key);
// 锁已过期,删除锁,重新获取
if($currMicroTime>(float)$lock_time){
$this->releaseLock($key);
$is_lock = $this->lockRedis->tableSetnx($key, $currMicroTime+$timeout);
}
}
return $is_lock? true : false;
}
public function releaseLock($key)
......
......@@ -48,27 +48,15 @@ class OrderConfirmUtil {
private $couponCacheFlag = false;
/**
* 添加订单
* @param $data
* @param $memberId
* @param $currentAddress
* @param string $formId 小程序微信支付支付表单id
* @return array
* @throws \Exception
* User: King <358887571@qq.com>
* Date: 2018/12/25 0025
* Time: 下午 3:01
*/
public function addOrder($data, $memberId, $currentAddress, $formId = ''){
public function addOrder($data,$memberId,$currentAddress){
$storeCartData = $this->checkPostData($data,$memberId,$currentAddress);
//return $storeCartData;
if(CURRENTVERSION==\Our\NameConst::versionDefault){
$storeCartData = $this->checkDeliveryTypeAndPayway($storeCartData);
}else{
$storeCartData = $this->checkDeliveryTypeAndPaywayNew($storeCartData);
}
return $this->saveOrderInfo($storeCartData, $formId);
$result = $this->saveOrderInfo($storeCartData);
return $result;
}
......@@ -82,10 +70,10 @@ class OrderConfirmUtil {
* @throws \Exception
*/
public function checkPostData($data,$memberId,$currentAddress){
$dbName = \Our\DbNameConst::masterDBConnectName;
$dbName = \Our\DbNameConst::salveDBConnectName;
$this->memberId = $memberId;
$this->member = \DAO\MemberModel::getInstance()->getInfo($this->memberId);
$this ->address = $this->checkCurrentAddress($currentAddress,$this->memberId);
$this->address = $this->checkCurrentAddress($currentAddress,$this->memberId);
//if($this ->address['addressId'] == )
$this->postData = json_decode($data['param'],true);
if(!$this->postData){
......@@ -346,7 +334,7 @@ class OrderConfirmUtil {
*/
public function checkDeliveryTypeAndPaywayNew($storeCartData){
$cartService = \Business\Cart\CartServiceModel::getInstance();
$storeCartData = $cartService->getDeliveryTypeForCartNew($this->address,$storeCartData,\Our\DbNameConst::masterDBConnectName,true);
$storeCartData = $cartService->getDeliveryTypeForCartNew($this->address,$storeCartData,\Our\DbNameConst::salveDBConnectName,true);
$currentTime = time();
$todayTime = strtotime(date('Y-m-d',time()));
$tomorrowTime = $todayTime + \Our\ApiConst::oneDaySecond;
......@@ -761,9 +749,8 @@ class OrderConfirmUtil {
public function pushMessage(){
if($this->pushMessageOrders){
$orderService=\Business\Order\OrderServiceModel::getInstance();
foreach($this->pushMessageOrders as $tempOrder){
$orderService->pushRecieveOrder($tempOrder);
\Our\Common::redisPublish('\Business\Order\OrderServiceModel','pushRecieveOrder',array($tempOrder));
}
}
}
......@@ -782,6 +769,7 @@ class OrderConfirmUtil {
$memberCouponDao = \DAO\Coupon\MemberCouponModel::getInstance();
$couponService = \Business\Coupon\CouponServiceModel::getInstance();
\Our\RedisHelper::delCachedFunction(\Redis\Db13\MemberCouponRedisModel::getInstance(),array(&$memberCouponDao, 'getList'),array(),array($this->memberId));
\Redis\Db13\MemberCouponRedisModel::getInstance()->tableDel(\Our\NameConst::memberCounponListPrefix.$this->memberId);
foreach($this->storeIds as $tempStoreId){
\Our\RedisHelper::delCachedFunction(\Redis\Db13\CouponRedisModel::getInstance(), array(&$couponService, 'getStoreCouponsById'),array(),array($tempStoreId."_".$this->memberId));
}
......@@ -930,11 +918,13 @@ class OrderConfirmUtil {
\Our\RedisHelper::delCachedFunction(\Redis\Db4\PBundlingRedisModel::getInstance(),array(&$pbundlingInstance, 'getList'),array(),array($storeId));
}
}
$this->updateGoodsStorageToDBAndCache($goodsCommonIds,$goodsIds,$blIds,$goodsNewList,$op,$updateSaleNumFlag);
//$this->updateGoodsStorageToDBAndCache($goodsCommonIds,$goodsIds,$blIds,$goodsNewList,$op,$updateSaleNumFlag);
$this->updateGoodsStorageToCache($goodsCommonIds,$goodsIds,$blIds,$goodsNewList,$op,$updateSaleNumFlag);
return true;
}
/**
* 更新库存信息到数据库
* @param $goodsCommons
* @param $goodsList
* @param $blGoodsList
......@@ -945,7 +935,7 @@ class OrderConfirmUtil {
* @throws \Error\OurExceptionModel
* @throws \Exception
*/
public function updateGoodsStorageToDBAndCache($goodsCommons,$goodsList,$blGoodsList,$goodsNewList,$op=\Our\ApiConst::minus,$updateSaleNumFlag=true){
public function updateGoodsStorageToDB($goodsCommons,$goodsList,$blGoodsList,$goodsNewList,$op=\Our\ApiConst::minus,$updateSaleNumFlag=true){
if($blGoodsList){
$dbName = \Our\DbNameConst::masterDBConnectName;
$pBundlingDao = \DAO\PBundlingModel::getInstance($dbName);
......@@ -966,7 +956,77 @@ class OrderConfirmUtil {
\Error\ErrorModel::throwException(\Error\CodeConfigModel::goodsStorageToDBFailedForOrder);
}
}
return true;
}
/**
* 更新库存信息到缓存
* @param $goodsCommons
* @param $goodsList
* @param $blGoodsList
* @param $goodsNewList
* @param int $op
* @param bool $updateSaleNumFlag
* @return bool
* @throws \Error\OurExceptionModel
* @throws \Exception
*/
public function updateGoodsStorageToCache($goodsCommons,$goodsList,$blGoodsList,$goodsNewList,$op=\Our\ApiConst::minus,$updateSaleNumFlag=true){
$pBundlingDao = \DAO\PBundlingModel::getInstance();
$goodsDao = \DAO\GoodsModel::getInstance();
if($blGoodsList){
foreach($blGoodsList as $key=>$blGoods){
$pBundlingCacheResult = $pBundlingDao->updatePBundlingStorageCacheByBlId($key,$blGoods['blStorage'],$op);//组合销售库存删减
if($pBundlingCacheResult===false){
\Error\ErrorModel::throwException(\Error\CodeConfigModel::blGoodsStorageToCacheFailedForOrder);
}
$pBundlingDao->addChangedPBundlingStorage(serialize(array('bl_id'=>$key,'bl_storage'=>$blGoods['blStorage'],'op'=>$op)));
}
}
if($goodsCommons&&$goodsList){
$resultGoodsCache = $goodsDao->opOnlineStorageGoodsByGoodsCommonIds($goodsList,$op,$updateSaleNumFlag);
if(!$resultGoodsCache){
\Error\ErrorModel::throwException(\Error\CodeConfigModel::goodsStorageToCacheFailedForOrder);
}
}
\Our\Common::redisPublish('\Business\Goods\GoodsCommonServiceModel','updateAllStorageForPublish',array());
return true;
}
/**
* @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){
$dbName = \Our\DbNameConst::masterDBConnectName;
$pBundlingDao = \DAO\PBundlingModel::getInstance($dbName);
$pBundlingResult = $pBundlingDao->updateBlStorage($blGoodsList);
if(!$pBundlingResult){
\Error\ErrorModel::throwException(\Error\CodeConfigModel::blGoodsStorageToDBFailedForOrder);
}
}
if($goodsCommons&&$goodsList){
$dbName = \Our\DbNameConst::masterDBConnectName;
$goodsDao = \DAO\GoodsModel::getInstance($dbName);
$goodsCommonDao = \DAO\GoodsCommonModel::getInstance($dbName);
$resultGoodsCommon = $goodsCommonDao->updateGoodsStorage($goodsCommons,$op,$updateSaleNumFlag);
$resultGoods = $goodsDao->updateGoodsStorage($goodsNewList,$op);
if(!($resultGoodsCommon&&$resultGoods)){
\Error\ErrorModel::throwException(\Error\CodeConfigModel::goodsStorageToDBFailedForOrder);
}
}
if($blGoodsList){
foreach($blGoodsList as $key=>$blGoods){
$pBundlingCacheResult = $pBundlingDao->opBlGoodsStorage($key,$blGoods['blStorage'],$op);//组合销售库存删减
......@@ -1027,8 +1087,7 @@ class OrderConfirmUtil {
//第一步:获取购物车可展示优惠券信息
$memberCouponDao = \DAO\Coupon\MemberCouponModel::getInstance(\Our\DbNameConst::masterDBConnectName);
$whereSql = ' coupon_state ='.\Our\ApiConst::couponUnused.' and member_id ='.$memberId.' and out_time > '.time();
$memberCouponArray = $memberCouponDao->getList($whereSql,'coupon_id');
$memberCouponArray = $memberCouponDao->getMemberCouponByMemberIdWithOuttime($memberId);
if(!$memberCouponArray){
$storeCartData['couponList'] = array();
return $storeCartData;
......
......@@ -692,7 +692,7 @@ public static function convertArrKey($arr, $key_name)
*/
public static function getIpCity($ip)
{
$url = "http://ip.taobao.com/service/getIpInfo.php?ip=" . $ip;
$url = (self::is_https()?'https':'http')."://ip.taobao.com/service/getIpInfo.php?ip=" . $ip;
$ip = json_decode(file_get_contents($url));
if ((string)$ip->code == '1') {
return false;
......@@ -701,4 +701,23 @@ public static function convertArrKey($arr, $key_name)
return $data;
}
public static function getAddressByLatLng($lat,$lng){
$key = \Our\SecretKeys::amapKey;
$url = (self::is_https()?'https':'http').'://restapi.amap.com/v3/geocode/regeo?key='.$key.'&location='.$lng.','.$lat.'&poitype=&radius=10&extensions=all&batch=false&roadlevel=0';
$address = json_decode(file_get_contents($url));
if($address->status){
return json_decode(json_encode($address->regeocode->addressComponent),true);
}
return false;
}
public static function getCityCodeByLatLng($lat,$lng){
$address = self::getAddressByLatLng($lat,$lng);
if($address&&isset($address['citycode'])){
return $address['citycode'];
}
return false;
}
}
......@@ -68,6 +68,8 @@ class NameConst {
const nearbyStoreGoodsPrefix = 'nearbyStoreGoods_';
const memberCounponListPrefix = 'unusedMemberCouponList_';
const cityCode = 'cityCode';
const lat = 'lat';
const lng = 'lng';
......@@ -132,6 +134,8 @@ class NameConst {
const onlineStorageBlGoodsPrefix = 'onlineStorageBlGoods';//组合销售库存前缀
const onlineStorageBlGoodsOriginPrefix = 'onlineStorageBlGoodsOrigin';//组合销售本身库存前缀
const storeCoverPrefix = 'storeCover_';
const storeMiddleAdvsPrefix = 'storeMiddleAdvs_';
......@@ -202,6 +206,12 @@ class NameConst {
const xp='xp';
const win='win';
const pBundlingStorageRedisPrefix = 'pBundlingStorage_';
const goodsStorageRedisPrefix = 'goodsStorage_';
const changedPBundlingStoragePrefix = 'changedPBundlingStorage';
const changedGoodsStoragePrefix = 'changedGoodsStorage';
}
?>
\ No newline at end of file
......@@ -54,6 +54,8 @@ class SecretKeys {
const pushKey='37e9a38cf2983bcdf885e5fd';
const pushSecret='c59868c235bc7ccbe865f9d9';
const amapKey = '51540038b13949411b93f05fd94da971';
}
......
......@@ -843,12 +843,12 @@ class CartServiceModel extends \Business\AbstractModel{
}
//第一步:获取购物车可展示优惠券信息
$memberCouponDao = \DAO\Coupon\MemberCouponModel::getInstance();
$whereSql = ' coupon_state ='.\Our\ApiConst::couponUnused.' and member_id ='.$memberId.' and out_time > '.time();
$memberCouponArray = $memberCouponDao->getList($whereSql,'coupon_id');
$memberCouponArray = $memberCouponDao->getMemberCouponByMemberIdWithOuttime($memberId);
if(!$memberCouponArray){
$storeCartData['couponList'] = array();
return $storeCartData;
}
$couponStoreIds = $storeCartData['storeIds'];
$couponStoreIds[] = \Our\ApiConst::zero;
$couponIds = array_column($memberCouponArray,'coupon_id');
......
......@@ -185,6 +185,7 @@ class CouponServiceModel extends \Business\AbstractModel{
$couponDao->db->doCommit();
//\Our\RedisHelper::delCachedFunction(\Redis\Db13\MemberCouponRedisModel::getInstance(), array(&$memberCouponDao, 'getList'),array(),array($where['couponId']));
\Our\RedisHelper::delCachedFunction(\Redis\Db13\MemberCouponRedisModel::getInstance(), array(&$memberCouponDao, 'getList'),array(),array($memberId));
\Redis\Db13\MemberCouponRedisModel::getInstance()->tableDel(\Our\NameConst::memberCounponListPrefix.$memberId);
\Our\RedisHelper::delCachedFunction(\Redis\Db13\CouponRedisModel::getInstance(), array(&$this, 'getStoreCouponsById'),array(),array($coupon['store_id']."_".$memberId));
return true;
}
......@@ -238,6 +239,7 @@ class CouponServiceModel extends \Business\AbstractModel{
}
}
\Our\RedisHelper::delCachedFunction(\Redis\Db13\MemberCouponRedisModel::getInstance(), array(&$memberCouponDao, 'getList'),array(),array($memberId));
\Redis\Db13\MemberCouponRedisModel::getInstance()->tableDel(\Our\NameConst::memberCounponListPrefix.$memberId);
$couponDao->db->doCommit();
return true;
}
......
......@@ -64,6 +64,8 @@ class GoodsClassServiceModel extends \Business\AbstractModel{
public function getPlatformGoodsClass($where){
//验证参数
$addressDao = \DAO\AddressModel::getInstance();
$validFlag = $addressDao->getValidAddress($where);
if(!$validFlag){
......@@ -86,6 +88,7 @@ class GoodsClassServiceModel extends \Business\AbstractModel{
if($serviceParentClassIds){
$classIds = array_merge($serviceParentClassIds,$classIds);
}
/*
//获取可快递店铺对应分类
$expressClassIds = $this->getExpressStoreClasses($where);
......@@ -93,6 +96,12 @@ class GoodsClassServiceModel extends \Business\AbstractModel{
$classIds = array_merge($expressClassIds,$classIds);
}
*/
/*$classIds = array();
$platformFirstClassDao = \DAO\GoodsClass\PlatformFirstClassModel::getInstance();
$firstClassList = \Our\RedisHelper::cachedFunction(\Redis\Db3\PlatformFirstClassRedisModel::getInstance(),array(&$platformFirstClassDao, 'getList'),array(),\Our\ApiConst::oneHour,array());
if($firstClassList){
$classIds = array_column($firstClassList,'gc_id');
}*/
$classIdKeys = array_flip($classIds);
$goodsClassDao = \DAO\GoodsClassModel::getInstance();
$parentClasses = $goodsClassDao->getParentClasses();
......
......@@ -531,7 +531,8 @@ class GoodsCommonServiceModel extends \Business\AbstractModel
$lat = $param['lat'];
}
$storeInfo = \DAO\StoreModel::getInstance()->get($commonInfo['store_id'],false);
$in_store_service_flag = \DAO\StoreModel::getInstance()->checkAddressInServiceArea(array('lng'=>$lng,'lat'=>$lat),$storeInfo);
//$in_store_service_flag = \DAO\StoreModel::getInstance()->checkAddressInServiceArea(array('lng'=>$lng,'lat'=>$lat),$storeInfo);
$in_store_service_flag = 1;
//所在地
$area = '';
if($commonInfo['areaid_1'] && $commonInfo['areaid_2']){
......@@ -585,7 +586,18 @@ class GoodsCommonServiceModel extends \Business\AbstractModel
$activities = \DAO\SaleMemberModel::getInstance()->isJoinStore($commonInfo['store_id'],$memberId);
//商品表
$goodsInstance = \DAO\GoodsModel::getInstance();
$goods = \Our\RedisHelper::cachedFunction(\Redis\Db4\GoodsRedisModel::getInstance(),array(&$goodsInstance, 'getListAndSetStorage'),array($goodsCommonId,'goods_id,goods_price,goods_marketprice,goods_image,goods_storage,goods_spec,goods_state,goods_verify,is_del'),\Our\ApiConst::oneDaySecond,array($goodsCommonId));
$goods = \Our\RedisHelper::cachedFunction(\Redis\Db4\GoodsRedisModel::getInstance(),array(&$goodsInstance, 'getListAndSetStorage'),array($goodsCommonId,'goods_id,goods_price,goods_marketprice,goods_image,goods_storage,goods_spec,goods_state,goods_verify,is_transport,transport_id,snapshot_id,is_del'),\Our\ApiConst::oneDaySecond,array($goodsCommonId));
$resetGoods = array();
foreach($goods as $tempGoods){
unset($tempGoods['goods_state']);
unset($tempGoods['goods_verify']);
unset($tempGoods['is_del']);
unset($tempGoods['is_transport']);
unset($tempGoods['transport_id']);
unset($tempGoods['snapshot_id']);
array_push($resetGoods,$tempGoods);
}
$goods = $resetGoods;
//商品图片表
$goodsImagesInstance = \DAO\GoodsImagesModel::getInstance();
$image = \Our\RedisHelper::cachedFunction(\Redis\Db4\GoodsImagesRedisModel::getInstance(),array(&$goodsImagesInstance, 'getListByCommonId'),array($goodsCommonId,'attr_name,attr_value,goods_image'),\Our\ApiConst::oneDaySecond,array($goodsCommonId));
......@@ -1452,6 +1464,47 @@ class GoodsCommonServiceModel extends \Business\AbstractModel
/**
* 更新从缓存链表中更新商品库存
* @return bool
*/
public function updateGoodsStorageByRedisList(){
$goodsModel = \DAO\GoodsModel::getInstance();
for($i=0;$i<2000;$i++){
$goodsStr = $goodsModel->getChangedGoodsStorage();
\Our\Log::getInstance()->write($goodsStr,'/data/log/apptest');
if($goodsStr){
$goods = unserialize($goodsStr);
$goodsModel->setDb(\Our\DbNameConst::masterDBConnectName);
$goodsModel->db->doTransaction();
$goodsUpdateResult = $goodsModel->updateStorageByRedis($goods);
if(!$goodsUpdateResult){
$goodsModel->db->doRollback();
}
$goodsCommonUpdateResult = \DAO\GoodsCommonModel::getInstance()->updateStorageByRedis($goods);
if(!$goodsCommonUpdateResult){
$goodsModel->db->doRollback();
}
$goodsModel->db->doCommit();
}else{
break;
}
}
return true;
}
/**
* 更新所有商品库存
* @return bool
*/
public function updateAllStorageForPublish(){
\Our\Log::getInstance()->write('1执行失败','/data/log/apptest');
$this->updateGoodsStorageByRedisList();
\Our\Log::getInstance()->write('2执行失败','/data/log/apptest');
\DAO\PBundlingModel::getInstance()->updateStorageByRedisList();
return true;
}
private static $_instance = null;
......
<?php
/**
* User: liuyuzhen
* Date: 2019/1/9
* Time: 17:09
* Description:
*/
namespace Business\Store;
use Our\ApiConst;
use Our\DbNameConst;
/**
* 店铺service
*
* @date 2018-5-15
* @author zhz
*/
class ClassStoreServiceModel extends \Business\AbstractModel{
$classStoreField = 'store_id as storeId,store_name as storeName,store_label as storeLabel,store_intro as storeIntro,store_longitude,store_latitude,gc_id as gcId,gc_name as gcName';
public function init() {
}
public function getRecommondStores($where,$memberId){
$addressDao = \DAO\AddressModel::getInstance();
$validFlag = $addressDao->getValidAddress($where);
if(!$validFlag){
\Error\ErrorModel::throwException($addressDao->errorCode);
}
$condition['lat'] = $where['lat'];
$condition['lng'] = $where['lng'];
$condition['cityCode'] = $where['cityCode'];
$gcId = $where['gcId'];
\DAO\AddressModel::getInstance()->getValidAddress($condition);
if(!$gcId){
\Error\ErrorModel::throwException(\Error\CodeConfigModel::emptyGcId);
}
/* \Our\RedisHelper::cachedFunction(\Redis\Db6\ClassStoreRedisModel::getInstance(), array(&$classStoreModel, 'getList'), array(array('gc_id'=>$gcId),'store_id,fav_time'), \Our\ApiConst::oneHour,array($memberId));*/
}
public function getStoreListByGcId($gcId,$position){
$lat = $position['lat'];
$lng = $position['lng'];
$classStoreModel = \DAO\Store\ClassStoreModel::getInstance();
$storeList = \Our\RedisHelper::cachedFunction(\Redis\Db6\ClassStoreRedisModel::getInstance(), array(&$classStoreModel, 'getList'), array(array('gc_id'=>$gcId),$this->classStoreField), \Our\ApiConst::oneHour,array());
$newStoreList = array();
if($storeList){
}
}
/**
*/
private static $_instance = null;
/**
* 单例模式获取类实例
*
*/
public static function getInstance() {
if (!(self::$_instance instanceof self)) {
self::$_instance = new self();
}
return self::$_instance;
}
}
......@@ -313,7 +313,7 @@ class StoreServiceModel extends \Business\AbstractModel{
$sellerDistribution = $storeInfo['seller_distribution'];
$buyerDistribution = $storeInfo['buyer_distribution'];
return array('storeLabel'=>$storeLabel,'storeName'=>$storeInfo['store_name'],'grade'=>$grade,'fansCount'=>\DAO\FavoritesStoreModel::getInstance()->getFavoritesStoreCountByStoreId($storeId),'favType'=>$favType,'monthlySalesCount'=>$monthlySalesCount,'defaultDeliveryTime'=>$defaultDeliveryTime,'freeShippingPrice'=>$storeInfo['free_shipping_price'],'storeDistance'=>$distince,'storeNotice'=>$storeInfo['store_notice'],'startShippingPrice'=>$storeInfo['start_shipping_price'],'memberId'=>$storeInfo['member_id'],'inStoreService'=>$in_store_service_flag,'adv'=>$adv,'memberId'=>$storeInfo['member_id'],'businessHours'=>$businessHours,'sellerDistribution'=>$sellerDistribution,'buyerDistribution'=>$buyerDistribution,'bannerColor'=>'#ffa92f','isClose'=>$storeInfo['isClose']);
return array('storeLabel'=>$storeLabel,'storeName'=>$storeInfo['store_name'],'grade'=>$grade,'fansCount'=>\DAO\FavoritesStoreModel::getInstance()->getFavoritesStoreCountByStoreId($storeId),'favType'=>$favType,'monthlySalesCount'=>$monthlySalesCount,'defaultDeliveryTime'=>$defaultDeliveryTime,'freeShippingPrice'=>$storeInfo['free_shipping_price'],'storeDistance'=>$distince,'storeNotice'=>$storeInfo['store_notice'],'startShippingPrice'=>$storeInfo['start_shipping_price'],'memberId'=>$storeInfo['member_id'],'inStoreService'=>1,'adv'=>$adv,'memberId'=>$storeInfo['member_id'],'businessHours'=>$businessHours,'sellerDistribution'=>$sellerDistribution,'buyerDistribution'=>$buyerDistribution,'bannerColor'=>'#ffa92f','isClose'=>$storeInfo['isClose']);
}
/**
......@@ -1176,6 +1176,8 @@ class StoreServiceModel extends \Business\AbstractModel{
$storeDao = \DAO\StoreModel::getInstance();
$storeDao->delNearbyStoresCache($cityCode);
$storeDao->delStoresCacheByCityCode($cityCode);
$platformFirstClassDao = \DAO\GoodsClass\PlatformFirstClassModel::getInstance();
\Our\RedisHelper::delCachedFunction(\Redis\Db3\PlatformFirstClassRedisModel::getInstance(),array(&$platformFirstClassDao, 'getList'),array(),array());
return true;
}
......
......@@ -69,6 +69,51 @@ class AreaModel extends \DAO\AbstractModel {
return $areaList;
}
public function writeToFile(){
$this->setDb($this->dbName);
$where = array('area_deep'=>array('neq',3));
$where= $this->db->getSqlWhereByArray($where);
$areaList = $this->db->select(\Our\NameConst::allField)->from($this->_tableName)->where($where)->order('area_deep','asc')->fetchAll();
$where = array('area_deep'=>3);
$areaSubList = $this->db->select(\Our\NameConst::allField)->from($this->_tableName)->where($where)->limit(0,3000)->order('area_id','asc')->fetchAll();
var_dump(count($areaSubList));
$proInfoList = array();
foreach($areaList as $area){
if($area['area_deep']==1){
$proInfoList[$area['area_id']]['area_name'] = $area['area_name'];
}else{
$city = array();
$city['city_name'] = $area['area_name'];
$city['city_id'] = $area['area_id'];
$proInfoList[$area['area_parent_id']]['list'][] = $city;
}
}
$newAreaList = array();
foreach($areaSubList as $area){
$newAreaList[$area['area_parent_id']][]= $area['area_name'];
}
$returnList = array();
$proList = array();
foreach($proInfoList as $proInfo){
$return = array();
$return['name'] = $proInfo['area_name'];
$return['city'] = array();
if($proInfo['list']){
foreach($proInfo['list'] as $city){
$newCity= array();
$newCity['name'] = $city['city_name'];
$newCity['area'] = $newAreaList[$city['city_id']]?$newAreaList[$city['city_id']]:array();
var_dump($newCity);
array_push($return['city'],$newCity);
}
}
$returnList[] = $return;
}
\Our\Log::getInstance()->write(json_encode($returnList),'/data/log/appcity');
return $returnList;
}
public function getCityListWithoutCounty(){
$addressRedis = AddressRedisModel::getInstance();
$cityList = $addressRedis->find('cityListWithoutCounty');
......
......@@ -41,7 +41,6 @@ class MemberCouponModel extends \DAO\AbstractModel{
*/
public function getListByMemberId($memberId,$couponIds){
$whereSql = ' member_id = '.$memberId .' and coupon_id in ('.implode(',',$couponIds).')';
$result = $this->getList($whereSql);
return $result;
}
......@@ -59,6 +58,34 @@ class MemberCouponModel extends \DAO\AbstractModel{
return $memberCoupons;
}
/**
* 获取当前用户未领取的有效优惠券
* @param $where
* @param $memberId
* @return array
*/
public function getMemberCouponByMemberIdWithOuttime($memberId){
$memberCouponRedisModel = \Redis\Db13\MemberCouponRedisModel::getInstance();
$memberCoupons = $memberCouponRedisModel->tableCacheGet(\Our\NameConst::memberCounponListPrefix.$memberId);
if($memberCoupons){
$newMemberCouponArray = array();
foreach($memberCoupons as $tempMemberCoupon){
if($tempMemberCoupon['out_time']>=TIMESTAMP){
$newMemberCouponArray[] =$tempMemberCoupon;
}
}
return $newMemberCouponArray;
}
$where = ' coupon_state ='.\Our\ApiConst::couponUnused.' and member_id ='.$memberId;
$where .= ' and out_time > '.TIMESTAMP;
$field = 'coupon_id,add_time,out_time';
$memberCoupons = $this->getList($where , $field);
if($memberCoupons){
$memberCouponRedisModel->tableCacheSet(\Our\NameConst::memberCounponListPrefix.$memberId,$memberCoupons,\Our\ApiConst::oneDaySecond);
}
return $memberCoupons;
}
public function getValidMemberCoupon($where,$memberId){
if(!$memberId){
$this->errorCode = \Error\CodeConfigModel::emptyMemberCouponMemberId;
......
......@@ -39,7 +39,7 @@ class GoodsModel extends \DAO\AbstractModel {
* @return mixed
*/
public function updateStorage($goodsId, $num, $op) {
$this->setDb();
$this->setDb(\Our\DbNameConst::masterDBConnectName);
$whereSql = 'goods_id='.$goodsId;
if($op==1){ //调整库存
$updateSql = 'goods_storage = goods_storage'.($num<0 ? '-'.(-$num) : '+'.$num);
......@@ -51,6 +51,26 @@ class GoodsModel extends \DAO\AbstractModel {
return $this->db->update($this->_tableName)->query($updateAllSql);
}
public function updateStorageByRedis($goods){
$this->setDb(\Our\DbNameConst::masterDBConnectName);
$sql = 'UPDATE '.$this->_tableName.' set goods_edittime = '.TIMESTAMP.',goods_storage = ';
if($goods['op']==\Our\ApiConst::set){
$sql .= $goods['goods_storage'] ;
}else{
$sql .= 'goods_storage '.\Our\ArrayConst::ops[$goods['op']].$goods['goods_storage'] ;
/*if($goods['sale_num']){
$sql .= ' sale'
}*/
}
$sql .= ' where goods_id = '.$goods['goods_id'];
\Our\Log::getInstance()->write($sql.' 执行失败','/data/log/apptest');
$result = $this->db->update($this->_tableName)->query($sql);
if($result===false){
\Our\Log::getInstance()->write($sql.' 执行失败');
}
return $result;
}
/**
*
* 分页获取商品列表
......@@ -122,6 +142,14 @@ class GoodsModel extends \DAO\AbstractModel {
return $goods;
}
public function getOnelineOneWithStorage($goodsId,$field= \Our\NameConst::allField){
$goodsInfo = $this->getOnlineOne($goodsId,$field);
if($goodsInfo){
}
return array();
}
public function validAddCartGoods($where,$storageFlag = false){
$goods = $this->getOnlineOne($where['goodsId'],$this->cartGoodsField);
if(!$goods){
......@@ -174,7 +202,7 @@ class GoodsModel extends \DAO\AbstractModel {
* 获取商品是否在售,如果在售还返回对应库存信息
* @param $goodsId
*/
public function getOnlineStorageGoods($goodsId){
/*public function getOnlineStorageGoods($goodsId){
$goodsRedis = \Redis\Db4\GoodsRedisModel::getInstance();
$onlineStorageGoodsKey = \Our\NameConst::onlineStorageGoodsPrefix.$goodsId;
$onlineStorageGoods = $goodsRedis->tableHGAll($onlineStorageGoodsKey);
......@@ -194,8 +222,27 @@ class GoodsModel extends \DAO\AbstractModel {
$goodsRedis->tableHMGet($onlineStorageGoodsKey,$data,\Our\ApiConst::tenDaySecond);
return $data;
}
}*/
/**
* 更新需要更新缓存的链表
* @param $pBundling
*/
public function addChangedGoodsStorage($pBundling){
$goodsRedisDao = \Redis\Db4\GoodsRedisModel::getInstance();
$goodsRedisDao->tableLPush(\Our\NameConst::changedGoodsStoragePrefix,$pBundling);
}
/**
* 获取需要更新缓存的链表数据
*/
public function getChangedGoodsStorage(){
$goodsRedisDao = \Redis\Db4\GoodsRedisModel::getInstance();
return $goodsRedisDao->tableLPop(\Our\NameConst::changedGoodsStoragePrefix);
}
/**
* 更新商品库存缓存以及更新销量
* @param $goodsList 商品列表
......@@ -204,12 +251,17 @@ class GoodsModel extends \DAO\AbstractModel {
*/
public function opOnlineStorageGoodsByGoodsCommonIds($goodsList,$op = \Our\ApiConst::minus,$updateSaleNumFalg = true){
$goodsRedis = \Redis\Db4\GoodsRedisModel::getInstance();
if($updateSaleNumFalg){
$goodsCommonRedis = \Redis\Db4\GoodsCommonRedisModel::getInstance();
$onlineGoodsCommonSaleNumKey = \Our\NameConst::onlineGoodsCommonSaleNumPrefix;
}
$goodsCommonRedis = \Redis\Db4\GoodsCommonRedisModel::getInstance();
$onlineGoodsCommonSaleNumKey = \Our\NameConst::onlineGoodsCommonSaleNumPrefix;
/*if($updateSaleNumFalg){
}*/
$goodsCommonList = $this->getOnlineStorageGoodsByGoodsCommonIds(array_keys($goodsList));
foreach($goodsCommonList as $goodsCommonId=>$goodsCommonsTemp){
$isLock = \Lock\RedisLock::getInstance()->getLock(\Our\NameConst::goodsStorageRedisPrefix.$goodsCommonId);
if(!$isLock){
\Lock\RedisLock::getInstance()->releaseLock(\Our\NameConst::goodsStorageRedisPrefix.$goodsCommonId);
return false;
}
$newGoodsList = array();
$totalGoodsNum = \Our\ApiConst::zero;
foreach($goodsCommonsTemp as $goodsId=>$temp){
......@@ -221,16 +273,29 @@ class GoodsModel extends \DAO\AbstractModel {
}else if($op == \Our\ApiConst::set){
$temp['goodsStorage'] = $goodsList[$goodsCommonId][$goodsId]['goodsNum'];
}else{
\Lock\RedisLock::getInstance()->releaseLock(\Our\NameConst::goodsStorageRedisPrefix.$goodsCommonId);
return false;
}
$totalGoodsNum += $goodsList[$goodsCommonId][$goodsId]['goodsNum'];
$updateGoods = array(
'goods_id'=>$goodsId,
'goods_commonid'=>$goodsCommonId,
'goods_storage'=>$goodsList[$goodsCommonId][$goodsId]['goodsNum'],
'op'=>$op
);
if($updateSaleNumFalg&&$op!=\Our\ApiConst::set){
$updateGoods['sale_num'] = $goodsList[$goodsCommonId][$goodsId]['goodsNum'];
}
$this->addChangedGoodsStorage(serialize($updateGoods));
}
$newGoodsList[$goodsId]= serialize($temp);
}
if($newGoodsList){
$onlineStorageGoodsKey = \Our\NameConst::onlineStorageGoodsPrefix.$goodsCommonId;
$result = $goodsRedis->tableHMSet($onlineStorageGoodsKey,$newGoodsList,\Our\ApiConst::tenDaySecond);
if(!$result){
\Lock\RedisLock::getInstance()->releaseLock(\Our\NameConst::goodsStorageRedisPrefix.$goodsCommonId);
return false;
}
......@@ -254,13 +319,14 @@ class GoodsModel extends \DAO\AbstractModel {
}
}
}
\DAO\PBundlingModel::getInstance()->deletePBundlingByGoodsCommonId($goodsCommonId);
//\DAO\PBundlingModel::getInstance()->deletePBundlingByGoodsCommonId($goodsCommonId);
\DAO\PBundlingModel::getInstance()->updatePBundlingByGoodsCommonId($goodsCommonId);
\Lock\RedisLock::getInstance()->releaseLock(\Our\NameConst::goodsStorageRedisPrefix.$goodsCommonId);
}
return true;
}
/**
* 根据商品CommonId获取库存信息
* @param $goodsCommonIds
......@@ -288,7 +354,7 @@ class GoodsModel extends \DAO\AbstractModel {
$sql = \Our\Common::format(' goods_commonid in ({0})',implode(',',$noRedisGoodsCommonIds));
$field = 'goods_commonid,goods_id,goods_storage,goods_state,goods_verify,is_del';
}
if($sql&&$field){
if(isset($sql)&&isset($field)){
$goodsArray = $this->getList($sql,$field);
$goodsCommonList = array();
$goodsList = array();
......@@ -354,18 +420,9 @@ class GoodsModel extends \DAO\AbstractModel {
if($goods['goods_state'] == \Our\ApiConst::onlineGoodsState && $goods['goods_verify'] == \Our\ApiConst::onlineGoodsVerify && $goods['is_del'] == \Our\ApiConst::onlineGoodsDel){
$onlineFlag = \Our\ApiConst::one;
}
unset($goodsList[$key]['goods_state']);
unset($goodsList[$key]['goods_verify']);
unset($goodsList[$key]['is_del']);
$data[$goods['goods_id']] = serialize(array('onlineFlag'=>$onlineFlag,'goodsStorage'=>$goods['goods_storage']));
}
$goodsRedis->tableHMSet($onlineStorageGoodsKey,$data,\Our\ApiConst::tenDaySecond);
}else{
foreach ($goodsList as $key => $goods){
unset($goodsList[$key]['goods_state']);
unset($goodsList[$key]['goods_verify']);
unset($goodsList[$key]['is_del']);
}
}
}
......
<?php
namespace DAO\GoodsClass;
/**
* User: liuyuzhen
* Date: 2018/7/18
* Time: 10:58
* Description:
*/
class PlatformFirstClassModel extends \DAO\AbstractModel{
/**
* 表名
*
* @var string
*/
protected $_tableName = 'han_platform_first_class';
/**
* 主键
*
* @var string
*/
protected $_primaryKey = 'gc_parent_id';
public function init(){
}
public function findByWhere($where){
$this->setDb(\Our\DbNameConst::salveDBConnectName);
$address = $this->db->from($this->_tableName)->where($where)->fetchOne();
return $address;
}
public function getList($where,$field = \Our\NameConst::allField){
$this->setDb($this->dbName);
$result = $this->db->select($field)->from($this->_tableName)->where($where)->fetchAll();
return $result;
}
/**
* 类实例
*/
private static $_instance = null;
/**
* 获取类实例
*/
public static function getInstance($dbName= \Our\DbNameConst::salveDBConnectName) {
if (!(self::$_instance instanceof self)) {
self::$_instance = new self($dbName);
}
return self::$_instance;
}
}
\ No newline at end of file
......@@ -80,6 +80,8 @@ class GoodsCommonModel extends \DAO\AbstractModel {
return $saleNum;
}
/**
* 删除销量缓存
* @param $goodsCommonId
......@@ -255,6 +257,28 @@ class GoodsCommonModel extends \DAO\AbstractModel {
}
public function updateStorageByRedis($goods){
$this->setDb(\Our\DbNameConst::masterDBConnectName);
$sql = 'UPDATE '.$this->_tableName.' set goods_edittime = '.TIMESTAMP.',goods_storage = ';
if($goods['op']==\Our\ApiConst::set){
$sql .= $goods['goods_storage'] ;
}else{
$sql .= 'goods_storage '.\Our\ArrayConst::ops[$goods['op']].$goods['goods_storage'] ;
if($goods['sale_num']){
$sql .= ' , sale_num = sale_num '.($goods['op']==\Our\ApiConst::plus?'-':'+').' '.$goods['sale_num'];
}
}
$sql .= ' where goods_commonid = '.$goods['goods_commonid'];
\Our\Log::getInstance()->write($sql.' 执行失败','/data/log/apptest');
$result = $this->db->update($this->_tableName)->query($sql);
if($result===false){
\Our\Log::getInstance()->write($sql.' 执行失败');
}
return $result;
}
public function updateGoodsStorage($dataList , $op = \Our\ApiConst::minus,$updateSaleNumFlag = false){
$datas = array_values($dataList);
$this->setDb(\Our\DbNameConst::masterDBConnectName);
......
......@@ -3,6 +3,8 @@
namespace DAO;
use Error\CodeConfigModel;
class PBundlingModel extends \DAO\AbstractModel {
......@@ -92,6 +94,8 @@ class PBundlingModel extends \DAO\AbstractModel {
$pBundling = $this->findById($blId,$field);
if($pBundling){
$storage = $pBundling['bl_storage'];
$bundingGoodsWhere['bl_id'] = $blId;
$bundlingGoodsList = \DAO\PBundlingGoodsModel::getInstance()->getList($this->pBundingGoodsField,$bundingGoodsWhere);
$pBundlingRedis->tableHSet(\Our\NameConst::onlineStorageBlGoodsPrefix,$blId,$pBundling['bl_storage'],\Our\ApiConst::oneDaySecond);
}else{
$storage = \Our\ApiConst::zero;
......@@ -160,9 +164,94 @@ class PBundlingModel extends \DAO\AbstractModel {
public function getPBundlingCacheByBlId($blId){
$pBundlingDao = \Redis\Db4\PBundlingRedisModel::getInstance();
return $pBundlingDao->getByKeys('gid_'.$blId);
$result = $pBundlingDao->getByKeys('gid_'.$blId);
if($result){
return $result['result'];
}
return false;
}
/**
* 更新组合销售缓存
* @param $blId
* @param $blStorage
* @param int $op
* @return bool
* @throws \Error\OurExceptionModel
* @throws \Exception
*/
public function updatePBundlingStorageCacheByBlId($blId,$blStorage,$op=\Our\ApiConst::minus){
$isLock = \Lock\RedisLock::getInstance()->getLock(\Our\NameConst::pBundlingStorageRedisPrefix.$blId);
if(!$isLock){
\Error\ErrorModel::throwException(\Error\CodeConfigModel::serverBusy);
}
$pBundlingRedisDao = \Redis\Db4\PBundlingRedisModel::getInstance();
$result = $pBundlingRedisDao->getByKeys('gid_'.$blId);
if(!$result){
\Lock\RedisLock::getInstance()->releaseLock(\Our\NameConst::pBundlingStorageRedisPrefix.$blId);
return false;
}
$pBundling = $result['result'];
\Our\Log::getInstance()->write(json_encode($pBundling),'/data/log/apptest');
$key = $result['key'];
if($op == \Our\ApiConst::minus){
$pBundling['bl_storage'] = $pBundling['bl_storage']-$blStorage;
if($pBundling['bl_storage']-$blStorage<\Our\ApiConst::zero){
\Lock\RedisLock::getInstance()->releaseLock(\Our\NameConst::pBundlingStorageRedisPrefix.$blId);
\Error\ErrorModel::throwException(\Our\CodeConfigModel::pBundlingNoStorageForOrder);
}
$pBundling['bl_origin_storage'] = $pBundling['bl_origin_storage']-$blStorage;
}else if($op == \Our\ApiConst::plus){
$pBundling['bl_storage'] = $pBundling['bl_storage']+$blStorage;
$pBundling['bl_origin_storage'] = $pBundling['bl_origin_storage']+$blStorage;
}
\Our\Log::getInstance()->write(json_encode($pBundling),'/data/log/apptest');
\Lock\RedisLock::getInstance()->releaseLock(\Our\NameConst::pBundlingStorageRedisPrefix.$blId);
\Our\Log::getInstance()->write($key,'/data/log/apptest');
return $pBundlingRedisDao->setNoPrefix($key,serialize($pBundling),\Our\ApiConst::oneDaySecond);
}
/**
* 更新需要更新缓存的链表
* @param $pBundling
*/
public function addChangedPBundlingStorage($pBundling){
$pBundlingRedisDao = \Redis\Db4\PBundlingRedisModel::getInstance();
$pBundlingRedisDao->tableLPush(\Our\NameConst::changedPBundlingStoragePrefix,$pBundling);
}
/**
* 获取需要更新缓存的链表数据
*/
public function getChangedPbundlingStorage(){
$pBundlingRedisDao = \Redis\Db4\PBundlingRedisModel::getInstance();
return $pBundlingRedisDao->tableLPop(\Our\NameConst::changedPBundlingStoragePrefix);
}
public function updateStorageByRedisList(){
$this->setDb(\Our\DbNameConst::masterDBConnectName);
for($i=0;$i<2000;$i++){
$pbundlingStr = $this->getChangedPbundlingStorage();
if(!$pbundlingStr){
break;
}
$pbundling = unserialize($pbundlingStr);
if($pbundling['op'] != \Our\ApiConst::set){
$sql = \Our\Common::format("UPDATE {$this->_tableName} set bl_storage = bl_storage {2} {0} where bl_id = {1} ",$pbundling['bl_storage'],$pbundling['bl_id'],\Our\ArrayConst::ops[$pbundling['op']]);
}else{
$sql = \Our\Common::format("UPDATE {$this->_tableName} set bl_storage = {0} where bl_id = {1} ",$pbundling['bl_storage'],$pbundling['bl_id']);
}
$one = $this->db->update($this->_tableName)->query($sql);
if($one===false){
\Our\Log::getInstance()->write($sql.' 执行失败');
}
}
return true;
}
public function deletePBundlingByBlId($blId){
$pBundlingDao = \Redis\Db4\PBundlingRedisModel::getInstance();
$pBundlingDao->tableDelAll($pBundlingDao->tableKeys('gid_'.$blId));
......@@ -170,7 +259,42 @@ class PBundlingModel extends \DAO\AbstractModel {
public function deletePBundlingByGoodsCommonId($goodsCommonId){
$pBundlingDao = \Redis\Db4\PBundlingRedisModel::getInstance();
$pBundlingDao->tableDelAll($pBundlingDao->tableKeys('*'.\Our\NameConst::blGoods.$goodsCommonId));
return $pBundlingDao->tableDelAll($pBundlingDao->tableKeys('*'.\Our\NameConst::blGoods.$goodsCommonId));
}
/**
* 根据GoodsCommonIds反向更新组合销售数据
* @param $goodsCommonId
*/
public function updatePBundlingByGoodsCommonId($goodsCommonId){
$goodsRedis = \Redis\Db4\GoodsRedisModel::getInstance();
$onlineStorageGoodsKey = \Our\NameConst::onlineStorageGoodsPrefix.$goodsCommonId;
$onlineStorageGoods = $goodsRedis->tableHGAll($onlineStorageGoodsKey);
$pBundlingRedisDao = \Redis\Db4\PBundlingRedisModel::getInstance();
$keys = $pBundlingRedisDao->tableKeys('*'.\Our\NameConst::blGoods.$goodsCommonId);
foreach($keys as $blIdKey){
$pBundling = $pBundlingRedisDao->getNoPrefix($blIdKey);
if(\Our\Common::isSerialized($pBundling)){
$pBundling = unserialize($pBundling);
}
$goodsList = $pBundling['goodsList'];
if($goodsList){
$newGoods = array();
foreach($goodsList as $goods){
if($goods['goodsCommonId']==$goodsCommonId){
$goods['goodsStorage'] = unserialize($onlineStorageGoods[$goods['goods_id']])['goodsStorage'];
if(intval($goods['goodsStorage']/$goods['num'])<$pBundling['bl_storage']){
$pBundling['bl_storage'] = intval($goods['goodsStorage']/$goods['num']);
}
}
$newGoods[] = $goods;
}
$pBundling['goodsList'] = $newGoods;
}
$pBundlingRedisDao->setNoPrefix($blIdKey,serialize($pBundling),\Our\ApiConst::oneDaySecond);
}
return true;
}
public function delPBundlingListByStoreIdAndBlIds($storeId=false,$blId=false){
......
......@@ -123,6 +123,8 @@ class QmStoreClassModel extends \DAO\AbstractModel{
if($storeId){
\Our\RedisHelper::delCachedFunction(\Redis\Db6\QmStoreClassRedisModel::getInstance(), array(&$this, 'getStoreSignClasses'),array(),array('store'.$storeId));
}
$platformFirstClassDao = \DAO\GoodsClass\PlatformFirstClassModel::getInstance();
\Our\RedisHelper::delCachedFunction(\Redis\Db3\PlatformFirstClassRedisModel::getInstance(),array(&$platformFirstClassDao, 'getList'),array(),array());
}
/**
......
......@@ -151,7 +151,7 @@ class GoodsStorageModel extends \DAO\AbstractModel {
* 获取商品是否在售,如果在售还返回对应库存信息
* @param $goodsId
*/
public function getOnlineStorageGoods($goodsId){
/*public function getOnlineStorageGoods($goodsId){
$goodsRedis = \Redis\Db4\GoodsRedisModel::getInstance();
$onlineStorageGoodsKey = \Our\NameConst::onlineStorageGoodsPrefix.$goodsId;
$onlineStorageGoods = $goodsRedis->tableHGAll($onlineStorageGoodsKey);
......@@ -170,7 +170,7 @@ class GoodsStorageModel extends \DAO\AbstractModel {
$goodsRedis->tableHMGet($onlineStorageGoodsKey,$data,\Our\ApiConst::tenDaySecond);
return $data;
}
}
}*/
/**
* 更新商品缓存
......
<?php
/**
* User: liuyuzhen
* Date: 2019/1/9
* Time: 16:52
* Description:
*/
namespace DAO\Store;
class ClassStoreModel extends \DAO\AbstractModel{
protected function init()
{
}
/**
* 表名
*
* @var string
*/
protected $_tableName = 'han_class_store';
/**
* 主键
*
* @var string
*/
protected $_primaryKey = 'id';
public function findByWhere($where){
$this->setDb(\Our\DbNameConst::salveDBConnectName);
$address = $this->db->from($this->_tableName)->where($where)->fetchOne();
return $address;
}
public function getList($where,$field = \Our\NameConst::allField,$orders = array('gc_parent_id'=>'asc','gc_sort'=>'asc','gc_id'=>'asc')){
$this->setDb($this->dbName);
$this->db->select($field)->from($this->_tableName);
if($orders){
foreach($orders as $key=>$val){
$this->db->order($key,$val);
}
}
$result = $this->db->where($where)->fetchAll();
return $result;
}
/**
* 类实例
*/
private static $_instance = null;
/**
* 获取类实例
*/
public static function getInstance($dbName= \Our\DbNameConst::salveDBConnectName) {
if (!(self::$_instance instanceof self)) {
self::$_instance = new self($dbName);
}
return self::$_instance;
}
}
......@@ -105,6 +105,7 @@ class CodeConfigModel
const notHaveAccess = 10117;
const sellerJoinUpdateFailed = 10118;
const passwordLenLimit = 10119;
const redisLockedFailed = 10120;
//访问错误
const illegalAccess = 200001;
......@@ -326,7 +327,9 @@ class CodeConfigModel
const beyondRecieverTime=300144;
const payTypeUpdateError = 30145;
const beyongRefundAmount = 300146;
const cancelRefundMoneyError = 300147;
const addOrderFrequently = 300147;
const cancelRefundMoneyError = 300148;
const serverBusy = 300149;
//店铺相关错误码
//商品分类
......@@ -482,7 +485,7 @@ class CodeConfigModel
self::emptyDeviceUniqueCode => '设备唯一识别码不能为空',
self::addMemberInfoFailed => '注册保存用户信息失败',
self::wrongMobileFormat => '手机号码格式错误',
self::registerMobileExist => '您的手机号码已经存在',
self::registerMobileExist => '该手机号码已注册',
self::emptyUserType => '用户来源不能为空',
self::wrongUserType => '用户只能来自微博、QQ、微信',
self::emptyUserAvatar => '第三方用户头像不能为空',
......@@ -539,7 +542,8 @@ class CodeConfigModel
self::sellerNameUpdateFailed => '更换手机时卖家手机号码更新失败',
self::notHaveAccess => '您没有权限使用',
self::sellerJoinUpdateFailed => '更换手机时卖家手机号码更新失败',
self::passwordLenLimit => '密码为6~16位的数字或字母组合',
self::passwordLenLimit => '密码长度不能小于6位',
self::redisLockedFailed => '获取redis锁失败',
//商品相关
self::emptyCommonId => '商品主键不能为空',
self::goodsNotExist => '商品不存在',
......@@ -835,7 +839,9 @@ class CodeConfigModel
self::beyondRecieverTime=>'设置收货时间不能早于当前时间',
self::payTypeUpdateError=> '更新支付类型失败',
self::beyongRefundAmount=>'退款金额不能超过可退款金额',
self::addOrderFrequently => '操作太频繁,请稍后重试',
self::cancelRefundMoneyError=>'退款有误,请于商家联系',
self::serverBusy => '服务器繁忙,请稍后重试',
//销售员
self::emptySaleGoodsId => '商品id不能为空',
self::emptySaleGoods => '销售商品不存在',
......
File mode changed from 100755 to 100644
......@@ -36,6 +36,9 @@ class LinkMySQLModel{
public static function get($database='resources.database.slave.params') {
if ( empty(self::$_configs[$database]) ) {
if($database===true){
$database = 'resources.database.params';
}
$config = \Yaf\Registry::get('config')->get($database);
$config = $config->toArray();
self::$_configs[$database]=$config;
......
......@@ -89,7 +89,8 @@ class AbstractModel {
* @return
*/
public function del($key) {
return $this->getRedis()->del($this->_addPrefix($key));
$keyNew = $this->_addPrefix($key);
return $this->getRedis()->del($keyNew);
}
public function delAll($data){
return $this->getRedis()->del($data);
......@@ -135,10 +136,21 @@ class AbstractModel {
return $this->getRedis()->get($this->_addPrefix($key));
}
public function setnx($key, $value,$expire=\Our\ApiConst::zero){
$res=$this->getRedis()->setnx($this->_addPrefix($key),$value);
if($expire>0){
$this->getRedis()->expire($this->_addPrefix($key),$expire);
}
return $res;
}
public function getNoPrefix($key){
return $this->getRedis()->get($key);
}
public function setNoPrefix($key,$value,$expire=0){
return $this->getRedis()->set($key,$value,$expire);
}
/**
* redis自增1
*
......
<?php
namespace Redis\Db0;
namespace Redis\Db1;
/**
* User: liuyuzhen
* Date: 2018/8/20
* Time: 10:30
* Description:
*/
class LockRedisModel extends \Redis\Db0\AbstractModel {
class LockRedisModel extends \Redis\Db1\AbstractModel {
/**
* 表名
*
......@@ -72,6 +72,10 @@ class LockRedisModel extends \Redis\Db0\AbstractModel {
return $this->del($this->calcKey($h));
}
public function tableSetnx($id,$data,$experio=\Our\ApiConst::zero){
$res=$this->setnx($this->calcKey($id), $data,$experio);
return $res;
}
public function tableExpire($key,$experio=0){
return $this->expire($this->calcKey($key),$experio);
}
......
<?php
namespace Redis\Db3;
/**
* 平台在经营一级分类
* User: liuyuzhen
* Date: 2019/01/08
* Time: 15:36
* Description:
*/
class PlatformFirstClassRedisModel extends \Redis\Db3\AbstractModel{
/**
* 表名
*
* @var string
*/
protected $_tableName = 'han_platform_first_class';
/**
* 类实例
*
*/
private static $_instance = null;
/**
* 获取类实例
*/
public static function getInstance() {
if (!(self::$_instance instanceof self)) {
self::$_instance = new self();
}
return self::$_instance;
}
}
\ No newline at end of file
......@@ -39,9 +39,9 @@ class AbstractModel extends \Redis\AbstractModel {
$str = $str[0];
$result = $this->getNoPrefix($str);
if($this->is_serialized($result)){
return unserialize($result);
$result = unserialize($result);
}
return $result;
return array('key'=>$str,'result'=>$result);
}else{
return false;
}
......
<?php
namespace Redis\Db6;
/**
* 分类店铺信息缓存
*/
class ClassStoreRedisModel extends \Redis\Db6\AbstractModel {
/**
* 表名
*
* @var string
*/
protected $_tableName = 'han_class_store';
/**
* 计算key
*
* @param int $id
* @return string
*/
public function calcKey($id) {
return $this->_tableName . self::DELIMITER . $id;
}
/**
* 根据id查找店铺信息
*
* @param int $id
* @return array
*/
public function find($id,$expire=\Our\ApiConst::zero) {
$result = $this->get($this->calcKey($id));
if($expire>\Our\ApiConst::zero){
$this->expire($this->calcKey($id),$expire);
}
if($this->is_serialized($result)){
return unserialize($result);
}
return $result;
}
/**
* 更新数据
*
* @param int $id
* @param array $data
*/
public function update($id, $data,$expire=0) {
return $this->set($this->calcKey($id), serialize($data),$expire);
}
public function tableHSet($h,$key,$val,$experio=0){
return $this->hset($this->calcKey($h),$key,$val,$experio);
}
public function tableHGet($h,$key){
return $this->hget($this->calcKey($h),$key);
}
public function tableHMSet($h,$keysvalue,$experio=0){
return $this->hmset($this->calcKey($h),$keysvalue,$experio);
}
public function tableHMGet($h,$keyvalues){
return $this->hmget($this->calcKey($h),$keyvalues);
}
public function tableHGAll($h){
return $this->hGetAll($this->calcKey($h));
}
public function tableDel($h){
return $this->del($this->calcKey($h));
}
public function tableCacheGet($id){
$result = $this->get($this->calcKey($id));
return $result;
}
public function tableCacheSet($id,$data,$experio){
$res=$this->set($this->calcKey($id), $data,$experio);
return $res;
}
/**
* 类实例
*
* @var \Redis\Db0\UserModel
*/
private static $_instance = null;
/**
* 获取类实例
*
* @return \Redis\Db0\UserModel
*/
public static function getInstance() {
if (!(self::$_instance instanceof self)) {
self::$_instance = new self();
}
return self::$_instance;
}
}
......@@ -12,7 +12,7 @@ application.dispatcher.catchException = true
; Admin模块用于后台管理
application.modules = Index,Api,Admin,Client
redis.redisPublishName='redisPublish';
redis.redisPublishName='redisPublish'
[productone : common]
; 数据库配置
......@@ -422,6 +422,8 @@ resources.database.slave.params.password = "123456"
resources.database.slave.params.charset = "UTF8"
resources.database.slave.params.driver_options.1002 = "SET NAMES utf8"
password.key='~!@#$`1234qwertasdfgzxcvb'
redis.database.params.host = "127.0.0.1"
......
......@@ -7,7 +7,7 @@ define("APP_ENV",ini_get('yaf.environ'));
if(APP_ENV=='develop'){
error_reporting(E_ALL);
}
if(APP_ENV=='test' || APP_ENV=='pre' ||APP_ENV=='ccwdevelop' || APP_ENV=='product' || APP_ENV=='productone'){
if(APP_ENV=='test' || APP_ENV=='pre' ||APP_ENV=='ccwdevelop' || APP_ENV=='product' || APP_ENV=='productone'|| APP_ENV=='lyztest' ){
if(isset($_POST['data']['debug'])&&!empty($_POST['data']['debug'])){
// define("DEBUG",1);
error_reporting(E_ALL);
......
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