jh-admin/addon/saas/api/controller/Region.php

185 lines
6.7 KiB
PHP

<?php
namespace addon\saas\api\controller;
use addon\saas\model\RegionAccount;
use addon\saas\model\RegionManage;
use addon\saas\model\RegionOrder;
use addon\saas\model\RegionWithdraw;
use app\api\controller\BaseApi;
class Region extends BaseApi
{
/**
* 获取分销商信息
*/
public function detail()
{
$token = $this->checkToken();
if ($token[ 'code' ] < 0) return $this->response($token);
$condition = [
[ 'f.member_id', '=', $this->member_id ],
[ 'f.is_delete', '=', 1]
];
$model = new RegionManage();
$info = $model->getManageInfo($condition);
if (!empty($info[ 'data' ])) {
if ($info['data']['status'] == 0) return $this->response($this->error('', '账号被冻结,请联系管理员'));
$where = [
['manage_id', '=', $info['data']['id']],
['site_id', '=' , $this->site_id],
['member_id' , '=' , $this->member_id],
];
$a_where = [
['status', '=' , 1],
];
//提现中
$withdarw = model('region_withdraw')->getSum(array_merge($where,$a_where), 'money');
//已提现金额
$b_where = [
['status', '=' , 2],
];
$account = model('region_withdraw')->getSum(array_merge($where,$b_where), 'money');
//结算中金额
$c_where = [
['is_settlement' , '=' , 0]
];
$settlement = model('region_order')->getSum(array_merge($where,$c_where), 'commission');
$info['data']['withdraw'] = $withdarw;
$info['data']['stop_account'] = $account;
$info['data']['settlement'] = $settlement;
return $this->response($info);
}else{
return $this->error([],'经理不存在');
}
}
/**
* 列表
*/
public function order()
{
$token = $this->checkToken();
if ($token['code'] < 0) return $this->response($token);
$model = new RegionManage();
$condition = [
[ 'f.member_id', '=', $this->member_id ],
[ 'f.is_delete', '=', 1]
];
$info = $model->getManageInfo($condition);
if (empty($info['data'])) return $this->response($this->error('', '经理不存在'));
if (!empty($info['data']) && $info['data']['status'] == 0) return $this->response($this->error('', '账号被冻结,请联系管理员'));
$page = isset($this->params['page']) ? $this->params['page'] : 1;
$page_size = isset($this->params['page_size']) ? $this->params['page_size'] : PAGE_LIST_ROWS;
$is_settlement = isset($this->params['is_settlement']) ? $this->params['is_settlement'] : 0;// 结算状态 0 全部 1 待结算 2 已结算 3 已退款
$condition = [
['manage_id', '=', $info['data']['id']],
['site_id', '=' ,$this->site_id],
];
if (!empty($is_settlement)) {
if ($is_settlement == 3) {
$condition[] = ['is_refund', '=', 1];
}
if (in_array($is_settlement, [1, 2])) {
$condition[] = ['is_settlement', '=', $is_settlement - 1];
$condition[] = ['is_refund', '=', 0];
}
}
$order_model = new RegionOrder();
$list = $order_model->getOrderPageList($condition, $page, $page_size, 'id desc');
return $this->response($list);
}
/**
* 提现记录分页
* @return false|string
*/
public function withdraw()
{
$token = $this->checkToken();
if ($token['code'] < 0) return $this->response($token);
$page = isset($this->params['page']) ? $this->params['page'] : 1;
$page_size = isset($this->params['page_size']) ? $this->params['page_size'] : PAGE_LIST_ROWS;
$status = isset($this->params['status']) ? $this->params['status'] : 0;// 当前状态 1待审核 2待转账 3已转账 -1 已拒绝
$condition = [
['member_id', '=', $this->member_id]
];
if (!empty($status)) {
$condition[] = ['status', '=', $status];
}
$order = 'id desc';
$withdraw_model = new RegionWithdraw();
$list = $withdraw_model->getWithdrawPageList($condition, $page, $page_size, $order);
return $this->response($list);
}
/**
* 流水分页
* @return false|string
*/
public function account()
{
$token = $this->checkToken();
if ($token['code'] < 0) return $this->response($token);
$model = new RegionManage();
$condition = [
[ 'f.member_id', '=', $this->member_id ],
[ 'f.is_delete', '=', 1]
];
$info = $model->getManageInfo($condition);
if (empty($info['data'])) return $this->response($this->error('', '经理不存在'));
if (!empty($info['data']) && $info['data']['status'] == 0) return $this->response($this->error('', '账号被冻结,请联系管理员'));
$page = isset($this->params['page']) ? $this->params['page'] : 1;
$page_size = isset($this->params['page_size']) ? $this->params['page_size'] : PAGE_LIST_ROWS;
$condition = [
['manage_id', '=', $info['data']['id']],
];
$account_model = new RegionAccount();
$list = $account_model->getAccountPageList($condition, $page, $page_size);
return $this->response($list);
}
/**
* 申请提现
* @return mixed
*/
public function withdraw_apply()
{
$token = $this->checkToken();
if ($token[ 'code' ] < 0) return $this->response($token);
$apply_money = $this->params[ 'apply_money' ] ?? 0;
$transfer_type = $this->params[ 'transfer_type' ] ?? '';//提现方式
$realname = $this->params[ 'realname' ] ?? '';//真实姓名
$bank_name = $this->params[ 'bank_name' ] ?? '';//银行名称
$account_number = $this->params[ 'account_number' ] ?? '';//账号名称
$mobile = $this->params[ 'mobile' ] ?? '';//手机号
$app_type = $this->params[ 'app_type' ];
$fenxiao_withdraw_model = new RegionWithdraw();
$data = array (
'member_id' => $this->member_id,
'transfer_type' => $transfer_type,
'realname' => $realname,
'bank_name' => $bank_name,
'account_number' => $account_number,
'apply_money' => $apply_money,
'mobile' => $mobile,
'app_type' => $app_type
);
$result = $fenxiao_withdraw_model->apply($data, $this->site_id, 'shop');
return $this->response($result);
}
}