Commit b6913b64 authored by clone's avatar clone

1

parent cede883a
......@@ -4,6 +4,11 @@ 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\api_broker\service\VipService;
use app\model\OfficeGRoom;
use app\model\OfficeOBargainModel;
use app\model\OfficeOImg;
use app\model\OfficeOMarchInModel;
use app\model\OMarchInModel;
/**
......@@ -17,13 +22,15 @@ class OfficeOrderLog extends Basic{
private $o_march_in_model;
private $service_;
private $verifyService_;
private $o_img_model;
function __construct($request = null)
{
parent::__construct($request);
$this->o_march_in_model = new OMarchInModel();
$this->o_march_in_model = new OfficeOMarchInModel();
$this->service_ = new OfficeOrderLogService();
$this->verifyService_ = new VerifyRepetitionService();
$this->o_img_model = new OfficeOImg();
}
/**
......@@ -61,15 +68,14 @@ class OfficeOrderLog extends Basic{
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);
$this->o_img_model->addImgAll($insert_id, 1, $march_in_img);
$pushMarchIn = new PushMessageService();
$pushMarchIn->pushMarchInMessage($params["report_id"], 1, $this->agentId); //推送
/*$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);
$push_client->record((int)$params["report_id"], (int)$params["order_id"], 0, '', (int)$this->agentId);*/
//对客户发送短信通知 7151
// $this->sendSMSForUser($params["report_id"]);
......@@ -79,24 +85,6 @@ class OfficeOrderLog extends Basic{
}
}
/**
* 对客户发送短信通知
* @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;
}
}
/**
* 收款
......@@ -447,14 +435,14 @@ class OfficeOrderLog extends Basic{
if (!isset($params["type"]) || $params["type"] != 20 && $params["type"] != 21 && $params["type"] != 30) {
return $this->response("101", "要修改的状态类型错误");
}
$obm = new OBargainModel();
$obm = new OfficeOBargainModel();
$save_param["status"] = $params["type"];
$is_ok = $obm->updateBargainById($params["id"], $save_param);
if ($is_ok > 0) {
$houseNumUpdateService = new HouseNumUpdateService();
$houseNumUpdateService = new OfficeGRoom();
$houseNumUpdateService->updateHouseNumByRevocationBargain($params["id"]);
return $this->response("200", "request success", ["msg" => "状态修改成功"]);
} else {
......
......@@ -13,6 +13,7 @@ use app\model\FollowUpLogModel;
use app\model\GHousesFollowUp;
use app\model\GHousesToAgents;
use app\model\OBargainModel;
use app\model\OfficeOImg;
use app\model\OImg;
use app\model\OMarchInModel;
use app\model\OPayLogAdjustment;
......@@ -33,11 +34,13 @@ class OfficeOrderLogService
{
private $payLogModel;
private $bargainModel;
private $o_img_model;
function __construct()
{
$this->payLogModel = new OPayLogModel();
$this->bargainModel = new OBargainModel();
$this->o_img_model = new OfficeOImg();
}
/**
......@@ -110,8 +113,7 @@ class OfficeOrderLogService
if ($father_id > 0) {
//保存图片
if ($transfer_img) {
$oImgModel = new OImg();
$oImgModel->addImgAll($father_id, 2, $transfer_img);
$this->o_img_model->addImgAll($father_id, 2, $transfer_img);
}
if ($pay_id > 0) {
......
......@@ -16,4 +16,7 @@ class OfficeGRoom extends BaseModel
parent::__construct($data);
$this->db_ = Db::name($this->table);
}
public function updateHouseNumByRevocationBargain($room_id){
}
}
<?php
namespace app\model;
use app\task\controller\ResultsSummaryNewTask;
use think\Db;
use think\Log;
use think\Model;
/**
* Created by PhpStorm.
* User : zw
* Date : 2018/2/1
* Time : 17:15
* Intro:
*/
class OfficeOBargainModel extends Model
{
protected $table = "office_o_bargain";
private $db_;
public function __construct()
{
$this->db_ = Db::name($this->table);
}
public function addBargain($params)
{
Db::startTrans();
try {
$this->db_->insertAll($params);
Db::commit();
return 1;
} catch (\Exception $e) {
Db::rollback();
return 0;
}
}
public function insertBargain($params)
{
Db::startTrans();
try {
$id = $this->db_->insertGetId($params);
Db::commit();
return $id;
} catch (\Exception $e) {
Db::rollback();
return 0;
}
}
/**
* 修改信息
*
* @param $id
* @param $params
* @return int
*/
public function updateBargainById($id, $params)
{
$params["update_time"] = date("Y-m-d H:i:s", time());
Db::startTrans();
try {
$this->db_->where('id', $id)->update($params);
Db::commit();
return 1;
} catch (\Exception $e) {
Db::rollback();
return 0;
}
}
/**
* 修改信息
*
* @param $data
* @param $params
* @return int
*/
public function updateBargainByWhere($data, $params)
{
$data["update_time"] = date("Y-m-d H:i:s", time());
Db::startTrans();
try {
$this->db_->where($params)->update($data);
Db::commit();
return 1;
} catch (\Exception $e) {
Db::rollback();
return 0;
}
}
/**
* 查询成交报告记录
*
* @param $filed
* @param $params
* @param string $order
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function selectBargainByOrderNo($filed, $params, $order = 'id desc')
{
$where_ = [];
if (isset($params["report_id"])) {
$where_["report_id"] = $params["report_id"];
}
if (isset($params["order_no"])) {
$where_["order_no"] = $params["order_no"];
}
if (isset($params["father_id"])) {
$where_["father_id"] = $params["father_id"];
}
if (isset($params["order_id"])) {
$where_["order_id"] = $params["order_id"];
}
if (isset($params["agent_id"])) {
$where_["agent_id"] = $params["agent_id"];
}
if (isset($params['id'])) {
$where_['id'] = $params['id'];
}
return $this->db_
->field($filed)
->where($where_)
->order($order)
->select();
}
/**
* 根据商铺号查询成交报告中业态
*
* @param $house_id
* @return string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function selectBargainListByHouseId($house_id)
{
$params["b.house_id"] = $house_id;
$params["a.status"] = array( "not in", "21,30" );
$data = $this->db_
->field("a.id,a.industry_type")
->alias("a")
->join("o_order b", "a.order_id=b.id", "left")
->where($params)
->select();
$str = "";
if (count($data) <= 0) {
return $str;
}
foreach ($data as $item) {
if (!empty($item["industry_type"])) {
$str .= "、" . $item["industry_type"];
}
}
return $str;
}
/**
* 查询成交报告记录
*
* @param $filed
* @param $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function selectBargainListByOrderNo($filed, $params)
{
$where_ = [];
if (isset($params["report_id"])) {
$where_["a.report_id"] = $params["report_id"];
}
if (isset($params["order_no"])) {
$where_["a.order_no"] = $params["order_no"];
}
if (isset($params["order_id"])) {
$where_["a.order_id"] = $params["order_id"];
}
if (isset($params["agent_id"])) {
$where_["a.agent_id"] = $params["agent_id"];
}
return $this->db_
->field($filed)
->alias("a")
->join("a_agents b", "a.agent_id = b.id", "left")
->where($where_)
->select();
}
/**
* @param $field
* @param $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getBargainByOrderId($field, $params)
{
$where_ = [];
if (isset($params["order_id"])) {
$where_["a.order_id"] = $params["order_id"];
}
if (isset($params["house_title"])) {
$where_["b.house_title"] = $params["house_title"];
}
return Db::table($this->table)
->field($field)
->alias("a")
->join("o_order b", "a.order_id = b.id", "left")
->join("a_agents c", "a.agent_id = c.id", "left")
->join("a_store d", "c.store_id = d.id", "left")
->where($where_)
->select();
}
/**
* 获取我得成交
*
* @param $filed
* @param $params
* @param $pageNo
* @param $pageSize
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function selectBargainList($filed, $params, $pageNo, $pageSize)
{
$where_ = [];
if (isset($params["status"])) {
$where_["a.status"] = $params["status"];
}
if (isset($params["ids"])) {
$where_["a.agent_id"] = array( "in", $params["ids"] );
}
if (isset($params["account_statement"])) {
$where_["a.account_statement"] = $params["account_statement"];
}
if (isset($params["order_id"])) {
$where_["a.order_id"] = $params["order_id"];
}
if (isset($params["father_id"])) {
$where_["a.father_id"] = $params["father_id"];
}
if (!isset($params["type"]) && isset($params["keyword"])) {
$where_["b.user_phone|b.user_name|d.internal_address"] = array( "like", "%" . $params["keyword"] . "%" );
}
switch ((int)$params["type"]){ //1商铺id 2商铺地址 3成交报告id 4带看id 5客户id
case 1:
$where_["d.id"] = $params["keyword"];
break;
case 2:
$where_["d.internal_address"] = array("like" , "%" . trim($params['keyword']) . "%");
break;
case 3:
$where_["a.id"] = $params["keyword"];
break;
case 4:
$where_["c.id"] = $params["keyword"];
break;
case 5:
$where_["b.user_id"] = $params["keyword"];
break;
}
if (isset($params["id"])) {
$where_["a.id"] = $params["id"];
}
$where_["b.status"] = 0;
$where_["c.is_del"] = 0;
$result = $this->db_
->field($filed)
->alias("a")
->join("o_report b", "a.report_id = b.id", "left")
->join("o_order c", "a.order_id = c.id", "left")
->join("g_houses d", "c.house_id = d.id", "left")
->where($where_)
->order("a.create_time desc")
->limit($pageSize)
->page($pageNo)
->select();
// big_log($this->db_->getLastSql());
return $result;
}
/**
* 获取成交报告详情
*
* @param $filed
* @param $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function selectBargainDetail($filed, $params)
{
$where_ = $whereOr_ = [];
if (isset($params["bargain_id"])) {
$where_["a.id"] = $params["bargain_id"];
}
$result = $this->db_
->field($filed)
->alias("a")
->join("o_order b", "a.order_id = b.id", "left")
->join("g_houses c", "b.house_id = c.id", "left")
->join("o_report d", "a.report_id = d.id", "left")
->where($where_)
->whereOr($whereOr_)
->order("a.id asc")
->select();
// echo $this->getLastSql();
return $result;
}
/**
* 获取成交报告详情
*
* @param $filed
* @param $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function selectBargainCommission($filed, $params)
{
$where_ = $whereOr_ = [];
if (isset($params["bargain_id"])) {
$where_["a.id"] = $params["bargain_id"];
$whereOr_["a.father_id"] = $params["bargain_id"];
}
if (isset($params['id'])) {
$where_['a.id'] = $params['id'];
}
$where_['a.status'] = array( "<>", 30 );
$result = $this->db_
->field($filed)
->alias("a")
->join("o_partial_commission b", "a.id = b.bargain_id", "left")
->join("a_agents c", "a.agent_id = c.id", "left")
->where($where_)
->whereOr($whereOr_)
->order("a.id asc")
->select();
// echo $this->getLastSql();
return $result;
}
/**
* 成交报告列表
*
* @param int $pageNo
* @param int $pageSize
* @param string $order_
* @param string $field
* @param string $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getBargainList($pageNo = 1, $pageSize = 15, $order_ = 'id desc', $field = '', $params = '')
{
return $this->db_->field($field)->alias('a')
->join('o_report b', 'a.report_id = b.id', 'left')
->join('o_order c', 'a.order_id = c.id', 'left')
->join('g_houses d', 'c.house_id = d.id', 'left')
->join('o_partial_commission e', 'a.id = e.bargain_id', 'left')
//->join('o_paylog f', 'a.id = f.bargain_id', 'left')
->where($params)
->order($order_)
->limit($pageSize)
->page($pageNo)
->group('a.id')
->select();
}
/**
* @param string $field
* @param string $params
* @return float|int
*/
public function getBargainListSum($field = '', $params = '')
{
return $this->db_->alias('a')
->join('o_report b', 'a.report_id = b.id', 'left')
->join('o_order c', 'a.order_id = c.id', 'left')
->join('g_houses d', 'c.house_id = d.id', 'left')
->join('o_partial_commission e', 'e.bargain_id = a.id', 'left')
//->join('o_paylog f', 'a.id = f.bargain_id', 'left')
->where($params)
->sum($field);
}
/**
* 成交报告总数
*
* @param array $params
* @return int
*/
public function getBargainTotal(array $params = [])
{
return $this->db_->alias('a')
->join('o_report b', 'a.report_id = b.id', 'left')
->join('o_order c', 'a.order_id = c.id', 'left')
->join('g_houses d', 'c.house_id = d.id', 'left')
->join('o_partial_commission e', 'e.bargain_id = a.id', 'left')
//->join('o_paylog f', 'a.id = f.bargain_id', 'left')
->where($params)
->group('a.id')
->count();
}
/**
* 成交报告审核
*
* @param int $id
* @param array $data
* @param int $source 审核来源 1成交报告申请结单 2退款 3申请撤销成交报告
* @param int $status 成交报告状态 10已提交 11审核开始 12驳回 13审核成功 20待撤销 21已撤销 30删除
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function addCheckBargain(int $id, array $data, int $source, int $status): bool
{
$this->startTrans();
$bargain_data = $this->field('id,report_id,agent_id,order_no,order_id')->where([
'id' => $id,
'status' => [ 'in', '10,11,20,21' ]
])->find();
if ($bargain_data != '') {
$audit = new OFinancialAudit();
$audit_data = $audit->getLastStep($bargain_data['id'], $source); //获取最后一次审核等级
$save_data['bargain_id'] = $bargain_data['id'];
$save_data['agent_id'] = $bargain_data['agent_id'];
$save_data['order_no'] = $bargain_data['order_no'];
$save_data['order_id'] = $bargain_data['order_id'];
$save_data['source'] = $source;
$save_data['status'] = 1;
$save_data['remark'] = $data['remark'];
$save_data['audit_id'] = $data['audit_id'];
$save_data['audit_name'] = $data['audit_name'];
$return = 0;
//是否有审核记录,只做一次审核。
if (isset($audit_data['id'])) {
if ($source == 3 && $data['audit_level'] == 3) {
$save_data['status'] = 4;
}
//第二、三审核
$save_data['audit_level'] = $data['audit_level'];
$return = $audit->addAudit($save_data);
} else {
//第一步审核
$save_data['audit_level'] = 1;
$return = $audit->addAudit($save_data);
}
if ($return) {
if ($status == 10 && $data['audit_level'] == 1) {
//审核开始
$update_data['status'] = 11;
} elseif ($data['audit_level'] == 3 && $status == 11) {
//成交报告审核-三级审核结束
$update_data['status'] = 13;
$update_data['account_statement'] = 1;
$update_data['account_time'] = date('Y-m-d H:i:s');
} elseif ($data['audit_level'] == 3 && $status == 20) {
//撤销审核结束
$update_data['status'] = 21;
$update_data['account_statement'] = 1;
$update_data['account_time'] = date('Y-m-d H:i:s');
}
//记录第几级审核-与 OFinancialAudit 表一致
$update_data['audit_level'] = $data['audit_level'];
$where_bargain['status'] = [ '<>', 30 ];
$where_bargain[] = [ 'EXP', 'id=' . $bargain_data['id'] . ' or father_id=' . $bargain_data['id'] ];
$this->where($where_bargain)->update($update_data);
$this->commit();
$result = true;
} else {
$this->rollback();
$result = false;
}
} else {
$result = false;
}
return $result;
}
/**
* 获取成交报告详情
*
* @param $field
* @param $params
* @return array|false|\PDOStatement|string|Model
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getBargainInfo($field, $params)
{
$data = $this->field($field)->alias('a')
->join('o_report b', 'a.report_id = b.id', 'left')
->join('o_order c', 'a.order_id = c.id', 'left')
->join('g_houses d', 'c.house_id = d.id', 'left')
->join('o_partial_commission e', 'e.bargain_id = a.id', 'left')
->where($params)
->find();
if (isset($data['id'])) {
$m_fee = new ORealIncome();
$data['practical_fee'] = $m_fee->getBargainTaxes($data['id']); //获取实收佣金
} else {
$data = [];
}
return $data;
}
/**
* 获取成交报告详情
*
* @param int $pageNo
* @param int $pageSize
* @param string $order_
* @param $field
* @param $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getBargainOrderList($pageNo = 1, $pageSize = 15, $order_ = 'a.id desc', $field, $params)
{
$data = $this->field($field)->alias('a')
->join('o_report b', 'a.report_id = b.id', 'left')
->join('o_order c', 'a.order_id = c.id', 'left')
->join('g_houses d', 'c.house_id = d.id', 'left')
->where($params)
->order($order_)
->limit($pageSize)
->page($pageNo)
->select();
foreach ($data as $k => $v) {
if (isset($v['singntime'])) {
$data[$k]['singntime'] = date('Y-m-d', strtotime($v['singntime']));
}
if (empty($v['shop_sign'])) {
$data[$k]['shangpu_tags'] = "";
} else {
$data[$k]['shangpu_tags'] = explode(',', $v['shop_sign']);
}
if (isset($v['house_id'])) {
$img_name = $this->db_->table('g_houses_imgs')->where('id', $v['house_id'])->value('img_name');
$data[$k]['img'] = CK_IMG_URL . 'images/' . $img_name;
}
}
return $data;
}
/**
* @param $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getReceivedGroupTime($params)
{
$where_ = [];
$field = "sum(b.practical_fee) as num,DATE(b.create_time) as day";
if (isset($params["agent_id"])) {
$where_["a.agent_id"] = $params["agent_id"];
}
if (isset($params["create_time"])) {
$where_["b.create_time"] = $params["create_time"];
}
return Db::table($this->table)
->field($field)
->alias("a")
->join("o_partial_commission b", "a.id=b.bargain_id", "right")
->where($where_)
->group("day")
->select();
}
/**
* @param $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getReceivedGroupTimeNew($params)
{
$where_ = [];
$field = "sum(b.practical_fee) as num";
if (isset($params["agent_id"])) {
$where_["a.agent_id"] = $params["agent_id"];
}
if (isset($params["create_time"])) {
$where_["c.income_time"] = $params["create_time"];
}
return Db::table($this->table)
->field($field)
->alias("a")
->join("o_partial_commission b", "a.id=b.bargain_id", "right")
->join('o_real_income c', 'b.real_income_id = c.id', 'left')
->where($where_)
->select();
}
/**
* @param $params
* @param $type
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getAddBargainNumGroupTime($params, $type)
{
$field = "";
$where_ = [];
if ($type == 1) {
$field = "sum(scale_fee) as num,DATE(create_time) as day";
} elseif ($type == 2) {
$field = "sum(practical_fee) as num,DATE(create_time) as day";
} elseif ($type == 3) {
$field = "count(1) as num,DATE(create_time) as day";
//$where_["father_id"] = 0;
//$where_["trade_type"] = 10;//产品要求统计数量必须是出租类型的180620
}
if (isset($params["agent_id"])) {
$where_["agent_id"] = $params["agent_id"];
}
if (isset($params["agent_id"]) && $type == 3) {
unset($where_["agent_id"]);
$where_["submit_agent_id"] = $params["agent_id"];
$where_["father_id"] = 0;
}
if (isset($params["create_time"])) {
$where_["create_time"] = $params["create_time"];
}
return Db::table($this->table)
->field($field)
->where($where_)
->group("day")
->select();
}
/**
* @param $params
* @param $type
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getAddBargainNumGroupTimeNew($params, $type)
{
$field = "";
$where_ = [];
if ($type == 1) {
$field = "sum(scale_fee) as num";
} elseif ($type == 2) {
$field = "sum(practical_fee) as num";
} elseif ($type == 3) {
$field = "count(1) as num";
//$where_["trade_type"] = 10;//产品要求统计数量必须是出租类型的180620
$where_["role"] = 3;//必须是反签方
}
$where_["status"] = array( "in", "10,11,13" );
if (isset($params["agent_id"])) {
$where_["agent_id"] = $params["agent_id"];
}
if (isset($params["create_time"])) {
$where_["create_time"] = $params["create_time"];
}
$data = Db::table($this->table)
->field($field)
->where($where_)
->select();
//echo $this->getLastSql();
return $data;
}
/**
* @param $params
* @param $type
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getAddBargainNum($params, $type)
{
$where_ = [];
$field = "";
$join = [];
if ($type == 1) {
$field = "sum(scale_fee) as num";
} elseif ($type == 2) {
$field = "sum(practical_fee) as num";
} elseif ($type == 3) {
$field = "count(1) as num";
$where_["a.trade_type"] = 10;
if (isset($params["is_case"]) && $params["is_case"] == 2) {
$where_["a.father_id"] = 0;
}
array_push($join, [ ' o_report c', 'a.report_id=c.id', 'left' ]);
}
if (isset($params["agent_id"])) {
$where_["a.agent_id"] = $params["agent_id"];
}
if (isset($params["agent_id"]) && $type == 3) {
unset($where_["agent_id"]);
$where_["c.report_agent_id"] = $params["agent_id"];
}
if (isset($params["create_time"])) {
$where_["a.create_time"] = $params["create_time"];
}
if (isset($params["house_ids"])) {
$where_["b.house_id"] = array( "in", $params["house_ids"] );
array_push($join, [ ' o_order b', 'a.order_id = b.id', 'left' ]);
}
if (isset($params["status"])) {
$where_["a.status"] = $params["status"];
}
$return = Db::table($this->table)
->field($field)
->alias("a")
->join($join)
->where($where_)
->select();
return $return;
}
public function getAddBargainNumV2($params, $type)
{
$where_ = [];
$field = "";
$join = [];
if ($type == 1) {
$field = "sum(scale_fee) as num";
} elseif ($type == 2) {
$field = "sum(practical_fee) as num";
} elseif ($type == 3) {
$field = "count(1) as num";
$where_["a.role"] = 3;//必须是反签方
$where_["a.status"] = array( "in", '10,11,13');
}
if (isset($params["agent_id"])) {
$where_["a.agent_id"] = $params["agent_id"];
}
if (isset($params["create_time"])) {
$where_["a.create_time"] = $params["create_time"];
}
if (isset($params["house_ids"])) {
$where_["b.house_id"] = array( "in", $params["house_ids"] );
array_push($join, [ ' o_order b', 'a.order_id = b.id', 'left' ]);
}
$return = Db::table($this->table)
->field($field)
->alias("a")
->join($join)
->where($where_)
->select();
return $return;
}
/**
* @param $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getReceived($params)
{
$where_ = [];
$field = "sum(b.practical_fee) as num";
if (isset($params["agent_id"])) {
$where_["a.agent_id"] = $params["agent_id"];
}
if (isset($params["create_time"])) {
$where_["b.create_time"] = $params["create_time"];
}
$date = Db::table($this->table)
->field($field)
->alias("a")
->join("o_partial_commission b", "a.id=b.bargain_id", "right")
->where($where_)
->select();
return $date;
}
/**
* 计算实收
* @param $params
* @return false|\PDOStatement|string|\think\Collection
*/
public function getReceivedV2($params)
{
$where_ = [];
$field = "sum(b.practical_fee) as num";
if (isset($params["agent_id"])) {
$where_["a.agent_id"] = $params["agent_id"];
}
if (isset($params["create_time"])) {
$where_["b.confirm_date"] = $params["create_time"];
}
$where_["b.is_del"] = 0;
$where_["b.confirm_status"] = 1;
$where_["a.status"] = array( "in", '10,11,13');
$date = Db::table($this->table)
->field($field)
->alias("a")
->join("o_partial_commission b", "a.id=b.bargain_id", "right")
->where($where_)
->select();
return $date;
}
/**
* @param $page_no
* @param $page_size
* @param $field
* @param $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getReceivedList($page_no, $page_size, $field, $params)
{
$where_ = [];
if (isset($params["agent_id"])) {
$where_["a.agent_id"] = $params["agent_id"];
}
if (isset($params["create_time"])) {
$where_["b.create_time"] = $params["create_time"];
}
$date = Db::table($this->table)
->field($field)
->alias("a")
->join("o_partial_commission b", "a.id=b.bargain_id", "right")
->join("a_agents c", "a.agent_id=c.id", "left")
->join("a_store d", "c.store_id=d.id", "left")
->join("a_district e", "c.district_id=e.id", "left")
->where($where_)
->page($page_no)
->limit($page_size)
->select();
//echo $this->getLastSql();
return $date;
}
/**
* @param $params
* @param $field
* @param $page_no
* @param $page_size
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getAddBargainList($params, $field, $page_no, $page_size)
{
$where_ = [];
if (isset($params["agent_id"])) {
$where_["a.agent_id"] = $params["agent_id"];
}
if (isset($params["create_time"])) {
$where_["a.create_time"] = $params["create_time"];
}
if (isset($params["house_ids"])) {
$where_["b.house_id"] = array( "in", $params["house_ids"] );
}
$where_["a.status"] = array( "in", "10,11,13,20" );
return Db::table($this->table)
->field($field)
->alias("a")
->join("a_agents b", "a.agent_id = b.id", "left")
->join("a_store c", "b.store_id = c.id", "left")
->join("a_district d", "b.district_id = d.id", "left")
->where($where_)
->limit($page_size)
->page($page_no)
->select();
}
/**
* @param $field
* @param $params
* @param $is_case
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getAddBargainOrderList($field, $params, $is_case)
{
$where_ = [];
if (isset($params["agent_id"])) {
$where_["a.agent_id"] = $params["agent_id"];
$where_["a.role"] = 3;
}
if (isset($params["create_time"])) {
$where_["a.create_time"] = $params["create_time"];
if ($is_case == 2) {
$where_["a.father_id"] = 0;
}
$where_["a.trade_type"] = 10;
}
if (isset($params["house_ids"])) {
$where_["b.house_id"] = array( "in", $params["house_ids"] );
}
$data = Db::table($this->table)
->field($field)
->alias("a")
->join("o_order b", "a.order_id = b.id", "left")
->join("o_report c", "b.f_id = c.id", "left")
//->join('g_houses d', 'b.house_id = d.id', 'left')
->where($where_)
->select();
//echo Db::table($this->table)->getLastSql();
return $data;
}
/**
* 判断同一个订单是否有多个成交报告
*/
public function ifBargainNumByOrderId($params)
{
return Db::table($this->table)
->where($params)
->count();
}
/**
* @param $field
* @param $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getBargainDetail($field, $params)
{
return Db::table($this->table)
->field($field)
->where($params)
->order("create_time desc")
->select();
}
/**
* 新增分佣
*
* @param $id
* @param $submit_agent_id
* @param $agent_id
* @param $role
* @param $scale_fee
* @param $scale
* @return bool|int|string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function addBargainCommission($id, $submit_agent_id, $agent_id, $role, $scale_fee, $scale, $source)
{
$this->startTrans();
$this->lock(true);
$bargain_data = $this->where('id', $id)->find();
$m_agent = new AAgents();
$submit_agent_name = $m_agent->getAgentsById($submit_agent_id, 'name');
if (empty($bargain_data['id'])) {
$result = false;
} else {
if ($bargain_data['father_id'] == 0) {
$insert_data['father_id'] = $id;
} else {
$insert_data['father_id'] = $bargain_data['father_id'];
$insert_data['is_commission'] = 1;
}
$insert_data['create_time'] = $bargain_data['create_time']; //分佣方保留打成交报告时间
$insert_data['report_id'] = $bargain_data['report_id'];
$insert_data['agent_id'] = $agent_id;
$insert_data['order_id'] = $bargain_data['order_id'];
$insert_data['order_no'] = $bargain_data['order_no'];
$insert_data['trade_type'] = $bargain_data['trade_type'];
$insert_data['submit_agent_id'] = $submit_agent_id;
$insert_data['submit_agent_name'] = $submit_agent_name;
$insert_data['price'] = $bargain_data['price'];
$insert_data['commission'] = $bargain_data['commission'];
$insert_data['status'] = $bargain_data['status'];
$insert_data['source'] = $source;
$insert_data['role'] = $role;
$insert_data['scale_fee'] = $scale_fee;
$insert_data['scale'] = $scale;
$insert_data['is_commission'] = 1;
$insert_data['is_open'] = $bargain_data['is_open'];
$insert_data['house_number'] = $bargain_data['house_number'];
$insert_data['account_statement'] = $bargain_data['account_statement'];
$insert_data['content'] = $bargain_data['content'];
$insert_data['industry_type'] = $bargain_data['industry_type'];
$result = $this->insert($insert_data);
if ($result == 1) {
$this->commit();
} else {
$this->rollback();
$result = false;
}
}
return $result;
}
/**
* 成交报告详情-分佣提成
*
* @param $pageNo
* @param $pageSize
* @param string $order_
* @param $fields
* @param $where
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getBargainPartial($pageNo, $pageSize, $order_ = 'id desc', $fields, $where, $bargain_id = 0)
{
$data = $this->field($fields)
->alias('a')
->join('a_agents b', 'a.agent_id = b.id', 'left')
->where($where)
->order($order_)
->limit($pageSize)
->page($pageNo)
->select();
$result = [];
$m_agent = new AAgents();
$m_partial = new OPartialCommission();
$m_real = new ORealIncome();
$fields_str = 'a.id,a.name,b.store_name';
foreach ($data as $k => $v) {
$result[$k] = $v;
if (isset($v['agent_id'])) {
$agent_data = $m_agent->getStoreDistrict($fields_str, [ 'a.id' => $v['agent_id'] ]);
$result[$k]['agent'] = $agent_data['name'];
$result[$k]['district_store'] = $agent_data['store_name'];
}
if (isset($v['role'])) {
switch ($v['role']) {
case 1 :
$result[$k]['role_name'] = '盘方';
break;
case 2 :
$result[$k]['role_name'] = '客方';
break;
case 3 :
$result[$k]['role_name'] = '反签';
break;
case 4 :
$result[$k]['role_name'] = '独家';
break;
case 5 :
$result[$k]['role_name'] = '合作方';
break;
case 6 :
$result[$k]['role_name'] = 'APP盘下载方';
break;
case 7 :
$result[$k]['role_name'] = 'APP客下载方';
break;
default :
$result[$k]['role_name'] = '无';
}
}
$partial_commission = $m_partial->field('id,scale,practical_fee,cash,service_charge,charity_fund,real_fee,confirm_date,confirm_status,should_commission,real_income_id')
->where('bargain_id', $v['id'])
->where('is_del', 0)
->order("id asc")
->select();
foreach ($partial_commission as $k2 => $v2) {
if (empty($v2['real_income_id'])) {
$income_time = $m_real->field('id,income_time')->where(['bargain_id'=>$bargain_id,'is_del'=>0])->select();
//当只有一个收入日期,给前端显示用
if (count($income_time) == 1) {
$income_time_add['id'] = $income_time[0]['id'];
$income_time_add['income_time'] = $income_time[0]['income_time'];
$partial_commission[$k2]['income_time_add'] = $income_time_add;
}
} else {
$income_time = $m_real->field('id,income_time')->where('is_del', 0)->find($v2['real_income_id']);
if (empty($income_time)) {
$partial_commission[$k2]['income_time'] = [];
} else {
$partial_commission[$k2]['income_time'] = $income_time;
}
}
}
//todo 最后一个分佣提成如果不为空则取其值
$i = count($partial_commission) - 1;
if ($partial_commission && $partial_commission[$i]["scale"] > 0) {
$result[$k]["scale"] = $partial_commission[$i]["scale"];
$result[$k]["scale_fee"] = $partial_commission[$i]["should_commission"];
}
$result[$k]["last_commission_id"] = $partial_commission[$i]["id"];
$result[$k]['partial_commission'] = $partial_commission;
}
return $result;
}
/**
* 成交报告详情-分佣提成
*
* @param $pageNo
* @param $pageSize
* @param string $order_
* @param $fields
* @param $where
* @param int $bargain_id
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getBargainPartialV2($pageNo, $pageSize, $order_ = 'id desc', $fields, $where, $bargain_id = 0)
{
return $this->field($fields)
->alias('a')
->join('a_agents b', 'a.agent_id = b.id', 'left')
->where($where)
->order($order_)
->limit($pageSize)
->page($pageNo)
->select();
}
/**
* 分佣提成汇总表
*
* @param int $pageNo
* @param int $pageSize
* @param string $order_
* @param string $field
* @param string $params
* @param $whereOr
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getCommissionTotalList($pageNo = 1, $pageSize = 15, $order_ = 'a.id desc', $field = '', $params = '', $whereOr = [])
{
$data = $this->alias('a')
->field($field)
->join('o_taxes b', 'a.id = b.bargain_id', 'left')
->join('o_partial_commission c', 'a.id = c.bargain_id', 'left')
->join('a_agents d', 'a.agent_id = d.id', 'left')
->join('o_real_income f', 'a.id = f.bargain_id', 'left')
->where($params)
->whereOr($whereOr)
->order($order_)
->limit($pageSize)
->page($pageNo)
->group('a.agent_id')
->select();
$m_agent = new AAgents();
foreach ($data as $k => $v) {
if (isset($v['agent_id'])) {
$district_store = $m_agent->getStoreDistrict('store_name,district_name', [ 'a.id' => $v['agent_id'] ]);
$data[$k]['district_store'] = $district_store['district_name'] . '-' . $district_store['store_name'];
}
}
return $data;
}
/**
* 分佣提成汇总表总数
*
* @param $params
* @param array $whereOr
* @return int|string
*/
public function getCommissionTotalListTotal($params, $whereOr = [])
{
return $this->alias('a')
->join('o_taxes b', 'a.id = b.bargain_id', 'left')
->join('o_partial_commission c', 'a.id = c.bargain_id', 'left')
->join('a_agents d', 'a.agent_id = d.id', 'left')
->join('o_real_income f', 'a.id = f.bargain_id', 'left')
->where($params)
->whereOr($whereOr)
->group('a.agent_id')
->count();
}
/**
* 1盘方,2客方,3反签,4独家,5合作方
*
* @param int $bargain_id
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getAgentTypeByBargainId(int $bargain_id): array
{
$result = [];
$m_partial = new OPartialCommission();
$partial_bargain = $m_partial->getBragainScale($bargain_id);
foreach ($partial_bargain as $val) {
$bargain_id_arr[] = $val['agent_id'];
}
$data = $this->field('role,agent_id,scale,scale_fee')
->where('','EXP','id='.$bargain_id.' OR father_id='.$bargain_id)
->where('status', '<>',30)
->select();
foreach ($data as $k=>$v) {
if (in_array($v['agent_id'], $bargain_id_arr)) {
unset($data[$k]);
}
}
if (!empty($partial_bargain)) {
$data = array_merge($partial_bargain, $data);
}
$m_agent = new AAgents();
foreach ($data as $k => $v) {
if (isset($v['role'])) {
$agent_name = $m_agent->getAgentInfo('id,name,phone', $v['agent_id']);
$result[$k]['id'] = $agent_name['id'];
$result[$k]['agent_id'] = $agent_name['id'];
$result[$k]['name'] = $agent_name['name'];
$result[$k]['phone'] = $agent_name['phone'];
$result[$k]['role'] = $v['role'];
$result[$k]['scale'] = $v['scale'];
$result[$k]['scale_fee'] = $v['scale_fee'];
switch ($v['role']) {
case 1 :
$result[$k]['role_name'] = '盘方';
break;
case 2 :
$result[$k]['role_name'] = '客方';
break;
case 3 :
$result[$k]['role_name'] = '反签';
break;
case 4 :
$result[$k]['role_name'] = '独家';
break;
case 5 :
$result[$k]['role_name'] = '合作方';
break;
}
}
}
return $result;
}
/**
* 获取正常成交报告
*
* @param string $field
* @param int $id
* @param string $status
* @return array|false|\PDOStatement|string|Model
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getCheckBargain(string $field, int $id, $status = '10,11')
{
return $this->field($field)->alias('a')
->join('o_order b', 'a.order_id=b.id', 'left')
->join('g_houses c', 'b.house_id=c.id', 'left')
->join('a_agents d', 'a.agent_id=d.id','left')
->where('a.status', 'in', $status)
->where('a.id', $id)
->find();
}
/**
* 成交报告分佣方详情
*
* @param $filed
* @param $params
* @return array|bool|false|\PDOStatement|string|Model
*/
public function getBargainPartialDetail($filed, $params)
{
$where_ = $whereOr_ = [];
if (isset($param["bargain_id"])) {
$where_["a.id"] = $params["bargain_id"];
$whereOr_["a.father_id"] = $params["bargain_id"];
}
if (isset($params['id'])) {
$where_['a.id'] = $params['id'];
}
try {
$result = $this->db_
->field($filed)
->alias("a")
->join("o_partial_commission b", "a.id = b.bargain_id", "left")
->where($where_)
->whereOr($whereOr_)
->order("a.id asc")
->find();
$result['scale'] = empty($result['new_scale']) ? $result['scale'] : $result['new_scale'];
$result['scale_fee'] = empty($result['should_commission']) ? $result['scale_fee'] : $result['should_commission'];
$m_agent = new AAgents();
$filed_agent = 'a.id,a.name,a.phone,b.store_name,c.district_name,a.store_id,a.district_id';
$agent_info = $m_agent->getStoreDistrict($filed_agent, [ 'a.id' => $result['agent_id'] ]);
$result['district_name'] = $agent_info['district_name'];
$result['store_name'] = $agent_info['store_name'];
$result['name'] = $agent_info['name'];
$result['phone'] = $agent_info['phone'];
$result['store_id'] = $agent_info['store_id'];
$result['district_id'] = $agent_info['district_id'];
} catch (\Exception $ex) {
$result = $ex->getMessage();
}
return $result;
}
/**
* 获取分组统计数据
*
* @param $field
* @param $params
* @param $type
* @param string $order
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getTotalByAgentId($field, $params, $type, $order = "")
{
$group_ = "";
switch ($type) {
case 1:
$group_ = "a.agent_id";
break;
case 2:
$group_ = "b.store_id";
break;
case 3:
$group_ = "b.district_id";
break;
}
$result = $this->db_
->field($field)
->alias("a")
->join("a_agents b", "a.agent_id = b.id", "left")
->where($params)
->group($group_)
->order($order)
->select();
//echo $this->db_->getLastSql();
return $result;
}
/**
* @param $where
* @param $filed
* @param $pageSize
* @param $pageNo
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function performancelInfo($where, $filed, $pageSize, $pageNo)
{
$result = $this->db_
->field($filed)
->alias("Obargain")
->join("o_report Oreport", "Obargain.report_id = Oreport.id", "left")
->join("o_order Oorder", "Obargain.order_id = Oorder.id", "left")
->join("g_houses Houses", "Oorder.house_id = Houses.id", "left")
->join("a_agents Agent", "Obargain.agent_id = Agent.id", "left")
// ->join('a_store Store', 'Agent.store_id = Store.id', 'left')
// ->join('a_district District', 'Agent.district_id = District.id', 'left')
->join('o_partial_commission PartialCommission', 'PartialCommission.bargain_id = Obargain.id', 'left')
->where($where)
->order("Obargain.create_time desc")
->limit($pageSize)
->page($pageNo)
->select();
//echo $this->db_->getLastSql();
return $result;
}
public function performancelInfoScaleFee($where, $filed)
{
$result = $this->db_
->field($filed)
->alias("Obargain")
->join("o_report Oreport", "Obargain.report_id = Oreport.id", "left")
->join("o_order Oorder", "Obargain.order_id = Oorder.id", "left")
->join("g_houses Houses", "Oorder.house_id = Houses.id", "left")
->join("a_agents Agent", "Obargain.agent_id = Agent.id", "left")
// ->join('a_store Store', 'Agent.store_id = Store.id', 'left')
// ->join('a_district District', 'Agent.district_id = District.id', 'left')
->join('o_partial_commission PartialCommission', 'PartialCommission.bargain_id = Obargain.id', 'left')
->where($where)
->order("Obargain.create_time desc")
->select();
//echo $this->db_->getLastSql();
return $result;
}
public function performancelInfoExcel($where, $filed)
{
$result = $this->db_
->field($filed)
->alias("Obargain")
->join("o_report Oreport", "Obargain.report_id = Oreport.id", "left")
->join("o_order Oorder", "Obargain.order_id = Oorder.id", "left")
->join("g_houses Houses", "Oorder.house_id = Houses.id", "left")
->join("a_agents Agent", "Obargain.agent_id = Agent.id", "left")
// ->join('a_store Store', 'Agent.store_id = Store.id', 'left')
// ->join('a_district District', 'Agent.district_id = District.id', 'left')
->join('o_partial_commission PartialCommission', 'PartialCommission.bargain_id = Obargain.id', 'left')
->where($where)
->order("Obargain.create_time desc")
->select();
// echo $this->db_->getLastSql();
return $result;
}
/**
* @param $where
* @param $filed
* @return int|string
*/
public function performancelInfoTotal($where, $filed)
{
$result = $this->db_
->field($filed)
->alias("Obargain")
->join("o_report Oreport", "Obargain.report_id = Oreport.id", "left")
->join("o_order Oorder", "Obargain.order_id = Oorder.id", "left")
->join("g_houses Houses", "Oorder.house_id = Houses.id", "left")
->join("a_agents Agent", "Obargain.agent_id = Agent.id", "left")
// ->join('a_store Store', 'Agent.store_id = Store.id', 'left')
// ->join('a_district District', 'Agent.district_id = District.id', 'left')
->join('o_partial_commission PartialCommission', 'PartialCommission.bargain_id = Obargain.id', 'left')
->where($where)
->count();
// echo $this->db_->getLastSql();
return $result;
}
/**
* 根据成交报告id修改信息
*
* @param int $id
* @param array $data
* @return int
*/
public function updateBargain(int $id = 0, array $data = []): int
{
if ($id) {
$result = $this->where('id', $id)
->whereOr('father_id', $id)
->update($data);
} else {
$result = 0;
}
return $result;
}
public function getBargainSumList($field, $params,$page_size,$page_no,$request_source_type)
{
$where_ = [];
if (isset($params["agent_id"])) {
$where_["a.agent_id"] = $params["agent_id"];
}
if (isset($params["create_time"])) {
$where_["a.create_time"] = $params["create_time"];
}
$where_["a.status"] = array( "in", "10,11,13" );
if($request_source_type && $request_source_type == 1){
//pc后台业绩 成交单数 需要调用
$where_["a.role"] = 3;//必须是反签方
}
$result = $this->db_
->field($field)
->alias("a")
->join("o_order b", "a.order_id = b.id", "left")
->join("g_houses c", "b.house_id = c.id", "left")
->join("o_report d", "a.report_id = d.id", "left")
->where($where_)
->limit($page_size)
->page($page_no)
->order("a.id asc")
->select();
// echo $this->getLastSql();
return $result;
}
public function getAddBargainNumOperation($params, $type)
{
$field = "count(1) as num";
//$where_["trade_type"] = 10;//产品要求统计数量必须是出租类型的180620
$params["a.role"] = 3;//必须是反签方
$params['c.shop_type'] = $type == 0 ? 0 : 1;
// dump($params);
$return = Db::table($this->table)
->field($field)
->alias("a")
->join("o_order b", "a.order_id = b.id", "left")
->join("g_houses c", "b.house_id = c.id", "left")
->where($params)
->select();
/*echo $this->getLastSql();
echo '--------------';*/
return $return;
}
/**
* @param $field
* @param $where
* @return float|int
*/
public function sumField($field, $where) {
return $this->field($field)->alias('a')
->join('o_report b', 'a.report_id = b.id', 'left')
->join('o_order c', 'a.order_id = c.id', 'left')
->join('g_houses d', 'c.house_id = d.id', 'left')
->where($where)
->group('a.id')
->sum($field);
}
/**
* @param $field
* @param $where
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function agentBargainAll($field, $where) {
return $this->db_->alias('a')
->field($field)
->join('a_agents b', 'a.agent_id = b.id', 'left')
->where($where)
->select();
}
/**
* @param $field
* @param $where
* @return mixed
*/
public function getFieldValue($field, $where) {
return $this->db_->where($where)->value($field);
}
/**
* @param $field
* @param $where
* @return mixed
*/
public function getFieldColumn($field, $where) {
return $this->db_->where($where)->column($field);
}
/**
* @param $field
* @param $where
* @return array|false|\PDOStatement|string|Model
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getDetail($field, $where) {
return $this->db_->field($field)
->where($where)
->find();
}
}
\ No newline at end of file
<?php
namespace app\model;
use think\Db;
use think\Model;
/**
* Created by PhpStorm.
* User : zw
* Date : 2018/12/17
* Time : 11:26 AM
* Intro:
*/
class OfficeODaily extends BaseModel
{
protected $table = "office_o_daily";
private $db_;
public function __construct($data = [])
{
parent::__construct($data);
$this->db_ = Db::name($this->table);
}
/**
* @param $field
* @param $params
* @param $page_no
* @param $page_size
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getDailyList($field, $params, $page_no, $page_size)
{
$where_ = [];
if (isset($params["agent_id"])) {
$where_["agent_id"] = $params["agent_id"];
}
if (isset($params["daily_date"])) {
$where_["daily_date"] = $params["daily_date"];
}
if (isset($params["store_id"])) {
$where_["store_id"] = $params["store_id"];
}
if (isset($params['id'])) {
$where_["id"] = $params['id'];
}
$where_["is_del"] = 0;
return $this->db_
->field($field)
->where($where_)
->page($page_no)
->limit($page_size)
->select();
}
/**
* @param $params
* @return int
*/
public function addDaily($params)
{
Db::startTrans();
try {
$this->db_->insert($params);
Db::commit();
return 1;
} catch (\Exception $e) {
Db::rollback();
return 0;
}
}
/**
* @param $where
* @param $params
* @return int
*/
public function updateDaily($where,$params)
{
Db::startTrans();
try {
$this->where($where)->update($params);
Db::commit();
return 1;
} catch (\Exception $e) {
Db::rollback();
return 0;
}
}
/**
* @param int $pageNo
* @param int $pageSize
* @param string $order_
* @param string $field
* @param string $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getDailyLogList($pageNo = 1, $pageSize = 15, $order_ = 'id desc', $field = '', $params = '') {
return $this->alias('a')
->field($field)
->join('o_daily_log b', 'a.id=b.daily_id', 'left')
->where($params)
->order($order_)
->limit($pageSize)
->group('a.id')
->page($pageNo)
->select();
}
/**
* @param $params
* @return int|string
*/
public function getDailyLogTotal($params) {
return $this->alias('a')
->join('o_daily_log b', 'a.id=b.daily_id', 'left')
->where($params)
->group('a.id')
->count();
}
public function getFieldValue($filed, $where) {
return $this->where($where)->value($filed);
}
}
\ No newline at end of file
<?php
namespace app\model;
use think\Db;
use think\Model;
/**
* Created by PhpStorm.
* User : zw
* Date : 2018/12/17
* Time : 2:36 PM
* Intro:
*/
class OfficeODailyLog extends BaseModel
{
protected $table = "office_o_daily_log";
private $db_;
public function __construct($data = [])
{
parent::__construct($data);
$this->db_ = Db::name($this->table);
}
/**
* @param $field
* @param $params
* @param $page_no
* @param $page_size
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getDailyLogList($field,$params,$page_no,$page_size){
$where_ = [];
if(isset($params["daily_id"])){
$where_["daily_id"] = $params["daily_id"];
}
if(isset($params["operation_id"])){
$where_["operation_id"] = $params["operation_id"];
}
if(isset($params["operation_status"])){
$where_["operation_status"] = $params["operation_status"];
}
if(isset($params["is_del"])){
$where_["is_del"] = $params["is_del"];
}
return $this->db_
->field($field)
->where($where_)
->order("create_time desc")
->page($page_no)
->limit($page_size)
->select();
}
/**
* @param $params
* @return int
*/
public function addDailyCheck($params){
Db::startTrans();
try {
$this->db_->insert($params);
Db::commit();
return 1;
} catch (\Exception $e) {
Db::rollback();
return 0;
}
}
}
\ No newline at end of file
<?php
namespace app\model;
/**
* Created by PhpStorm.
* User : zw
* Date : 2018/7/4
* Time : 10:15
* Intro:
*/
use think\Db;
use think\Exception;
use Think\Log;
class OfficeOImg extends BaseModel
{
protected $table = "office_o_imgs";
private $db_;
public function __construct($data = [])
{
parent::__construct($data);
$this->db_ = Db::name($this->table);
}
/**
* 新增图片一张
* @param $params
* @return int|string
* @throws Exception xx
*/
public function addImgOnce(array $params): int
{
$imgBin = $this->imgBin($params);
Db::startTrans();
try {
$id = $this->insertGetId($imgBin);
Db::commit();
return $id;
} catch (Exception $exception) {
Db::rollback();
throw $exception;
}
}
/**
* 新增多张图片
* @param $params
* @param $img_id
* @param $img_type
* @return int|string
* @throws Exception xx
*/
public function addImgAll(int $img_id, int $img_type, array $params): int
{
$imgBin = [];
foreach ($params as $item) {
$insert_["img_id"] = $img_id;
$insert_["img_type"] = $img_type;
$insert_["img_name"] = $item;
$insert_["img_status"] = 0;
array_push($imgBin, $this->imgBin($insert_));
}
Db::startTrans();
try {
$this->saveAll($imgBin);
Db::commit();
return 1;
} catch (Exception $exception) {
Db::rollback();
throw $exception;
}
}
/**
* 修改图片单张
* @param array $params
* @return int
* @throws Exception
*/
public function updateImgStatus(array $params): int
{
$imgBin = $this->imgBin($params);
Db::startTrans();
try {
$this->update($imgBin);
Db::commit();
return $params["id"];
} catch (Exception $exception) {
Db::rollback();
throw $exception;
}
}
/**
* 批量删除
* @param $where
* @param $params
* @return int|string
*/
public function updateImgs($where,$params)
{
Db::startTrans();
try {
$id = $this->db_->where($where)->update($params);
Db::commit();
return $id;
} catch (\Exception $e) {
Db::rollback();
return 0;
}
}
/**
* 根据id和类型获取图片
* @param array $params
* @param string $field
* @return false|\PDOStatement|string|\think\Collection
*/
public function getImgList(array $params, string $field = "id,img_name")
{
if (isset($params["img_id"])) {
$where_["img_id"] = $params["img_id"];
}
if (isset($params["img_type"])) {
$where_["img_type"] = $params["img_type"];
}
$where_["img_status"] = 0;
$data = $this->db_
->field($field)
->where($where_)
->select();
// echo $this->getLastSql();
return $data;
}
/**
* bin
* @param $params
* @return array
*/
private function imgBin($params)
{
$arr = [];
if (isset($params["id"])) {
$arr["id"] = $params["id"];
} else {
$arr["create_time"] = date("Y-m-d H:i:s", time());
}
if (isset($params["img_id"])) {
$arr["img_id"] = $params["img_id"];
}
if (isset($params["img_type"])) {
$arr["img_type"] = $params["img_type"];
}
if (isset($params["img_name"])) {
$arr["img_name"] = $params["img_name"];
}
if (isset($params["img_status"])) {
$arr["img_status"] = $params["img_status"];
}
$arr["update_time"] = date("Y-m-d H:i:s", time());
return $arr;
}
}
\ No newline at end of file
<?php
namespace app\model;
use think\Db;
use think\Model;
/**
* Created by PhpStorm.
* User : zw
* Date : 2018/2/1
* Time : 13:32
* Intro:
*/
class OfficeOMarchInModel extends Model
{
protected $table = "office_o_march_in";
private $db_model;
function __construct()
{
$this->db_model = Db::name($this->table);
}
/**
* 新增跟进信息
* @param $params
* @return int
*/
public function addMarchIn($params)
{
$params["create_time"] = date("Y-m-d H:i:s", time());
$params["update_time"] = date("Y-m-d H:i:s", time());
Db::startTrans();
try {
$id = $this->db_model->insertGetId($params);
Db::commit();
return $id;
} catch (\Exception $e) {
Db::rollback();
return 0;
}
}
/**
* 新增跟进信息 批量
* @param $params
* @return int
*/
public function addMarchInAll($params)
{
Db::startTrans();
try {
$this->db_model->insertAll($params);
Db::commit();
return 1;
} catch (\Exception $e) {
Db::rollback();
return 0;
}
}
/**
* @param $filed
* @param $params
* @return mixed
*/
public function selectMarchInByOrderNo($filed, $params)
{
$where_ = [];
if (isset($params["id"])) {
$where_["id"] = $params["id"];
}
if (isset($params["reception_id"])) {
$where_["reception_id"] = $params["reception_id"];
}
if (isset($params["reception_name"])) {
$where_["reception_name"] = $params["reception_name"];
}
if (isset($params["report_id"])) {
$where_["report_id"] = $params["report_id"];
}
if (isset($params["order_no"])) {
$where_["order_no"] = $params["order_no"];
}
if (isset($params["order_id"])) {
$where_["order_id"] = $params["order_id"];
}
return $this->db_model
->field($filed)
->where($where_)
->select();
}
/**
* 查询经纪人进场数据 todo 产品定义同一天带看同一个客户去多个铺子算一个带看,下个方法同样
* @param $params
* @return false|\PDOStatement|string|\think\Collection
*/
public function getAddMarchInNumGroupTime($params)
{
$field = "count(DISTINCT report_id) as num,DATE(create_time) as day";
$where_ = [];
if (isset($params["agent_id"])) {
$where_["reception_id"] = $params["agent_id"];
}
if (isset($params["create_time"])) {
$where_["create_time"] = $params["create_time"];
}
return Db::table($this->table)
->field($field)
->where($where_)
->group("day")
->select();
}
/**
* 查询经纪人进场数据 todo 产品定义同一天带看同一个客户去多个铺子算一个带看,下个方法同样
* @param $params
* @return false|\PDOStatement|string|\think\Collection
*/
public function getAddMarchInNumGroupTimeNew($params)
{
$field = "count(DISTINCT report_id) as num";
$where_ = [];
if (isset($params["agent_id"])) {
$where_["reception_id"] = $params["agent_id"];
}
if (isset($params["create_time"])) {
$where_["create_time"] = $params["create_time"];
}
return Db::table($this->table)
->field($field)
->where($where_)
->select();
}
/**
* 统计房源进场数据 过滤重负
* @param $params
* @return false|\PDOStatement|string|\think\Collection
*/
public function getAddMarchInNum($params)
{
$field = "count(DISTINCT report_id) as num";
$where_ = [];
if (isset($params["agent_id"])) {
$where_["a.reception_id"] = $params["agent_id"];
}
if (isset($params["create_time"])) {
$where_["a.create_time"] = $params["create_time"];
}
if (isset($params["house_ids"])) {
$where_["b.house_id"] = array( "in", $params["house_ids"] );
}
$return = Db::table($this->table)
->field($field)
->alias("a")
->join("o_order b", "a.order_id = b.id", "left")
->where($where_)
->select();
//echo $this->getLastSql();
//echo '=============';
return $return;
}
/**
* 统计房源进场数据 不过滤
* @param $params
* @return int|string
*/
public function getMarchInNum($params)
{
$where_ = [];
if (isset($params["agent_id"])) {
$where_["a.reception_id"] = $params["agent_id"];
}
if (isset($params["create_time"])) {
$where_["a.create_time"] = $params["create_time"];
}
if (isset($params["house_id"])) {
$where_["b.house_id"] = $params["house_id"];
$where_["b.is_del"] = 0;//选择正常状态的参数
}
$return = Db::table($this->table)
->field("count(1) as num,max(a.create_time) as create_time")
->alias("a")
->join("o_order b", "a.order_id = b.id", "left")
->where($where_)
->select();
return $return;
}
/**统计房源进场数据列表
* @param $field
* @param $params
* @param $page_no
* @param $page_size
* @return false|\PDOStatement|string|\think\Collection
*/
public function getMarchInList($field, $params, $page_no, $page_size)
{
$where_ = [];
if (isset($params["create_time"])) {
$where_["a.create_time"] = $params["create_time"];
}
if (isset($params["house_id"])) {
$where_["b.house_id"] = $params["house_id"];
$where_["b.is_del"] = 0;//选择正常状态的参数
}
$return=Db::table($this->table)
->field($field)
->alias("a")
->join("o_order b", "a.order_id = b.id", "left")
->join("a_agents c", "a.reception_id = c.id", "left")
->where($where_)
->order("a.create_time desc")
->limit($page_size)
->page($page_no)
->select();
//dump($this->getLastSql());
return $return;
}
/**
* @param $params
* @param $field
* @param $page_no
* @param $page_size
* @return false|\PDOStatement|string|\think\Collection
*/
public function getAddMarchInList($params, $field, $page_no, $page_size)
{
$where_ = [];
if (isset($params["agent_id"])) {
$where_["a.reception_id"] = $params["agent_id"];
}
if (isset($params["create_time"])) {
$where_["a.create_time"] = $params["create_time"];
}
if (isset($params["house_ids"])) {
$where_["b.house_id"] = array( "in", $params["house_ids"] );
}
return Db::table($this->table)
->field($field)
->alias("a")
->join("o_order b", "a.order_id = b.id", "left")
->join("o_report c", "b.f_id = c.id", "left")
->where($where_)
->limit($page_size)
->page($page_no)
->select();
}
public function getAddMarchInListPcInfo($params, $field, $page_no, $page_size)
{
$where_ = [];
if (isset($params["agent_id"])) {
$where_["a.reception_id"] = $params["agent_id"];
}
if (isset($params["create_time"])) {
$where_["a.create_time"] = $params["create_time"];
}
if (isset($params["house_ids"])) {
$where_["b.house_id"] = array( "in", $params["house_ids"] );
}
return Db::table($this->table)
->field($field)
->alias("a")
->join("o_order b", "a.order_id = b.id", "left")
->join("o_report c", "b.f_id = c.id", "left")
->join('a_store e', 'c.report_store_id = e.id', 'left')
->where($where_)
->limit($page_size)
->page($page_no)
->select();
}
public function getAddMarchInListPcInfoTotal($params, $field)
{
$where_ = [];
if (isset($params["agent_id"])) {
$where_["a.reception_id"] = $params["agent_id"];
}
if (isset($params["create_time"])) {
$where_["a.create_time"] = $params["create_time"];
}
if (isset($params["house_ids"])) {
$where_["b.house_id"] = array( "in", $params["house_ids"] );
}
return Db::table($this->table)
->field($field)
->alias("a")
->join("o_order b", "a.order_id = b.id", "left")
->join("o_report c", "b.f_id = c.id", "left")
->join('a_store e', 'c.report_store_id = e.id', 'left')
->where($where_)
->count();
}
public function getAddMarchInOrderList($field, $params)
{
$where_ = [];
if (isset($params["agent_id"])) {
$where_["a.reception_id"] = $params["agent_id"];
}
if (isset($params["create_time"])) {
$where_["a.create_time"] = $params["create_time"];
}
if (isset($params["house_ids"])) {
$where_["b.house_id"] = array( "in", $params["house_ids"] );
}
return Db::table($this->table)
->field($field)
->alias("a")
->join("o_order b", "a.order_id = b.id", "left")
->join("o_report c", "b.f_id = c.id", "left")
// ->join('g_houses d', 'b.house_id = d.id', 'left')
->where($where_)
->select();
}
public function getMarchInListByOrderId($field, $params)
{
$where_ = [];
if (isset($params["order_id"])) {
$where_["a.order_id"] = $params["order_id"];
}
if (isset($params["house_title"])) {
$where_["b.house_title"] = $params["house_title"];
}
return Db::table($this->table)
->field($field)
->alias("a")
->join("o_order b", "a.order_id = b.id", "left")
->join("a_agents c", "a.reception_id = c.id", "left")
->join("a_store d", "c.store_id = d.id", "left")
->where($where_)
->select();
}
public function findmarchInList($pageNo = 1, $pageSize = 15, $order_ = 'id desc', $field, $params = '')
{
$result = $this
->field($field)
->alias('a')
->join('a_agents b', 'a.reception_id = b.id', 'left')
->join('o_order c', 'a.order_id = c.id', 'left')
->join('o_report d', 'a.report_id = d.id', 'left')
->join('a_store e', 'd.report_store_id = e.id', 'left')
->join('g_houses f', 'c.house_id = f.id', 'left')
->where($params)
->order($order_)
->limit($pageSize)
->page($pageNo)
->select();
//dump($this->getLastSql());
return $result;
}
public function findmarchInListCount($field, $params = '')
{
$result = $this
->field($field)
->alias('a')
->join('a_agents b', 'a.reception_id = b.id', 'left')
->join('o_order c', 'a.order_id = c.id', 'left')
->join('o_report d', 'a.report_id = d.id', 'left')
->join('a_store e', 'd.report_store_id = e.id', 'left')
->join('g_houses f', 'c.house_id = f.id', 'left')
->where($params)
->count();
return $result;
}
/**
* 获取进场数-运营
* @param $params
* @return int|string
*/
public function getMarchInNumOperation($params)
{
//dump($params);
$return = Db::table($this->table)
->alias("a")
->join("o_order b", "a.order_id = b.id", "left")
->join('g_houses c', 'b.house_id = c.id', 'LEFT')
->where($params)
->count();
//dump($this->getLastSql($return));
return $return;
}
/**
* @param $field
* @param $where
* @return array|false|\PDOStatement|string|Model
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getMaxMarchInAgent($field, $where) {
return $this->alias('a')
->field($field)
->join('o_order b', 'a.order_id = b.id', 'left')
->where($where)
->group('a.reception_id ')
->find();
}
/**
* @param $filed
* @param $params
* @return array|false|\PDOStatement|string|Model
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function selectMarchInOne($filed, $params)
{
$where_ = [];
if (isset($params["id"])) {
$where_["a.id"] = $params["id"];
}
if (isset($params["reception_id"])) {
$where_["a.reception_id"] = $params["reception_id"];
}
if (isset($params["reception_name"])) {
$where_["a.reception_name"] = $params["reception_name"];
}
if (isset($params["site_id"])) {
$where_["b.site_id"] = $params["site_id"];
}
return $this->db_model
->alias('a')
->field($filed)
->join('a_agents b', 'a.reception_id = b.id', 'left')
->where($where_)
->find();
}
/**
* 带看经纪人
*
* @param $field
* @param $where
* @return mixed
*/
public function getAgentMarchIn($field, $where) {
try {
$data['data'] = $this->db_model->field($field)
->alias('a')
->join('a_agents b', 'a.reception_id = b.id', 'left')
->join('o_bargain c', 'a.order_id = c.order_id', 'left')
->where($where)
->select();
$data['status'] = 'successful';
} catch (\Exception $e) {
$data['status'] = 'fail';
$data['msg'] = $e->getMessage();
}
return $data;
}
/**
* @param $field
* @param $where
* @param string $order
* @return array|false|\PDOStatement|string|Model
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getInfo($field, $where, $order = 'id desc') {
return $this->db_model->field($field)
->where($where)
->order($order)
->find();
}
}
\ No newline at end of file
<?php
namespace app\model;
use think\Db;
use think\Model;
/**
* Created by PhpStorm.
* User : zw
* Date : 2018/2/1
* Time : 14:44
* Intro:
*/
class OfficeOPayLogModel extends Model
{
protected $table = "office_o_paylog";
private $db_;
function __construct()
{
$this->db_ = Db::name($this->table);
}
public function addPayLog($params)
{
Db::startTrans();
try {
$this->db_->insertAll($params);
Db::commit();
return 1;
} catch (\Exception $e) {
Db::rollback();
return 0;
}
}
public function insertPayLog($params)
{
Db::startTrans();
try {
$id = $this->db_->insertGetId($params);
Db::commit();
return $id;
} catch (\Exception $e) {
Db::rollback();
return 0;
}
}
public function updatePayLog($params)
{
$id = $params["id"];
unset($params["id"]);
Db::startTrans();
try {
$id = $this->db_->where([ "id" => $id ])->update($params);
Db::commit();
return $id;
} catch (\Exception $e) {
echo $this->getLastSql();
dump("error:" . $e);
Db::rollback();
return 0;
}
}
/**
* 查询付款记录
*
* @param $filed
* @param $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function selectPayLogByOrderNo($filed, $params)
{
$where_ = [];
if (isset($params["id"])) {
$where_["id"] = $params["id"];
}
if (isset($params["report_id"])) {
$where_["report_id"] = $params["report_id"];
}
if (isset($params["order_no"])) {
$where_["order_no"] = $params["order_no"];
}
if (isset($params["order_id"])) {
$where_["order_id"] = $params["order_id"];
}
if (isset($params["agent_id"])) {
$where_["agent_id"] = $params["agent_id"];
}
$where_["is_del"] = 0;
return $this->db_
->field($filed)
->where($where_)
->select();
}
/**
* 获取上次提交记录
* @param $filed
* @param $params
* @return false|\PDOStatement|string|\think\Collection
*/
public function getBeforeBillInfo($filed, $params)
{
$where_ = [];
if (isset($params["order_id"])) {
$where_["order_id"] = $params["order_id"];
}
if (isset($params["id"])) {
$where_["id"] = $params["id"];
}
$where_["father_id"] = 0;
return $this->db_
->field($filed)
->where($where_)
->order("id desc")
->limit(1)
->select();
}
public function getPayLogByOrderId($field, $params)
{
$where_ = [];
if (isset($params["order_id"])) {
$where_["a.order_id"] = $params["order_id"];
}
if (isset($params["house_title"])) {
$where_["b.house_title"] = $params["house_title"];
}
if (isset($params["bargain_id"])) {
$where_["a.bargain_id"] = $params["bargain_id"];
}
if (isset($params["id"])) {
$where_["a.id"] = $params["id"];
}
$where_["a.is_del"] = 0;
return Db::table($this->table)
->field($field)
->alias("a")
->join("o_order b", "a.order_id = b.id", "left")
->join("a_agents c", "a.agent_id = c.id", "left")
->join("a_store d", "c.store_id = d.id", "left")
->where($where_)
->select();
}
/**
* @param $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getAddPayLogNumGroupTime($params)
{
$field = "count(1) as num,DATE(create_time) as day";
$where_ = [];
if (isset($params["agent_id"])) {
$where_["agent_id"] = $params["agent_id"];
}
if (isset($params["create_time"])) {
$where_["create_time"] = $params["create_time"];
}
$where_["is_del"] = 0;
return Db::table($this->table)
->field($field)
->where($where_)
->group("day")
->select();
}
/**
* @param $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getAddPayLogNumGroupTimeNew($params)
{
$field = "count(1) as num";
$where_ = [];
if (isset($params["agent_id"])) {
$where_["agent_id"] = $params["agent_id"];
}
if (isset($params["create_time"])) {
$where_["create_time"] = $params["create_time"];
}
$where_["is_del"] = 0;
return Db::table($this->table)
->field($field)
->where($where_)
->select();
}
/**
* @param $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getAddPayLogNum($params)
{
$field = "count(1) as num";
$where_ = [];
if (isset($params["agent_id"])) {
$where_["a.agent_id"] = $params["agent_id"];
}
if (isset($params["create_time"])) {
$where_["a.create_time"] = $params["create_time"];
}
if (isset($params["house_ids"])) {
$where_["b.house_id"] = array( "in", $params["house_ids"] );
}
$where_["a.is_del"] = 0;
return Db::table($this->table)
->field($field)
->alias("a")
->join("o_order b", "a.order_id = b.id", "left")
->where($where_)
->select();
}
/**
* @param $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getAddPayLogList($params, $field, $page_no, $page_size)
{
$where_ = [];
if (isset($params["agent_id"])) {
$where_["a.agent_id"] = $params["agent_id"];
}
if (isset($params["create_time"])) {
$where_["a.create_time"] = $params["create_time"];
}
if (isset($params["house_ids"])) {
$where_["b.house_id"] = array( "in", $params["house_ids"] );
}
$where_["a.is_del"] = 0;
return Db::table($this->table)
->field($field)
->alias("a")
->join("o_order b", "a.order_id = b.id", "left")
->join("o_report c", "b.f_id = c.id", "left")
->where($where_)
->limit($page_size)
->page($page_no)
->select();
}
public function getAddPayLogListPcInfo($params, $field, $page_no, $page_size)
{
$where_ = [];
if (isset($params["agent_id"])) {
$where_["a.agent_id"] = $params["agent_id"];
}
if (isset($params["create_time"])) {
$where_["a.create_time"] = $params["create_time"];
}
if (isset($params["house_ids"])) {
$where_["b.house_id"] = array( "in", $params["house_ids"] );
}
$where_["a.is_del"] = 0;
return Db::table($this->table)
->field($field)
->alias("a")
->join("o_order b", "a.order_id = b.id", "left")
->join("g_houses h", "b.house_id = h.id", "left")
->join("o_report c", "b.f_id = c.id", "left")
->where($where_)
->limit($page_size)
->page($page_no)
->select();
}
/**
* @param $field
* @param $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getAddPayLogOrderList($field, $params)
{
$where_ = [];
if (isset($params["agent_id"])) {
$where_["a.agent_id"] = $params["agent_id"];
}
if (isset($params["create_time"])) {
$where_["a.create_time"] = $params["create_time"];
}
if (isset($params["house_ids"])) {
$where_["b.house_id"] = array( "in", $params["house_ids"] );
}
$where_["a.is_del"] = 0;
return Db::table($this->table)
->field($field)
->alias("a")
->join("o_order b", "a.order_id = b.id", "left")
->join("o_report c", "b.f_id = c.id", "left")
//->join('g_houses d','b.house_id = d.id','left')
->where($where_)
->group("a.id")
->select();
}
/**
* 收款记录
*
* @param int $pageNo
* @param int $pageSize
* @param string $order_
* @param string $field
* @param string $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getAddPayLogOrderListLimit($pageNo = 1, $pageSize = 15, $order_ = 'id desc', $field = '', $params = '')
{
$params["a.is_del"] = 0;
return $this->db_->field($field)
->alias("a")
->join("o_order b", "a.order_id = b.id", "left")
->join('g_houses d', 'b.house_id = d.id', 'left')
->join('a_agents e', 'a.agent_id=e.id', 'left')
->join('o_bargain f', 'a.bargain_id=f.id', 'left')
->limit($pageSize)
->page($pageNo)
->order($order_)
->where($params)
->select();
}
/**
* 收款记录总数
*
* @param string $params
* @return int|string
*/
public function getAddPayLogOrderListLimitTotal($params = '')
{
$params["a.is_del"] = 0;
return $this->db_->alias("a")
->join("o_order b", "a.order_id = b.id", "left")
->join('g_houses d', 'b.house_id = d.id', 'left')
->join('a_agents e', 'a.agent_id=e.id', 'left')
->join('o_bargain f', 'a.bargain_id=f.id', 'left')
->where($params)
->count();
}
/**
* 订单总额
*
* @param $where
* @param $field
* @return float|int
*/
public function getMoneyTotal($where, $field)
{
$params["a.is_del"] = 0;
if (isset($params['e.name']) || isset($params['f.store_name']) || isset($params['e.phone'])) {
$data = Db::table($this->table)
->alias("a")
->join("o_order b", "a.order_id = b.id", "left")
->join('g_houses d', 'b.house_id = d.id', 'left')
->join('a_agents e', 'a.agent_id=e.id', 'left')
->join('o_bargain f', 'a.bargain_id=f.id', 'left')
->where($where)
->sum($field);
} else {
$data = Db::table($this->table)
->alias("a")
->join("o_order b", "a.order_id = b.id", "left")
->join('g_houses d', 'b.house_id = d.id', 'left')
->join('a_agents e', 'a.agent_id=e.id', 'left')
->join('o_bargain f', 'a.bargain_id=f.id', 'left')
->where($where)
->sum($field);
}
// big_log($this->getLastSql());
return $data;
}
/**
* 收款列表-查询收款数据
* 朱伟 2018-07-04
*/
public function selectReceiptImgList($filed, $params)
{
$where_ = [];
if (isset($params["id"])) {
$where_["id"] = $params["id"];
}
$where["is_del"] = 0;
return Db::table($this->table)
->field($filed)
->where($where_)
->select();
}
/**
* @param $filed
* @param $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function selectPayLogListByBargain($filed,$params)
{
return $this->db_->field($filed)
->alias("a")
->join("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")
->where($params)
->group("a.id")
->select();
}
/**
* @param $filed
* @param $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function selectPayLogListByBargainReport($filed,$params)
{
return $this->db_->field($filed)
->alias("a")
->join("o_order b", "a.order_id = b.id", "left")
->join("o_report d", "a.report_id = d.id", "left")
->where($params)
->select();
}
/**
* @param $filed
* @param $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function selectAdjustmentList($filed,$params)
{
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")
->where($params)
->select();
}
/**
* @param $filed
* @param $params
* @param $group
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getTotal($filed,$params,$group){
return $this->db_
->field($filed)
->where($params)
->group($group)
->select();
}
/**
* @param $filed
* @param $params
* @return float|int
*/
public function getSum($filed,$params){
if (!isset($params['is_del'])) {
$params['is_del'] = 0;
}
return $this->db_
->where($params)
->sum($filed);
}
/**
* @param $filed
* @param $params
* @return float|int
*/
public function getAdjustmentSum($filed,$params){
return $this->db_
->alias('a')
->join('o_paylog_adjustment b','a.id=b.paylog_id')
->where($params)
->sum($filed);
}
/**
* @param $field
* @param $where
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getOrderHouse($field, $where) {
return $this->db_->alias('a')
->field($field)
->join('o_order b', 'a.order_id=b.id', 'left')
->join('g_houses c', 'b.house_id=c.id', 'left')
->where($where)
->select();
}
/**
* @param $field
* @param $where
* @return float|int
*/
public function sumBargainPrice($field, $where) {
return $this->db_->alias('a')
->join('o_bargain b','a.bargain_id=b.id', 'left')
->where($where)
->sum($field);
}
/**
* @param string $field
* @param array $where
* @return float|int|string
*/
public function sumPayLogAdjustment(string $field, array $where) {
return $this->db_->alias('a')
->join('o_paylog_adjustment b','a.id=b.paylog_id','left')
->where($where)
->sum($field);
}
/**
* @param string $field
* @param array $where
* @return float|int
*/
public function sumPayLog(string $field, array $where) {
return $this->db_->where($where)->sum($field);
}
public function getCount($where) {
if (!isset($params['is_del'])) {
$params['is_del'] = 0;
}
return $this->db_->where($where)->count('id');
}
/**
* @param $where
* @return array
*/
public function getFieldColumn($field, $where) {
if (!isset($params['is_del'])) {
$params['is_del'] = 0;
}
return $this->db_->where($where)->column($field);
}
/**
* @param $field
* @param $where
* @return mixed
*/
public function getFieldValue($field, $where) {
if (!isset($params['is_del'])) {
$params['is_del'] = 0;
}
return $this->db_->where($where)->value($field);
}
public function getPayLogByUserId($field, $params)
{
$where_ = [];
if (isset($params["user_id"])) {
$where_["b.user_id"] = $params["user_id"];
}
if (isset($params["type"])) {
$where_["a.type"] = $params["type"];
}
$where_["a.is_del"] = 0;
return $this->db_
->field($field)
->alias("a")
->join("o_report b", "a.report_id = b.id", "left")
->where($where_)
->order('a.create_time asc')
->find();
}
}
\ No newline at end of file
<?php
namespace app\model;
use think\Db;
use think\Model;
/**
* Created by PhpStorm.
* User : zw
* Date : 2018/2/1
* Time : 16:02
* Intro:
*/
class OfficeORefundModel extends Model{
protected $table = "office_o_refund";
private $db_;
function __construct()
{
$this->db_=Db::name($this->table);
}
/**
* 新增退款记录
* @param $params
* @return int|string
*/
public function addRefund($params){
Db::startTrans();
try {
$id = $this->db_->insertGetId($params);
Db::commit();
return $id;
} catch (\Exception $e) {
Db::rollback();
return 0;
}
}
/**
* @param $params
* @return int|string
*/
public function updateRefund($params){
$where_["id"] = $params["id"];
unset($params["id"]);
Db::startTrans();
try {
$id = $this->db_->where($where_)->update($params);
Db::commit();
return $id;
} catch (\Exception $e) {
Db::rollback();
return 0;
}
}
/**
* 查询退款记录
*
* @param $filed
* @param $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function selectRefundByOrderNo($filed , $params)
{
$where_ = [];
if (isset($params["report_id"])) {
$where_["report_id"] = $params["report_id"];
}
if (isset($params["order_no"])) {
$where_["order_no"] = $params["order_no"];
}
if (isset($params["order_id"])) {
$where_["order_id"] = $params["order_id"];
}
if (isset($params["agent_id"])) {
$where_["agent_id"] = $params["agent_id"];
}
if (isset($params["id"])) {
$where_["id"] = $params["id"];
}
if (isset($params["is_del"])) {
$where_["is_del"] = $params["is_del"];
}
if (isset($params["status"])) {
$where_["status"] = $params["status"];
}
if (isset($params["pay_log_id"])) {
$where_["pay_log_id"] = $params["pay_log_id"];
}
return $this->db_
->field($filed)
->where($where_)
->select();
}
/**
* @param $filed
* @param $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function selectRefundDetailByOrderNo($filed , $params)
{
$where_ = [];
if (isset($params["order_id"])) {
$where_["a.order_id"] = $params["order_id"];
}
if (isset($params["id"])) {
$where_["a.id"] = $params["id"];
}
if (isset($params["del"])) {
$where_["a.is_del"] = $params["del"];
}
return $this->db_
->field($filed)
->alias("a")
->join("o_paylog b","a.pay_log_id = b.id","left")
->where($where_)
->select();
}
/**
* 查询退款记录带分页
*
* @param int $pageNo
* @param int $pageSize
* @param string $order_
* @param string $field
* @param string $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function selectRefundByOrderNoPage($pageNo = 1, $pageSize = 15, $order_ = 'id desc', $field = '', $params = '')
{
$where_ = [];
if (isset($params["report_id"])) {
$where_["report_id"] = $params["report_id"];
}
if (isset($params["order_no"])) {
$where_["order_no"] = $params["order_no"];
}
if (isset($params["order_id"])) {
$where_["order_id"] = $params["order_id"];
}
if (isset($params["agent_id"])) {
$where_["agent_id"] = $params["agent_id"];
}
return $this->db_
->field($field)
->alias('a')
->join('o_report b', 'a.report_id = b.id', 'left')
->where($params)
->limit($pageSize)
->page($pageNo)
->order($order_)
->select();
}
/**
* 查询退款记录带分页总数
*
* @param $params
* @return int|string
*/
public function selectRefundByOrderNoPageTotal($params) {
return $this->db_
->alias('a')
->join('o_report b', 'a.report_id = b.id', 'left')
->where($params)
->count();
}
/**
* @param $field
* @param $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getRefundByOrderId($field,$params){
$where_ = [];
if(isset($params["order_id"])){
$where_["a.order_id"] = $params["order_id"];
}
if(isset($params["house_title"])){
$where_["b.house_title"] = $params["house_title"];
}
return Db::table($this->table)
->field($field)
->alias("a")
->join("o_order b","a.order_id = b.id","left")
->join("a_agents c","a.agent_id = c.id","left")
->join("a_store d","c.store_id = d.id","left")
->where($where_)
->select();
}
/**
* 退款列表
*
* @param int $pageNo
* @param int $pageSize
* @param string $order_
* @param string $field
* @param string $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getCheckRefundList($pageNo = 1, $pageSize = 15, $order_ = 'id desc', $field = '', $params = '') {
return $this->db_->alias('a')
->field($field)
->join('o_order b', 'a.order_id = b.id', 'left')
->join('a_agents c', 'a.agent_id = c.id', 'left')
->join('o_paylog d', 'a.pay_log_id = d.id', 'left')
->join('o_refund_log e', 'a.id = e.refund_id', 'left')
->join('o_bargain f', 'd.bargain_id = f.id', 'left')
->where($params)
->limit($pageSize)
->page($pageNo)
->order($order_)
->group('a.id')
->select();
}
public function getCheckRefundListForExcel($order_ = 'id desc', $field = '', $params = '') {
return $this->db_->alias('a')
->field($field)
->join('o_order b', 'a.order_id = b.id', 'left')
->join('a_agents c', 'a.agent_id = c.id', 'left')
->join('o_paylog d', 'a.pay_log_id = d.id', 'left')
->join('o_refund_log e', 'a.id = e.refund_id', 'left')
->join('o_bargain f', 'd.bargain_id = f.id', 'left')
->where($params)
->order($order_)
->group('a.id')
->select();
}
/**
* 退款列表
*
* @param $params
* @return int|string
*/
public function getCheckRefundListTotal($params) {
return $this->db_->alias('a')
->join('o_order b', 'a.order_id = b.id', 'left')
->join('a_agents c', 'a.agent_id = c.id', 'left')
->join('o_paylog d', 'a.pay_log_id = d.id', 'left')
->join('o_refund_log e', 'a.id = e.refund_id', 'left')
->join('o_bargain f', 'd.bargain_id = f.id', 'left')
->where($params)
->group('a.id')
->count();
}
public function getRefundSum($field, $params)
{
if (!isset($params['is_del'])) {
$params['is_del'] = 0;
}
$data = $this->db_
->where($params)
->sum($field);
return $data;
}
public function getRefundSumV2($field, $params)
{
if (!isset($params['is_del'])) {
$params['a.is_del'] = 0;
}
$data = $this->db_->alias('a')
->join('o_paylog b','a.pay_log_id=b.id')
->where($params)
->sum($field);
return $data;
}
/**
* @param $params
* @return float|int
*/
public function getSumMoney($params) {
$refund_money = $this->db_->alias('a')
->field('a.refund_money')
->join('o_order b', 'a.order_id = b.id', 'left')
->join('a_agents c', 'a.agent_id = c.id', 'left')
->join('o_paylog d', 'a.pay_log_id = d.id', 'left')
->join('o_refund_log e', 'a.id = e.refund_id', 'left')
->join('o_bargain f', 'd.bargain_id = f.id', 'left')
->where($params)
->group('a.id')
->select();
$price = 0;
foreach ($refund_money as $v) {
$price += $v['refund_money'];
}
return $price;
}
/**
* @param $data
* @param $where
* @return ORefundModel
*/
public function updateData($data, $where) {
return $this->where($where)->update($data);
}
/**
* @param $field
* @param $where
* @return float|int
*/
public function sumBargainPrice($field, $where) {
return $this->db_->alias('a')
->join('o_paylog b','a.pay_log_id=b.id', 'left')
->where($where)
->sum($field);
}
/**
* @param $field
* @param $where
* @return array|false|\PDOStatement|string|Model
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getFind($field, $where) {
return $this->db_->field($field)
->where($where)
->find();
}
}
\ No newline at end of file
<?php
namespace app\model;
/**
* Created by PhpStorm.
* User : zw
* Date : 2018/1/26
* Time : 16:48
* Intro:
*/
use think\Model;
use think\helper\Time;
use think\Db;
class OfficeOReportModel extends Model
{
// 设置当前模型对应的完整数据表名称
protected $table = 'office_o_report';
protected $db;
/**
* OReportModel constructor.
*/
function __construct()
{
$this->db = Db::name($this->table);
}
/**
* 添加报备
*
* @param $params
* @return int|string
*/
public function addReport($params)
{
Db::startTrans();
try {
$this->db->insert($params);
$id = $this->db->getLastInsID();
Db::commit();
return $id;
} catch (\Exception $e) {
Db::rollback();
return 0;
}
}
/**
* 查询报备信息
*
* @param string $filed
* @param $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function selectReportById($filed = "id", $params)
{
$where_ = [];
if (isset($params["id"])) {
$where_["id"] = $params["id"];
}
if (isset($params["report_agent_id"])) {
$where_["report_agent_id"] = $params["report_agent_id"];
}
if (isset($params["report_store_id"])) {
$where_["report_store_id"] = $params["report_store_id"];
}
if (isset($params["user_id"])) {
$where_["user_id"] = $params["user_id"];
}
$where_["status"] = 0;
return $this->db
->field($filed)
->where($where_)
->select();
}
/**
* 查询报备信息
*
* @param string $filed
* @param $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function selectReportInfoById($filed = "id", $params)
{
$where_ = [];
if (isset($params["id"])) {
$where_["a.id"] = $params["id"];
}
if (isset($params["report_agent_id"])) {
$where_["a.report_agent_id"] = $params["report_agent_id"];
}
if (isset($params["report_store_id"])) {
$where_["a.report_store_id"] = $params["report_store_id"];
}
if (isset($params["user_id"])) {
$where_["a.user_id"] = $params["user_id"];
}
$where_["a.status"] = 0;
return $this->db
->field($filed)
->alias("a")
->join("a_agents e", "a.report_agent_id=e.id", "left")
->join("a_store b", "e.store_id=b.id", "left")
->join("a_district c", "e.district_id=c.id", "left")
->where($where_)
->select();
}
/**
* 查询报备信息
*
* @param string $filed
* @param $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function selectReportByUserId($filed = "id", $params)
{
$where_ = [];
if (isset($params["id"])) {
$where_["a.id"] = $params["id"];
}
if (isset($params["report_agent_id"])) {
$where_["a.report_agent_id"] = $params["report_agent_id"];
}
if (isset($params["report_store_id"])) {
$where_["a.report_store_id"] = $params["report_store_id"];
}
if (isset($params["user_id"])) {
$where_["a.user_id"] = $params["user_id"];
}
if (isset($params["house_id"])) {
$where_["b.house_id"] = $params["house_id"];
}
if (isset($params["create_time"])) {
$where_["a.create_time"] = $params["create_time"];
}
$where_["a.status"] = 0;
return $this->db
->field($filed)
->alias("a")
->join("o_order b", "a.id = b.f_id", "left")
->join("a_agents c", "a.report_agent_id = c.id", "left")
->join("a_store d", "c.store_id = d.id", "left")
->where($where_)
->select();
}
/**
* 获取最近一条报备记录
* @param string $filed
* @param $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getReport($filed = "id",$params){
$where_ = [];
if (isset($params["user_id"])) {
$where_["a.user_id"] = $params["user_id"];
}
if (isset($params["id"])) {
$where_["a.id"] = $params["id"];
}
return $this->db->field($filed)
->alias("a")
->join("o_order b", "a.id = b.f_id", "left")
->join("a_agents c", "a.report_agent_id = c.id", "left")
->where($where_)
->order("a.create_time desc")
->limit(1)
->select();
}
public function selectReportListAll($filed = "id", $params, $pageNo, $pageSize){
$result = [];
$where["a.status"] = 0;
$where["b.is_del"] = 0;
switch ($params["type"]) {
case 2:
$result = $this->db->field($filed)
->alias("a")
->join("o_order b", "a.id=b.f_id", "left")
->join("o_march_in c", "b.id=c.order_id", "right")
->where($where)
->order("b.id desc")
->page($pageNo)
->limit($pageSize)
->select();
break;
case 3:
$result = $this->db->field($filed)
->alias("a")
->join("o_order b", "a.id=b.f_id", "left")
->join("o_paylog c", "b.id=c.order_id", "right")
->where($where)
->order("b.id desc")
->page($pageNo)
->limit($pageSize)
->select();
break;
case 4:
$result = $this->db->field($filed)
->alias("a")
->join("o_order b", "a.id=b.f_id", "left")
->join("o_bargain c", "b.id=c.order_id", "right")
->where($where)
->order("b.id desc")
->page($pageNo)
->limit($pageSize)
->select();
break;
default:
$result = $this->db->field($filed)
->alias("a")
->join("o_order b", "a.id=b.f_id", "left")
->where($where)
->order("b.id desc")
->page($pageNo)
->limit($pageSize)
->select();
}
//echo $this->getLastSql();
return $result;
}
/**
* @param string $filed
* @param $params
* @param $pageNo
* @param $pageSize
* @return mixed
* @throws \think\db\exception\BindParamException
* @throws \think\exception\PDOException
*/
public function selectReportList($filed = "id", $params, $pageNo, $pageSize)
{
$report_agent_str = $house_str = "1=1 ";
$start_index = ($pageNo - 1) * $pageSize;
if (isset($params["report_agent_id"])) {
$report_agent_id = $params["report_agent_id"];
$report_agent_str = "a.report_agent_id IN ($report_agent_id )";
}
if (isset($params["house_ids"])) {
$house_ids = $params["house_ids"];
$house_str = "b.house_id IN ($house_ids)";
}
// 约带看时间 开始 结束
if (!empty($params['create_time_start']) && !empty($params['create_time_end'])) {
$conditions[] = "aaa.create_time BETWEEN '".$params['create_time_start']. " 00:00:00' AND '" .$params['create_time_end'] . " 23:59:59'";
}
// 约带看人姓名
if (!empty($params['report_agent_name'])) {
$conditions[] = "aaa.report_agent_name LIKE '%".$params['report_agent_name']."%'";
}
// 约带看人手机号
if (!empty($params['report_agent_phone'])) {
$conditions[] = "aaa.report_agent_phone LIKE '%".$params['report_agent_phone']."%'";
}
// 商铺名
if (!empty($params['house_title'])) {
$conditions[] = "aaa.house_title LIKE '%".$params['house_title']."%'";
}
// 客户手机号
if (!empty($params['user_phone'])) {
$conditions[] = "aaa.user_phone LIKE '%".$params['user_phone']."%'";
}
if (!empty($params['order_id'])) {
$conditions[] = "aaa.order_id =".$params['order_id'];
}
//城市
if (!empty($params['city'])) {
$conditions[] = "aaa.city = '{$params['city']}'" ;
}
//商铺地址
if (!empty($params['internal_address'])) {
$conditions[] = "aaa.internal_address LIKE '%".$params['internal_address']."%'";
}
//商铺ID
if (!empty($params['shop_id'])) {
$conditions[] = "aaa.house_id = {$params['shop_id']}" ;
}
//客户ID
if (!empty($params['user_id'])) {
$conditions[] = "aaa.user_id = {$params['user_id']}" ;
}
#组装搜索where条件
if ($conditions) {
$where_params = 'WHERE ' . implode(" AND ", $conditions);
}
//
// dump($where_params);
// dump($params["type"]);
switch ($params["type"]) {
case 2:
$sql = "SELECT * FROM
(( SELECT
$filed
FROM
`o_report` `a`
LEFT JOIN `o_order` `b` ON `a`.`id` = `b`.`f_id`
RIGHT JOIN `o_march_in` `c` ON `b`.`id` = `c`.`order_id`
WHERE
$report_agent_str
AND `a`.`status` = 0
AND `b`.`is_del` = 0
GROUP BY
`c`.`order_id`
)UNION(
SELECT
$filed
FROM
`o_report` `a`
LEFT JOIN `o_order` `b` ON `a`.`id` = `b`.`f_id`
RIGHT JOIN `o_march_in` `c` ON `b`.`id` = `c`.`order_id`
WHERE
$house_str
AND `a`.`status` = 0
AND `b`.`is_del` = 0
GROUP BY
`c`.`order_id`
) ) AS aaa ORDER BY `create_time` DESC LIMIT $start_index,$pageSize";
$result = $this->db->query($sql);
return $result;
case 3:
$sql = "SELECT * FROM
(
(
SELECT
$filed
FROM
`o_report` `a`
LEFT JOIN `o_order` `b` ON `a`.`id` = `b`.`f_id`
RIGHT JOIN `o_paylog` `c` ON `b`.`id` = `c`.`order_id`
WHERE
$report_agent_str
AND `a`.`status` = 0
AND `b`.`is_del` = 0
GROUP BY
`c`.`order_id`
)
UNION
(
SELECT
$filed
FROM
`o_report` `a`
LEFT JOIN `o_order` `b` ON `a`.`id` = `b`.`f_id`
RIGHT JOIN `o_paylog` `c` ON `b`.`id` = `c`.`order_id`
WHERE
$house_str
AND `a`.`status` = 0
AND `b`.`is_del` = 0
GROUP BY
`c`.`order_id`
)
) AS aaa ORDER BY `create_time` DESC LIMIT $start_index,$pageSize";
$result = $this->db->query($sql);
return $result;
case 4:
$sql = "SELECT * FROM
((
SELECT
$filed
FROM
`o_report` `a`
LEFT JOIN `o_order` `b` ON `a`.`id` = `b`.`f_id`
RIGHT JOIN `o_bargain` `c` ON `b`.`id` = `c`.`order_id`
WHERE
$report_agent_str
AND `a`.`status` = 0
AND `b`.`is_del` = 0
GROUP BY
`c`.`order_id`
)
UNION
(
SELECT
$filed
FROM
`o_report` `a`
LEFT JOIN `o_order` `b` ON `a`.`id` = `b`.`f_id`
RIGHT JOIN `o_bargain` `c` ON `b`.`id` = `c`.`order_id`
WHERE
$house_str
AND `a`.`status` = 0
AND `b`.`is_del` = 0
GROUP BY
`c`.`order_id`
)
) AS aaa ORDER BY `create_time` DESC limit $start_index,$pageSize";
$result = $this->db->query($sql);
return $result;
default:
$filed = "a.id,a.user_id,a.report_agent_name,a.report_agent_phone,a.user_phone,a.user_name,a.predict_see_time,a.create_time,b.id as order_id,b.order_no,b.house_id,b.house_title,c.province,c.city,c.disc,c.internal_address";
$sql = "SELECT * FROM
((SELECT
$filed
FROM
`o_report` `a`
LEFT JOIN `o_order` `b` ON `a`.`id` = `b`.`f_id`
LEFT JOIN `g_houses` `c` ON `b`.`house_id` = `c`.`id`
WHERE
$report_agent_str
AND `a`.`status` = 0
AND `b`.`is_del` = 0)
UNION
(SELECT
$filed
FROM
`o_report` `a`
LEFT JOIN `o_order` `b` ON `a`.`id` = `b`.`f_id`
LEFT JOIN `g_houses` `c` ON `b`.`house_id` = `c`.`id`
WHERE
$house_str
AND `a`.`status` = 0
AND `b`.`is_del` = 0
) ) as aaa $where_params ORDER BY `create_time` DESC limit $start_index,$pageSize";
$result = $this->db->query($sql);
// dump($sql);
// dump($result);
// echo $this->getLastSql();
return $result;
}
}
/**
* @param string $filed
* @param $params
* @return mixed
* @throws \think\db\exception\BindParamException
* @throws \think\exception\PDOException
*/
public function selectReportCount($filed = "id", $params)
{
if (isset($params["report_agent_id"])) {
$report_agent_id = $params["report_agent_id"];
}
if (isset($params["house_ids"])) {
$house_ids = $params["house_ids"];
}
// 约带看时间 开始 结束
if (!empty($params['create_time_start']) && !empty($params['create_time_end'])) {
$conditions[] = "aaa.create_time BETWEEN '".$params['create_time_start']. " 00:00:00' AND '" .$params['create_time_end'] . " 23:59:59'";
}
// 约带看人姓名
if (!empty($params['report_agent_name'])) {
$conditions[] = "aaa.report_agent_name LIKE '%".$params['report_agent_name']."%'";
}
// 约带看人手机号
if (!empty($params['report_agent_phone'])) {
$conditions[] = "aaa.report_agent_phone LIKE '%".$params['report_agent_phone']."%'";
}
// 商铺名
if (!empty($params['house_title'])) {
$conditions[] = "aaa.house_title LIKE '%".$params['house_title']."%'";
}
// 客户手机号
if (!empty($params['user_phone'])) {
$conditions[] = "aaa.user_phone LIKE '%".$params['user_phone']."%'";
}
if (!empty($params['report_id'])) {
$conditions[] = "aaa.order_id =".$params['report_id'];
}
#组装搜索where条件
if ($conditions) {
$where_params = 'WHERE ' . implode(" AND ", $conditions);
}
switch ($params["type"]) {
case 2:
$sql = "SELECT count(1) as total FROM
(( SELECT
$filed
FROM
`o_report` `a`
LEFT JOIN `o_order` `b` ON `a`.`id` = `b`.`f_id`
RIGHT JOIN `o_march_in` `c` ON `b`.`id` = `c`.`order_id`
WHERE
`a`.`report_agent_id` IN ($report_agent_id )
AND `a`.`status` = 0
AND `b`.`is_del` = 0
GROUP BY
`c`.`order_id`
)UNION(
SELECT
$filed
FROM
`o_report` `a`
LEFT JOIN `o_order` `b` ON `a`.`id` = `b`.`f_id`
RIGHT JOIN `o_march_in` `c` ON `b`.`id` = `c`.`order_id`
WHERE
`b`.`house_id` IN ($house_ids)
AND `a`.`status` = 0
AND `b`.`is_del` = 0
GROUP BY
`c`.`order_id`
) ) AS aaa ";
$result = $this->db->query($sql);
return $result;
case 3:
$sql = "SELECT count(1) as total FROM
(
(
SELECT
$filed
FROM
`o_report` `a`
LEFT JOIN `o_order` `b` ON `a`.`id` = `b`.`f_id`
RIGHT JOIN `o_paylog` `c` ON `b`.`id` = `c`.`order_id`
WHERE
`a`.`report_agent_id` IN ($report_agent_id )
AND `a`.`status` = 0
AND `b`.`is_del` = 0
GROUP BY
`c`.`order_id`
)
UNION
(
SELECT
$filed
FROM
`o_report` `a`
LEFT JOIN `o_order` `b` ON `a`.`id` = `b`.`f_id`
RIGHT JOIN `o_paylog` `c` ON `b`.`id` = `c`.`order_id`
WHERE
`b`.`house_id` IN ($house_ids)
AND `a`.`status` = 0
AND `b`.`is_del` = 0
GROUP BY
`c`.`order_id`
)
) AS aaa";
$result = $this->db->query($sql);
return $result;
case 4:
$sql = "SELECT count(1) as total FROM
((
SELECT
$filed
FROM
`o_report` `a`
LEFT JOIN `o_order` `b` ON `a`.`id` = `b`.`f_id`
RIGHT JOIN `o_bargain` `c` ON `b`.`id` = `c`.`order_id`
WHERE
`a`.`report_agent_id` IN ($report_agent_id )
AND `a`.`status` = 0
AND `b`.`is_del` = 0
GROUP BY
`c`.`order_id`
)
UNION
(
SELECT
$filed
FROM
`o_report` `a`
LEFT JOIN `o_order` `b` ON `a`.`id` = `b`.`f_id`
RIGHT JOIN `o_bargain` `c` ON `b`.`id` = `c`.`order_id`
WHERE
`b`.`house_id` IN ($house_ids)
AND `a`.`status` = 0
AND `b`.`is_del` = 0
GROUP BY
`c`.`order_id`
)
) AS aaa ";
$result = $this->db->query($sql);
return $result;
default:
$filed = "a.id,a.user_id,a.report_agent_name,a.report_agent_phone,a.user_phone,a.user_name,a.predict_see_time,a.create_time,b.id as order_id,b.order_no,b.house_id,b.house_title,c.province,c.city,c.disc,c.internal_address";
$sql = "SELECT count(1) as total FROM
((SELECT
$filed
FROM
`o_report` `a`
LEFT JOIN `o_order` `b` ON `a`.`id` = `b`.`f_id`
WHERE
`a`.`report_agent_id` IN ($report_agent_id )
AND `a`.`status` = 0
AND `b`.`is_del` = 0)
UNION
(SELECT
$filed
FROM
`o_report` `a`
LEFT JOIN `o_order` `b` ON `a`.`id` = `b`.`f_id`
WHERE
`b`.`house_id` IN ($house_ids)
AND `a`.`status` = 0
AND `b`.`is_del` = 0
) ) as aaa $where_params";
$result = $this->db->query($sql);
//echo $this->getLastSql();
return $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 getAddReportNumGroupTime($params)
{
$field = "count(1) as num,DATE(create_time) as day";
$where_ = [];
if (isset($params["agent_id"])) {
$where_["report_agent_id"] = $params["agent_id"];
}
if (isset($params["create_time"])) {
$where_["create_time"] = $params["create_time"];
}
$where_["status"] = 0;
return Db::table($this->table)
->field($field)
->where($where_)
->group("day")
->select();
}
/**
* @param $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getAddReportNumGroupTimeNew($params)
{
$field = "count(1) as num";
$where_ = [];
if (isset($params["agent_id"])) {
$where_["report_agent_id"] = $params["agent_id"];
}
if (isset($params["create_time"])) {
$where_["create_time"] = $params["create_time"];
}
$where_["status"] = 0;
return Db::table($this->table)
->field($field)
->where($where_)
->select();
}
/**
* @param $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getAddReportNum($params)
{
$field = "count(DISTINCT a.id) as num";
$where_ = [];
if (isset($params["agent_id"])) {
$where_["a.report_agent_id"] = $params["agent_id"];
}
if (isset($params["create_time"])) {
$where_["a.create_time"] = $params["create_time"];
}
if (isset($params["house_ids"])) {
$where_["b.house_id"] = array( "in", $params["house_ids"] );
}
$where_["a.status"] = 0;
$result = Db::table($this->table)
->field($field)
->alias("a")
->join("o_order b", "a.id = b.f_id", "left")
->where($where_)
->select();
return $result;
}
/**
* @param $params
* @param $field
* @param $page_no
* @param $page_size
* @return false|\PDOStatement|string|\think\Collection
*/
public function getAddReportList($params, $field, $page_no, $page_size)
{
$where_ = [];
if (isset($params["agent_id"])) {
$where_["a.report_agent_id"] = $params["agent_id"];
}
if (isset($params["create_time"])) {
$where_["a.create_time"] = $params["create_time"];
}
if (isset($params["house_ids"])) {
$where_["b.house_id"] = array( "in", $params["house_ids"] );
}
$where_["a.status"] = 0;
$result = Db::table($this->table)
->field($field)
->alias("a")
->join("o_order b", "a.id = b.f_id", "left")
->join("g_houses c", "b.house_id = c.id", "left")
->where($where_)
->limit($page_size)
->page($page_no)
->select();
//echo Db::table($this->table)->getLastSql();
return $result;
}
/**
* @param int $pageNo 7151
* @param int $pageSize
* @param string $order_
* @param string $field
* @param string $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getReportList($pageNo = 1, $pageSize = 15, $order_ = 'a.id desc', $field = '', $params = '')
{
$result = $this->db->field($field)
->alias("a")
->join("a_agents d", "a.report_agent_id = d.id", "left")
->join("o_order b", "a.id = b.f_id", "left")
->join("g_houses c", "b.house_id = c.id", "left")
->where($params)
->limit($pageSize)
->page($pageNo)
->order($order_)
->select();
return $result;
}
/**
* 约带看总数
*
* @param $params
* @return int|string
*/
public function getAddReportListTotal($params)
{
return $this->db->alias("a")
->join("a_agents d", "a.report_agent_id = d.id", "left")
->join("o_order b", "a.id = b.f_id", "left")
->join("g_houses c", "b.house_id = c.id", "left")
->where($params)
->count('a.id');
}
public function getAddReportListPcInfo($params, $field, $page_no, $page_size)
{
$where_ = [];
if (isset($params["agent_id"])) {
$where_["a.report_agent_id"] = $params["agent_id"];
}
if (isset($params["create_time"])) {
$where_["a.create_time"] = $params["create_time"];
}
if (isset($params["house_ids"])) {
$where_["b.house_id"] = array( "in", $params["house_ids"] );
}
$where_["a.status"] = 0;
$result = Db::table($this->table)
->field($field)
->alias("a")
->join("o_order b", "a.id = b.f_id", "left")
->join("g_houses c", "b.house_id = c.id", "left")
->join('a_store e', 'a.report_store_id = e.id', 'left')
->where($where_)
->limit($page_size)
->page($page_no)
->select();
//echo Db::table($this->table)->getLastSql();
return $result;
}
public function getAddReportListPcInfoTotal($params, $field)
{
$where_ = [];
if (isset($params["agent_id"])) {
$where_["a.report_agent_id"] = $params["agent_id"];
}
if (isset($params["create_time"])) {
$where_["a.create_time"] = $params["create_time"];
}
if (isset($params["house_ids"])) {
$where_["b.house_id"] = array( "in", $params["house_ids"] );
}
$where_["a.status"] = 0;
$result = Db::table($this->table)
->field($field)
->alias("a")
->join("o_order b", "a.id = b.f_id", "left")
->join("g_houses c", "b.house_id = c.id", "left")
->join('a_store e', 'a.report_store_id = e.id', 'left')
->where($where_)
->count();
//echo Db::table($this->table)->getLastSql();
return $result;
}
/**
* @param $field
* @param $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getAddReportOrderList($field, $params)
{
$where_ = [];
if (isset($params["agent_id"])) {
$where_["a.report_agent_id"] = $params["agent_id"];
}
if (isset($params["create_time"])) {
$where_["a.create_time"] = $params["create_time"];
}
if (isset($params["house_ids"])) {
$where_["b.house_id"] = array( "in", $params["house_ids"] );
}
$where_["a.status"] = 0;
return Db::table($this->table)
->field($field)
->alias("a")
->join("o_order b", "a.id = b.f_id", "left")
// ->join('g_houses d', 'b.house_id = d.id', 'left')
->where($where_)
->group("a.id")
->select();
}
/**
* 获取报备和订单信息
*
* @param $field
* @param $where
* @param string $order
* @return array|false|\PDOStatement|string|Model
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getReportOrder($field, $where, $order = 'a.id desc')
{
return $this->db->field($field)
->alias('a')
->join('o_order b', 'b.f_id=a.id', 'left')
->where($where)
->order($order)
->find();
}
/**
* 根据order_id获得客方
*
* @param $report_id
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getAgentByReportId($report_id)
{
$user_id = $this->db->field('user_id')
->where('id', $report_id)
->value('user_id');
$user = new Users();
$agent_id = $user->where('id', $user_id)->value('agent_id');
$agent_data = $this->db->table('a_agents')->field('id,device_id')->where('id', $agent_id)->find();
return $agent_data;
}
public function getAgentByOrderId($field, $params)
{
return Db::name($this->table)
->field($field)
->alias("a")
->join("a_agents b", "a.report_agent_id = b.id", "left")
->where($params)
->select();
}
/**
* 获取经纪人新增带看数量
* @param $params
* @return int|string
*/
public function getAddFollowUpNumByAgentId($params)
{
$where_ = [];
if (isset($params["agent_id"])) {
$where_["report_agent_id"] = $params["agent_id"];
}
if (isset($params["create_time"])) {
$where_["create_time"] = $params["create_time"];
}
return Db::name($this->table)
->where($where_)
->count();
}
/**
* 预约看铺待看列表
* @param int $pageNo
* @param int $pageSize
* @param string $order_
* @param $field
* @param $params
* @return false|\PDOStatement|string|\think\Collection
*/
public function getWaitToSeeList($pageNo = 1, $pageSize = 15, $order_ = 'id desc', $field, $params)
{
/*$data = $this
->field($field)
->alias("a")
->join("o_order b", "b.f_id = a.id", "left")
->join("o_march_in c", "c.report_id = b.id", "left")
->join("g_houses d", "d.id = b.house_id", "left")
->where($params)
->order($order_)
->limit($pageSize)
->page($pageNo)
->select();*/
$start_index = ($pageNo - 1) * $pageSize;
if (isset($params["user_id"])) {
$user_id = $params["user_id"];
}
$sql = "select * from ((
SELECT
`a`.`id`,
a.user_id,
a.report_agent_id AS agents_id,
a.predict_see_time AS expect_time,
`b`.`house_id`,
a.create_time,
d.external_title AS house_title,
d.residue_num AS room_num_left,
d.is_show,
d.status,
d.external_image_id,
d.is_show_image
FROM
`o_report` `a`
LEFT JOIN `o_order` `b` ON `b`.`f_id` = `a`.`id`
LEFT JOIN `o_march_in` `c` ON `c`.`report_id` = `a`.`id`
LEFT JOIN `g_houses` `d` ON `d`.`id` = `b`.`house_id`
WHERE
`a`.`user_id` = $user_id
AND (`c`.`id` IS NULL)
)
UNION
(
SELECT
a.id,
a.user_id,
a.agents_id,
a.expect_time,
a.house_id,
a.create_time,
b.external_title AS house_title,
b.residue_num AS room_num_left,
b.is_show,
b.status,
b.external_image_id,
b.is_show_image
FROM
u_appoint_watch_shop a
LEFT JOIN g_houses b ON a.house_id = b.id
WHERE
a.user_id = $user_id
and a.agents_id IS NULL
and a.status in (0,1)
) ) as aaa order by aaa.create_time desc limit $start_index,$pageSize";
//echo $sql;
$data = $this->db->query($sql);
return $data;
}
/**
* 预约看铺列表 已看列表
*
* @param int $pageNo
* @param int $pageSize
* @param string $order_
* @param $field
* @param $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getHaveToSeeList($pageNo = 1, $pageSize = 15, $order_ = 'id desc', $field, $params)
{
$data = $this
->field($field)
->alias("a")
->join("o_order b", "b.f_id = a.id", "left")
->join("o_march_in c", "c.report_id = a.id", "right")
->join("g_houses d", "d.id = b.house_id", "left")
->where($params)
->order($order_)
->limit($pageSize)
->page($pageNo)
->select();
//echo $this->getLastSql();
return $data;
}
/**
* @param $field
* @param $where
* @return array|false|\PDOStatement|string|Model
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getMaxReportAgent($field, $where) {
return $this->alias('a')
->field($field)
->join('o_order b', 'a.id = b.f_id', 'left')
->where($where)
->group('a.report_agent_id ')
->find();
}
/**
* @param $field
* @param $where
* @return mixed
*/
public function getFieldValue($field, $where) {
return $this->db->where($where)->value($field);
}
public function selectReportByIdTime($filed = "id", $params)
{
$params["status"] = 0;
return $this->db
->field($filed)
->where($params)
->select();
}
}
<?php
namespace app\model;
use think\Db;
use think\helper\Time;
use think\Model;
/**
* Created by PhpStorm.
* User: zw
* Date: 2018/1/29
* Time: 下午5:47
*/
class OfficeOrderModel extends Model
{
// 设置当前模型对应的完整数据表名称
protected $table = 'office_o_order';
protected $db_;
public function __construct()
{
$this->db_ = Db::name($this->table);
}
public function insertOrderByAll($params)
{
Db::startTrans();
try {
$this->db_->insertAll($params);
Db::commit();
return 1;
} catch (\Exception $e) {
Db::rollback();
return 0;
}
}
/**
* @param $filed
* @param $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function selectOrderByOrderId($filed, $params)
{
$where_ = [];
if (isset($params["order_id"])) {
$where_["a.id"] = $params["order_id"];
}
if (isset($params["f_id"])) {
$where_["a.f_id"] = $params["f_id"];
}
if (isset($params["house_id"])) {
$where_["a.house_id"] = $params["house_id"];
}
$result = $this->db_
->field($filed)
->alias("a")
->join("g_houses b", "a.house_id = b.id", "left")
->where($where_)
->select();
//echo $this->db_->getLastSql();
return $result;
}
/**
* @param $ids
* @return false|\PDOStatement|string|\think\Collection
*/
public function selectSign($ids)
{
return $this->db_
->field('id as order_id,1 as type')
->where("id", "in", 0)
->union('SELECT order_id,2 as type FROM o_march_in where order_id in (' . $ids . ') group by order_id')
->union('SELECT order_id,3 as type FROM o_paylog where order_id in (' . $ids . ') group by order_id')
->union('SELECT order_id,4 as type FROM o_bargain where order_id in (' . $ids . ') group by order_id')
->select();
}
/**
* 订单详情主要信息
* @param $field
* @param $params
* @return false|\PDOStatement|string|\think\Collection
*/
public function selectOrderDetail($field, $params)
{
$where_ = [];
if (isset($params["order_id"])) {
$where_["a.id"] = $params["order_id"];
}
$where_["a.is_del"] = 0;
$where_["b.status"] = 0;
return $this->db_
->field($field)
->alias("a")
->join("o_report b", "a.f_id = b.id", "left")
->join("u_users c", "b.user_id = c.id", "left")
->join("g_houses d", "d.id = a.house_id", "left")
->where($where_)
->select();
}
/**
* @param $field
* @param $params
* @param $where_
* @return mixed
* @throws \think\db\exception\BindParamException
* @throws \think\exception\PDOException
*/
public function searchOrder($field, $params, $where_,$pageNo,$pageSize)
{
$start_index = ($pageNo - 1) * $pageSize;
$sql = "SELECT * FROM
(
(
SELECT
$field
FROM
`o_order` `a`
LEFT JOIN `o_report` `b` ON `a`.`f_id` = `b`.`id`
LEFT JOIN `g_houses` `c` ON `a`.`house_id` = `c`.`id`
WHERE
$params
)
UNION
(
SELECT
$field
FROM
`o_order` `a`
LEFT JOIN `o_report` `b` ON `a`.`f_id` = `b`.`id`
LEFT JOIN `g_houses` `c` ON `a`.`house_id` = `c`.`id`
WHERE
$where_
)
) AS aaa order by aaa.id desc LIMIT $start_index,$pageSize";
$result = $this->db_->query($sql);
//echo $this->getLastSql();
return $result;
}
/**
* @param $field
* @param $params
* @param $pageNo
* @param $pageSize
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function searchOrderAll($field, $params,$pageNo,$pageSize)
{
return $this
->field($field)
->alias("a")
->join("o_report b","a.f_id = b.id","left")
->join("g_houses c","a.house_id = c.id","left")
->where($params)
->order("a.id desc")
->page($pageNo)
->limit($pageSize)
->select();
}
/**
* @param $field
* @param $order_id
* @return array|false|\PDOStatement|string|Model
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getOrderById($field, $order_id)
{
return $this->field($field)
->where('id', $order_id)
->find();
}
/**
* 获取月均价
* @return float
*/
function getTurnover()
{
$timeArr = Time::lastWeek();
$signStartTime = date("Y-m-d H:i:s", $timeArr[0]);
$signEndTime = date("Y-m-d H:i:s", $timeArr[1]);
$where_['a.create_time'] = array( "between", array( $signStartTime, $signEndTime ) );
$where_['b.father_id'] = array( "eq", 0 );
return $this->db_
->alias("a")
->join("o_bargain b", "a.id = b.order_id", "left")
->where($where_)
->count();
}
/**
* 根据订单id获取楼盘info
*
* @param $field
* @param $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getHouseInfoByOrderId($field, $params)
{
return $this->db_
->field($field)
->alias("a")
->join("g_houses b", "a.house_id = b.id", "left")
->where($params)
->select();
}
/**
* 根据订单id获取楼盘info
*
* @param $field
* @param $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getHouseInfoByOrderIdOne($field, $params)
{
return $this->db_
->field($field)
->alias("a")
->join("g_houses b", "a.house_id = b.id", "left")
->where($params)
->find();
}
public function getOrderByHouseId(array $params): bool
{
$where_ = $select_ = [];
if (isset($params["create_time"])) {
$where_["create_time"] = $params["create_time"];
$select_["b.create_time"] = $params["create_time"];
}
if (isset($params["house_id"])) {
$where_["house_id"] = $params["house_id"];
$select_["a.house_id"] = $params["house_id"];
}
//判断此楼盘10天内是否有订单记录
$orderResult = $this->db_
->field("id")
->where($where_)
->limit(1)
->select();
//echo $this->getLastSql();
if (count($orderResult) > 0) {
return true;
}
//判断此楼盘10天内是否有跟进记录
$marchIn = $this->db_
->field("b.id")
->alias("a")
->join("o_march_in b", "a.id = b.order_id", "left")
->where($select_)
->limit(1)
->select();
// echo $this->getLastSql();
if (count($marchIn) > 0) {
return true;
}
return false;
}
/**
* 获取7日30日次数
*/
public function getCountByHouseId($params)
{
$result = Db::table($this->table)
->field("id")
->where($params)
->count();
//echo Db::table($this->table)->getLastSql();
//dump($this->getLastSql());
return $result;
}
/**
* @param $field
* @param $where
* @return mixed
*/
public function getFieldValue($field, $where) {
return $this->db_->where($where)->value($field);
}
}
\ 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