【程序目录】新增用户注销功能

This commit is contained in:
evoxwht 2022-04-27 11:31:02 +08:00
parent ae04e0f802
commit 510277f9ce
11 changed files with 299 additions and 19 deletions

View File

@ -126,10 +126,14 @@ class User extends AuthController
if (!check_phone($data['phone'])) {
return app('json')->fail('手机号码格式不正确');
}
if ($this->services->count(['phone' => $data['phone']])) {
if ($this->services->count(['phone' => $data['phone'], 'is_del' => 0])) {
return app('json')->fail('手机号已经存在不能添加相同的手机号用户');
}
$data['nickname'] = substr_replace($data['phone'], '****', 3, 4);
if (trim($data['real_name']) != '') {
$data['nickname'] = $data['real_name'];
} else {
$data['nickname'] = substr_replace($data['phone'], '****', 3, 4);
}
}
if ($data['card_id']) {
if (!check_card($data['card_id'])) return app('json')->fail('请输入正确的身份证');

View File

@ -0,0 +1,59 @@
<?php
namespace app\adminapi\controller\v1\user;
use app\adminapi\controller\AuthController;
use app\services\user\UserCancelServices;
use think\facade\App;
class UserCancel extends AuthController
{
/**
* UserCancel constructor.
* @param App $app
* @param UserCancelServices $services
*/
public function __construct(App $app, UserCancelServices $services)
{
parent::__construct($app);
$this->services = $services;
}
/**
* 获取注销列表
* @return mixed
*/
public function getCancelList()
{
$where = $this->request->postMore([
['status', 0],
['keywords', ''],
]);
$data = $this->services->getCancelList($where);
return app('json')->success($data);
}
/**
* 备注
* @return mixed
*/
public function setMark()
{
[$id, $mark] = $this->request->postMore([
['id', 0],
['mark', ''],
], true);
$this->services->serMark($id, $mark);
return app('json')->success('备注成功');
}
public function agreeCancel($id)
{
return app('json')->success('注销成功');
}
public function refuseCancel($id)
{
return app('json')->success('拒绝注销');
}
}

View File

@ -135,6 +135,13 @@ Route::group('user', function () {
Route::get('member/agreement', 'v1.user.member.MemberCardBatch/getAgreement')->option(['real_name' => '获取会员协议']);
//用户标签(分类)树形列表
Route::get('user_tree_label', 'v1.user.UserLabel/tree_list')->option(['real_name' => '用户标签(分类)树形列表']);
/** 用户注销 */
Route::get('cancel_list', 'v1.user.UserCancel/getCancelList')->option(['real_name' => '用户注销列表']);
Route::post('cancel/set_mark', 'v1.user.UserCancel/setMark')->option(['real_name' => '注销列表备注']);
Route::get('cancel/agree/:id', 'v1.user.UserCancel/agreeCancel')->option(['real_name' => '同意注销']);
Route::get('cancel/refuse/:id', 'v1.user.UserCancel/refuseCancel')->option(['real_name' => '拒绝注销']);
})->middleware([
\app\http\middleware\AllowOriginMiddleware::class,
\app\adminapi\middleware\AdminAuthTokenMiddleware::class,

View File

@ -11,6 +11,7 @@
namespace app\api\controller\v1\user;
use app\Request;
use app\services\user\UserCancelServices;
use app\services\user\UserServices;
use app\services\wechat\WechatUserServices;
@ -229,4 +230,16 @@ class UserController
}
}
/**
* 用户注销
* @param Request $request
* @return mixed
*/
public function SetUserCancel(Request $request)
{
/** @var UserCancelServices $userCancelServices */
$userCancelServices = app()->make(UserCancelServices::class);
$userCancelServices->SetUserCancel($request->uid());
return app('json')->success('注销成功');
}
}

View File

