Commit a1f4bb89 authored by zhuwei's avatar zhuwei

1

parent ebcef3c2
<?php
namespace app\index\controller;
/**
* Created by PhpStorm.
* User: zhuwei
* Date: 2018/7/31
* Time: 上午10:18
*/
use app\index\extend\Basic;
use app\index\service\PerformanceService;
use app\index\untils\ExportExcelUntil;
use think\Request;
use \think\Session;
class OfficePerformance extends Basic
{
private $service_;
private $pageSize;
function __construct(Request $request = null)
{
parent::__construct($request);
$this->service_ = new PerformanceService();
$this->pageSize = 20;
}
/**
* 区域业绩排行
*/
public function selectDistrictPerformance()
{
header('Access-Control-Allow-Origin:*');
$params = $this->params;
/*$params = array(
"type" => 3, //1表示个人业绩排行 2门店 3区域
"end_day" => "",
"start_day" =>"",
);*/
$checkResult = $this->validate($params, "PerformanceServiceValidate.selectStorePerformance");
if (true !== $checkResult) {
return $this->response(101, $checkResult);
}
$params["type"] = 3;
$pageNo = empty($this->params['pageNo']) ? 1 : $this->params['pageNo'];
$pageSize = empty($this->params['pageSize']) ? 15 : $this->params['pageSize'];
//默认排序一周 2018-07-18改为本月
$start_day = !empty($params["start_day"]) ? $params["start_day"] : date("Y-m-01", time());
$end_day = !empty($params["end_day"]) ? $params["end_day"] : date("Y-m-d", time());
$father_id = !empty($params["father_id"]) ? $params["father_id"] : '' ;
//判断是否是导出EXCEL
$is_excel = !empty($params["is_excel"]) ? $params["is_excel"] : '' ;
if($is_excel == 1){
$list = $this->service_->totalAgentExcel($params["type"], $end_day, $start_day,$father_id,$params);
}
$list = $this->service_->totalAgent($params["type"], $end_day, $start_day,$pageNo,$pageSize,$father_id,$params);
//dump($list);
if (count($list) > 0) {
$result["list"] = $list['list'];
$result["total"] = $list['total'];
$result["performance_total"] = $list['performance_total'];
$result["start_time"] = $start_day;
$result["end_time"] = $end_day;
return $this->response("200", "request success", $result);
}
return $this->response("200", "request null");
}
/**
* 门店排行
*/
public function selectStorePerformance()
{
header('Access-Control-Allow-Origin:*');
$params = $this->params;
/*$params = array(
"start_day" => '2018-08-08',
"end_day" => '2018-08-08',
);*/
$checkResult = $this->validate($params, "PerformanceServiceValidate.selectStorePerformance");
if (true !== $checkResult) {
return $this->response(101, $checkResult);
}
$params["type"] = 2;
$pageNo = empty($this->params['pageNo']) ? 1 : $this->params['pageNo'];
$pageSize = empty($this->params['pageSize']) ? 15 : $this->params['pageSize'];
//默认排序一周 2018-07-18改为本月
$end_day = !empty($params["end_day"]) ? $params["end_day"] : date("Y-m-d", time());
$start_day = !empty($params["start_day"]) ? $params["start_day"] : date("Y-m-01", time());
$father_id = !empty($params["father_id"]) ? $params["father_id"] : '' ;
//判断是否是导出EXCEL
$is_excel = !empty($params["is_excel"]) ? $params["is_excel"] : '' ;
if($is_excel == 1){
$list = $this->service_->totalAgentExcel($params["type"], $end_day, $start_day,$father_id,$params);
}
$list = $this->service_->totalAgent($params["type"], $end_day, $start_day,$pageNo,$pageSize,$father_id,$params);
if (count($list) > 0) {
$result["list"] = $list['list'];
$result["total"] = $list['total'];
$result["performance_total"] = $list['performance_total'];
$result["start_time"] = $start_day;
$result["end_time"] = $end_day;
return $this->response("200", "request success", $result);
}
return $this->response("200", "request null");
}
/**
* 个人业绩排行
*/
public function selectIndividualPerformance()
{
header('Access-Control-Allow-Origin:*');
$params = $this->params;
/* $params = array(
"type" => 1, //1表示个人业绩排行 2门店 3区域
"end_day" => "",
"start_day" => "",
);*/
$checkResult = $this->validate($params, "PerformanceServiceValidate.selectStorePerformance");
if (true !== $checkResult) {
return $this->response(101, $checkResult);
}
$params["type"] = 1;
$pageNo = empty($this->params['pageNo']) ? 1 : $this->params['pageNo'];
$pageSize = empty($this->params['pageSize']) ? 15 : $this->params['pageSize'];
//默认排序一周 2018-07-18改为本月
$end_day = !empty($params["end_day"]) ? $params["end_day"] : date("Y-m-d", time());
$start_day = !empty($params["start_day"]) ? $params["start_day"] : date("Y-m-01", time());
$father_id = !empty($params["father_id"]) ? $params["father_id"] : '' ;
//判断是否是导出EXCEL
$is_excel = !empty($params["is_excel"]) ? $params["is_excel"] : '' ;
if($is_excel == 1){
$list = $this->service_->totalAgentExcel($params["type"], $end_day, $start_day,$father_id,$params);
}
$list = $this->service_->totalAgent($params["type"], $end_day, $start_day,$pageNo,$pageSize,$father_id,$params);
//dump($list);
if (count($list) > 0) {
$result["list"] = $list['list'];
$result["total"] = $list['total'];
$result["performance_total"] = $list['performance_total'];
$result["start_time"] = $start_day;
$result["end_time"] = $end_day;
return $this->response("200", "request success", $result);
}
return $this->response("200", "request null");
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: fuju
* Date: 2018/4/24
* Time: 16:55
*/
namespace app\index\controller;
use app\api_broker\service\RedisCacheService;
use app\api_broker\service\VipService;
use app\index\extend\Basic;
use app\index\untils\ExportExcelUntil;
use app\model\OBargainModel;
use app\model\OPartialCommission;
use think\Session;
class OfficePerformanceInfo extends Basic
{
protected $oBargainModel;
protected $status;
protected $redis_service;
public function __construct($request = null)
{
parent::__construct($request);
$this->oBargainModel = new OBargainModel();
$this->status = array('in','10,11,13');
$this->redis_service = new RedisCacheService();
}
/**
* 业绩明细
*/
public function performanceInfo() {
if ($this->request->isAjax()) {
$pageNo = empty($this->params['pageNo']) ? 1 : $this->params['pageNo'];
$pageSize = empty($this->params['pageSize']) ? 15 : $this->params['pageSize'];
$where['Obargain.status'] = $this->status;
/*开始结束时间*/
if (($this->params['create_time_start'] != NULL) && ($this->params['create_time_end'] != NULL)) {
$where['Obargain.create_time'] = ['between time', [$this->params['create_time_start']. ' 00:00:00', $this->params['create_time_end'] . ' 23:59:59']];
}
if ($this->params['shop_type'] != NULL) {
$where['Houses.shop_type'] = $this->params['shop_type'];
}
// 成交类型
if ($this->params['trade_type'] != NULL) {
$where['Obargain.trade_type'] = $this->params['trade_type'];
}
// 商铺地址
if ($this->params['landmark'] != NULL) {
$where['Houses.internal_address'] = ['like', '%'.$this->params['landmark'].'%'];
}
// 商铺编号
if ($this->params['house_id'] != NULL) {
$where['Oorder.house_id'] = $this->params['house_id'];
}
// 部门
if ($this->params['district_id'] != NULL) {
$where['Agent.district_id'] = $this->params['district_id'] ;
}
// 门店
if ($this->params['store_id'] != NULL) {
$where['Agent.store_id'] = $this->params['store_id'] ;
}
// 经纪人ID
if ($this->params['agents_id'] != NULL) {
$where['Agent.id'] = $this->params['agents_id'];
}
// 姓名
if ($this->params['name'] != NULL) {
$where['Agent.name'] = ['like', '%'.$this->params['name'].'%'];
}
// 手机号
if ($this->params['phone'] != NULL) {
$where['Agent.phone'] = ['like', '%'.$this->params['phone'].'%'];
}
// 成交报告id
if ($this->params['bargain_id'] != NULL) {
$exp ='(Obargain.id = '.$this->params['bargain_id'] .' and Obargain.father_id = 0) or (Obargain.father_id = '.$this->params['bargain_id'] .' and Obargain.father_id > 0)';
$where[] = ['EXP',$exp];
}
//dump($where);
$field = 'Obargain.create_time,';
$field .= 'Obargain.id,';
$field .= 'Obargain.father_id,';
$field .= 'Obargain.trade_type,';
$field .= 'Obargain.agent_id,';//分佣方ID,前端做权限判断用
$field .= 'Obargain.scale,';
$field .= 'Obargain.scale_fee,';
$field .= 'Obargain.order_id,';
$field .= 'Obargain.role,';
$field .= 'Obargain.price,';//pricec成交价格
$field .= 'Agent.name,';
$field .= 'Agent.phone,';
// $field .= 'Store.store_name,';
// $field .= 'District.district_name,';
$field .= 'Houses.internal_address,';
$field .= 'PartialCommission.practical_fee,';
$field .= 'Oorder.house_id';
$return = $this->oBargainModel->performancelInfo($where,$field,$pageSize,$pageNo);
foreach ($return as $key => $val) {
//成交报告ID
$return[$key]['bargain_id'] = $val["father_id"] == 0 ? $val["id"] : $val["father_id"];
//分佣ID
$return[$key]['commission_id'] = $val["id"] ;
$return[$key]['practical_fee'] = $val["practical_fee"] ? $val["practical_fee"] : 0 ;
//商铺地址只显示前3位,后面*替代
$return[$key]['landmark'] = $val["internal_address"] ? mb_substr($val["internal_address"],0,3,'utf-8').'****' : '';
$agent_data = $this->redis_service->getRedisCache(2, $val['agent_id']);
$return[$key]['store_name'] = $agent_data['store_name'];
$return[$key]['district_name'] = $agent_data['district_name'];
}
$return_total = $this->oBargainModel->performancelInfoTotal($where,$field);
/*计算业绩总计 即应分佣金 根据分佣ID去重*/
/*real_fee o_partial_commission数据表对应备注为'实分佣金字段' 作为 '预分业绩总计' */
$field = 'Obargain.scale_fee,Obargain.id,Obargain.father_id,PartialCommission.real_fee';
$return_sum = $this->oBargainModel->performancelInfoScaleFee($where,$field);
foreach ($return_sum as $key1 => $val1) {
//成交报告ID
$return_sum[$key1]['bargain_id'] = $val1["father_id"] == 0 ? $val1["id"] : $val1["father_id"];
//分佣ID
$return_sum[$key1]['commission_id'] = $val1["id"] ;
}
$return_sum_unique = $this->arr_unset($return_sum,'commission_id');
$return_sum = 0;
$real_fee = 0;
foreach ($return_sum_unique as $key12 => $val2) {
$return_sum += $val2["scale_fee"];
$real_fee += $val2["real_fee"];
}
/*计算业绩总计 即应分佣金 根据分佣ID去重*/
$data['data'] = $return;
$data['total'] = $return_total;
$data['scale_fee_sum'] = $return_sum;
$data['real_fee'] = $real_fee;
return $this->response(200, '', $data);
} else {
return view('performanceInfo');
}
}
/**
* 导出分佣提成明细表
*
* @return string
*/
public function getPerformanceInfoExcel()
{
//查询当前登录人权限
$vip_services = new VipService();
$get_group_res = $vip_services->getGroup($this->userId, '2,3,4,5');
$where['Obargain.status'] = $this->status;
/*开始结束时间*/
if (($this->params['create_time_start'] != NULL) && ($this->params['create_time_end'] != NULL)) {
$where['Obargain.create_time'] = ['between time', [$this->params['create_time_start']. ' 00:00:00', $this->params['create_time_end'] . ' 23:59:59']];
}
if ($this->params['shop_type'] != NULL) {
$where['Houses.shop_type'] = $this->params['shop_type'];
}
// 成交类型
if ($this->params['trade_type'] != NULL) {
$where['Obargain.trade_type'] = $this->params['trade_type'];
}
// 商铺地址
if ($this->params['landmark'] != NULL) {
$where['Houses.internal_address'] = ['like', '%'.$this->params['landmark'].'%'];
}
// 商铺编号
if ($this->params['house_id'] != NULL) {
$where['Oorder.house_id'] = $this->params['house_id'];
}
// 部门
if ($this->params['district_id'] != NULL) {
$where['Agent.district_id'] = $this->params['district_id'] ;
}
// 门店
if ($this->params['store_id'] != NULL) {
$where['Agent.store_id'] = $this->params['store_id'] ;
}
// 姓名
if ($this->params['name'] != NULL) {
$where['Agent.name'] = ['like', '%'.$this->params['name'].'%'];
}
// 手机号
if ($this->params['phone'] != NULL) {
$where['Agent.phone'] = ['like', '%'.$this->params['phone'].'%'];
}
// 成交报告id
if ($this->params['bargain_id'] != NULL) {
$exp ='(Obargain.id = '.$this->params['bargain_id'] .' and Obargain.father_id = 0) or (Obargain.father_id = '.$this->params['bargain_id'] .' and Obargain.father_id > 0)';
$where[] = ['EXP',$exp];
}
$field = 'Obargain.create_time,';
$field .= 'Obargain.id,';
$field .= 'Obargain.father_id,';
$field .= 'Obargain.trade_type,';
$field .= 'Obargain.agent_id,';//分佣方ID
$field .= 'Houses.internal_address,';
$field .= 'Oorder.house_id,';
$field .= 'Obargain.price,';//pricec成交价格
$field .= 'Agent.name,';
$field .= 'Agent.phone,';
// $field .= 'Store.store_name,';
// $field .= 'District.district_name,';
$field .= 'Obargain.scale,';
$field .= 'Obargain.scale_fee,';
$field .= 'PartialCommission.practical_fee,';
$field .= 'Obargain.role';
$return = $this->oBargainModel->performancelInfoExcel($where,$field);
if(!$return){
return $this->response("101","无数据");
}
$export = new ExportExcelUntil();
$e_data_new = [];
$role_arr = [1=>'盘方',2=>'客方',3=>'反签',4=>'独家',5=>'合作方',6=>'APP盘下载方',7=>'APP客下载方'];
foreach ($return as $key => $v) {
$e_data_old['bargain_id'] = $v["father_id"] == 0 ? $v["id"] : $v["father_id"];
$e_data_old['commission_id'] = $v["id"] ;
$e_data_old['create_time'] = $v['create_time'];//提交时间
if($v['trade_type'] == 10){
$e_data_old['trade_type'] = "出租";
}elseif($v['trade_type'] == 20){
$e_data_old['trade_type'] = "增佣";
}elseif($v['trade_type'] == 30){
$e_data_old['trade_type'] = "代理";
}else{
$e_data_old['trade_type'] = "好处费";
}
//商铺地址截取字符串前3位,角色'2,3,4,5'的做隐藏
if($v["internal_address"] && $get_group_res){
$landmark = mb_substr($v["internal_address"],0,3,'utf-8').'****';
}else{
$landmark = $v["internal_address"] ;
}
$e_data_old['landmark'] = $landmark;//商铺地址
$e_data_old['house_id'] = $v['house_id'];//商铺编号
$e_data_old['role_name'] = $role_arr[$v['role']];//分佣提成方
$e_data_old['name_phone'] = $v['name'].'-'.$v['phone'];//分佣提成方
$agent_data = $this->redis_service->getRedisCache(2, $v['agent_id']);
$e_data_old['store_name'] = $agent_data['store_name'];//所属门店
$e_data_old['scale'] = $v['scale'];//分佣比例
$e_data_old['scale_fee'] = $v['scale_fee'] ? $v['scale_fee'] : 0;//应收佣金
$e_data_old['practical_fee'] = $v['practical_fee'] ? $v['practical_fee'] : 0;//实收佣金
$e_data_old['price'] = $v['price'];//成交价
$e_data_new[]=$e_data_old;
}
$title = [ '成交报告ID', '分佣ID','提交时间', '成交类型', '商铺地址', '商铺编号','角色', '分佣提成方', '所属部门门店', '分佣比例', '应分佣金', '实收佣金' ,'成交价'];
$export->exportTable('业绩明细', $e_data_new, count($e_data_new[0]) - 1, '业绩明细表', $title);
return '';
}
//对一个二维数组的某个键进行去重
private function arr_unset($arr,$key){
$res = array();
foreach ($arr as $value) {
if(isset($res[$value[$key]])){//查看有没有重复项
unset($value[$key]); //有:销毁
}
else{
$res[$value[$key]] = $value;
}
}
return $res;
}
}
\ No newline at end of file
......@@ -1105,6 +1105,10 @@ Route::group('office_index', [
'partialCommissionList' => ['index/OfficeFinance/partialCommissionList', ['method' => 'get']], //分佣提成明细表
'performanceInfo' => [ 'index/OfficePerformanceInfo/performanceInfo', [ 'method' => 'GET|POST' ] ],//业绩明细办公楼
'selectDistrictPerformance' => [ 'index/OfficePerformance/selectDistrictPerformance', [ 'method' => 'GET|POST' ] ],//区域业绩排行
'selectStorePerformance' => [ 'index/OfficePerformance/selectStorePerformance', [ 'method' => 'GET|POST' ] ],//门店排行
'selectIndividualPerformance' => [ 'index/OfficePerformance/selectIndividualPerformance', [ 'method' => 'GET|POST' ] ],//个人业绩排行
]);
Route::group('office_api', [
......
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