作者 杨育虎
1 个管道 的构建 通过 耗费 1 秒

ok

@@ -97,7 +97,6 @@ class House extends Backend @@ -97,7 +97,6 @@ class House extends Backend
97 $params['com_number'] = $data['num'] + 1; 97 $params['com_number'] = $data['num'] + 1;
98 } 98 }
99 99
100 -  
101 if ($this->dataLimit && $this->dataLimitFieldAutoFill) { 100 if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
102 $params[$this->dataLimitField] = $this->auth->id; 101 $params[$this->dataLimitField] = $this->auth->id;
103 } 102 }
@@ -114,6 +113,9 @@ class House extends Backend @@ -114,6 +113,9 @@ class House extends Backend
114 113
115 //小区id 114 //小区id
116 $house_id = $this->model->getLastInsID(); 115 $house_id = $this->model->getLastInsID();
  116 + $data = Db::name('house')->where('id',$house_id)->find();
  117 +
  118 + Db::name('house_admin')->where('id',$data['admin_user_id'])->update(['house_id'=>$house_id]);
117 $url = request()->domain().'/index/index/hourse?id='.$house_id; 119 $url = request()->domain().'/index/index/hourse?id='.$house_id;
118 120
119 //生成二维码 121 //生成二维码
@@ -171,6 +173,9 @@ class House extends Backend @@ -171,6 +173,9 @@ class House extends Backend
171 $row->validateFailException(true)->validate($validate); 173 $row->validateFailException(true)->validate($validate);
172 } 174 }
173 $result = $row->allowField(true)->save($params); 175 $result = $row->allowField(true)->save($params);
  176 + $data = Db::name('house')->where('id',$ids)->find();
  177 + Db::name('house_admin')->where('id',$data['admin_user_id'])->update(['house_id'=>$ids]);
  178 +
174 Db::commit(); 179 Db::commit();
175 } catch (ValidateException $e) { 180 } catch (ValidateException $e) {
176 Db::rollback(); 181 Db::rollback();
@@ -61,6 +61,7 @@ class HouseAdmin extends Backend @@ -61,6 +61,7 @@ class HouseAdmin extends Backend
61 $list = collection($list)->toArray(); 61 $list = collection($list)->toArray();
62 foreach ($list as &$v){ 62 foreach ($list as &$v){
63 $v['user_id'] = Db::name('user')->where('id',$v['user_id'])->value('nickname'); 63 $v['user_id'] = Db::name('user')->where('id',$v['user_id'])->value('nickname');
  64 + $v['house_id'] = Db::name('house')->where('id',$v['house_id'])->value('name');
64 } 65 }
65 $result = array("total" => $total, "rows" => $list); 66 $result = array("total" => $total, "rows" => $list);
66 67
@@ -79,13 +80,6 @@ class HouseAdmin extends Backend @@ -79,13 +80,6 @@ class HouseAdmin extends Backend
79 $params = $this->request->post("row/a"); 80 $params = $this->request->post("row/a");
80 if ($params) { 81 if ($params) {
81 $params = $this->preExcludeFields($params); 82 $params = $this->preExcludeFields($params);
82 -  
83 - $data = Db::name('user')  
84 - ->where('id',$params['user_id'])  
85 - ->field('id,id_num')  
86 - ->find();  
87 - $params['number'] = $data['id_num'];  
88 -  
89 if ($this->dataLimit && $this->dataLimitFieldAutoFill) { 83 if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
90 $params[$this->dataLimitField] = $this->auth->id; 84 $params[$this->dataLimitField] = $this->auth->id;
91 } 85 }
@@ -99,6 +93,14 @@ class HouseAdmin extends Backend @@ -99,6 +93,14 @@ class HouseAdmin extends Backend
99 $this->model->validateFailException(true)->validate($validate); 93 $this->model->validateFailException(true)->validate($validate);
100 } 94 }
101 $result = $this->model->allowField(true)->save($params); 95 $result = $this->model->allowField(true)->save($params);
  96 +
  97 +// $house_admin_id = $this->model->getLastInsID();
  98 +//
  99 +// $data = Db::name('house_admin')->where('id',$house_admin_id)->find();
  100 +// if(!empty($data['user_id'])){
  101 +// Db::name('user')->where('id',$data['user_id'])->update(['identity'=>1]);
  102 +// }
  103 +
