You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
232 lines
4.4 KiB
232 lines
4.4 KiB
2 months ago
|
<?php
|
||
|
namespace app\massage\model;
|
||
|
|
||
|
use app\BaseModel;
|
||
|
use think\facade\Db;
|
||
|
|
||
|
class Salesman extends BaseModel
|
||
|
{
|
||
|
//定义表名
|
||
|
protected $name = 'massage_salesman_list';
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
/**
|
||
|
* @author chenniang
|
||
|
* @DataTime: 2020-09-29 11:04
|
||
|
* @功能说明:添加
|
||
|
*/
|
||
|
public function dataAdd($data){
|
||
|
|
||
|
$data['create_time'] = time();
|
||
|
|
||
|
$res = $this->insert($data);
|
||
|
|
||
|
return $res;
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
/**
|
||
|
* @author chenniang
|
||
|
* @DataTime: 2020-09-29 11:05
|
||
|
* @功能说明:编辑
|
||
|
*/
|
||
|
public function dataUpdate($dis,$data){
|
||
|
|
||
|
$res = $this->where($dis)->update($data);
|
||
|
|
||
|
return $res;
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* @author chenniang
|
||
|
* @DataTime: 2020-09-29 11:06
|
||
|
* @功能说明:列表
|
||
|
*/
|
||
|
public function dataList($dis,$page){
|
||
|
|
||
|
$data = $this->where($dis)->order('status desc,id desc')->paginate($page)->toArray();
|
||
|
|
||
|
return $data;
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* @author chenniang
|
||
|
* @DataTime: 2020-09-29 11:43
|
||
|
* @功能说明:
|
||
|
*/
|
||
|
public function dataInfo($dis){
|
||
|
|
||
|
$data = $this->where($dis)->find();
|
||
|
|
||
|
return !empty($data)?$data->toArray():[];
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* @author chenniang
|
||
|
* @DataTime: 2023-04-21 11:13
|
||
|
* @功能说明:后台业务员列表
|
||
|
*/
|
||
|
public function adminDataList($dis,$mapor,$page=10){
|
||
|
|
||
|
$data = $this->alias('a')
|
||
|
->join('massage_service_user_list b','a.user_id = b.id','left')
|
||
|
->where($dis)
|
||
|
->where(function ($query) use ($mapor) {
|
||
|
$query->whereOr($mapor);
|
||
|
})
|
||
|
->field('a.*,b.nickName,b.avatarUrl')
|
||
|
->group('a.id')
|
||
|
->order('id desc')
|
||
|
->paginate($page)
|
||
|
->toArray();
|
||
|
|
||
|
if(!empty($data['data'])){
|
||
|
|
||
|
$admin_model = new Admin();
|
||
|
|
||
|
foreach ($data['data'] as &$v){
|
||
|
|
||
|
$v['admin_name'] = $admin_model->where(['id'=>$v['admin_id'],'status'=>1])->value('agent_name');
|
||
|
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return $data;
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* @author chenniang
|
||
|
* @DataTime: 2023-04-27 15:32
|
||
|
* @功能说明:业务员相关的订单金额
|
||
|
*/
|
||
|
public function salesmanOrderPrice($salesman_id,$channel_id=0,$type=1){
|
||
|
|
||
|
$order_model = new Order();
|
||
|
|
||
|
$dis = [
|
||
|
|
||
|
'pay_type' => 7,
|
||
|
|
||
|
'salesman_id' => $salesman_id,
|
||
|
|
||
|
// 'have_tx' => 1,
|
||
|
];
|
||
|
|
||
|
if(!empty($channel_id)){
|
||
|
|
||
|
$dis['channel_id'] = $channel_id;
|
||
|
}
|
||
|
|
||
|
if($type==1){
|
||
|
|
||
|
$price = $order_model->where($dis)->sum('true_service_price');
|
||
|
|
||
|
return round($price,2);
|
||
|
|
||
|
}else{
|
||
|
|
||
|
$order_id = $order_model->where($dis)->column('id');
|
||
|
|
||
|
return $order_id;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* @author chenniang
|
||
|
* @DataTime: 2023-04-28 10:47
|
||
|
* @功能说明:业务员渠道商佣金
|
||
|
*/
|
||
|
public function getSalesmanChannelCash($salesman_id,$channel_id){
|
||
|
|
||
|
$order_id = $this->salesmanOrderPrice($salesman_id,$channel_id,2);
|
||
|
|
||
|
$comm_model = new Commission();
|
||
|
|
||
|
$dis = [
|
||
|
|
||
|
'type' => 12,
|
||
|
|
||
|
'status' => 2
|
||
|
];
|
||
|
|
||
|
$cash = $comm_model->where('order_id','in',$order_id)->where($dis)->sum('cash');
|
||
|
|
||
|
return round($cash,2);
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* @author chenniang
|
||
|
* @DataTime: 2023-04-27 15:55
|
||
|
* @功能说明:获取业务员历史订单的渠道商
|
||
|
*/
|
||
|
public function getSalesmanCash($salesman_id){
|
||
|
|
||
|
$comm_model = new Commission();
|
||
|
|
||
|
$dis = [
|
||
|
|
||
|
'top_id' => $salesman_id,
|
||
|
|
||
|
'status' => 2,
|
||
|
|
||
|
'type' => 12
|
||
|
];
|
||
|
|
||
|
$cash = $comm_model->where($dis)->sum('cash');
|
||
|
|
||
|
return round($cash,2);
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* @param $data
|
||
|
* @功能说明:获取业务员审核结果
|
||
|
* @author chenniang
|
||
|
* @DataTime: 2023-05-06 16:28
|
||
|
*/
|
||
|
public function checkAuthData($data){
|
||
|
|
||
|
$cap_dis[] = ['user_id','=',$data['id']];
|
||
|
|
||
|
$cap_dis[] = ['status','in',[1,2,3,4]];
|
||
|
//查看是否是团长
|
||
|
$cap_info = $this->where($cap_dis)->order('id desc')->find();
|
||
|
|
||
|
$cap_info = !empty($cap_info)?$cap_info->toArray():[];
|
||
|
//-1表示未申请,1申请中,2已通过,3取消,4拒绝
|
||
|
$arr['salesman_status'] = !empty($cap_info)?$cap_info['status']:-1;
|
||
|
|
||
|
$arr['salesman_sh_text'] = !empty($cap_info)?$cap_info['sh_text']:'';
|
||
|
|
||
|
return $arr;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
}
|