Commit d6de4340 authored by wwccw0591's avatar wwccw0591

upd

parent 44d1902a
......@@ -49,6 +49,7 @@ class PathConst {
const orderCloseWaitRecieveOrder="/orderCloseWaitRecieveOrder.conf";
const goodsStatTime="/goodsStat.conf";
const goodsSellStatTime="/goodsSellStat.conf";
const storeStatTime="/storeStat.conf";
const orderCancelTime="/orderCancelTime.conf";
......
......@@ -2,6 +2,7 @@
namespace Business\Store;
use Our\ApiConst;
use Our\DbNameConst;
/**
* 店铺service
......@@ -16,6 +17,58 @@ class StoreServiceModel extends \Business\AbstractModel{
}
/**
* 更新店铺分布数据
* @return bool
* User: King <358887571@qq.com>
* Date: 2018/11/30 0030
* Time: 下午 4:27
*/
public function updateStatStore(){
$beginTime = file_get_contents($this->baseDir . \Our\PathConst::storeStatTime, TIMESTAMP);
$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);
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)';
if($datas = $storeDao->getStores($where, $field)) { //插入报表
echo 'not in:'.count($datas);
foreach ($datas as $key=>$val) {
$insert_data = $val;
$insert_data['upd_time'] = $endTime;
if(!$statDao->insert($insert_data)){
echo 'insert fail'.var_export($val, true)."\n";
$result = false;
}
}
}
if($result) { //商品报表更新成功
file_put_contents($this->baseDir . \Our\PathConst::storeStatTime, $endTime);
}
return $result;
}
/**
* 获取店铺首页渲染信息
* add by zhz
......
......@@ -7,6 +7,15 @@ use Our\ApiConst;
use Our\Common;
use Our\CommonExtension;
/**
* 商品报表模型类
* Class StatGoodsModel
* @package DAO
* User: King <358887571@qq.com>
* Date: 2018/11/30 0030
* Time: 下午 5:30
*
*/
class StatGoodsModel extends \DAO\AbstractModel {
public $errorCode;
......@@ -25,7 +34,7 @@ class StatGoodsModel extends \DAO\AbstractModel {
*
* @var string
*/
protected $_primaryKey = '';
protected $_primaryKey = 'statg_id';
public function init(){
}
......
<?php
namespace DAO;
use Our\ApiConst;
use Our\Common;
use Our\CommonExtension;
/**
*店铺报表模型类
* Class StatStoreModel
* @package DAO
* User: King <358887571@qq.com>
* Date: 2018/11/30 0030
* Time: 下午 5:29
*
*/
class StatStoreModel extends \DAO\AbstractModel {
public $errorCode;
/**
* 表名
*
* @var string
*/
protected $_tableName = 'han_stat_store';
/**
* 主键
*
* @var string
*/
protected $_primaryKey = 'stats_id';
public function init(){
}
/**
*
* 分页获取商品列表
* @param $where
* @param $field
* @param $pageIndex
* @param $pageSize
* @param array $order
* @return array|mixed
*/
public function getListPage($where, $field, $pageIndex, $pageSize, $order = array('goods_id' => 'asc'))
{
$this->setDb($this->dbName);
if($datas = $this->lists($where, $order, $field, $pageIndex, $pageSize)) {
foreach ($datas['list'] as $key=>$val) {
$datas['list'][$key]['goodsAttr'] = $this->getFormatGoodsAttr($val['goodsAttr']);
}
}
return $datas ? $datas : array();
}
/**
* 根据条件更新
* @param $sql
* @return mixed
* User: King <358887571@qq.com>
* Date: 2018/11/27 0027
* Time: 下午 7:27
*/
public function updatBySql($sql) {
$this->setDb(\Our\DbNameConst::masterDBConnectName);
return $this->db->update($this->_tableName)->execute($sql);
}
/**
* 更新数据
* @param $data
* @param $where
* @return mixed
*/
public function update($where, $data, $setData = array())
{
$this->setDb(\Our\DbNameConst::masterDBConnectName);
$this->db->update($this->_tableName)->where($where)->rows($data);
foreach ($setData as $val) {
$this->db->set($val['field'], $val['value'], TRUE);
}
return $this->db->execute();
}
/**
* 插入数据
* @param $data
* @return mixed
* User: King <358887571@qq.com>
* Date: 2018/11/27 0027
* Time: 下午 5:51
*/
public function insert($data){
$this->setDb(\Our\DbNameConst::masterDBConnectName);
$result = $this->db->insert($this->_tableName)->rows($data)->execute();
return $result ;
}
public function getList($where,$field){
$this->setDb();
return $this->db->select($field)->from($this->_tableName)->where($where)->fetchAll();
}
public function find($where,$field = \Our\NameConst::allField){
$this->setDb($this->dbName);
$result = $this->db->select($field)->from($this->_tableName)->where($where)->fetchOne();
return $result;
}
/**
* 获取在线商品列表
* @param $where
* @param string $field
* @return mixed
*/
public function getOnlineList($where,$field = \Our\NameConst::allField){
$whereSql = ' goods_state ='.\Our\ApiConst::onlineGoodsState.' and goods_verify='.\Our\ApiConst::onlineGoodsVerify.' and is_del='.\Our\ApiConst::onlineGoodsDel;
if($where){
$whereSql .= ' and '.$where;
}
return $this->getList($whereSql,$field);
}
public function getOnlineOne($goodsId,$field= \Our\NameConst::allField){
$where['goods_state'] = \Our\ApiConst::onlineGoodsState;
$where['goods_verify'] = \Our\ApiConst::onlineGoodsVerify;
$where['is_del'] = \Our\ApiConst::onlineGoodsDel;
$where['goods_id'] = $goodsId;
$goods = \Our\RedisHelper::cachedFunction(\Redis\Db4\GoodsRedisModel::getInstance(),array(&$this, 'find'),array($where,$field),\Our\ApiConst::oneHour,array($goodsId));
return $goods;
}
/**
* 类实例
*/
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;
}
}
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