add-licheb-brokerage

This commit is contained in:
lccsw
2021-12-24 14:38:41 +08:00
parent 8952ef31a6
commit 1954668475
6 changed files with 230 additions and 10 deletions
+171
View File
@@ -0,0 +1,171 @@
<?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);
}
$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);
}
$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';
$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;
}
}
+14 -7
View File
@@ -41,22 +41,29 @@ class Deal_entity
$this->load->model('auto/auto_cars_model');
$this->load->model($this->app_config['model'], 'mdUser');
$this->load->model('app/Deal_log_model', 'mdDealLog');
$this->load->model('app/licheb/app_licheb_brokerage_model');
$order = $this->ci->receiver_orders_model->get(['id'=>$oid]);
$clue = $this->ci->receiver_clues_model->get(['id'=>$order['clue_id']]);
if(!$clue){
return array('code' => 0, 'msg' => '参数错误');
}
if(!$clue['recommend_id']){
return array('code' => 0, 'msg' => '该订单不存在分销');
}
//该线索是否存在分销
if($this->ci->mdDealLog->get(['ex_id'=>$clue['id'],'status>='=>0])){
return array('code' => 0, 'msg' => '该线索已存在分销记录');
}
$where = [
'brand_id' => $order['brand_id'],
's_id' => $order['s_id'],
'v_id' => $order['v_id'],
'status' => 1
];
$car = $this->ci->auto_cars_model->get($where);
$car = $this->app_licheb_brokerage_model->get(['biz_id'=>$order['biz_id']],'brokerage_1,brokerage_2');
if(!$car){
$where = [
'brand_id' => $order['brand_id'],
's_id' => $order['s_id'],
'v_id' => $order['v_id'],
'status' => 1
];
$car = $this->ci->auto_cars_model->get($where,'brokerage_1,brokerage_2');
}
if(!$car['brokerage_1'] && !$car['brokerage_2']){
return array('code' => 0, 'msg' => '该车辆未设置分销佣金');
}
@@ -31,7 +31,9 @@ class Customers_entity
*/
public function add_log_visit($customer_id, $uid, $uname, $content, $type = '', $visit = 0, $imgs = [], $cf_platform = 'wxapp')
{
$result = $this->add_log($customer_id, $uid, $uname, $content, $type, $cf_platform, $imgs);
if($content){
$result = $this->add_log($customer_id, $uid, $uname, $content, $type, $cf_platform, $imgs);
}
if ($visit && $result) {//更新客户已回访
$this->ci->load->model('receiver/receiver_customers_visit_model', 'mdCustomersVisit');
$result = $this->ci->mdCustomersVisit->update(array('contact' => 2, 'status' => 2)
@@ -0,0 +1,19 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Created by Vim.
* User: lcc
* Date: 2021/06/23
* Time: 16:24
*/
class App_licheb_brokerage_model extends HD_Model
{
private $table_name = 'lc_app_licheb_brokerage';
public function __construct()
{
parent::__construct($this->table_name, 'default');
}
}
@@ -72,7 +72,7 @@ class Receiver_clues_model extends HD_Model
return $this->db->get()->result_array();
}
public function selectClues($where = array(), $order = '', $page = 0, $page_size = 20, $count = 0){
public function selectClues($where = array(), $order = '', $page = 0, $page_size = 20, $count = 0 ,$fileds = ''){
$this->db->from('lc_receiver_clues');
$this->db->join('lc_receiver_orders', 'lc_receiver_orders.clue_id = lc_receiver_clues.id and lc_receiver_orders.status>=0', 'left');
@@ -84,7 +84,11 @@ class Receiver_clues_model extends HD_Model
$this->db->distinct()->select('lc_receiver_clues.*');
return $this->db->count_all_results();
}else{
$this->db->select('lc_receiver_clues.*,lc_receiver_orders.id as o_id');
if($fileds){
$this->db->select($fileds);
}else{
$this->db->select('lc_receiver_clues.*,lc_receiver_orders.id as o_id');
}
$this->db->group_by('lc_receiver_clues.id');
}
+17
View File
@@ -23,3 +23,20 @@ create table lc_app_licheb_users (
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='狸车宝用户表';
alter table lc_app_licheb_users add column jsondata json default null comment '其他信息' after biz_id;
alter table lc_app_licheb_users modify biz_id varchar(200) not null default 0 comment '门店id多个用逗号隔开(1,2,3)';
-- ----------------------------
-- Title:商家订单分佣配置
-- Author:lcc
-- Table:lc_app_licheb_brokerage
-- ---------------------------
drop table if exists lc_app_licheb_brokerage;
create table lc_app_licheb_brokerage (
id int(10) not null auto_increment comment '自增id',
biz_id varchar(50) not null default '' comment '商家id',
brokerage_1 decimal(12,2) not null default 0.00 comment '一级佣金',
brokerage_2 decimal(12,2) not null default 0.00 comment '二级佣金',
status tinyint(1) not null default 0 comment '状态(1正常 0禁用 -1删除)',
c_time int(10) not null default 0 comment '创建时间',
u_time timestamp not null default current_timestamp on update current_timestamp comment '更新时间',
primary key (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='商家订单分佣配置';