@ -16,7 +16,6 @@ use think\Response;
Route::any('wechat/serve', 'v1.wechat.WechatController/serve');//公众号服务
Route::any('wechat/notify', 'v1.wechat.WechatController/notify');//公众号支付回调
Route::any('routine/notify', 'v1.wechat.AuthController/notify');//小程序支付回调
Route::any('pay/notify/:type', 'v1.PayController/notify');//支付回调
Route::get('get_script', 'v1.PublicController/getScript');//获取统计代码
@ -253,6 +252,11 @@ Route::group(function () {
Route::post('agent/set_staff_percent', 'v1.user.DivisionController/setStaffPercent')->name('setStaffPercent');//设置员工分佣比例
Route::get('agent/del_staff/:uid', 'v1.user.DivisionController/delStaff')->name('delStaff');//删除员工
/** 用户注销 */
Route::get('user_cancel', 'v1.user.UserController/SetUserCancel')->name('SetUserCancel');//用户注销
})->middleware(\app\http\middleware\AllowOriginMiddleware::class)->middleware(\app\api\middleware\StationOpenMiddleware::class)->middleware(\app\api\middleware\AuthTokenMiddleware::class, true);
//未授权接口
Route::group(function () {
@ -360,6 +364,7 @@ Route::group(function () {
Route::get('get_open_adv', 'v1.PublicController/getOpenAdv')->name('getOpenAdv');
//获取用户协议
Route::get('user_agreement', 'v1.PublicController/getUserAgreement')->name('getUserAgreement');
Route::get('get_agreement/:type', 'v1.PublicController/getAgreement')->name('getAgreement');
})->middleware(\app\http\middleware\AllowOriginMiddleware::class)->middleware(\app\api\middleware\StationOpenMiddleware::class)->middleware(\app\api\middleware\AuthTokenMiddleware::class, false);
Route::miss(function () {

View File

@ -0,0 +1,35 @@
<?php
namespace app\dao\user;
use app\dao\BaseDao;
use app\model\user\UserCancel;
class UserCancelDao extends BaseDao
{
/**
* @return string
*/
protected function setModel(): string
{
return UserCancel::class;
}
/**
* 获取列表
* @param $where
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList($where, $page = 0, $limit = 0)
{
return $this->search($where)->with(['user'])
->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->select()->toArray();
}
}

View File

@ -431,4 +431,13 @@ class User extends BaseModel
if ($value !== '') $query->where('uid|nickname', 'like', '%' . $value . '%');
}
/**
* 注销搜索器
* @param $query
* @param $value
*/
public function searchIsDelAttr($query, $value)
{
if ($value !== '') $query->where('is_del', $value);
}
}

View File

@ -0,0 +1,75 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\model\user;
use crmeb\basic\BaseModel;
use crmeb\traits\ModelTrait;
/**
* Class UserCancel
* @package app\model\user
*/
class UserCancel extends BaseModel
{
use ModelTrait;
/**
* 数据表主键
* @var string
*/
protected $pk = 'id';
/**
* 模型名称
* @var string
*/
protected $name = 'user_cancel';
/**
* 关联用户表
* @return \think\model\relation\HasOne
*/
public function user()
{
return $this->hasOne(User::class, 'uid', 'uid')->bind([
'money' => 'now_money',
'brokerage' => 'brokerage_price'
]);
}
/**
* 状态搜索器
* @param $query
* @param $value
*/
public function searchStatusAttr($query, $value)
{
if ($value !== '') {
$query->where('status', $value);
}
}
/**
* 关键字搜索器
* @param $query
* @param $value
*/
public function searchKeywordsAttr($query, $value)
{
if ($value !== '') {
$query->where('uid|name|phone', 'like', '%' . $value . '%');
}
}
}

View File

@ -48,7 +48,7 @@ class LoginServices extends BaseServices
*/
public function login($account, $password, $spread)
{
$user = $this->dao->getOne(['account|phone' => $account]);
$user = $this->dao->getOne(['account|phone' => $account, 'is_del' => 0]);
if ($user) {
if ($user->pwd !== md5((string)$password))
throw new ValidateException('账号或密码错误');
@ -156,7 +156,7 @@ class LoginServices extends BaseServices
public function verify(SmsSendServices $services, $phone, $type, $time, $ip)
{
if ($this->dao->getOne(['account' => $phone]) && $type == 'register') {
if ($this->dao->getOne(['account' => $phone, 'is_del' => 0]) && $type == 'register') {
throw new ValidateException('手机号已注册');
}
$default = Config::get('sms.default', 'yunxin');
@ -190,7 +190,7 @@ class LoginServices extends BaseServices
*/
public function register($account, $password, $spread, $user_type = 'h5')
{
if ($this->dao->getOne(['account|phone' => $account])) {
if ($this->dao->getOne(['account|phone' => $account, 'is_del' => 0])) {
throw new ValidateException('用户已存在,请去修改密码');
}
$phone = $account;
@ -236,7 +236,7 @@ class LoginServices extends BaseServices
*/
public function reset($account, $password)
{
$user = $this->dao->getOne(['account|phone' => $account]);
$user = $this->dao->getOne(['account|phone' => $account, 'is_del' => 0]);
if (!$user) {
throw new ValidateException('用户不存在');
}
@ -258,7 +258,7 @@ class LoginServices extends BaseServices
public function mobile($phone, $spread, $user_type = 'h5')
{
//数据库查询
$user = $this->dao->getOne(['phone' => $phone]);
$user = $this->dao->getOne(['phone' => $phone, 'is_del' => 0]);
if (!$user) {
$user = $this->register($phone, '123456', $spread, $user_type);
if (!$user) {
@ -288,11 +288,11 @@ class LoginServices extends BaseServices
public function switchAccount($user, $from)
{
if ($from === 'h5') {
$where = [['phone', '=', $user['phone']], ['user_type', '<>', 'h5']];
$where = [['phone', '=', $user['phone']], ['user_type', '<>', 'h5'], ['is_del', '=', 0]];
$login_type = 'wechat';
} else {
//数据库查询
$where = [['account|phone', '=', $user['phone']], ['user_type', '=', 'h5']];
$where = [['account|phone', '=', $user['phone']], ['user_type', '=', 'h5'], ['is_del', '=', 0]];
$login_type = 'h5';
}
$switch_user = $this->dao->getOne($where);
@ -359,14 +359,14 @@ class LoginServices extends BaseServices
if (!$userInfo) {
throw new ValidateException('用户不存在');
}
if ($this->dao->getOne([['phone', '=', $phone], ['user_type', '<>', 'h5']])) {
if ($this->dao->getOne([['phone', '=', $phone], ['user_type', '<>', 'h5'], ['is_del', '=', 0]])) {
throw new ValidateException('此手机已经绑定,无法多次绑定!');
}
if ($userInfo->phone) {
throw new ValidateException('您的账号已经绑定过手机号码!');
}
$data = [];
if ($this->dao->getOne(['account' => $phone, 'phone' => $phone, 'user_type' => 'h5'])) {
if ($this->dao->getOne(['account' => $phone, 'phone' => $phone, 'user_type' => 'h5', 'is_del' => 0])) {
if (!$step) return ['msg' => 'H5已有账号是否绑定此账号上', 'data' => ['is_bind' => 1]];
} else {
$data['account'] = $phone;
@ -387,14 +387,14 @@ class LoginServices extends BaseServices
*/
public function updateBindindPhone(int $uid, $phone)
{
$userInfo = $this->dao->get($uid);
$userInfo = $this->dao->get(['uid' => $uid, 'is_del' => 0]);
if (!$userInfo) {
throw new ValidateException('用户不存在');
}
if ($userInfo->phone == $phone) {
throw new ValidateException('新手机号和原手机号相同,无需修改');
}
if ($this->dao->getOne([['phone', '=', $phone]])) {
if ($this->dao->getOne([['phone', '=', $phone], ['is_del', '=', 0]])) {
throw new ValidateException('此手机已经注册');
}
$data = [];

View File

@ -0,0 +1,73 @@
<?php
namespace app\services\user;
use app\dao\user\UserCancelDao;
use app\services\BaseServices;
use app\services\wechat\WechatUserServices;
use crmeb\services\CacheService;
class UserCancelServices extends BaseServices
{
protected $status = ['待审核', '已通过', '已拒绝'];
/**
* UserExtractServices constructor.
* @param UserCancelDao $dao
*/
public function __construct(UserCancelDao $dao)
{
$this->dao = $dao;
}
/**
* 提交用户注销
* @param $userInfo
* @return mixed
*/
public function SetUserCancel($uid)
{
// $data = [];
// $data['uid'] = $userInfo['uid'];
// $data['name'] = $userInfo['nickname'];
// $data['phone'] = $userInfo['phone'];
// $data['add_time'] = time();
// return $this->dao->save($data);
/** @var UserServices $userServices */
$userServices = app()->make(UserServices::class);
/** @var WechatUserServices $wechatUserServices */
$wechatUserServices = app()->make(WechatUserServices::class);
$userServices->update($uid, ['is_del' => 1]);
$wechatUserServices->update(['uid' => $uid], ['is_del' => 1]);
CacheService::clearTokenAll('api' . $uid);
}
/**
* 获取注销列表
* @param $where
* @return array
*/
public function getCancelList($where)
{
[$page, $limit] = $this->getPageValue();
$list = $this->dao->getList($where, $page, $limit);
foreach ($list as &$item) {
$item['add_time'] = date('Y-m-d H:i:s', $item['add_time']);
$item['up_time'] = $item['up_time'] != 0 ? date('Y-m-d H:i:s', $item['add_time']) : '';
$item['status'] = $this->status[$item['status']];
}
$count = $this->dao->count($where);
return compact('list', 'count');
}
/**
* 备注
* @param $id
* @param $mark
* @return mixed
*/
public function serMark($id, $mark)
{
return $this->dao->update($id, ['remark' => $mark]);
}
}

View File

@ -203,7 +203,7 @@ class WechatUserServices extends BaseServices
{
$user = [];
//兼容老用户
$uids = $this->dao->getColumn(['unionid|openid' => $openid], 'uid,user_type', 'user_type');
$uids = $this->dao->getColumn(['unionid|openid' => $openid, 'is_del' => 0], 'uid,user_type', 'user_type');
if ($uids) {
$uid = $uids[$user_type]['uid'] ?? 0;
if (!$uid) {
@ -303,13 +303,13 @@ class WechatUserServices extends BaseServices
$userInfo = [];
$uid = 0;
if (isset($wechatInfo['phone']) && $wechatInfo['phone']) {
$userInfo = $userServices->getOne(['phone' => $wechatInfo['phone']]);
$userInfo = $userServices->getOne(['phone' => $wechatInfo['phone'], 'is_del' => 0]);
}
if (!$userInfo) {
if (isset($wechatInfo['unionid']) && $wechatInfo['unionid']) {
$uid = $this->dao->value(['unionid' => $wechatInfo['unionid']], 'uid');
$uid = $this->dao->value(['unionid' => $wechatInfo['unionid'], 'is_del' => 0], 'uid');
if ($uid) {
$userInfo = $userServices->getOne(['uid' => $uid]);
$userInfo = $userServices->getOne(['uid' => $uid, 'is_del' => 0]);
}
} else {
$userInfo = $this->getAuthUserInfo($openid, $userType);
@ -323,7 +323,7 @@ class WechatUserServices extends BaseServices
if ($userInfo) {
//更新用户表和wechat_user表
//判断该类性用户在wechatUser中是否存在
$wechatUser = $this->dao->getOne(['uid' => $uid, 'user_type' => $userType]);
$wechatUser = $this->dao->getOne(['uid' => $uid, 'user_type' => $userType, 'is_del' => 0]);
/** @var LoginServices $loginService */
$loginService = app()->make(LoginServices::class);
$this->transaction(function () use ($loginService, $wechatInfo, $userInfo, $uid, $userType, $spreadId, $wechatUser) {