Commit 2709e290 authored by hujun's avatar hujun

新增分佣提成修改

parent f5cb755b
<?php
/**
* Created by PhpStorm.
* User: fuju
* User: hu jun
* Date: 2017/12/22
* Time: 14:44
*/
......@@ -11,7 +11,6 @@ namespace app\index\controller;
use app\index\extend\Basic;
use app\model\AAgents;
use app\model\Agents;
use app\model\GHousesToAgents;
class Broker extends Basic
......@@ -187,6 +186,9 @@ class Broker extends Basic
* 获取经纪人和楼盘关系信息
*
* @return \think\Response
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getAgentsTohouses() {
$data['status'] = 200;
......@@ -210,7 +212,19 @@ class Broker extends Basic
return $this->response($data['status'], $data['msg'], $data['data']);
}
/**
* 根据经纪人id获取部门和门店id
*
* @return \think\Response
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getAgentDistrictStore() {
$m_store = new AAgents();
$where['a.id'] = $this->params['id'];
$field = 'b.store_name, c.district_name';
$data = $m_store->getStoreDistrict($field, $where);
return $this->response(200, '', $data);
}
}
\ No newline at end of file
......@@ -244,39 +244,18 @@ class Finance extends Basic
$data['msg'] = "";
$data['data'] = [];
if (empty($this->params['id'])) {
if (empty($this->params['id']) || empty($this->params['agent_id'])) {
$data['code'] = 101;
$data['msg'] = 'Id is null.';
$data['msg'] = '提交信息错误!';
} else {
$bargain = new OBargainModel();
$bargain_data = $bargain->get($this->params['id']);
if (empty($bargain_data)) {
$data['data'] = $bargain->addBargainCommission($this->params['id'], $this->userId, $this->params['agent_id'],
$this->params['role'], $this->params['scale_fee'], $this->params['scale']);
if ($data['data'] == 0) {
$data['code'] = 101;
$data['msg'] = 'Don\'t have info.';
} else {
$insert_data['report_id'] = $bargain_data['report_id'];
$insert_data['agent_id'] = $bargain_data['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'] = $bargain_data['submit_agent_id'];
$insert_data['price'] = $bargain_data['price'];
$insert_data['commission'] = $bargain_data['commission'];
$insert_data['status'] = $bargain_data['status'];
$insert_data['source'] = 1;
$insert_data['role'] = empty($this->params['role']) ? 0 : $this->params['role'];
$insert_data['scale_fee'] = empty($this->params['scale_fee']) ? 0 : $this->params['scale_fee'];
$insert_data['practical_fee'] = empty($this->params['practical_fee']) ? 0 : $this->params['practical_fee'];
$insert_data['father_id'] = empty($this->params['id']) ? 0 : $this->params['id'];
$insert_data['scale'] = empty($this->params['scale']) ? 0 : $this->params['scale'];
$data['data']['id'] = $bargain->insertBargain($insert_data);
if ($data['data'] == 0) {
$data['code'] = 101;
$data['msg'] = 'Add the failure.';
}
$data['msg'] = 'Add the failure.';
}
}
return $this->response($data['code'], $data['msg'], $data['data']);
......@@ -299,14 +278,15 @@ class Finance extends Basic
$data['code'] = 101;
$data['msg'] = 'Id is null.';
} else {
$bargain = new OBargainModel();
$fields = 'role,agent_id,scale,scale_fee,practical_fee,content';
$where = "id = {$this->params['id']} or father_id = {$this->params['id']}";
$data['data'] = $bargain->selectBargainByOrderNo($fields, $where);
$agent = new AAgents();
$m_comm = new OPartialCommission();
$fields = 'role,b.agent_id,scale,scale_fee,a.practical_fee,content,a.cash,a.service_charge,a.tallage,a.charity_fund,a.real_fee,a.create_time';
$where[0] = ['EXP',"b.id = {$this->params['id']} or b.father_id = {$this->params['id']}"];
$data['data'] = $m_comm->getCommissionBargainList(1, 100, 'a.id desc', $fields, $where);
$m_agent = new AAgents();
$fields_a = 'name,store_name';
foreach ($data['data'] as $k=>$v) {
$agent_store = $agent->getAgentsStoreById(['a.id'=>$v['agent_id']], $fields_a);
$agent_store = $m_agent->getAgentsStoreById(['a.id'=>$v['agent_id']], $fields_a);
$data['data'][$k]['agent_name'] = $agent_store['name'];
$data['data'][$k]['store_name'] = $agent_store['store_name'];
......
......@@ -46,7 +46,8 @@ class Basic extends Controller
'index/getLabelsList',
'index/regions',
'index/getAuth2',
'index/getDistrict'
'index/getDistrict',
'index/getAgentDistrictStore'
);
/**
......
......@@ -485,4 +485,57 @@ class OBargainModel extends Model
->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) {
$this->startTrans();
$bargain_data = $this->where('id', $id)->find()->lock(true);
if (empty($bargain_data['id'])) {
$result = false;
} else {
$insert_data['father_id'] = $id;
$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'] = $bargain_data['submit_agent_name'];
$insert_data['price'] = $bargain_data['price'];
$insert_data['commission'] = $bargain_data['commission'];
$insert_data['status'] = $bargain_data['status'];
$insert_data['source'] = $bargain_data['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['is_commission'] = $bargain_data['is_commission'];
$insert_data['content'] = $bargain_data['content'];
$result = $this->insert($insert_data);
if ($result == 1) {
$this->commit();
} else {
$this->rollback();
$result = false;
}
}
return $result;
}
}
\ No newline at end of file
......@@ -102,6 +102,7 @@ Route::group('index', [
'addHousesAgentsDish' => ['index/broker/AddHousesAgents', ['method' => 'POST']], //新增楼盘与经纪人关系(盘方)
'delTohouses' => ['index/broker/delTohouses', ['method' => 'POST']], //解除经纪人和楼盘关系
'getAgentsTohouses' => ['index/broker/getAgentsTohouses', ['method' => 'GET']], //获取经纪人和楼盘关系信息
'getAgentDistrictStore' => ['index/broker/getAgentDistrictStore', ['method' => 'GET']], //获取经纪人id获取部门门店名称
'batchChangDish' => [ 'index/houses/batchChangDish', [ 'method' => 'post' ] ],//批量修改盘方
//版本管理
......
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