Commit 5a1c9757 authored by clone's avatar clone

财务日报

parent 53f179ef
......@@ -11,6 +11,9 @@ use app\model\GHousesToAgents;
use app\model\OBargainModel;
use app\model\ODaily;
use app\model\ODailyLog;
use app\model\OfficeGRoom;
use app\model\OfficeOBargainModel;
use app\model\OfficeOPayLogModel;
use app\model\OImg;
use app\model\OPayLogAdjustment;
use app\model\OPayLogModel;
......@@ -275,34 +278,37 @@ class DailyPaperService
return null;
}
$payLogModel = new OPayLogModel();
$payLogOpenModel = new OPayLogOpen();
$officePayLogModel = new OfficeOPayLogModel();
//中介费入账
$field = "a.id,c.id as bargain_id,b.house_id,c.price,a.money,a.pay_type,a.transfer_name,a.type,a.type_ext,a.income_time,
d.report_agent_id as agent_id,a.is_open,a.is_dividend,a.receipt_number,a.create_time,a.remark,a.received_money,a.transaction_fee,
a.order_no,a.order_id,a.report_id,a.bargain_id,a.real_money";
$field = "a.id,c.id as bargain_id,b.house_id,c.price,a.money,a.pay_type,a.transfer_name,a.type, a.type_ext,
a.income_time,d.report_agent_id as agent_id,d.report_agent_name as current_agent_name,a.is_open,a.is_dividend,
a.receipt_number,a.create_time,a.remark,a.received_money,a.transaction_fee, a.order_no,a.order_id,a.report_id,
a.bargain_id,a.real_money";
$params["a.agent_id"] = array("in", ($ids));
$params["a.create_time"] = array("between", array($daily_data, $daily_data . " 23:59:59"));
$params["a.is_del"] = 0;
$params["a.type"] = 91;
$params["c.father_id"] = 0;
$info["agency_fee"] = $this->getHouseAndAgentInfo(
$payLogModel->selectPayLogListByBargain($field, $params)
$agency_fee_shop = $this->getHouseAndAgentInfo(
$payLogModel->selectPayLogListByBargain($field . ",1 as type", $params)
);
$agency_fee_office = $this->getHouseAndAgentInfo(
$officePayLogModel->selectPayLogListByBargain($field . ",2 as type", $params), 2
);
$info["agency_fee"] = array_merge($agency_fee_shop, $agency_fee_office);
foreach ($info["agency_fee"] as $k => $v) {
$info["agency_fee"][$k]['current_agent_name'] = '';
if ($v['bargain_id'] > 0) {
$current_agent_name = $this->getBargainAgent($v['bargain_id']);
$current_agent_name = $this->getBargainAgent($v['bargain_id'], $v["type"]);
if ($current_agent_name) {
$info["agency_fee"][$k]['current_agent_name'] = $current_agent_name;
}
}
$open_id = $payLogOpenModel->getFieldOneValue('id', ['pay_log_id' => $v['id'],'is_del'=>0]);
if ($open_id) {
$info["agency_fee"][$k]['is_check'] = 1;
} else {
$info["agency_fee"][$k]['is_check'] = 0;
if ($v["type"] == 1 && $this->openCheckButton($v['id'])) {
$info["agency_fee"][$k]['is_check'] = 1;
}
}
......@@ -310,74 +316,85 @@ class DailyPaperService
//案场费入账 盘方
$params["a.type"] = 92;
$case_fee_arr = $payLogModel->selectPayLogListByBargain($field, $params);
$new_case_fee_arr = $this->getHousePan($case_fee_arr);
$info["case_fee"] = $this->getHouseAndAgentInfo($new_case_fee_arr);
$case_fee_arr_shop = $payLogModel->selectPayLogListByBargain($field . ",1 as type", $params);
$case_fee_shop = $this->getHouseAndAgentInfo($this->getHousePan($case_fee_arr_shop));
$case_fee_arr_office = $officePayLogModel->selectPayLogListByBargain($field . ",2 as type", $params);
$case_fee_office = $this->getHouseAndAgentInfo($this->getHousePan($case_fee_arr_office), 2);
$info["case_fee"] = array_merge($case_fee_shop, $case_fee_office);
foreach ($info["case_fee"] as $k => $v) {
$info["case_fee"][$k]['current_agent_name'] = '';
if ($v['bargain_id'] > 0) {
$current_agent_name = $this->getBargainAgent($v['bargain_id']);
$current_agent_name = $this->getBargainAgent($v['bargain_id'], $v["type"]);
if ($current_agent_name) {
$info["case_fee"][$k]['current_agent_name'] = $current_agent_name;
}
}
$open_id = $payLogOpenModel->getFieldOneValue('id', ['pay_log_id' => $v['id'],'is_del'=>0]);
if ($open_id) {
$info["case_fee"][$k]['is_check'] = 1;
} else {
$info["case_fee"][$k]['is_check'] = 0;
$info["agency_fee"][$k]['is_check'] = 0;
if ($v["type"] == 1 && $this->openCheckButton($v['id'])) {
$info["agency_fee"][$k]['is_check'] = 1;
}
}
$field_money = "a.id,a.money,a.type,a.type_ext,b.house_id,b.id as order_id,a.pay_type,a.transfer_name, d.report_agent_id as agent_id,
a.is_dividend,a.receipt_number,a.create_time,a.income_time,a.transaction_fee,a.order_no,a.order_id,a.report_id,a.real_money";
$field_money = "a.id,a.money,a.type,a.type_ext,b.house_id,b.id as order_id,a.pay_type,a.transfer_name,
d.report_agent_id as agent_id, d.report_agent_name as current_agent_name, a.is_dividend,a.receipt_number,
a.create_time,a.income_time,a.transaction_fee,a.order_no,a.order_id,a.report_id,a.real_money";
//意向金
$params["a.type"] = 10;
unset($params["c.father_id"]);
$info["earnest_money"] = $this->getHouseAndAgentInfo(
$payLogModel->selectPayLogListByBargainReport($field_money, $params)
$earnest_money_shop = $this->getHouseAndAgentInfo(
$payLogModel->selectPayLogListByBargainReport($field_money . ",1 as type", $params)
);
$m_report = new OReportModel();
foreach ($info["earnest_money"] as $k => $v) {
if ($v['report_id'] > 0) {
$current_agent_name = $m_report->selectReportById('report_agent_name,report_store_id', ['id' => $v['report_id']]);
$info["earnest_money"][$k]['current_agent_name'] = empty($current_agent_name[0]['report_agent_name']) ? "" : $current_agent_name[0]['report_agent_name'];
} else {
$info['earnest_money'][$k]['current_agent_name'] = '';
}
}
$earnest_money_office = $this->getHouseAndAgentInfo(
$officePayLogModel->selectPayLogListByBargainReport($field_money . ",2 as type", $params), 2
);
$info["earnest_money"] = array_merge($earnest_money_shop, $earnest_money_office);
//保管金
$params["a.type"] = 30;
$info["custody_money"] = $this->getHouseAndAgentInfo(
$payLogModel->selectPayLogListByBargainReport($field_money, $params)
$custody_money_shop = $this->getHouseAndAgentInfo(
$payLogModel->selectPayLogListByBargainReport($field_money . ",1 as type", $params)
);
foreach ($info["custody_money"] as $k => $v) {
if ($v['report_id'] > 0) {
$current_agent_name = $m_report->selectReportById('report_agent_name,report_store_id', ['id' => $v['report_id']]);
$info['custody_money'][$k]['current_agent_name'] = empty($current_agent_name[0]['report_agent_name']) ? "" : $current_agent_name[0]['report_agent_name'];
} else {
$info['custody_money'][$k]['current_agent_name'] = '';
}
}
$custody_money_office = $this->getHouseAndAgentInfo(
$officePayLogModel->selectPayLogListByBargainReport($field_money . ",2 as type", $params), 2
);
$info["custody_money"] = array_merge($custody_money_shop, $custody_money_office);
//调整出账
$field_adjustment = "b.id,c.house_id,b.new_paylog_id as pay_log_id,a.agent_id,b.money,a.income_time,b.type,
a.receipt_number,a.create_time,a.transaction_fee,b.paylog_id as old_paylog_id,a.report_id,a.real_money";
$params_adjustment["b.operation_id"] = array("in", ($ids));
$params_adjustment["a.is_del"] = 0;
$params_adjustment["b.is_del"] = 0;
$params_adjustment["b.create_time"] = array("between", array($daily_data, $daily_data . " 23:59:59"));
$info["adjustment"] = $this->getHouseAndAgentInfo(
$payLogModel->selectAdjustmentList($field_adjustment, $params_adjustment)
$adjustment_shop = $this->getHouseAndAgentInfo(
$payLogModel->selectAdjustmentList($field_adjustment . ",1 as type", $params_adjustment)
);
$adjustment_office = $this->getHouseAndAgentInfo(
$officePayLogModel->selectAdjustmentList($field_adjustment . ",2 as type", $params_adjustment), 2
);
$info["adjustment"] = array_merge($adjustment_shop, $adjustment_office);
return $info;
}
/**
* 判断是否申请开盘,申请了的不显示申请按钮
* @param $id
* @return bool
*/
private function openCheckButton($id)
{
$payLogOpenModel = new OPayLogOpen();
$open_id = $payLogOpenModel->getFieldOneValue('id', ['pay_log_id' => $id, 'is_del' => 0]);
if ($open_id) {
return true;
}
return false;
}
/**
* 获取盘方
* @param $data
......@@ -411,12 +428,13 @@ class DailyPaperService
/**
* @param $data
* @param $type
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
private function getHouseAndAgentInfo($data)
private function getHouseAndAgentInfo($data, $type = 1)
{
$agent_id_str = "";
$house_id_str = "";
......@@ -429,7 +447,14 @@ class DailyPaperService
$house_id_str = rtrim($house_id_str, ",");
$agent_arr = $this->agentInfo($agent_id_str);
$house_arr = [];
if ($type == 1) {
$house_arr = $this->houseInfo($house_id_str);
} else {
$house_arr = $this->roomInfo($house_id_str);
}
foreach ($data as $k => $v) {
$data[$k]["agent_name"] = "";
......@@ -452,6 +477,7 @@ class DailyPaperService
}
/**
* @param $agent_id_str
* @return false|\PDOStatement|string|\think\Collection
......@@ -479,6 +505,20 @@ class DailyPaperService
return $houseModel->getHouseInfo("id,internal_address", $params);
}
/**
* @param $house_id_str
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
private function roomInfo($house_id_str)
{
$roomModel = new OfficeGRoom();
$params["a.id"] = array("in", ($house_id_str));
return $roomModel->getRoomInfo("a.id,b.address as internal_address", $params);
}
/**
* 获取盘方
* @param $house_id_str
......@@ -820,18 +860,23 @@ class DailyPaperService
* 对应业务员
*
* @param $bargain_id
* @param $type
* @return string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getBargainAgent($bargain_id)
public function getBargainAgent($bargain_id, $type)
{
$bargain_where[] = ['EXP', 'a.id =' . $bargain_id . ' or father_id=' . $bargain_id];
$bargain_where['a.status'] = ['in', '10,11,13'];
$bargain_where['a.role'] = ['in', '3,4,5'];
if ($type == 1) {
$m_bargain = new OBargainModel();
} else {
$m_bargain = new OfficeOBargainModel();
}
$bargain_data = $m_bargain->agentBargainAll('a.role,a.scale,b.name', $bargain_where);
$role_arr = [1 => '盘方', 2 => '客方', 3 => '反签', 4 => '独家', 5 => '合作方', 6 => 'APP盘下载方', 7 => 'APP客下载方'];
$name = '';
......
......@@ -36,12 +36,12 @@ class DailyPaper extends Basic
{
header('Access-Control-Allow-Origin:*');
$params = $this->params;
/* $params = array(
"store_id" => 730,//门店id
$params = array(
"store_id" => 0,//门店id
"is_store" => 0,//身份是否是店长,财务显示不一样 0店长 1财务
"daily_data" => "2018-12-18"
"daily_data" => "2019-06-03"
);
$this->userId = 5775;*/
$this->userId = 1;
if (!isset($params["store_id"]) || !isset($params["is_store"]) || !isset($params["daily_data"])) {
return $this->response("101", "请求参数错误");
}
......
......@@ -247,6 +247,18 @@ class OfficeGRoom extends BaseModel
return $result;
}
public function getRoomInfo($field, $params)
{
$result = Db::table($this->table)
->field($field)
->alias("a")
->join('office_g_building b', 'a.building_id = b.id', 'left')
->where($params)
->select();
return $result;
}
/**
* @param $page_no
* @param $page_size
......
......@@ -437,10 +437,10 @@ class OfficeOPayLogModel extends Model
{
return $this->db_->field($filed)
->alias("a")
->join("o_order b", "a.order_id = b.id", "left")
->join("office_o_order b", "a.order_id = b.id", "left")
// ->join("o_bargain c", "c.order_id = b.id", "left")
->join("o_bargain c", "c.id = a.bargain_id", "left")
->join("o_report d", "a.report_id = d.id", "left")
->join("office_o_bargain c", "c.id = a.bargain_id", "left")
->join("office_o_report d", "a.report_id = d.id", "left")
->where($params)
->group("a.id")
->select();
......@@ -476,8 +476,8 @@ class OfficeOPayLogModel extends Model
{
return $this->db_->field($filed)
->alias("a")
->join("o_paylog_adjustment b", "a.id = b.paylog_id", "right")
->join("o_order c", "a.order_id = c.id", "left")
->join("office_o_paylog_adjustment b", "a.id = b.paylog_id", "right")
->join("office_o_order c", "a.order_id = c.id", "left")
->where($params)
->select();
}
......
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