2023-03-21 16:41:13 +08:00

937 lines
42 KiB
PHP

<?php
namespace app\admin\controller\nk;
use app\admin\BaseController;
use think\facade\View;
use think\facade\Db;
use app\admin\model\ShopUser;
use app\admin\model\InformationUserMsg;
use app\admin\model\InformationUserAddress;
/**
* 文章
*
* @icon fa fa-circle-o
*/
class User extends BaseController
{
public function __construct()
{
$this->adminInfo = get_login_admin();
$this->category_id = 305;
$this->url = [
'/admin/nk.user/index?category_id=' . $this->category_id,
'/admin/nk.user/add',
'/admin/nk.user/edit',
'/admin/nk.user/del',
'/admin/nk.user/read',
'/admin/nk.user/auths',
'/admin/nk.user/postedit',
];
}
/**
* 查看
*/
public function index()
{
if (request()->isAjax()) {
$mmm = [];
$map = [];
$post = get_params();
if (!empty($post['keywords'])) {
$map[] = ['m.name', 'LIKE', '%' . $post['keywords'] . '%'];
}
if (!empty($post['phone'])) {
$map[] = ['m.phone', 'LIKE', '%' . $post['phone'] . '%'];
}
//权限组信息
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'];
}
}
//权限组信息
$total = InformationUserMsg::alias('m')
->where($mmm)
->where($map)
->where('user_id', '<>', $this->adminInfo['user_id'])
->count();
$list = InformationUserMsg::alias('m')
->where($mmm)
->where($map)
->where('user_id', '<>', $this->adminInfo['user_id'])
// ->join(['shop.eb_user' => 'u'], 'm.user_id=u.uid')u.avatar,u.group_id,u.status,
->with(['user.userGroup'])
// ->field('m.user_id id,m.name,m.phone,m.gender,m.age,m.householder_id,m.user_id')
->withAttr('count', function ($value, $data) {
if ($data['householder_id']) {
$count = InformationUserMsg::where('householder_id', $data['householder_id'])->count();
} else {
$count = '未绑定户主无法查询';
}
return $count;
})
->withAttr('gender', function ($value, $data) {
if ($value == 1) {
return '男';
} elseif ($value == 2) {
return '女';
}
})
->order('id DESC')
->page($post['page'])
->limit($post['limit'])
->select();
$result = ['total' => $total, 'data' => $list];
return table_assign(0, '', $result);
}
//权限组信息
if ($this->adminInfo['group_access'] != 1) { //不是超级管理员
$www['admin_id'] = $this->adminInfo['id'];
$user_address = Db::table('fa_szxc_information_useraddress')->where($www)->find();
if ($user_address) {
if ($user_address['auth_range'] <=3 &&$user_address['auth_range'] >=1 ) {
$select = Db::table('fa_geo_area')->where('city_code', '510500')->where('area_code', $user_address['area_id'])->select();
} else {
$select = Db::table('fa_geo_area')->where('city_code', '510500')->select();
}
View::assign('row', $user_address);
} else {
$user_address['area_id'] = '';
$user_address['street_id'] = '';
$user_address['village_id'] = '';
$user_address['auth_range'] = '1';
$select = Db::table('fa_geo_area')->where('city_code', '510500')->select();
View::assign('row', $user_address);
}
$is_admin = 0;
} else {
$user_address['area_id'] = '';
$user_address['street_id'] = '';
$user_address['village_id'] = '';
$user_address['auth_range'] = '';
$select = Db::table('fa_geo_area')->where('city_code', '510500')->select();
View::assign('row', $user_address);
$is_admin = 1;
}
View::assign('arealist', $select);
View::assign('is_admin', $is_admin);
View::assign('url', $this->url);
return view();
}
/**
* 添加
*/
public function add()
{
if (request()->isAjax()) {
$params = get_params();
$params['category_id'] = $this->category_id;
(new Article())->add($params);
} else {
View::assign('editor', get_system_config('other', 'editor'));
View::assign('url', $this->url);
return view('nk/article/add');
}
}
/**
* 修改
*/
public function edit()
{
$params = get_params();
$find = Db::table('fa_szxc_information_usermsg')
->where('user_id', $params['id'])->find();
//获取所有分类
$www2[] = ['type', 'in', ['Nation', 'Education', 'Occupation', 'Zzmm', 'Family', 'Nature_of_land', 'Blood_type', 'Drug_allergy', 'Exposure_history', 'History_of_disease', 'Whether_disabled', 'Cfpfss', 'Fuel_type', 'Drinking_water', 'Toilet_msg', 'Poultry_corral', 'Insurance_type', 'House', 'Car', 'Grade', 'Insurance', 'Medical_insurance_type', 'FamilyHistory', 'Marriage']];
$all_category = Db::table('fa_category')->where($www2)->field('id,type,name,pid')->select();
//种植信息
$planting = Db::table('fa_szxc_information_planting')->where('user_id', $params['id'])
->find();
//保险信息
$insurancearr = Db::table('fa_szxc_information_insurance')->where('user_id', $params['id'])->find();
//健康信息
$healthyarr = Db::table('fa_szxc_information_healthy')->where('user_id', $params['id'])->find();
if ($planting == null) {
$planting = [
"tools_msg" => "",
"crops_msg" => "",
"land_area" => "",
"is_wz" => '',
"nature_of_land" => "",
];
}else{
$strlen = strlen($planting['breed_msg']);
if ($strlen != 0 || $strlen > 10) {
$planting['breed_msg'] = json_decode($planting['breed_msg'], true);
}
$strlen1 = strlen($planting['crops_msg']);
if ($strlen1 != 0 || $strlen1 > 10) {
$planting['crops_msg'] = json_decode($planting['crops_msg'], true);
}
$strlen2 = strlen($planting['tools_msg']);
if ($strlen2 != 0 || $strlen2 > 10) {
$planting['tools_msg'] = json_decode($planting['tools_msg'], true);
}
}
if ($insurancearr == null) {
$insurancearr = [
"endowment_insurance_status" => "",
"is_subsidy" => "",
"insurance_reason" => "",
"medical_insurance_type" => "",
"whether_disabled" => "",
"disability_num" => "",
"disability_type" => "",
"disability_level" => "",
"insurance_type" => "",
"ny_insurance" => "",
"sy_insurance" => "",
];
}
if ($healthyarr == null) {
$healthyarr = [
"medical_insurance_type" => "",
"insurance_type" => "",
"blood_type" => "",
"drug_allergy" => "",
"exposure_history" => "",
"history_of_disease" => "",
"history_of_surgery" => "",
"family_history" => "",
"familial_diseases" => "",
"genetic_history" => "",
"genetic_name" => "",
"whether_disabled" => "",
"cfpfss" => "",
"fuel_type" => "",
"drinking_water" => "",
"toilet_msg" => "",
"poultry_corral" => "",
];
}
View::assign('user_id', $params['id']);
View::assign('healthyarr', $healthyarr);
View::assign('insurancearr', $insurancearr);
View::assign('planting', $planting);
View::assign('all_category', $all_category);
View::assign('user', $find);
View::assign('url', $this->url);
View::assign('editor', get_system_config('other', 'editor'));
return view();
}
/**
* 提交修改
*/
public function postedit()
{
$params = get_params();
// halt($params);
if ($params['type'] == 1) {
unset($params['type']);
$res = Db::table('fa_szxc_information_usermsg')->where('user_id', $params['user_id'])->update($params);
if ($res) {
return to_assign(0, '操作成功');
} else {
return to_assign(1, '操作失败');
}
}
if ($params['type'] == 2) {
$params['crops_msg'] = json_encode($params['crops_msg']);
unset($params['type']);
$find = Db::table('fa_szxc_information_planting')->where('user_id', $params['user_id'])->find();
if ($find) {
$res = Db::table('fa_szxc_information_planting')->where('id', $find['id'])->update($params);
$id = $find['id'];
} else {
$res = Db::table('fa_szxc_information_planting')->where('user_id', $params['user_id'])->insertGetId($params);
$id = $res;
}
if ($res) {
$time = time();
// 新增写入种植表
Db::table('fa_szxc_planting')->where('user_id',$params['user_id'])->delete();
$mianji = 0;
if($params['crops_msg']){
$crops_msg_arr = json_decode($params['crops_msg'],1);
foreach ($crops_msg_arr as $k=>$v){
// 根据名字查询分类
if($v['name']){
$type = Db::table('fa_szxc_planting_type')->where('name',$v['name'])->find();
if($type){
$planting_data['type_id'] = $type['id'];
}else{
$type_data['name'] = $v['name'];
$type_data['createtime'] = $time;
$type_id = Db::table('fa_szxc_planting_type')->strict(false)->insertGetId($type_data);
$planting_data['type_id'] = $type_id;
}
$planting_data['user_id'] = $params['user_id'];
$planting_data['num'] = $v['num']??0;
$planting_data['measure'] = $v['mianji']??0;
$planting_data['createtime'] = $time;
Db::table('fa_szxc_planting')->strict(false)->insertGetId($planting_data);
}
// 计算面积
if($v['mianji']){
$mianji += $v['mianji'];
}
}
}
// 新增写入养殖表
Db::table('fa_szxc_breed')->where('user_id',$params['user_id'])->delete();
// $mianji = 0;
if(isset($params['breed_msg']) && !empty($params['breed_msg'])){
$breed_msg_arr = json_decode($params['breed_msg'],1);
foreach ($breed_msg_arr as $k=>$v){
// 根据名字查询分类
if($v['name']){
$type = Db::table('fa_szxc_breed_type')->where('name',$v['name'])->find();
if($type){
$breed_data['type_id'] = $type['id'];
}else{
$type_data['name'] = $v['name'];
$type_data['createtime'] = $time;
$type_id = Db::table('fa_szxc_breed_type')->strict(false)->insertGetId($type_data);
$breed_data['type_id'] = $type_id;
}
$breed_data['user_id'] = $params['user_id'];
$breed_data['num'] = $v['num']??0;
$breed_data['measure'] = $v['mianji']??0;
$breed_data['createtime'] = $time;
Db::table('fa_szxc_breed')->strict(false)->insertGetId($breed_data);
}
}
}
$waste_land_area = $params['land_area'] - $mianji;
if($waste_land_area < 0){
$waste_land_area = 0;
}
$ddd['waste_land_area'] = $waste_land_area;
Db::table('fa_szxc_information_planting')->where('id', $id)->update($ddd);
return to_assign(0, '操作成功');
} else {
return to_assign(1, '操作失败');
}
}
if ($params['type'] == 3) {
unset($params['type']);
$find = Db::table('fa_szxc_information_insurance')->where('user_id', $params['user_id'])->find();
if ($find) {
$res = Db::table('fa_szxc_information_insurance')->where('id', $find['id'])->update($params);
} else {
$res = Db::table('fa_szxc_information_insurance')->where('user_id', $params['user_id'])->insert($params);
}
if ($res) {
return to_assign(0, '操作成功');
} else {
return to_assign(1, '操作失败');
}
}
if ($params['type'] == 4) {
unset($params['type']);
$find = Db::table('fa_szxc_information_healthy')->where('user_id', $params['user_id'])->find();
if ($find) {
$res = Db::table('fa_szxc_information_healthy')->where('id', $find['id'])->update($params);
} else {
$res = Db::table('fa_szxc_information_healthy')->where('user_id', $params['user_id'])->insert($params);
}
if ($res) {
return to_assign(0, '操作成功');
} else {
return to_assign(1, '操作失败');
}
}
}
/**
* 查看信息
*/
public function read()
{
$params = get_params();
$find = Db::table('fa_szxc_information_usermsg')
->withAttr('gender', function ($value, $data) {
if ($value == 1) {
return '男';
}
return '女';
})->withAttr('education', function ($value, $data) {
return Db::table('fa_category')->where('id', $value)->value('name');
})->withAttr('nation', function ($value, $data) {
return Db::table('fa_category')->where('id', $value)->value('name');
})->withAttr('political_outlook', function ($value, $data) {
return Db::table('fa_category')->where('id', $value)->value('name');
})->withAttr('house_msg', function ($value, $data) {
return Db::table('fa_category')->where('id', $value)->value('name');
})->withAttr('car_msg', function ($value, $data) {
return Db::table('fa_category')->where('id', $value)->value('name');
})->withAttr('marital_status', function ($value, $data) {
return Db::table('fa_category')->where('id', $value)->value('name');
})
->where('user_id', $params['id'])->find();
//家庭信息
//用户id
$user_id = $params['id'];
// 获取户主id
$f_where[] = ['user_ids','find in set',$user_id];
$family_arr = Db::table('fa_szxc_family')->where($f_where)->find();
if ($family_arr) {
$map[] = ['user_id','in',$family_arr['user_ids']];
} else {
$where['user_id'] = $user_id;
$where['status'] = 1;
$householder_id = Db::table('fa_szxc_information_usermsg')->where($where)->value('householder_id');
if ($householder_id) {
$map[] = ['householder_id','=',$householder_id];
$map[] = ['status','=',1];
} else {
$map[] = ['user_id','=',$user_id];
$map[] = ['status','=',1];
}
}
// 获取家庭的人员信息
$family['list'] = Db::table('fa_szxc_information_usermsg')->where($map)
->order('id desc')
->field("id,user_id,name,age,gender,family_num,political_outlook,householder_id,is_hz,address_name,family_relation,phone")
->withAttr('avatar', function ($value, $data) {
return ShopUser::where('uid', $data['user_id'])->value('avatar');
})
->select()->toArray();
if ($find['householder_id'] == $find['user_id']) {
$family['name'] = '本人';
} else {
$family['name'] = Db::table('fa_szxc_information_usermsg')->where('user_id', $find['householder_id'])->value('name');
$family['relation'] = Db::table('fa_category')->where('id', $find['family_relation'])->value('name');
}
// if ($find == null || $find['householder_id'] == 0) {
// $family['list'] = [];
// } else {
// if ($find['householder_id'] == $find['user_id']) {
// $family['name'] = '本人';
// } else {
// $family['name'] = Db::table('fa_szxc_information_usermsg')->where('user_id', $find['householder_id'])->value('name');
// $family['relation'] = Db::table('fa_category')->where('id', $find['family_relation'])->value('name');
// }
// $family['list'] = Db::table('fa_szxc_information_usermsg')->where('householder_id', $find['householder_id'])->where('user_id', '<>', $find['householder_id'])->field('user_id,name,age,gender,phone')->select();
// }
//种植信息
if ($find || $find['householder_id'] == $params['id']) {
$Planting['is'] = 1;
$Planting['list'] = [];
$finds = Db::table('fa_szxc_information_planting')->where('user_id', $params['id'])
->withAttr('crops_msg', function ($value, $data) {
return json_decode($value, true);
})
->withAttr('breed_msg', function ($value, $data) {
return json_decode($value, true);
})
->withAttr('tools_msg', function ($value, $data) {
return json_decode($value, true);
})
->withAttr('nature_of_land', function ($value, $data) {
return Db::table('fa_category')->where('id', $value)->value('name');
})
->withAttr('is_wz', function ($value, $data) {
return $value == 0 ? '否' : '是';
})
->find();
if ($find) {
$Planting['list'] = $finds;
}
} else {
$Planting['is'] = 0;
}
$insurancearr = Db::table('fa_szxc_information_insurance')
->withAttr('endowment_insurance_status', function ($value, $data) {
return Db::table('fa_category')->where('id', $value)->value('name');
})->withAttr('insurance_type', function ($value, $data) {
return Db::table('fa_category')->where('id', $value)->value('name');
})->withAttr('whether_disabled', function ($value, $data) {
return Db::table('fa_category')->where('id', $value)->value('name');
})->withAttr('disability_level', function ($value, $data) {
return Db::table('fa_category')->where('id', $value)->value('name');
})->withAttr('ny_insurance', function ($value, $data) {
return Db::table('fa_category')->where('id', $value)->value('name');
})->withAttr('sy_insurance', function ($value, $data) {
return Db::table('fa_category')->where('id', $value)->value('name');
})
->where('user_id', $params['id'])->find();
$healthyarr = Db::table('fa_szxc_information_healthy')
->withAttr('blood_type', function ($value, $data) {
return Db::table('fa_category')->where('id', $value)->value('name');
})->withAttr('drug_allergy', function ($value, $data) {
return Db::table('fa_category')->where('id', $value)->value('name');
})->withAttr('exposure_history', function ($value, $data) {
return Db::table('fa_category')->where('id', $value)->value('name');
})->withAttr('history_of_disease', function ($value, $data) {
return Db::table('fa_category')->where('id', $value)->value('name');
})->withAttr('history_of_surgery', function ($value, $data) {
return Db::table('fa_category')->where('id', $value)->value('name');
})->withAttr('family_history', function ($value, $data) {
return Db::table('fa_category')->where('id', $value)->value('name');
})->withAttr('familial_diseases', function ($value, $data) {
return Db::table('fa_category')->where('id', $value)->value('name');
})->withAttr('genetic_history', function ($value, $data) {
return Db::table('fa_category')->where('id', $value)->value('name');
})->withAttr('cfpfss', function ($value, $data) {
return Db::table('fa_category')->where('id', $value)->value('name');
})->withAttr('fuel_type', function ($value, $data) {
return Db::table('fa_category')->where('id', $value)->value('name');
})->withAttr('drinking_water', function ($value, $data) {
return Db::table('fa_category')->where('id', $value)->value('name');
})->withAttr('toilet_msg', function ($value, $data) {
return Db::table('fa_category')->where('id', $value)->value('name');
})->withAttr('poultry_corral', function ($value, $data) {
return Db::table('fa_category')->where('id', $value)->value('name');
})->withAttr('genetic_name', function ($value, $data) {
return Db::table('fa_category')->where('id', $value)->value('name');
})
->where('user_id', $params['id'])->find();
View::assign('id', $params['id']);
View::assign('read', $find);
View::assign('family', $family);
View::assign('planting', $Planting);
View::assign('insurancearr', $insurancearr);
View::assign('healthyarr', $healthyarr);
return view();
}
public function auths()
{
$params = get_params();
if (request()->isPost()) {
$admin = Db::name('Admin')->where('user_id', $params['id'])->find();
$user = Db::connect('shop')->table('eb_user')->where('uid', $params['id'])->find();
if ($params['village_id'] != '') {
$village = Db::table('fa_geo_village')->where('village_code', $params['village_id'])->find();
}
// 组装地址名
if ($params['area_id'] != '') {
$area_name = Db::table('fa_geo_area')->where('area_code', $params['area_id'])->value('area_name');
}
if ($params['street_id'] != '') {
$street_name = Db::table('fa_geo_street')->where('street_code', $params['street_id'])->value('street_name');
}
if ($params['brigade_id'] != '') {
$brigade_name = Db::table('fa_geo_brigade')->where('id', $params['brigade_id'])->value('brigade_name');
}
$address_name = $area_name . $street_name . $village['village_name'] . $brigade_name;
// $useraddress = [
// 'area_id' => $params['area_id'],
// 'street_id' => $params['street_id'],
// 'village_code' => $params['village_id'],
// 'brigade_id' => $params['brigade_id'],
// 'auth_range' => $params['auth_range'],
// 'village_id' => $params['village_id'] != '' ? $village['village_id'] : 0,
// 'admin_id' => $admin['id'],
// ];
$phone = Db::table('fa_szxc_information_usermsg')->where('user_id', $params['id'])->value('phone');
// 如果为工作人员 == 服务小组采购人员
if($params['group_id'] == 3)
{
Db::connect('shop')->table('eb_user')->where('phone', $phone)->update(['fa_supply_team_id' => 1]); // 默认分佣比例 1 为小组服务
}else{
Db::connect('shop')->table('eb_user')->where('phone', $phone)->update(['fa_supply_team_id' => null]); // 如果不是工作人员,则去除分佣
}
if ($admin) {
Db::startTrans();
try {
if ($params['groupdata'] == 0) {
Db::name('admin_group_access')->where('uid', $admin['id'])->delete();
Db::name('Admin')->where('id', $admin['id'])->update(['status' => 0]);
} else {
$is_have_admin = Db::name('admin_group_access')->where('uid', $admin['id'])->find();
if ($is_have_admin) {
Db::name('admin_group_access')->where('uid', $admin['id'])->update(['group_id' => $params['groupdata']]);
} else {
$group_access2 = ['uid' => $admin['id'], 'group_id' => $params['groupdata']];
//写入权限组
Db::name('admin_group_access')->insert($group_access2);
}
Db::name('Admin')->where('id', $admin['id'])->update(['status' => 1]);
}
$useraddress = [
'area_id' => $params['area_id'],
'street_id' => $params['street_id'],
'village_code' => $params['village_id'],
'brigade_id' => $params['brigade_id'],
'auth_range' => $params['auth_range'],
'village_id' => $params['village_id'] != '' ? $village['village_id'] : 0,
'admin_id' => $admin['id'],
];
Db::table('fa_szxc_information_useraddress')->where('user_id', $params['id'])->update($useraddress);
// 修改user表
$ddd['is_admin'] = 1;
$ddd['group_id'] = $params['group_id'];
Db::connect('shop')->table('eb_user')->where('uid',$params['id'])->update($ddd);
// 修改用户详细地址
$u_msg['address_name'] = $address_name;
$u_msg['area_id'] = $params['area_id'];
$u_msg['street_id'] = $params['street_id'];
$u_msg['village_id'] = $params['village_id'] != '' ? $village['village_id'] : 0;
$u_msg['brigade_id'] = $params['brigade_id'];
Db::table('fa_szxc_information_usermsg')->where('user_id', $params['id'])->update($u_msg);
// 提交事务
Db::commit();
} catch (\Exception $e) {
// 回滚事务
Db::rollback();
return to_assign(1, '操作失败,原因:' . $e->getMessage());
}
return to_assign(0, '操作成功');
} else {
$salt = set_salt(20);
$data = [
'user_id' => $params['id'],
// 'username' => $user['mobile'], // --- 原来的废弃
'username' => $phone,
'nickname' => $user['nickname'],
'thumb' => $user['avatar'],
// 'mobile' => $user['mobile'], // --- 原来的废弃
'mobile' => $phone,
'did' => 1,
'position_id' => 3,
'salt' => $salt,
'pwd' => set_password(123456, $salt),
'email' => '',
];
Db::startTrans();
try {
$w['user_id'] = $params['id'];
// $is_have = Db::table('fa_szxc_information_useraddress')->where($w)->find();
// 创建管理员账号
$admin_id = Db::name('Admin')->insertGetId($data);
// 写入权限组
Db::name('AdminGroupAccess')->strict(false)->field(true)->insert([
'uid' => $admin_id,
'group_id' => $params['groupdata'],
]);
add_log('add', $this->adminInfo['id'], $params);
// Db::table('fa_auth_group_access')->insert($group_access);
// 修改user表
$ddd['is_admin'] = 1;
$ddd['group_id'] = $params['group_id'];
Db::connect('shop')->table('eb_user')->where('uid',$params['id'])->update($ddd);
// Db::table('fa_user')->where('id', $params['id'])->update($ddd);
// 修改商城关系表
// $nk_user['n_user_id'] = $params['id'];
// $is_nk_user = Db::connect('shop')->name('nk_user')->where($nk_user)->find();
$address=Db::table('fa_szxc_information_useraddress')->where($w)->find();
if ($address) {
$useraddress = [
'user_id' => $params['id'],
'admin_id' => $admin_id,
'area_id' => $params['area_id'],
'street_id' => $params['street_id'],
'village_code' => $params['village_id'],
'village_id' => $village['village_id'],
'brigade_id' => $params['brigade_id'],
'auth_range' => $params['auth_range'],
];
Db::table('fa_szxc_information_useraddress')->where($w)->update($useraddress);
// if ($is_nk_user) {
// $useraddress['group_id'] = $params['group_id'];
// unset($useraddress['user_id'],$useraddress['admin_id'],$useraddress['auth_range']);
// Db::connect('shop')->name('nk_user')->where($nk_user)->update($useraddress);
// }
} else {
$useraddress = [
'user_id' => $params['id'],
'admin_id' => $admin_id,
'area_id' => $params['area_id'],
'street_id' => $params['street_id'],
'village_code' => $params['village_id'],
'village_id' => $village['village_id'],
'brigade_id' => $params['brigade_id'],
'auth_range' => $params['auth_range'],
'createtime' => date('Y-m-d H:i:s')
];
Db::table('fa_szxc_information_useraddress')->insert($useraddress);
}
// 修改用户详细地址
$u_msg['address_name'] = $address_name;
$u_msg['area_id'] = $params['area_id'];
$u_msg['street_id'] = $params['street_id'];
$u_msg['village_id'] = $params['village_id'] != '' ? $village['village_id'] : 0;
$u_msg['brigade_id'] = $params['brigade_id'];
Db::table('fa_szxc_information_usermsg')->where('user_id', $params['id'])->update($u_msg);
// 提交事务
Db::commit();
} catch (\Exception $e) {
// 回滚事务
Db::rollback();
return to_assign(1, '操作失败,原因:' . $e->getMessage());
}
return to_assign(0, '操作成功');
}
}
// $user = Db::connect('shop')->table('eb_user')->where('uid', )->->find();
$user = ShopUser::field('uid id,nickname,group_id')->find($params['id']);
// $geo_brigade = Db::table('fa_geo_brigade')->select();
$useraddress = [
'area_id' => 0,
'street_id' => 0,
'village_id' => 0,
'village_code' => 0,
'brigade_id' => 0,
'admin_group' => 0,
'auth_range' => 1,
];
$address = InformationUserAddress::where('user_id', $params['id'])->find();
if ($address) {
$useraddress['area_id'] = $address['area_id'];
$useraddress['street_id'] = $address['street_id'];
$useraddress['village_id'] = $address['village_id'];
$useraddress['brigade_id'] = $address['brigade_id'];
$useraddress['village_code'] = $address['village_code'];
$useraddress['auth_range'] = $address['auth_range'];
$admin = Db::name('admin_group_access')->where('uid', $address['admin_id'])->find();
if ($admin) {
$useraddress['admin_group'] = $admin['group_id'];
}
}
//权限组信息
$groupwhereAdmin[] = ['id', '<>', 1];
$groupwhereWeb[] = ['group_id', '<>', 1];
if ($this->adminInfo['group_access'] != 1) { //不是超级管理员
// $www['admin_id'] = $this->adminInfo['id'];
// $user_address = Db::table('fa_szxc_information_useraddress')->where($www)->find();
// if ($user_address) {
if ($this->adminInfo['group_access'] == 2) {
$auth_range = [
['name' => '村级', 'value' => '1'],
];
// $groupwhere[] = ['id', '=', 2];
$groupwhereAdmin[] = ['id', '=', 3];
$groupwhereWeb[] = ['group_id', '=', 3];
}
if ($this->adminInfo['group_access'] == 4) {
$auth_range = [
['name' => '村级', 'value' => '1'],
['name' => '乡镇', 'value' => '2']
];
$groupwhere['id'] = [ '=',[2,4]];
}
// if ($user_address['auth_range'] == 3) {
// $auth_range = [['name' => '村级', 'value' => '1'], ['name' => '乡镇', 'value' => '2'], ['name' => '区县', 'value' => '3']];
// }
// if ($user_address['auth_range'] == 4) {
// $auth_range = [['name' => '村级', 'value' => '1'], ['name' => '乡镇', 'value' => '2'], ['name' => '区县', 'value' => '3'], ['name' => '市级', 'value' => '4']];
// }
// }
} else {
$auth_range = [
['name' => '小组', 'value' => '5'],
['name' => '村级', 'value' => '1'],
['name' => '乡镇', 'value' => '2'],
['name' => '区县', 'value' => '3'],
['name' => '市级', 'value' => '4']
];
}
// 区县
$street = Db::table('fa_geo_area')->where([
'switch' => 1,
'city_code' => '510500'
])
->field('area_id id,area_code code,area_name name')
->select();
//
$brigade = Db::table('fa_geo_brigade')
->limit(30)
->select();
//后端权限
$groupdata = Db::name('admin_group')
->where($groupwhereAdmin)
->limit(30)
->select();
$groupdata[] = ['id' => 0, 'title' => '无后台权限'];
//前端权限
$user_group = Db::connect('shop')
->table('eb_user_group')
->where($groupwhereWeb)
->limit(30)
->select();
$user_group[] = ['group_id' => 0, 'group_name' => '无前端权限'];
View::assign('id', $params['id']);
View::assign('user_group', $user_group);
View::assign('groupdata', $groupdata);
View::assign('street', $street);
View::assign('brigade', $brigade);
View::assign('auth_range', $auth_range);
View::assign('user', $user);
View::assign('address', $useraddress);
View::assign('url', $this->url);
View::assign('editor', get_system_config('other', 'editor'));
return view();
}
public function tongji()
{
$post = get_params();
$where = [];
//权限组信息
$find = Db::table('fa_szxc_information_useraddress')->where('user_id', $this->adminInfo['user_id'])->find();
if ($find) {
if ($find['auth_range'] == 1) {
$mmm['area_id'] = $find['area_id'];
$mmm['street_id'] = $find['street_id'];
} elseif ($find['auth_range'] == 2) {
$mmm['area_id'] = $find['area_id'];
}
}
if (!empty($post['village_id'])) {
$where['village_id'] = $post['village_id'];
}
if (!empty($post['brigade_id'])) {
$where['brigade_id'] = $post['brigade_id'];
}
if (!empty($post['street_id'])) {
$where['street_id'] = $post['street_id'];
}
$where['area_id'] = $post['area_id'];
// 大于60岁人数
$old_num = Db::table('fa_szxc_information_usermsg')->where($where)->whereAge('>=', 60)->count();
// 儿童人数
$children_num = Db::table('fa_szxc_information_usermsg')->where($where)->whereAge('<', 15)->count();
// 未婚男
$unmarried_man_num = Db::table('fa_szxc_information_usermsg')->where($where)->where([['gender', '=', 1], ['marital_status', '=', 169]])->count();
// 未婚女
$unmarried_woman_num = Db::table('fa_szxc_information_usermsg')->where($where)->where([['gender', '=', 2], ['marital_status', '=', 169]])->count();
$land_area_num = Db::table('fa_szxc_information_useraddress')
->alias('u')
->where($where)
->join(['fa_szxc_information_planting'=>'p'], 'u.user_id = p.user_id')->sum('p.land_area');
$sum_218 = Db::table('fa_szxc_information_useraddress')
->alias('u')
->where($where)
->join(['fa_szxc_information_planting'=>'p'], 'u.user_id = p.user_id and p.nature_of_land=218')->sum('p.land_area');
$sum_217 = Db::table('fa_szxc_information_useraddress')
->alias('u')
->where($where)
->join(['fa_szxc_information_planting'=>'p'], 'u.user_id = p.user_id and p.nature_of_land=217')->sum('p.land_area');
$sum_216 = Db::table('fa_szxc_information_useraddress')
->alias('u')
->where($where)
->join(['fa_szxc_information_planting'=>'p'], 'u.user_id = p.user_id and p.nature_of_land=216')->sum('p.land_area');
$sum_215 = Db::table('fa_szxc_information_useraddress')
->alias('u')
->where($where)
->join(['fa_szxc_information_planting'=>'p'], 'u.user_id = p.user_id and p.nature_of_land=215')->sum('p.land_area');
$sum_214 = Db::table('fa_szxc_information_useraddress')
->alias('u')
->where($where)
->join(['fa_szxc_information_planting'=>'p'], 'u.user_id = p.user_id and p.nature_of_land=214')->sum('p.land_area');
$sum_70 = Db::table('fa_szxc_information_useraddress')
->alias('u')
->where($where)
->join(['fa_szxc_information_planting'=>'p'], 'u.user_id = p.user_id and p.nature_of_land=70')->sum('p.land_area');
$sum_69 = Db::table('fa_szxc_information_useraddress')
->alias('u')
->where($where)
->join(['fa_szxc_information_planting'=>'p'], 'u.user_id = p.user_id and p.nature_of_land=69')->sum('p.land_area');
$result = [
'old_num' => $old_num,
'children_num' => $children_num,
'unmarried_man_num' => $unmarried_man_num,
'unmarried_woman_num' => $unmarried_woman_num,
'land_area_num' => $land_area_num,
'sum_218' => $sum_218,
'sum_217' => $sum_217,
'sum_216' => $sum_216,
'sum_215' => $sum_215,
'sum_214' => $sum_214,
'sum_70' => $sum_70,
'sum_69' => $sum_69,
];
$result = ['total' => 0, 'data' => $result];
return table_assign(0, '', $result);
}
/**
* 修改
*/
public function del()
{
$params = get_params();
(new Article())->del($params);
}
}