Commit 880737df authored by clone's avatar clone

客户动态

parent bac92942
......@@ -13,6 +13,7 @@ use app\api\untils\GenerateCodeUntils;
use app\api\untils\JwtUntils;
use app\api\untils\MessageUntils;
use app\api_broker\extend\Basic;
use app\api_broker\service\OrderLogService;
use app\model\AAgents;
use app\model\GOperatingRecords;
use app\model\NoteLog;
......@@ -233,21 +234,26 @@ class Broker extends Basic
{
header('Access-Control-Allow-Origin:*');
$params = $this->params;
/* $params = array(
"user_id" => 1
);*/
if (!isset($params['user_id'])) {
return $this->response("300", "参数不全", [ 'remote_groupid' => '' ]);
}
$user_id = $params['user_id'];
$searchdate = empty($params['searchdate']) ? '':$params['searchdate'];
$agent = new AAgents();
/* $searchdate = empty($params['searchdate']) ? '':$params['searchdate'];
$pagenum = isset($params['pagenum']) ? $params['pagenum'] : 1;
$pagesize = 15;
$user_id = $params['user_id'];
$UPhoneFollowPp = new UPhoneFollowPp();
// 查询电话跟进数据
$UPhoneFollowPp_res = $UPhoneFollowPp->select_useraction_search($user_id,$searchdate);
$agent = new AAgents();
foreach($UPhoneFollowPp_res as $k=>$v){
$agents_res = $agent->verifyUser('name,phone,img','',['id'=>$v['agent_id']]);
$UPhoneFollowPp_res[$k]['agentinfo'] = $agents_res ? $agents_res['name'].'-'.$agents_res['phone']:'未知';
......@@ -260,7 +266,7 @@ class Broker extends Basic
$table_res = $labels->get_labelsname($v['labels_id']);
$UPhoneFollowPp_res[$k]['label'] = $table_res[0]['name'];
}
}
}*/
$user = new Users();
$user_res = $user->useraction_search_user_res($user_id);
......@@ -270,10 +276,11 @@ class Broker extends Basic
$agents_res = $agent->verifyUser('name,phone','', ['id'=>$user_res['agent_id']]);
$user_res['agentinfo'] = $agents_res ? $agents_res['name'].'-'.$agents_res['phone']:'未知';
$orderLog = new OrderLogService();
$records = new GOperatingRecords();
$records_result = $records->user_history($user_id);
$data['user_info'] = $user_res;
$data['user_date'] = $UPhoneFollowPp_res;
$data['user_date'] = $orderLog->selectListByUserId($user_id,'');
$data['user_history'] = $records_result;
return $this->response("200", "success!", $data);
}
......
......@@ -12,6 +12,7 @@ use app\model\OrderModel;
use app\model\ORefundModel;
use app\model\OReportModel;
use app\model\Regions;
use app\model\UPhoneFollowPp;
use app\model\Users;
......@@ -195,7 +196,7 @@ class OrderLogService
}
/**
* 查询流程
* 查询流程 订单时间轴
* @param $order_id
* @return array
*/
......@@ -216,7 +217,7 @@ class OrderLogService
$orderData = $orderModel->selectOrderByOrderId("f_id,house_title", [ "order_id" => $order_id ]);
//dump($orderData);
if (count($orderData) == 0) {
if (count($orderData) <= 0) {
return [ "101", "找不到此订单编号" ];
}
$report_id = $orderData[0]["f_id"];
......@@ -294,10 +295,156 @@ class OrderLogService
return $this->sortByTime($result);
}
/**
* 查询流程 客户动态
* @param $user_id
* @param $search | null
* @return array
*/
public function selectListByUserId($user_id, $search = "")
{
$result = [];
$sort = 0;
//todo 1.验证订单是否存在
$orderModel = new OrderModel();
$oReportModel = new OReportModel();
$oMarchInModel = new OMarchInModel();
$followUpLogModel = new FollowUpLogModel();
$oPayLogModel = new OPayLogModel();
$oRefundModel = new ORefundModel();
$oBargainModel = new OBargainModel();
$field_report = "a.id,a.create_time,b.id as order_id,b.house_title,c.id as agent_id,c.name,c.img,d.store_name";
$reportData = $oReportModel->selectReportByUserId($field_report, [ "user_id" => $user_id ]);
if (count($reportData) <= 0) {
return [ "101", "报备记录未找到" ];
}
$order_ids = $report_ids = "";
//报备
foreach ($reportData as $k => $v) {
$v["step_name"] = "report";
$v["step"] = "报备【".$v['house_title']."】";
$result[$sort++] = $v;
$order_ids .= $v["order_id"] . ",";
$order_ids = rtrim($order_ids, ",");
$report_ids .= $v["id"] . ",";
$report_ids = rtrim($report_ids, ",");
}
$orderParams["order_id"] = array( "in", $order_ids );
$orderParams["house_title"] = array( "like" , "%" . trim($search) . "%" );
$reportParams["report_id"] = array( "in", $report_ids );
//进场 march in
$field_march_in = "a.id,a.reception_id,a.create_time,b.id as order_id,b.house_id,b.house_title,c.id as agent_id,c.name,c.img,d.store_name";
$marchInData = $oMarchInModel->getMarchInListByOrderId($field_march_in, $orderParams);
if (count($marchInData) > 0) {
foreach ($marchInData as $k => $v) {
$v["step_name"] = "march_in";
$v["step"] = "进场【".$v['house_title']."】";
$result[$sort++] = $v;
}
}
//跟进
$field_follow_up = "id,agent_id,agent_name,user_type,decision_maker,industry_type,area_requirement,price_requirement,province,city,
district,business_area,explain,explain_img,create_time";
$followUpLogData = $followUpLogModel->selectFollowUpListByReportId($field_follow_up, $reportParams);
if (count($followUpLogData) > 0) {
foreach ($followUpLogData as $k => $v) {
$v["step_name"] = "follow_up_log";
$v["step"] = "进场";
$v = $this->convertFollowUp($v);
$v["img_path"] = CHAT_IMG_URL;
$result[$sort++] = $v;
}
}
//收款
$field_pay_log = "a.id,a.create_time,b.id as order_id,b.house_id,b.house_title,c.id as agent_id,c.name,c.img,d.store_name";
$payLogData = $oPayLogModel->getPayLogByOrderId($field_pay_log, $orderParams);
if (count($payLogData) > 0) {
foreach ($payLogData as $k => $v) {
$v["step_name"] = "pay_log";
$v["step"] = "收款【".$v['house_title']."】";
$result[$sort++] = $v;
}
}
//退款
$field_refund = "a.id,a.create_time,b.id as order_id,b.house_id,b.house_title,c.id as agent_id,c.name,c.img,d.store_name";
$refundData = $oRefundModel->getRefundByOrderId($field_refund, $orderParams);
if (count($refundData) > 0) {
foreach ($refundData as $k => $v) {
$v["step_name"] = "refund";
$v["step"] = "退款【".$v['house_title']."】";
$result[$sort++] = $v;
}
}
//成交报告
$field_bargain = "a.id,a.create_time,b.id as order_id,b.house_id,b.house_title,c.id as agent_id,c.name,c.img,d.store_name";
$bargainData = $oBargainModel->getBargainByOrderId($field_bargain, $orderParams);
if (count($bargainData) > 0) {
foreach ($bargainData as $k => $v) {
$v["step_name"] = "bargain";
$v["step"] = "成交报告【".$v['house_title']."】";
$result[$sort++] = $v;
}
}
$uPhoneFollowModel = new UPhoneFollowPp();
//电话跟进
$userParams["user_id"] = $user_id;
$userParams["type"] = 0; //电话跟进
$field_user_follow = "a.id,a.content,a.user_id,a.agent_id,a.type,a.create_time,a.user_status,b.name,b.phone,b.img,c.store_name";
$bargainData = $uPhoneFollowModel->getFollowUpListByUserId($field_user_follow, $userParams);
if (count($bargainData) > 0) {
foreach ($bargainData as $k => $v) {
$type = "无效";
if($v["user_status"] == 0){
$type = "求租";
}elseif($v["user_status"] == 1){
$type = "已租";
}
$v["step_name"] = "phone_follow_up";
$v["step"] = "电话跟进:".$v['content']."【". $type ."】";
$result[$sort++] = $v;
}
}
//跟进
$userParams["type"] = 1; //普通跟进
$bargainData = $uPhoneFollowModel->getFollowUpListByUserId($field_user_follow, $userParams);
if (count($bargainData) > 0) {
foreach ($bargainData as $k => $v) {
$type = "无效";
if($v["user_status"] == 0){
$type = "求租";
}elseif($v["user_status"] == 1){
$type = "已租";
}
$v["step_name"] = "follow_up";
$v["step"] = "跟进:".$v['content']."【". $type ."】";
$result[$sort++] = $v;
}
}
return $this->sortByTime($result);
}
private function convertFollowUp($item)
{
// $field_follow_up = "id,user_type,decision_maker,industry_type,area_requirement,price_requirement,province,city,
// district,business_area,explain,explain_img,create_time";
switch ($item["user_type"]) {
case 1:
$item["user_type"] = "A类(成交意愿较强)";
......
......@@ -134,6 +134,24 @@ class OBargainModel extends Model
->select();
}
public function getBargainByOrderId($field,$params){
$where_ = [];
if(isset($params["order_id"])){
$where_["a.order_id"] = $params["order_id"];
}
if(isset($params["house_title"])){
$where_["b.house_title"] = $params["house_title"];
}
return Db::table($this->table)
->field($field)
->alias("a")
->join("o_order b","a.order_id = b.id","left")
->join("a_agents c","a.agent_id = c.id","left")
->join("a_store d","c.store_id = d.id","left")
->where($where_)
->select();
}
/**
* 获取我得成交
*
......
......@@ -154,4 +154,22 @@ class OMarchInModel extends Model
->select();
}
public function getMarchInListByOrderId($field,$params){
$where_ = [];
if(isset($params["order_id"])){
$where_["a.order_id"] = $params["order_id"];
}
if(isset($params["house_title"])){
$where_["b.house_title"] = $params["house_title"];
}
return Db::table($this->table)
->field($field)
->alias("a")
->join("o_order b","a.order_id = b.id","left")
->join("a_agents c","a.reception_id = c.id","left")
->join("a_store d","c.store_id = d.id","left")
->where($where_)
->select();
}
}
\ No newline at end of file
......@@ -77,6 +77,23 @@ class OPayLogModel extends Model
->where($where_)
->select();
}
public function getPayLogByOrderId($field,$params){
$where_ = [];
if(isset($params["order_id"])){
$where_["a.order_id"] = $params["order_id"];
}
if(isset($params["house_title"])){
$where_["b.house_title"] = $params["house_title"];
}
return Db::table($this->table)
->field($field)
->alias("a")
->join("o_order b","a.order_id = b.id","left")
->join("a_agents c","a.agent_id = c.id","left")
->join("a_store d","c.store_id = d.id","left")
->where($where_)
->select();
}
/**
* @param $params
......
......@@ -104,4 +104,22 @@ class ORefundModel extends Model{
->where($where_)
->select();
}
public function getRefundByOrderId($field,$params){
$where_ = [];
if(isset($params["order_id"])){
$where_["a.order_id"] = $params["order_id"];
}
if(isset($params["house_title"])){
$where_["b.house_title"] = $params["house_title"];
}
return Db::table($this->table)
->field($field)
->alias("a")
->join("o_order b","a.order_id = b.id","left")
->join("a_agents c","a.agent_id = c.id","left")
->join("a_store d","c.store_id = d.id","left")
->where($where_)
->select();
}
}
\ No newline at end of file
......@@ -81,6 +81,43 @@ class OReportModel extends Model
->select();
}
/**
* 查询报备信息
*
* @param string $filed
* @param $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function selectReportByUserId($filed = "id", $params)
{
$where_ = [];
if (isset($params["id"])) {
$where_["a.id"] = $params["id"];
}
if (isset($params["report_agent_id"])) {
$where_["a.report_agent_id"] = $params["report_agent_id"];
}
if (isset($params["report_store_id"])) {
$where_["a.report_store_id"] = $params["report_store_id"];
}
if (isset($params["user_id"])) {
$where_["a.user_id"] = $params["user_id"];
}
$where_["a.status"] = 0;
return $this->db
->field($filed)
->alias("a")
->join("o_order b","a.id = b.f_id","left")
->join("a_agents c","a.report_agent_id = c.id","left")
->join("a_store d","c.store_id = d.id","left")
->where($where_)
->select();
}
/**
* @param string $filed
* @param $params
......
<?php
namespace app\model;
use think\Db;
......@@ -39,8 +40,9 @@ class UPhoneFollowPp extends BaseModel
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getSearch($p = 1, $pageSize = 15, $order_= 'id desc',$field,$join, $where,$group){
$r = $this->field($field)
public function getSearch($p = 1, $pageSize = 15, $order_ = 'id desc', $field, $join, $where, $group)
{
$r = $this->field($field)
->alias('f')
->join($join)
->where($where)
......@@ -51,13 +53,13 @@ class UPhoneFollowPp extends BaseModel
->select();
$data = array();
foreach($r as $k=>$v){
foreach ($r as $k => $v) {
$data[$k] = $v;
if($v['agent_id']){
$data[$k]['imagename']='http://admin.tonglianjituan.com/agentsimg/'.Db::table('agentsimgs')->field('imagename')
->where("agent_id={$v['agent_id']}")
->order('id desc')
->value('imagename');
if ($v['agent_id']) {
$data[$k]['imagename'] = 'http://admin.tonglianjituan.com/agentsimg/' . Db::table('agentsimgs')->field('imagename')
->where("agent_id={$v['agent_id']}")
->order('id desc')
->value('imagename');
}
}
......@@ -65,7 +67,8 @@ class UPhoneFollowPp extends BaseModel
}
public function getUserAgentTotal($params,$join) {
public function getUserAgentTotal($params, $join)
{
$result = $this->alias('f')
->join($join)
->where($params)->count();
......@@ -77,12 +80,12 @@ class UPhoneFollowPp extends BaseModel
* @param $searchdate
* @return mixed
*/
public function select_useraction_search($user_id,$searchdate)
public function select_useraction_search($user_id, $searchdate)
{
if($searchdate){
$UPhoneFollowPp_res = db('u_phone_follow_up')
->where('user_id',$user_id)
->where('content',$searchdate)
if ($searchdate) {
$UPhoneFollowPp_res = db('u_phone_follow_up')
->where('user_id', $user_id)
->where('content', $searchdate)
->order('create_time', 'desc')
//->limit($pagesize)
//->page($pagenum)
......@@ -91,9 +94,9 @@ class UPhoneFollowPp extends BaseModel
->where('user_id',$user_id)
->where('content',$searchdate)
->count();*/
}else{
$UPhoneFollowPp_res = db('u_phone_follow_up')
->where('user_id',$user_id)
} else {
$UPhoneFollowPp_res = db('u_phone_follow_up')
->where('user_id', $user_id)
->order('create_time', 'desc')
//->limit($pagesize)
//->page($pagenum)
......@@ -106,9 +109,34 @@ class UPhoneFollowPp extends BaseModel
return $UPhoneFollowPp_res;
}
public function phone_up_list($pagesize,$pagenum)
/*zw start**/
public function getFollowUpListByUserId($field, $params)
{
$where_ = [];
if (isset($params["user_id"])) {
$where_["a.user_id"] = $params["user_id"];
}
if (isset($params["type"])) {
$where_["a.type"] = $params["type"];
}
$result = Db::name($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")
->where($where_)
->select();
return $result;
}
/*zw end**/
public function phone_up_list($pagesize, $pagenum)
{
$UPhoneFollowPp_res = db('u_phone_follow_up')
$UPhoneFollowPp_res = db('u_phone_follow_up')
->order('create_time', 'desc')
->limit($pagesize)
->page($pagenum)
......@@ -116,19 +144,20 @@ class UPhoneFollowPp extends BaseModel
return $UPhoneFollowPp_res;
}
public function phone_up_list_count()
{
$UPhoneFollowPp_res = db('u_phone_follow_up')
$UPhoneFollowPp_res = db('u_phone_follow_up')
->count();
return $UPhoneFollowPp_res;
}
public function all_user_search($searchdate,$pagesize,$pagenum)
public function all_user_search($searchdate, $pagesize, $pagenum)
{
$UPhoneFollowPp_res = db('u_phone_follow_up')
$UPhoneFollowPp_res = db('u_phone_follow_up')
//->where('user_id',$user_id)
->where('content','like',"%$searchdate%")
->where('content', 'like', "%$searchdate%")
->order('create_time', 'desc')
->limit($pagesize)
->page($pagenum)
......@@ -142,9 +171,9 @@ class UPhoneFollowPp extends BaseModel
public function all_user_search_count($searchdate)
{
$UPhoneFollowPp_res = db('u_phone_follow_up')
$UPhoneFollowPp_res = db('u_phone_follow_up')
//->where('user_id',$user_id)
->where('content','like',"%$searchdate%")
->where('content', 'like', "%$searchdate%")
//->limit($pagesize)
//->page($pagenum)
->count();
......
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