Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tl_estate
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hujun
tl_estate
Commits
8481d1f5
Commit
8481d1f5
authored
Jun 04, 2019
by
hujun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
楼盘报备
parent
36c3d883
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
1784 additions
and
0 deletions
+1784
-0
OfficeReport.php
application/api_broker/controller/OfficeReport.php
+363
-0
OfficeReportService.php
application/api_broker/service/OfficeReportService.php
+390
-0
OfficeUserService.php
application/index/service/OfficeUserService.php
+897
-0
OfficeFollowUpLogModel.php
application/model/OfficeFollowUpLogModel.php
+134
-0
No files found.
application/api_broker/controller/OfficeReport.php
0 → 100644
View file @
8481d1f5
<?php
namespace
app\api_broker\controller
;
use
app\api_broker\extend\Basic
;
use
app\api_broker\service\OfficeReportService
;
use
app\api_broker\service\PushMessageService
;
use
app\index\service\OfficeUserService
;
use
app\model\AAgents
;
use
app\model\GHousesToAgents
;
use
app\model\OfficeFollowUpLogModel
;
use
think\Exception
;
/**
* Created by PhpStorm.
* User : zw
* Date : 2018/1/24
* Time : 14:24
* Intro: 报备流程
*/
class
Report
extends
Basic
{
private
$service_
;
private
$fulModel
;
private
$userService
;
public
function
__construct
(
$request
=
null
)
{
parent
::
__construct
(
$request
);
$this
->
service_
=
new
OfficeReportService
();
$this
->
fulModel
=
new
OfficeFollowUpLogModel
();
$this
->
userService
=
new
OfficeUserService
();
}
/**
* 报备
* @return \think\Response
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public
function
report
()
{
$params
=
$this
->
params
;
if
(
!
isset
(
$params
[
'report_agent_id'
])
||
!
isset
(
$params
[
'report_agent_phone'
])
||
!
isset
(
$params
[
'report_store_id'
])
||
!
isset
(
$params
[
'user_id'
])
||
!
isset
(
$params
[
'house_ids'
])
||
!
isset
(
$params
[
'vehicle'
]))
{
return
$this
->
response
(
"101"
,
"请求参数错误"
);
}
/* $params = array(
"report_agent_id" => 1,//报备经纪人id
"report_agent_phone" => '13817616471',//报备经纪人id
"report_store_id" => 1,//门店id
"user_id" => 1,//用户id
"house_ids" => "1,2,3",//楼盘id
"vehicle" => 10,//交通工具
"intro" => "123123123",//备注
"predict_see_time" => time(),//预计到看时间
);*/
$agent_id
=
$params
[
"report_agent_id"
];
$agent_phone
=
$params
[
"report_agent_phone"
];
$store_id
=
$params
[
"report_store_id"
];
$user_id
=
$params
[
"user_id"
];
$house_ids
=
$params
[
"house_ids"
];
$vehicle
=
$params
[
"vehicle"
];
$intro
=
$params
[
"intro"
];
$predict_see_time
=
$params
[
"predict_see_time"
];
//todo 验证用户id是否正常
$userArr
=
$this
->
service_
->
verifyUser
(
$user_id
);
if
(
!
$userArr
)
{
return
$this
->
response
(
"101"
,
"不存在此用户"
);
}
$is_ok
=
$this
->
service_
->
verifyReport
(
$agent_id
,
$agent_phone
,
$this
->
agentName
,
$store_id
,
$user_id
,
$userArr
[
"user_phone"
],
$userArr
[
"user_name"
],
$house_ids
,
$vehicle
,
$intro
,
$predict_see_time
);
if
(
$is_ok
>
0
)
{
$this
->
userService
->
setUserSites
(
$user_id
,
$this
->
siteId
);
//设置用户站点 朱伟 2018-10-22
/*记录推送*/
// $push = new PushMessageService();
// $house_ids_arr = explode(',', $house_ids);
//
// if (is_array($house_ids_arr)) {
// foreach ($house_ids_arr as $k=>$v) {
// $push->pushReportMessage($v, $agent_id, 1, $this->agentId, $user_id); //推送报备信息
// }
// }
/*记录推送*/
return
$this
->
response
(
"200"
,
"request success"
,
[]);
}
else
{
return
$this
->
response
(
"101"
,
"save exception"
);
}
}
/**
* 获取报备列表
* @return \think\Response
* @throws \think\db\exception\BindParamException
* @throws \think\exception\PDOException
*/
public
function
reportList
()
{
$params
=
$this
->
params
;
/* $params = array(
"agent_id" =>5741,
"type" => 2,//1表示全部 2表示进场 3 表示收款 4成交报告
"is_all"=>1,//0搜索我自己的,1全部
"page_no"=>1,
"page_size"=>15
);*/
if
(
!
isset
(
$params
[
"agent_id"
])
||
!
isset
(
$params
[
"type"
]))
{
return
$this
->
response
(
"101"
,
"请求参数错误"
);
}
$pageNo
=
empty
(
$params
[
'page_no'
])
?
1
:
$params
[
'page_no'
];
$pageSize
=
empty
(
$params
[
'page_size'
])
?
15
:
$params
[
'page_size'
];
$field
=
"a.id,a.user_id,a.user_phone,a.user_name,a.predict_see_time,a.create_time,b.id as order_id,b.order_no,
b.house_id,b.house_title"
;
$params
[
"report_agent_id"
]
=
$params
[
"agent_id"
];
$result
=
[];
if
(
isset
(
$params
[
"is_all"
])
&&
$params
[
"is_all"
]
==
1
){
$check_type
=
$this
->
service_
->
getCheckType
(
$this
->
agentId
);
if
(
$check_type
==
0
)
{
return
$this
->
response
(
101
,
"暂无权限"
);
}
$result
=
$this
->
service_
->
orderListAll
(
$field
,
$params
,
$pageNo
,
$pageSize
,
$check_type
);
}
else
{
$result
=
$this
->
service_
->
orderList
(
$field
,
$params
,
$pageNo
,
$pageSize
);
}
if
(
count
(
$result
)
>
0
)
{
return
$this
->
response
(
"200"
,
"request success"
,
$result
);
}
else
{
return
$this
->
response
(
"200"
,
"request null"
);
}
}
/**
* 获取权限
* @return int|\think\Response
*/
public
function
getCheckType
()
{
$result
=
$this
->
service_
->
getCheckType
(
$this
->
agentId
);
if
(
$result
==
0
)
{
return
$this
->
response
(
101
,
"暂无权限"
);
}
else
{
return
$this
->
response
(
"200"
,
"request success"
,
[
'check_type'
=>
$result
]);
}
}
/**
* 获取报备列表 pc
* @return \think\Response
* @throws \think\db\exception\BindParamException
* @throws \think\exception\PDOException
*/
public
function
reportListForPc
()
{
$params
=
$this
->
params
;
/*$params = array(
"AuthToken" =>'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJkYXRhIjp7ImlkIjoxLCJuYW1lIjoiXHU3YmExXHU3NDA2XHU1NDU4MTEiLCJwaG9uZSI6InJvb3QiLCJsZXZlbCI6MTB9LCJ0aW1lU3RhbXBfIjoxNTMxODA3NTAxfQ.zQp_zyCknWsdJbmNvsFOzuuq-C_zeUijYUWomBHeIFU',
"agent_id" =>1,
"type" => 1,//1表示全部 2表示进场 3 表示收款 4成交报告
"page_no"=>0,
"page_size"=>15,
"create_time_start"=>'2018-07-13',
"create_time_end"=>'2018-07-13',
"district_id"=>5,
);*/
if
(
!
isset
(
$params
[
"agent_id"
])
||
!
isset
(
$params
[
"type"
]))
{
return
$this
->
response
(
"101"
,
"请求参数错误"
);
}
$pageNo
=
empty
(
$params
[
'pageNo'
])
?
1
:
$params
[
'pageNo'
];
$pageSize
=
empty
(
$params
[
'pageSize'
])
?
15
:
$params
[
'pageSize'
];
$field
=
"a.id,a.user_id,a.report_agent_name,a.report_agent_phone,a.user_phone,a.user_name,a.predict_see_time,a.create_time,b.id as order_id,b.order_no,b.house_id,b.house_title"
;
if
(
isset
(
$params
[
"report_id"
]))
{
$params
[
"a.id"
]
=
$params
[
"report_id"
];
}
$params
[
"report_agent_id"
]
=
$params
[
"agent_id"
];
// $result = $this->service_->orderListForPc($field, $params, $pageNo, $pageSize);
$result
=
$this
->
service_
->
orderList
(
$field
,
$params
,
$pageNo
,
$pageSize
);
if
(
count
(
$result
)
>
0
)
{
return
$this
->
response
(
"200"
,
"request success"
,
$result
);
}
else
{
return
$this
->
response
(
"200"
,
"request null"
);
}
}
/**
* 权限判定
* @return \think\Response
*/
public
function
appAgentAuth
()
{
$params
=
$this
->
params
;
/* $params = array(
"agent_id" => 51,
"house_id" => 1
);*/
if
(
!
isset
(
$params
[
"agent_id"
]))
{
return
$this
->
response
(
"101"
,
"请求参数错误"
);
}
if
(
isset
(
$params
[
"house_id"
]))
{
$agent_id
=
$params
[
"agent_id"
];
$house_id
=
$params
[
"house_id"
];
//todo 判断是不是案场权限人
$agentToHouseModel
=
new
GHousesToAgents
();
$where_
[
"houses_id"
]
=
$house_id
;
$where_
[
"agents_id"
]
=
$agent_id
;
$where_
[
"type"
]
=
1
;
$where_
[
"is_del"
]
=
0
;
$isCase
=
$agentToHouseModel
->
getHouseToAgents
(
"id"
,
$where_
);
$result
[
"marchIn"
]
=
$result
[
"collectingBill"
]
=
$result
[
"refund"
]
=
$result
[
"bargain"
]
=
false
;
if
(
count
(
$isCase
)
>
0
)
{
$result
[
"marchIn"
]
=
true
;
$result
[
"collectingBill"
]
=
true
;
$result
[
"refund"
]
=
true
;
$result
[
"bargain"
]
=
true
;
return
$this
->
response
(
"200"
,
"request success"
,
$result
);
}
}
$auth_arr
=
[
/*'broker/report',
'broker/addFollowUp',*/
'broker/marchIn'
,
'broker/collectingBill'
,
'broker/refund'
,
'broker/bargain'
,
/* 'broker/statusBargain',*/
];
$param
[
"name"
]
=
array
(
"in"
,
$auth_arr
);
$agents
=
new
AAgents
();
$is_auth
=
$agents
->
agentsAuthIds
(
$params
[
"agent_id"
],
$param
);
if
(
count
(
$is_auth
)
>
0
)
{
foreach
(
$is_auth
as
$item
)
{
if
(
$item
[
'name'
]
==
"broker/marchIn"
)
{
$result
[
"marchIn"
]
=
true
;
}
if
(
$item
[
'name'
]
==
"broker/collectingBill"
)
{
$result
[
"collectingBill"
]
=
true
;
}
if
(
$item
[
'name'
]
==
"broker/refund"
)
{
$result
[
"refund"
]
=
true
;
}
if
(
$item
[
'name'
]
==
"broker/bargain"
)
{
$result
[
"bargain"
]
=
true
;
}
}
return
$this
->
response
(
"200"
,
"request success"
,
$result
);
}
return
$this
->
response
(
"200"
,
"request null"
);
}
/**
* 新增跟进
* @return \think\Response
*/
public
function
addFollowUp
()
{
/* $params = array(
"report_id" => 1,
"agent_id" => 12,
"agent_name" => "saewerw",
"user_type" =>"1,2", // 用户类型
"decision_maker" =>"zhangsan",// 第一决策人
"industry_type" =>"1,2",//租商铺做什么
"area_requirement" =>"1,2",//面积要求
"price_requirement" =>"1,2", //价格要求
"province" =>"1,2", //省
"city" =>"1,2",//市
"district" =>"1,2",//区
"business_area" =>"1,2",//商圈
"other_area" =>"1,2",//其他地区
"explain" =>"1,2",//备注
"explain_img" =>"1,2"//备注图
);*/
header
(
'Access-Control-Allow-Origin:*'
);
$params
=
$this
->
params
;
if
(
!
isset
(
$params
[
'report_id'
])
||
!
isset
(
$params
[
'agent_id'
])
||
!
isset
(
$params
[
'agent_name'
])
||
!
isset
(
$params
[
'user_type'
])
||
!
isset
(
$params
[
'industry_type'
])
||
!
isset
(
$params
[
'area_requirement'
])
||
!
isset
(
$params
[
'price_requirement'
]))
{
return
$this
->
response
(
"101"
,
"请求参数错误"
);
}
$params
[
"agent_name"
]
=
$this
->
agentName
;
$is_ok
=
$this
->
fulModel
->
addFollowUpLog
(
$params
);
if
(
$is_ok
>
0
)
{
return
$this
->
response
(
"200"
,
"request success"
,
[]);
}
else
{
return
$this
->
response
(
"101"
,
"request error"
);
}
}
/**
* 获取跟进记录列表
* @return \think\Response
*/
public
function
getFollowUpList
()
{
/* $params = array(
"report_id" => 1,// 报备id
"agent_id" => 1,//非必填 经纪人id 没有就获取最新一条跟进记录
);*/
header
(
'Access-Control-Allow-Origin:*'
);
$params
=
$this
->
params
;
if
(
!
isset
(
$params
[
"report_id"
]))
{
return
$this
->
response
(
"101"
,
"请求参数错误"
);
}
$field_
=
"id,report_id,agent_id,user_type,decision_maker,industry_type,area_requirement,price_requirement,province
,city,district,business_area,other_area,explain,explain_img,create_time,update_time"
;
$order_
=
"create_time desc"
;
$where_
=
[];
$where_
[
"report_id"
]
=
$params
[
"report_id"
];
if
(
isset
(
$params
[
"agent_id"
]))
{
$where_
[
"agent_id"
]
=
$params
[
"agent_id"
];
}
try
{
$result
=
$this
->
fulModel
->
selectFollowUpList
(
$field_
,
$where_
,
$order_
);
if
(
count
(
$result
)
>
0
)
{
return
$this
->
response
(
"200"
,
"request success"
,
$result
);
}
else
{
return
$this
->
response
(
"300"
,
"not fund list"
,
[]);
}
}
catch
(
Exception
$e
)
{
return
$this
->
response
(
"101"
,
"request error:"
.
$e
);
}
}
}
\ No newline at end of file
application/api_broker/service/OfficeReportService.php
0 → 100644
View file @
8481d1f5
<?php
namespace
app\api_broker\service
;
use
app\api\untils\GeTuiUtils
;
use
app\model\GHouses
;
use
app\model\GHousesToAgents
;
use
app\model\OfficeOrderModel
;
use
app\model\OfficeOReportModel
;
use
app\model\Users
;
/**
* Created by PhpStorm.
* User : zw
* Date : 2018/1/26
* Time : 16:41
* Intro:
*/
class
OfficeReportService
{
private
$reportModel
;
private
$orderModel
;
function
__construct
()
{
$this
->
reportModel
=
new
OfficeOReportModel
();
$this
->
orderModel
=
new
OfficeOrderModel
();
}
/**
* 验证用户信息
*
* @param $user_id
* @return array|null
*/
public
function
verifyUser
(
$user_id
)
{
$userResult
=
[];
$userModel
=
new
Users
();
$userArr
=
$userModel
->
selectUser
(
$user_id
,
"id,user_nick,user_name,user_phone"
);
if
(
count
(
$userArr
)
>
0
)
{
$userResult
[
"user_phone"
]
=
$userArr
[
"user_phone"
];
if
(
empty
(
$userArr
[
'user_name'
]))
{
$userResult
[
"user_name"
]
=
$userArr
[
"user_nick"
];
}
else
{
$userResult
[
"user_name"
]
=
$userArr
[
"user_name"
];
}
}
else
{
return
null
;
}
return
$userResult
;
}
/**
* 生成报备和保存订单
*
* @param $agent_id
* @param $agent_phone
* @param $agent_name
* @param $store_id
* @param $user_id
* @param $user_phone
* @param $user_name
* @param $house_ids
* @param $vehicle
* @param $intro
* @param $predict_see_time
* @return int
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public
function
verifyReport
(
$agent_id
,
$agent_phone
,
$agent_name
,
$store_id
,
$user_id
,
$user_phone
,
$user_name
,
$house_ids
,
$vehicle
,
$intro
,
$predict_see_time
)
{
$id
=
$this
->
reportBin
(
$agent_id
,
$agent_phone
,
$agent_name
,
$store_id
,
$user_id
,
$user_phone
,
$user_name
,
$vehicle
,
$intro
,
$predict_see_time
);
if
(
$id
>
0
)
{
$house_arr
=
explode
(
","
,
$house_ids
);
$order_arr
=
[];
foreach
(
$house_arr
as
$k
=>
$v
)
{
//todo 批量插入到数据库
if
(
$v
<=
0
){
break
;
}
$order_no
=
$this
->
createOrderNumber
();
array_push
(
$order_arr
,
$this
->
orderBin
(
$order_no
,
$id
,
$v
));
}
//todo 保存order表 订单返回成功返回报备id
return
(
$this
->
orderModel
->
insertOrderByAll
(
$order_arr
)
>
0
)
?
$id
:
0
;
}
}
/**
* 报备订单列表
* @param $field
* @param $params
* @param $pageNo
* @param $pageSize
* @return mixed|null
* @throws \think\db\exception\BindParamException
* @throws \think\exception\PDOException
*/
public
function
orderList
(
$field
,
$params
,
$pageNo
,
$pageSize
)
{
//todo 获取我报备的我的案场的,
//如果是店长则获取其下所有的经纪人 这里去掉了for190218
$vModel
=
new
VerifyService
();
// $agentArr = $vModel->getAgentsByAgentId($params["report_agent_id"]);
$params
[
"agent_id_s"
]
=
array
(
"in"
,
$params
[
"report_agent_id"
]
);
$caseHouseId
=
$vModel
->
getCaseHouseIdByAgentIdV2
(
$params
[
"agent_id_s"
]);
$ids
=
""
;
if
(
count
(
$caseHouseId
)
>
0
)
{
foreach
(
$caseHouseId
as
$item
)
{
$ids
.=
$item
[
"houses_id"
]
.
","
;
}
}
$ids
=
rtrim
(
$ids
,
","
);
$ids
=
$ids
?
$ids
:
0
;
$params
[
"house_ids"
]
=
$ids
;
$result
=
$this
->
reportModel
->
selectReportList
(
$field
,
$params
,
$pageNo
,
$pageSize
);
return
$this
->
returnResult
(
$result
);
}
/**
* @param $result
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public
function
returnResult
(
$result
){
$ids_str
=
""
;
$house_id_str
=
""
;
if
(
count
(
$result
)
>
0
)
{
foreach
(
$result
as
$k
=>
$v
)
{
$order_id
=
0
;
if
(
isset
(
$v
[
"order_id"
])){
$order_id
=
$v
[
"order_id"
];
}
else
{
$order_id
=
$v
[
"id"
];
}
$ids_str
.=
$order_id
.
","
;
$house_id_str
.=
$v
[
"house_id"
]
.
","
;
}
$ids_str
=
rtrim
(
$ids_str
,
","
);
$house_id_str
=
rtrim
(
$house_id_str
,
","
);
$sign_arr
=
$this
->
orderSign
(
$ids_str
);
$house_arr
=
$this
->
houseInfo
(
$house_id_str
);
foreach
(
$result
as
$k
=>
$v
)
{
$result
[
$k
][
"sign"
]
=
""
;
foreach
(
$sign_arr
as
$value
)
{
if
(
$v
[
"order_id"
]
==
$value
[
"order_id"
])
{
$result
[
$k
][
"sign"
]
.=
$this
->
signTitle
(
$value
[
"type"
])
.
","
;
}
}
foreach
(
$house_arr
as
$item
)
{
if
(
$v
[
"house_id"
]
==
$item
[
"id"
])
{
$result
[
$k
][
"house_address"
]
.=
$item
[
"internal_address"
];
}
}
}
}
return
$result
;
}
/**
* 报备订单列表All
* @param $field
* @param $params
* @param $pageNo
* @param $pageSize
* @return mixed|null
* @throws \think\db\exception\BindParamException
* @throws \think\exception\PDOException
*/
public
function
orderListAll
(
$field
,
$params
,
$pageNo
,
$pageSize
,
$check_type
)
{
$vModel
=
new
VerifyService
();
$result
=
[];
switch
(
$check_type
)
{
case
1
:
$result
=
$this
->
reportModel
->
selectReportListAll
(
$field
,
$params
,
$pageNo
,
$pageSize
);
break
;
case
2
:
case
3
:
$agentArr
=
$vModel
->
getAgentsByAgentIdAndType
(
$params
[
"report_agent_id"
],
$check_type
);
$params
[
"agent_id_s"
]
=
array
(
"in"
,
$agentArr
);
$params
[
"report_agent_id"
]
=
$agentArr
;
$caseHouseId
=
$vModel
->
getPanpartyAndExclusiveHouseIdByAgentId
(
$params
[
"agent_id_s"
]);
$ids
=
""
;
if
(
count
(
$caseHouseId
)
>
0
)
{
foreach
(
$caseHouseId
as
$item
)
{
$ids
.=
$item
[
"houses_id"
]
.
","
;
}
}
$ids
=
rtrim
(
$ids
,
","
);
$ids
=
$ids
?
$ids
:
0
;
$params
[
"house_ids"
]
=
$ids
;
$result
=
$this
->
reportModel
->
selectReportList
(
$field
,
$params
,
$pageNo
,
$pageSize
);
break
;
default
:
}
return
$this
->
returnResult
(
$result
);
}
/**
* 报备订单列表
* @param $field
* @param $params
* @param $pageNo
* @param $pageSize
* @return mixed|null
* @throws \think\db\exception\BindParamException
* @throws \think\exception\PDOException
*/
public
function
orderListForPc
(
$field
,
$params
,
$pageNo
,
$pageSize
)
{
//todo 获取我报备的我的案场的,如果是店长则获取其下所有的经纪人
$vModel
=
new
VerifyService
();
$agentArr
=
$vModel
->
getAgentsByAgentId
(
$params
[
"report_agent_id"
]);
if
(
$agentArr
)
{
$params
[
"agent_id_s"
]
=
array
(
"in"
,
$agentArr
);
$params
[
"report_agent_id"
]
=
$agentArr
;
}
$caseHouseId
=
$vModel
->
getCaseHouseIdByAgentId
(
$params
[
"agent_id_s"
]);
$ids
=
""
;
if
(
count
(
$caseHouseId
)
>
0
)
{
foreach
(
$caseHouseId
as
$item
)
{
$ids
.=
$item
[
"houses_id"
]
.
","
;
}
}
$ids
=
rtrim
(
$ids
,
","
);
$ids
=
$ids
?
$ids
:
0
;
$params
[
"house_ids"
]
=
$ids
;
$result
=
$this
->
reportModel
->
selectReportList
(
$field
,
$params
,
$pageNo
,
$pageSize
);
$count
=
$this
->
reportModel
->
selectReportCount
(
$field
,
$params
);
if
(
count
(
$result
)
>
0
)
{
$data
[
"result"
]
=
$this
->
returnResult
(
$result
);
$data
[
"total"
]
=
$count
[
0
][
"total"
]
?
$count
[
0
][
"total"
]
:
0
;
return
$data
;
}
return
null
;
}
public
function
orderSign
(
$ids_str
)
{
return
$this
->
orderModel
->
selectSign
(
$ids_str
);
}
/**
* @param $house_id_str
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public
function
houseInfo
(
$house_id_str
)
{
$houseModel
=
new
GHouses
();
$params
[
"id"
]
=
array
(
"in"
,(
$house_id_str
));
return
$houseModel
->
getHouseInfo
(
"id,internal_address"
,
$params
);
}
public
function
signTitle
(
$type
)
{
switch
(
$type
)
{
case
2
:
return
"进场"
;
case
3
:
return
"收款"
;
case
4
:
return
"成交报告"
;
default
:
return
null
;
}
}
/**
* 订单号
* @return string
*/
private
function
createOrderNumber
()
{
return
time
()
.
mt_rand
(
100000
,
999999
);
}
/**
* 报备主表
*
* @param $report_agent_id
* @param $agent_phone
* @param $report_agent_name
* @param $report_store_id
* @param $user_id
* @param $user_phone
* @param $user_name
* @param $vehicle
* @param $intro
* @param $predict_see_time int 时间戳
* @return int|string
*/
public
function
reportBin
(
$report_agent_id
,
$agent_phone
,
$report_agent_name
,
$report_store_id
,
$user_id
,
$user_phone
,
$user_name
,
$vehicle
,
$intro
,
$predict_see_time
)
{
$param
[
"report_agent_id"
]
=
$report_agent_id
;
$param
[
"report_agent_phone"
]
=
$agent_phone
;
$param
[
"report_agent_name"
]
=
$report_agent_name
;
$param
[
"report_store_id"
]
=
$report_store_id
;
$param
[
"user_id"
]
=
$user_id
;
$param
[
"user_phone"
]
=
$user_phone
;
$param
[
"user_name"
]
=
$user_name
;
$param
[
"vehicle"
]
=
$vehicle
;
$param
[
"status"
]
=
0
;
$param
[
"intro"
]
=
$intro
;
$param
[
"predict_see_time"
]
=
date
(
"Y-m-d H:i:s"
,
$predict_see_time
);
$param
[
"create_time"
]
=
date
(
"Y-m-d H:i:s"
,
time
());
$param
[
"update_time"
]
=
date
(
"Y-m-d H:i:s"
,
time
());
return
$this
->
reportModel
->
addReport
(
$param
);
}
/**
* 订单子表
* @param $order_no
* @param $f_id
* @param $house_id
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
private
function
orderBin
(
$order_no
,
$f_id
,
$house_id
)
{
$houseModel
=
new
GHouses
();
$houseResult
=
$houseModel
->
getHouseDetail
(
"id,internal_title"
,
[
"id"
=>
$house_id
]);
$house_title
=
count
(
$houseResult
)
>
0
&&
isset
(
$houseResult
[
"internal_title"
])
?
$houseResult
[
"internal_title"
]
:
null
;
$param
[
"order_no"
]
=
$order_no
;
$param
[
"f_id"
]
=
$f_id
;
$param
[
"house_id"
]
=
$house_id
;
$param
[
"house_title"
]
=
$house_title
;
$param
[
"create_time"
]
=
date
(
"Y-m-d H:i:s"
,
time
());
$param
[
"update_time"
]
=
date
(
"Y-m-d H:i:s"
,
time
());
return
$param
;
}
/**
* 获取权限
* @param $agent_id
* @return int
*/
public
function
getCheckType
(
$agent_id
)
{
$vip
=
new
VipService
();
if
(
$vip
->
vip
(
$agent_id
,
'index/inspectionRecordAll/3'
)
==
0
){
//代表公司
return
1
;
}
if
(
$vip
->
vip
(
$agent_id
,
'index/inspectionRecordDistrict/2'
)
==
0
){
//代表部门
return
2
;
}
if
(
$vip
->
vip
(
$agent_id
,
'index/inspectionRecordStore/1'
)
==
0
){
//代表门店
return
3
;
}
return
0
;
}
}
\ No newline at end of file
application/index/service/OfficeUserService.php
0 → 100644
View file @
8481d1f5
<?php
/**
* Created by PhpStorm.
* User: fuju
* Date: 2018/8/27
* Time: 12:43
*/
namespace
app\index\service
;
use
app\api_broker\service\PushMessageService
;
use
app\api_broker\service\RedisCacheService
;
use
app\api_broker\service\VipService
;
use
app\extra\RedisExt
;
use
app\index\validate\MemberValidate
;
use
app\model\AAgents
;
use
app\model\ACollectUser
;
use
app\model\GOperatingRecords
;
use
app\model\OReportModel
;
use
app\model\Users
;
use
app\task\controller\ResultsSummaryNewTask
;
use
think\Log
;
class
OfficeUserService
{
protected
$user
;
protected
$code
=
200
;
protected
$msg
=
''
;
protected
$operation_id
;
public
function
__construct
()
{
$this
->
user
=
new
Users
();
}
/**
* 新增或编辑客户
*
* @param $id
* @param $data
* @param $operation_id
* @param $site_id
* @return array|int|mixed
*/
public
function
editUser
(
$id
,
$data
,
$operation_id
,
$site_id
)
{
$validate
=
new
MemberValidate
();
if
(
!
$validate
->
scene
(
'add'
)
->
check
(
$data
))
{
$result
[
'status'
]
=
'fail'
;
$result
[
'msg'
]
=
$validate
->
getError
();
return
$result
;
}
$this
->
operation_id
=
$operation_id
;
$result
=
[];
$agent_id_old
=
$referrer_id_old
=
$referrer_source_old
=
0
;
$type
=
$user_name
=
''
;
try
{
if
(
empty
(
$id
))
{
//新增用户
$where
[
'user_phone'
]
=
$data
[
'user_phone'
];
$num
=
$this
->
user
->
all_user_count
(
$where
);
if
(
$num
>
0
)
{
$result
[
'status'
]
=
'fail'
;
$result
[
'msg'
]
=
'该用户已经存在'
;
return
$result
;
}
$type
=
'add'
;
$future_time
=
date
(
"Y-m-d H:i:s"
,
strtotime
(
"+1 day"
));
//24小时前的时间
$data
[
'protect_time'
]
=
$future_time
;
}
else
{
$user_data
=
$this
->
user
->
getUserById
(
'id,agent_id,referrer_id,referrer_source,user_name,site_ids'
,
$id
);
if
(
empty
(
$user_data
[
'id'
]))
{
$result
[
'status'
]
=
'fail'
;
$result
[
'msg'
]
=
'没有该用户信息'
;
return
$result
;
}
$agent_id_old
=
empty
(
$user_data
[
'agent_id'
])
?
0
:
$user_data
[
'agent_id'
];
$referrer_id_old
=
empty
(
$user_data
[
'referrer_id'
])
?
0
:
$user_data
[
'referrer_id'
];
$referrer_source_old
=
empty
(
$user_data
[
'referrer_source'
])
?
0
:
$user_data
[
'referrer_source'
];
$user_name
=
empty
(
$user_data
[
'user_name'
])
?
''
:
$user_data
[
'user_name'
];
$site_id_old
=
empty
(
$user_data
[
'site_ids'
])
?
''
:
$user_data
[
'site_ids'
];
if
(
$data
[
'referrer_source'
]
==
20
)
{
unset
(
$data
[
'referrer_source'
]);
unset
(
$data
[
'referrer_id'
]);
unset
(
$user_data
[
'referrer_id'
]);
unset
(
$user_data
[
'referrer_id'
]);
}
}
$id
=
$this
->
user
->
edit
(
$data
,
$id
,
$operation_id
);
//新增或编辑
if
(
$id
<=
0
)
{
$msg
=
$this
->
getCodeMsg
(
$id
);
$result
[
'status'
]
=
'fail'
;
$result
[
'msg'
]
=
$msg
;
return
$result
;
}
else
{
$result
[
'status'
]
=
'successful'
;
$result
[
'msg'
]
=
''
;
$redis_service
=
new
RedisCacheService
();
$redis_service
->
userCache
(
$id
);
}
// $this->setUserSites($id, $data['site_id']);//设置站点
//操作完成之后判断下是什么动作
// if($type == 'add'){
// //$type等于'add'说明是新增客户,需要设置保护期截止日期
// $this->setUserProtectTime($id);
// }
//记录修改客方
if
(
!
empty
(
$data
[
'agents_id'
]))
{
$this
->
recordGuest
((
int
)
$data
[
'agents_id'
],
(
int
)
$agent_id_old
,
$id
,
$user_name
,
$type
);
}
//记录邀请人 修改记录
if
(
!
empty
(
$data
[
'referrer_id'
]))
{
$this
->
recordReferrer
(
$data
[
'referrer_id'
],
$data
[
'referrer_source'
],
$id
,
$referrer_id_old
);
}
//城市标签 修改记录
if
(
!
empty
(
$data
[
'site_id'
])
&&
(
$data
[
'site_id'
]
!=
$site_id_old
))
{
$this
->
userSiteChangeLog
(
$this
->
operation_id
,
$id
,
$site_id_old
,
$data
[
'site_id'
]);
}
//客户姓名 修改记录
if
(
!
empty
(
$data
[
'user_name'
])
&&
(
$data
[
'user_name'
]
!=
$user_name
))
{
$this
->
userNameChangeLog
(
$this
->
operation_id
,
$id
,
$user_name
,
$data
[
'user_name'
]);
}
//更新业绩统计
$agent
=
new
AAgents
();
$agent_data
=
$agent
->
getAgentInfo
(
'id,name,phone,store_id,district_id'
,
$data
[
'agents_id'
]);
$sum
=
new
ResultsSummaryNewTask
();
$date
=
date
(
'Y-m-d'
);
$sum
->
updateTotalByAgentId
(
$agent_data
[
'id'
],
$agent_data
[
'store_id'
],
$agent_data
[
'district_id'
],
$date
,
$site_id
);
}
catch
(
\Exception
$e
)
{
$result
[
'status'
]
=
'fail'
;
$result
[
'msg'
]
=
$e
->
getMessage
();
}
return
$result
;
}
/**
* 城市标签 修改记录
* @param $operation_id
* @param $user_id
* @param $site_id_old
* @param $site_id_new
*/
public
function
userSiteChangeLog
(
$operation_id
,
$user_id
,
$site_id_old
,
$site_id_new
)
{
$agent
=
new
AAgents
();
$agent_data
=
$agent
->
getAgentInfo
(
'name'
,
$operation_id
);
$site_id_old_
=
$this
->
getSiteNameStr
(
$site_id_old
);
$site_id_new_
=
$this
->
getSiteNameStr
(
$site_id_new
);
$remark
=
"客户城市标签被【
{
$agent_data
[
'name'
]
}
】由【
{
$site_id_old_
}
】修改为【
{
$site_id_new_
}
】"
;
$this
->
operating_records
(
$this
->
operation_id
,
10
,
$remark
,
$user_id
);
}
/**
*客户姓名 修改记录
* @param $operation_id
* @param $user_id
* @param $user_name_old
* @param $user_name_new
*/
public
function
userNameChangeLog
(
$operation_id
,
$user_id
,
$user_name_old
,
$user_name_new
)
{
$redis_service
=
new
RedisCacheService
();
$agent_data
=
$redis_service
->
getRedisCache
(
2
,
$operation_id
);
$remark
=
"客户姓名被【
{
$agent_data
[
'name'
]
}
】由【
{
$user_name_old
}
】修改为【
{
$user_name_new
}
】"
;
$this
->
operating_records
(
$this
->
operation_id
,
9
,
$remark
,
$user_id
);
}
/**
* 城市标签 数字id转文字
* @param $site_id
* @return string
*/
public
function
getSiteNameStr
(
$site_id
){
$site_ids_arr
=
explode
(
','
,
$site_id
);
$site_ids_str
=
[];
if
(
count
(
$site_ids_arr
)
>
0
)
{
foreach
(
$site_ids_arr
as
$key
=>
$value
)
{
$site_name
=
$this
->
getSiteName
(
$value
);
$site_ids_str
[]
=
$site_name
;
}
}
return
implode
(
','
,
$site_ids_str
);
}
/**
* 城市标签 根据id获取城市名
* @param $siteId
* @return array|bool|false|mixed|\PDOStatement|string|\think\Model
*/
public
function
getSiteName
(
$siteId
){
$redis_service
=
new
RedisCacheService
();
$site_name
=
$redis_service
->
getRedisCache
(
4
,
$siteId
);
return
$site_name
;
}
/**
* 根据客户id获取客户信息
*
* @param int $user_id
* @return array
*/
public
function
getUserData
(
int
$user_id
)
:
array
{
if
(
$user_id
)
{
try
{
$data
[
'data'
]
=
$this
->
user
->
getClient
(
$user_id
);
$data
[
'msg'
]
=
''
;
$data
[
'status'
]
=
'successful'
;
}
catch
(
\Exception
$e
)
{
$data
[
'msg'
]
=
$e
->
getMessage
();
$data
[
'status'
]
=
'fail'
;
}
}
else
{
$data
[
'status'
]
=
'fail'
;
$data
[
'msg'
]
=
'Id is null'
;
}
return
$data
;
}
/**
* 记录客方记录修改并推送消息
*
* @param int $agent_id
* @param int $agent_id_old
* @param int $user_id
* @param string $user_name
* @param string $type
* @return array
*/
public
function
recordGuest
(
int
$agent_id
,
int
$agent_id_old
,
int
$user_id
,
$user_name
,
$type
=
'add'
)
:
array
{
try
{
$agent
=
new
AAgents
();
$agent_data
=
$agent
->
getAgentInfo
(
'id,name,phone,store_id,district_id'
,
$agent_id
);
$remark
=
''
;
if
(
$type
==
'add'
)
{
$remark
=
'新增为'
.
$agent_data
[
'name'
]
.
'-'
.
$agent_data
[
'phone'
];
}
else
{
if
(
$agent_id
!=
$agent_id_old
)
{
$remark
=
'修改为'
.
$agent_data
[
'name'
]
.
'-'
.
$agent_data
[
'phone'
];
$this
->
pushMessage
(
$agent_id
,
$agent_id_old
,
$this
->
operation_id
,
$user_name
,
$user_id
);
//客户被修改客方后也进入保护期
$this
->
setUserProtectTime
(
$user_id
);
}
}
if
(
$remark
!=
''
)
{
$this
->
operating_records
(
$this
->
operation_id
,
3
,
$remark
,
$user_id
);
//记录日志
}
$result
[
'status'
]
=
'successful'
;
$result
[
'msg'
]
=
''
;
}
catch
(
\Exception
$e
)
{
$result
[
'status'
]
=
'fail'
;
$result
[
'msg'
]
=
$e
->
getMessage
();
}
return
$result
;
}
/**
* 记录邀请人修改记录
* @param $referrer_id
* @param $referrer_source
* @param $user_id
* @param $referrer_id_old
* @return array
*/
public
function
recordReferrer
(
$referrer_id
,
$referrer_source
,
$user_id
,
$referrer_id_old
)
{
$result
=
[];
$remark
=
''
;
try
{
if
(
$referrer_source
==
10
)
{
$user_data
=
$this
->
user
->
getUserById
(
'user_name,user_phone'
,
$referrer_id
);
$user_phone
=
empty
(
$user_data
[
'user_phone'
])
?
''
:
substr_replace
(
$user_data
[
'user_phone'
],
'****'
,
3
,
4
);
$name
=
$user_data
[
'user_name'
];
}
else
{
$m_agent
=
new
AAgents
();
$agent_where
[
'agent_id'
]
=
$referrer_id
;
$agent_data
=
$m_agent
->
getAgentById
(
'name,phone'
);
$name
=
$agent_data
[
0
][
'name'
];
$user_phone
=
$agent_data
[
0
][
'phone'
];
}
$if_inviter
=
$this
->
getUserInviterHistory
(
$user_id
);
//查询是否存在邀请人修改记录
if
(
!
$if_inviter
&&
$referrer_id
!=
-
1
)
{
//无记录则为新增
if
(
$referrer_source
==
10
)
{
$remark
=
'新增为'
.
$name
.
'-'
.
$user_phone
.
',客户ID:'
.
$referrer_id
;
}
else
{
$remark
=
'新增为'
.
$name
.
'-'
.
$user_phone
;
}
}
else
{
if
(
$referrer_id
==
-
1
)
{
if
(
$referrer_id
==
-
1
&&
!
empty
(
$referrer_id_old
)
&&
$if_inviter
)
{
$remark
=
'删除邀请人'
;
}
}
else
{
if
(
$referrer_id
!=
$referrer_id_old
&&
!
empty
(
$referrer_id
))
{
if
(
$referrer_source
==
10
)
{
$remark
=
'修改为'
.
$name
.
'-'
.
$user_phone
.
',客户ID:'
.
$referrer_id
;
}
else
{
$remark
=
'修改为'
.
$name
.
'-'
.
$user_phone
;
}
}
}
}
if
(
$remark
!=
''
)
{
$this
->
operating_records
(
$this
->
operation_id
,
5
,
$remark
,
$user_id
);
//邀请人修改-客户
}
$result
[
'status'
]
=
'successful'
;
$result
[
'msg'
]
=
""
;
}
catch
(
\Exception
$e
)
{
$result
[
'status'
]
=
'fail'
;
$result
[
'msg'
]
=
$e
->
getMessage
();
}
return
$result
;
}
/**
* 查询客户是否有邀请人
* @param $user_id
* @return array|false|\PDOStatement|string|\think\Collection
*/
public
function
getUserInviterHistory
(
$user_id
)
{
$m_records
=
new
GOperatingRecords
();
$param_
[
'user_id'
]
=
$user_id
;
$param_
[
'type'
]
=
5
;
return
$m_records
->
user_history
(
$param_
);
}
/**
* @param $code
* @return string
*/
public
function
getCodeMsg
(
$code
)
{
switch
(
$code
)
{
case
-
1
:
$msg
=
'该用户已存在'
;
break
;
case
-
2
:
$msg
=
'此号码为虚拟号码'
;
break
;
case
-
3
:
$msg
=
'没有新增和编辑VIP权限'
;
break
;
case
-
4
:
$msg
=
'客户信息错误,请检查!'
;
break
;
case
-
5
:
$msg
=
'市或区未选择'
;
break
;
default
:
$msg
=
'新增或编辑成功'
;
}
return
$msg
;
}
/**
* 记录操作
*
* @param int $agents_id
* @param string $type
* @param string $remark
* @param string $user_id
* @return bool|false|int
*/
public
function
operating_records
(
$agents_id
=
0
,
$type
=
''
,
$remark
=
''
,
$user_id
=
''
)
{
$records
=
new
GOperatingRecords
();
$result
=
$records
->
record
(
$agents_id
,
$type
,
$remark
,
''
,
$user_id
);
return
$result
;
}
/**
* 推送消息
*
* @param $agent_id
* @param $operation_id
* @param $user_name
* @param $user_id
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public
function
pushMessage
(
$agent_id
,
$old_agent_id
,
$operation_id
,
$user_name
,
$user_id
)
{
$push
=
new
PushMessageService
();
$agent
=
new
AAgents
();
$ccr_agent_data
=
$agent
->
getAgentInfo
(
'name'
,
$operation_id
);
$agent_name
=
$agent
->
getAgentInfo
(
'name'
,
$agent_id
);
$content
=
"你的【客户ID:
{
$user_id
}
】客户,客方被【
{
$ccr_agent_data
[
'name'
]
}
】修改为【
{
$agent_name
[
'name'
]
}
】"
;
$data
[
'message'
]
=
$content
;
$data
[
'user_id'
]
=
$user_id
;
$push
->
record
(
2
,
0
,
[
0
=>
$old_agent_id
],
$operation_id
,
$data
);
}
/**
* 查询客户是否在保护期内
* @param $user_id
* @return bool
*/
public
function
isUserProtect
(
$user_id
){
if
(
!
$user_id
){
return
1
;
}
$redis_cache
=
new
RedisCacheService
();
$user_data
=
$redis_cache
->
getRedisCache
(
1
,
$user_id
);
if
(
empty
(
$user_data
))
{
$res
=
$this
->
user
->
selectUser
(
$user_id
,
"id,protect_time,create_time"
);
}
else
{
if
(
$user_data
[
'status'
]
==
0
||
$user_data
[
'status'
]
==
-
1
)
{
$res
[
'protect_time'
]
=
$user_data
[
'protect_time'
];
}
}
if
(
empty
(
$res
[
'protect_time'
]))
{
return
1
;
//过保护期
}
/*先判断客户创建时间是否超过24小时 目的是兼容老数据 2018-10-20号之后的版本可去除此处代码*/
// if((time() - strtotime($res['create_time'])) < (60*60*24)){
// return 0;//保护期内
// }
/*目的是兼容老数据 2018-10-20号之后的版本可去除此处代码 end */
if
((
time
()
<
strtotime
(
$res
[
'protect_time'
])))
{
return
0
;
//保护期内
}
else
{
return
1
;
//过保护期
}
}
/**
* 经纪人客户是否有约带看 0:可查看 1:不可查看
* @param $agent_id
* @param $user_id
* @return int
*/
public
function
isReport
(
$agent_id
,
$user_id
){
if
(
!
$agent_id
or
!
$user_id
){
return
1
;
}
$time
=
time
();
$m_report
=
new
OReportModel
();
$begin_date
=
date
(
"Y-m-d H:i:s"
,
strtotime
(
"-1 week"
));
$end_date
=
date
(
"Y-m-d H:i:s"
,
$time
);
$conditions
[
'report_agent_id'
]
=
$agent_id
;
$conditions
[
'user_id'
]
=
$user_id
;
$conditions
[
'create_time'
]
=
array
(
'between'
,
array
(
$begin_date
,
$end_date
));
$report
=
$m_report
->
selectReportByIdTime
(
'id'
,
$conditions
);
if
(
count
(
$report
)
>
0
)
{
return
0
;
//有约带看
}
else
{
return
1
;
//无约带看
}
}
/**
* 编辑客户详情权限 0:有权限 1:无权限
* @param $user_agent_id
* @param $agent_id
* @return int
*/
public
function
isCanEditUserInfo
(
$user_agent_id
,
$agent_id
){
$is_can_edit_user_info
=
1
;
if
(
$user_agent_id
==
$agent_id
){
$is_can_edit_user_info
=
0
;
}
$s_vip
=
new
VipService
();
//0:有权限 1:无权限
$is_can_edit
=
$s_vip
->
vip
(
$agent_id
,
'index/pcEditClient'
);
if
(
$is_can_edit
==
0
)
{
$is_can_edit_user_info
=
0
;
}
return
$is_can_edit_user_info
;
}
/**
* 设置或者更新客户保护期
* @return mixed
*/
public
function
setUserProtectTime
(
$user_id
){
if
(
!
$user_id
){
return
false
;
}
$future_time
=
date
(
"Y-m-d H:i:s"
,
strtotime
(
"+1 day"
));
//24小时前的时间
$params_
[
'protect_time'
]
=
$future_time
;
$res
=
$this
->
user
->
updateUsers
(
$user_id
,
$params_
);
//int(1)
$redis_service
=
new
RedisCacheService
();
$redis_service
->
userCache
(
$user_id
);
if
(
$res
==
1
){
return
true
;
}
else
{
return
false
;
}
}
/**
* 设置客户站点
* @param $user_id
* @param $site_id
* @return bool
*/
public
function
setUserSites
(
$user_id
,
$site_id
)
{
if
(
!
$user_id
)
{
return
false
;
}
if
(
!
$site_id
)
{
return
false
;
}
//根据客户id查询
// $user_res = $this->user->selectUser($user_id, "id,site_ids");
/*if ($user_res['site_ids']) {
$site_ids_array = explode(',', rtrim($user_res['site_ids'], ','));
$site_ids_array_ = explode(',', rtrim($site_id, ','));
$site_ids_merge = array_merge($site_ids_array, $site_ids_array_);//数组合并
$site_ids_merge = array_unique($site_ids_merge);//数组去重
$site_ids = implode(",", $site_ids_merge);
} else {
$site_ids = $site_id;
}*/
$site_ids
=
$site_id
;
//保存数据
$params_
[
'site_ids'
]
=
$site_ids
;
$this
->
user
->
updateUsers
(
$user_id
,
$params_
);
//int(1)
$redis_service
=
new
RedisCacheService
();
$redis_service
->
userCache
(
$user_id
);
return
true
;
}
/**
* 查询当前经纪人是否是某个客方的总监
* @param $user_agent_id 1当前用户客方
* @param $agent_id 1当前登录用户
* @return int 0:可查看 1:不可查看
*/
public
function
isUserAgentDirector
(
$user_agent_id
,
$agent_id
){
if
(
!
$user_agent_id
){
return
1
;
}
if
(
!
$agent_id
){
return
1
;
}
$redis_server
=
new
RedisCacheService
();
$agent_data
=
$redis_server
->
getRedisCache
(
2
,
$user_agent_id
);
$agent_model
=
new
AAgents
();
if
(
empty
(
$agent_data
))
{
$params_
[
"id"
]
=
$user_agent_id
;
$result
=
$agent_model
->
searchAgentsByKeyword
(
"district_id"
,
$params_
);
}
else
{
$result
[
0
][
'district_id'
]
=
$agent_data
[
'district_id'
];
}
if
(
!
$result
){
return
1
;
}
$params__
[
'district_id'
]
=
$result
[
0
][
'district_id'
];
$params__
[
'level'
]
=
30
;
$result
=
$agent_model
->
searchAgentsByKeyword
(
"id"
,
$params__
);
if
(
isset
(
$result
[
0
][
'district_id'
])){
if
(
$result
[
0
][
'district_id'
]
==
$agent_id
)
{
return
0
;
//可查看
}
else
{
return
1
;
//不可查看
}
}
else
{
return
1
;
//不可查看
}
}
public
function
isUserByweiXin
(
$open_id
){
if
(
!
$open_id
){
return
false
;
}
$param
[
'wx_union_id'
]
=
$open_id
;
$fields
=
'a.user_phone'
;
$result
=
$this
->
user
->
getUserInfoByOpenId
(
$param
,
$fields
);
if
(
$result
)
{
return
true
;
}
else
{
return
false
;
}
}
/**
* 查询客户是否被经纪人收藏
* @param $agent_id
* @param $user_id
* @return int
*/
public
function
isCollect
(
$agent_id
,
$user_id
){
$is_collect
=
2
;
if
(
$agent_id
&&
$user_id
){
$field
=
'id,status'
;
$get_params
[
'agents_id'
]
=
$agent_id
;
$get_params
[
'user_id'
]
=
$user_id
;
$collect_house
=
new
ACollectUser
();
$res
=
$collect_house
->
getCollectUser
(
$field
,
$get_params
);
if
(
$res
&&
(
$res
[
0
][
'status'
]
==
1
))
{
$is_collect
=
1
;
}
}
return
$is_collect
;
}
/**
* 根据站点id组装站点名字
* @param string $site
* @return string
*/
public
function
userSiteName
(
$site
=
'10001,10002'
){
if
(
!
$site
){
return
''
;
}
$site_name
=
[];
foreach
(
explode
(
','
,
$site
)
as
$k
=>
$v
){
switch
(
$v
)
{
case
10001
:
$site_name
[]
=
'上海市'
;
break
;
case
10002
:
$site_name
[]
=
'杭州市'
;
break
;
case
10003
:
$site_name
[]
=
'深圳市'
;
break
;
case
10004
:
$site_name
[]
=
'广州市'
;
break
;
case
10005
:
$site_name
[]
=
'北京市'
;
break
;
default
:
}
}
return
implode
(
','
,
$site_name
);
}
/**
* 新增客户绑定
* @param $user_id
* @param $bind_id
* @return int
*/
public
function
addUserBind
(
$user_id
,
$bind_id
){
if
(
!
$user_id
or
!
$bind_id
){
return
'参数不全'
;
}
if
(
$user_id
==
$bind_id
){
return
'不得绑定自己'
;
}
// 先查当前用户bind_id是否等于0 user_id 当前详情页客户
$user_info
=
$this
->
user
->
getUserById
(
$field
=
'bind_id'
,
$user_id
);
if
(
$user_info
[
'bind_id'
]
!=
0
){
//排除主账号
$user_bind_count
=
$this
->
user
->
getBindCount
(
$bind_id
);
if
(
$user_bind_count
>
0
){
return
'当前客户已经存在绑定关系'
;
//当前客户已经存在绑定关系
}
$params_user_id
=
$bind_id
;
$params_bind_id
=
$user_info
[
'bind_id'
];
}
else
{
//=o 主账号
$b_user_info
=
$this
->
user
->
getUserById
(
$field
=
'bind_id'
,
$bind_id
);
if
(
$b_user_info
[
'bind_id'
]
==
0
){
//排除主账号
$user_bind_count
=
$this
->
user
->
getBindCount
(
$bind_id
);
if
(
$user_bind_count
>
0
){
return
'当前客户已经存在绑定关系'
;
//当前客户已经存在绑定关系
}
}
$params_user_id
=
$bind_id
;
$params_bind_id
=
$user_id
;
}
$bind_count
=
$this
->
userBindInfo
(
$params_bind_id
);
if
(
count
(
$bind_count
)
>
3
){
return
'绑定客户关系数超限'
;
}
$params_
[
'bind_id'
]
=
$params_bind_id
;
$res
=
$this
->
user
->
updateUsers
(
$params_user_id
,
$params_
);
if
(
$res
==
1
){
$redis_service
=
new
RedisCacheService
();
$redis_service
->
userCache
(
$user_id
);
return
true
;
}
else
{
return
'绑定失败或已绑定过'
;
}
}
/**
* 解除绑定关系
* @param $now_user_id //当前详情页客户
* @param $user_id //被取消对象客户id
* @param $agent_id //当前操作经纪人id
* @return int
*/
public
function
removeUserBind
(
$now_user_id
,
$user_id
,
$agent_id
){
// 检查权限 客方自己 有权限的人
$s_vip
=
new
VipService
();
$user_agent_id
=
$this
->
user
->
getUserByWhereValue
(
'agent_id'
,
[
'id'
=>
$now_user_id
]);
$is_can_edit
=
$s_vip
->
vip
(
$agent_id
,
'removeUserBind'
);
//0:有权限 1:无权限
if
((
$is_can_edit
==
1
)
&&
(
$user_agent_id
!=
$agent_id
))
{
return
2
;
//无解除关联权限权限
}
$now_user_info
=
$this
->
user
->
getUserById
(
$field
=
'bind_id'
,
$now_user_id
);
$params_
[
'bind_id'
]
=
0
;
if
(
$now_user_info
[
'bind_id'
]
==
0
){
//当前客户详情 客户 为主账户的情况
$this
->
user
->
updateUsers
(
$user_id
,
$params_
);
$this
->
userDoLog
(
$now_user_id
,
$user_id
,
$agent_id
);
}
else
{
//当前客户详情 客户 为子账户的情况
$id
=
$user_id
;
$this
->
userDoLog
(
$now_user_id
,
$user_id
,
$agent_id
);
if
(
$now_user_info
[
'bind_id'
]
==
$user_id
){
//如果要解绑的对象是 主账号 将当前页面客户bind_id 改 0
$id
=
$now_user_id
;
$this
->
userDoLog
(
$user_id
,
$now_user_id
,
$agent_id
);
}
$this
->
user
->
updateUsers
(
$id
,
$params_
);
}
$redis_service
=
new
RedisCacheService
();
$redis_service
->
userCache
(
$user_id
);
$redis_service
->
userCache
(
$now_user_id
);
return
0
;
}
/**
* 客户绑定详情
* @param $user_id
* @return false|\PDOStatement|string|\think\Collection
*/
public
function
userBindInfo
(
$user_id
){
if
(
!
$user_id
){
return
''
;
}
//bind_id是否等于0 是否主账号
$user_info
=
$this
->
user
->
getUserById
(
$field
=
'bind_id'
,
$user_id
);
$field
=
'id as user_id,user_nick,user_name,user_phone,bind_id,user_status'
;
if
(
$user_info
[
'bind_id'
]
==
0
){
//主账号只需要查bind_id等于当前用户的ID
$where
[
'bind_id'
]
=
$user_id
;
}
else
{
// 不等于0副号 把相同bind_id的查出来 主账号查出来 同时排除当前客户
$where
[]
=
[
'EXP'
,
"(bind_id = '
{
$user_info
[
'bind_id'
]
}
' or id = '
{
$user_info
[
'bind_id'
]
}
') and id != '
{
$user_id
}
'"
];
}
$user_info_list
=
$this
->
user
->
getUserByWhere
(
$where
,
$field
);
foreach
(
$user_info_list
as
$k
=>
$v
)
{
$user_info_list
[
$k
][
'user_phone'
]
=
preg_replace
(
'/(\d{3})\d{4}(\d{4})/'
,
'$1****$2'
,
$v
[
"user_phone"
]);
}
return
$user_info_list
;
}
/**
* 记录操作日志
* @param $id
* @param $remove_bind_id
* @param $agent_id
*/
private
function
userDoLog
(
$id
,
$remove_bind_id
,
$agent_id
)
{
$records
=
new
GOperatingRecords
();
$remark
=
'与ID: '
.
$remove_bind_id
.
'解除绑定关系'
;
$records
->
record
(
$agent_id
,
8
,
$remark
,
''
,
$id
);
}
/**
* 客户邀请人
* @param $phone
* @return int
*/
public
function
userInvite
(
$user_id
,
$phone
)
{
$m_agent
=
new
AAgents
();
// 判断经纪人表是否存在
$agent_res
=
$m_agent
->
findByOne
(
'id,name,phone'
,
[
"phone"
=>
$phone
,
"status"
=>
0
]);
// 判断客户表是否存在
$user_res
=
$this
->
user
->
findByOne
(
'id,user_name,user_phone'
,
[
"user_phone"
=>
$phone
,
"status"
=>
0
]);
if
(
!
$agent_res
&&
!
$user_res
){
return
4
;
}
if
(
$agent_res
)
{
// 邀请人 为 经纪人 经纪人表客户表同时存在
$referrer_source
=
20
;
$referrer_id
=
$agent_res
[
'id'
];
$name
=
$agent_res
[
'name'
];
$user_phone
=
$agent_res
[
'phone'
];
}
else
{
// 邀请人 为 经纪人 只存在于客户表
$referrer_source
=
10
;
$referrer_id
=
$user_res
[
'id'
];
$name
=
$agent_res
[
'user_name'
];
$user_phone
=
$agent_res
[
'user_phone'
];
}
if
((
$referrer_source
==
10
)
and
(
$user_id
==
$referrer_id
)){
return
2
;
//不能绑定自己
}
$res
=
$this
->
user
->
setUserInvite
(
$user_id
,
$referrer_source
,
$referrer_id
);
if
(
$res
==
1
){
//修改成功记录一下邀请人新增日志日志
$redis_service
=
new
RedisCacheService
();
$redis_service
->
userCache
(
$user_id
);
if
(
$referrer_source
==
10
)
{
$remark
=
'新增为'
.
$name
.
'-'
.
$user_phone
.
',客户ID:'
.
$referrer_id
;
}
else
{
$remark
=
'新增为'
.
$name
.
'-'
.
$user_phone
;
}
$this
->
operating_records
(
1
,
5
,
$remark
,
$user_id
);
//邀请人修改-客户
return
1
;
}
else
{
return
0
;
}
}
/**
* 判断是否已经存在客户邀请人
* @param $user_id
* @return bool
*/
public
function
verifyUserInvite
(
$user_id
)
{
$user_info
=
$this
->
user
->
getUserById
(
$field
=
'referrer_id'
,
$user_id
);
if
(
$user_info
[
'referrer_id'
]
>
0
){
return
false
;
}
return
true
;
}
}
\ No newline at end of file
application/model/OfficeFollowUpLogModel.php
0 → 100644
View file @
8481d1f5
<?php
namespace
app\model
;
/**
* Created by PhpStorm.
* User: zw
* Date: 2017/12/21
* Time: 14:41
*/
use
think\Db
;
use
think\Model
;
class
OfficeFollowUpLogModel
extends
Model
{
// 设置当前模型对应的完整数据表名称
protected
$table
=
'office_o_follow_up_log'
;
private
$db_
;
function
__construct
()
{
$this
->
db_
=
Db
::
name
(
$this
->
table
);
}
/**
* 新增跟进
* @param $params
* @return int
*/
public
function
addFollowUpLog
(
$params
)
{
$params
[
"create_time"
]
=
date
(
"Y-m-d H:i:s"
,
time
());
$params
[
"update_time"
]
=
date
(
"Y-m-d H:i:s"
,
time
());
Db
::
startTrans
();
try
{
$this
->
db_
->
insert
(
$params
);
Db
::
commit
();
return
1
;
}
catch
(
\Exception
$e
)
{
Db
::
rollback
();
return
0
;
}
}
/**
* 获取跟进数据
* @param $field_
* @param $where_
* @param $order_
* @return false|\PDOStatement|string|\think\Collection
*/
public
function
selectFollowUpList
(
$field_
,
$where_
,
$order_
)
{
if
(
isset
(
$where_
[
"agent_id"
]))
{
$data
=
$this
->
db_
->
field
(
$field_
)
->
where
(
$where_
)
->
order
(
$order_
)
->
select
();
}
else
{
$data
=
$this
->
db_
->
field
(
$field_
)
->
where
(
$where_
)
->
order
(
$order_
)
->
limit
(
1
)
->
select
();
}
return
$data
;
}
/**
* 查询跟进记录
* @param $field
* @param $params
* @return false|\PDOStatement|string|\think\Collection
*/
public
function
selectFollowUpListByReportId
(
$field
,
$params
)
{
$where_
=
[];
if
(
isset
(
$params
[
"report_id"
]))
{
$where_
[
"report_id"
]
=
$params
[
"report_id"
];
}
if
(
isset
(
$params
[
"agent_id"
]))
{
$where_
[
"agent_id"
]
=
$params
[
"agent_id"
];
}
return
$this
->
db_
->
field
(
$field
)
->
where
(
$where_
)
->
select
();
}
public
function
getFollowUpByOrderId
(
$field
,
$params
){
$where_
=
[];
if
(
isset
(
$params
[
"report_id"
]))
{
$where_
[
"report_id"
]
=
$params
[
"report_id"
];
}
if
(
isset
(
$params
[
"agent_id"
]))
{
$where_
[
"agent_id"
]
=
$params
[
"agent_id"
];
}
return
Db
::
table
(
$this
->
table
)
->
field
(
$field
)
->
alias
(
"a"
)
->
join
(
"a_agents b"
,
"a.agent_id = b.id"
,
"left"
)
->
join
(
"a_store c"
,
"b.store_id = c.id"
,
"left"
)
->
join
(
"o_report d"
,
"a.report_id = d.id"
,
"left"
)
->
where
(
$where_
)
->
select
();
}
/**
* 获取经纪人新增带看数量
* @param $params
* @return int|string
*/
public
function
getAddFollowUpNumByAgentId
(
$params
){
$where_
=
[];
if
(
isset
(
$params
[
"agent_id"
])){
$where_
[
"agent_id"
]
=
$params
[
"agent_id"
];
}
if
(
isset
(
$params
[
"create_time"
])){
$where_
[
"create_time"
]
=
$params
[
"create_time"
];
}
return
$this
->
db_
->
where
(
$where_
)
->
count
();
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment