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

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

@@ -3,7 +3,12 @@ @@ -3,7 +3,12 @@
3 namespace app\admin\controller\user; 3 namespace app\admin\controller\user;
4 4
5 use app\common\controller\Backend; 5 use app\common\controller\Backend;
  6 +use Endroid\QrCode\QrCode;
  7 +use Exception;
  8 +use fast\Random;
6 use think\Db; 9 use think\Db;
  10 +use think\exception\PDOException;
  11 +use think\exception\ValidateException;
7 12
8 /** 13 /**
9 * 会员管理 14 * 会员管理
@@ -61,6 +66,75 @@ class User extends Backend @@ -61,6 +66,75 @@ class User extends Backend
61 return $this->view->fetch(); 66 return $this->view->fetch();
62 } 67 }
63 68
  69 + /**
  70 + * 添加
  71 + */
  72 + public function add()
  73 + {
  74 + if ($this->request->isPost()) {
  75 + $params = $this->request->post("row/a");
  76 + if ($params) {
  77 + $params = $this->preExcludeFields($params);
  78 +
  79 + if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
  80 + $params[$this->dataLimitField] = $this->auth->id;
  81 + }
  82 + $result = false;
  83 + Db::startTrans();
  84 + try {
  85 + $params['pwd'] = $params['password'];
  86 + $params['salt'] = Random::alnum();
  87 + $params['password'] = md5(md5($params['password']) . $params['salt']);
  88 + $params['status'] = 'normal';
  89 + $params['createtime'] = $params['updatetime'] = time();
  90 + $params['joinip'] = request()->ip();
  91 + $result = $this->model->validate('User.add')->save($params);
  92 + //生成二维码
  93 + $id = $this->model->id;
  94 + $page = '/pages/myIndex/myIndex?user_id='.$id;
  95 + $thumbnail = $this->qrcode($page,$id);
  96 + Db::name('user')->where('id',$id)->update(['thumbnail'=>$thumbnail]);
  97 + Db::commit();
  98 + } catch (ValidateException $e) {
  99 + Db::rollback();
  100 + $this->error($e->getMessage());
  101 + } catch (PDOException $e) {
  102 + Db::rollback();
  103 + $this->error($e->getMessage());
  104 + } catch (Exception $e) {
  105 + Db::rollback();
  106 + $this->error($e->getMessage());
  107 + }
  108 + if ($result !== false) {
  109 + $this->success();
  110 + } else {
  111 + $this->error($this->model->getError());
  112 + }
  113 + }
  114 + $this->error(__('Parameter %s can not be empty', ''));
  115 + }
  116 + return $this->view->fetch();
  117 + }
  118 +
  119 + //生成二维码
  120 + private function qrcode($url,$user_id)
  121 + {
  122 + $qrCode = new QrCode('Life is too short to be generating QR codes');
  123 + $qrCode
  124 + ->setText($url)
  125 + ->setSize(450)
  126 + ->setPadding(10)
  127 + ->setErrorCorrection('high')
  128 + ->setForegroundColor(['r' => 0, 'g' => 0, 'b' => 0, 'a' => 0])
  129 + ->setBackgroundColor(['r' => 255, 'g' => 255, 'b' => 255, 'a' => 0])
  130 + ->setImageType(QrCode::IMAGE_TYPE_PNG);
  131 + $file_path = "code".$user_id.".png";
  132 +
  133 + $qrCode->save(ROOT_PATH . 'public' . DS . 'upload/code' . DS . $file_path);
  134 + $qrcodeurl = request()->domain().'/upload/code/code'.$user_id.'.png';
  135 + return $qrcodeurl;
  136 + }
  137 +
