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.
393 lines
8.5 KiB
393 lines
8.5 KiB
<?php
|
|
namespace app\massage\controller;
|
|
use app\AdminRest;
|
|
use app\ApiRest;
|
|
use app\massage\model\ChannelList;
|
|
use app\massage\model\City;
|
|
use app\massage\model\Coach;
|
|
use app\massage\model\CoachLevel;
|
|
use app\massage\model\Commission;
|
|
use app\massage\model\Config;
|
|
use app\massage\model\DistributionList;
|
|
use app\massage\model\Order;
|
|
use app\massage\model\Salesman;
|
|
use app\massage\model\User;
|
|
use app\massage\model\Wallet;
|
|
use longbingcore\wxcore\YsCloudApi;
|
|
use think\App;
|
|
use think\facade\Db;
|
|
|
|
|
|
class IndexSalesman extends ApiRest
|
|
{
|
|
|
|
|
|
protected $model;
|
|
|
|
protected $user_model;
|
|
|
|
protected $cash_model;
|
|
|
|
protected $wallet_model;
|
|
|
|
protected $coach_model;
|
|
|
|
protected $salesman_info;
|
|
|
|
|
|
public function __construct(App $app) {
|
|
|
|
parent::__construct($app);
|
|
|
|
$this->model = new Salesman();
|
|
|
|
$this->user_model = new User();
|
|
|
|
$this->cash_model = new Commission();
|
|
|
|
$this->wallet_model = new Wallet();
|
|
|
|
$this->coach_model = new Coach();
|
|
|
|
$this->salesman_info = $this->salesmanDataInfo();
|
|
|
|
if(empty($this->salesman_info)){
|
|
|
|
$this->errorMsg('你还不是业务员');
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2023-04-26 14:39
|
|
* @功能说明:业务员详情
|
|
*/
|
|
public function salesmanDataInfo(){
|
|
|
|
$cap_dis[] = ['user_id', '=', $this->getUserId()];
|
|
|
|
$cap_dis[] = ['status', 'in', [2,3]];
|
|
|
|
$data = $this->model->dataInfo($cap_dis);
|
|
|
|
return $data;
|
|
}
|
|
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2023-03-23 13:49
|
|
* @功能说明:业务员中心
|
|
*/
|
|
public function index(){
|
|
|
|
$data = $this->salesman_info;
|
|
|
|
$user_model = new User();
|
|
|
|
$wallet_model = new Wallet();
|
|
|
|
$data['avatarUrl'] = $user_model->where(['id'=>$this->salesman_info['user_id']])->value('avatarUrl');
|
|
//累计提现
|
|
$data['wallet_cash'] = $wallet_model->where(['coach_id'=>$this->salesman_info['id']])->where('status','in',[1,2])->sum('total_price');
|
|
//总成交金额
|
|
$data['order_price'] = $this->model->salesmanOrderPrice($this->salesman_info['id']);
|
|
|
|
$data['wallet_cash'] = round($data['wallet_cash'],2);
|
|
|
|
return $this->success($data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2023-03-23 14:30
|
|
* @功能说明:业务渠道商佣金记录
|
|
*/
|
|
public function salesmanChannelCash(){
|
|
|
|
$channel_model = new ChannelList();
|
|
|
|
$dis[] = ['salesman_id','=',$this->salesman_info['id']];
|
|
|
|
$dis[] = ['status','in',[2,3]];
|
|
|
|
$channel_list = $channel_model->dataList($dis,10,'user_name,id');
|
|
|
|
if(!empty($channel_list['data'])){
|
|
|
|
foreach ($channel_list['data'] as &$value){
|
|
//订单金额
|
|
$value['order_price'] = $this->model->salesmanOrderPrice($this->salesman_info['id'],$value['id']);
|
|
//佣金
|
|
$value['salesman_cash'] = $this->model->getSalesmanChannelCash($this->salesman_info['id'],$value['id']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->success($channel_list);
|
|
}
|
|
|
|
|
|
/**\
|
|
* @author chenniang
|
|
* @DataTime: 2023-04-28 10:54
|
|
* @功能说明:业务员渠道商明细
|
|
*/
|
|
public function salesmanChannelOrderList(){
|
|
|
|
$input = $this->_param;
|
|
|
|
$dis[] = ['pay_type','=',7];
|
|
|
|
$dis[] = ['salesman_id','=',$this->salesman_info['id']];
|
|
|
|
$dis[] = ['channel_id','=',$input['channel_id']];
|
|
|
|
if(!empty($input['start_time'])&&!empty($input['end_time'])){
|
|
|
|
$dis[] = ['can_tx_date','between',"{$input['start_time']},{$input['end_time']}"];
|
|
}
|
|
|
|
$order_model = new Order();
|
|
|
|
$commis_model= new Commission();
|
|
|
|
$data = $order_model->where($dis)->order('id desc')->field('order_code,can_tx_date,id')->paginate(10)->toArray();
|
|
|
|
if(!empty($data['data'])){
|
|
|
|
foreach ($data['data'] as &$v){
|
|
|
|
$v['can_tx_date'] = date('Y-m-d H:i:s',$v['can_tx_date']);
|
|
|
|
$dis = [
|
|
|
|
'status' => 2,
|
|
|
|
'type' => 12,
|
|
|
|
'order_id'=> $v['id']
|
|
];
|
|
|
|
$v['salesman_cash'] = $commis_model->where($dis)->sum('cash');
|
|
|
|
}
|
|
}
|
|
|
|
return $this->success($data);
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2021-03-24 13:33
|
|
* @功能说明:渠道商申请提现
|
|
*/
|
|
public function applyWallet()
|
|
{
|
|
|
|
$input = $this->_input;
|
|
|
|
if (empty($input['apply_price']) || $input['apply_price'] < 0.01) {
|
|
|
|
$this->errorMsg('提现费最低一分');
|
|
}
|
|
|
|
if ($input['apply_price'] > $this->salesman_info['cash']) {
|
|
|
|
$this->errorMsg('余额不足');
|
|
}
|
|
//获取税点
|
|
$tax_point = getConfigSetting($this->_uniacid,'tax_point');
|
|
|
|
$balance = 100 - $tax_point;
|
|
|
|
$key = 'salesman_wallet' . $this->getUserId();
|
|
//加一个锁防止重复提交
|
|
incCache($key, 1, $this->_uniacid);
|
|
|
|
$value = getCache($key,$this->_uniacid);
|
|
|
|
if ($value!=1) {
|
|
|
|
delCache($key,1, $this->_uniacid);
|
|
|
|
$this->errorMsg('网络错误,请刷新重试');
|
|
|
|
}
|
|
|
|
Db::startTrans();
|
|
//减佣金
|
|
$res = $this->model->dataUpdate(['id' => $this->salesman_info['id']], ['cash' => $this->salesman_info['cash'] - $input['apply_price']]);
|
|
|
|
if ($res != 1) {
|
|
|
|
Db::rollback();
|
|
//减掉
|
|
delCache($key, $this->_uniacid);
|
|
|
|
$this->errorMsg('申请失败');
|
|
}
|
|
|
|
$insert = [
|
|
|
|
'uniacid' => $this->_uniacid,
|
|
|
|
'user_id' => $this->getUserId(),
|
|
|
|
'coach_id' => $this->salesman_info['id'],
|
|
|
|
'admin_id' => 0,
|
|
|
|
'total_price' => $input['apply_price'],
|
|
|
|
'balance' => $balance,
|
|
|
|
'apply_price' => round($input['apply_price'] * $balance / 100, 2),
|
|
|
|
'service_price' => round( $input['apply_price'] * $tax_point / 100, 2),
|
|
|
|
'code' => orderCode(),
|
|
|
|
'tax_point' => $tax_point,
|
|
|
|
'text' => $input['text'],
|
|
|
|
'type' => 6,
|
|
|
|
'apply_transfer' => !empty($input['apply_transfer'])?$input['apply_transfer']:0
|
|
|
|
];
|
|
|
|
$wallet_model = new Wallet();
|
|
//提交审核
|
|
$res = $wallet_model->dataAdd($insert);
|
|
|
|
if ($res != 1) {
|
|
|
|
Db::rollback();
|
|
//减掉
|
|
delCache($key, $this->_uniacid);
|
|
|
|
$this->errorMsg('申请失败');
|
|
}
|
|
|
|
Db::commit();
|
|
//减掉
|
|
decCache($key,1, $this->_uniacid);
|
|
|
|
return $this->success($res);
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2021-03-30 14:39
|
|
* @功能说明:渠道商提现记录
|
|
*/
|
|
public function walletList()
|
|
{
|
|
|
|
$wallet_model = new Wallet();
|
|
|
|
$input = $this->_param;
|
|
|
|
$dis = [
|
|
|
|
'coach_id' => $this->salesman_info['id']
|
|
];
|
|
|
|
if (!empty($input['status'])) {
|
|
|
|
$dis['status'] = $input['status'];
|
|
}
|
|
|
|
$dis['type'] = 6;
|
|
//提现记录
|
|
$data = $wallet_model->dataList($dis, 10);
|
|
|
|
if (!empty($data['data'])) {
|
|
|
|
foreach ($data['data'] as &$v) {
|
|
|
|
$v['create_time'] = date('Y-m-d H:i:s', $v['create_time']);
|
|
}
|
|
}
|
|
//累计提现
|
|
$data['extract_total_price'] = $wallet_model->capCash($this->salesman_info['id'], 2, 6);
|
|
|
|
return $this->success($data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2022-08-30 14:18
|
|
* @功能说明:业务员码
|
|
*/
|
|
public function salesmanQr(){
|
|
|
|
$input = $this->_param;
|
|
|
|
$key = 'salesman'.$this->salesman_info['id'].'-'.$this->is_app;
|
|
|
|
$qr = getCache($key,$this->_uniacid);
|
|
|
|
if(empty($qr)){
|
|
//小程序
|
|
if($this->is_app==0){
|
|
|
|
$input['page'] = 'user/pages/channel/apply';
|
|
|
|
$input['salesman_id'] = $this->salesman_info['id'];
|
|
//获取二维码
|
|
$qr = $this->user_model->orderQr($input,$this->_uniacid);
|
|
|
|
}else{
|
|
|
|
$page = 'https://'.$_SERVER['HTTP_HOST'].'/h5/#/user/pages/channel/apply?salesman_id='.$this->salesman_info['id'];
|
|
|
|
$qr = base64ToPng(getCode($this->_uniacid,$page));
|
|
|
|
}
|
|
|
|
setCache($key,$qr,86400,$this->_uniacid);
|
|
}
|
|
|
|
$qr = !empty($qr)?$qr:'https://'.$_SERVER['HTTP_HOST'].'/favicon.ico';
|
|
|
|
return $this->success($qr);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|