Commit 8a2d687e authored by clone's avatar clone

1

parent cd207cf1
<?php
namespace app\api_broker\controller;
use app\api_broker\extend\Basic;
use app\api_broker\service\OfficeOrderLogService;
use app\api_broker\service\OrderLogService;
use app\api_broker\service\VerifyRepetitionService;
use app\model\OMarchInModel;
/**
* Created by PhpStorm.
* User: zw
* Date: 2019/5/30
* Time: 10:54
*/
class OfficeOrderLog extends Basic{
private $o_march_in_model;
private $service_;
private $verifyService_;
function __construct($request = null)
{
parent::__construct($request);
$this->o_march_in_model = new OMarchInModel();
$this->service_ = new OfficeOrderLogService();
$this->verifyService_ = new VerifyRepetitionService();
}
/**
* @return \think\Response
* @throws Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function marchInV2()
{
$params = $this->params;
if (!isset($params["march_in_area"]) || !isset($params["report_id"]) || !isset($params["reception_id"])
|| !isset($params["reception_name"]) || !isset($params["order_id"]) || !isset($params["order_no"])) {
return $this->response("101", "请求参数错误");
}
/* $params = array(
"reception_id" => 10010,//带看经纪人id
"reception_name" => 1,//带看经纪人id
"report_id" => 1,//报备id
"order_id" => 1, //关联order表id
"order_no" => "123123123123123", //订单no
"march_in_remark" => "有意向购买", //进场备注
"march_in_img" => "123123", //备注图片
"march_in_area" => "上海市虹口区中山公园", //进场地址
);*/
// $params["reception_id"] = $this->agentName;
$march_in_img = isset($params["march_in_img"]) ? json_decode($params["march_in_img"], true) : "";
$is_execute = $this->verifyService_->verifyStart(1, $params["reception_id"], $params["order_id"]);
if (!$is_execute) {
return $this->response("101", "请不要重复提交");
}
unset($params["march_in_img"]);
$insert_id = $this->o_march_in_model->addMarchIn($params);
if ($insert_id > 0) {
$oImgModel = new OImg();
$oImgModel->addImgAll($insert_id, 1, $march_in_img);
$pushMarchIn = new PushMessageService();
$pushMarchIn->pushMarchInMessage($params["report_id"], 1, $this->agentId); //推送
//评价经纪人
$push_client = new PushClientService();
$push_client->record((int)$params["report_id"], (int)$params["order_id"], 0, '', (int)$this->agentId);
//对客户发送短信通知 7151
// $this->sendSMSForUser($params["report_id"]);
return $this->response("200", "request success", []);
} else {
return $this->response("101", "request faild");
}
}
/**
* 对客户发送短信通知
* @param $report_id
* @return bool
*/
public function sendSMSForUser($report_id)
{
$report = new OReportModel();
$messageUntil = new MessageUntils();
$user_phone = $report->getFieldValue('user_phone', ['id' => $report_id]);
$result = $messageUntil->sendSMSForUser($user_phone, [SMS_TEMPLATE_URL], '415209');
if ($result == 'true') {
return true;
} else {
return false;
}
}
/**
* 收款
* @return \think\Response
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @throws Exception
*/
public function collectingBill()
{
$params = $this->params;
if (!isset($params["agent_id"]) || !isset($params["report_id"]) ||
!isset($params["order_id"]) || !isset($params["order_no"]) | !isset($params["collecting_bill"]) ||
!isset($params["house_number"]) || !isset($params["industry_type"]) || !isset($params['bargain_id'])) {
return $this->response("101", "请求参数错误");
}
/* $params = array(
"agent_id" => 1,//收款经纪人id
"agent_name" => 1,//收款经纪人id
"report_id" => 111,//报备id
"order_id" => 2, //关联order表id
"order_no" => "123123123", //订单no
// `type` '付款类型 10意向金 20定金 30保管金 40押金 50 租金 60 进场费 70转让费 80其他',
//`pay_type` '支付方式 10支付宝 20 微信 30pos机器 40转账 50现金',
// `money` '入账金额',
"collecting_bill" => [ { "type" : 10, "pay_type" : 10, "money" : 1100 }, { "type" :10, "pay_type" : 10, "money": 1200 } ],
"house_number" => "3301号",
"industry_type" => "asdasdasd",
"remark" => "没什么备注",
"transfer_img" => "12312312312",
"is_dividend" => 1, //是否分红 1否 0是
"last_transfer_time" => "2018-10-18", //最后转定时间
"pay_id" => 1,
"receipt_number" => "12312",
"transfer_name" => "sdafsdf",
);*/
$vip_services = new VipService();
if ($vip_services->vip($params['agent_id'], 'broker/collectingBill')) {
return $this->response("101", "没有权限");
}
$params["collecting_bill"] = json_decode($params["collecting_bill"], true);
$remark = isset($params["remark"]) ? $params["remark"] : "";
$transfer_img = isset($params["transfer_img"]) ? json_decode($params["transfer_img"], true) : "";
$income_time = isset($params["income_time"]) ? $params["income_time"] : "";
$last_transfer_time = isset($params["last_transfer_time"]) ? $params["last_transfer_time"] : "";
$pay_id = isset($params["pay_id"]) ? $params["pay_id"] : 0;
$source = $params["source"] ? $params["source"] : 0;
$receipt_number = isset($params["receipt_number"]) ? $params["receipt_number"] : "";
$transfer_name = isset($params["transfer_name"]) ? $params["transfer_name"] : "";
$received_money = isset($params["received_money"]) ? $params["received_money"] : 0;
$type_ext = isset($params["type_ext"]) ? $params["type_ext"] : 0;
$is_open = isset($params['is_open']) ? $params['is_open'] : -1;
if ($pay_id > 0) {
$source = 2;
}
$is_ok = $this->service_->addCollectingBill($params["agent_id"], $params["agent_name"], $params["report_id"],
$params["order_id"], $params["order_no"], $params["collecting_bill"], $params["house_number"], $params["industry_type"],
$remark, $transfer_img, $source, $income_time, $params["is_dividend"], $last_transfer_time, $pay_id,
$receipt_number, $transfer_name, $received_money, $type_ext, $params['bargain_id'], $is_open);
if ($is_ok > 0) {
return $this->response("200", "request success", ["bill_id" => $is_ok]);
} elseif ($is_ok == -1) {
return $this->response("101", "付款类型或支付方式错误");
} elseif ($is_ok == -2) {
return $this->response("101", "调整金额不能多于可被调整的金额");
}
return $this->response("101", "request faild");
}
/**
* 是否显示调整按钮
* @return \think\Response
*/
public function isShowAdjustment()
{
$params = $this->params;
/* $params = array(
"pay_id" => 1,
"agent_id" => 11,
);*/
if (empty($params["pay_id"]) || empty($params["agent_id"])) {
return $this->response("101", "请求参数错误");
}
$pay_id = $params["pay_id"];
$agent_id = $params["agent_id"];
$result = $this->service_->verifyIsShowAdjustment($pay_id, $agent_id);
if($result["code"] == 101){
return $this->response("101",$result["msg"]);
}else if($result["code"] == 200){
return $this->response("200","success",["is_show" => $result["is_show"]]);
}
return $this->response("200","success",["is_show" => false]);
}
/**
* 获取上次提交付款的门牌号业态等
* @return \think\Response
*/
public function getBeforeBillInfo()
{
$params = $this->params;
/* $params = array(
"order_id" => 15523, //关联order表id
);*/
if (!isset($params["order_id"])) {
return $this->response("101", "订单编号不能为空");
}
$billInfo = $this->service_->getBillInfo($params["order_id"]);
if (count($billInfo) > 0) {
return $this->response("200", "request success", $billInfo[0]);
} else {
return $this->response("200", "request null");
}
}
public function getCommission()
{
$params = $this->params;
/* $params = array(
"bargain_id" => 1
);*/
if (!isset($params["bargain_id"])) {
return $this->response("101", "成交交报告id不能为空");
}
$CommissionInfo = $this->service_->getCommission($params["bargain_id"]);
if (count($CommissionInfo) > 0) {
return $this->response("200", "request success", $CommissionInfo);
} else {
return $this->response("200", "request null");
}
}
/**
* 保存pos机收款记录
* @return \think\Response
*/
public function savePosBillMessage()
{
$params = $this->params;
/* $params = array(
"p_id" => 50,
"trade_no" =>00012,
"pay_time"=>time(),
"real_money" => 11.12
);*/
if (!isset($params["p_id"]) || !isset($params["trade_no"])
|| !isset($params["pay_time"]) || !isset($params["real_money"])) {
return $this->response("101", "请求参数错误");
}
$is_ok = $this->service_->updateBillInfo($params["p_id"], $params["trade_no"], $params["pay_time"], $params["real_money"]);
if ($is_ok > 0) {
return $this->response("200", "支付成功!");
} else {
return $this->response("101", "支付失败!");
}
}
/**
* 成交报告
* @return \think\Response
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function bargain()
{
$params = $this->params;
if (!isset($params["submit_agent_id"]) || !isset($params["submit_agent_name"]) || !isset($params["report_id"]) ||
!isset($params["order_id"]) || !isset($params["order_no"]) || !isset($params["trade_type"]) ||
//!isset($params["estimated_receipt_date"]) ||
!isset($params["house_number"]) || !isset($params["industry_type"]) ||
!isset($params["price"]) || !isset($params["commission"]) || !isset($params["commission_arr"])) {
return $this->response("101", "请求参数错误");
}
/* $params = array(
"submit_agent_id" => 1,//申请经纪人id
"submit_agent_name" => 1,//申请经纪人id
"report_id" => 1,//报备id
"order_id" => 1, //关联order表id
"order_no" => "123123123", //订单no
"house_number" =>"门牌号",
"is_open" => 0,//是否开业,0未开业 1开业
"trade_type" => 10, //成交类型 10出租 20 增佣 30 代理 40 好处费
"price" => 112131, //成交价格 存分
"commission" => 111, //佣金 存分
"estimated_receipt_date" => '2018-07-15',
//`role` '分佣方 1盘方 2客方 3 反签 4独家 5合作方 6APP盘下载方 7APP客下载方',
//`agent_id`'分佣经纪人id',
//`scale`'分佣比例 如 5表示百分之5',
// `scale_fee` '应分佣金 存分 ',
"commission_arr" => '[ { "role" : 10, "agent_id" : 10, "scale" : 10, "scale_fee" : 1222 },
{ "role": 11, "agent_id" : 12, "scale": 13, "scale_fee" : 1112 }]',
);*/
$house_number = !isset($params["house_number"]) ? null : $params["house_number"];
$is_open = !isset($params["is_open"]) ? 0 : $params["is_open"];
$industry_type = !isset($params["industry_type"]) ? null : $params["industry_type"];
$estimated_receipt_date = $params["estimated_receipt_date"];
$params["commission_arr"] = json_decode($params["commission_arr"], true);
$is_ok = $this->service_->addBargain($params["submit_agent_id"], $params["submit_agent_name"], $params["report_id"],
$params["order_id"], $params["order_no"], $params["trade_type"], $params["price"], $params["commission"],
$params["commission_arr"], $house_number, $is_open, $industry_type, $estimated_receipt_date);
if ($is_ok > 0) {
//todo 更改用户信息 求租->已租
$this->service_->userUpdateInfo($params["report_id"]);
return $this->response("200", "request success", []);
}
return $this->response("101", "request faild");
}
/**
* 成交报告客户搜索
* @return \think\Response
*/
public function searchBargainAgents()
{
$params = $this->params;
/* $params = array(
"type" => 1,//1盘方,2客方,3反签,4独家,5合作方
"order_id" => 36,
);*/
if (!isset($params["type"]) || !isset($params["order_id"])) {
return $this->response("101", "请求参数错误");
}
try {
$list = $this->service_->searchBargainAgents($params["type"], $params["order_id"]);
if (count($list) > 0) {
return $this->response("200", "request success", $list);
} else {
return $this->response("200", "request null");
}
} catch (Exception $e) {
return $this->response("101", "request error,msg:" . $e);
}
}
/**
* 详情页
* @return \think\Response
*/
public function orderDetail()
{
$params = $this->params;
/*$params = array(
"order_id" => 1,
);*/
if (!isset($params["order_id"])) {
return $this->response("101", "order_id不能为空");
}
$where_["order_id"] = $params["order_id"];
try {
$result = $this->service_->selectOrderDetail($where_);
if (count($result) > 0) {
return $this->response("200", "request success", $result[0]);
} else {
return $this->response("200", "request list is null", []);
}
} catch (Exception $e) {
return $this->response("101", "request error,msg:" . $e);
}
}
/**
* 报备时间轴
*
* @return \think\Response
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function selectReportAll()
{
$params = $this->params;
/* $params = array(
"order_id" => 112,
);*/
if (!isset($params["order_id"])) {
return $this->response("101", "请求参数错误");
}
$data = $this->service_->selectListByOrderNo($params["order_id"]);
return $this->response("200", "request success", $data);
}
/**
* 报备时间轴
*
* @return \think\Response
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function selectReportAllV2()
{
$params = $this->params;
/* $params = array(
"order_id" => 38024,
);*/
if (!isset($params["order_id"])) {
return $this->response("101", "请求参数错误");
}
$data = $this->service_->selectListByOrderNo($params["order_id"]);
return $this->response("200", "request success", $data);
}
/**
* 修改成单状态
* @return \think\Response
*/
public function statusBargain()
{
$params = $this->params;
/* $params = array(
"id" => 1,
"type" => 20 //20撤销 21已撤销 30已审核
);*/
if (!isset($params["id"])) {
return $this->response("101", "请求参数错误");
}
if (!isset($params["type"]) || $params["type"] != 20 && $params["type"] != 21 && $params["type"] != 30) {
return $this->response("101", "要修改的状态类型错误");
}
$obm = new OBargainModel();
$save_param["status"] = $params["type"];
$is_ok = $obm->updateBargainById($params["id"], $save_param);
if ($is_ok > 0) {
$houseNumUpdateService = new HouseNumUpdateService();
$houseNumUpdateService->updateHouseNumByRevocationBargain($params["id"]);
return $this->response("200", "request success", ["msg" => "状态修改成功"]);
} else {
return $this->response("101", "request error");
}
}
/**
* 搜索订单
* @return \think\Response
*/
public function searchOrder()
{
$params = $this->params;
/* $params = array(
"type" => 6, //0.客户电话 1.客户姓名,去掉 2.报备人电话 3.报备人姓名 4.商铺名称 5.商铺地址 6客户编号 7商铺编号
"agent_id" => 4022,
"is_all" => 1,//0自己的,1全部
"search_keyword" => "123",
"page_no"=>1,
"page_size"=>15
);*/
if (!isset($params["type"]) || !isset($params["agent_id"]) || empty($params["search_keyword"])) {
return $this->response("101", "请求参数错误");
}
if (($params["type"] == 6 || $params["type"] == 7 || $params["type"] == 8) && !preg_match("/^\d*$/", $params["search_keyword"])) {
return $this->response("101", "客户编号或商铺编号错误");
}
$pageNo = empty($params['page_no']) ? 1 : $params['page_no'];
$pageSize = empty($params['page_size']) ? 15 : $params['page_size'];
try {
$result = [];
if (isset($params["is_all"]) && $params["is_all"] == 1) {
// $s_report = new ReportService();
// $check_type = $s_report->getCheckType($this->agentId);
// if ($check_type == 0) {
// return $this->response(101, "暂无权限");
// }
$result = $this->service_->getSearchOrderByAll($params, $pageNo, $pageSize);
} else {
$result = $this->service_->getSearchOrder($params, $pageNo, $pageSize);
}
if (count($result) > 0) {
return $this->response("200", "request success", $result);
} else {
return $this->response("200", "request null");
}
} catch (Exception $e) {
return $this->response("101", "request error,msg:" . $e);
}
}
/**
* 我的成交
* @return \think\Response
*/
public function bargainList()
{
$params = $this->params;
/* $params = array(
"submit_agent_id" => 1,
"status" => 10,
"page_no" => 1,
"page_size" => 15
);*/
if (!isset($params["submit_agent_id"]) || !isset($params["status"])) {
return $this->response("101", "请求参数错误");
}
try {
$result = $this->service_->getBargainList($params);
if (count($result) > 0) {
return $this->response("200", "request success", $result);
} else {
return $this->response("200", "request null");
}
} catch (Exception $e) {
return $this->response("101", "request error,msg:" . $e);
}
}
/**
* 成交报告详情
* @return \think\Response
*/
public function bargainDetail()
{
header('Access-Control-Allow-Origin:*');
$params = $this->params;
/* $params = array(
"bargain_id" => 705,
);*/
if (!isset($params["bargain_id"])) {
return $this->response("101", "请求参数错误");
}
try {
$result = $this->service_->getBargainDetail($params);
if (count($result) > 0) {
return $this->response("200", "request success", $result);
} else {
return $this->response("200", "request null");
}
} catch (Exception $e) {
return $this->response("101", "request error,msg:" . $e);
}
}
/**
* 搜索我的成交报告
* @return \think\Response
*/
public function searchBargainList()
{
$params = $this->params;
/* $params = array(
"submit_agent_id" => 1,
"keyword" => "17717536291",
"type" => 1,//1商铺id 2商铺地址 3成交报告id 4带看id 5客户id
"page_no" => 1,
"page_size" => 15
);*/
if (!isset($params["submit_agent_id"]) || !isset($params["keyword"]) || !isset($params["type"])) {
return $this->response("101", "请求参数错误");
}
if (($params["type"] == 1 || $params["type"] == 3 || $params["type"] == 4 || $params["type"] == 7) && !preg_match("/^\d*$/", $params["search_keyword"])) {
return $this->response("101", "输入的搜索内容错误");
}
try {
$result["result"] = $this->service_->getBargainList($params);
if (count($result) > 0) {
return $this->response("200", "request success", $result);
} else {
return $this->response("200", "request null");
}
} catch (Exception $e) {
return $this->response("101", "request error,msg:" . $e);
}
}
/**
* 搜索我的成交报告
* @return \think\Response
*/
public function searchBargainListByOrderId()
{
$params = $this->params;
/* $params = array(
"order_id" => 11231,
);*/
if (!isset($params["order_id"])) {
return $this->response("101", "请求参数错误");
}
try {
$result = $this->service_->getBargainListByOrderId($params["order_id"]);
if (count($result) > 0) {
return $this->response("200", "request success", $result);
} else {
return $this->response("200", "request null");
}
} catch (Exception $e) {
return $this->response("101", "request error,msg:" . $e);
}
}
/**
* 搜索经纪人
* @return \think\Response
*/
public function searchAgents()
{
$params = $this->params;
/* $params = array(
"keyword" => "17", //姓名或者手机号
"page_no" => 1,
"page_size" => 15
);*/
$where_ = [];
if (!isset($params["keyword"])) {
return $this->response("101", "请求参数错误");
} else {
$where_["phone|name"] = array("like", "%" . trim($params["keyword"]) . "%");
}
$pageNo = empty($params["page_no"]) ? 1 : $params["page_no"];
$pageSize = empty($params["page_size"]) ? 15 : $params["page_size"];
$agentModel = new AAgents();
$field = "id,phone,name,status";
try {
$result = $agentModel->getList($pageNo, $pageSize, "id desc", $field, "", $where_);
if (count($result) > 0) {
return $this->response("200", "request success", $result);
} else {
return $this->response("200", "request null");
}
} catch (Exception $e) {
return $this->response("101", "request error,msg:" . $e);
}
}
/**
* 新增分佣提成
*
* @return \think\Response
* @throws \think\exception\DbException
*/
public function addBargain()
{
$data['code'] = 200;
$data['msg'] = "";
$data['data'] = [];
if (empty($this->params['id']) || empty($this->params['agent_id'])) {
return $this->response(101, 'Id or agent_id or source is null.');
}
$source = empty($this->params['source']) ? 0 : $this->params['source'];
$bargain = new OBargainModel();
$data['data'] = $bargain->addBargainCommission($this->params['id'], $this->agentId, $this->params['agent_id'],
$this->params['role'], $this->params['scale_fee'], $this->params['scale'], $source);
$this->updatePerformance((int)$this->params['id'], (int)$this->params['agent_id']);
if ($data['data'] == 0) {
$data['code'] = 101;
$data['msg'] = 'Add the failure.';
}
return $this->response($data['code'], $data['msg'], ["id" => $data['data']]);
}
/**
* 获取未结单的成交报告id 最新的id
*
* @return \think\Response
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function isBargainEnd()
{
$params = $this->params;
/* $params = array(
"order_id" => 1,//订单id
"submit_agent_id" => 1//提交人id
);*/
if (!isset($params["order_id"]) || !isset($params["submit_agent_id"])) {
return $this->response("101", "请求参数错误");
}
$bargainModel = new OBargainModel();
$where_["father_id"] = 0;
$where_["order_id"] = $params["order_id"];
$where_["submit_agent_id"] = $params["submit_agent_id"];
$where_["status"] = 10;
$field = "id";
$bargain = $bargainModel->getBargainDetail($field, $where_);
if (count($bargain) > 0) {
return $this->response("200", "request success", ["id" => $bargain[0]["id"]]);
} else {
return $this->response("200", "request null");
}
}
/**
* 店铺动态
* @return \think\Response
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getListByHouseId()
{
header('Access-Control-Allow-Origin:*');
$params = $this->params;
/* $params = array(
"house_id"=>1
);*/
if (!isset($params["house_id"])) {
return $this->response("101", "请求参数错误");
}
$data = $this->service_->selectListByHouseId($params["house_id"]);
if (count($data) > 0) {
return $this->response("200", "request success", $data);
} else {
return $this->response("200", "request null");
}
}
/**
* 判断是否有未结单的成交报告
* @return \think\Response
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getIsAccountStatement()
{
$params = $this->params;
/* $params = array(
"order_id" => 7353,
);*/
if (!isset($params["order_id"])) {
return $this->response("101", "请求参数错误");
}
$field = "id,order_id,account_statement,commission,house_number,is_open,industry_type";
$where_["order_id"] = $params["order_id"];
$where_["father_id"] = 0;
$where_["account_statement"] = 0;
$oBargainModel = new OBargainModel();
$data = $oBargainModel->selectBargainByOrderNo($field, $where_, "id desc");
if (count($data) > 0) {
$list["bargain_id"] = $data[0]["id"];
$list["house_number"] = $data[0]["house_number"];
$list["commission"] = $data[0]["commission"];
$list["is_open"] = $data[0]["is_open"];
$list["industry_type"] = $data[0]["industry_type"];
return $this->response("200", "request success", $list);
} else {
return $this->response("200", "request null");
}
}
/**
* 商铺详情-带看记录
* User: 朱伟
* Date: 2018-07-24
* Time: 16:01:27
*/
public function getLook()
{
$params = $this->params;
//$params['house_id']=260;
if (!isset($params['house_id'])) {
return $this->response("101", "参数不全");
}
//todo 该商铺7日带看次数
$model = new OrderModel();
$params["house_id"] = $params['house_id'];
$start_time = date("Y-m-d", strtotime("-7 day"));
$end_time = date("Y-m-d", time());
$params['create_time'] = array('between', array($start_time . " 00:00:00", $end_time . " 23:59:59"));
$res_7 = $model->getCountByHouseId($params);
//dump($params);
$return['week'] = $res_7;
//todo 该商铺30日带看次数
$start_time = date("Y-m-d", strtotime("-30 day"));
$end_time = date("Y-m-d", time());
$params['create_time'] = array('between', array($start_time . " 00:00:00", $end_time . " 23:59:59"));
$res_30 = $model->getCountByHouseId($params);
//dump($params);
$return['month'] = $res_30;
return $this->response("200", "success!", $return);
}
/**
* 更新个人业绩
*
* @param int $bargain_id
* @param int $agent_id
* @return bool
*/
private function updatePerformance(int $bargain_id = 0, int $agent_id = 0): bool
{
$where = [];
if ($bargain_id) {
$where['b.id'] = $bargain_id;
}
if ($agent_id) {
$where['a.id'] = $agent_id;
}
if (!empty($where)) {
//获取被修改人信息
$m_agent = new AAgents();
$agent_data = $m_agent->agentBargainDetail('a.id,a.store_id,a.district_id,b.create_time', ['b.id' => $bargain_id]);
//更新业绩统计
$sum = new ResultsSummaryNewTask();
$date = date('Y-m-d', strtotime($agent_data['create_time']));
$sum->updateTotalByAgentId($agent_data['id'], $agent_data['store_id'], $agent_data['district_id'], $date); //被修改的人
}
return true;
}
}
\ No newline at end of file
<?php
namespace app\api_broker\service;
/**
* Created by PhpStorm.
* User: zw
* Date: 2019/5/30
* Time: 15:14
*/
use app\model\AAgents;
use app\model\AppointWatchShop;
use app\model\FollowUpLogModel;
use app\model\GHousesFollowUp;
use app\model\GHousesToAgents;
use app\model\OBargainModel;
use app\model\OImg;
use app\model\OMarchInModel;
use app\model\OPayLogAdjustment;
use app\model\OPayLogModel;
use app\model\OrderModel;
use app\model\ORealIncome;
use app\model\ORefundLogModel;
use app\model\ORefundModel;
use app\model\OReportModel;
use app\model\OTaxes;
use app\model\Regions;
use app\model\UPhoneFollowUp;
use app\model\UPhoneFollowUpTemporary;
use app\model\Users;
class OfficeOrderLogService
{
private $payLogModel;
private $bargainModel;
function __construct()
{
$this->payLogModel = new OPayLogModel();
$this->bargainModel = new OBargainModel();
}
/**
* 批量插入收款记录
*
* @param $agent_id
* @param $agent_name
* @param $report_id
* @param $order_id
* @param $order_no
* @param $collecting_bill
* @param $house_number
* @param $industry_type
* @param $remark
* @param $transfer_img
* @param $source
* @param $income_time
* @param $is_dividend
* @param $last_transfer_time
* @param $pay_id
* @param $receipt_number
* @param $transfer_name
* @param $received_money
* @param $type_ext
* @param $bargain_id
* @param $is_open
* @return int|string
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function addCollectingBill($agent_id, $agent_name, $report_id, $order_id, $order_no, $collecting_bill, $house_number,
$industry_type, $remark, $transfer_img, $source, $income_time, $is_dividend,
$last_transfer_time, $pay_id, $receipt_number, $transfer_name, $received_money,
$type_ext, $bargain_id, $is_open)
{
$bill_arr = $params = [];
$father_id = 0;
$money = 0;
$type = 0;
foreach ($collecting_bill as $collecting) {
if (isset($collecting["type"]) && isset($collecting["pay_type"]) && isset($collecting["money"])) {
if (!$this->verifyType($collecting["type"], $collecting["pay_type"], $receipt_number)) {
return -1;
}
$money = $collecting["money"];
$type = $collecting["type"];
if ($pay_id > 0) {
$is_ok = $this->verifyMoney($pay_id, $money);
if ($is_ok != 0) {
return $is_ok;
}
}
if ($father_id == 0) {
$params = $this->collectingBillBin($father_id, $collecting, $agent_id, $agent_name, $report_id,
$order_id, $order_no, $house_number, $industry_type, $remark, $transfer_img, $source, $income_time,
$is_dividend, $last_transfer_time, $receipt_number, $transfer_name, $received_money, $type_ext,
$bargain_id, $is_open);
$father_id = $this->payLogModel->insertPayLog($params);
} else {
array_push($bill_arr, $this->collectingBillBin($father_id, $collecting, $agent_id, $agent_name,
$report_id, $order_id, $order_no, $house_number, $industry_type, $remark, $transfer_img, $source,
$income_time, $is_dividend, $last_transfer_time, $receipt_number, $transfer_name, $received_money,
$type_ext, $bargain_id, $is_open));
}
//$this->updateBargainIsOpen($bargain_id, $collecting['type'], $is_open);
}
}
if ($father_id > 0) {
//保存图片
if ($transfer_img) {
$oImgModel = new OImg();
$oImgModel->addImgAll($father_id, 2, $transfer_img);
}
if ($pay_id > 0) {
$payLogService = new PayLogService();
$payLogService->addAdjustment($father_id, $pay_id, $money, $type, $agent_id);
}
$pushMarchIn = new PushMessageService();
$pushMarchIn->pushMarchInMessage($params["report_id"], 2, $agent_id, $type); //推送
}
//todo if bill_arr not null, save database table
if (!empty($bill_arr)) {
return $this->payLogModel->addPayLog($bill_arr);
}
return $father_id;
}
public function verifyIsShowAdjustment($pay_id, $agent_id)
{
$params["id"] = $pay_id;
$pay_log_info = $this->payLogModel->getPayLogByOrderId("a.id,a.agent_id,c.store_id", $params);
if (count($pay_log_info) <= 0) {
return ["code" => 101, "msg" => "没有找到相对应的收款信息"];
}
$agentModel = new AAgents();
$agent_info = $agentModel->getAgentById("id,store_id", ["id" => $agent_id]);
if (count($agent_info) <= 0) {
return ["code" => 101, "msg" => "没有找到相对应的经纪人信息"];
}
if ($pay_log_info[0]["store_id"] != $agent_info[0]["store_id"]) {
return ["code" => 200, "is_show" => false];
} else {
return ["code" => 200, "is_show" => true];
}
}
/**
* 验证金额是否合法
* @param $pay_id
* @param $money
* @return int
*/
private function verifyMoney($pay_id, $money)
{
$payLogService = new PayLogService();
$residue_money = $payLogService->adjustment($pay_id);
if ($residue_money < $money) {
return -2;
}
return 0;
}
/**
* @param $type
* @param $pay_type
* @param $receipt_number
* @return bool
*/
private function verifyType($type, $pay_type, $receipt_number)
{
switch ($pay_type) {
case 10:
break;
case 11:
break;
case 12:
break;
case 13:
break;
case 20:
break;
case 21:
break;
case 22:
break;
case 23:
break;
case 30:
break;
case 40:
break;
case 41:
break;
case 42:
break;
case 50:
break;
case 60:
break;
case 70:
break;
case 71:
break;
case 72:
break;
case 73:
break;
case 74:
break;
default:
return false;
}
switch ($type) {
case 10:
/* if(empty($receipt_number)){
return false;
}*/
break;
case 30:
/* if(empty($receipt_number)){
return false;
}*/
break;
case 20:
break;
case 40:
break;
case 50:
break;
case 60:
break;
case 70:
break;
case 80:
break;
case 90:
break;
case 91:
break;
case 92:
break;
default:
return false;
}
return true;
}
/**
* @param $father_id
* @param $collecting_arr
* @param $agent_id
* @param $agent_name
* @param $report_id
* @param $order_id
* @param $order_no
* @param $house_number
* @param $industry_type
* @param $remark
* @param $transfer_img
* @param $source
* @param $income_time
* @param $is_dividend
* @param $last_transfer_time
* @param $receipt_number
* @param $transfer_name
* @param $received_money
* @param $type_ext
* @param $bargain_id
* @param $is_open
* @return mixed
*/
private function collectingBillBin($father_id, $collecting_arr, $agent_id, $agent_name, $report_id, $order_id,
$order_no, $house_number, $industry_type, $remark, $transfer_img, $source,
$income_time, $is_dividend, $last_transfer_time, $receipt_number, $transfer_name,
$received_money, $type_ext, $bargain_id, $is_open)
{
$arr["report_id"] = $report_id;
$arr["father_id"] = $father_id;
$arr["order_no"] = $order_no;
$arr["order_id"] = $order_id;
$arr["source"] = $source;
$arr["agent_id"] = $agent_id;
$arr["agent_name"] = $agent_name;
$arr["type"] = $collecting_arr["type"];
$arr["pay_type"] = $collecting_arr["pay_type"];
$arr["money"] = $collecting_arr["money"];
$arr["house_number"] = $house_number;
$arr["industry_type"] = $industry_type;
$arr["remark"] = $remark;
$arr["receipt_number"] = $receipt_number;
$arr["transfer_name"] = $transfer_name;
$arr["transfer_img"] = $transfer_img;
$arr["create_time"] = date("Y-m-d H:i:s", time());
$arr["update_time"] = date("Y-m-d H:i:s", time());
$arr["is_dividend"] = $is_dividend;
$arr["received_money"] = $received_money;
$arr["type_ext"] = $type_ext;
$arr["bargain_id"] = $bargain_id;
$arr["is_open"] = $is_open;
if ($income_time) {
$arr["income_time"] = date("Y-m-d H:i:s", $income_time);
}
if ($last_transfer_time) {
$arr["last_transfer_time"] = date("Y-m-d H:i:s", $last_transfer_time);
}
if ($is_open && $is_open == 1) {
$arr["open_time"] = date("Y-m-d H:i:s");
}
return $arr;
}
/**
* 批量插入成交报告
* @param $submit_agent_id
* @param $submit_agent_name
* @param $report_id
* @param $order_id
* @param $order_no
* @param $trade_type
* @param $price
* @param $commission
* @param $commission_arr
* @param $house_number
* @param $is_open
* @param $industry_type
* @param $estimated_receipt_date
* @return int|string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function addBargain($submit_agent_id, $submit_agent_name, $report_id, $order_id, $order_no, $trade_type, $price,
$commission, $commission_arr, $house_number, $is_open, $industry_type, $estimated_receipt_date)
{
$bargain_arr = [];
$father_id = 0;
foreach ($commission_arr as $commission_val) {
if (isset($commission_val["role"]) && isset($commission_val["agent_id"]) && isset($commission_val["scale"])
&& isset($commission_val["scale_fee"])) {
if ($father_id == 0) {
$params = $this->bargainBin($father_id, $commission_val, $submit_agent_id, $submit_agent_name, $report_id, $order_id,
$order_no, $trade_type, $price, $commission, $house_number, $is_open, $industry_type, $estimated_receipt_date);
$father_id = $this->bargainModel->insertBargain($params);
} else {
array_push($bargain_arr, $this->bargainBin($father_id, $commission_val, $submit_agent_id, $submit_agent_name, $report_id,
$order_id, $order_no, $trade_type, $price, $commission, $house_number, $is_open, $industry_type, $estimated_receipt_date));
}
}
array_push($agent_arr, [$commission_val["agent_id"]]);
}
if ($father_id > 0) { //修改楼盘
$houseNumUpdateService = new HouseNumUpdateService();
$houseNumUpdateService->updateHouseNumByBargain($order_id);
$push_message = new PushMessageService();
//todo 0923 经理提的问题
$push_message->pushBargainMessage($report_id); //推送
}
//todo if bill_arr not null, save database table
if (!empty($bargain_arr)) {
return $this->bargainModel->addBargain($bargain_arr);
}
return $father_id;
}
private function bargainBin($father_id, $commission_val, $submit_agent_id, $submit_agent_name, $report_id, $order_id,
$order_no, $trade_type, $price, $commission, $house_number, $is_open, $industry_type, $estimated_receipt_date)
{
$arr["report_id"] = $report_id;
$arr["father_id"] = $father_id;
$arr["order_no"] = $order_no;
$arr["order_id"] = $order_id;
$arr["submit_agent_id"] = $submit_agent_id;
$arr["submit_agent_name"] = $submit_agent_name;
$arr["trade_type"] = $trade_type;
$arr["price"] = $price;
$arr["commission"] = $commission;
$arr["role"] = $commission_val["role"];
$arr["agent_id"] = $commission_val["agent_id"];
$arr["scale"] = $commission_val["scale"];
$arr["scale_fee"] = $commission_val["scale_fee"];
$arr["house_number"] = $house_number;
$arr["is_open"] = $is_open;
$arr["create_time"] = date("Y-m-d H:i:s", time());
$arr["update_time"] = date("Y-m-d H:i:s", time());
$arr["estimated_receipt_date"] = date("Y-m-d H:i:s", $estimated_receipt_date);
$arr["industry_type"] = $industry_type;
return $arr;
}
/**
* 订单详情主体信息
* @param $where_
* @return false|\PDOStatement|string|\think\Collection
*/
public function selectOrderDetail($where_)
{
$orderModel = new OrderModel();
$field = "a.id,a.order_no,a.house_id,a.house_title,b.id as report_id,b.user_id,c.user_name as user_nick,c.user_phone,
c.user_pic,c.sex,d.internal_address as house_address";
$result = $orderModel->selectOrderDetail($field, $where_);
foreach ($result as $k => $v) {
//$result[$k]["user_phone"] = preg_replace('/(\d{3})\d{4}(\d{4})/','$1****$2',$v["user_phone"]);
$result[$k]["user_pic"] = HEADERIMGURL . $v["user_pic"];
}
//todo 获取楼盘的案场权限人
return $result;
}
/**
* 查询流程 订单时间轴
* @param $order_id
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function selectListByOrderNoV2($order_id)
{
$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();
$orderData = $orderModel->selectOrderByOrderId("a.f_id,a.house_title,b.internal_address", ["order_id" => $order_id]);
//dump($orderData);
if (count($orderData) <= 0) {
return ["101", "找不到此订单编号"];
}
$report_id = $orderData[0]["f_id"];
$field_report = "a.id,a.report_agent_id,a.report_agent_phone,a.report_agent_name,a.report_store_id,
a.user_id,a.user_phone,a.user_name,a.vehicle,a.intro,a.predict_see_time,a.create_time,b.store_name,c.district_name";
$reportData = $oReportModel->selectReportInfoById($field_report, ["id" => $report_id]);
if (count($reportData) == 0) {
return ["101", "报备记录未找到"];
}
//报备
$reportData[0]["step_name"] = "report";
$reportData[0]["house_title"] = $orderData[0]["house_title"];
$reportData[0]["internal_address"] = $orderData[0]["internal_address"];
$result[$sort++] = $reportData[0];
//进场 march in
$field_march_in = "id,reception_id,reception_name,report_id,order_no,march_in_remark,march_in_img,march_in_area,create_time";
$marchInData = $oMarchInModel->selectMarchInByOrderNo($field_march_in, ["order_id" => $order_id]);
if (count($marchInData) > 0) {
/* foreach ($marchInData as $k => $v) {
$v["step_name"] = "march_in";
$v["img_path"] = CHAT_IMG_URL;
$result[$sort++] = $v;
}*/
foreach ($marchInData as $k => $v) {
$v["step_name"] = "march_in";
$v["img_path"] = CHAT_IMG_URL;
$v["img"] = $this->getOImg($v["id"], 1);
$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, ["report_id" => $report_id]);
if (count($followUpLogData) > 0) {
foreach ($followUpLogData as $k => $v) {
$v["step_name"] = "follow_up_log";
$v = $this->convertFollowUp($v);
$v["img_path"] = CHAT_IMG_URL;
$result[$sort++] = $v;
}
}
//收款
$field_pay_log = "id,order_no,father_id,order_id,agent_id,agent_name,type,pay_type,money,house_number,industry_type,
remark,transfer_img,real_money,source,create_time";
$payLogData = $oPayLogModel->selectPayLogByOrderNo($field_pay_log, ["order_id" => $order_id]);
if (count($payLogData) > 0) {
$sortPayLogData = $this->arr2tree($payLogData);
foreach ($sortPayLogData as $k => $v) {
$v["step_name"] = "pay_log";
$v["img_path"] = CHAT_IMG_URL;
$result[$sort++] = $v;
}
}
//退款
$field_refund = "id,report_id,agent_id,agent_name,order_no,order_id,refund_money,status,name,bank,card_no,
remark,remark_img,create_time";
$refundData = $oRefundModel->selectRefundByOrderNo($field_refund, ["order_id" => $order_id]);
if (count($refundData) > 0) {
foreach ($refundData as $k => $v) {
$v["step_name"] = "refund";
$v["img_path"] = CHAT_IMG_URL;
$result[$sort++] = $v;
}
}
//成交报告
$field_bargain = "a.id,a.father_id,a.house_number,a.is_open,a.report_id,a.order_id,a.trade_type,a.submit_agent_id,a.industry_type,
a.estimated_receipt_date,a.submit_agent_name, a.price,a.commission,a.role,a.agent_id,a.scale,a.scale_fee,a.create_time,b.name,b.phone,a.is_commission";
$bargainData = $oBargainModel->selectBargainListByOrderNo($field_bargain, ["order_id" => $order_id]);
if (count($bargainData) > 0) {
$bargain_data_arr = $this->arr2TreeBargain($bargainData);
foreach ($bargain_data_arr as $k2 => $v2) {
$v2["step_name"] = "bargain";
$result[$sort++] = $v2;
}
}
return $this->sortByTime($result);
}
/**
* 查询流程 订单时间轴
* @param $order_id
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function selectListByOrderNo($order_id)
{
$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();
$oPayLogAdjustmentModel = new OPayLogAdjustment();
$oRefundLogModel = new ORefundLogModel();
$orderData = $orderModel->selectOrderByOrderId("a.f_id,a.house_title,b.internal_address", ["order_id" => $order_id]);
//dump($orderData);
if (count($orderData) <= 0) {
return ["101", "找不到此订单编号"];
}
$report_id = $orderData[0]["f_id"];
$field_report = "a.id,a.report_agent_id,a.report_agent_phone,a.report_agent_name,a.report_store_id,
a.user_id,a.user_phone,a.user_name,a.vehicle,a.intro,a.predict_see_time,a.create_time,b.store_name,c.district_name";
$reportData = $oReportModel->selectReportInfoById($field_report, ["id" => $report_id]);
if (count($reportData) == 0) {
return ["101", "报备记录未找到"];
}
//报备
$reportData[0]["step_name"] = "report";
$reportData[0]["house_title"] = $orderData[0]["house_title"];
$reportData[0]["internal_address"] = $orderData[0]["internal_address"];
$result[$sort++] = $reportData[0];
//进场 march in
$field_march_in = "id,reception_id,reception_name,report_id,order_no,march_in_remark,march_in_img,march_in_area,create_time";
$marchInData = $oMarchInModel->selectMarchInByOrderNo($field_march_in, ["order_id" => $order_id]);
if (count($marchInData) > 0) {
foreach ($marchInData as $k => $v) {
$v["step_name"] = "march_in";
$v["img_path"] = CHAT_IMG_URL;
$v["img"] = $this->getOImg($v["id"], 1);
$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, ["report_id" => $report_id]);
if (count($followUpLogData) > 0) {
foreach ($followUpLogData as $k => $v) {
$v["step_name"] = "follow_up_log";
$v = $this->convertFollowUp($v);
$v["img_path"] = CHAT_IMG_URL;
$result[$sort++] = $v;
}
}
//收款
$field_pay_log = "id,order_no,father_id,order_id,agent_id,agent_name,type,pay_type,money,house_number,industry_type,
remark,transfer_img,real_money,source,create_time,is_dividend,last_transfer_time,receipt_number,transfer_name,income_time";
$payLogData = $oPayLogModel->selectPayLogByOrderNo($field_pay_log, ["order_id" => $order_id]);
if (count($payLogData) > 0) {
$sortPayLogData = $this->arr2tree($payLogData);
foreach ($sortPayLogData as $k => $v) {
$v["step_name"] = "pay_log";
$v["img_path"] = CHAT_IMG_URL;
$result[$sort++] = $v;
}
}
//退款
$field_refund = "a.id,a.report_id,a.agent_id,a.agent_name,a.order_no,a.order_id,a.refund_money,a.status,a.name
,a.phone,a.bank,a.card_no, a.remark,a.receipt_number,a.type,a.refund_cause,a.pay_log_id,a.refund_way,
a.create_time,b.income_time";
$refundData = $oRefundModel->selectRefundDetailByOrderNo($field_refund, ["order_id" => $order_id, 'del' => 0]);
if (count($refundData) > 0) {
foreach ($refundData as $k => $v) {
$v["step_name"] = "refund";
$v["img_path"] = CHAT_IMG_URL;
$v["img"] = $this->getOImg($v["id"], 3);
$result[$sort++] = $v;
}
}
//成交报告
$field_bargain = "a.id,a.father_id,a.house_number,a.is_open,a.report_id,a.order_id,a.trade_type,a.submit_agent_id,a.industry_type,
a.estimated_receipt_date,a.submit_agent_name, a.price,a.commission,a.role,a.agent_id,a.scale,a.scale_fee,a.create_time,b.name,b.phone,a.is_commission";
$bargainData = $oBargainModel->selectBargainListByOrderNo($field_bargain, ["order_id" => $order_id, 'status' => ['<>', 30]]);
if (count($bargainData) > 0) {
$bargain_data_arr = $this->arr2TreeBargain($bargainData);
foreach ($bargain_data_arr as $k2 => $v2) {
$v2["step_name"] = "bargain";
$result[$sort++] = $v2;
}
}
//调整
$field_adjustment = "a.id,a.paylog_id,a.new_paylog_id,d.order_id,a.type,a.money,a.create_time,a.update_time,c.name";
$adjustmentData = $oPayLogAdjustmentModel->getAdjustmentListByOrderId($field_adjustment, ["order_id" => $order_id, 'is_del' => 0]);
if (count($adjustmentData) > 0) {
foreach ($adjustmentData as $k2 => $v2) {
$v2["step_name"] = "adjustment";
$result[$sort++] = $v2;
}
}
//退款审核
$field_turn_down = "id,refund_id,status,remark,operation_id,operation_name,create_time";
$turn_down["order_id"] = $order_id;
$turn_down["status"] = array("in", ("2,4"));
$turn_down["is_del"] = 0;
$turnDownData = $oRefundLogModel->getListAll($field_turn_down, $turn_down);
if (count($turnDownData) > 0) {
foreach ($turnDownData as $k2 => $v2) {
$v2["step_name"] = "refund_check";
$v2["img_path"] = CHAT_IMG_URL;
$v2["img"] = $this->getOImg($v2["id"], 4);
$result[$sort++] = $v2;
}
}
return $this->sortByTime($result);
}
public function getOImg($id, $img_type)
{
//查询图片
$oImgModel = new OImg();
$params["img_id"] = $id;
$params["img_type"] = $img_type;
$img_arr = $oImgModel->getImgList($params);
return $img_arr;
}
public function arr2tree($list)
{
$tree = $trees = [];
foreach ($list as $key => $item) {
if ($item["father_id"] == 0) {
$list[$key]["father_id"] = $item["id"];
}
}
foreach ($list as $value) {
$tree[$value["father_id"]][] = $value;
}
foreach ($tree as $i => $v) {
//查询图片
$oImgModel = new OImg();
$params["img_id"] = $v[0]["father_id"];
$params["img_type"] = 2;
$img_arr = $oImgModel->getImgList($params);
$trees[$i]["img"] = $img_arr;
$trees[$i]["list"] = $v;
$trees[$i]["create_time"] = $v[0]["create_time"];
}
unset($tree);
sort($trees);
return $trees;
}
/**
* @param $list
* @return array
*/
public function arr2TreeBargain($list)
{
$tree = $trees = [];
foreach ($list as $key => $item) {
if ($item["father_id"] == 0) {
$list[$key]["father_id"] = $item["id"];
}
}
foreach ($list as $k => $v) {
$tree[$v["father_id"]]['create_time'] = $v['create_time'];
if ($v['father_id'] == $v['id']) {
$tree[$v["father_id"]]['trade_type'] = $v['trade_type'];
$tree[$v["father_id"]]['house_number'] = $v['house_number'];
$tree[$v["father_id"]]['industry_type'] = $v['industry_type'];
$tree[$v["father_id"]]['price'] = $v['price'];
$tree[$v["father_id"]]['commission'] = $v['commission'];
$tree[$v["father_id"]]['is_open'] = $v['is_open'];
}
$tree[$v["father_id"]]['list_array'][] = $v;
}
return $tree;
}
/**
* 查询流程 客户动态
*
* @param $user_id
* @param string $search
* @param string $site_id
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function selectListByUserId($user_id, $search = "", $site_id)
{
$result = [];
$sort = 0;
//todo 1.验证订单是否存在
$oReportModel = new OReportModel();
$oMarchInModel = new OMarchInModel();
$followUpLogModel = new FollowUpLogModel();
$oPayLogModel = new OPayLogModel();
$oRefundModel = new ORefundModel();
$oBargainModel = new OBargainModel();
$uPhoneFollowModel = new UPhoneFollowUp($site_id);
$uPhoneFollowTempModel = new UPhoneFollowUpTemporary($site_id);
//电话跟进
$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);
$bargainDataTemp = $uPhoneFollowTempModel->getFollowUpListByUserId($field_user_follow, $userParams);
if (count($bargainDataTemp) > 0) {
foreach ($bargainDataTemp 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;
}
}
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);
$bargainDataTemp = $uPhoneFollowTempModel->getFollowUpListByUserId($field_user_follow, $userParams);
if (count($bargainDataTemp) > 0) {
foreach ($bargainDataTemp 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;
}
}
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;
}
}
$field_report = "a.id,a.create_time,a.predict_see_time,a.intro,b.id as order_id,b.house_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($result) <= 0 && count($reportData) <= 0) {
return [];
}
$order_ids = $report_ids = "";
//报备
foreach ($reportData as $k => $v) {
$v["step_name"] = "report";
//$house_title = mb_substr($v['house_title'], 0, 3, 'utf-8') . "***";
$house_title = $v['house_title'];
$v["step"] = "报备【id:" . $v['house_id'] . " " . $house_title . "】";
$result[$sort++] = $v;
$order_ids .= $v["order_id"] . ",";
$report_ids .= $v["id"] . ",";
}
$order_ids = rtrim($order_ids, ",");
$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";
//$house_title = mb_substr($v['house_title'], 0, 3, 'utf-8') . "***";
$house_title = $v['house_title'];
$v["step"] = "进场【id:" . $v['house_id'] . " " . $house_title . "】";
$result[$sort++] = $v;
}
}
//跟进 20190112产品沟通去掉这块
/* $field_follow_up = "a.id,a.agent_id,a.agent_name,a.user_type,a.decision_maker,a.industry_type,a.area_requirement,a.price_requirement,a.province,a.city,
a.district,a.business_area,a.explain,a.explain_img,a.create_time,b.name,b.img,c.store_name";
$followUpLogData = $followUpLogModel->getFollowUpByOrderId($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;
$v["explain_img"] = $v["explain_img"];
$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";
//$house_title = mb_substr($v['house_title'], 0, 3, 'utf-8') . "***";
$house_title = $v['house_title'];
$v["step"] = "收款【id:" . $v['house_id'] . " " . $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";
//$house_title = mb_substr($v['house_title'], 0, 3, 'utf-8') . "***";
$house_title = $v['house_title'];
$v["step"] = "退款【id:" . $v['house_id'] . " " . $house_title . "】";
$result[$sort++] = $v;
}
}
//成交报告
$field_bargain = "a.id,a.create_time,a.house_number,a.is_open,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";
//$house_title = mb_substr($v['house_title'], 0, 3, 'utf-8') . "***";
$house_title = $v['house_title'];
$v["step"] = "成交报告【id:" . $v['house_id'] . " " . $house_title . "】";
$result[$sort++] = $v;
}
}
return $this->sortByTime($result);
}
/**
* 最新 客户动态时间轴
* @param $user_id
* @param string $search
* @param $site_id
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function selectListByUserIdAndSiteId($user_id, $search = "", $site_id)
{
$result = [];
$sort = 0;
//todo 1.验证订单是否存在
$oReportModel = new OReportModel();
$oMarchInModel = new OMarchInModel();
$followUpLogModel = new FollowUpLogModel();
$oPayLogModel = new OPayLogModel();
$oRefundModel = new ORefundModel();
$oBargainModel = new OBargainModel();
$appointWatchShopModel = new AppointWatchShop();
//客户c端提交预约看铺
$field_appoint = "a.id,a.create_time,b.user_name as name";
$appointData = $appointWatchShopModel->getAppointWatchOur(1, 15, "a.id desc", $field_appoint, ["a.user_id" => $user_id]);
if (count($appointData) > 0) {
foreach ($appointData as $k => $v) {
$v["step_name"] = "appoint";
$v["step"] = "提交预约看铺";
$result[$sort++] = $v;
}
}
$field_report = "a.id,a.create_time,a.predict_see_time,a.intro,b.id as order_id,b.house_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($appointData) > 0 && count($reportData) <= 0) {
return $this->sortByTime($result);
} elseif (count($appointData) <= 0 && count($reportData) <= 0) {
return [];
}
$order_ids = $report_ids = "";
//报备
foreach ($reportData as $k => $v) {
$v["step_name"] = "report";
//$house_title = mb_substr($v['house_title'], 0, 3, 'utf-8') . "***";
$house_title = $v['house_title'];
$v["step"] = "报备【id:" . $v['house_id'] . " " . $house_title . "】";
$result[$sort++] = $v;
$order_ids .= $v["order_id"] . ",";
$report_ids .= $v["id"] . ",";
}
$order_ids = rtrim($order_ids, ",");
$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";
//$house_title = mb_substr($v['house_title'], 0, 3, 'utf-8') . "***";
$house_title = $v['house_title'];
$v["step"] = "进场【id:" . $v['house_id'] . " " . $house_title . "】";
$result[$sort++] = $v;
}
}
//跟进
$field_follow_up = "a.id,a.agent_id,a.agent_name,a.user_type,a.decision_maker,a.industry_type,a.area_requirement,a.price_requirement,a.province,a.city,
a.district,a.business_area,a.explain,a.explain_img,a.create_time,b.name,b.img,c.store_name";
$followUpLogData = $followUpLogModel->getFollowUpByOrderId($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;
$v["explain_img"] = $v["explain_img"];
$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";
//$house_title = mb_substr($v['house_title'], 0, 3, 'utf-8') . "***";
$house_title = $v['house_title'];
$v["step"] = "收款【id:" . $v['house_id'] . " " . $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";
//$house_title = mb_substr($v['house_title'], 0, 3, 'utf-8') . "***";
$house_title = $v['house_title'];
$v["step"] = "退款【id:" . $v['house_id'] . " " . $house_title . "】";
$result[$sort++] = $v;
}
}
//成交报告
$field_bargain = "a.id,a.create_time,a.house_number,a.is_open,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";
//$house_title = mb_substr($v['house_title'], 0, 3, 'utf-8') . "***";
$house_title = $v['house_title'];
$v["step"] = "成交报告【id:" . $v['house_id'] . " " . $house_title . "】";
$result[$sort++] = $v;
}
}
return $this->sortByTime($result);
}
/**
* 查询流程 商铺动态
* @param $house_id
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function selectListByHouseId($house_id)
{
$result = [];
$sort = 0;
$gHousesFollowModel = new GHousesFollowUp();
//楼盘跟进
$field_shop_follow_up = "a.id,a.follow_up_info,a.agent_id,a.create_time,b.name as agent_name,b.img,c.store_name";
$houseFollowUpData = $gHousesFollowModel->getShopFollowUpList($field_shop_follow_up, ["house_id" => $house_id]);
if (count($houseFollowUpData) > 0) {
foreach ($houseFollowUpData as $k => $v) {
$v["step_name"] = "shop_follow_up";
$v["step"] = "跟进:" . $v["follow_up_info"];
$result[$sort++] = $v;
}
}
return $this->sortByTime($result);
}
/**
* @param $item
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
private function convertFollowUp($item)
{
switch ($item["user_type"]) {
case 1:
$item["user_type"] = "A类(成交意愿较强)";
break;
case 2:
$item["user_type"] = "B类(成交意愿中等)";
break;
case 3:
$item["user_type"] = "C类(成交意愿较弱)";
break;
}
switch ($item["industry_type"]) {
case 1:
$item["industry_type"] = "轻餐饮";
break;
case 2:
$item["industry_type"] = "重餐饮";
break;
case 3:
$item["industry_type"] = "百货零售";
break;
case 4:
$item["industry_type"] = "服装";
break;
case 5:
$item["industry_type"] = "亲子教育";
break;
case 6:
$item["industry_type"] = "休闲娱乐";
break;
default:
$item["industry_type"] = "其他";
}
switch ($item["area_requirement"]) {
case 1:
$item["area_requirement"] = "30平米内";
break;
case 2:
$item["area_requirement"] = "30-60平米";
break;
case 3:
$item["area_requirement"] = "60-100平米";
break;
case 4:
$item["area_requirement"] = "100平米上";
break;
default:
$item["area_requirement"] = "其他";
}
switch ($item["price_requirement"]) {
case 1:
$item["price_requirement"] = "月租金10000元以内";
break;
case 2:
$item["price_requirement"] = " 月租金10000-30000元";
break;
case 3:
$item["price_requirement"] = "月租金30000元以上";
break;
default:
$item["price_requirement"] = "其他";
}
$regions = new Regions();
$cityInfo = $regions->getAddressByDiscCode($item["district"]);
$item["area_detail"] = $cityInfo;
return $item;
}
/**
* 排序时间
* @param $result
* @return mixed
*/
private function sortByTime($result)
{
for ($i = 0; $i < count($result); $i++) {
for ($j = $i + 1; $j < count($result); $j++) {
if (strtotime($result[$j]["create_time"]) - strtotime($result[$i]["create_time"]) > 0) {
$temp = $result[$j];
$result[$j] = $result[$i];
$result[$i] = $temp;
}
}
}
return $result;
}
/**
* @param $params 0.客户电话 1.客户姓名,去掉 2.报备人电话 3.报备人姓名 4.商铺名称 5.商铺地址 6客户编号 7商铺编号 8订单id
* @param $pageNo
* @param $pageSize
* @return mixed
* @throws \think\db\exception\BindParamException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @throws \think\exception\PDOException
*/
public function getSearchOrder($params, $pageNo, $pageSize)
{
$condition = $where_ = "1=1 ";
$field = "a.id,a.order_no,a.f_id as report_id,a.house_id,a.house_title,b.report_agent_id,b.report_agent_phone,b.report_agent_name,
b.user_id,b.user_phone,b.user_name,b.predict_see_time";
switch ((int)$params["type"]) {
case 0:
$condition .= "and b.user_phone like '%" . trim($params['search_keyword']) . "%' ";
break;
case 1:
$condition .= "and b.user_name like '%" . trim($params['search_keyword']) . "%' ";
break;
case 2:
$condition .= "and b.report_agent_phone like '%" . trim($params['search_keyword']) . "%' ";
break;
case 3:
$condition .= "and b.report_agent_name like '%" . trim($params['search_keyword']) . "%' ";
break;
case 4:
$condition .= "and a.house_title like '%" . trim($params['search_keyword']) . "%' ";
break;
case 5:
$condition .= "and c.internal_address like '%" . trim($params['search_keyword']) . "%' ";
break;
case 6://客户编号
$condition .= "and b.user_id = " . trim($params['search_keyword']);
break;
case 7://商铺编号
$condition .= "and a.house_id = " . trim($params['search_keyword']);
break;
case 8://订单id
$condition .= "and a.id = " . trim($params['search_keyword']);
break;
default:
return ["code" => "101", "msg" => "搜索类型错误"];
}
$vModel = new VerifyService();
$agentArr = $vModel->getAgentsByAgentId($params["agent_id"]);
if (empty($agentArr)) {
return ["code" => "101", "msg" => "经纪人不存在"];
}
$where_ = $condition;
if ($agentArr) {
$params["report_agent_id"] = $agentArr;
$params["agent_id_s"] = array("in", $agentArr);
$condition .= " and b.report_agent_id in (" . trim($agentArr) . ") ";
}
$caseHouseId = $vModel->getPanpartyAndExclusiveHouseIdByAgentId($params["agent_id_s"]);
$ids = "";
foreach ($caseHouseId as $item) {
$ids .= $item["houses_id"] . ",";
}
$ids = rtrim($ids, ",");
$ids = $ids ? $ids : 0;
$where_ .= " and a.house_id in ($ids)";
$orderModel = new OrderModel();
$result = $orderModel->searchOrder($field, $condition, $where_, $pageNo, $pageSize);
$reportService = new ReportService();
return $reportService->returnResult($result);
}
/**
* @param $params 1 .客户姓名 2.报备人电话 3.报备人姓名 4.商铺名称 5.商铺地址 8订单id
* @param $pageNo
* @param $pageSize
* @return array|mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getSearchOrderByAll($params, $pageNo, $pageSize)
{
$condition = $where_ = "1=1 ";
$field = "a.id,a.order_no,a.f_id as report_id,a.house_id,a.house_title,b.report_agent_id,b.report_agent_phone,b.report_agent_name,
b.user_id,b.user_phone,b.user_name,b.predict_see_time";
switch ((int)$params["type"]) {
case 0:
$condition .= "and b.user_phone like '%" . trim($params['search_keyword']) . "%' ";
break;
case 1:
$condition .= "and b.user_name like '%" . trim($params['search_keyword']) . "%' ";
break;
case 2:
$condition .= "and b.report_agent_phone like '%" . trim($params['search_keyword']) . "%' ";
break;
case 3:
$condition .= "and b.report_agent_name like '%" . trim($params['search_keyword']) . "%' ";
break;
case 4:
$condition .= "and a.house_title like '%" . trim($params['search_keyword']) . "%' ";
break;
case 5:
$condition .= "and c.internal_address like '%" . trim($params['search_keyword']) . "%' ";
break;
case 6://客户编号
$condition .= "and b.user_id = " . trim($params['search_keyword']);
break;
case 7://商铺编号
$condition .= "and a.house_id = " . trim($params['search_keyword']);
break;
case 8://订单id
$condition .= "and a.id = " . trim($params['search_keyword']);
break;
default:
return ["code" => "101", "msg" => "搜索类型错误"];
}
$orderModel = new OrderModel();
$result = $orderModel->searchOrderAll($field, $condition, $pageNo, $pageSize);
$reportService = new ReportService();
return $reportService->returnResult($result);
}
/**
* 获取成交报告列表
* @param $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getBargainList($params)
{
$pageNo = empty($params["page_no"]) ? 1 : $params["page_no"];
$pageSize = empty($params["page_size"]) ? 15 : $params["page_size"];
$agent_id = $params["submit_agent_id"];
$aService = new VerifyService();
$ids = $aService->getAgentsByAgentId($agent_id);
$params["ids"] = $ids;
$bargainModel = new OBargainModel();
$filed = "a.id,a.father_id,a.house_number,a.price,a.commission,a.agent_id,a.create_time,b.user_phone,
b.user_name,b.user_id,c.id as order_id,c.order_no,d.id as house_id,d.internal_title,d.internal_address,b.id as report_id";
$result = $bargainModel->selectBargainList($filed, $params, $pageNo, $pageSize);
$list = [];
foreach ($result as $k => $v) {
$father_id = $v["father_id"];
if ($father_id > 0 && in_array($father_id, $list)) {
unset($result[$k]);
} else {
$result[$k]["create_time"] = date("Y-m-d", strtotime($v["create_time"]));
$result[$k]["id"] = $v["father_id"] == 0 ? $v["id"] : $v["father_id"];
array_push($list, $father_id);
}
}
$sortResult = [];
foreach ($result as $k => $v) {
$sortResult[] = $v;
}
return $sortResult;
}
/**
* 根据订单id搜索成交报告
* @param $params
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getBargainListByOrderId($order_id)
{
$params["order_id"] = $order_id;
$bargainModel = new OBargainModel();
$filed = "a.id,a.father_id,a.price,a.house_number,a.commission,a.agent_id,a.create_time,b.user_phone,b.user_name,b.user_id,c.id as order_id,
d.id as house_id,d.internal_title,d.internal_address,c.order_no,a.report_id";
$result = $bargainModel->selectBargainList($filed, $params, 1, 15);
$list = [];
foreach ($result as $k => $v) {
$father_id = $v["father_id"];
if ($father_id > 0 && in_array($father_id, $list)) {
unset($result[$k]);
} else {
$result[$k]["create_time"] = date("Y-m-d", strtotime($v["create_time"]));
$result[$k]["id"] = $v["father_id"] == 0 ? $v["id"] : $v["father_id"];
array_push($list, $father_id);
}
}
$sortResult = [];
foreach ($result as $k => $v) {
$sortResult[] = $v;
}
return $sortResult;
}
private function recursion($params, $cent_commissions, $i)
{
if (count($params) == 0) {
return $cent_commissions;
} else {
$item = $params[0];
$role = !empty($params[0]["role"]) ? $params[0]["role"] : $params[0]["roles"];
$cent_commission["id"] = $item["id"];
$cent_commission["agent_id"] = $item["agent_id"];
$cent_commission["role"] = !empty($item["role"]) ? $item["role"] : $item["roles"];
$cent_commission["scale"] = !empty($item["scale"]) ? $item["scale"] : $item["scales"];
$cent_commission["name"] = $item["name"];
$cent_commission["phone"] = $item["phone"];
$cent_commission["should_commission"] = $item["should_commission"];
$cent_commission["scale_fee"] = $item["scale_fee"];
$key = 0;
$length = count($params);
for ($j = 0; $j < $length; $j++) {
$value = $params[$j];
if ($value["role"] == $role || $value["roles"] == $role) {
$arr["real_fee"] = $value["real_fee"];
$arr["create_time"] = $value["create_time"];
$arr["confirm_date"] = $value["confirm_date"];
$arr["charity_fund"] = $value["charity_fund"];
$arr["cash"] = $value["cash"];
$arr["practical_fee"] = $value["practical_fee"];
$arr["service_charge"] = $value["service_charge"];
if (!empty($value["real_fee"]) && !empty($value["create_time"])) { //过滤掉空的
$cent_commission["info"][$key] = $arr;
}
$key++;
unset($params[$j]);
}
}
$cent_commissions[$i] = $cent_commission;
$i++;
return $this->recursion(array_merge($params), $cent_commissions, $i);
}
}
/**
* 获取我得成交报告详情
* @param $params
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getBargainDetail($params): array
{
$bargainModel = new OBargainModel();
$bargain_info_filed = "a.id,a.house_number,a.account_time,a.account_statement,a.father_id,a.is_open,a.trade_type,
a.price,a.industry_type,a.estimated_receipt_date,a.commission,c.id as house_id,c.internal_title,c.internal_address,
d.user_id,d.user_phone,d.user_name";
$result = [];
$bargainInfo = $bargainModel->selectBargainDetail($bargain_info_filed, $params);
if (count($bargainInfo) <= 0) {
return [];
}
//o_real_income
$realIncomeModel = new ORealIncome();
$realIncomeArr = $realIncomeModel->getBargainTaxes($params["bargain_id"]);
$bargainInfo[0]["realIncome"] = $realIncomeArr;
$bargainInfo[0]["user_phone"] = substr_replace($bargainInfo[0]["user_phone"], '****', 3, 4);
$result["bargainInfo"] = $bargainInfo[0];
$bargain_id = $bargainInfo[0]["father_id"] == 0 ? $bargainInfo[0]["id"] : $bargainInfo[0]["father_id"];
//分佣提成 o_partial_commission
$field_commission = "a.id,a.agent_id,a.role as roles,a.scale as scales,a.scale_fee,b.role,c.name,c.phone,b.scale,
b.should_commission,b.confirm_date,b.create_time,b.real_fee,b.charity_fund,b.cash,b.practical_fee,b.service_charge";
$cent_commission_arr = $bargainModel->selectBargainCommission($field_commission, ["bargain_id" => $bargain_id]);
//dump($cent_commission_arr);
$cent_commissions = [];
$result["cent_commission"] = $this->recursion($cent_commission_arr, $cent_commissions, 0);
//税费
$taxesModel = new OTaxes();
$fieldTaxes = "id,bargain_id,fee,total_fee,father_id,operation_date,agent_id,agent_name,scale,create_time,role";
$taxesArr = $taxesModel->getBargainTaxes($bargain_id, $fieldTaxes);
$taxes_ = $taxes = array();
foreach ($taxesArr as $items) {
$taxes_[$items["operation_date"]][] = $items;
}
$z = 0;
foreach ($taxes_ as $item) {
$taxes[$z]["operation_date"] = $item[0]["operation_date"];
$taxes[$z]["total_fee"] = $item[0]["total_fee"];
$key = 0;
foreach ($item as $i => $j) {
$taxes[$z]["info"][$key]["role"] = $j["role"];
$taxes[$z]["info"][$key]["agent_name"] = $j["agent_name"];
$taxes[$z]["info"][$key]["scale"] = $j["scale"];
$taxes[$z]["info"][$key]["fee"] = $j["fee"];
$key++;
}
$z++;
}
$result["taxes"] = $taxes;
return $result;
}
/**
* 成交报告提交后用户状态从求租变成已租
* @param $report_id
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function userUpdateInfo($report_id)
{
$reportModel = new OReportModel();
$filed = "id,user_id";
$params["id"] = $report_id;
$result = $reportModel->selectReportById($filed, $params);
if (count($result) > 0) {
$Users = new Users();
$Users->update_user_status(['id' => $result[0]["user_id"], 'user_status' => 1]);
}
}
/**
* 成交报告客户搜索
* @param $type
* @param $order_id
* @return false|null|\PDOStatement|string|\think\Collection
*/
public function searchBargainAgents($type, $order_id)
{
$orderModel = new OrderModel();
$field = "a.id,a.order_no,a.house_id,a.house_title,b.id as report_id,b.user_id,c.user_nick,c.user_phone,
c.user_pic,c.sex";
$where_["order_id"] = $order_id;
$result = $orderModel->selectOrderDetail($field, $where_);
if (count($result) <= 0 || $result[0]["house_id"] <= 0 || $result[0]["user_id"] <= 0) {
return null;
}
$houseAgents = new GHousesToAgents();
$field = "b.id,b.phone,b.name";
switch ($type) {//1盘方,2客方,3反签,4独家,5合作方
case 1:
$params["a.houses_id"] = $result[0]["house_id"];
$params["a.type"] = 2;
$params["a.is_del"] = 0;
$params["b.status"] = 0;
$list = $houseAgents->getAgentsByHouseId($field, $params);
break;
case 2:
$userModel = new Users();
$params["a.id"] = $result[0]["user_id"];
$params["b.status"] = 0;
$list = $userModel->getAgentByUserId($field, $params);
break;
case 3: //反签 == 报备人
$reportModel = new OReportModel();
$params["a.id"] = $result[0]["report_id"];
$params["b.status"] = 0;
$list = $reportModel->getAgentByOrderId($field, $params);
break;
case 4:
$params["a.houses_id"] = $result[0]["house_id"];
$params["a.type"] = 3;
$params["a.is_del"] = 0;
$params["b.status"] = 0;
$list = $houseAgents->getAgentsByHouseId($field, $params);
break;
case 5:
return null;
break;
case 6:
return null;
break;
case 7:
$userModel = new Users();
$params["a.id"] = $result[0]["user_id"];
$params["a.referrer_source"] = 20;
$params["a.status"] = 0;
$params["b.status"] = 0;
$list = $userModel->getAgentByReferrer($field, $params);
break;
default:
return null;
}
return $list;
}
/**
* 1盘方,2客方,3反签,4独家,5合作方(不返回),6APP盘下载方(不返回) 7APP客下载方
*
* @param $order_id
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function searchBargainAllAgents($order_id)
{
$orderModel = new OrderModel();
$field = "a.id,a.order_no,a.house_id,a.house_title,b.id as report_id,b.user_id,c.user_nick,c.user_phone,
c.user_pic,c.sex";
$where_["order_id"] = $order_id;
$result = $orderModel->selectOrderDetail($field, $where_);
if (count($result) <= 0 || $result[0]["house_id"] <= 0 || $result[0]["user_id"] <= 0) {
return null;
}
$houseAgents = new GHousesToAgents();
$field = "b.id,b.phone,b.name";
$where_house["a.houses_id"] = $result[0]["house_id"];
$where_house["a.type"] = ['in', '2,3'];
$where_house["a.is_del"] = 0;
$where_house["b.status"] = 0;
$agent_house = $houseAgents->getAgentsByHouseId($field . ',a.type', $where_house);
$list = [];
$key = 0;
//盘方和独家
foreach ($agent_house as $v) {
$list[$key]['id'] = $v['id'];
$list[$key]['phone'] = $v['phone'];
$list[$key]['name'] = $v['name'];
if ($v['type'] == 2) {
$list[$key]['role'] = 1;
$list[$key]['role_name'] = '盘方';
} else {
$list[$key]['role'] = 4;
$list[$key]['role_name'] = '独家';
}
$key++;
}
$userModel = new Users();
$where_user["a.id"] = $result[0]["user_id"];
$where_user["b.status"] = 0;
$user_data = $userModel->getAgentByUserId($field, $where_user);
//客方
if (isset($user_data[0]['id'])) {
$list[$key]['id'] = $user_data[0]['id'];
$list[$key]['phone'] = $user_data[0]['phone'];
$list[$key]['name'] = $user_data[0]['name'];
$list[$key]['role'] = 2;
$list[$key]['role_name'] = '客方';
$key++;
}
$reportModel = new OReportModel();
$params["a.id"] = $result[0]["report_id"];
$params["b.status"] = 0;
$report_data = $reportModel->getAgentByOrderId($field, $params);
//反签
if (isset($report_data[0]['id'])) {
$list[$key]['id'] = $report_data[0]['id'];
$list[$key]['phone'] = $report_data[0]['phone'];
$list[$key]['name'] = $report_data[0]['name'];
$list[$key]['role'] = 3;
$list[$key]['role_name'] = '反签';
$key++;
}
$params["a.id"] = $result[0]["user_id"];
$params["a.referrer_source"] = 20;
$params["a.status"] = 0;
$params["b.status"] = 0;
$referrer = $userModel->getAgentByReferrer($field, $params);
if ($referrer[0]['id']) {
$list[$key]['id'] = $referrer[0]['id'];
$list[$key]['phone'] = $referrer[0]['phone'];
$list[$key]['name'] = $referrer[0]['name'];
$list[$key]['role'] = 7;
$list[$key]['role_name'] = 'APP客下载方';
}
return $list;
}
/**
* @param $order_id
* @return false|\PDOStatement|string|\think\Collection
*/
public function getBillInfo($order_id)
{
$filed = "house_number,industry_type";
return $this->payLogModel->getBeforeBillInfo($filed, ["order_id" => $order_id]);
}
/**
* pos机付款成功回调
* @param $id
* @param $trade_no
* @param $pay_time
* @param $real_money
* @return false|int
*/
public function updateBillInfo($id, $trade_no, $pay_time, $real_money)
{
$params["id"] = $id;
$params["trade_no"] = $trade_no;
$params["pay_time"] = date("Y-m-d H:i:s", $pay_time);
$params["real_money"] = $real_money;
return $this->payLogModel->updatePayLog($params);
}
public function getCommission($bargain_id)
{
$filed = "a.role,a.agent_id,b.name,a.scale";
$params["a.id|a.father_id"] = $bargain_id;
$params["a.role"] = array("in", "3,4,5");
return $this->bargainModel->agentBargainAll($filed, $params);
}
/**
* 更新成交报告开业
*
* @param $bargain_id
* @param $type
* @param $is_open
* @return bool|int
*/
public function updateBargainIsOpen($bargain_id, $type, $is_open)
{
if (empty($bargain_id) || !in_array($type, [91, 92])) {
return false;
}
if (!in_array($is_open, [0, 1])) {
return false;
}
$num = $this->bargainModel->updateBargainById($bargain_id, ['is_open' => $is_open]);
if ($num) {
$result = 1;
} else {
$result = 0;
}
return $result;
}
}
\ No newline at end of file
......@@ -924,4 +924,9 @@ Route::group('search', [
'search' => ['search/Search/search', ['method' => 'get|post']],
]);
Route::group('office', [
'isBargainEnd' => ['api_broker/OrderLog/isBargainEnd', ['method' => 'get']],
]);
//Route::miss('api/index/miss');//处理错误的url
\ 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