2023-03-21 15:50:55 +08:00

155 lines
4.4 KiB
PHP

<?php
namespace app\admin\controller\nk;
use app\admin\BaseController;
use think\exception\ValidateException;
use think\facade\Db;
use app\admin\controller\nk\Article;
use think\facade\View;
use app\admin\model\ShopUser;
use app\admin\model\InformationUserMsg;
use app\admin\model\InformationUserAddress;
use app\admin\model\SupplyBrokerage as SupplyBrokerageModel;
/**
* 佣金管理
*
* @icon fa fa-circle-o
*/
class Spread extends BaseController
{
public function __construct()
{
$this->adminInfo = get_login_admin();
$this->category_id=309;
$this->url=[
'/admin/nk.spread/index',
'/admin/nk.spread/read',
];
}
/**
* 查看
*/
public function index()
{
$total = 0;
$list = [];
$mmm = [];
$map = [];
$post = get_params();
//权限组信息
if ($this->adminInfo['group_access'] != 1) {
$find = InformationUserAddress::where('admin_id', $this->adminInfo['id'])->find();
if ($find) {
if ($find['auth_range'] == 1) {
$mmm['area_id'] = $find['area_id'];
$mmm['street_id'] = $find['street_id'];
$mmm['village_id'] = $find['village_id'];
} elseif ($find['auth_range'] == 2) {
$mmm['area_id'] = $find['area_id'];
$mmm['street_id'] = $find['street_id'];
}elseif ($find['auth_range'] == 5) {
$mmm['area_id'] = $find['area_id'];
$mmm['street_id'] = $find['street_id'];
$mmm['village_id'] = $find['village_id'];
$mmm['brigade_id'] = $find['brigade_id'];
}
}
}
if ($post) {
if (isset($post['area_id']) && !empty($post['area_id'])) {
$mmm['area_id'] = $post['area_id'];
}
if (isset($post['street_id']) && !empty($post['street_id'])) {
$mmm['street_id'] = $post['street_id'];
}
if (isset($post['village_id']) && !empty($post['village_id'])) {
$mmm['village_id'] = $post['village_id'];
}
if (isset($post['brigade_id']) && !empty($post['brigade_id'])) {
$mmm['brigade_id'] = $post['brigade_id'];
}
}
if (request()->isAjax()) {
if (!empty($post['keywords'])) {
$map[] = ['m.name', 'LIKE', '%' . $post['keywords'] . '%'];
}
if (!empty($post['phone'])) {
$map[] = ['m.phone', 'LIKE', '%' . $post['phone'] . '%'];
}
// 获取当前地域成员
$userList = InformationUserMsg::where($mmm)
->where($map)
->with(['user'])
->select();
$arrUid = [];
foreach ($userList as $v) {
// 如果存在服务小组的话,则取出
if($v['user']['fa_supply_team_id'])
{
$arrUid[] = $v['user']['uid'];
}
}
$params= get_params();
$list = SupplyBrokerageModel::whereIn('user_id', $arrUid)
->with(['user', 'merchant', 'supplyChain', 'level'])
->page($params['page'])
->limit($params['limit'])
->select();
$result = ['total' => $total, 'data' => $list];
return table_assign(0, '', $result);
}
// 获取当前地域成员
$userList = InformationUserMsg::where($mmm)
->where($map)
->with(['user'])
->select();
$arrUid = [];
foreach ($userList as $v) {
// 如果存在服务小组的话,则取出
if($v['user']['fa_supply_team_id'])
{
$arrUid[] = $v['user']['uid'];
}
}
// 总佣金
$borkerageSum = SupplyBrokerageModel::whereIn('user_id', $arrUid)->sum('brokerage_price');
View::assign('brokerage_price', $borkerageSum);
return view('',['url' => $this->url]);
}
/**
* 查看信息
*/
public function read()
{
$params = get_params();
return view('',['url'=>$this->url]);
}
}