102 Db::commit(); 104 Db::commit();
103 } catch (ValidateException $e) { 105 } catch (ValidateException $e) {
104 Db::rollback(); 106 Db::rollback();
@@ -141,11 +143,6 @@ class HouseAdmin extends Backend @@ -141,11 +143,6 @@ class HouseAdmin extends Backend
141 if ($params) { 143 if ($params) {
142 $params = $this->preExcludeFields($params); 144 $params = $this->preExcludeFields($params);
143 145
144 - $data = Db::name('user')  
145 - ->where('id',$params['user_id'])  
146 - ->field('id,id_num')  
147 - ->find();  
148 - $params['number'] = $data['id_num'];  
149 146
150 $result = false; 147 $result = false;
151 Db::startTrans(); 148 Db::startTrans();
@@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
3 <div class="form-group"> 3 <div class="form-group">
4 <label class="control-label col-xs-12 col-sm-2">{:__('Admin_user_id')}:</label> 4 <label class="control-label col-xs-12 col-sm-2">{:__('Admin_user_id')}:</label>
5 <div class="col-xs-12 col-sm-8"> 5 <div class="col-xs-12 col-sm-8">
6 - <input id="c-admin_user_id" data-source="house_admin/index" class="form-control selectpage" name="row[admin_user_id]" type="text" value=""> 6 + <input id="c-admin_user_id" data-rule="required" data-source="house_admin/index" class="form-control selectpage" name="row[admin_user_id]" type="text" value="">
7 </div> 7 </div>
8 </div> 8 </div>
9 <div class="form-group"> 9 <div class="form-group">
@@ -24,20 +24,20 @@ @@ -24,20 +24,20 @@
24 <input id="c-phone" class="form-control" name="row[phone]" type="text"> 24 <input id="c-phone" class="form-control" name="row[phone]" type="text">
25 </div> 25 </div>
26 </div> 26 </div>
27 - <div class="form-group">  
28 - <label class="control-label col-xs-12 col-sm-2">{:__('Image')}:</label>  
29 - <div class="col-xs-12 col-sm-8">  
30 - <div class="input-group">  
31 - <input id="c-image" class="form-control" size="50" name="row[image]" type="text">  
32 - <div class="input-group-addon no-border no-padding">  
33 - <span><button type="button" id="plupload-image" class="btn btn-danger plupload" data-input-id="c-image" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/bmp" data-multiple="false" data-preview-id="p-image"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>  
34 - <span><button type="button" id="fachoose-image" class="btn btn-primary fachoose" data-input-id="c-image" data-mimetype="image/*" data-multiple="false"><i class="fa fa-list"></i> {:__('Choose')}</button></span>  
35 - </div>  
36 - <span class="msg-box n-right" for="c-image"></span>  
37 - </div>  
38 - <ul class="row list-inline plupload-preview" id="p-image"></ul>  
39 - </div>  
40 - </div> 27 + <!--<div class="form-group">-->
  28 + <!--<label class="control-label col-xs-12 col-sm-2">{:__('Image')}:</label>-->
  29 + <!--<div class="col-xs-12 col-sm-8">-->
  30 + <!--<div class="input-group">-->
  31 + <!--<input id="c-image" class="form-control" size="50" name="row[image]" type="text">-->
  32 + <!--<div class="input-group-addon no-border no-padding">-->
  33 + <!--<span><button type="button" id="plupload-image" class="btn btn-danger plupload" data-input-id="c-image" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/bmp" data-multiple="false" data-preview-id="p-image"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>-->
  34 + <!--<span><button type="button" id="fachoose-image" class="btn btn-primary fachoose" data-input-id="c-image" data-mimetype="image/*" data-multiple="false"><i class="fa fa-list"></i> {:__('Choose')}</button></span>-->
  35 + <!--</div>-->
  36 + <!--<span class="msg-box n-right" for="c-image"></span>-->
  37 + <!--</div>-->
  38 + <!--<ul class="row list-inline plupload-preview" id="p-image"></ul>-->
  39 + <!--</div>-->
  40 + <!--</div>-->
41 <div class="form-group layer-footer"> 41 <div class="form-group layer-footer">
42 <label class="control-label col-xs-12 col-sm-2"></label> 42 <label class="control-label col-xs-12 col-sm-2"></label>
43 <div class="col-xs-12 col-sm-8"> 43 <div class="col-xs-12 col-sm-8">
1 <form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action=""> 1 <form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
2 2
3 -  
4 -  
5 <div class="form-group"> 3 <div class="form-group">
6 <label class="control-label col-xs-12 col-sm-2">{:__('用户id')}:</label> 4 <label class="control-label col-xs-12 col-sm-2">{:__('用户id')}:</label>
7 <div class="col-xs-12 col-sm-8"> 5 <div class="col-xs-12 col-sm-8">
8 <input id="c-user_id" data-rule="required" data-source="user/user/index" data-field="nickname" class="form-control selectpage" name="row[user_id]" type="text" value="{$row.user_id}"> 6 <input id="c-user_id" data-rule="required" data-source="user/user/index" data-field="nickname" class="form-control selectpage" name="row[user_id]" type="text" value="{$row.user_id}">
9 </div> 7 </div>
10 </div> 8 </div>
11 - <!--<div class="form-group">-->  
12 - <!--<label class="control-label col-xs-12 col-sm-2">{:__('Number')}:</label>-->  
13 - <!--<div class="col-xs-12 col-sm-8">-->  
14 - <!--<input id="c-number" class="form-control" name="row[number]" type="number" value="{$row.number|htmlentities}">-->  
15 - <!--</div>-->  
16 - <!--</div>-->  
17 <div class="form-group"> 9 <div class="form-group">
18 <label class="control-label col-xs-12 col-sm-2">{:__('Name')}:</label> 10 <label class="control-label col-xs-12 col-sm-2">{:__('Name')}:</label>
19 <div class="col-xs-12 col-sm-8"> 11 <div class="col-xs-12 col-sm-8">
@@ -26,20 +18,6 @@ @@ -26,20 +18,6 @@
26 <input id="c-phone" class="form-control" name="row[phone]" type="text" value="{$row.phone|htmlentities}"> 18 <input id="c-phone" class="form-control" name="row[phone]" type="text" value="{$row.phone|htmlentities}">
27 </div> 19 </div>
28 </div> 20 </div>
29 - <div class="form-group">  
30 - <label class="control-label col-xs-12 col-sm-2">{:__('Image')}:</label>  
31 - <div class="col-xs-12 col-sm-8">  
32 - <div class="input-group">  
33 - <input id="c-image" class="form-control" size="50" name="row[image]" type="text" value="{$row.image|htmlentities}">  
34 - <div class="input-group-addon no-border no-padding">  
35 - <span><button type="button" id="plupload-image" class="btn btn-danger plupload" data-input-id="c-image" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/bmp" data-multiple="false" data-preview-id="p-image"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>  
36 - <span><button type="button" id="fachoose-image" class="btn btn-primary fachoose" data-input-id="c-image" data-mimetype="image/*" data-multiple="false"><i class="fa fa-list"></i> {:__('Choose')}</button></span>  
37 - </div>  
38 - <span class="msg-box n-right" for="c-image"></span>  
39 - </div>  
40 - <ul class="row list-inline plupload-preview" id="p-image"></ul>  
41 - </div>  
42 - </div>  
43 <div class="form-group layer-footer"> 21 <div class="form-group layer-footer">
44 <label class="control-label col-xs-12 col-sm-2"></label> 22 <label class="control-label col-xs-12 col-sm-2"></label>
45 <div class="col-xs-12 col-sm-8"> 23 <div class="col-xs-12 col-sm-8">
@@ -12,8 +12,8 @@ namespace app\api\controller; @@ -12,8 +12,8 @@ namespace app\api\controller;
12 use app\common\controller\Api; 12 use app\common\controller\Api;
13 use think\Cache; 13 use think\Cache;
14 use think\Db; 14 use think\Db;
15 -  
16 -/** 15 +use think\Validate;
  16 + /**
17 * 社区首页 17 * 社区首页
18 */ 18 */
19 class House extends Api 19 class House extends Api
@@ -117,9 +117,8 @@ class House extends Api @@ -117,9 +117,8 @@ class House extends Api
117 $info['is_new'] = 1; 117 $info['is_new'] = 1;
118 } 118 }
119 } 119 }
120 - $this->success('success',$info);  
121 -  
122 } 120 }
  121 + $this->success('success',$info);
