From 56d80852ff7e20fe3bf6dda0293216b04fd66919 Mon Sep 17 00:00:00 2001 From: monanxiao Date: Sat, 18 Mar 2023 16:31:08 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=95=86=E5=9F=8E=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E4=BF=A1=E6=81=AF=E8=8E=B7=E5=8F=96=EF=BC=8C?= =?UTF-8?q?=E7=BB=9F=E4=B8=80=E8=B0=83=E6=95=B4=E4=B8=BA=E5=95=86=E5=9F=8E?= =?UTF-8?q?=E7=94=A8=E6=88=B7=EF=BC=8C=E5=89=94=E9=99=A4=E6=97=A0=E7=94=A8?= =?UTF-8?q?=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/Index.php | 12 +- app/api/controller/Article.php | 1 + app/api/controller/User.php | 20 ++- app/api/controller/Userinfo.php | 210 ++++++++++++++++++++------------ app/api/middleware/Auth.php | 13 +- 5 files changed, 168 insertions(+), 88 deletions(-) diff --git a/app/admin/controller/Index.php b/app/admin/controller/Index.php index ea75c50..462d27f 100644 --- a/app/admin/controller/Index.php +++ b/app/admin/controller/Index.php @@ -44,8 +44,16 @@ class Index extends BaseController public function main() { - $street_id=Db::table('fa_szxc_information_useraddress')->where('admin_id',$this->adminInfo['id'])->value('street_id'); - $street_name=Db::table('fa_geo_street')->where('street_code',$street_id)->value('street_name'); + // return json($this->adminInfo); + $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){ $urls="http://zhen.lihaink.cn/#/?street_id=$street_id"."&street_name=".$street_name; View::assign('urls',$urls); diff --git a/app/api/controller/Article.php b/app/api/controller/Article.php index f3fe1f4..e1763d5 100644 --- a/app/api/controller/Article.php +++ b/app/api/controller/Article.php @@ -653,6 +653,7 @@ class Article extends BaseController $where[] = ['a.user_id','=',$this->request->uid]; $where[] = ['b.is_read','=','0']; $which = []; + //根据个人村id进行查询 if ($this->request->uid) { $find = Db::table('fa_szxc_information_useraddress')->where('user_id', $this->request->uid)->find(); diff --git a/app/api/controller/User.php b/app/api/controller/User.php index 3f2de73..9c9ffef 100644 --- a/app/api/controller/User.php +++ b/app/api/controller/User.php @@ -11,6 +11,8 @@ use app\api\BaseController; use app\api\middleware\Auth; use think\facade\Db; use Firebase\JWT\Key; +use app\admin\model\ShopUser; + /** * 会员接口. */ @@ -30,14 +32,20 @@ class User extends BaseController */ public function index() { - $user = Db::table('fa_user')->where('id', $this->request->uid)->find(); - $user_msg = Db::table('fa_szxc_information_usermsg')->where('user_id', $this->request->uid)->field('id,name,address_name,phone')->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(); + $this->apiSuccess('', [ 'nickname' => $user['nickname'], - 'phone'=>$user_msg['phone'], - 'avatar'=>$user['avatar'], - 'address_name'=>$user_msg['address_name'], - 'name'=>$user_msg['name'] + 'phone' => $user['phone'], + 'avatar' => $user['avatar'], + 'address_name' => $user_msg['address_name'], + 'name' => $user_msg['name'] ]); } diff --git a/app/api/controller/Userinfo.php b/app/api/controller/Userinfo.php index 7617a8b..e080424 100644 --- a/app/api/controller/Userinfo.php +++ b/app/api/controller/Userinfo.php @@ -9,6 +9,7 @@ use think\Exception; use think\facade\Db; use think\exception\ValidateException; use think\facade\Request; +use app\admin\model\ShopUser; /** * 用户信息相关接口. @@ -101,36 +102,35 @@ class Userinfo extends BaseController $this->apiError('手机号错误'); } - $where['id'] = $this->request->uid; + // $where['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(); -// 已绑定 - if ($user) { - Db::startTrans(); + $user = ShopUser::where('phone', $post['phone'])->find(); // 通过唯一手机号获取商城用户信息 + // $user = Db::table('fa_user')->where($where)->field('id,nickname,group_id,mobile,avatar,username,createtime,score')->find(); // 农科user表废弃 + + // 已绑定 + if ($user) { // 如果用户存在 + + Db::startTrans(); // 开启事务 + 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) { $this->apiError('身份证号已被使用'); } -// $validateIDCard = $this->validateIDCard($post['idcard']); -// if($validateIDCard == false){ -// $this->apiError('身份证号错误'); -// } -// $ip = request()->ip(); -// $time = -// $salt = Random::alnum(); //随机字符串 + // 获取用户user_id + $userid = $user['uid']; + // $userid = $post['user_id']; // 原user_id 废弃 - $userid = $post['user_id']; - - // 组装地址名 + // 组装地址名 if ($post['area_id'] != '') { $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'] != '') { $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']; - Db::table('fa_user')->where($where)->update($u_up); -// $header = Request::header('x-Token'); -// if(isset($header['x-token']) && !empty($header['x-token'])){ + $u_up['nickname'] = $post['name']; // 真实姓名-- 待处理 -// }else{ -// $post['phone'] = $user['mobile']??''; -// } + // Db::table('fa_user')->where($where)->update($u_up); // 废弃的农科user表 //写入用户信息表 $data['user_id'] = $userid; @@ -164,21 +160,26 @@ class Userinfo extends BaseController $data['marital_status'] = $post['marital_status']; $data['phone'] = $post['phone']??''; $data['idcard'] = $post['idcard']; - $data['address_name'] = $post['address_name']; + $data['address_name'] = $address_name; $data['createtime'] = time(); $data['street_id'] = $post['street_id']; $data['village_id'] = $post['village_id_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['area_id'] = $post['area_id']; @@ -187,57 +188,112 @@ class Userinfo extends BaseController $address_data['village_code'] = $post['village_id']; $address_data['brigade_id'] = $post['brigade_id']; $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){ + 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){ - 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']]); - } - } + + // 商城农科user表,被废弃 + // $eb_nk_user = Db::connect('shop') + // ->table('eb_nk_user') + // ->where('n_user_id',$post['user_id']) + // ->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 -// 先获取当前村推官员 - $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'); + // 新增修改用户推广员id spread_uid + // $spread_uid = $userid; + + // 先获取当前村推官员 + $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){ - $eb_nk_user=Db::connect('shop')->table('eb_nk_user')->where('n_user_id',$post['user_id'])->find(); - 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(); - } + + // 更新本用户推广人UID + ShopUser::where('uid', $spread_uid) + ->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_id'] = $post['user_id']; - $userinfo_data['userinfo'] = $Userinfo; + $Userinfo = $user; + $Userinfo['user_id'] = $userid; + // $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'] = ''; + } + + \think\facade\Log::info($userinfo_data); + 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) { + Db::rollback(); $this->apiError($e->getMessage()); + } } else { + $this->apiError('未注册不能绑定'); } } diff --git a/app/api/middleware/Auth.php b/app/api/middleware/Auth.php index bfe148d..93570d4 100644 --- a/app/api/middleware/Auth.php +++ b/app/api/middleware/Auth.php @@ -13,6 +13,7 @@ use think\Config; use think\facade\Db; use think\facade\Request; use think\Response; +use app\admin\model\ShopUser; class Auth { @@ -20,7 +21,9 @@ class Auth { $token = Request::header('x-Token'); + if ($token) { + if (strpos($token, 'Bearer') === 0){ $token = trim(substr($token, 6)); } @@ -29,11 +32,15 @@ class Auth } try { + JWT::$leeway = 60;//当前时间减去60,把时间留点余地 $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){ - $request->uid=$user['n_user_id']; + + // $user=Db::connect('shop')->name('nk_user')->where('user_id',$decoded->jti[0])->find(); + $user= ShopUser::where('uid',$decoded->jti[0])->find(); + + if ($user && $user['uid']!=0){ + $request->uid = $user['uid']; }else{ $request->uid=$this->addUser($decoded->jti[0],$user); } From d3e2d1bce694907e7b65c7f9baebc3d30696f931 Mon Sep 17 00:00:00 2001 From: monanxiao Date: Sat, 18 Mar 2023 17:10:35 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BE=9B=E5=BA=94?= =?UTF-8?q?=E9=93=BE=E5=B0=8F=E7=BB=84=E5=A2=9E=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/SupplyTeam.php | 20 +++++++---------- app/admin/model/InformationUserAddress.php | 22 ++++++++++++++++++ app/admin/model/InformationUserMsg.php | 22 ++++++++++++++++++ app/admin/model/ShopUser.php | 19 ++++++++++++++++ app/admin/model/SupplyTeam.php | 26 ++++++++++++++++------ app/admin/view/supply_team/add.html | 2 +- app/admin/view/supply_team/datalist.html | 2 +- app/api/controller/Userinfo.php | 1 - 8 files changed, 92 insertions(+), 22 deletions(-) create mode 100644 app/admin/model/InformationUserAddress.php create mode 100644 app/admin/model/InformationUserMsg.php diff --git a/app/admin/controller/SupplyTeam.php b/app/admin/controller/SupplyTeam.php index ff3ed69..a188684 100644 --- a/app/admin/controller/SupplyTeam.php +++ b/app/admin/controller/SupplyTeam.php @@ -20,6 +20,7 @@ use app\admin\model\GeoCity; use app\admin\model\GeoArea; use app\admin\model\GeoStreet; use app\admin\model\GeoVillage; +use app\admin\model\ShopUser; class SupplyTeam extends BaseController @@ -41,7 +42,7 @@ class SupplyTeam extends BaseController $param = get_params(); $where = []; - $list = $this->model->with(['level', 'user'])->select(); + $list = $this->model->with(['level', 'user', 'userMsg'])->select(); $total = $this->model->count(); // $list = $this->model->getSupplyTeamList($where,$param); foreach ($list as $k =>$v){ @@ -91,7 +92,8 @@ class SupplyTeam extends BaseController 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 = ''; // 验证用户级别,获取对应的区域代码 @@ -118,7 +120,7 @@ class SupplyTeam extends BaseController $param['parent_code'] = $parent_code; // 所属区域代码 $this->model->addSupplyTeam($param); - + }else{ $geo_area = Db::table('fa_geo_area')->where('city_code',510500)->select(); View::assign('geo_area', $geo_area); @@ -126,15 +128,9 @@ class SupplyTeam extends BaseController View::assign('level', $level); //获取用户信息 - $this->users = Db::table('fa_szxc_information_useraddress') - ->alias('a') - ->where('a.status',1) - ->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); + $usersList = ShopUser::with(['userAddress', 'userMsg'])->select(); + + View::assign('users', $usersList); return view(); } } diff --git a/app/admin/model/InformationUserAddress.php b/app/admin/model/InformationUserAddress.php new file mode 100644 index 0000000..3f9f26d --- /dev/null +++ b/app/admin/model/InformationUserAddress.php @@ -0,0 +1,22 @@ +hasOne(InformationUserAddress::class, 'user_id', 'uid'); + } + + /** + * + * 用户家庭信息 + * + */ + public function userMsg() + { + return $this->hasOne(InformationUserMsg::class, 'user_id', 'uid'); + } } \ No newline at end of file diff --git a/app/admin/model/SupplyTeam.php b/app/admin/model/SupplyTeam.php index f751b62..5cdea58 100644 --- a/app/admin/model/SupplyTeam.php +++ b/app/admin/model/SupplyTeam.php @@ -7,6 +7,7 @@ namespace app\admin\model; use think\model; use app\common\model\User; +use app\admin\model\ShopUser; class SupplyTeam extends Model { @@ -30,7 +31,17 @@ class SupplyTeam extends Model */ 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) { - $insertId = 0; + $insertId = 0; try { - $param['create_time'] = time(); - $insertId = self::strict(false)->field(true)->insertGetId($param); - add_log('add', $insertId, $param); + $param['create_time'] = time(); + $insertId = self::strict(false)->field(true)->insertGetId($param); + ShopUser::where('uid', $param['user_id'])->update([ 'fa_supply_team_id' => $insertId]); + add_log('add', $insertId, $param); } 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]); } /** diff --git a/app/admin/view/supply_team/add.html b/app/admin/view/supply_team/add.html index 0cc0bbf..528ca00 100644 --- a/app/admin/view/supply_team/add.html +++ b/app/admin/view/supply_team/add.html @@ -37,7 +37,7 @@ diff --git a/app/admin/view/supply_team/datalist.html b/app/admin/view/supply_team/datalist.html index 3d90417..653f95a 100644 --- a/app/admin/view/supply_team/datalist.html +++ b/app/admin/view/supply_team/datalist.html @@ -68,7 +68,7 @@ // width: 100, templet: function (d) { - return d.user.nickname + ',手机号:' + d.user.mobile; + return d.userMsg.name + ',手机号:' + d.user.phone; } },{ field: 'auth_range', diff --git a/app/api/controller/Userinfo.php b/app/api/controller/Userinfo.php index e080424..457fcde 100644 --- a/app/api/controller/Userinfo.php +++ b/app/api/controller/Userinfo.php @@ -278,7 +278,6 @@ class Userinfo extends BaseController $userinfo_data['userinfo']['address_name'] = ''; } - \think\facade\Log::info($userinfo_data); Db::commit(); $this->apiSuccess('已完善,登录成功', $userinfo_data); From 781fe13f0ee314297ca6c4d26c85b10f14fa9511 Mon Sep 17 00:00:00 2001 From: monanxiao Date: Sat, 18 Mar 2023 17:13:55 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=AE=B6=E5=BA=AD=E6=88=90=E5=91=98?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=88=B7=E4=B8=BB=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/Maintainentry.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/api/controller/Maintainentry.php b/app/api/controller/Maintainentry.php index 00b4d31..8daaf72 100644 --- a/app/api/controller/Maintainentry.php +++ b/app/api/controller/Maintainentry.php @@ -1680,6 +1680,7 @@ class Maintainentry extends BaseController // 获取家庭的人员信息 $res = Db::table('fa_szxc_information_usermsg')->where($map) ->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") ->withAttr('avatar', function ($value, $data) { return Db::table('fa_user')->where('id', $data['user_id'])->value('avatar');