64 // public function edit($ids = NULL) 138 // public function edit($ids = NULL)
65 // { 139 // {
66 // $row = $this->model->get($ids); 140 // $row = $this->model->get($ids);
@@ -10,17 +10,27 @@ class User extends Validate @@ -10,17 +10,27 @@ class User extends Validate
10 * 验证规则 10 * 验证规则
11 */ 11 */
12 protected $rule = [ 12 protected $rule = [
  13 + 'username' => 'require|unique:user',
  14 + 'password' => 'require|regex:\S{32}',
  15 + 'mobile' => 'require|regex:^1\d{10}$|unique:user',
13 ]; 16 ];
14 /** 17 /**
15 * 提示消息 18 * 提示消息
16 */ 19 */
17 protected $message = [ 20 protected $message = [
  21 + 'username.require' => '请填写用户名',
  22 + 'username.unique' => '用户名已存在',
  23 + 'password.require' => '请填写密码',
  24 + 'password.regex' => '密码格式错误',
  25 + 'mobile.require' => '请填写手机号',
  26 + 'mobile.regex' => '手机号格式错误',
  27 + 'mobile.unique' => '手机号已存在',
18 ]; 28 ];
19 /** 29 /**
20 * 验证场景 30 * 验证场景
21 */ 31 */
22 protected $scene = [ 32 protected $scene = [
23 - 'add' => [], 33 + 'add' => ['username','password','mobile'],
24 'edit' => [], 34 'edit' => [],
25 ]; 35 ];
26 36
  1 +<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
  2 + {:token()}
  3 + <div class="form-group">
  4 + <label for="c-username" class="control-label col-xs-12 col-sm-2">{:__('Username')}:</label>
  5 + <div class="col-xs-12 col-sm-4">
  6 + <input id="c-username" data-rule="required" class="form-control" name="row[username]" type="text" value="">
  7 + </div>
  8 + </div>
  9 + <div class="form-group">
  10 + <label for="c-password" class="control-label col-xs-12 col-sm-2">{:__('Password')}:</label>
  11 + <div class="col-xs-12 col-sm-4">
  12 + <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" />
  13 + </div>
  14 + </div>
  15 + <div class="form-group">
  16 + <label for="c-mobile" class="control-label col-xs-12 col-sm-2">{:__('Mobile')}:</label>
  17 + <div class="col-xs-12 col-sm-4">
  18 + <input id="c-mobile" data-rule="" class="form-control" name="row[mobile]" type="text" value="">
  19 + </div>
  20 + </div>
  21 + <div class="form-group">
  22 + <label for="c-avatar" class="control-label col-xs-12 col-sm-2">{:__('Avatar')}:</label>
  23 + <div class="col-xs-12 col-sm-8">
  24 + <div class="input-group">
  25 + <input id="c-avatar" data-rule="" class="form-control" size="50" name="row[avatar]" type="text" value="">
  26 + <div class="input-group-addon no-border no-padding">
  27 + <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>
  28 + <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>
  29 + </div>
  30 + <span class="msg-box n-right" for="c-avatar"></span>
  31 + </div>
  32 + <ul class="row list-inline plupload-preview" id="p-avatar"></ul>
  33 + </div>
  34 + </div>
  35 + <div class="form-group layer-footer">
  36 + <label class="control-label col-xs-12 col-sm-2"></label>
  37 + <div class="col-xs-12 col-sm-8">
  38 + <button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
  39 + <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
  40 + </div>
  41 + </div>
  42 +</form>