123 } 122 }
124 123
125 /** 124 /**
@@ -399,6 +398,9 @@ class House extends Api @@ -399,6 +398,9 @@ class House extends Api
399 * @ApiMethod (POST) 398 * @ApiMethod (POST)
400 * @ApiRoute (/api/house/city_list) 399 * @ApiRoute (/api/house/city_list)
401 * 400 *
  401 + * @ApiParams (name="page", type="inter", required=false, description="当前页(默认1)")
  402 + * @ApiParams (name="pageNum", type="inter", required=false, description="每页显示数据个数(默认10)")
  403 + *
402 * @ApiReturn({ 404 * @ApiReturn({
403 "code": 1, 405 "code": 1,
404 "msg": "成功", 406 "msg": "成功",
@@ -413,7 +415,10 @@ class House extends Api @@ -413,7 +415,10 @@ class House extends Api
413 */ 415 */
414 public function city_list() 416 public function city_list()
415 { 417 {
416 - $data = Db::name('area')->field('id,name')->where('level',2)->select(); 418 +// $page = $this->request->param('page', 1, 'intval');
  419 +// $pageNum = $this->request->param('pageNum', 10, 'intval');
  420 + $data['total_num'] = Db::name('area')->field('id,name')->where('level',2)->count();
  421 + $data['info'] = Db::name('area')->field('id,name')->where('level',2)->select();
417 $this->success('success',$data); 422 $this->success('success',$data);
418 423
419 } 424 }
@@ -561,7 +566,7 @@ class House extends Api @@ -561,7 +566,7 @@ class House extends Api
561 * @ApiTitle (获取验证码) 566 * @ApiTitle (获取验证码)
562 * @ApiSummary (获取验证码) 567 * @ApiSummary (获取验证码)
563 * @ApiMethod (POST) 568 * @ApiMethod (POST)
564 - * @ApiRoute (/api/login/getcode) 569 + * @ApiRoute (/api/house/getcode)
565 * @ApiHeaders (name=token, type=string, required=true, description="请求的Token") 570 * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
566 * 571 *
567 * @ApiParams (name="mobile", type="string", required=false, description="手机号") 572 * @ApiParams (name="mobile", type="string", required=false, description="手机号")
@@ -605,7 +610,7 @@ class House extends Api @@ -605,7 +610,7 @@ class House extends Api
605 * @ApiTitle (验证验证码) 610 * @ApiTitle (验证验证码)
606 * @ApiSummary (验证验证码) 611 * @ApiSummary (验证验证码)
607 * @ApiMethod (POST) 612 * @ApiMethod (POST)
608 - * @ApiRoute (/api/login/verify) 613 + * @ApiRoute (/api/house/verify)
609 * @ApiHeaders (name=token, type=string, required=true, description="请求的Token") 614 * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
610 * 615 *
611 * @ApiParams (name="mobile", type="string", required=true, description="手机号") 616 * @ApiParams (name="mobile", type="string", required=true, description="手机号")
@@ -638,4 +643,140 @@ class House extends Api @@ -638,4 +643,140 @@ class House extends Api
638 } 643 }
639 644
640 } 645 }
  646 +
  647 +
  648 + /**
  649 + * @ApiTitle (社区物业管理员列表)
  650 + * @ApiSummary (社区物业管理员列表)
  651 + * @ApiMethod (POST)
  652 + * @ApiRoute (/api/house/house_admin_list)
  653 + *
  654 + * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  655 + * @ApiParams (name="house_id", type="string", required=true, description="小区id")
  656 + *
  657 + * @ApiReturn({
  658 + "code": 1,
  659 + "msg": "成功",
  660 + "time": "1571492001",
  661 + "data": {
  662 + "id"://id
  663 + "user_id"://用户id
  664 + "avatar"://管理员头像
  665 + "nickname"://昵称
  666 + "is_have"://是否带有红标签 1有2没有
  667 + }
  668 + })
  669 + */
  670 + public function house_admin_list()
  671 + {
  672 + $user_id = $this->auth->id;
  673 + $house_id = $this->request->param('house_id');
  674 + if(empty($house_id)){
  675 + $this->error('缺少必要参数');
  676 + }
  677 +
  678 + $data = Db::name('house_admin')
  679 + ->alias('a')
  680 + ->join('user b','a.user_id = b.id')
  681 + ->where('a.house_id',$house_id)
  682 + ->field('a.id,a.user_id,b.avatar,b.nickname')
  683 + ->order('a.direct')
  684 + ->select();
  685 + foreach ($data as &$v){
  686 + $mes = Db::name('message')
  687 + ->where('house_id',$house_id)
  688 + ->where('user_id',$v['user_id'])
  689 + ->where('to_user_id',$user_id)
  690 + ->where('is_read',2)
  691 + ->find();
  692 + if(empty($mes)){
  693 + $v['is_have'] = 2;
  694 + }else{
  695 + $v['is_have'] = 1;
  696 + }
  697 + }
  698 + $this->success('success',$data);
  699 + }
  700 +
  701 + /**
  702 + * @ApiTitle (聊天记录列表)
  703 + * @ApiSummary (聊天记录列表)
  704 + * @ApiMethod (POST)
  705 + * @ApiRoute (/api/house/chat_record)
  706 + *
  707 + * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  708 + * @ApiParams (name="house_id", type="inter", required=true, description="社区id")
  709 + * @ApiParams (name="user_id", type="inter", required=true, description="社区物业管理员用户id")
  710 + *
  711 + * @ApiReturn({
  712 + "code": 1,
  713 + "msg": "成功",
  714 + "time": "1571492001",
  715 + "data": {
  716 + "id"://id
  717 + "user_id"://发送者id
  718 + "house_id"://社区id
  719 + "to_user_id"://接收者用户id
  720 + "type"://消息类型1文字类型2图片类型
  721 + "content"://文字消息
  722 + "image"://图片消息
  723 + "is_read"://是否已读1已读2未读
  724 + "createtime"://创建时间
  725 + "updatetime"://修改时间
  726 + "nickname"://昵称
  727 + "is_have"://是否带有红标签 1有2没有
  728 + "is_left"://是否在右边 1是2否
  729 + }
  730 + })
  731 + */
  732 + public function chat_record()
  733 + {
  734 + $qiniu = get_addon_config('qiniu')['cdnurl'];
  735 + $user_id = $this->auth->id; //当前登录用户id
  736 + $house_id = $this->request->param('house_id'); //社区id
  737 + $wuye_user_id = $this->request->param('user_id'); //物业用户id
  738 + if(empty($house_id) || empty($wuye_user_id)){
  739 + $this->error('缺少必要参数');
  740 + }
  741 +
  742 + $house_admin = Db::name('house_admin')->where('user_id',$wuye_user_id)->where('house_id',$house_id)->find();
  743 + if(empty($house_admin)){
  744 + $this->error('参数有误,社区与管理员id不匹配');
  745 + }
  746 +
  747 + $data = Db::name('message')
  748 + ->where('house_id',$house_id)
  749 + ->where('user_id',$user_id)
  750 + ->where('to_user_id',$wuye_user_id)
  751 + ->order('createtime desc')
  752 + ->select();
  753 + foreach ($data as &$v){
  754 + $v['is_right'] = 1;
  755 + if($v['type'] == 2){
  756 + $v['image'] = $qiniu.$v['image'];
  757 + }
  758 + }
  759 + $arr = Db::name('message')
  760 + ->where('house_id',$house_id)
  761 + ->where('user_id',$wuye_user_id)
  762 + ->where('to_user_id',$user_id)
  763 + ->order('createtime desc')
  764 + ->select();
  765 + foreach ($arr as &$v){
  766 + $v['is_right'] = 2;
  767 + if($v['type'] == 2){
  768 + $v['image'] = $qiniu.$v['image'];
  769 + }
  770 + }
  771 +
  772 + $info = array_merge($data,$arr);
  773 +
  774 + array_multisort(array_column($info,'createtime'),SORT_DESC,$info);
  775 + foreach ($info as &$val){
  776 + $val['createtime'] = date('Y-m-d H:i:s',$val['createtime']);
  777 + }
  778 +
  779 + $this->success('success',$info);
  780 +
  781 + }
