Commit 759c43a0 authored by christ's avatar christ

refundstatic

parents 0a754718 9e150f7d
File mode changed from 100755 to 100644
......@@ -197,7 +197,8 @@ class ApiConst
//是否退款成功
const refundSuccess = 1;
const refundFail = 0;
//order refundState all
const refundStateAll=2;
const isNotSuccessRefund=0;
const refundCompleted=3;
......@@ -310,6 +311,7 @@ class ApiConst
const commonClassStyle = 1;
const signClassStyle = 2;
const isEffective=0;
const defaultAddressCount = 3;
......
......@@ -365,7 +365,10 @@ class Common
},$str);
return $str;
}
public static function getTodayBeginTimpSpan(){
$totayTimeSpan=strtotime(date('Y-m-d'));
return $totayTimeSpan;
}
/**
* 驼峰数组转下划线数组
* @param array $data
......
......@@ -638,7 +638,7 @@ class OrderServiceModel extends \Business\AbstractModel
echo " 退款操作操作成功:".$orderId;
return true;
}else{
echo $refundReturnDao->errorMessage;
echo $refundReturnDao->errorMessage."orderId:".$orderId;
}
......
......@@ -49,6 +49,7 @@ class ShopkeeperServiceModel extends \Business\AbstractModel
{
$memberDao = \DAO\MemberModel::getInstance();
$storeId = $memberDao->getInfo($memberId, 'store_id');
$storeStaticDao=\DAO\StoreStatisticsModel::getInstance();
//$storeId = $this->_getStoreByMemberId($memberId);
// $storeStatisticsDayDao = \DAO\Store\StoreStatisticsDayModel::getInstance();
// $storeStatisticsDao = \DAO\StoreStatisticsModel::getInstance();
......@@ -67,7 +68,9 @@ class ShopkeeperServiceModel extends \Business\AbstractModel
// $storeStats=$orderDao->getShopKeeperCountByStoreId($storeId);
$storeStats = $orderDao->getShopKeeperCountByStoreIdCache($storeId);
$storeFavariteCount = $favoritesStoreDao->getFavoritesCountByStoreIdCache($storeId);
$todayTotalOnline=\Our\RedisHelper::cachedFunction(\Redis\Db6\StoreRedisModel::getInstance(), array(&$orderDao, 'getOrderOrderTotalOnlineByStoreId'), array($storeId,true), ApiConst::oneDaySecond, array($storeId));
$orderTotalOnline=\Our\RedisHelper::cachedFunction(\Redis\Db6\StoreRedisModel::getInstance(), array(&$storeStaticDao, 'getByStoreId'), array($storeId), ApiConst::oneDaySecond, array($storeId));;
$orderTotalOnline=$orderTotalOnline['orderTotalOnline']?$orderTotalOnline['orderTotalOnline']:ApiConst::zero;
$goodsCount = $totalOrderCount['orderGoodsCount'];
$orderTotal = $totalOrderCount['orderTotal'];
$data['storeId'] = $store['store_id'];
......@@ -76,9 +79,11 @@ class ShopkeeperServiceModel extends \Business\AbstractModel
$data['goodsCount'] = $goodsCount?$goodsCount:ApiConst::zero;
$data['orderCount'] = $storeStats['orderCount'];
$data['orderTotal'] = $orderTotal?$orderTotal:ApiConst::zero;
$data['orderTotalOnline'] = $orderTotalOnline;
$data['favCount'] = $storeFavariteCount['favCount'];
$data['todayOrderCount'] = $storeStats['todayOrderCount'];
$data['todayOrderTotal'] = $storeStats['todayOrderTotal'];
$data['todayOrderTotalOnline']=$todayTotalOnline;
$data['tadayFavCount'] = $storeFavariteCount['todayFavCount'];
$data['todayFavCount'] = $storeFavariteCount['todayFavCount'];
return $data;
......@@ -322,7 +327,7 @@ class ShopkeeperServiceModel extends \Business\AbstractModel
//$orderCommons = $orderCommonDao->getAllByOrderIds($orderIds, $orderCommonDao->orderCommonField);
$ordersOrderCommons = Common::intergrateOneToOne($orders, $qmDeliveryManLogs['list'], 'orderId', 'orderId');
$ordersOrderCommons=Common::intergrateOneToOne($ordersOrderCommons, $orderCommons, 'orderId', 'orderId');
$orderMerge = \Our\Common::intergrateOneToMany($ordersOrderCommons, $orderGoods, 'orderId', 'orderId', 'orderGoods','addTime');
$orderMerge = \Our\Common::intergrateOneToMany($ordersOrderCommons, $orderGoods, 'orderId', 'orderId', 'orderGoods');
$orderConvert=$orderDao->convertOrder($orders,'orderId');
foreach ($orderMerge as &$value) {
$value['orderStateName'] = $orderDao->getStatusText($value);
......@@ -411,7 +416,7 @@ class ShopkeeperServiceModel extends \Business\AbstractModel
public function getOrders($memberId, $pageIndex, $pageSize, $orderState, $keyword)
{
$order = array('add_time' => 'desc');
$order = array('update_time' => 'desc');
$orderDao=\DAO\Order\OrderModel::getInstance();
$storeId = $this->_getStoreByMemberId($memberId);
if (empty($storeId)) {
......@@ -445,7 +450,7 @@ class ShopkeeperServiceModel extends \Business\AbstractModel
// 'gmt_update'=>'asc'
// );
$order=array(
'add_time'=>'desc'
'update_time'=>'desc'
);
// $where .= ' and han_order.shipping_type=' . ApiConst::bySeller;
$where=$orderDao->getWaitDeliveryCondition($storeId);
......@@ -653,51 +658,80 @@ class ShopkeeperServiceModel extends \Business\AbstractModel
}
return $results;
}
public function insertStoreMemberStaticsDistinct($distincts){
$orderDao = \DAO\Order\OrderModel::getInstance();
$orderGoodDao = \DAO\Order\OrderGoodsModel::getInstance(DbNameConst::salveDBConnectName);
$reufndReturnDao = \DAO\Order\RefundReturnModel::getInstance(DbNameConst::masterDBConnectName);
$storeMemberStatisticDao = \DAO\StoreMemberStatisticsModel::getInstance(DbNameConst::masterDBConnectName);
$storeStatisticsDao=\DAO\StoreStatisticsModel::getInstance(DbNameConst::masterDBConnectName);
$storeDao=\DAO\StoreModel::getInstance();
$memberFavoritesStoreMemberStatisticsDao=\DAO\Store\MemberFavoritesStoreStoreMemberStatisticsModel::getInstance(DbNameConst::masterDBConnectName);
foreach($distincts as $order){
$storeDao->deleteStoreTotalCount($order['storeId']);
// $orderDao->deleteOrderCache($order['buyerId'], $order['orderId'], $order['storeId'], true, true);
$storeMemberStatisticsData['storeId']=$order['storeId'];
$storeMemberStatisticsData['buyerId']=$order['buyerId'];
$orderRes=$orderDao->getSumAmountCountByMemberIdAndStoreId($storeMemberStatisticsData['storeId'],$storeMemberStatisticsData['buyerId']);
$storeMemberStatisticsData['orderTotal']=$orderRes['orderTotal']?$orderRes['orderTotal']:ApiConst::zero;
$orderGoodsRes=$orderGoodDao->getOrderGoodsCountBuyStoreIdAndMemberId( $storeMemberStatisticsData['storeId'],$storeMemberStatisticsData['buyerId']);
$orderGoodsCount=$orderGoodsRes['orderGoodsCount']?$orderGoodsRes['orderGoodsCount']:ApiConst::zero;
$storeMemberStatisticsData['orderGoodsCount']=$orderGoodsCount;
$storeMemberStatisticsData['addTime']=TIMESTAMP;
$res=$reufndReturnDao->getSumRefundAmountByMemberIdAndStoreId($order['storeId'],$order['buyerId']);
$refundAmount=$res['refundAmount']?$res['refundAmount']:'';
$storeMemberStatisticsData['orderTotal']=$storeMemberStatisticsData['orderTotal']-$refundAmount;
try{
$storeMemberStatisticDao->addOrUpdate($storeMemberStatisticsData);
}catch(\Exception $ex){
echo $ex->getMessage().json_encode($storeMemberStatisticsData)."\r\n";
}
//插入 han_store_statistics
$orderCountObj=$orderDao->getOrderCountByStoreId($order['storeId']);
$storeStatisticsData['orderCount']=$orderCountObj['orderCount']?$orderCountObj['orderCount']:ApiConst::zero;
$orderRes=$orderDao->getSumAmountCountByMemberIdAndStoreId($storeMemberStatisticsData['storeId']);
$orderTotal= $orderRes['orderTotal']?$orderRes['orderTotal']:ApiConst::zero;
$res=$reufndReturnDao->getSumRefundAmountByMemberIdAndStoreId($order['storeId']);
$refundAmount=$res['refundAmount']?$res['refundAmount']:'';
$storeStatisticsData['orderTotal']=$orderTotal-$refundAmount;
$orderOnline=$orderDao->getOrderOrderTotalOnlineByStoreId($order['storeId']);
$storeStatisticsData['orderTotalOnline']=$orderOnline['orderTotalOnline']?$orderOnline['orderTotalOnline']:ApiConst::zero;
$favCount= $memberFavoritesStoreMemberStatisticsDao->getFavCountByStoreId($order['storeId']);
$storeStatisticsData['favCount']=$favCount['favCount']?$favCount['favCount']:ApiConst::zero;
$orderGoodsRes=$orderGoodDao->getOrderGoodsCountBuyStoreIdAndMemberId($storeMemberStatisticsData['storeId']);
$orderGoodsCount=$orderGoodsRes['orderGoodsCount']?$orderGoodsRes['orderGoodsCount']:ApiConst::zero;
$storeStatisticsData['goodsCount']=$orderGoodsCount;
$storeStatisticsData['storeId']=$order['storeId'];
try{
$storeStatisticsDao->addOrUpdate($storeStatisticsData);
}catch(\Exception $ex){
echo $ex->getMessage().json_encode($storeMemberStatisticsData)."\r\n";
}
}
}
//任务脚本原来的方法是下面那个
public function insertStoreMemberStatics()
{
$orderGoodDao = \DAO\Order\OrderGoodsModel::getInstance(DbNameConst::salveDBConnectName);
$orderDao = \DAO\Order\OrderModel::getInstance();
$storeMemberStatisticDao = \DAO\StoreMemberStatisticsModel::getInstance(DbNameConst::masterDBConnectName);
$reufndReturnDao = \DAO\Order\RefundReturnModel::getInstance(DbNameConst::masterDBConnectName);
$gmtCreate = file_get_contents($this->baseDir . PathConst::orderGoodsCreateTime);
$gmtCreate = $gmtCreate ? $gmtCreate : ApiConst::zero;
$beginTime = $gmtCreate;
$this->taskIndex = PageConst::taskPageBegin;
$this->taskSize = PageConst::taskPageSize;
do {
$storeMemberStatisticData = $orderGoodDao->getMemberStoreStaticsByCreateTime($beginTime, $this->taskIndex, $this->taskSize);
$storeMemberStatisticData = isset($storeMemberStatisticData['list']) ? $storeMemberStatisticData['list'] : false;
if ($storeMemberStatisticData) {
$storeMemberStatisticDatas = $orderDao->getMemberStoreStaticsByCreateTime($beginTime, $this->taskIndex, $this->taskSize);
$orders = isset($storeMemberStatisticDatas['list']) ? $storeMemberStatisticDatas['list'] : false;
$this->taskIndex++;
$storeId = array_column($storeMemberStatisticData, 'storeId');
$memberId = array_column($storeMemberStatisticData, 'buyerId');
$storeIds = array_unique($storeId);
$memberIds = array_unique($memberId);
$goodsNumCount = $orderGoodDao->getMemberStoreOrderGoodsCount($storeIds, $memberIds);
$ordersCount = $orderDao->getSumAmountCountByMemberAndStoreId($storeIds, $memberIds);
$refundLists = $reufndReturnDao->getRefundSuccessMoneyByStoreIdAndMemberId($storeIds, $memberIds);
if (!empty($ordersCount) && !empty($refundLists)) {
foreach ($ordersCount as &$order) {
foreach ($refundLists as $refund) {
if ($order['buyerId'] == $refund['buyerId'] && $order['storeId'] == $refund['storeId']) {
$order['orderTotal'] = $order['orderTotal'] - $refund['refundTotal'];
}
}
}
}
if (!empty($goodsNumCount)) {
$storeMemberStatisticDao->addAll($goodsNumCount, 'orderGoodsCount');
if ($orders) {
$distincts=array();
foreach($orders as $order){
$key=$order['storeId'].'+'.$order['buyerId'];
$distincts[$key]=$order;
}
if (!empty($ordersCount)) {
$storeMemberStatisticDao->addAll($ordersCount, 'orderTotal');
$this->insertStoreMemberStaticsDistinct($distincts);
}
}
} while ($storeMemberStatisticData);
} while ($orders);
file_put_contents($this->baseDir . PathConst::orderGoodsCreateTime, TIMESTAMP);
}
//任务脚本原来的方法是下面那个
// public function insertStoreMemberStatics()
......@@ -898,38 +932,66 @@ class ShopkeeperServiceModel extends \Business\AbstractModel
}
}
//任务脚本
public function reduceStoreMemberStatics()
{
$refundReturnDao = \DAO\Order\RefundReturnModel::getInstance(DbNameConst::salveDBConnectName);
$storeMemberStatisticDao = \DAO\StoreMemberStatisticsModel::getInstance(DbNameConst::masterDBConnectName);
$orderGoodsDao = \DAO\Order\OrderGoodsModel::getInstance(DbNameConst::masterDBConnectName);
$orderDao = \DAO\Order\OrderModel::getInstance(DbNameConst::masterDBConnectName);
// $storeMemberStatisticDao = \DAO\StoreMemberStatisticsModel::getInstance(DbNameConst::masterDBConnectName);
// $orderGoodsDao = \DAO\Order\OrderGoodsModel::getInstance(DbNameConst::masterDBConnectName);
// $orderDao = \DAO\Order\OrderModel::getInstance(DbNameConst::masterDBConnectName);
$gmtUpdate = file_get_contents($this->baseDir . PathConst::refundRetrunGmtUpdate);
$gmtUpdate = $gmtUpdate ? $gmtUpdate : ApiConst::zero;
$this->taskIndex = PageConst::taskPageBegin;
$this->taskSize = PageConst::taskPageSize;
do {
$storeMemberStatisticData = $refundReturnDao->getMemberStoreStaticsByGmtUpdate($gmtUpdate, $this->taskIndex, $this->taskSize);
$storeMemberStatisticData = isset($storeMemberStatisticData['list']) ? $storeMemberStatisticData['list'] : false;
if (!empty($storeMemberStatisticData)) {
foreach ($storeMemberStatisticData as $item) {
$orderDao->deleteOrderCache($item['buyerId'], $item['orderId'], $item['storeId'], true, true);
}
$orderIds = array_column($storeMemberStatisticData, 'orderId');
foreach ($orderIds as $orderId) {
$res = $orderGoodsDao->find(array('order_id' => $orderId, 'refund_id' => ApiConst::zero));
if (empty($res)) {
$orderDao->update(array('order_id' => $orderId), array('order_state' => ApiConst::orderStateClose));
}
$refundReturns = $refundReturnDao->getMemberStoreStaticsByGmtUpdate($gmtUpdate, $this->taskIndex, $this->taskSize);
$this->taskIndex++;
$refundReturns = isset($refundReturns['list']) ? $refundReturns['list'] : false;
$reduceDatasDistinct=array();
if (!empty($refundReturns)) {
foreach ($refundReturns as $refundReturn) {
$key=$refundReturn['storeId'].'+'.$refundReturn['buyerId'];
$reduceDatasDistinct[$key]=$refundReturn;
}
}
$this->taskIndex++;
} while ($storeMemberStatisticData);
$this->insertStoreMemberStaticsDistinct($reduceDatasDistinct);
} while ($refundReturns);
//$storeMemberStatisticDao->addAllReduce($refundReturns);
file_put_contents($this->baseDir . PathConst::refundRetrunGmtUpdate, TIMESTAMP);
}
// //任务脚本
// public function reduceStoreMemberStatics()
// {
// $refundReturnDao = \DAO\Order\RefundReturnModel::getInstance(DbNameConst::salveDBConnectName);
// $storeMemberStatisticDao = \DAO\StoreMemberStatisticsModel::getInstance(DbNameConst::masterDBConnectName);
// $orderGoodsDao = \DAO\Order\OrderGoodsModel::getInstance(DbNameConst::masterDBConnectName);
// $orderDao = \DAO\Order\OrderModel::getInstance(DbNameConst::masterDBConnectName);
// $gmtUpdate = file_get_contents($this->baseDir . PathConst::refundRetrunGmtUpdate);
// $gmtUpdate = $gmtUpdate ? $gmtUpdate : ApiConst::zero;
// $this->taskIndex = PageConst::taskPageBegin;
// $this->taskSize = PageConst::taskPageSize;
// do {
// $storeMemberStatisticData = $refundReturnDao->getMemberStoreStaticsByGmtUpdate($gmtUpdate, $this->taskIndex, $this->taskSize);
// $storeMemberStatisticData = isset($storeMemberStatisticData['list']) ? $storeMemberStatisticData['list'] : false;
// if (!empty($storeMemberStatisticData)) {
// foreach ($storeMemberStatisticData as $item) {
// $orderDao->deleteOrderCache($item['buyerId'], $item['orderId'], $item['storeId'], true, true);
// }
// $orderIds = array_column($storeMemberStatisticData, 'orderId');
// foreach ($orderIds as $orderId) {
// $res = $orderGoodsDao->find(array('order_id' => $orderId, 'refund_id' => ApiConst::zero));
// if (empty($res)) {
// $orderDao->update(array('order_id' => $orderId), array('order_state' => ApiConst::orderStateClose));
// }
// }
// }
// $this->taskIndex++;
// } while ($storeMemberStatisticData);
// file_put_contents($this->baseDir . PathConst::refundRetrunGmtUpdate, TIMESTAMP);
//
// }
//店铺订单统计任务脚本
public function storeStatictisTask()
......
......@@ -419,10 +419,11 @@ class OrderModel extends \DAO\AbstractModel
return [];
}
}
public function getMemberStoreStaticsByCreateTime($gmtCreate,$pageIndex,$pageSize){
$this->setDb($this->dbName);
$where =\Our\Common::format(' gmt_update>={0} and gmt_update<{1} and order_state={2}',$gmtCreate,TIMESTAMP,ApiConst::orderStateWaitRecieve);
$res=$this->lists($where,array('gmt_update'=>'asc'),$this->sumField,$pageIndex,$pageSize);
$where =\Our\Common::format(' gmt_update>={0} and gmt_update<{1}',$gmtCreate,TIMESTAMP);
$res=$this->lists($where,array('gmt_update'=>'asc'),$this->getOrderDetailField(),$pageIndex,$pageSize);
return $res['list']?$res:false;
}
public function getSumAmountCountByMemberAndStoreId($storeIds,$memberIds)
......@@ -438,6 +439,62 @@ class OrderModel extends \DAO\AbstractModel
$res=$this->db->from($this->_tableName)->where($where)->select(" buyer_id as buyerId,store_id as storeId,(SUM(order_amount)) AS orderTotal")->group('buyer_id')->group('store_id')->fetchAll();
return $res;
}
public function getSumAmountCountByMemberIdAndStoreId($storeId,$memberId=false)
{
$this->setDb($this->dbName);
$where['store_id']=$storeId;
if($memberId){
$where['buyer_id']=$memberId;
}
$where['order_state']=array('notin',ArrayConst::orderCloseAndCancel);
if(is_array($where)){
$where = $this->db->getSqlWhereByArray($where);
}
$res=$this->db->from($this->_tableName)->where($where)->select(" buyer_id as buyerId,store_id as storeId,(SUM(order_amount)) AS orderTotal")->fetchOne();
return $res?$res:array();
}
public function getOrderCountByStoreId($storeId,$today=false){
$this->setDb($this->dbName);
$where['store_id']=$storeId;
$where['order_state']=array('notin',ArrayConst::orderCloseAndCancel);
$where['refund_state']=array('neq',ApiConst::refundStateAll);
if($today){
$todayTimeSpan=Common::getTodayBeginTimpSpan();
$where['gmt_update']=array('egt', $todayTimeSpan);
$where['gmt_update']=array('elt', TIMESTAMP);
}
if(is_array($where)){
$where = $this->db->getSqlWhereByArray($where);
}
$res=$this->db->from($this->_tableName)->where($where)->select(" buyer_id as buyerId,store_id as storeId,(count(*)) AS orderCount")->fetchOne();
return $res?$res:array();
}
public function deleteGetOrderOrderTotalOnlineByStoreIdCache($storeId){
\Our\RedisHelper::delCachedFunction(\Redis\Db6\StoreRedisModel::getInstance(), array(&$this, 'getOrderOrderTotalOnlineByStoreId'), array(), array($storeId));
}
public function getOrderOrderTotalOnlineByStoreId($storeId,$today=false){
$this->setDb($this->dbName);
$where['store_id']=$storeId;
$where['order_state']=array('notin',ArrayConst::orderCloseAndCancel);
$where['refund_state']=array('neq',ApiConst::refundStateAll);
$where['payment_type']=array('in',ArrayConst::payTypeOnlines);
if($today){
$todayBegin=Common::getTodayBeginTimpSpan();
$where['gmt_update']=array('egt',$todayBegin);
$where['gmt_update']=array('elt',TIMESTAMP);
}
if(is_array($where)){
$where= $this->db->getSqlWhereByArray($where);
}
$res=$this->db->from($this->_tableName)->where($where)->select(" buyer_id as buyerId,store_id as storeId,(order_amount-refund_amount) as orderTotalOnline")->fetchOne();
return $res?$res:array();
}
//待收货获取订单状态信息
public function getOrderStatusExtent($order)
......
......@@ -246,22 +246,42 @@ class OrderGoodsModel extends \DAO\AbstractModel {
}
public function getMemberStoreOrderGoodsCount($storeIds,$memberIds){
$this->setDb($this->dbName);
$orderDao=\DAO\Order\OrderModel::getInstance(DbNameConst::salveDBConnectName);
$whereOrder['store_id']=array('in',$storeIds);
$whereOrder['buyer_id']=array('in',$memberIds);
$whereOrder['order_state']=array('in',ArrayConst::orderCloseAndCancel);
$orderIds=$orderDao->getFieldByWhere($whereOrder,'order_id');
$where['store_id']=array('in',$storeIds);
$where['buyer_id']=array('in',$memberIds);
$where['is_refund']=array('neq',ApiConst::refundSuccess);
if($orderIds){
$where['order_id']=array('notin',$orderIds);
}
$where=$this->db->getSqlWhereByArray($where);
$res=$this->db->from($this->_tableName)->select($this->sumGoodsNum)->where($where)->group("buyer_id")->group("store_id")->fetchAll();
return $res;
}
public function getOrderGoodsCountBuyStoreIdAndMemberId($storeId,$memberId=false){
$this->setDb($this->dbName);
if($memberId){
$selectSql=Common::format("select {0} from {1} where store_id={2} and buyer_id={3} and is_refund<>{4} and order_id in (select order_id from han_order where store_id={2} and buyer_id={3} and order_state not in({5}) ) ",$this->sumGoodsNum,$this->_tableName,$storeId,$memberId,ApiConst::refundSuccess,"0,-1");
}else{
$selectSql=Common::format("select {0} from {1} where store_id={2} and is_refund<>{4} and order_id in (select order_id from han_order where store_id={2} and order_state not in({5}) ) ",$this->sumGoodsNum,$this->_tableName,$storeId,$memberId,ApiConst::refundSuccess,"0,-1");
}
$res=$this->db->from($this->_tableName)->query($selectSql);
return $res->one?$res->one:array();
}
// public function getMemberStoreOrderGoodsCount($storeIds,$memberIds){
// $this->setDb($this->dbName);
// $orderDao=\DAO\Order\OrderModel::getInstance(DbNameConst::salveDBConnectName);
// $whereOrder['store_id']=array('in',$storeIds);
// $whereOrder['buyer_id']=array('in',$memberIds);
// $whereOrder['order_state']=array('in',ArrayConst::orderCloseAndCancel);
// $orderIds=$orderDao->getFieldByWhere($whereOrder,'order_id');
// $where['store_id']=array('in',$storeIds);
// $where['buyer_id']=array('in',$memberIds);
// $where['is_refund']=array('neq',ApiConst::refundSuccess);
// if($orderIds){
// $where['order_id']=array('notin',$orderIds);
// }
// $where=$this->db->getSqlWhereByArray($where);
// $res=$this->db->from($this->_tableName)->select($this->sumGoodsNum)->where($where)->group("buyer_id")->group("store_id")->fetchAll();
// return $res;
//
// }
public function getMemberStoreOrderGoodsCountBak($storeIds,$memberIds){
$this->setDb($this->dbName);
$orderDao=\DAO\Order\OrderModel::getInstance(DbNameConst::salveDBConnectName);
......
......@@ -68,6 +68,20 @@ class RefundReturnModel extends \DAO\AbstractModel
}
// public function getRefundSuccessMoneyByStoreIdAndMemberId($storeId, $buyerId)
// {
// $this->setDb($this->dbName);
// if (is_array($storeId)) {
// $storeId = implode(',', $storeId);
// }
// if (is_array($buyerId)) {
// $buyerId = implode(',', $buyerId);
// }
// $where = \Our\Common::format(" store_id in({0}) and buyer_id in({1}) and is_suc_refund={2}", $storeId, $buyerId, ApiConst::refundSuccess);
// $res = $this->db->from($this->_tableName)->where($where)->select(" buyer_id as buyerId,store_id as storeId,(SUM(refund_amount)) AS refundTotal")->group('buyer_id')->group('store_id')->fetchAll();
// return !empty($res) ? $res : [];
//
// }
public function getRefundSuccessMoneyByStoreIdAndMemberId($storeId, $buyerId)
{
$this->setDb($this->dbName);
......@@ -78,7 +92,7 @@ class RefundReturnModel extends \DAO\AbstractModel
$buyerId = implode(',', $buyerId);
}
$where = \Our\Common::format(" store_id in({0}) and buyer_id in({1}) and is_suc_refund={2}", $storeId, $buyerId, ApiConst::refundSuccess);
$res = $this->db->from($this->_tableName)->where($where)->select(" buyer_id as buyerId,store_id as storeId,(SUM(refund_amount)) AS refundTotal")->group('buyer_id')->group('store_id')->fetchAll();
$res = $this->db->from($this->_tableName)->where($where)->select(" buyer_id as buyerId,store_id as storeId,(SUM(refund_amount)) AS refundTotal,")->group('buyer_id')->group('store_id')->fetchAll();
return !empty($res) ? $res : [];
}
......@@ -662,7 +676,7 @@ class RefundReturnModel extends \DAO\AbstractModel
public function getMemberStoreStaticsByGmtUpdate($gmtUpdate, $pageIndex, $pageSize)
{
$this->setDb($this->dbName);
$where = \Our\Common::format(' gmt_update>={0} and gmt_update<{1} and refund_state={2}', $gmtUpdate, TIMESTAMP, ApiConst::refundStateComplete);
$where = \Our\Common::format(' gmt_update>={0} and gmt_update<{1} and is_suc_refund={2}', $gmtUpdate, TIMESTAMP, ApiConst::refundSuccess);
$res = $this->lists($where, array('gmt_update' => 'asc'), $this->sumField, $pageIndex, $pageSize);
return $res['list'] ? $res : false;
}
......@@ -698,7 +712,18 @@ class RefundReturnModel extends \DAO\AbstractModel
return self::$_instance;
}
public function getSumRefundAmountByMemberIdAndStoreId($storeId,$memberId=false)
{
$this->setDb($this->dbName);
$where['store_id']=$storeId;
$where['buyer_id']=$memberId;
$where['is_suc_refund']=ApiConst::refundSuccess;
if(is_array($where)){
$where = $this->db->getSqlWhereByArray($where);
}
$res=$this->db->from($this->_tableName)->where($where)->select(" buyer_id as buyerId,store_id as storeId,(SUM(refund_amount)) AS refundAmount")->fetchOne();
return $res?$res:array();
}
/**
* @param $storeId
* @param $orderState
......
......@@ -295,6 +295,18 @@ class StoreModel extends \DAO\AbstractModel
}
}
public function deleteStoreTotalCount($storeId){
$favoritesStoreDao = \DAO\FavoritesStoreModel::getInstance();
$orderDao=\DAO\Order\OrderModel::getInstance();
$storeStatisticsDao=\DAO\StoreStatisticsModel::getInstance();
$favoritesStoreDao->deleteGetFavoritesCountByStoreId($storeId);
$memberFavoritesStoreStoreMemberStatisticsDao = \DAO\Store\MemberFavoritesStoreStoreMemberStatisticsModel::getInstance();
$memberFavoritesStoreStoreMemberStatisticsDao->deleteGetGoodsCountOrderTotalByStoreIdCache($storeId);
$orderDao->deleteGetOrderOrderTotalOnlineByStoreIdCache($storeId);
$storeStatisticsDao->deleteGetByStoreIdCache($storeId);
}
public function getStoresByCityCode($cityCode, $field = 'store_id,store_longitude,store_latitude,max_sign_rang,max_sales_rang,store_sales_scope')
{
$storeClassCondition = " store_citycode = '" . $cityCode . "' ";
......
<?php
namespace DAO\Store;
use Our\ApiConst;
use Our\Common;
use Redis\Db6\StoreRedisModel;
/**
* 店铺数据统计
* @date 2018-5-14
* @author csw
*/
class MemberFavoritesStoreStoreMemberStatisticsModel extends \DAO\AbstractModel {
class MemberFavoritesStoreStoreMemberStatisticsModel extends \DAO\AbstractModel
{
protected $redis;
......@@ -20,9 +23,9 @@ class MemberFavoritesStoreStoreMemberStatisticsModel extends \DAO\AbstractModel
* @var string
*/
protected $_tableName = 'han_member-favorites_store-store_member_statistics';
public $sumField='sum(order_total) as orderTotal,sum(order_goods_count) as orderGoodsCount';
public $sumField = 'sum(order_total) as orderTotal,sum(order_goods_count) as orderGoodsCount';
public $field="fav_type as favType,member_id as memberId,member_mobile as memberMobile,is_backlist as isBacklist,fav_time as favTime,member_avatar as memberAvatar,member_name as memberName,order_total as orderTotal,order_goods_count as orderGoodsCount";
public $field = "fav_type as favType,member_id as memberId,member_mobile as memberMobile,is_backlist as isBacklist,fav_time as favTime,member_avatar as memberAvatar,member_name as memberName,order_total as orderTotal,order_goods_count as orderGoodsCount";
/**
* 主键
*
......@@ -30,67 +33,86 @@ class MemberFavoritesStoreStoreMemberStatisticsModel extends \DAO\AbstractModel
*/
protected $_primaryKey = 'id';
public function init(){
public function init()
{
$this->setDb();
}
/**
* 获取店铺统计信息
* @param $where
* @return array
*/
public function find($where) {
public function find($where)
{
$this->setDb($this->dbName);
$field = $this->_getColumns();
$data=$this->db->select($field)->from($this->_tableName)->where($where)->fetchOne();
$data = $this->db->select($field)->from($this->_tableName)->where($where)->fetchOne();
return $data;
}
public function getById($id){
$where['id']=$id;
$res=$this->find($where);
public function getById($id)
{
$where['id'] = $id;
$res = $this->find($where);
return $res;
}
public function getSortBySortType($sortType){
$order=array("fav_time"=>'asc');
switch($sortType){
case ApiConst::favTimeAsc: $order=array("fav_time"=>'asc');break;
case ApiConst::favTimeDesc: $order=array("fav_time"=>'desc');break;
case ApiConst::orderTotalAsc: $order=array("order_total"=>'asc');break;
case ApiConst::orderTotalDesc: $order=array("order_total"=>'desc');break;
default:break;
public function getSortBySortType($sortType)
{
$order = array("fav_time" => 'asc');
switch ($sortType) {
case ApiConst::favTimeAsc:
$order = array("fav_time" => 'asc');
break;
case ApiConst::favTimeDesc:
$order = array("fav_time" => 'desc');
break;
case ApiConst::orderTotalAsc:
$order = array("order_total" => 'asc');
break;
case ApiConst::orderTotalDesc:
$order = array("order_total" => 'desc');
break;
default:
break;
}
return $order;
}
public function getList($storeId, $pageIndex, $pageSize, $sort, $keyword=''){
public function getList($storeId, $pageIndex, $pageSize, $sort, $keyword = '')
{
$this->setDb($this->dbName);
$whereStr=" store_id=".$storeId;
if(!empty($keyword)){
$whereStr.=Common::format(" and(member_name like '%{0}%' or member_mobile like '%{0}%') ",$keyword);
}
$result=$this->lists($whereStr, $sort, $this->field, $pageIndex, $pageSize);
if(!empty($result['list'])){
$result['list']=$this->getListNotNull($result['list']);
foreach($result['list'] as $key=>$val){
if($val['favType']==ApiConst::two){
$result['list'][$key]['isBacklist']=ApiConst::one;
}else{
$result['list'][$key]['isBacklist']=ApiConst::zero;
$whereStr = " store_id=" . $storeId;
if (!empty($keyword)) {
$whereStr .= Common::format(" and(member_name like '%{0}%' or member_mobile like '%{0}%') ", $keyword);
}
$result = $this->lists($whereStr, $sort, $this->field, $pageIndex, $pageSize);
if (!empty($result['list'])) {
$result['list'] = $this->getListNotNull($result['list']);
foreach ($result['list'] as $key => $val) {
if ($val['favType'] == ApiConst::two) {
$result['list'][$key]['isBacklist'] = ApiConst::one;
} else {
$result['list'][$key]['isBacklist'] = ApiConst::zero;
}
// $result['list'][$key]['isBacklist']=$val['isBacklist']?$val['isBacklist']:ApiConst::zero;
$result['list'][$key]['orderTotal']=$val['orderTotal']?$val['orderTotal']:ApiConst::zero;
$result['list'][$key]['orderGoodsCount']=$val['orderGoodsCount']?$val['orderGoodsCount']:ApiConst::zero;
$result['list'][$key]['orderTotal'] = $val['orderTotal'] ? $val['orderTotal'] : ApiConst::zero;
$result['list'][$key]['orderGoodsCount'] = $val['orderGoodsCount'] ? $val['orderGoodsCount'] : ApiConst::zero;
}
}
return $result;
}
/**
* 更新数据
* @param $data
* @param $where
* @return mixed
*/
public function update($data,$where){
public function update($data, $where)
{
return $this->db->update($this->_tableName)->where($where)->rows($data)->execute();
}
......@@ -99,7 +121,8 @@ class MemberFavoritesStoreStoreMemberStatisticsModel extends \DAO\AbstractModel
* @param $data
* @return mixed
*/
public function insert($data){
public function insert($data)
{
return $this->db->insert($this->_tableName)->rows($data)->execute();
}
......@@ -107,29 +130,32 @@ class MemberFavoritesStoreStoreMemberStatisticsModel extends \DAO\AbstractModel
* @param $storeId 店铺id
* @param $field 更新栏目
* @param $value 增加值
* @param $type,'INC':增加,'DEC':减少
* @param $type ,'INC':增加,'DEC':减少
*/
public function updateStoreStatisticsToday($storeId,$field,$value,$type='INC'){
$h = 'todayData'.date('Ymd');
public function updateStoreStatisticsToday($storeId, $field, $value, $type = 'INC')
{
$h = 'todayData' . date('Ymd');
$key = $storeId;
$this->redis = StoreRedisModel::getInstance();
$data = $this->redis->tableHGet($h,$key);
$data[$field] = $type=='INC' ? $data[$field] + $value : $data[$field] - $value;
StoreRedisModel::tableHSet($h,$storeId,$data,ApiConst::oneDaySecond);
$data = $this->redis->tableHGet($h, $key);
$data[$field] = $type == 'INC' ? $data[$field] + $value : $data[$field] - $value;
StoreRedisModel::tableHSet($h, $storeId, $data, ApiConst::oneDaySecond);
}
public function getInfoById($id,$field='*',$isField=false){
public function getInfoById($id, $field = '*', $isField = false)
{
$this->setDb();
$where[$this->_primaryKey]=$id;
$store=$this->db->from($this->_tableName)->select($field)->where($where)->fetchOne();
if($isField){
$where[$this->_primaryKey] = $id;
$store = $this->db->from($this->_tableName)->select($field)->where($where)->fetchOne();
if ($isField) {
return $store[$isField];
}else{
} else {
return $store;
}
}
public function getInfoByMemberId($memberId,$field='*',$isField=false)
public function getInfoByMemberId($memberId, $field = '*', $isField = false)
{
$this->setDb($this->dbName);
$where['member_id'] = $memberId;
......@@ -140,15 +166,29 @@ class MemberFavoritesStoreStoreMemberStatisticsModel extends \DAO\AbstractModel
return $store;
}
}
public function getGoodsCountOrderTotalByStoreId($storeId){
public function getGoodsCountOrderTotalByStoreId($storeId)
{
$this->setDb($this->dbName);
$where['store_id']=$storeId;
$res=$this->db->from($this->_tableName)->select($this->sumField)->where($where)->fetchOne();
return $res?$res:[];
$where['store_id'] = $storeId;
$res = $this->db->from($this->_tableName)->select($this->sumField)->where($where)->fetchOne();
return $res ? $res : [];
}
public function deleteCacheGetGoodsCountOrderTotalByStoreId($storeId){
return \Our\RedisHelper::delCachedFunction(\Redis\Db6\StoreRedisModel::getInstance(), array(&$this, 'getGoodsCountOrderTotalByStoreId'), array(),array($storeId));
public function deleteCacheGetGoodsCountOrderTotalByStoreId($storeId)
{
return \Our\RedisHelper::delCachedFunction(\Redis\Db6\StoreRedisModel::getInstance(), array(&$this, 'getGoodsCountOrderTotalByStoreId'), array(), array($storeId));
}
public function getFavCountByStoreId($storeId)
{
$this->setDb($this->dbName);
$where['store_id'] = $storeId;
$res = $this->db->from($this->_tableName)->select("store_id,count(*) as favCount")->where($where)->fetchOne();
return $res ? $res : [];
}
/**
* 类实例
*
......@@ -156,12 +196,18 @@ class MemberFavoritesStoreStoreMemberStatisticsModel extends \DAO\AbstractModel
*/
private static $_instance = null;
public function deleteGetGoodsCountOrderTotalByStoreIdCache($storeId)
{
\Our\RedisHelper::delCachedFunction(\Redis\Db6\StoreRedisModel::getInstance(), array(&$this, 'getGoodsCountOrderTotalByStoreId'), array(), array($storeId));
}
/**
* 获取类实例
*
* @return \DAO\UserModel
*/
public static function getInstance() {
public static function getInstance()
{
if (!(self::$_instance instanceof self)) {
self::$_instance = new self();
}
......@@ -173,7 +219,8 @@ class MemberFavoritesStoreStoreMemberStatisticsModel extends \DAO\AbstractModel
* 获取字段
* @return array
*/
private function _getColumns() {
private function _getColumns()
{
return array(
'store_id as storeId',
'order_count as orderCount',
......
......@@ -40,9 +40,10 @@ class StoreMemberStatisticsModel extends \DAO\AbstractModel {
* @return array
*/
public function find($where) {
$this->setDb();
$this->setDb($this->dbName);
$field='*';
$data=$this->db->select($field)->from($this->_tableName)->where($where)->fetchOne();
echo $this->db->getLastSql();exit;
return $data;
}
public function getField(){
......@@ -55,18 +56,15 @@ class StoreMemberStatisticsModel extends \DAO\AbstractModel {
* @return mixed
*/
public function update($data,$where){
$this->setDb();
$this->setDb(DbNameConst::masterDBConnectName);
return $this->db->update($this->_tableName)->where($where)->rows($data)->execute();
}
/**
* 插入数据
* @param $data
* @return mixed
*/
public function insert($data){
$this->setDb(DbNameConst::masterDBConnectName);
return $this->db->insert($this->_tableName)->rows($data)->execute();
}
/**
* 排序,1:关注时间降序,2:关注时间升序,3:购买力降序,4:购买力升序,默认1
* @param $data
......@@ -169,6 +167,19 @@ class StoreMemberStatisticsModel extends \DAO\AbstractModel {
return $result;
}
//插入数据大量
public function addOrUpdate($data)
{
$this->setDb(DbNameConst::masterDBConnectName);
$error = 0;
$baseSql = "insert into {$this->_tableName}({$this->insertField}) values";
$addSql = \Our\Common::format("({0},{1},{2},{3},{4}) ", $data['storeId'], $data['buyerId'],$data['orderGoodsCount'], $data['orderTotal'],TIMESTAMP);
$extentSql=" ON DUPLICATE KEY UPDATE order_goods_count=values(order_goods_count),order_total=values(order_total),add_time=".TIMESTAMP;
$excuteSql=$baseSql.$addSql.$extentSql;
$one = $this->db->insert($this->_tableName)->query($excuteSql);
return $one;
}
//插入数据大量
public function addAll($datas,$field="orderGoodsCount")
{
......
......@@ -43,6 +43,15 @@ class StoreStatisticsModel extends \DAO\AbstractModel {
return $data;
}
public function deleteGetByStoreIdCache($storeId){
\Our\RedisHelper::delCachedFunction(\Redis\Db6\StoreRedisModel::getInstance(), array(&$this, 'getByStoreId'), array(), array($storeId));
}
public function getByStoreId($storeId){
$where['store_id']=$storeId;
$res=$this->find($where);
return $res?$res:array();
}
/**
* 更新数据
* @param $data
......@@ -141,7 +150,19 @@ class StoreStatisticsModel extends \DAO\AbstractModel {
* @var \DAO\UserModel
*/
private static $_instance = null;
//插入数据大量
public $insertFields="store_id,order_count,order_total,order_total_online,fav_count,goods_count,add_time";
public function addOrUpdate($data)
{
$this->setDb(DbNameConst::masterDBConnectName);
$baseSql = "insert into {$this->_tableName}({$this->insertFields}) values";
$addSql = \Our\Common::format("({0},{1},{2},{3},{4},{5},{6}) ", $data['storeId'],$data['orderCount'], $data['orderTotal'],$data['orderTotalOnline'], $data['favCount'], $data['goodsCount'],TIMESTAMP);
$extentSql=" ON DUPLICATE KEY UPDATE order_count=values(order_count),order_total=values(order_total),order_total_online=values(order_total_online),fav_count=values(fav_count),goods_count=values(goods_count),add_time=".TIMESTAMP;
$excuteSql=$baseSql.$addSql.$extentSql;
$one = $this->db->insert($this->_tableName)->query($excuteSql);
return $one;
}
/**
* 获取类实例
*
......@@ -166,6 +187,7 @@ class StoreStatisticsModel extends \DAO\AbstractModel {
'order_total as orderTotal',
'fav_count as favCount',
'goods_count as goodsCount',
'order_total_online as orderTotalOnline',
);
}
......
......@@ -48,7 +48,7 @@ class cliOrderClose extends basecli
$redis->auth($conf['password']);
}
$clientPush=\JPush\ClientPush::getInstance();
$clientPush->pushTest(array());exit;
$clientPush->pushTest(array());
$memberCenterServiceDao=\Business\User\MemberCenterServiceModel::getInstance();
//$messageService=\DAO\MessageHistoryModel::getInstance();
while($pushData=$redis->rPop('push_center')){
......
......@@ -70,15 +70,15 @@ class cliShopkeeperIndex extends basecli
$shopkeeperService = \Business\Store\ShopkeeperServiceModel::getInstance();
$shopkeeperService->baseDir= \Our\Common::getConfig('out.config');
try {
// $shopkeeperService->insertStoreMemberStatics();
$shopkeeperService->insertStoreMemberStatics();
//退货退款订单自动关闭
$shopkeeperService->reduceStoreMemberStatics();
//$shopkeeperService->storeStatictisTask();
$shopkeeperService->updateLastId();
// $shopkeeperService->storeStatictisTask();
// $shopkeeperService->updateLastId();
} catch (Exception $ex) {
throw new Exception($ex->getCode() . '|' . $ex->getMessage());
}
echo '店铺统计数据插入成功' .date('Y-m-d H:i:s',TIMESTAMP). "\r\n";
echo 'store static insert success' .date('Y-m-d H:i:s',TIMESTAMP). "\r\n";
}
}
......
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