@@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
6 <div class="tab-pane fade active in" id="one"> 6 <div class="tab-pane fade active in" id="one">
7 <div class="widget-body no-padding"> 7 <div class="widget-body no-padding">
8 <div id="toolbar" class="toolbar"> 8 <div id="toolbar" class="toolbar">
9 - {:build_toolbar('refresh,edit,del')} 9 + {:build_toolbar('refresh,add,edit,del')}
10 <div class="dropdown btn-group {:$auth->check('user/user/multi')?'':'hide'}"> 10 <div class="dropdown btn-group {:$auth->check('user/user/multi')?'':'hide'}">
11 <a class="btn btn-primary btn-more dropdown-toggle btn-disabled disabled" data-toggle="dropdown"><i class="fa fa-cog"></i> {:__('More')}</a> 11 <a class="btn btn-primary btn-more dropdown-toggle btn-disabled disabled" data-toggle="dropdown"><i class="fa fa-cog"></i> {:__('More')}</a>
12 <ul class="dropdown-menu text-left" role="menu"> 12 <ul class="dropdown-menu text-left" role="menu">
@@ -838,7 +838,7 @@ class Index extends Api @@ -838,7 +838,7 @@ class Index extends Api
838 $tiao['a.user_id'] = ['eq',$user_id]; 838 $tiao['a.user_id'] = ['eq',$user_id];
839 $tiao['b.is_up'] = 1; 839 $tiao['b.is_up'] = 1;
840 $myfile = $this->myfile($type_id,$where); 840 $myfile = $this->myfile($type_id,$where);
841 - $zhuan = $this->zhuan($type_id,$tiao,1); 841 + $zhuan = $this->zhuan($type_id,$tiao);
842 $gong = $this->gong($type_id,$myfile,$zhuan); 842 $gong = $this->gong($type_id,$myfile,$zhuan);
843 $sundry = $this->sundry($gong); 843 $sundry = $this->sundry($gong);
844 $this->success('success',$sundry); 844 $this->success('success',$sundry);
@@ -44,7 +44,7 @@ @@ -44,7 +44,7 @@
44 {else /} 44 {else /}
45 {foreach $data.folder as $vo} 45 {foreach $data.folder as $vo}
46 <div class="file-item"> 46 <div class="file-item">
47 - <div class="time">{$vo.times}</div> 47 +<!-- <div class="time">{$vo.times}</div>-->
48 {foreach $vo.info as $val} 48 {foreach $vo.info as $val}
49 <a href="{:url('index/filedetail',array('file_id'=>$val.id))}"> 49 <a href="{:url('index/filedetail',array('file_id'=>$val.id))}">
50 <div class="file-item-bottom"> 50 <div class="file-item-bottom">
@@ -67,7 +67,7 @@ @@ -67,7 +67,7 @@
67 {else /} 67 {else /}
68 {foreach $data.note as $vo} 68 {foreach $data.note as $vo}
69 <div class="file-item"> 69 <div class="file-item">
70 - <div class="time">{$vo.times}</div> 70 +<!-- <div class="time">{$vo.times}</div>-->
71 {foreach $vo.info as $val} 71 {foreach $vo.info as $val}
72 <a href="{:url('index/detail',array('file_id'=>$val.id))}"> 72 <a href="{:url('index/detail',array('file_id'=>$val.id))}">
73 <div class="file-item-bottom"> 73 <div class="file-item-bottom">
@@ -86,7 +86,7 @@ @@ -86,7 +86,7 @@
86 {else /} 86 {else /}
87 {foreach $data.pic as $vo} 87 {foreach $data.pic as $vo}
88 <div class="file-item pic-item"> 88 <div class="file-item pic-item">
89 - <div class="time">{$vo.times}</div> 89 +<!-- <div class="time">{$vo.times}</div>-->
90 90
91 <div class="file-item-bottom pic"> 91 <div class="file-item-bottom pic">
92 {foreach $vo.info as $val} 92 {foreach $vo.info as $val}
@@ -106,7 +106,7 @@ @@ -106,7 +106,7 @@
106 {else /} 106 {else /}
107 {foreach $data.video as $vo} 107 {foreach $data.video as $vo}
108 <div class="file-item pic-item"> 108 <div class="file-item pic-item">
109 - <div class="time">{$vo.times}</div> 109 +<!-- <div class="time">{$vo.times}</div>-->
110 <div class="file-item-bottom pic"> 110 <div class="file-item-bottom pic">
111 {foreach $vo.info as $val} 111 {foreach $vo.info as $val}
112 <a href="{:url('index/detail',array('file_id'=>$val.id))}"> 112 <a href="{:url('index/detail',array('file_id'=>$val.id))}">