Commit 3432ea24 authored by zhz's avatar zhz

试用期店铺考核相关

parent 5e03cd2c
...@@ -43,7 +43,7 @@ class GoodsController extends \Our\Controller_AbstractIndex { ...@@ -43,7 +43,7 @@ class GoodsController extends \Our\Controller_AbstractIndex {
public function testAction(){ public function testAction(){
//$info = $this->goodsService->recommend(); //$info = $this->goodsService->recommend();
//\Business\Goods\GoodsCommonServiceModel::getInstance()->saleGoods(); //\Business\Goods\GoodsCommonServiceModel::getInstance()->saleGoods();
\Business\Store\StoreServiceModel::getInstance()->tryExpireInform(); \Business\Store\StoreServiceModel::getInstance()->drainageAmountStatistics();
} }
public function getAttrsAction(){ public function getAttrsAction(){
......
...@@ -212,6 +212,8 @@ class NameConst { ...@@ -212,6 +212,8 @@ class NameConst {
const changedPBundlingStoragePrefix = 'changedPBundlingStorage'; const changedPBundlingStoragePrefix = 'changedPBundlingStorage';
const changedGoodsStoragePrefix = 'changedGoodsStorage'; const changedGoodsStoragePrefix = 'changedGoodsStorage';
const tryStoreExamineFail = '试用期考核不合格';
} }
?> ?>
\ No newline at end of file
...@@ -43,6 +43,7 @@ class PathConst { ...@@ -43,6 +43,7 @@ class PathConst {
const orderWaitRecieveTaskAddTime="/orderWaitRecieveTaskAddTime.conf"; const orderWaitRecieveTaskAddTime="/orderWaitRecieveTaskAddTime.conf";
const orderConfirmTaskAddTime="/orderConfirmTaskAddTime.conf"; const orderConfirmTaskAddTime="/orderConfirmTaskAddTime.conf";
const saleOrderGoodsAddTime="/saleOrderGoodsAddTime.conf"; const saleOrderGoodsAddTime="/saleOrderGoodsAddTime.conf";
const drainageAmountAddTime="/drainageAmountAddTime.conf";
const orderId="orderId={0}"; const orderId="orderId={0}";
const authInfoOtherLogin="/authInfo/otherLogin"; const authInfoOtherLogin="/authInfo/otherLogin";
......
...@@ -1297,6 +1297,64 @@ class StoreServiceModel extends \Business\AbstractModel{ ...@@ -1297,6 +1297,64 @@ class StoreServiceModel extends \Business\AbstractModel{
} }
} }
} }
/**
* 试用期店铺引流人数统计
*/
public function drainageAmountStatistics() {
$orderDao = \DAO\Order\OrderGoodsModel::getInstance(\Our\DbNameConst::masterDBConnectName);
$pageBegin = \Our\PageConst::taskPageBegin;
$storeDao = \DAO\FavoritesStoreModel::getInstance();
$storeDrainageAmountDao = \DAO\Store\StoreDrainageAmountModel::getInstance();
while (true) {
// -\Our\ApiConst::oneDaySecond 防止试用期最后一天的引流人数没统计到
$stores = $storeDao->getStoreAndFavoriteStore('count(han_favorites_store.favid) AS amount,han_store.store_id,han_favorites_store.store_id AS storeId',array('store_end_time'=>array('gt',TIMESTAMP-\Our\ApiConst::oneDaySecond)),array(),array($pageBegin,500),'storeId','LEFT');
if(empty($stores)) {
break;
}
$storeDrainageAmountDao->insertAllOrUpdate($stores);
$pageBegin = ($pageBegin + 1) * 500;
}
}
/**
* 试用期的店铺考核
*/
public function tryStoreExamine() {
$storeDrainageAmountDao = \DAO\Store\StoreDrainageAmountModel::getInstance();
$storeClassPayLogDao = \DAO\Store\StoreClassPayLogModel::getInstance();
$pageBegin = \Our\PageConst::taskPageBegin;
while (true) {
$stores = $storeDrainageAmountDao->getStoreAndDrainageAmount(array('han_store.store_end_time'=>array('between',TIMESTAMP-\Our\ApiConst::oneDaySecond,TIMESTAMP),'han_store_drainage_amount.gmt_examine'=>0),'han_store_drainage_amount.*',array($pageBegin,1000));
if(empty($stores)) {
break;
}
foreach ($stores as $store) {
if($store['amount'] >= 400) {
//自动免费续费 当前签约分类租金2个月
}elseif ($store['amount'] >= 300) {
//自动免费续费 当前签约分类租金1个月
}elseif ($store['amount'] < 30) {
//查看是否有签约分类续费记录
$log = $storeClassPayLogDao->getStoreClassPayLog(array('store_id'=>$store['store_id'],'pay_state'=>1));
if(empty($log)) {
//店铺下架,下架理由为 试用期考核不合格 并且 发送短信
$this->storeClose($store['store_id'],\Our\NameConst::tryStoreExamineFail);
}
}
}
$pageBegin = ($pageBegin + 1) * 1000;
}
}
/**
* 店铺下架处理
* @param $storeId
* @param $reason 下架原因
*/
public function storeClose($storeId, $reason) {
}
/** /**
*/ */
private static $_instance = null; private static $_instance = null;
......
...@@ -58,20 +58,23 @@ class FavoritesStoreModel extends \DAO\AbstractModel { ...@@ -58,20 +58,23 @@ class FavoritesStoreModel extends \DAO\AbstractModel {
$result = $this->db->select($field)->from($this->_tableName)->where($where)->fetchOne(); $result = $this->db->select($field)->from($this->_tableName)->where($where)->fetchOne();
return $result; return $result;
} }
public function getStoreAndFavoriteStore($field,$where,$order = array('fav_time'=>'desc','favid'=>'desc'),$limit = null) { public function getStoreAndFavoriteStore($field,$where,$order = array('fav_time'=>'desc','favid'=>'desc'),$limit = null,$group = null,$type='inner') {
$this->setDb($this->dbName); $this->setDb($this->dbName);
if($order){ if($order){
foreach($order as $key=>$value){ foreach($order as $key=>$value){
$this->db->order($key,$value); $this->db->order($key,$value);
} }
} }
if($group) {
$this->db->group($group);
}
if($limit) { if($limit) {
$this->db->limit($limit[0],$limit[1]); $this->db->limit($limit[0],$limit[1]);
} }
if(is_array($where)){ if(is_array($where)){
$where=$this->db->getSqlWhereByArray($where); $where=$this->db->getSqlWhereByArray($where);
} }
$result = $this->db->select($field)->from($this->_tableName)->join('han_store','han_store.store_id = han_favorites_store.store_id','inner')->where($where)->fetchAll(); $result = $this->db->select($field)->from('han_store')->join($this->_tableName,'han_store.store_id = han_favorites_store.store_id',$type)->where($where)->fetchAll();
return $result; return $result;
} }
public function insert($param){ public function insert($param){
......
...@@ -263,11 +263,10 @@ class StoreModel extends \DAO\AbstractModel ...@@ -263,11 +263,10 @@ class StoreModel extends \DAO\AbstractModel
public function getStores($where, $field = "*", $limit = []) public function getStores($where, $field = "*", $limit = [])
{ {
$this->setDb(); $this->setDb();
if ($limit) { if($limit) {
$result = $this->db->select($field)->from($this->_tableName)->where($where)->limit($limit[0], $limit[1])->fetchAll(); $this->db->limit($limit[0], $limit[1]);
} else {
$result = $this->db->select($field)->from($this->_tableName)->where($where)->fetchAll();
} }
$result = $this->db->select($field)->from($this->_tableName)->where($where)->fetchAll();
return $result; return $result;
} }
...@@ -423,6 +422,10 @@ class StoreModel extends \DAO\AbstractModel ...@@ -423,6 +422,10 @@ class StoreModel extends \DAO\AbstractModel
return $storeInfo; return $storeInfo;
} }
public function delStoreInfoCache($storeId)
{
\Our\RedisHelper::delCachedFunction(\Redis\Db6\StoreRedisModel::getInstance(), array(&$this, 'getInfoById'), array($storeId), array($storeId));
}
/** /**
* 店铺分享图片 * 店铺分享图片
* *
...@@ -640,7 +643,7 @@ class StoreModel extends \DAO\AbstractModel ...@@ -640,7 +643,7 @@ class StoreModel extends \DAO\AbstractModel
*/ */
public function getTryExpireStore() { public function getTryExpireStore() {
$this->setDb($this->dbName); $this->setDb($this->dbName);
$sql = "SELECT store.store_id,store.store_end_time,store.store_phone,store.store_name FROM han_store store LEFT JOIN han_store_class_pay_log store_class_pay_log on store.store_id = store_class_pay_log.store_id where ((unix_timestamp(now())+9*24*3600) < store.store_end_time and store.store_end_time <= (unix_timestamp(now())+10*24*3600) ) or ((unix_timestamp(now())+2*24*3600) < store.store_end_time and store.store_end_time <= (unix_timestamp(now())+3*24*3600) ) or ((unix_timestamp(now())+4*24*3600) < store.store_end_time and store.store_end_time <= (unix_timestamp(now())+5*24*3600) ) and store_class_pay_log.id IS NULL"; $sql = "SELECT store.store_id,store.store_end_time,store.store_phone,store.store_name,max(pay_state) AS pay_state FROM han_store store LEFT JOIN han_store_class_pay_log store_class_pay_log on store.store_id = store_class_pay_log.store_id where ((unix_timestamp(now())+9*24*3600) < store.store_end_time and store.store_end_time <= (unix_timestamp(now())+10*24*3600) ) or ((unix_timestamp(now())+2*24*3600) < store.store_end_time and store.store_end_time <= (unix_timestamp(now())+3*24*3600) ) or ((unix_timestamp(now())+4*24*3600) < store.store_end_time and store.store_end_time <= (unix_timestamp(now())+5*24*3600) ) GROUP BY store.store_id HAVING pay_state IS NULL or pay_state = 0";
$query = $this->db->query($sql); $query = $this->db->query($sql);
return $query->rows; return $query->rows;
} }
......
<?php
namespace DAO\Store;
class StoreClassPayLogModel extends \DAO\AbstractModel
{
/**
* 表名
*
* @var string
*/
protected $_tableName = 'han_store_class_pay_log';
/**
* 主键
*
* @var string
*/
protected $_primaryKey = 'id';
public function init()
{
}
public function getStoreClassPayLog($where, $field = '*') {
$this->setDb($this->dbName);
return $this->db->select($field)->from($this->_tableName)->where($where)->fetchOne();
}
/**
* 类实例
*
* @var \DAO\UserModel
*/
private static $_instance = null;
/**
* 获取类实例
*
* @return \DAO\UserModel
*/
public static function getInstance($dbName = \Our\DbNameConst::salveDBConnectName)
{
if (!(self::$_instance instanceof self)) {
self::$_instance = new self($dbName);
}
return self::$_instance;
}
}
<?php
namespace DAO\Store;
class StoreDrainageAmountModel extends \DAO\AbstractModel
{
/**
* 表名
*
* @var string
*/
protected $_tableName = 'han_store_drainage_amount';
/**
* 主键
*
* @var string
*/
protected $_primaryKey = 'id';
public function init()
{
}
public function insertAllOrUpdate($datas)
{
$this->setDb(\Our\DbNameConst::masterDBConnectName);
$error = 0;
$baseSql = "insert into {$this->_tableName}(store_id,amount,gmt_create,gmt_update) values";
$insertAllSql = $baseSql;
for ($i = 0; $i < count($datas); $i++) {
$addSql = \Our\Common::format("({0},{1},{2},{3}),", $datas[$i]['store_id'], $datas[$i]['amount'], TIMESTAMP,TIMESTAMP);
$insertAllSql .= $addSql;
if ($i % 1000 == 0 && $i != 0) {
$insertAllSql = rtrim($insertAllSql, ',');
$insertAllSql .= 'ON DUPLICATE KEY UPDATE amount = VALUES(amount),gmt_update=VALUES(gmt_update)';
$one = $this->db->insert()->query($insertAllSql);
if ($one === false) {
$error++;
}
$insertAllSql = $baseSql;
}
}
if ($insertAllSql != $baseSql) {
$insertAllSql = rtrim($insertAllSql, ',');
$insertAllSql .= 'ON DUPLICATE KEY UPDATE amount = VALUES(amount),gmt_update=VALUES(gmt_update)';
$one = $this->db->insert($this->_tableName)->query($insertAllSql);
if ($one === false) {
$error++;
}
}
if ($error > 0) {
return false;
}
return true;
}
public function getStoreAndDrainageAmount($where, $field, $limit = null)
{
$this->setDb();
if($limit) {
$this->db->limit($limit[0],$limit[1]);
}
$result = $this->db->select($field)->from('han_store')->join($this->_tableName,'han_store.store_id = han_store_drainage_amount.store_id','inner')->where($where)->fetchAll();
return $result;
}
/**
* 类实例
*
* @var \DAO\UserModel
*/
private static $_instance = null;
/**
* 获取类实例
*
* @return \DAO\UserModel
*/
public static function getInstance()
{
if (!(self::$_instance instanceof self)) {
self::$_instance = new self();
}
return self::$_instance;
}
}
<?php
/**
* 引流人数统计
* 执行时间:每天0:00
*/
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 cliSaleOrder 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);
}
}
protected function drainageAmountStatistics(){
\Business\Store\StoreServiceModel::getInstance()->drainageAmountStatistics();
}
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('store');
if(!$this->mkdirs($lockDir)){
echo '****create dir fail ****';
exit;
}
$this->lockFileName = $lockDir .'/drainageAmountStatistics.locks';
if( file_exists( $this->lockFileName ) )
{
$stat = stat($this->lockFileName);
if( (TIMESTAMP - $stat['mtime']) > 3600 )
{
echo "文件被锁超过3600秒,被强制删除";
@unlink($this->lockFileName);
}
else
{
$this->halt( '[' . date('Y-m-d H:i:s') .'] The CLI is running'."\n");
}
}
$this->bDoUnLock = true;
file_put_contents($this->lockFileName ,"running" ); // CLI 独占锁
$this->drainageAmountStatistics();
echo '店铺引流人数统计完成'."\r\n";
}
}
$oCli = new cliSaleOrder(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