641 } 782 }
此 diff 太大无法显示。
@@ -25,11 +25,12 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin @@ -25,11 +25,12 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
25 [ 25 [
26 {checkbox: true}, 26 {checkbox: true},
27 {field: 'id', title: __('Id'), operate:false}, 27 {field: 'id', title: __('Id'), operate:false},
28 - {field: 'user_id', title: __('用户id'), operate:false},  
29 - {field: 'number', title: __('Number'), operate:false}, 28 + {field: 'user_id', title: __('用户昵称'), operate:false},
  29 + {field: 'house_id', title: __('社区名称'), operate:false},
30 {field: 'name', title: __('Name'), operate:'like'}, 30 {field: 'name', title: __('Name'), operate:'like'},
31 {field: 'phone', title: __('Phone')}, 31 {field: 'phone', title: __('Phone')},
32 - {field: 'image', title: __('Image'), events: Table.api.events.image, formatter: Table.api.formatter.image}, 32 + {field: 'is_direct', title: __('管理员类型'), searchList: {"1":"主管理员","2":'子管理员'},formatter: Table.api.formatter.status},
  33 + // {field: 'image', title: __('Image'), events: Table.api.events.image, formatter: Table.api.formatter.image},
33 {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime}, 34 {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
34 // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime}, 35 // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
35 {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate} 36 {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}