add 用户注册,后台片区建档目标数

This commit is contained in:
chenbo 2023-12-28 10:45:34 +08:00
parent 44432d06ad
commit 1b4822e8c7
9 changed files with 485 additions and 58 deletions

View File

@ -0,0 +1,108 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\controller;
use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\UserInformationThresholdLists;
use app\adminapi\logic\UserInformationThresholdLogic;
use app\adminapi\validate\UserInformationThresholdValidate;
/**
* UserInformationThreshold控制器
* Class UserInformationThresholdController
* @package app\adminapi\controller
*/
class UserInformationThresholdController extends BaseAdminController
{
/**
* @notes 获取列表
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/28 10:41
*/
public function lists()
{
return $this->dataLists(new UserInformationThresholdLists());
}
/**
* @notes 添加
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/28 10:41
*/
public function add()
{
$params = (new UserInformationThresholdValidate())->post()->goCheck('add');
$result = UserInformationThresholdLogic::add($params);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(UserInformationThresholdLogic::getError());
}
/**
* @notes 编辑
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/28 10:41
*/
public function edit()
{
$params = (new UserInformationThresholdValidate())->post()->goCheck('edit');
$result = UserInformationThresholdLogic::edit($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(UserInformationThresholdLogic::getError());
}
/**
* @notes 删除
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/28 10:41
*/
public function delete()
{
$params = (new UserInformationThresholdValidate())->post()->goCheck('delete');
UserInformationThresholdLogic::delete($params);
return $this->success('删除成功', [], 1, 1);
}
/**
* @notes 获取详情
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/28 10:41
*/
public function detail()
{
$params = (new UserInformationThresholdValidate())->goCheck('detail');
$result = UserInformationThresholdLogic::detail($params);
return $this->data($result);
}
}

View File

@ -71,7 +71,7 @@ class OperationLog
$systemLog->type = $request->isGet() ? 'GET' : 'POST';
$systemLog->params = json_encode($params, true);
$systemLog->ip = $request->ip();
$systemLog->result = $response->getContent();
$systemLog->result = substr($response->getContent(), 0, 65535);
return $systemLog->save();
}
}

View File

@ -0,0 +1,77 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\lists;
use app\adminapi\lists\BaseAdminDataLists;
use app\common\model\UserInformationThreshold;
use app\common\lists\ListsSearchInterface;
/**
* UserInformationThreshold列表
* Class UserInformationThresholdLists
* @package app\adminapi\lists
*/
class UserInformationThresholdLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2023/12/28 10:41
*/
public function setSearch(): array
{
return [
'=' => ['village_code', 'threshold_value'],
];
}
/**
* @notes 获取列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2023/12/28 10:41
*/
public function lists(): array
{
return UserInformationThreshold::where($this->searchWhere)
->field(['id', 'village_code', 'threshold_value'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()
->toArray();
}
/**
* @notes 获取数量
* @return int
* @author likeadmin
* @date 2023/12/28 10:41
*/
public function count(): int
{
return UserInformationThreshold::where($this->searchWhere)->count();
}
}

View File

@ -0,0 +1,108 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\logic;
use app\common\model\UserInformationThreshold;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* UserInformationThreshold逻辑
* Class UserInformationThresholdLogic
* @package app\adminapi\logic
*/
class UserInformationThresholdLogic extends BaseLogic
{
/**
* @notes 添加
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/12/28 10:41
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
UserInformationThreshold::create([
'village_code' => $params['village_code'],
'threshold_value' => $params['threshold_value'],
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/12/28 10:41
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
UserInformationThreshold::where('id', $params['id'])->update([
'village_code' => $params['village_code'],
'threshold_value' => $params['threshold_value'],
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/12/28 10:41
*/
public static function delete(array $params): bool
{
return UserInformationThreshold::destroy($params['id']);
}
/**
* @notes 获取详情
* @param $params
* @return array
* @author likeadmin
* @date 2023/12/28 10:41
*/
public static function detail($params): array
{
return UserInformationThreshold::findOrEmpty($params['id'])->toArray();
}
}

View File

@ -0,0 +1,94 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\validate;
use app\common\validate\BaseValidate;
/**
* UserInformationThreshold验证器
* Class UserInformationThresholdValidate
* @package app\adminapi\validate
*/
class UserInformationThresholdValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require',
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'id' => 'id',
];
/**
* @notes 添加场景
* @return UserInformationThresholdValidate
* @author likeadmin
* @date 2023/12/28 10:41
*/
public function sceneAdd()
{
return $this->remove('id', true);
}
/**
* @notes 编辑场景
* @return UserInformationThresholdValidate
* @author likeadmin
* @date 2023/12/28 10:41
*/
public function sceneEdit()
{
return $this->only(['id']);
}
/**
* @notes 删除场景
* @return UserInformationThresholdValidate
* @author likeadmin
* @date 2023/12/28 10:41
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return UserInformationThresholdValidate
* @author likeadmin
* @date 2023/12/28 10:41
*/
public function sceneDetail()
{
return $this->only(['id']);
}
}

View File

