Merge branch 'monanxiao'

This commit is contained in:
monanxiao 2023-03-18 17:14:08 +08:00
commit 3b920cc5d6
13 changed files with 260 additions and 109 deletions

View File

@ -44,8 +44,16 @@ class Index extends BaseController
public function main() public function main()
{ {
$street_id=Db::table('fa_szxc_information_useraddress')->where('admin_id',$this->adminInfo['id'])->value('street_id'); // return json($this->adminInfo);
$street_name=Db::table('fa_geo_street')->where('street_code',$street_id)->value('street_name'); $street_id = Db::table('fa_szxc_information_useraddress')
->where('admin_id',$this->adminInfo['id'])
->value('street_id');
// return $street_id;
$street_name = Db::table('fa_geo_street')
->where('street_code',$street_id)
->value('street_name');
if ($this->adminInfo['group_access']==4){ if ($this->adminInfo['group_access']==4){
$urls="http://zhen.lihaink.cn/#/?street_id=$street_id"."&street_name=".$street_name; $urls="http://zhen.lihaink.cn/#/?street_id=$street_id"."&street_name=".$street_name;
View::assign('urls',$urls); View::assign('urls',$urls);

View File

@ -20,6 +20,7 @@ use app\admin\model\GeoCity;
use app\admin\model\GeoArea; use app\admin\model\GeoArea;
use app\admin\model\GeoStreet; use app\admin\model\GeoStreet;
use app\admin\model\GeoVillage; use app\admin\model\GeoVillage;
use app\admin\model\ShopUser;
class SupplyTeam extends BaseController class SupplyTeam extends BaseController
@ -41,7 +42,7 @@ class SupplyTeam extends BaseController
$param = get_params(); $param = get_params();
$where = []; $where = [];
$list = $this->model->with(['level', 'user'])->select(); $list = $this->model->with(['level', 'user', 'userMsg'])->select();
$total = $this->model->count(); $total = $this->model->count();
// $list = $this->model->getSupplyTeamList($where,$param); // $list = $this->model->getSupplyTeamList($where,$param);
foreach ($list as $k =>$v){ foreach ($list as $k =>$v){
@ -91,7 +92,8 @@ class SupplyTeam extends BaseController
return to_assign(1, $e->getError()); return to_assign(1, $e->getError());
} }
$userAdmin = Db::table('fa_szxc_information_useraddress')->where('admin_id', $param['user_id'])->find(); $userAdmin = Db::table('fa_szxc_information_useraddress')->where('user_id', $param['user_id'])->find();
$parent_code = ''; $parent_code = '';
// 验证用户级别,获取对应的区域代码 // 验证用户级别,获取对应的区域代码
@ -118,7 +120,7 @@ class SupplyTeam extends BaseController
$param['parent_code'] = $parent_code; // 所属区域代码 $param['parent_code'] = $parent_code; // 所属区域代码
$this->model->addSupplyTeam($param); $this->model->addSupplyTeam($param);
}else{ }else{
$geo_area = Db::table('fa_geo_area')->where('city_code',510500)->select(); $geo_area = Db::table('fa_geo_area')->where('city_code',510500)->select();
View::assign('geo_area', $geo_area); View::assign('geo_area', $geo_area);
@ -126,15 +128,9 @@ class SupplyTeam extends BaseController
View::assign('level', $level); View::assign('level', $level);
//获取用户信息 //获取用户信息
$this->users = Db::table('fa_szxc_information_useraddress') $usersList = ShopUser::with(['userAddress', 'userMsg'])->select();
->alias('a')
->where('a.status',1) View::assign('users', $usersList);
->whereNotIn('a.id', [1])
->leftJoin ('nk_lihaink_cn.cms_admin b', 'a.admin_id = b.id')
->field('b.id, b.username, b.nickname, a.admin_id, a.street_id, a.area_id, a.village_id, a.village_code, a.brigade_id')
->select();
View::assign('users', $this->users);
return view(); return view();
} }
} }

View File

