Commit c7cdefaa authored by christ's avatar christ

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

parents 9eff9888 6d88eae2
......@@ -29,15 +29,63 @@ class StoreServiceModel extends \Business\AbstractModel{
$beginTime = $beginTime ? $beginTime : ApiConst::zero;
$endTime = TIMESTAMP;
$where = 'store_id in (select ss.store_id from han_stat_store ss) and store_id in (select se.store_id from han_store_extend se where se.gmt_update > '.$beginTime.' ) and store_id in (select qs.store_id from han_qm_store_class qs where qs.gmt_update > '.$beginTime.' or (qs.deadline>'.$beginTime.' and qs.deadline<='.$endTime.'))';
$field = 'store_id,store_state,store_time,store_end_time,province_id,city_id,area_id,(select se.cashed_deposit from han_store_extend se where se.store_id=han_store.store_id) cashed_deposit,if((store_state=1 and store_end_time>=0), ifnull((select sum(qs.service_fee) from han_qm_store_class qs where qs.is_charged<>0 and qs.class_style=2 and qs.store_id=han_store.store_id), 0), ifnull((select sum(qs.service_fee) from han_qm_store_class qs where qs.is_charged<>0 and qs.class_style=2 and qs.store_id=han_store.store_id and qs.deadline>=0), 0)) service_fee';
$result = true;
$storeDao = \DAO\StoreModel::getInstance();
$statDao = \DAO\StatStoreModel::getInstance(DbNameConst::masterDBConnectName);
// $store_tmp = array();
if($datas = $storeDao->getStores($where, $field)) { //更新报表
echo 'in:'.count($datas);
//更新店铺基础数据
$where = 'store_id in (select ss.store_id from han_stat_store ss) and store_id in (select se.store_id from han_store_extend se where se.gmt_update > '.$beginTime.' )';
$field = 'store_id,store_state,store_time,store_end_time,province_id,city_id,area_id,(select se.cashed_deposit from han_store_extend se where se.store_id=han_store.store_id) cashed_deposit';
if($datas = $storeDao->getStores($where, $field)) {
echo 'extend in:'.count($datas);
foreach ($datas as $key=>$val) {
$update_data = $val;
$update_data['upd_time'] = $endTime;
unset($update_data['store_id']);
$where = 'store_id='.$val['store_id'];
if(!$statDao->update($where, $update_data)){
$result = false;
}
}
}
//更新店铺经营分类数据
$where = 'store_id in (select ss.store_id from han_stat_store ss) and store_id in (select qs.store_id from han_qm_store_class qs where qs.gmt_update > '.$beginTime.' or (qs.deadline>'.$beginTime.' and qs.deadline<='.$endTime.'))';
$field = 'store_id, (select count(qs.store_id) from han_qm_store_class qs where qs.is_charged<>0 and qs.store_id=han_store.store_id) class_style1_count, (select count(qs.store_id) from han_qm_store_class qs where qs.is_charged<>0 and qs.class_style=2 and qs.store_id=han_store.store_id) class_style2_count, if((store_state=1 and store_end_time>=0), ifnull((select sum(qs.service_fee) from han_qm_store_class qs where qs.is_charged<>0 and qs.class_style=2 and qs.store_id=han_store.store_id), 0), ifnull((select sum(qs.service_fee) from han_qm_store_class qs where qs.is_charged<>0 and qs.class_style=2 and qs.store_id=han_store.store_id and qs.deadline>=0), 0)) service_fee';
if($datas = $storeDao->getStores($where, $field)) {
echo 'class in:'.count($datas);
foreach ($datas as $key=>$val) {
$update_data = $val;
$update_data['upd_time'] = $endTime;
unset($update_data['store_id']);
$where = 'store_id='.$val['store_id'];
if(!$statDao->update($where, $update_data)){
$result = false;
}
}
}
//更新店铺关注信息
$where = 'store_id in (select ss.store_id from han_stat_store ss) and store_id in (select fs.store_id from han_favorites_store fs where fs.fav_time > '.$beginTime.')';
$field = 'store_id,(select count(fs.store_id) from han_favorites_store fs where fs.fav_type=1 and fs.store_id=han_store.store_id) fav_total,(select count(fs.store_id) from han_favorites_store fs where fs.fav_type=1 and fs.fav_from=3 and fs.store_id=han_store.store_id) fav3_total';
if($datas = $storeDao->getStores($where, $field)) {
echo 'favorite in:'.count($datas);
foreach ($datas as $key=>$val) {
$update_data = $val;
$update_data['upd_time'] = $endTime;
unset($update_data['store_id']);
$where = 'store_id='.$val['store_id'];
if(!$statDao->update($where, $update_data)){
$result = false;
}
}
}
//更新店铺有效订单信息
$where = 'store_id in (select ss.store_id from han_stat_store ss) and store_id in (select ss.store_id from han_store_statistics ss where ss.add_time > '.$beginTime.')';
$field = 'store_id,(select t.order_count from han_store_statistics t where t.store_id=han_store.store_id limit 1) order_count,(select t.order_total from han_store_statistics t where t.store_id=han_store.store_id limit 1) order_total';
if($datas = $storeDao->getStores($where, $field)) {
echo 'statistics in:'.count($datas);
foreach ($datas as $key=>$val) {
$update_data = $val;
$update_data['upd_time'] = $endTime;
......@@ -49,12 +97,74 @@ class StoreServiceModel extends \Business\AbstractModel{
}
}
//更新店铺订单超时信息
$where = 'store_id in (select ss.store_id from han_stat_store ss) and store_id in (select o.store_id from han_order o where o.gmt_update > '.$beginTime.')';
$field = 'store_id,(select count(*) from han_order o where o.store_id=han_store.store_id) all_order_count,(select count(*) from han_order o where o.is_effective=1 and o.store_id=han_store.store_id) expire_order_count';
if($datas = $storeDao->getStores($where, $field)) {
echo 'statistics in:'.count($datas);
foreach ($datas as $key=>$val) {
$update_data = $val;
$update_date['expire_order_percent'] = intval($val['expire_order_count']/$val['all_order_count']*100);
$update_data['upd_time'] = $endTime;
unset($update_data['all_order_count']);
unset($update_data['store_id']);
$where = 'store_id='.$val['store_id'];
if(!$statDao->update($where, $update_data)){
$result = false;
}
}
}
//更新店铺退货退款信息
$where = 'store_id in (select ss.store_id from han_stat_store ss) and store_id in (select rr.store_id from han_refund_return rr where rr.gmt_update > '.$beginTime.')';
$field = 'store_id,(select count(distinct t.order_id) from han_refund_return t where t.store_id=han_store.store_id and t.seller_state!=3) refund_order_count,(select sum(t.refund_amount) from han_refund_return t where t.seller_state!=3 and t.store_id=han_store.store_id) refund_order_total';
if($datas = $storeDao->getStores($where, $field)) {
echo 'refund in:'.count($datas);
foreach ($datas as $key=>$val) {
$update_data = $val;
$update_data['upd_time'] = $endTime;
unset($update_data['store_id']);
$where = 'store_id='.$val['store_id'];
if(!$statDao->update($where, $update_data)){
$result = false;
}
}
}
//更新店铺举报信息
$where = 'store_id in (select ss.store_id from han_stat_store ss) and store_id in (select t.seller_id from han_report t where t.report_time > '.$beginTime.')';
$field = 'store_id,(select count(*) from han_report t where t.seller_id=han_store.store_id) report_count';
if($datas = $storeDao->getStores($where, $field)) {
echo 'favorite in:'.count($datas);
foreach ($datas as $key=>$val) {
$update_data = $val;
$update_data['upd_time'] = $endTime;
unset($update_data['store_id']);
$where = 'store_id='.$val['store_id'];
if(!$statDao->update($where, $update_data)){
$result = false;
}
}
}
//处理新店铺信息
$where = 'store_id not in (select ss.store_id from han_stat_store ss)';
$field = 'store_id,store_state,store_time,store_end_time,province_id,city_id,area_id,(select se.cashed_deposit from han_store_extend se where se.store_id=han_store.store_id) cashed_deposit';
$field .= ',(select count(qs.store_id) from han_qm_store_class qs where qs.is_charged<>0 and qs.store_id=han_store.store_id) class_style1_count, (select count(qs.store_id) from han_qm_store_class qs where qs.is_charged<>0 and qs.class_style=2 and qs.store_id=han_store.store_id) class_style2_count, if((store_state=1 and store_end_time>=0), ifnull((select sum(qs.service_fee) from han_qm_store_class qs where qs.is_charged<>0 and qs.class_style=2 and qs.store_id=han_store.store_id), 0), ifnull((select sum(qs.service_fee) from han_qm_store_class qs where qs.is_charged<>0 and qs.class_style=2 and qs.store_id=han_store.store_id and qs.deadline>=0), 0)) service_fee';
$field .= ',(select count(fs.store_id) from han_favorites_store fs where fs.fav_type=1 and fs.store_id=han_store.store_id) fav_total,(select count(fs.store_id) from han_favorites_store fs where fs.fav_type=1 and fs.fav_from=3 and fs.store_id=han_store.store_id) fav3_total';
$field .= ',(select t.order_count from han_store_statistics t where t.store_id=han_store.store_id limit 1) order_count,(select t.order_total from han_store_statistics t where t.store_id=han_store.store_id limit 1) order_total';
$field .= ',(select count(*) from han_order o where o.store_id=han_store.store_id) all_order_count,(select count(*) from han_order o where o.is_effective=1 and o.store_id=han_store.store_id) expire_order_count';
$field .= ',(select count(distinct t.order_id) from han_refund_return t where t.store_id=han_store.store_id and t.seller_state!=3) refund_order_count,(select sum(t.refund_amount) from han_refund_return t where t.seller_state!=3 and t.store_id=han_store.store_id) refund_order_total';
$field .= ',(select count(*) from han_report t where t.seller_id=han_store.store_id) report_count';
if($datas = $storeDao->getStores($where, $field)) { //插入报表
echo 'not in:'.count($datas);
foreach ($datas as $key=>$val) {
$insert_data = $val;
$insert_data['expire_order_percent'] = $val['all_order_count'] ? intval
($val['expire_order_count']/$val['all_order_count']*100) : 0;
$insert_data['upd_time'] = $endTime;
unset($insert_data['all_order_count']);
if(!$statDao->insert($insert_data)){
echo 'insert fail'.var_export($val, true)."\n";
......
......@@ -7,13 +7,13 @@ error_reporting(E_ALL ^ E_NOTICE);
/**
* 店铺数据统计
* 执行时间:每分钟执行一次
* Class cliStoreStoreStat
* Class cliStoreStat
* User: King <358887571@qq.com>
* Date: 2018/11/30 0030
* Time: 下午 3:00
*
*/
class cliStoreStoreStat extends basecli
class cliStoreStat extends basecli
{
const CLI_ADMIN_ID = 255;
private $bDoUnLock = FALSE; // 是否允许释放 LOCK 文件
......@@ -97,7 +97,7 @@ class cliStoreStoreStat extends basecli
}
}
$oCli = new cliStoreStoreStat(TRUE);
$oCli = new cliStoreStat(TRUE);
EXIT;
?>
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