作者 何书鹏
1 个管道 的构建 通过 耗费 1 秒

合并分支 'heshupeng' 到 'master'

管理员公告管理



查看合并请求 !289
@@ -93,7 +93,11 @@ class House extends Api @@ -93,7 +93,11 @@ class House extends Api
93 $info['house_name'] = Db::name('house')->where('id',$data['house_id'])->value('name'); 93 $info['house_name'] = Db::name('house')->where('id',$data['house_id'])->value('name');
94 94
95 //查询该社区的社区公告 95 //查询该社区的社区公告
96 - $house_board = Db::name('house_board')->where('house_id',$data['house_id'])->order('createtime desc')->find(); 96 + $house_board = Db::name('house_board')
  97 + ->where('house_id',$data['house_id'])
  98 + ->where('deletetime','') //未下架
  99 + ->order('createtime desc')
  100 + ->find();
97 if(empty($house_board)){ 101 if(empty($house_board)){
98 $info['is_have'] = 2; 102 $info['is_have'] = 2;
99 $info['title'] = ''; 103 $info['title'] = '';
@@ -411,9 +411,38 @@ class HouseAdmin extends Api @@ -411,9 +411,38 @@ class HouseAdmin extends Api
411 $count >= 2 && $this->error('本周发布次数已用完'); 411 $count >= 2 && $this->error('本周发布次数已用完');
412 $images = $this->request->param('images/a'); 412 $images = $this->request->param('images/a');
413 $post['images'] = implode(',',$images); 413 $post['images'] = implode(',',$images);
414 - (new HouseBoard)->allowField(true)->save(array_merge([  
415 - 'admin_user_id' => $this->auth->id  
416 - ],$post)); 414 + Db::startTrans();
  415 + try{
  416 + (new HouseBoard)->allowField(true)->save(array_merge([
  417 + 'admin_user_id' => $this->auth->id
  418 + ],$post));
  419 + // 该社区下的业主ID
  420 + $user_id_arr = UserHouse::where('house_id',$post['house_id'])
  421 + ->where('status',2)
  422 + ->column('user_id');
  423 + // 发送模板消息
  424 + if(!empty($user_id_arr)){
  425 + $house_name = House::where('house_id',$post['house_id'])->value('name');
  426 + $send_data = array(
  427 + "first" => '您绑定的社区【'.$house_name.'】发布了一条公告',
  428 + 'keyword1' => $post['title'],
  429 + "keyword2" => date('Y-m-s H:i:s',time()),
  430 + "remark" => '',
  431 + );
  432 + foreach ($user_id_arr as $user_id) {
  433 + $openid = Db::name('third')->where('user_id',$user_id)->value('openid');
  434 + $url = config('option.vue_url') . '/messagelk?is_template=1&house_id='.$post['house_id'].'&user_id='.$user_id;
  435 + $this->wxsendmessage($openid,$send_data,config('option.template')['msg'],$url);
  436 + }
  437 + }
  438 + Db::commit();
  439 + } catch (PDOException $e) {
  440 + Db::rollback();
  441 + $this->error($e->getMessage());
  442 + } catch (Exception $e) {
  443 + Db::rollback();
  444 + $this->error($e->getMessage());
  445 + }
417 $this->success('success'); 446 $this->success('success');
418 } 447 }
419 448
@@ -910,10 +939,10 @@ class HouseAdmin extends Api @@ -910,10 +939,10 @@ class HouseAdmin extends Api
910 $post = $this->request->param(); 939 $post = $this->request->param();
911 empty($post['house_id']) && $this->error('缺少必要参数'); 940 empty($post['house_id']) && $this->error('缺少必要参数');
912 empty($post['name']) && $this->error('请填写标题'); 941 empty($post['name']) && $this->error('请填写标题');
913 - empty($post['phone']) && $this->error('请填写手机号'); 942 + empty($post['phone']) && $this->error('请填写电话');
914 empty($post['weigh']) && $this->error('请填写排序号'); 943 empty($post['weigh']) && $this->error('请填写排序号');
915 - if (!Validate::regex($post['phone'], "^1\d{10}$")) {  
916 - $this->error(__('Mobile is incorrect')); 944 + if (!Validate::regex($post['phone'], "^1\d{10}$") && !Validate::regex($post['phone'], "^([0-9]{3,4}-)?[0-9]{7,8}$")) {
  945 + $this->error('电话格式不正确');
917 } 946 }
918 $admin = HouseAdminModel::get(['user_id'=>$this->auth->id,'house_id'=>$post['house_id'],'is_direct'=>1]); 947 $admin = HouseAdminModel::get(['user_id'=>$this->auth->id,'house_id'=>$post['house_id'],'is_direct'=>1]);
919 empty($admin) && $this->error('您不是该小区的主管理员'); 948 empty($admin) && $this->error('您不是该小区的主管理员');
@@ -92,6 +92,7 @@ class HouseBoard extends Api @@ -92,6 +92,7 @@ class HouseBoard extends Api
92 /*最新公告信息*/ 92 /*最新公告信息*/
93 $house_board = Db::name('house_board') 93 $house_board = Db::name('house_board')
94 ->where('house_id',$data['house_id']) 94 ->where('house_id',$data['house_id'])
  95 + ->where('deletetime','') //未下架
95 ->order('createtime desc') 96 ->order('createtime desc')
96 ->field('id,title,content,look_num,createtime,images') 97 ->field('id,title,content,look_num,createtime,images')
97 ->find(); 98 ->find();
@@ -223,6 +224,7 @@ class HouseBoard extends Api @@ -223,6 +224,7 @@ class HouseBoard extends Api
223 ->count(); 224 ->count();
224 $data['info'] = Db::name('house_board') 225 $data['info'] = Db::name('house_board')
225 ->where('house_id',$house_id) 226 ->where('house_id',$house_id)
  227 + ->where('deletetime','') //未下架
226 ->order('weigh desc') 228 ->order('weigh desc')
227 ->page($page,$pageNum) 229 ->page($page,$pageNum)
228 ->select(); 230 ->select();