Commit 8c850986 authored by hujun's avatar hujun

拨打电话默认跟进

parent 69b5ee8a
......@@ -38,11 +38,19 @@ class CallPhoneService
private $day_num = 0; //号码绑定有效期
private $landlord_phone_day = 0; //房东号码绑定有效期
private $city;
public $redis;
public function __construct(string $city = '上海市')
{
$this->readRedis();
$this->city = $city;
$this->redis = RedisExt::getRedis();
$this->is_privacy = $this->redis->get('s_is_privacy');
$this->day_num = $this->redis->get('s_day_num');
$this->landlord_phone_day = $this->redis->get('s_landlord_phone_day');
$this->is_privacy = empty($this->is_privacy) ? 0 : $this->is_privacy;
$this->day_num = empty($this->day_num) ? 1 : $this->day_num;
$this->landlord_phone_day = empty($this->landlord_phone_day) ? 1 : $this->landlord_phone_day;
}
/**
......@@ -73,7 +81,9 @@ class CallPhoneService
$this->user_id = $user_id;
$user_data = $this->getUserData();
if (empty($user_data['user_phone'])) {
return $this->response(101, '没有用户信息');
$result['status'] = 'fail';
$result['msg'] = '没有用户信息';
return $result;
}
$phone_b = $user_data['user_phone'];
......@@ -101,20 +111,20 @@ class CallPhoneService
$this->agent_id = $agent_id;
$this->agent_name = $agent_name;
try {
$result['follow_id'] = 0;
if ($landlord) {
if ($house_id) {
$this->recordCallRedis($agent_id, $house_id, $this->phone_a, $this->phone_b, 2);
}
} else {
$this->recordCallRedis($agent_id, $user_id, $this->phone_a, $this->phone_b);
}
//0不使用隐私号码 1阿里云 2容联云
if ($this->is_privacy == 0) {
$this->originalPhone();
$result['status'] = 'success';
$result['phone'] = $phone_b;
// if ($landlord) {
// if ($house_id) {
// $result['follow_id'] = $this->addPhoneFollow(false, $house_id); //打默认跟进(房源)
// }
// } else {
// $result['follow_id'] = $this->addPhoneFollow(); //打默认跟进(客源)
// }
$result['follow_id'] = 0;
return $result;
}
......@@ -130,15 +140,6 @@ class CallPhoneService
$result['status'] = 'success';
$result['phone'] = $phone_x['phone_x'];
$result['msg'] = '已绑定,返回隐私号码。';
// if ($landlord) {
// if ($house_id) {
// $result['follow_id'] = $this->addPhoneFollow(false, $house_id); //打默认跟进(房源)
// }
// } else {
// $result['follow_id'] = $this->addPhoneFollow(); //打默认跟进(客源)
// }
$result['follow_id'] = 0;
return $result; //绑定过了,返回隐号
}
......@@ -185,15 +186,6 @@ class CallPhoneService
if ($result['status'] == 'success') {
$bind->recordBindPhone($call_phone['phone'], $phone_a, $phone_b, $record, $this->expiry_date, $this->subs_id, $this->request_id, $this->mapping_id, $this->is_privacy, $this->release);
// if ($landlord) {
// if ($house_id) {
// $result['follow_id'] = $this->addPhoneFollow(false, $house_id); //打默认跟进(客源)
// }
// } else {
// $result['follow_id'] = $this->addPhoneFollow(); //打默认跟进(房源)
// }
$result['follow_id'] = 0;
}
Log::write(json_encode($result), $type); //记录日志
......@@ -415,49 +407,96 @@ class CallPhoneService
}
/**
* 读取配置
* 查询经纪人与客户绑定数量
*
* @param $phone_a
* @param $phone_b
* @param $status
* @return int|string
*/
public function readRedis() {
$redis = RedisExt::getRedis();
$this->is_privacy = $redis->get('s_is_privacy');
$this->day_num = $redis->get('s_day_num');
$this->landlord_phone_day = $redis->get('s_landlord_phone_day');
$this->is_privacy = empty($this->is_privacy) ? 0 : $this->is_privacy;
$this->day_num = empty($this->day_num) ? 1 : $this->day_num;
$this->landlord_phone_day = empty($this->landlord_phone_day) ? 1 : $this->landlord_phone_day;
public function getBindNum( $phone_b, $phone_a, $status = 1) {
$m_bind = new BindingPhone();
return $m_bind->getCallNumber($phone_a, $phone_b, $status);
}
/**
* 打默认跟进
*
* @param bool $is_Client true客源跟进 false 商铺跟进
* @param int $house_id
* @return int|string
* 默认跟进,供定时任务使用
*/
private function addPhoneFollow($is_Client = true, $house_id = 0) {
public function defaultFollowUp() {
$m_follow_up = new UPhoneFollowPp();
$m_follow_house = new GHousesFollowUp();
$current_time = time();
$time = $current_time - 3600;
$start_date = date('Y-m-d', $time);
$end_date = date('Y-m-d');
$user_key = 'call_phone_user_'.$end_date;
$landlord_key = 'call_phone_landlord_'.$end_date;
$user_data = $this->redis->hKeys($user_key);
$landlord_data = $this->redis->hKeys($landlord_key);
$content = '拨打电话,未打跟进。';
if ($is_Client) {
$follow = new UPhoneFollowPp();
$id = $follow->insertDefaultFollow($this->agent_id, $this->user_id, $content, 0, $this->city);
} else {
$follow = new GHousesFollowUp();
$id = $follow->insertDefaultFollow($this->agent_id, $house_id, $content, $this->city, $this->phone_b, $this->phone_a, $this->agent_name);
$follow_where['create_time'] = ['between', [$start_date, $end_date]];
//用户
if (!empty($user_data)) {
foreach ($user_data as $k=>$v) {
$call_time = $this->redis->hGet($user_key, $v);
if ($current_time - $call_time > 3600) {
$array = explode('-', $v);
$follow_where['agent_id'] = $array[0];
$follow_where['user_id'] = $array[1];
$num = $m_follow_up->getFollowTotal($follow_where);
if (empty($num)) {
$m_follow_up->insertDefaultFollow($array[0], $array[1], $content, 0);
$this->redis->hDel($user_key, $v);
}
}
}
}
//房东
if (!empty($landlord_data)) {
foreach ($landlord_data as $k2=>$v2) {
$call_time = $this->redis->hGet($landlord_key, $v2);
if ($current_time - $call_time > 3600) {
$array = explode('-', $v2);
$follow_where['agent_id'] = $array[0];
$follow_where['house_id'] = $array[1];
$is = $m_follow_house->getFollowUpByHouseId($follow_where);
if (!$is) {
$m_follow_house->insertDefaultFollow($array[0], $array[1], $content, $array[3], $array[2]);
$this->redis->hDel($landlord_key, $v2);
}
}
}
}
return $id;
return ;
}
/**
* 查询经纪人与客户绑定数量
* 记录拨打
*
* @param $phone_a
* @param $phone_b
* @param $status
* @return int|string
* @param $agent_id
* @param $user_id
* @param $user_type
*/
public function getBindNum( $phone_b, $phone_a, $status = 1) {
$m_bind = new BindingPhone();
return $m_bind->getCallNumber($phone_a, $phone_b, $status);
public function recordCallRedis($agent_id, $user_id, $phone_a, $phone_b, $user_type = 1) {
$date = date('Y-m-d');
if ($user_type == 1) {
$key = 'call_phone_user_'.$date;
} else {
$key = 'call_phone_landlord_'.$date;
}
$this->redis->hSet($key, $agent_id.'-'. $user_id . '-'. $phone_a .'-'. $phone_b, time());
return ;
}
}
\ No newline at end of file
......@@ -59,9 +59,9 @@ class AliYunSecretReport extends BaseModel
if ($phone_b) {
$where['peer_no'] = $phone_b;
}
if (!empty($start_date) && !empty($end_date)) {
$where['create_time'] = ['between time', $start_date. ' 00:00:00', $start_date . ' 23:59:59'];
$where['create_time'] = ['between time', $start_date. ' 00:00:00', $end_date . ' 23:59:59'];
} else {
$date = date('Y-m-d');
$where['create_time'] = ['between time', [$date. ' 00:00:00', $date . ' 23:59:59']];
......@@ -72,4 +72,35 @@ class AliYunSecretReport extends BaseModel
return $this->where($where)
->count();
}
/**
* @param $phone_a
* @param $phone_b
* @param $start_date
* @param $end_date
* @return array|false|\PDOStatement|string|\think\Collection
*/
public function getCallTimeList($start_date, $end_date, $field = 'agents_id,users_id') {
if (!empty($start_date) && !empty($end_date)) {
$where['create_time'] = ['between time', [$start_date, $end_date]];
} else {
$date = date('Y-m-d');
$where['create_time'] = ['between time', [$date. ' 00:00:00', $date . ' 23:59:59']];
}
$where['time'] = ['>', 0];
try {
$data['data'] = $this->field($field)
->where($where)
->select();
$data['status'] = 'successful';
} catch (\Exception $e) {
$data['data'] = [];
$data['status'] = 'fail';
}
return $data;
}
}
\ No newline at end of file
......@@ -49,8 +49,6 @@ class GHousesFollowUp extends BaseModel
if (isset($params['landlord_name'])) {
$where_['landlord_name'] = $params['landlord_name'];
}
if (isset($params["province"])) {
$where_["province"] = $params["province"];
}
......@@ -61,15 +59,14 @@ class GHousesFollowUp extends BaseModel
$where_["disc"] = $params["disc"];
}
$where_["create_time"] = date("Y-m-d H:i:s", time());
$where_["update_time"] = date("Y-m-d H:i:s", time());
Db::startTrans();
try {
if (empty($params['id'])) {
$id = $this->db_->insertGetId($where_);
$where_["create_time"] = date("Y-m-d H:i:s", time());
$id = $this->db_->table($this->table)->insertGetId($where_);
} else {
$this->db_->where('id',$params['id'])->update($where_);
$where_["update_time"] = date("Y-m-d H:i:s", time());
$this->db_->table($this->table)->where('id',$params['id'])->update($where_);
$id = $params['id'];
}
......@@ -151,9 +148,6 @@ class GHousesFollowUp extends BaseModel
/**
* @param array $params
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getFollowUpByHouseId(array $params): bool
{
......@@ -164,10 +158,19 @@ class GHousesFollowUp extends BaseModel
if (isset($params["house_id"])) {
$where_["house_id"] = $params["house_id"];
}
$follow_list = $this
->field("id")
->where($where_)
->select();
if (isset($params["agent_id"])) {
$where_["agent_id"] = $params["agent_id"];
}
try {
$follow_list = $this
->field("id")
->where($where_)
->select();
} catch (\Exception $e) {
$follow_list = [];
}
if (count($follow_list) > 0) {
return true;
}
......@@ -180,30 +183,33 @@ class GHousesFollowUp extends BaseModel
* @param $agent_id
* @param $house_id
* @param $content
* @param $city
* @param $landlord_phone
* @param $agent_phone
* @param $agent_name
* @return int|string
*/
public function insertDefaultFollow($agent_id, $house_id, $content, $city, $landlord_phone, $agent_phone, $agent_name) {
public function insertDefaultFollow($agent_id, $house_id, $content, $landlord_phone, $agent_phone) {
$data['agent_id'] = $agent_id;
$data['house_id'] = $house_id;
$data['follow_up_info'] = $content;
$data['city'] = $city;
if ($city == '上海市') {
$data['province'] = '上海市';
$data['disc'] = '黄浦区';
}
if ($city == '杭州市') {
$data['province'] = '浙江省';
$data['disc'] = '西湖区';
if ($house_id > 0) {
try {
$house_data = $this->db_->table('u_users')->field('province,city,disc')->find($house_id);
$data['province'] = $house_data['province'];
$data['city'] = $house_data['city'];
$data['disc'] = $house_data['disc'];
$house_data = $this->db_->table('a_agents')->field('name')->find($agent_id);
$data['agent_name'] = $house_data['name'];
} catch (\Exception $e) {
$data['province'] = "";
$data['city'] = "";
$data['disc'] = "";
$data['agent_name'] = "";
$data['agent_phone'] = "";
}
}
$data['landlord_phone'] = $landlord_phone;
$data['agent_name'] = $agent_name;
$data['agent_phone'] = $agent_phone;
return $this->addHousesFollowUp($data);
}
......
......@@ -165,7 +165,8 @@ class MPushMessage
*/
public function selectAgentHouse($house_id) {
$m_house = new GHousesToAgents();
$where['a.house_id'] = $house_id;
$where['a.houses_id'] = $house_id;
$where['a.type'] = 2;
$result = $m_house->getHouseAgent('agents_id', $where);
$data = [];
......
......@@ -101,33 +101,6 @@ class UPhoneFollowPp extends BaseModel
return $data;
}
/**
* @param $where
* @return int
*/
public function getSearchCount( $where)
{
$r = $this
->alias('f')
->where($where)
->count();
return $r;
}
/**
* @param $join
* @param $where
* @return int
*/
public function getCount( $where)
{
$r = $this
->where($where)
->count();
return $r;
}
public function getUserAgentTotal($params, $join)
{
$result = $this->alias('f')
......@@ -350,23 +323,24 @@ class UPhoneFollowPp extends BaseModel
* @param $user_id
* @param $content
* @param $type
* @param $city
* @return int|string
*/
public function insertDefaultFollow($agent_id, $user_id, $content, $type, $city) {
public function insertDefaultFollow($agent_id, $user_id, $content, $type) {
$data['agent_id'] = $agent_id;
$data['user_id'] = $user_id;
$data['content'] = $content;
$data['city'] = $city;
if ($city == '上海市') {
$data['province'] = '上海市';
$data['disc'] = '黄浦区';
}
if ($city == '杭州市') {
$data['province'] = '浙江省';
$data['disc'] = '西湖区';
if ($user_id > 0) {
try {
$user_data = Db::table('u_users')->field('province,city,disc')->find($user_id);
$data['province'] = $user_data['province'];
$data['city'] = $user_data['city'];
$data['disc'] = $user_data['disc'];
} catch (\Exception $e) {
$data['province'] = "";
$data['city'] = "";
$data['disc'] = "";
}
}
$data['type'] = $type;
......
......@@ -422,6 +422,7 @@ Route::group('task', [
'rongBilledInformUrl' => [ 'task/PrivacyNumber/rongBilledInformUrl', [ 'method' => 'post | get' ] ],//隐私号码回调[话单通知]
'rongRecordingInformUrl' => [ 'task/PrivacyNumber/rongRecordingInformUrl', [ 'method' => 'post | get' ] ],//隐私号码回调[录音通知]
'rongStatusInformUrl' => [ 'task/PrivacyNumber/rongStatusInformUrl', [ 'method' => 'post | get' ] ],//隐私号码回调[状态通知]
'defaultFollowUp' => [ 'task/PrivacyNumber/defaultFollowUp', [ 'method' => 'post | get' ] ] //默认跟进
]);
Route::group('broker', [
......
......@@ -8,6 +8,7 @@
namespace app\task\controller;
use app\api_broker\service\CallPhoneService;
use app\api_broker\service\ClientService;
use app\api_broker\untils\PlsDemo;
use app\api_broker\untils\RongDemo;
......@@ -293,4 +294,12 @@ class PrivacyNumber
// $result = $m_phone->saveAll($insert);
// dump($result);die;
}
/**
* 默认跟进
*/
public function defaultFollowUp() {
$call_service = new CallPhoneService();
$call_service->defaultFollowUp();
}
}
\ 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