Commit b73048ac authored by zw's avatar zw

统计

parent 1f27bee3
...@@ -74,7 +74,7 @@ class AAgents extends BaseModel ...@@ -74,7 +74,7 @@ class AAgents extends BaseModel
*/ */
public function getListJoin($p = 1, $pageSize = 15, $order_ = 'id desc', $field = '', $join = '', $where = '') public function getListJoin($p = 1, $pageSize = 15, $order_ = 'id desc', $field = '', $join = '', $where = '')
{ {
return $this->field($field) $data = $this->field($field)
->alias('a') ->alias('a')
->join($join) ->join($join)
->where($where) ->where($where)
...@@ -82,6 +82,8 @@ class AAgents extends BaseModel ...@@ -82,6 +82,8 @@ class AAgents extends BaseModel
->limit($pageSize) ->limit($pageSize)
->page($p) ->page($p)
->select(); ->select();
//echo $this->getLastSql();
return $data;
} }
...@@ -190,13 +192,16 @@ class AAgents extends BaseModel ...@@ -190,13 +192,16 @@ class AAgents extends BaseModel
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException * @throws \think\exception\DbException
*/ */
public function verifyUser($field,$join,$params) public function verifyUser($field, $join, $params)
{ {
return $this->field($field)
$r = $this->field($field)
->alias('a') ->alias('a')
->join($join) ->join($join)
->where($params) ->where($params)
->find(); ->find();
//echo $this->getLastSql();
return $r;
} }
/** /**
...@@ -293,15 +298,66 @@ class AAgents extends BaseModel ...@@ -293,15 +298,66 @@ class AAgents extends BaseModel
return $result; return $result;
} }
public function saveList()
{
}
/** /**
* 批量获取经纪人 * 分页列表
* * @param int $p
* @param $params * @param int $pageSize
* @param string $order_
* @param string $field
* @param string $join
* @param string $where
* @return false|\PDOStatement|string|\think\Collection * @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException * @throws \think\exception\DbException
*/ */
public function getList($p = 1, $pageSize = 15, $order_ = 'id desc', $field = '', $join = '', $where = '')
{
$data = $this->field($field)
->alias('a')
->join($join)
->where($where)
->order($order_)
->limit($pageSize)
->page($p)
->select();
return $data;
}
/**
* 统计任务获取经纪人列表
* @param int $pageNo
* @param int $pageSize
* @param string $field
* @return false|\PDOStatement|string|\think\Collection
*/
public function getAgentsListByTask($pageNo = 1,$pageSize = 15,$field = "id"){
return Db::table($this->table)
->field("id")
->select();
}
/**
* 获取经纪人总数
* @return int|string
*/
public function getAgentsCountByTask(){
return Db::table($this->table)
->count();
}
/**
* 批量获取经纪人
* @param $params
* @return false|\PDOStatement|string|\think\Collection
*/
public function getAgentsByStoreId($params) public function getAgentsByStoreId($params)
{ {
$result = Db::table($this->table) $result = Db::table($this->table)
...@@ -312,7 +368,6 @@ class AAgents extends BaseModel ...@@ -312,7 +368,6 @@ class AAgents extends BaseModel
return $result; return $result;
} }
public function getAgentsInfoByAgentId($field, $params) public function getAgentsInfoByAgentId($field, $params)
{ {
$where_ = []; $where_ = [];
...@@ -329,28 +384,8 @@ class AAgents extends BaseModel ...@@ -329,28 +384,8 @@ class AAgents extends BaseModel
->where($where_) ->where($where_)
->select(); ->select();
return $result; return $result;
}
/**
* 检查是否有权限
*
* @param $id
* @param $agents_id
* @return array|false|\PDOStatement|string|\think\Model
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function agentsAuth($id, $agents_id) {
return $this->alias('a')
->field('b.id')
->join('auth_group b','a.auth_group_id=b.id','left')
->where("FIND_IN_SET({$id},b.rules)")
->where('a.id',$agents_id)
->where('b.status',0)
->find();
}
}
public function searchAgentsByKeyword($field, $params) public function searchAgentsByKeyword($field, $params)
{ {
...@@ -364,32 +399,4 @@ class AAgents extends BaseModel ...@@ -364,32 +399,4 @@ class AAgents extends BaseModel
return $result; return $result;
} }
/**
* 根据id获取单个字段值
*
* @param $id
* @param $fields
* @return mixed
*/
public function getAgentsById($id, $fields) {
return $this->where('id',$id)->value($fields);
}
/**
* @param $where
* @param $fields
* @return array|false|\PDOStatement|string|\think\Model
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getAgentsStoreById($where, $fields) {
return $this->alias('a')
->field($fields)
->join('a_store b','a.store_id=b.id','left')
->where($where)
->find();
}
} }
\ No newline at end of file
...@@ -394,7 +394,10 @@ class GHouses extends BaseModel ...@@ -394,7 +394,10 @@ class GHouses extends BaseModel
* 获取商铺详情 * 获取商铺详情
* @param $field * @param $field
* @param $params * @param $params
* @return mixed * @return array|false|\PDOStatement|string|\think\Model
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/ */
function getHouseDetail($field, $params) function getHouseDetail($field, $params)
{ {
......
<?php
namespace app\model;
use think\Db;
use think\Model;
/**
* Created by PhpStorm.
* User : zw
* Date : 2018/3/15
* Time : 下午2:00
* Intro:
*/
class TAgentTotalModel extends Model{
protected $table = "t_agent_total";
private $db_;
function __construct()
{
$this->db_ = Db::table($this->table);
}
/**
* @param $params
* @return int
*/
public function addTotal($params){
Db::startTrans();
try {
$this->db_->insertAll($params);
Db::commit();
return 1;
} catch (\Exception $e) {
Db::rollback();
return 0;
}
}
/**
* @param $field
* @param $param
* @return false|\PDOStatement|string|\think\Collection
*/
public function getTotalEndTimeByAgentId($field,$param){
return $this->db_
->field($field)
->where($param)
->order("total_time desc")
->limit(1)
->select();
}
}
\ No newline at end of file
...@@ -34,7 +34,7 @@ class Exclusive { ...@@ -34,7 +34,7 @@ class Exclusive {
if ($house_data) { if ($house_data) {
$insert = array(); $insert = array();
foreach ($house_data as $k => $v) { foreach ($house_data as $k => $v) {
if ((strtotime($v['exclusive_end'] . '23:59:59') > time()) && ($v['exclusive_end'] != NULL)) { if ((strtotime($v['exclusive_end'] . ' 23:59:59') > time()) && ($v['exclusive_end'] != NULL)) {
continue; continue;
} }
$insert[$k]['id'] = $v['id']; $insert[$k]['id'] = $v['id'];
......
<?php
namespace app\task\controller;
use app\model\AAgents;
use app\model\GHouses;
use app\model\TAgentTotalModel;
/**
* Created by PhpStorm.
* User : zw
* Date : 2018/3/15
* Time : 上午10:07
* Intro:
*/
class ResultsSummaryTask{
private $agentsModel;
private $tAgentTotalModel;
function __construct()
{
$this->agentsModel = new AAgents();
$this->tAgentTotalModel = new TAgentTotalModel();
}
public function totalAgentResults(){
//todo 1.分页查询经纪人, 2遍历执行,判断一个经纪人在统计表最后一条统计数据的日期
//TODO 3.日期加一天并判断是否大于等于当前时间大于return 4.执行此日期的统计,5.当次日期小于当前日期,递归日期加一。继续统计
$total = $this->agentsModel->getAgentsCountByTask();
$pageSize = 50;
$pageTotal = ceil($total / $pageSize);
for($pageNo = 1 ; $pageNo <= $pageTotal ; $pageNo++ ){
$resultArr = $this->agentsModel->getAgentsListByTask($pageNo,$pageSize,"id,store_id,district_id");
$this->executeTotal($resultArr);
}
}
private function executeTotal($resultArr){
foreach ($resultArr as $key=>$value){
$param["agent_id"] = $value["id"];
$param["is_del"] = 0;
$total_time_arr = $this->tAgentTotalModel->getTotalEndTimeByAgentId("total_time",$param);
$start_total_time = "2018-03-12";
$end_total_time = date("Y-m-d",strtotime("-1 day"));
if(count($total_time_arr) > 0){
$start_total_time = $total_time_arr[0]["total_time"];
}
$agent_id = empty($value["id"]) ? 0 : $value["id"];
$district_id = empty($value["district_id"]) ? 0 : $value["district_id"];
$store_id = empty($value["store_id"]) ? 0 : $value["store_id"];
//todo 查询时间段的数据
$this->selectTotal($agent_id,$start_total_time,$end_total_time);
$this->binAgentModel($agent_id,$district_id,$store_id);
}
}
private function selectTotal($agent_id,$start_total_time,$end_total_time){
//todo 如果查询出这个时间段都为0 则给此经纪人插入条最后一个日期的为空的数据
//房源
$houseSourceModel = new GHouses();
$params["agent_id"] = $agent_id;
$houseSourceModel->getAddHouseNumByAgentId();
}
private function binAgentModel($agent_id,$district_id,$store_id){
$param = [];
$param["district_id"] = 1;
$param["store_id"] = 1;
$param["agent_id"] = 1;
$param["total_time"] = 1;
$param["add_house_num"] = 1;
$param["add_user_num"] = 1;
$param["performance"] = 1;
$param["official_receipts"] = 1;
$param["look_at_num"] = 1;
$param["march_in_num"] = 1;
$param["paylog"] = 1;
$param["supervision_num"] = 1;
$param["create_time"] = 1;
$param["update_time"] = 1;
return $param;
}
}
\ 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