作者 Cool
1 个管道 的构建 通过 耗费 12 秒

h5修改,新增用户功能开发

... ... @@ -3,7 +3,12 @@
namespace app\admin\controller\user;
use app\common\controller\Backend;
use Endroid\QrCode\QrCode;
use Exception;
use fast\Random;
use think\Db;
use think\exception\PDOException;
use think\exception\ValidateException;
/**
* 会员管理
... ... @@ -61,6 +66,75 @@ class User extends Backend
return $this->view->fetch();
}
/**
* 添加
*/
public function add()
{
if ($this->request->isPost()) {
$params = $this->request->post("row/a");
if ($params) {
$params = $this->preExcludeFields($params);
if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
$params[$this->dataLimitField] = $this->auth->id;
}
$result = false;
Db::startTrans();
try {
$params['pwd'] = $params['password'];
$params['salt'] = Random::alnum();
$params['password'] = md5(md5($params['password']) . $params['salt']);
$params['status'] = 'normal';
$params['createtime'] = $params['updatetime'] = time();
$params['joinip'] = request()->ip();
$result = $this->model->validate('User.add')->save($params);
//生成二维码
$id = $this->model->id;
$page = '/pages/myIndex/myIndex?user_id='.$id;
$thumbnail = $this->qrcode($page,$id);
Db::name('user')->where('id',$id)->update(['thumbnail'=>$thumbnail]);
Db::commit();
} catch (ValidateException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (PDOException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($result !== false) {
$this->success();
} else {
$this->error($this->model->getError());
}
}
$this->error(__('Parameter %s can not be empty', ''));
}
return $this->view->fetch();
}
//生成二维码
private function qrcode($url,$user_id)
{
$qrCode = new QrCode('Life is too short to be generating QR codes');
$qrCode
->setText($url)
->setSize(450)
->setPadding(10)
->setErrorCorrection('high')
->setForegroundColor(['r' => 0, 'g' => 0, 'b' => 0, 'a' => 0])
->setBackgroundColor(['r' => 255, 'g' => 255, 'b' => 255, 'a' => 0])
->setImageType(QrCode::IMAGE_TYPE_PNG);
$file_path = "code".$user_id.".png";
$qrCode->save(ROOT_PATH . 'public' . DS . 'upload/code' . DS . $file_path);
$qrcodeurl = request()->domain().'/upload/code/code'.$user_id.'.png';
return $qrcodeurl;
}
// public function edit($ids = NULL)
// {
// $row = $this->model->get($ids);
... ...
... ... @@ -10,17 +10,27 @@ class User extends Validate
* 验证规则
*/
protected $rule = [
'username' => 'require|unique:user',
'password' => 'require|regex:\S{32}',
'mobile' => 'require|regex:^1\d{10}$|unique:user',
];
/**
* 提示消息
*/
protected $message = [
'username.require' => '请填写用户名',
'username.unique' => '用户名已存在',
'password.require' => '请填写密码',
'password.regex' => '密码格式错误',
'mobile.require' => '请填写手机号',
'mobile.regex' => '手机号格式错误',
'mobile.unique' => '手机号已存在',
];
/**
* 验证场景
*/
protected $scene = [
'add' => [],
'add' => ['username','password','mobile'],
'edit' => [],
];
... ...
<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
{:token()}
<div class="form-group">
<label for="c-username" class="control-label col-xs-12 col-sm-2">{:__('Username')}:</label>
<div class="col-xs-12 col-sm-4">
<input id="c-username" data-rule="required" class="form-control" name="row[username]" type="text" value="">
</div>
</div>
<div class="form-group">
<label for="c-password" class="control-label col-xs-12 col-sm-2">{:__('Password')}:</label>
<div class="col-xs-12 col-sm-4">
<input id="c-password" data-rule="password" class="form-control" name="row[password]" type="password" value="" placeholder="{:__('Leave password blank if dont want to change')}" autocomplete="new-password" />
</div>
</div>
<div class="form-group">
<label for="c-mobile" class="control-label col-xs-12 col-sm-2">{:__('Mobile')}:</label>
<div class="col-xs-12 col-sm-4">
<input id="c-mobile" data-rule="" class="form-control" name="row[mobile]" type="text" value="">
</div>
</div>
<div class="form-group">
<label for="c-avatar" class="control-label col-xs-12 col-sm-2">{:__('Avatar')}:</label>
<div class="col-xs-12 col-sm-8">
<div class="input-group">
<input id="c-avatar" data-rule="" class="form-control" size="50" name="row[avatar]" type="text" value="">
<div class="input-group-addon no-border no-padding">
<span><button type="button" id="plupload-avatar" class="btn btn-danger plupload" data-input-id="c-avatar" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/bmp" data-multiple="false" data-preview-id="p-avatar"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
<span><button type="button" id="fachoose-avatar" class="btn btn-primary fachoose" data-input-id="c-avatar" data-mimetype="image/*" data-multiple="false"><i class="fa fa-list"></i> {:__('Choose')}</button></span>
</div>
<span class="msg-box n-right" for="c-avatar"></span>
</div>
<ul class="row list-inline plupload-preview" id="p-avatar"></ul>
</div>
</div>
<div class="form-group layer-footer">
<label class="control-label col-xs-12 col-sm-2"></label>
<div class="col-xs-12 col-sm-8">
<button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
<button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
</div>
</div>
</form>
... ...
... ... @@ -6,7 +6,7 @@
<div class="tab-pane fade active in" id="one">
<div class="widget-body no-padding">
<div id="toolbar" class="toolbar">
{:build_toolbar('refresh,edit,del')}
{:build_toolbar('refresh,add,edit,del')}
<div class="dropdown btn-group {:$auth->check('user/user/multi')?'':'hide'}">
<a class="btn btn-primary btn-more dropdown-toggle btn-disabled disabled" data-toggle="dropdown"><i class="fa fa-cog"></i> {:__('More')}</a>
<ul class="dropdown-menu text-left" role="menu">
... ...
... ... @@ -838,7 +838,7 @@ class Index extends Api
$tiao['a.user_id'] = ['eq',$user_id];
$tiao['b.is_up'] = 1;
$myfile = $this->myfile($type_id,$where);
$zhuan = $this->zhuan($type_id,$tiao,1);
$zhuan = $this->zhuan($type_id,$tiao);
$gong = $this->gong($type_id,$myfile,$zhuan);
$sundry = $this->sundry($gong);
$this->success('success',$sundry);
... ...
... ... @@ -44,7 +44,7 @@
{else /}
{foreach $data.folder as $vo}
<div class="file-item">
<div class="time">{$vo.times}</div>
<!-- <div class="time">{$vo.times}</div>-->
{foreach $vo.info as $val}
<a href="{:url('index/filedetail',array('file_id'=>$val.id))}">
<div class="file-item-bottom">
... ... @@ -67,7 +67,7 @@
{else /}
{foreach $data.note as $vo}
<div class="file-item">
<div class="time">{$vo.times}</div>
<!-- <div class="time">{$vo.times}</div>-->
{foreach $vo.info as $val}
<a href="{:url('index/detail',array('file_id'=>$val.id))}">
<div class="file-item-bottom">
... ... @@ -86,7 +86,7 @@
{else /}
{foreach $data.pic as $vo}
<div class="file-item pic-item">
<div class="time">{$vo.times}</div>
<!-- <div class="time">{$vo.times}</div>-->
<div class="file-item-bottom pic">
{foreach $vo.info as $val}
... ... @@ -106,7 +106,7 @@
{else /}
{foreach $data.video as $vo}
<div class="file-item pic-item">
<div class="time">{$vo.times}</div>
<!-- <div class="time">{$vo.times}</div>-->
<div class="file-item-bottom pic">
{foreach $vo.info as $val}
<a href="{:url('index/detail',array('file_id'=>$val.id))}">
... ...