@ -0,0 +1,22 @@
<?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/Apache-2.0
* @link https://www.gougucms.com
*/
namespace app\admin\model;
use think\facade\Db;
use think\model;
/**
*
* 用户关联居住信息表
*
*/
class InformationUserAddress extends Model
{
// 设置当前模型对应的完整数据表名称
protected $table = 'fa_szxc_information_useraddress';
}

View File

@ -0,0 +1,22 @@
<?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/Apache-2.0
* @link https://www.gougucms.com
*/
namespace app\admin\model;
use think\facade\Db;
use think\model;
/**
*
* 用户关联居住信息表
*
*/
class InformationUserMsg extends Model
{
// 设置当前模型对应的完整数据表名称
protected $table = 'fa_szxc_information_usermsg';
}

View File

@ -22,4 +22,23 @@ class ShopUser extends Model
protected $table = 'eb_user'; protected $table = 'eb_user';
protected $pk = 'uid'; protected $pk = 'uid';
/**
*
* 用户地址信息
*
*/
public function userAddress()
{
return $this->hasOne(InformationUserAddress::class, 'user_id', 'uid');
}
/**
*
* 用户家庭信息
*
*/
public function userMsg()
{
return $this->hasOne(InformationUserMsg::class, 'user_id', 'uid');
}
} }

View File

