Commit 99f8d964 authored by zhuwei's avatar zhuwei

获取每月新增客户数

parent 0da62cea
...@@ -8,6 +8,7 @@ namespace app\index\controller; ...@@ -8,6 +8,7 @@ namespace app\index\controller;
* Date: 2019/9/17 * Date: 2019/9/17
* Time: 15:40:20 * Time: 15:40:20
*/ */
use app\extra\RedisExt;
use app\index\extend\Basic; use app\index\extend\Basic;
use app\model\GHouses; use app\model\GHouses;
use app\model\OBargainModel; use app\model\OBargainModel;
...@@ -23,6 +24,7 @@ class ClinchMap extends Basic ...@@ -23,6 +24,7 @@ class ClinchMap extends Basic
private $marchInModel; private $marchInModel;
private $bargainModel; private $bargainModel;
private $partialCommission; private $partialCommission;
private $redis_user_prefix;
public function __construct($request = null) public function __construct($request = null)
...@@ -34,6 +36,7 @@ class ClinchMap extends Basic ...@@ -34,6 +36,7 @@ class ClinchMap extends Basic
$this->bargainModel = new OBargainModel(); $this->bargainModel = new OBargainModel();
$this->partialCommission = new OPartialCommission(); $this->partialCommission = new OPartialCommission();
$this->redis_user_prefix = 'clinch_map_user_add_num_';//每月新增客户数 redis 前缀
} }
...@@ -59,6 +62,7 @@ class ClinchMap extends Basic ...@@ -59,6 +62,7 @@ class ClinchMap extends Basic
$result["performance_info"] = $this->getPerformanceInfo(); $result["performance_info"] = $this->getPerformanceInfo();
$result["user_month_info"] = $this->getUserInfo();
return $this->response(200, 'success', $result); return $this->response(200, 'success', $result);
} }
...@@ -77,13 +81,16 @@ class ClinchMap extends Basic ...@@ -77,13 +81,16 @@ class ClinchMap extends Basic
/** /**
* 客户总数 * 客户总数
* @param $params
* @return int * @return int
*/ */
public function getUserNum() public function getUserNum($params=[])
{ {
$conditions = []; $conditions = [ 'status' => 0 ];
$conditions['status'] = 0; if(isset($params['start_time']) && isset($params['end_time'])){
$addUserNum = $this->userModel->getAddUserNumForOperation($conditions); $conditions['create_time'] = array( 'between', array( $params['start_time'] . " 00:00:00", $params['end_time'] . " 23:59:59" ) );
}
$addUserNum = $this->userModel->getAddUserNumForOperation($conditions);
$user_num = isset($addUserNum[0]["num"]) ? $addUserNum[0]["num"] : 0; $user_num = isset($addUserNum[0]["num"]) ? $addUserNum[0]["num"] : 0;
return $user_num; return $user_num;
} }
...@@ -169,5 +176,41 @@ class ClinchMap extends Basic ...@@ -169,5 +176,41 @@ class ClinchMap extends Basic
return $time_arr; return $time_arr;
} }
/**
* 获取每月新增客户数
* @return array
*/
public function getUserInfo()
{
$time_arr = [date('Y-m', strtotime('-1 month'))=>['type'=>'1'],
date('Y-m', strtotime('-2 month'))=>['type'=>'2'],
date('Y-m', strtotime('-3 month'))=>['type'=>'3'],
date('Y-m', strtotime('-4 month'))=>['type'=>'4'],
date('Y-m', strtotime('-5 month'))=>['type'=>'5'],
date('Y-m', strtotime('-6 month'))=>['type'=>'6'],
date('Y-m', strtotime('-7 month'))=>['type'=>'7'],
date('Y-m', strtotime('-8 month'))=>['type'=>'8'],
date('Y-m', strtotime('-9 month'))=>['type'=>'9'],
date('Y-m', strtotime('-10 month'))=>['type'=>'10']];
$redis = RedisExt::getRedis();
foreach ($time_arr as $key => $v) {
if (!$redis->get($this->redis_user_prefix.$key)) {
//数据库查询
$last_num = $v['type'] - 1;
$params = [];
$params['start_time'] = date('Y-m-d', strtotime(date('Y-m-01') . "-{$v['type']} month"));// 计算出本月第一天再减一个月
$last_time = date('Y-m-d', strtotime(date('Y-m-01') . "-{$last_num} month"));//计算出本月
$params['end_time'] = date('Y-m-d', strtotime($last_time . ' -1 day'));//本月第一天再减一天
$month_user_num = $this->getUserNum($params);
$redis->set($this->redis_user_prefix.$key, $month_user_num); //商铺自动下架天数
} else {
$month_user_num = $redis->get($this->redis_user_prefix.$key);
}
$time_arr[$key]["user_num"] = $month_user_num;
}
return $time_arr;
}
} }
\ No newline at end of file
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