王总上门按摩后台代码
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.
 
 
 
 
 

329 lines
7.4 KiB

<?php
namespace app\massage\controller;
use app\ApiRest;
use app\massage\model\BalanceWater;
use app\massage\model\ChannelList;
use app\massage\model\Coach;
use app\massage\model\Commission;
use app\massage\model\Config;
use app\massage\model\Goods;
use app\massage\model\Order;
use app\massage\model\OrderGoods;
use app\massage\model\Police;
use app\massage\model\RefundOrder;
use app\massage\model\RefundOrderGoods;
use app\massage\model\User;
use app\massage\model\Wallet;
use longbingcore\wxcore\WxSetting;
use think\App;
use think\facade\Db;
use think\Request;
class IndexChannel extends ApiRest
{
protected $model;
protected $channel_info;
protected $order_model;
protected $user_model;
public function __construct(App $app) {
parent::__construct($app);
$this->model = new ChannelList();
$this->order_model = new Order();
$this->user_model = new User();
$cap_dis[] = ['user_id','=',$this->getUserId()];
$cap_dis[] = ['status','in',[2,3]];
$this->channel_info = $this->model->dataInfo($cap_dis);
if(empty($this->channel_info)){
$this->errorMsg('你还不是渠道商');
}
}
/**
* @author chenniang
* @DataTime: 2021-07-08 11:39
* @功能说明:技师首页
*/
public function index(){
$this->order_model->coachBalanceArr($this->_uniacid);
$input = $this->_param;
$data = $this->channel_info;
$order_data = $this->order_model->channelData($this->channel_info['id'],$input);
$data = array_merge($order_data,$data);
//税点
$data['tax_point'] = getConfigSetting($this->_uniacid,'tax_point');
return $this->success($data);
}
/**
* @author chenniang
* @DataTime: 2022-08-30 14:18
* @功能说明:渠道码
*/
public function channelQr(){
$input = $this->_param;
$key = 'channel_qr'.$this->channel_info['id'].'-'.$this->is_app;
$qr = getCache($key,$this->_uniacid);
if(empty($qr)){
//小程序
if($this->is_app==0){
//$input['page'] = 'pages/service';
$input['page'] = 'user/pages';
$input['channel_id'] = $this->channel_info['id'];
//获取二维码
$qr = $this->user_model->orderQr($input,$this->_uniacid);
}else{
// $page = 'https://'.$_SERVER['HTTP_HOST'].'/h5/#/pages/service?channel_id='.$this->channel_info['id'];
$page = 'https://'.$_SERVER['HTTP_HOST'].'/h5/#/user/pages/gzh?channel_id='.$this->channel_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);
}
/**
* @author chenniang
* @DataTime: 2022-08-30 14:34
* @功能说明:订单列表
*/
public function orderList(){
$input = $this->_param;
$dis[] = ['a.uniacid','=',$this->_uniacid];
$dis[] = ['a.pay_type','>',1];
$dis[] = ['a.channel_id','=',$this->channel_info['id']];
if(!empty($input['start_time'])&&!empty($input['end_time'])){
$dis[] = ['a.create_time','between',"{$input['start_time']},{$input['end_time']}"];
}
$where = [];
if(!empty($input['name'])){
$where[] = ['b.goods_name','like','%'.$input['name'].'%'];
$where[] = ['a.order_code','like','%'.$input['name'].'%'];
}
$data = $this->order_model->indexDataList($dis,$where);
if(!empty($data['data'])){
$refund_model = new RefundOrder();
$com_model = new Commission();
foreach ($data['data'] as &$v){
$v['refund_price'] = $refund_model->where(['order_id'=>$v['id'],'status'=>2])->sum('service_price');
//渠道商佣金
$v['channel_cash'] = $com_model->where(['order_id'=>$v['id'],'type'=>10])->where('status','>',-1)->value('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->channel_info['cash']) {
$this->errorMsg('余额不足');
}
//获取税点
$tax_point = getConfigSetting($this->_uniacid,'tax_point');
$balance = 100 - $tax_point;
$key = 'channel_wallet' . $this->getUserId();
//加一个锁防止重复提交
incCache($key, 1, $this->_uniacid);
$value = getCache($key,$this->_uniacid);
if ($value!=1) {
decCache($key,1, $this->_uniacid);
$this->errorMsg('网络错误,请刷新重试');
}
Db::startTrans();
//减佣金
$res = $this->model->dataUpdate(['id' => $this->channel_info['id']], ['cash' => $this->channel_info['cash'] - $input['apply_price']]);
if ($res != 1) {
Db::rollback();
//减掉
decCache($key, $this->_uniacid);
$this->errorMsg('申请失败');
}
$insert = [
'uniacid' => $this->_uniacid,
'user_id' => $this->getUserId(),
'coach_id' => $this->channel_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' => 5,
'apply_transfer' => !empty($input['apply_transfer'])?$input['apply_transfer']:0
];
$wallet_model = new Wallet();
//提交审核
$res = $wallet_model->dataAdd($insert);
if ($res != 1) {
Db::rollback();
//减掉
decCache($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->channel_info['id']
];
if (!empty($input['status'])) {
$dis['status'] = $input['status'];
}
$dis['type'] = 5;
//提现记录
$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->channel_info['id'], 2, 5);
return $this->success($data);
}
}