Commit f53eab4c authored by clone's avatar clone

1

parent 7c9e6fac
......@@ -14,15 +14,18 @@ use think\Log;
*/
class BargainService
{
/**
* 获取成交报告列表
/**获取成交报告列表
* @param $pageNo
* @param $pageSize
* @param $submit_agent_id
* @param $status
* @param $is_my_correlation
* @param $keyword
* @return array|false|\PDOStatement|string|\think\Collection
* @param $bargain_id
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getBargainList($pageNo, $pageSize, $submit_agent_id, $status, $is_my_correlation, $keyword, $bargain_id)
{
......@@ -33,6 +36,7 @@ class BargainService
$ids = $aService->getAgentsByAgentId($submit_agent_id);
$condition["ids"] = $ids;
$condition["submit_agent_id"] = $submit_agent_id;
} else {
$condition["father_id"] = 0;
}
......@@ -51,7 +55,7 @@ class BargainService
$condition["status"] = 21;
break;
case 5://调账->搜成交报告 不包括 待撤销和已撤销
$condition["status"] = array('not in','20,21');
$condition["status"] = array('not in', '20,21');
break;
default:
}
......@@ -74,7 +78,7 @@ class BargainService
return $convertResult;
}
public function getBargainListV2($pageNo, $pageSize, $submit_agent_id, $status, $is_my_correlation, $keyword, $bargain_id,$type)
public function getBargainListV2($pageNo, $pageSize, $submit_agent_id, $status, $is_my_correlation, $keyword, $bargain_id, $type)
{
$condition = [];
......@@ -83,6 +87,7 @@ class BargainService
$ids = $aService->getAgentsByAgentId($submit_agent_id);
$condition["ids"] = $ids;
$condition["submit_agent_id"] = $submit_agent_id;
} else {
$condition["father_id"] = 0;
}
......@@ -101,7 +106,7 @@ class BargainService
$condition["status"] = 21;
break;
case 5://调账->搜成交报告 不包括 待撤销和已撤销
$condition["status"] = array('not in','20,21');
$condition["status"] = array('not in', '20,21');
break;
default:
}
......
......@@ -143,7 +143,7 @@ class OBargainModel extends Model
public function selectBargainListByHouseId($house_id)
{
$params["b.house_id"] = $house_id;
$params["a.status"] = array( "not in", "21,30" );
$params["a.status"] = array("not in", "21,30");
$data = $this->db_
->field("a.id,a.industry_type")
->alias("a")
......@@ -243,7 +243,10 @@ class OBargainModel extends Model
$where_["a.status"] = $params["status"];
}
if (isset($params["ids"])) {
$where_["a.agent_id"] = array( "in", $params["ids"] );
$where_["a.agent_id"] = array("in", $params["ids"]);
}
if (isset($params["submit_agent_id"])) {
$where_["a.submit_agent_id"] = $params["submit_agent_id"];
}
if (isset($params["account_statement"])) {
......@@ -258,14 +261,14 @@ class OBargainModel extends Model
}
if (!isset($params["type"]) && isset($params["keyword"])) {
$where_["b.user_phone|b.user_name|d.internal_address"] = array( "like", "%" . $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
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']) . "%");
$where_["d.internal_address"] = array("like", "%" . trim($params['keyword']) . "%");
break;
case 3:
$where_["a.id"] = $params["keyword"];
......@@ -351,7 +354,7 @@ class OBargainModel extends Model
if (isset($params['id'])) {
$where_['a.id'] = $params['id'];
}
$where_['a.status'] = array( "<>", 30 );
$where_['a.status'] = array("<>", 30);
$result = $this->db_
->field($filed)
......@@ -448,7 +451,7 @@ class OBargainModel extends Model
$this->startTrans();
$bargain_data = $this->field('id,report_id,agent_id,order_no,order_id')->where([
'id' => $id,
'status' => [ 'in', '10,11,20,21' ]
'status' => ['in', '10,11,20,21']
])->find();
if ($bargain_data != '') {
......@@ -500,8 +503,8 @@ class OBargainModel extends Model
//记录第几级审核-与 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'] ];
$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();
......@@ -640,7 +643,7 @@ class OBargainModel extends Model
if (isset($params["create_time"])) {
$where_["c.income_time"] = $params["create_time"];
}
$where_["status"] = array( "in", "10,11,13" );
$where_["status"] = array("in", "10,11,13");
return Db::table($this->table)
->field($field)
->alias("a")
......@@ -715,7 +718,7 @@ class OBargainModel extends Model
$where_["role"] = 3;//必须是反签方
}
$where_["status"] = array( "in", "10,11,13" );
$where_["status"] = array("in", "10,11,13");
if (isset($params["agent_id"])) {
$where_["agent_id"] = $params["agent_id"];
......@@ -756,7 +759,7 @@ class OBargainModel extends Model
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' ]);
array_push($join, [' o_report c', 'a.report_id=c.id', 'left']);
}
if (isset($params["agent_id"])) {
......@@ -771,8 +774,8 @@ class OBargainModel extends Model
}
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' ]);
$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"])) {
......@@ -788,6 +791,7 @@ class OBargainModel extends Model
->select();
return $return;
}
public function getAddBargainNumV2($params, $type)
{
$where_ = [];
......@@ -800,7 +804,7 @@ class OBargainModel extends Model
} elseif ($type == 3) {
$field = "count(1) as num";
$where_["a.role"] = 3;//必须是反签方
$where_["a.status"] = array( "in", '10,11,13');
$where_["a.status"] = array("in", '10,11,13');
}
......@@ -813,8 +817,8 @@ class OBargainModel extends Model
}
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' ]);
$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)
......@@ -834,13 +838,13 @@ class OBargainModel extends Model
$join = [];
if ($type == 1) {
$field = "sum(scale_fee) as num";
$where_["a.status"] = array( "in", '10,11,13');
$where_["a.status"] = array("in", '10,11,13');
} elseif ($type == 2) {
$field = "sum(practical_fee) as num";
} elseif ($type == 3) {
$field = "count(1) as num";
$where_["a.role"] = 3;//必须是反签方1
$where_["a.status"] = array( "in", '10,11,13');
$where_["a.status"] = array("in", '10,11,13');
}
if (isset($params["agent_id"])) {
......@@ -852,8 +856,8 @@ class OBargainModel extends Model
}
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' ]);
$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)
......@@ -864,6 +868,7 @@ class OBargainModel extends Model
->select();
return $return;
}
/**
* @param $params
* @return false|\PDOStatement|string|\think\Collection
......@@ -895,7 +900,6 @@ class OBargainModel extends Model
}
/**
* @param $page_no
* @param $page_size
......@@ -953,9 +957,9 @@ class OBargainModel extends Model
}
if (isset($params["house_ids"])) {
$where_["b.house_id"] = array( "in", $params["house_ids"] );
$where_["b.house_id"] = array("in", $params["house_ids"]);
}
$where_["a.status"] = array( "in", "10,11,13,20" );
$where_["a.status"] = array("in", "10,11,13,20");
return Db::table($this->table)
->field($field)
->alias("a")
......@@ -994,7 +998,7 @@ class OBargainModel extends Model
}
if (isset($params["house_ids"])) {
$where_["b.house_id"] = array( "in", $params["house_ids"] );
$where_["b.house_id"] = array("in", $params["house_ids"]);
}
$data = Db::table($this->table)
......@@ -1134,7 +1138,7 @@ class OBargainModel extends Model
$result[$k] = $v;
if (isset($v['agent_id'])) {
$agent_data = $m_agent->getStoreDistrict($fields_str, [ 'a.id' => $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'];
}
......@@ -1174,7 +1178,7 @@ class OBargainModel extends Model
->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();
$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'];
......@@ -1261,7 +1265,7 @@ class OBargainModel extends Model
$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'] ]);
$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'];
}
}
......@@ -1309,11 +1313,11 @@ class OBargainModel extends Model
}
$data = $this->field('role,agent_id,scale,scale_fee')
->where('','EXP','id='.$bargain_id.' OR father_id='.$bargain_id)
->where('status', '<>',30)
->where('', 'EXP', 'id=' . $bargain_id . ' OR father_id=' . $bargain_id)
->where('status', '<>', 30)
->select();
foreach ($data as $k=>$v) {
foreach ($data as $k => $v) {
if (in_array($v['agent_id'], $bargain_id_arr)) {
unset($data[$k]);
}
......@@ -1376,7 +1380,7 @@ class OBargainModel extends Model
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')
->join('a_agents d', 'a.agent_id=d.id', 'left')
->where('a.status', 'in', $status)
->where('a.id', $id)
->find();
......@@ -1416,7 +1420,7 @@ class OBargainModel extends Model
$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'] ]);
$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'];
......@@ -1559,7 +1563,6 @@ class OBargainModel extends Model
// ->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();
......@@ -1587,8 +1590,7 @@ class OBargainModel extends Model
}
public function getBargainSumList($field, $params,$page_size,$page_no,$request_source_type)
public function getBargainSumList($field, $params, $page_size, $page_no, $request_source_type)
{
$where_ = [];
......@@ -1599,9 +1601,9 @@ class OBargainModel extends Model
if (isset($params["create_time"])) {
$where_["a.create_time"] = $params["create_time"];
}
$where_["a.status"] = array( "in", "10,11,13" );
$where_["a.status"] = array("in", "10,11,13");
if($request_source_type && $request_source_type == 1){
if ($request_source_type && $request_source_type == 1) {
//pc后台业绩 成交单数 需要调用
$where_["a.role"] = 3;//必须是反签方
}
......@@ -1645,7 +1647,8 @@ class OBargainModel extends Model
* @param $where
* @return float|int
*/
public function sumField($field, $where) {
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')
......@@ -1663,7 +1666,8 @@ class OBargainModel extends Model
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function agentBargainAll($field, $where) {
public function agentBargainAll($field, $where)
{
return $this->db_->alias('a')
->field($field)
->join('a_agents b', 'a.agent_id = b.id', 'left')
......@@ -1676,7 +1680,8 @@ class OBargainModel extends Model
* @param $where
* @return mixed
*/
public function getFieldValue($field, $where) {
public function getFieldValue($field, $where)
{
return $this->db_->where($where)->value($field);
}
......@@ -1685,7 +1690,8 @@ class OBargainModel extends Model
* @param $where
* @return mixed
*/
public function getFieldColumn($field, $where) {
public function getFieldColumn($field, $where)
{
return $this->db_->where($where)->column($field);
}
......@@ -1697,7 +1703,8 @@ class OBargainModel extends Model
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getDetail($field, $where) {
public function getDetail($field, $where)
{
return $this->db_->field($field)
->where($where)
->find();
......@@ -1711,7 +1718,8 @@ class OBargainModel extends Model
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function agentBargainIncome($field, $where) {
public function agentBargainIncome($field, $where)
{
return $this->db_->alias('a')
->field($field)
->join('a_agents b', 'a.agent_id = b.id', 'left')
......
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