Files
2022-06-21 16:11:30 +08:00

178 lines
7.4 KiB
PHP

<?php
defined('WXAPP_APP') OR exit('No direct script access allowed');
/**
* Created by Vim
* User: lcc
* Date: 2021/12/22
* Time: 14:08
*/
require_once APPPATH . 'controllers/wxapp/Wxapp.php';
class Brokerage extends Wxapp
{
function __construct($inputs, $app_key)
{
parent::__construct($inputs, $app_key);
$this->login_white = array();//登录白名单
$this->check_status = array();//用户状态校验
$this->check_mobile = array();//需要手机号
$this->check_headimg = array();//授权微信信息
$this->load->model('app/licheb/app_licheb_brokerage_model');
$this->load->model('app/liche/app_liche_users_model');
$this->load->model('receiver/receiver_clues_model');
$this->load->model('auto/auto_series_model');
$this->load->model('auto/auto_brand_model');
$this->load->model('auto/auto_attr_model');
$this->load->model('auto/auto_cars_model');
}
protected function get(){
$biz_id = $this->session['new_biz_id'] ? $this->session['new_biz_id'] : intval($this->session['biz_id']);
$row = $this->app_licheb_brokerage_model->get(['biz_id'=>$biz_id,'status'=>1]);
$data = [
'id' => $row['id'] ? $row['id'] : '',
'brokerage_1' => $row['brokerage_1'] ? $row['brokerage_1'] : 0,
'brokerage_2' => $row['brokerage_2'] ? $row['brokerage_2'] : 0,
];
return $data;
}
//创建佣金
protected function post(){
$biz_id = $this->session['new_biz_id'] ? $this->session['new_biz_id'] : intval($this->session['biz_id']);
$brokerage_1 = $this->input_param('brokerage_1');
$brokerage_2 = $this->input_param('brokerage_2');
$row = $this->app_licheb_brokerage_model->get(['biz_id'=>$biz_id,'status'=>1]);
if($row){
throw new Exception('数据已存在', ERR_PARAMS_ERROR);
}
if($brokerage_1+$brokerage_2>3000){
throw new Exception('总分佣金额不得大于3000', API_CODE_FAIL);
}
$data = [
'biz_id' => $biz_id,
'brokerage_1' => $brokerage_1,
'brokerage_2' => $brokerage_2,
'status' => 1,
'c_time' => time()
];
$result = $this->app_licheb_brokerage_model->add($data);
if($result){
throw new Exception('添加成功', API_CODE_SUCCESS);
}else{
throw new Exception('添加失败', ERR_PARAMS_ERROR);
}
}
//修改佣金
protected function put(){
$biz_id = $this->session['new_biz_id'] ? $this->session['new_biz_id'] : intval($this->session['biz_id']);
$id = $this->input_param('id');
$brokerage_1 = $this->input_param('brokerage_1');
$brokerage_2 = $this->input_param('brokerage_2');
$row = $this->app_licheb_brokerage_model->get(['id'=>$id,'biz_id'=>$biz_id]);
if(!$row){
throw new Exception('数据不存在', ERR_PARAMS_ERROR);
}
if($brokerage_1+$brokerage_2>3000){
throw new Exception('总分佣金额不得大于3000', API_CODE_FAIL);
}
$up_data = [
'brokerage_1' => $brokerage_1,
'brokerage_2' => $brokerage_2
];
$result = $this->app_licheb_brokerage_model->update($up_data,['id'=>$id]);
if($result){
throw new Exception('修改成功', API_CODE_SUCCESS);
}else{
throw new Exception('修改失败', ERR_PARAMS_ERROR);
}
}
//转介绍订单
protected function get_orders(){
$biz_id = $this->session['new_biz_id'] ? $this->session['new_biz_id'] : intval($this->session['biz_id']);
$keyword = $this->input_param('keyword');
$page = $this->input_param('page');
$size = $this->input_param('size');
!$page && $page = 1;
!$size && $size = 10;
$t1 = 'lc_receiver_clues';
$t2 = 'lc_receiver_orders_v2';
$where = [
"{$t2}.status>=" => 0,
"{$t1}.recommend_id>" => 0,
"{$t2}.biz_id" => $biz_id
];
if($keyword){
if(is_numeric($keyword)){
$where["{$t1}.mobile like '%{$keyword}%'"] = null;
}else{
$where["{$t1}.name like '%{$keyword}%'"] = null;
}
}
$count = $this->receiver_clues_model->selectClues($where,'', '', '', 1);
$lists = [];
if($count){
$fileds = "{$t1}.recommend_id,{$t1}.c_time as b_time,{$t1}.name,{$t1}.mobile,{$t2}.brand_id,{$t2}.s_id,{$t2}.v_id,{$t2}.cor_id,{$t2}.c_time";
$rows = $this->receiver_clues_model->selectClues($where,"{$t1}.id desc", $page, $size,0,$fileds);
//品牌车型
$brand_arr = array_unique(array_column($rows,'brand_id'));
$brands = $this->auto_brand_model->get_map_by_ids($brand_arr,'id,name');
//车系车型
$series_arr = array_unique(array_column($rows,'s_id'));
$series = $this->auto_series_model->get_map_by_ids($series_arr,'id,name');
//获取车辆属性
$version_arr = array_unique(array_column($rows,'v_id'));
$color_arr = array_unique(array_column($rows,'cor_id'));
$attrs_arr = array_merge($version_arr,$color_arr);
$attrs = $this->auto_attr_model->get_map_by_ids($attrs_arr,'id,title');
//获取报备用户
$uids = array_unique(array_column($rows,'recommend_id'));
$uid_str = implode(',',$uids);
$user_rows = [];
$uid_str && $user_rows = $this->app_liche_users_model->map('id','',["id in ($uid_str)"=>null],'','','','id,nickname,up_uid');
foreach($rows as $key=>$val){
$brand_name = isset($brands[$val['brand_id']]) ? $brands[$val['brand_id']][0]['name'] : '';
$serie_name = isset($series[$val['s_id']]) ? $series[$val['s_id']][0]['name'] : '';
$color = isset($attrs[$val['cor_id']]) ? $attrs[$val['cor_id']][0]['title'] : '';
$version = isset($attrs[$val['v_id']]) ? $attrs[$val['v_id']][0]['title'] : '';
$user = $user_rows[$val['recommend_id']] ? $user_rows[$val['recommend_id']][0] : [];
$nickname = $user['nickname'] ? name_asterisk($user['nickname']) : '';
$up_nickname = '';
if($user['up_uid']){
$up_user = $this->app_liche_users_model->get(['id'=>$user['up_uid']],'nickname');
$up_nickname = $up_user['nickname'] ? '(上级:'.name_asterisk($up_user['nickname']).')' : '';
}
$car = $this->auto_cars_model->get(['brand_id'=>$val['brand_id'],'s_id'=>$val['s_id'],'v_id'=>$val['v_id']],'brokerage_1,brokerage_2');
$info = [
'品牌车型' => "{$brand_name}{$serie_name}-{$color}-{$version}",
'报备人' => $nickname.$up_nickname,
'佣金金额' => $car['brokerage_1']+$car['brokerage_2'],
'订单日期' => date('Y-m-d',$val['c_time']),
];
$lists[] = [
'name' => $val['name'],
'mobile' => mobile_asterisk($val['mobile']),
'info' => $info,
'b_time' => date('Y-m-d',$val['b_time'])
];
}
}
$data = [
'list' => $lists,
'total' => $count
];
return $data;
}
}