Commit 0c20cc60 authored by zw's avatar zw

业绩

parent 7080021a
......@@ -21,6 +21,13 @@ class Performance extends Basic{
$this->service_ = new PerformanceService();
}
/**
* 业绩列表
* @return \think\Response
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function selectPerformanceByTime(){
$params = $this->params;
$params = array(
......@@ -30,6 +37,19 @@ class Performance extends Basic{
if(!isset($params["agent_id"]) || !isset($params["type"])){
return $this->response("101","请求参数错误");
}
$this->service_->totalAgent($params["agent_id"],$params["type"]);
$yesterday = date("Y-m-d", strtotime("-1 day"));
$end_day = date("Y-m-d", strtotime("-7 day"));
$list = $this->service_->totalAgent($params["agent_id"],$params["type"],$yesterday,$end_day);
//dump($list);
if(count($list) > 0){
$result["list"] = $list;
$result["start_time"] = $yesterday;
$result["end_time"] = $end_day;
return $this->response("200","request success",$result);
}
}
}
......@@ -2,6 +2,7 @@
namespace app\api_broker\service;
use app\model\AAgents;
use app\model\TAgentTotalModel;
/**
......@@ -14,23 +15,104 @@ use app\model\TAgentTotalModel;
class PerformanceService
{
private $totalModel;
private $agentModel;
public function __construct()
{
$this->totalModel = new TAgentTotalModel();
$this->agentModel = new AAgents();
}
public function totalAgent($agent_id, $type)
/**
* @param $agent_id
* @param $type
* @param $yesterday
* @param $end_day
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function totalAgent($agent_id, $type, $yesterday, $end_day)
{
$agent_info = $this->getStoreAndDistrict($agent_id);
$where_ = [];
$yesterday = date("Y-m-d", strtotime("-1 day"));
$end_day = date("Y-m-d", strtotime("-7 day"));
$where_['total_time'] = array( 'between', array( $end_day ,$yesterday,) );
//$where_['agent_id'] = $agent_id;
$where_['total_time'] = array( 'between', array( $end_day, $yesterday, ) );
$result = $this->totalModel->getTotalByAgentId($where_, $type);
//dump($result);
$arr = [];
$field = "a.name,a.img,b.store_name,c.district_name";
foreach ($result as $key => $value) {
switch ($type) {
case 1:
if ($value["agent_id"] == $agent_info["id"] || $key < 5) {
$value["index_"] = $key + 1;
$value["is_my"] = $agent_info["id"];
$info = $this->agentModel->getAgentsInfoByAgentId($field,["agent_id"=>$value["agent_id"]]);
if(count($info) > 0){
$value["name"] = $info[0]["name"];
$value["img"] = AGENTHEADERIMGURL . $info[0]["img"];
$value["store_name"] = $info[0]["store_name"];
$value["district_name"] = $info[0]["district_name"];
}
array_push($arr, $value);
}
break;
case 2:
if ($value["store_id"] == $agent_info["store_id"] || $key < 5) {
$value["index_"] = $key + 1;
$value["is_my"] = $agent_info["store_id"];
$info = $this->agentModel->getAgentsInfoByAgentId($field,["agent_id"=>$value["agent_id"]]);
if(count($info) > 0){
$value["name"] = $info[0]["name"];
$value["img"] = AGENTHEADERIMGURL . $info[0]["img"];
$value["store_name"] = $info[0]["store_name"];
$value["district_name"] = $info[0]["district_name"];
}
array_push($arr, $value);
}
break;
case 3:
$value["index_"] = $key + 1;
$value["is_my"] = $agent_info["district_id"];
$info = $this->agentModel->getAgentsInfoByAgentId($field,["agent_id"=>$value["agent_id"]]);
if(count($info) > 0){
$value["name"] = $info[0]["name"];
$value["img"] = AGENTHEADERIMGURL . $info[0]["img"];
$value["store_name"] = $info[0]["store_name"];
$value["district_name"] = $info[0]["district_name"];
}
array_push($arr, $value);
break;
}
}
return $arr;
}
/**
* @param $agent_id
* @return mixed|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getStoreAndDistrict($agent_id)
{
$params["agent_id"] = $agent_id;
$agent_info = $this->agentModel->getAgentById("id,store_id,district_id,level", $params);
if (count($agent_info) > 0) {
return $agent_info[0];
}
return null;
$result = $this->totalModel->getTotalByAgentId($where_,$type);
dump($result);
}
}
\ No newline at end of file
......@@ -364,7 +364,7 @@ class AAgents extends BaseModel
->field("id")
->where($params)
->select();
echo Db::table($this->table)->getLastSql();
//echo Db::table($this->table)->getLastSql();
return $result;
}
......@@ -374,6 +374,14 @@ class AAgents extends BaseModel
if (isset($params["agent_id"])) {
$where_["a.id"] = $params["agent_id"];
}
if (isset($params["store_id"])) {
$where_["b.id"] = $params["store_id"];
$where_["a.level"] = array("in","20,40");
}
if (isset($params["district_id"])) {
$where_["c.id"] = $params["district_id"];
$where_["a.level"] = array("in","30,40");
}
$where_["a.status"] = 0;
$result = Db::table($this->table)
......
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