@ -7,6 +7,7 @@
namespace app\admin\model; namespace app\admin\model;
use think\model; use think\model;
use app\common\model\User; use app\common\model\User;
use app\admin\model\ShopUser;
class SupplyTeam extends Model class SupplyTeam extends Model
{ {
@ -30,7 +31,17 @@ class SupplyTeam extends Model
*/ */
public function user() public function user()
{ {
return $this->hasOne(User::class, 'id', 'user_id'); return $this->hasOne(ShopUser::class, 'uid', 'user_id');
}
/**
*
* 用户家庭信息
*
*/
public function userMsg()
{
return $this->hasOne(InformationUserMsg::class, 'user_id', 'user_id');
} }
/** /**
@ -55,15 +66,16 @@ class SupplyTeam extends Model
*/ */
public function addSupplyTeam($param) public function addSupplyTeam($param)
{ {
$insertId = 0; $insertId = 0;
try { try {
$param['create_time'] = time(); $param['create_time'] = time();
$insertId = self::strict(false)->field(true)->insertGetId($param); $insertId = self::strict(false)->field(true)->insertGetId($param);
add_log('add', $insertId, $param); ShopUser::where('uid', $param['user_id'])->update([ 'fa_supply_team_id' => $insertId]);
add_log('add', $insertId, $param);
} catch(\Exception $e) { } catch(\Exception $e) {
return to_assign(1, '操作失败,原因:'.$e->getMessage()); return to_assign(1, '操作失败,原因:'.$e->getMessage());
} }
return to_assign(0,'操作成功',['aid'=>$insertId]); return to_assign(0,'操作成功',['aid'=>$insertId]);
} }
/** /**

View File

@ -37,7 +37,7 @@
<select name="user_id" lay-verify="required" lay-reqText="供应链后台团队负责人"> <select name="user_id" lay-verify="required" lay-reqText="供应链后台团队负责人">
<option value="">请选择</option> <option value="">请选择</option>
{volist name='users' id='vo'} {volist name='users' id='vo'}
<option value="{$vo.id}" >{$vo.username}|{$vo.nickname}</option> <option value="{$vo.uid}" >{$vo.nickname}---{$vo.userMsg.name}---{$vo.userMsg.phone}</option>
{/volist} {/volist}
</select> </select>
</td> </td>

View File

@ -68,7 +68,7 @@
// width: 100, // width: 100,
templet: function (d) templet: function (d)
{ {
return d.user.nickname + ',手机号:' + d.user.mobile; return d.userMsg.name + ',手机号:' + d.user.phone;
} }
},{ },{
field: 'auth_range', field: 'auth_range',

View File

@ -653,6 +653,7 @@ class Article extends BaseController
$where[] = ['a.user_id','=',$this->request->uid]; $where[] = ['a.user_id','=',$this->request->uid];
$where[] = ['b.is_read','=','0']; $where[] = ['b.is_read','=','0'];
$which = []; $which = [];
//根据个人村id进行查询 //根据个人村id进行查询
if ($this->request->uid) { if ($this->request->uid) {
$find = Db::table('fa_szxc_information_useraddress')->where('user_id', $this->request->uid)->find(); $find = Db::table('fa_szxc_information_useraddress')->where('user_id', $this->request->uid)->find();

View File

@ -1680,6 +1680,7 @@ class Maintainentry extends BaseController
// 获取家庭的人员信息 // 获取家庭的人员信息
$res = Db::table('fa_szxc_information_usermsg')->where($map) $res = Db::table('fa_szxc_information_usermsg')->where($map)
->order('id desc') ->order('id desc')
->order('is_hz desc')
->field("id,user_id,name,age,gender,family_num,political_outlook,householder_id,is_hz,address_name,family_relation,phone") ->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) { ->withAttr('avatar', function ($value, $data) {
return Db::table('fa_user')->where('id', $data['user_id'])->value('avatar'); return Db::table('fa_user')->where('id', $data['user_id'])->value('avatar');

View File

@ -11,6 +11,8 @@ use app\api\BaseController;
use app\api\middleware\Auth; use app\api\middleware\Auth;
use think\facade\Db; use think\facade\Db;
use Firebase\JWT\Key; use Firebase\JWT\Key;
use app\admin\model\ShopUser;
/** /**
* 会员接口. * 会员接口.
*/ */
@ -30,14 +32,20 @@ class User extends BaseController
*/ */
public function index() public function index()
{ {
$user = Db::table('fa_user')->where('id', $this->request->uid)->find(); $user = ShopUser::find($this->request->uid); // 获取用户信息
$user_msg = Db::table('fa_szxc_information_usermsg')->where('user_id', $this->request->uid)->field('id,name,address_name,phone')->find();
// 获取用户关联信息
$user_msg = Db::table('fa_szxc_information_usermsg')
->where('user_id', $this->request->uid)
->field('id,name,address_name,phone')
->find();
$this->apiSuccess('', [ $this->apiSuccess('', [
'nickname' => $user['nickname'], 'nickname' => $user['nickname'],
'phone'=>$user_msg['phone'], 'phone' => $user['phone'],
'avatar'=>$user['avatar'], 'avatar' => $user['avatar'],
'address_name'=>$user_msg['address_name'], 'address_name' => $user_msg['address_name'],
'name'=>$user_msg['name'] 'name' => $user_msg['name']
]); ]);
} }

View File

@ -9,6 +9,7 @@ use think\Exception;
use think\facade\Db; use think\facade\Db;
use think\exception\ValidateException; use think\exception\ValidateException;
use think\facade\Request; use think\facade\Request;
use app\admin\model\ShopUser;
/** /**
* 用户信息相关接口. * 用户信息相关接口.
@ -101,36 +102,35 @@ class Userinfo extends BaseController
$this->apiError('手机号错误'); $this->apiError('手机号错误');
} }
$where['id'] = $this->request->uid; // $where['id'] = $this->request->uid; // 废弃
$post['user_id'] = $this->request->uid; $post['user_id'] = $this->request->uid;
$user = Db::table('fa_user')->where($where)->field('id,nickname,group_id,mobile,avatar,username,createtime,score')->find();
// 已绑定 $user = ShopUser::where('phone', $post['phone'])->find(); // 通过唯一手机号获取商城用户信息
if ($user) { // $user = Db::table('fa_user')->where($where)->field('id,nickname,group_id,mobile,avatar,username,createtime,score')->find(); // 农科user表废弃
Db::startTrans();
// 已绑定
if ($user) { // 如果用户存在
Db::startTrans(); // 开启事务
try { try {
// 判断手机号是否已经注册
// $is_mobile = Db::table('fa_user')->getByMobile($post['phone']);
// if ($is_mobile) {
// $this->apiError('手机号已被使用');
// }
//判断身份证号是否已被使用 //判断身份证号是否已被使用
$InformationUsermsg = Db::table('fa_szxc_information_usermsg')->where('idcard',$post['idcard'])->field('idcard')->find(); $InformationUsermsg = Db::table('fa_szxc_information_usermsg')
->where('idcard',$post['idcard']) // 身份证号
->field('idcard')
->find();
// 假如身份证号被使用,则报错
if ($InformationUsermsg) { if ($InformationUsermsg) {
$this->apiError('身份证号已被使用'); $this->apiError('身份证号已被使用');
} }
// $validateIDCard = $this->validateIDCard($post['idcard']); // 获取用户user_id
// if($validateIDCard == false){ $userid = $user['uid'];
// $this->apiError('身份证号错误'); // $userid = $post['user_id']; // 原user_id 废弃
// }
// $ip = request()->ip();
// $time =
// $salt = Random::alnum(); //随机字符串
$userid = $post['user_id']; // 组装地址名
// 组装地址名
if ($post['area_id'] != '') { if ($post['area_id'] != '') {
$area_name = Db::table('fa_geo_area')->where('area_code', $post['area_id'])->value('area_name'); $area_name = Db::table('fa_geo_area')->where('area_code', $post['area_id'])->value('area_name');
} }
@ -143,17 +143,13 @@ class Userinfo extends BaseController
if ($post['brigade_id'] != '') { if ($post['brigade_id'] != '') {
$brigade_name = Db::table('fa_geo_brigade')->where('id', $post['brigade_id'])->value('brigade_name'); $brigade_name = Db::table('fa_geo_brigade')->where('id', $post['brigade_id'])->value('brigade_name');
} }
$post['address_name'] = $area_name.$street_name.$village.$brigade_name;
$address_name = $area_name.$street_name.$village.$brigade_name;
// 更新用户表 // 更新用户表
$u_up['nickname'] = $post['name']; $u_up['nickname'] = $post['name']; // 真实姓名-- 待处理
Db::table('fa_user')->where($where)->update($u_up);
// $header = Request::header('x-Token');
// if(isset($header['x-token']) && !empty($header['x-token'])){
// }else{ // Db::table('fa_user')->where($where)->update($u_up); // 废弃的农科user表
// $post['phone'] = $user['mobile']??'';
// }
//写入用户信息表 //写入用户信息表
$data['user_id'] = $userid; $data['user_id'] = $userid;
@ -164,21 +160,26 @@ class Userinfo extends BaseController
$data['marital_status'] = $post['marital_status']; $data['marital_status'] = $post['marital_status'];
$data['phone'] = $post['phone']??''; $data['phone'] = $post['phone']??'';
$data['idcard'] = $post['idcard']; $data['idcard'] = $post['idcard'];
$data['address_name'] = $post['address_name']; $data['address_name'] = $address_name;
$data['createtime'] = time(); $data['createtime'] = time();
$data['street_id'] = $post['street_id']; $data['street_id'] = $post['street_id'];
$data['village_id'] = $post['village_id_id']; $data['village_id'] = $post['village_id_id'];
$data['brigade_id'] = $post['brigade_id']; $data['brigade_id'] = $post['brigade_id'];
$msg=Db::table('fa_szxc_information_usermsg')->where('user_id',$post['user_id'])->find();
if (!$msg){ // 写入用户关联信息表
Db::table('fa_szxc_information_usermsg')->strict(false)->insert($data); $msgExists = Db::table('fa_szxc_information_usermsg')
->where('user_id', $userid)
->find();
// 录入信息
// 判断写入状态
if (!$msgExists){
// 假如没写如果,则增加一条记录
Db::table('fa_szxc_information_usermsg')
->strict(false)
->insert($data);
} }
$fa_user['mobile'] = $post['phone']??'';
$fa_user['nickname'] = $post['name']??'';
Db::table('fa_user')->where($where)->update($fa_user);
// else{
// $this->apiError('请勿重新提交');
// }
//写入用户地区表 //写入用户地区表
$address_data['user_id'] = $userid; $address_data['user_id'] = $userid;
$address_data['area_id'] = $post['area_id']; $address_data['area_id'] = $post['area_id'];
@ -187,57 +188,111 @@ class Userinfo extends BaseController
$address_data['village_code'] = $post['village_id']; $address_data['village_code'] = $post['village_id'];
$address_data['brigade_id'] = $post['brigade_id']; $address_data['brigade_id'] = $post['brigade_id'];
$address_data['createtime'] = date('Y-m-d H:i:s'); $address_data['createtime'] = date('Y-m-d H:i:s');
$add=Db::table('fa_szxc_information_useraddress')->where('user_id',$post['user_id'])->find(); $add = Db::table('fa_szxc_information_useraddress')
->where('user_id', $userid)
->find();
// 判断用户地区写入状态
if (!$add){ if (!$add){
Db::table('fa_szxc_information_useraddress')->strict(false)->insert($address_data); Db::table('fa_szxc_information_useraddress')->strict(false)->insert($address_data);
$eb_nk_user=Db::connect('shop')->table('eb_nk_user')->where('n_user_id',$post['user_id'])->find();
if ($eb_nk_user){ // 商城农科user表被废弃
Db::connect('shop')->table('eb_nk_user')->where('id',$eb_nk_user['id']) // $eb_nk_user = Db::connect('shop')
->update(['area_id'=>$post['area_id'],'street_id'=>$post['street_id'],'village_id'=>$post['village_id_id'],'village_code'=>$post['village_id']]); // ->table('eb_nk_user')
if ($fa_user['nickname']){ // ->where('n_user_id',$post['user_id'])
Db::connect('shop')->table('eb_user')->where('uid',$eb_nk_user['user_id'])->update(['nickname'=>$fa_user['nickname']]); // ->find();
}
} // if ($eb_nk_user){
// 废弃同步更新商城用户表
// Db::connect('shop')->table('eb_nk_user')->where('id',$eb_nk_user['id'])
// ->update(['area_id'=>$post['area_id'],'street_id'=>$post['street_id'],'village_id'=>$post['village_id_id'],'village_code'=>$post['village_id']]);
// 无需更新用户昵称 废弃
// if ($fa_user['nickname']){
// Db::connect('shop')->table('eb_user')->where('uid',$eb_nk_user['user_id'])->update(['nickname'=>$fa_user['nickname']]);
// }
// }
} }
// 新增修改用户推广员id spread_uid // 新增修改用户推广员id spread_uid
// 先获取当前村推官员 // $spread_uid = $userid;
$s_where[] = ['b.village_id','=',$post['village_id_id']];
$s_where[] = ['a.is_promoter','=',1]; // 先获取当前村推官员
$spread_uid = Db::connect('shop')->table('eb_user')->alias('a')->join('eb_nk_user b','a.uid = b.user_id')->where($s_where)->value('a.uid'); $s_where[] = ['b.village_id', '=', $post['village_id_id']];
$s_where[] = ['a.is_promoter', '=', 1];
// 废弃复杂查询uid上一步已获取到
$spread_uid = Db::connect('shop')
->table('eb_user')
->alias('a')
->join('eb_nk_user b','a.uid = b.user_id')
->where($s_where)
->value('a.uid');
// 推广员uid
if($spread_uid){ if($spread_uid){
$eb_nk_user=Db::connect('shop')->table('eb_nk_user')->where('n_user_id',$post['user_id'])->find();
if ($eb_nk_user){ // 更新本用户推广人UID
Db::connect('shop')->table('eb_user')->where('uid',$eb_nk_user['user_id'])->update(['spread_uid'=>$spread_uid,'promoter_time'=>date('Y-m-d H:i:s')]); ShopUser::where('uid', $spread_uid)
Db::connect('shop')->table('eb_user')->where('uid',$spread_uid)->inc('spread_count','1')->update(); ->update([
} 'spread_uid' => $spread_uid,
'promoter_time'=>date('Y-m-d H:i:s')
]);
// 推广员邀请人数增加
ShopUser::where('uid', $spread_uid)
->inc('spread_count','1')
->update();
// -- 废弃复杂更新推荐用户uid
// if ($eb_nk_user){
// Db::connect('shop')->table('eb_user')->where('uid',$eb_nk_user['user_id'])->update(['spread_uid'=>$spread_uid,'promoter_time'=>date('Y-m-d H:i:s')]);
// Db::connect('shop')->table('eb_user')->where('uid',$spread_uid)->inc('spread_count','1')->update();
// }
} }
$Userinfo = $user; $Userinfo = $user;
$Userinfo['user_id'] = $post['user_id']; $Userinfo['user_id'] = $userid;
$userinfo_data['userinfo'] = $Userinfo; // $Userinfo['user_id'] = $post['user_id']; // 临时废弃
$userinfo_data['userinfo'] = $Userinfo;
$find = Db::table('fa_szxc_information_usermsg')
->where('user_id', $userid)
->find();
// $group = Db::connect('shop')->table('eb_user_group')
// ->where('id',$userinfo_data['userinfo']['group_id'])
// ->find();
// $userinfo_data['userinfo']['group_name'] = $group['name'];
if ($find){
$userinfo_data['userinfo']['name'] = $find['name'];
$userinfo_data['userinfo']['no_update'] = 0;
$userinfo_data['userinfo']['address_name'] = $find['address_name'];
}else{
$userinfo_data['userinfo']['no_update'] = 1;
$userinfo_data['userinfo']['address_name'] = '';
}
Db::commit();
$this->apiSuccess('已完善,登录成功', $userinfo_data);
// } else {
// $this->apiError($this->auth->getError());
// }
$find=Db::table('fa_szxc_information_usermsg')->where('user_id',$post['user_id'])->find();
$group=Db::table('fa_user_group')->where('id',$userinfo_data['userinfo']['group_id'])->find();
$userinfo_data['userinfo']['group_name']=$group['name'];
if ($find){
$userinfo_data['userinfo']['name']=$find['name'];
$userinfo_data['userinfo']['no_update']=0;
$userinfo_data['userinfo']['address_name']=$find['address_name'];
}else{
$userinfo_data['userinfo']['no_update']=1;
$userinfo_data['userinfo']['address_name']='';
}
Db::commit();
$this->apiSuccess('已完善,登录成功', $userinfo_data);
// } else {
// $this->apiError($this->auth->getError());
// }
} catch (ValidateException | PDOException | Exception $e) { } catch (ValidateException | PDOException | Exception $e) {
Db::rollback(); Db::rollback();
$this->apiError($e->getMessage()); $this->apiError($e->getMessage());
} }
} else { } else {
$this->apiError('未注册不能绑定'); $this->apiError('未注册不能绑定');
} }
} }

View File

@ -13,6 +13,7 @@ use think\Config;
use think\facade\Db; use think\facade\Db;
use think\facade\Request; use think\facade\Request;
use think\Response; use think\Response;
use app\admin\model\ShopUser;
class Auth class Auth
{ {
@ -20,7 +21,9 @@ class Auth
{ {
$token = Request::header('x-Token'); $token = Request::header('x-Token');
if ($token) { if ($token) {
if (strpos($token, 'Bearer') === 0){ if (strpos($token, 'Bearer') === 0){
$token = trim(substr($token, 6)); $token = trim(substr($token, 6));
} }
@ -29,11 +32,15 @@ class Auth
} }
try { try {
JWT::$leeway = 60;//当前时间减去60把时间留点余地 JWT::$leeway = 60;//当前时间减去60把时间留点余地
$decoded = JWT::decode($token, new Key('ae47e94a7dcd1fdfacb499b60e361a8d', 'HS256')); //HS256方式这里要和签发的时候对应 $decoded = JWT::decode($token, new Key('ae47e94a7dcd1fdfacb499b60e361a8d', 'HS256')); //HS256方式这里要和签发的时候对应
$user=Db::connect('shop')->name('nk_user')->where('user_id',$decoded->jti[0])->find();
if ($user && $user['n_user_id']!=0){ // $user=Db::connect('shop')->name('nk_user')->where('user_id',$decoded->jti[0])->find();
$request->uid=$user['n_user_id']; $user= ShopUser::where('uid',$decoded->jti[0])->find();
if ($user && $user['uid']!=0){
$request->uid = $user['uid'];
}else{ }else{
$request->uid=$this->addUser($decoded->jti[0],$user); $request->uid=$this->addUser($decoded->jti[0],$user);
} }