Commit 7739913a authored by christ's avatar christ

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

parents 15dcb131 b3c00e76
......@@ -47,6 +47,8 @@ class PathConst {
const authInfoOtherLogin="/authInfo/otherLogin";
const orderCloseWaitRecieveOrder="/orderCloseWaitRecieveOrder.conf";
const goodsStatTime="/goodsStat.conf";
const goodsSellStatTime="/goodsSellStat.conf";
const orderCancelTime="/orderCancelTime.conf";
......@@ -55,4 +57,4 @@ class PathConst {
//const favoritesStoreFavTimeConf="favoritesStoreFavTime.conf";
}
\ No newline at end of file
}
......@@ -277,6 +277,135 @@ class GoodsCommonServiceModel extends \Business\AbstractModel
}
return array($where,$order,$attrStr,$saleSort);
}
public $baseDir = '';
/**
* 更新商品报表列表
* @param $where 查询条件 已统计或未统计
* @return array
* @throws \Exception
* User: King <358887571@qq.com>
* Date: 2018/11/27 0027
* Time: 下午 3:37
*/
public function updateStatGoods(){
$beginTime = file_get_contents($this->baseDir . \Our\PathConst::goodsStatTime, TIMESTAMP);
$beginTime = $beginTime ? $beginTime : ApiConst::zero;
$endTime = TIMESTAMP;
$where = 'goods_edittime > '.$beginTime.' and goods_edittime<=' . $endTime . ' and goods_id in (select sg.goods_id from han_stat_goods sg)';
$field = 'goods_id,is_del,goods_name,goods_storage,goods_price,store_id';
$result = true;
$goodsDao = \DAO\GoodsModel::getInstance();
$storeDao = \DAO\StoreModel::getInstance();
$statGoodsDao = \DAO\StatGoodsModel::getInstance(DbNameConst::masterDBConnectName);
$store_tmp = array();
if($datas = $goodsDao->getList($where, $field)) { //更新商品报表
echo 'in:'.count($datas);
foreach ($datas as $key=>$val) {
if(isset($store_tmp[$val['store_id']])) {
$store_info = $store_tmp[$val['store_id']];
} else {
$store_info = $storeDao->getFieldsInfo(array('store_id'=>$val['store_id']), 'province_id, city_id, area_id');
}
$update_stat_goods = $val;
$update_stat_goods['upd_time'] = $endTime;
$update_stat_goods['province_id'] = $store_info['province_id'];
$update_stat_goods['city_id'] = $store_info['city_id'];
$update_stat_goods['area_id'] = $store_info['area_id'];
unset($update_stat_goods['goods_id']);
$where = 'goods_id='.$val['goods_id']. ' and upd_time <'.$beginTime;
if(!$statGoodsDao->update($where, $update_stat_goods)){
$result = false;
}
}
}
$where = 'goods_id not in (select sg.goods_id from han_stat_goods sg)';
if($datas = $goodsDao->getList($where, $field)) { //插入高品报表
echo 'not in:'.count($datas);
foreach ($datas as $key=>$val) {
if(isset($store_tmp[$val['store_id']])) {
$store_info = $store_tmp[$val['store_id']];
} else {
$store_info = $storeDao->getFieldsInfo(array('store_id'=>$val['store_id']), 'province_id, city_id, area_id');
}
$insert_stat_goods = $val;
$insert_stat_goods['upd_time'] = $endTime;
$insert_stat_goods['province_id'] = intval($store_info['province_id']);
$insert_stat_goods['city_id'] = intval($store_info['city_id']);
$insert_stat_goods['area_id'] = intval($store_info['area_id']);
if(!$statGoodsDao->insert($insert_stat_goods)){
echo 'insert fail'.$val['goods_id']."\n";
$result = false;
}
}
}
if($result) { //商品报表更新成功
file_put_contents($this->baseDir . \Our\PathConst::goodsStatTime, $endTime);
}
return $result;
}
/**
* 更新商品报表销售记录
* User: King <358887571@qq.com>
* Date: 2018/11/27 0027
* Time: 下午 6:19
*/
public function updateStatGoodsSell(){
file_put_contents($this->baseDir . \Our\PathConst::goodsSellStatTime, '');
$beginTime = file_get_contents($this->baseDir . \Our\PathConst::goodsSellStatTime, TIMESTAMP);
$beginTime = $beginTime ? $beginTime : ApiConst::zero;
$endTime = TIMESTAMP;
$orderGoodsDao = \DAO\Order\OrderGoodsModel::getInstance(DbNameConst::masterDBConnectName);
$statGoodsDao = \DAO\StatGoodsModel::getInstance(DbNameConst::masterDBConnectName);
$where = 'order_id in (select o.order_id from han_order o where o.payment_time > '.$beginTime . ') and goods_id in (select sg.goods_id from han_stat_goods sg)';
$field = 'goods_id,goods_num,goods_pay_price';
$result = true;
if($list = $orderGoodsDao->getOrderGoodsList($where, $field)) {
$statGoodsDao->setDb(DbNameConst::masterDBConnectName);
$statGoodsDao->db->doTransaction();
foreach ($list as $key=>$val){
$where = array('goods_id'=>$val['goods_id']);
$data = array('sell_upd_time'=>$endTime);
$setData = array(
array('field'=>'goods_sell_num', 'value'=>'+'.$val['goods_num']),
array('field'=>'goods_sell_amount', 'value'=>'+'.$val['goods_pay_price']),
);
// var_dump($setData);
//$sql = 'update han_stat_goods set goods_sell_num=goods_sell_num +'.$val['goods_num']. ',
//goods_sell_amount =goods_sell_amount +'.$val['goods_pay_price'].',sell_upd_time=' . $endTime . ' where goods_id='.$val['goods_id'];
$statGoodsDao = \DAO\StatGoodsModel::getInstance(DbNameConst::masterDBConnectName);
if(!$statGoodsDao->update($where, $data, $setData)){
var_dump($setData);
var_dump($data);
echo 'execute fail.'.$val['goods_id']."\n";
$result = false;
$statGoodsDao->db->doRollback();
return $result;
} else {
echo 'execute succ.'.$val['goods_id']."\n";
}
}
if(!$result) {
$statGoodsDao->db->doRollback();
}
}
if($result) { //商品报表更新成功
$statGoodsDao->db->doCommit();
file_put_contents($this->baseDir . \Our\PathConst::goodsSellStatTime, $endTime);
}
}
/**
* 获取商品列表
* @param $param
......
......@@ -36,8 +36,11 @@ class StoreServiceModel extends \Business\AbstractModel{
if($param['sid']) {
$sale = \DAO\SaleModel::getInstance()->getOne(array('sale_id'=>$param['sid']),'sale_act_id,member_id');
if($sale) {
\DAO\SaleMemberModel::getInstance()->insertOrUpdate(array('sale_id'=>$sale['member_id'],'sale_act_id'=>$sale['sale_act_id'],'member_id'=>$memberId,'store_id'=>$storeId));
\Redis\Db4\SaleActivityRedisModel::getInstance()->tableDel('storeId:'.$storeId);
$sale_act = \DAO\SaleActivityModel::getInstance()->getOne(array('sale_act_id'=>$sale['sale_act_id'],'sale_act_state'=>1));
if($sale_act && $sale_act['sale_start_date'] >= time() && $sale_act['sale_end_date'] <= time()){
\DAO\SaleMemberModel::getInstance()->insertOrUpdate(array('sale_id'=>$sale['member_id'],'sale_act_id'=>$sale['sale_act_id'],'member_id'=>$memberId,'store_id'=>$storeId));
\Redis\Db4\SaleActivityRedisModel::getInstance()->tableDel('storeId:'.$storeId);
}
}
}
$storeMembers = array();
......
......@@ -332,4 +332,4 @@ class CartModel extends \DAO\AbstractModel{
return self::$_instance;
}
}
\ No newline at end of file
}
<?php
namespace DAO;
use Our\ApiConst;
use Our\Common;
use Our\CommonExtension;
class StatGoodsModel extends \DAO\AbstractModel {
public $errorCode;
/**
* 表名
*
* @var string
*/
protected $_tableName = 'han_stat_goods';
private $cartGoodsField = 'goods_id,goods_storage,store_id,goods_commonid,goods_name,goods_image,goods_spec,snapshot_id';
/**
* 主键
*
* @var string
*/
protected $_primaryKey = '';
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;
}
}
......@@ -73,6 +73,25 @@ class StoreModel extends \DAO\AbstractModel
}
/**
*
* 获取指定字段店铺信息
*
* @param $where 查询条件
* @param $field 查询字段
* @return mixed 店铺信息
* User: King <358887571@qq.com>
* Date: 2018/11/27 0027
* Time: 下午 5:27
*/
public function getFieldsInfo($where, $field)
{
$this->setDb();
$store = $this->db->select($field)->from($this->_tableName)->where($where)->fetchOne();
return $store;
}
public function getInfoById($id, $field = '*', $isField = false)
{
$this->setDb($this->dbName);
......
......@@ -1001,4 +1001,4 @@ if ( ! function_exists('stripslashes_deep') ) {
function stripslashes_deep($value){
return is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value);
}
}
\ No newline at end of file
}
<?php
define("APPLICATION_PATH", realpath(dirname(__FILE__) . '/../../../')); //指向public的上一级
require APPLICATION_PATH . '/scripts/crontab/baseCli.php';
require APPLICATION_PATH . '/scripts/crontab/common.php';
error_reporting(E_ALL ^ E_NOTICE);
/**
* 商品分析
* 执行时间:每分钟执行一次
* Class cliGoodsStat
* User: linqin <358887571@qq.com>
* Date: 2018/11/27 0027
* Time: 下午 1:56
*
*/
class cliGoodsStat extends basecli
{
const CLI_ADMIN_ID = 255;
private $bDoUnLock = FALSE; // 是否允许释放 LOCK 文件
private $_debug = 0;
private $lockFileName;
private $fromState;
private function mkdirs($dir, $mode = 0777)
{
if (is_dir($dir) || @mkdir($dir, $mode)){
return TRUE;
}
if (!$this->mkdirs(dirname($dir), $mode)){
return FALSE;
}
return @mkdir($dir, $mode);
}
/**
* 析构
*/
public function __destruct()
{
parent::__destruct();
if ($this->bDoUnLock)
{
@unlink($this->lockFileName);
}
}
/**
* 自动统计商品
* User: linqin <358887571@qq.com>
* Date: 2018/11/27 0027
* Time: 下午 3:23
*/
protected function autoStatGoods(){
$goodsService = \Business\Goods\GoodsCommonServiceModel::getInstance(\Our\DbNameConst::masterDBConnectName);
$goodsService->baseDir = \Our\Common::getConfig('out.config');
echo "update goods \n";
if($goodsService->updateStatGoods()) { //更新商品基础信息
echo "update goods_sell \n";
$goodsService->updateStatGoodsSell();
}
}
protected function _runCli()
{
$this->_debug = isset($this->aArgv[1]) ? intval($this->aArgv[1]) : 0;
if ($this->_debug)
{
echo "*** Debug mode ***\n";
}
// Step: 02 检查是否已有相同CLI在运行中
$lockDir=$this->_getBaseFileName('goods');
if(!$this->mkdirs($lockDir)){
echo '****create dir fail ****';
exit;
}
$this->lockFileName = $lockDir .DS.'stat.locks';
if( file_exists( $this->lockFileName ) )
{
$stat = stat($this->lockFileName);
if( (TIMESTAMP - $stat['mtime']) > 1800 )
{
echo "文件被锁超过1800秒,被强制删除";
@unlink($this->lockFileName);
}
else
{
$this->halt( '[' . date('Y-m-d H:i:s') .'] The CLI is running'."\n");
}
}
$this->bDoUnLock = true;
if(APP_ENV =='pre' || APP_ENV=='product'){
file_put_contents($this->lockFileName ,"running" ); // CLI 独占锁
}
$this->autoStatGoods();
echo date('Y-m-d H:i:s',TIMESTAMP).'定单关闭消息成功'."\r\n";
}
}
$oCli = new cliGoodsStat(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