Commit 122b3c1c authored by hujun's avatar hujun

修改

检查是否有邀请人
parent fbf23e74
......@@ -34,6 +34,7 @@ use app\model\OPartialCommission;
use app\model\OPayLogModel;
use app\model\ORefundModel;
use app\model\TAgentTotalModel;
use app\model\Users;
use app\task\controller\ResultsSummaryNewTask;
use think\Request;
......@@ -600,6 +601,107 @@ class Finance extends Basic
return $this->response($data['code'], $data['msg'], $data['data']);
}
/**
* 成交报告详情-分佣提成V2
*
* @return \think\Response
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function commissionListV2()
{
$data['code'] = 200;
$data['msg'] = "";
$data['data'] = [];
if (empty($this->params['id'])) {
$data['code'] = 101;
$data['msg'] = 'Id is null.';
return $data;
}
$fields = 'a.id,a.role,a.agent_id,a.scale,a.scale_fee,a.father_id,a.report_id';
$where[0] = [ 'EXP', "a.id = {$this->params['id']} or a.father_id = {$this->params['id']}" ];
$where['a.status'] = [ '<>', 30 ];
$list = $this->m_bargain->getBargainPartial(1, 100, 'a.id desc', $fields, $where);
$result = [];
$m_agent = new AAgents();
$m_partial = new OPartialCommission();
$m_real = new ORealIncome();
$fields_str = 'a.id,a.name,b.store_name';
$partial_field = 'id,scale,practical_fee,cash,service_charge,charity_fund,real_fee,confirm_date,confirm_status,should_commission,real_income_id';
$partial_where['is_del'] = 0;
$role_arr = [1=>'盘方', 2=>'客方',3=>'反签',4=>'独家',5=>'合作方',6=>'APP盘下载方',7=>'APP客下载方'];
foreach ($list as $k => $v) {
$result[$k] = $v;
$result[$k]['role_name'] = array_key_exists($v['role'], $role_arr) ? $role_arr[$v['role']] : '无';
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'];
}
$partial_where['bargain_id'] = $v['id'];
$partial_commission = $m_partial->getPartialList($partial_field, $partial_where);
foreach ($partial_commission as $k2 => $v2) {
if (empty($v2['real_income_id'])) {
$income_time = $m_real->getBargainTaxes($this->params['id'],'id,income_time');
//当只有一个收入日期,给前端显示用
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->getBargainIncome($this->params['id'], 'id,income_time');
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;
}
$data['data'] = $result;
return $this->response($data['code'], $data['msg'], $data['data']);
}
/**
* 检查是否有邀请人(客户邀请客户)
*
* @return \think\Response
*/
public function checkReferrer()
{
$report_id = $this->params['report_id'];
if (empty($report_id)) {
return $this->response(101, '参数错误');
}
$m_report = new OReportModel();
$m_user = new Users();
$user_id = $m_report->getFieldValue('user_id', ['id'=>$report_id]);
$referrer_id = $m_user->getUserByWhereValue('referrer_id', ['id'=>$user_id,'referrer_source'=>10]);
$is_show = 0;
if ($referrer_id) {
$is_show = 1;
}
return $this->response(200,'', ['is_show'=>$is_show]);
}
/**
* 收款记录
*
......
......@@ -85,6 +85,7 @@ class Basic extends Controller
'index/getRandKingListByAgentId',
'index/saveActivity',
'index/getActivityList',
'index/checkReferrer',
);
/**
......
......@@ -1146,6 +1146,43 @@ class OBargainModel extends Model
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
*/
/**
* @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();
}
/**
* 分佣提成汇总表
*
......
......@@ -487,4 +487,20 @@ class OPartialCommission extends BaseModel
return $num;
}
/**
* @param string $field
* @param array $where
* @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 getPartialList(string $field, array $where, $order = 'id asc') {
return $this->field($field)
->where($where)
->order($order)
->select();
}
}
\ No newline at end of file
......@@ -37,6 +37,21 @@ class ORealIncome extends BaseModel
->select();
}
/**
* @param int $bargain_id
* @param string $field
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getBargainIncome(int $bargain_id, $field = 'id as fee_id,money,income_time') {
return $this->field($field)
->where('bargain_id', $bargain_id)
->where('is_del', 0)
->find();
}
/**
* @param int $field
* @param array $where
......
......@@ -246,7 +246,8 @@ Route::group('index', [
'bargainInfo' => ['index/Finance/bargainInfo', ['method' => 'get']], //获取成交报告详情
'editBargainInfo' => ['index/Finance/editBargainInfo', ['method' => 'post']], //修改成交报告佣金
'addBargain' => ['index/Finance/addBargain', ['method' => 'post']], //新增成交报告佣金(分佣提成)
'commissionList' => ['index/Finance/commissionList', ['method' => 'get']], //成交报告详情-分佣提成
'commissionList' => ['index/Finance/commissionListV2', ['method' => 'get']], //成交报告详情-分佣提成
'checkReferrer' => ['index/Finance/checkReferrer', ['method' => 'get']], //检查是否有邀请人(客户邀请客户)
'payLogList' => ['index/Finance/payLogList', ['method' => 'get']], //收款记录
'phone_up_list' => ['index/remark/phone_up_list', ['method' => 'get|post']], //电话跟进列表
'selectReportAll' => ['index/Finance/selectReportAll', ['method' => 'get|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