@ -3,64 +3,21 @@
namespace app\api\controller\new;
use app\api\controller\BaseApiController;
use app\common\model\dict\DictData;
use app\common\model\user\User;
use app\common\service\ConfigService;
use think\facade\Config;
use app\api\logic\UserLogic;
use app\api\validate\RegisterValidate;
class UserController extends BaseApiController
{
public array $notNeedLogin = ['register'];
public function register()
{
// 用户注册逻辑
$params = $this->request->param();
try {
// 手机号已被使用
$mobileUser = User::where(['account' => $params['account']])->find();
if (!empty($mobileUser)) {
self::setError('手机号已被注册');
return false;
}
// 生成用户编号
$userSn = User::createUserSn();
$passwordSalt = Config::get('project.unique_identification');
$password = create_password($params['password'], $passwordSalt);
if ($params['avatar'] != '') {
$avatar = $params['avatar'];
} else {
$avatar = ConfigService::get('default_image', 'user_avatar');
}
User::create([
'sn' => $userSn,
'avatar' => $avatar,
'is_captain' => $params['is_captain'],
'nickname' => $params['nickname'],
'account' => $params['account'],
'mobile' => $params['account'],
'id_card' => $params['id_card'],
'password' => $password,
'channel' => 0,
'sex' => $params['sex'],
'province' => $params['province'],
'city' => $params['city'],
'area' => $params['area'],
'street' => $params['street'],
'village' => $params['village'],
'brigade' => $params['brigade'],
'address' => $params['address'],
'qualification' => json_encode($params['qualification']),
'company_id' => $params['company_id'],
'group_id' => $params['group_id'],
]);
return true;
} catch (\Exception $e) {
self::setError($e->getMessage());
return false;
$params = (new RegisterValidate())->post()->goCheck('register');
$result = UserLogic::register($params);
if (true === $result) {
return $this->success('注册成功', [], 1, 1);
}
return $this->fail(UserLogic::getError());
}
}

View File

@ -22,6 +22,7 @@ use app\common\{enum\notice\NoticeEnum,
model\user\User,
model\user\UserAuth,
model\user\Withdraw,
service\ConfigService,
service\sms\SmsDriver,
service\wechat\WeChatMnpService};
use app\common\model\dict\DictData;
@ -366,4 +367,54 @@ class UserLogic extends BaseLogic
return [$count, $list];
}
public static function register(array $params)
{
try {
// 手机号已被使用
$mobileUser = User::where(['account' => $params['account']])->find();
if (!empty($mobileUser)) {
self::setError('手机号已被注册');
return false;
}
// 生成用户编号
$userSn = User::createUserSn();
$passwordSalt = Config::get('project.unique_identification');
$password = create_password($params['password'], $passwordSalt);
if ($params['avatar'] != '') {
$avatar = $params['avatar'];
} else {
$avatar = ConfigService::get('default_image', 'user_avatar');
}
User::create([
'sn' => $userSn,
'avatar' => $avatar,
'is_captain' => 0,
'nickname' => $params['nickname'],
'account' => $params['account'],
'mobile' => $params['account'],
'id_card' => $params['id_card'],
'password' => $password,
'channel' => $params['channel'],
'sex' => $params['sex'],
'province' => $params['province'],
'city' => $params['city'],
'area' => $params['area'],
'street' => $params['street'],
'village' => $params['village'],
'brigade' => $params['brigade'],
'address' => $params['address'],
'qualification' => json_encode($params['qualification']),
'company_id' => 0, // 暂时为0
'group_id' => $params['group_id'],
]);
return true;
} catch (\Exception $e) {
self::setError($e->getMessage());
return false;
}
}
}

View File

@ -26,13 +26,12 @@ class RegisterValidate extends BaseValidate
{
protected $regex = [
'register' => '^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]+$',
'account' => '/^1[3-9][0-9]\d{8}$/',
'password' => '/^(?![0-9]+$)(?![a-z]+$)(?![A-Z]+$)(?!([^(0-9a-zA-Z)]|[\(\)])+$)([^(0-9a-zA-Z)]|[\(\)]|[a-z]|[A-Z]|[0-9]){6,20}$/'
];
protected $rule = [
'channel' => 'require',
'account' => 'require|length:3,12|unique:' . User::class . '|regex:register',
'account' => 'require|unique:' . User::class . '|regex:account',
'password' => 'require|length:6,20|regex:password',
'password_confirm' => 'require|confirm'
];
@ -40,9 +39,8 @@ class RegisterValidate extends BaseValidate
protected $message = [
'channel.require' => '注册来源参数缺失',
'account.require' => '请输入账号',
'account.regex' => '账号须为字母数字组合',
'account.length' => '账号须为3-12位之间',
'account.unique' => '账号已存在',
'account.regex' => '账号须为手机号',
'password.require' => '请输入密码',
'password.length' => '密码须在6-25位之间',
'password.regex' => '密码须为数字,字母或符号组合',

View File

@ -0,0 +1,34 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\common\model;
use app\common\model\BaseModel;
use think\model\concern\SoftDelete;
/**
* UserInformationThreshold模型
* Class UserInformationThreshold
* @package app\common\model
*/
class UserInformationThreshold extends BaseModel
{
use SoftDelete;
protected $name = 'user_information_threshold';
protected $deleteTime = 'delete_time';
}