浏览代码

modify room info and add room changed

stanley-king 6 年之前
父节点
当前提交
b8daa39057

+ 13 - 0
data/logic/queue.logic.php

@@ -26,6 +26,7 @@ require_once (BASE_ROOT_PATH . '/helper/stat_helper.php');
 require_once (BASE_ROOT_PATH . '/helper/message/publisher.php');
 require_once (BASE_ROOT_PATH . '/helper/search/tcp_client.php');
 require_once (BASE_ROOT_PATH . '/helper/ugc_helper.php');
+require_once (BASE_ROOT_PATH . '/helper/room_helper.php');
 
 class queueLogic
 {
@@ -842,4 +843,16 @@ class queueLogic
             return callback($ret);
         }
     }
+    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+    public function OnUpdateRoom($param)
+    {
+        $roomid = intval($param['room_id']);
+        if($roomid <= 0) {
+            return callback(false);
+        }
+        else {
+            $ret = room_helper::OnUpdateRoom($roomid);
+            return callback($ret);
+        }
+    }
 }

+ 7 - 2
data/model/room.model.php

@@ -19,7 +19,7 @@ class roomModel extends Model
     {
         return $this->table('room_participant')->field('*')->where(['room_id' => $room_id,'state' => 0])->limit(false)->select();
     }
-    public function getPartRooms($cond,$field = '*',$limit = false,$order='invite_time asc') {
+    public function getRoomParts($cond,$field = '*',$limit = false,$order='invite_time asc') {
         if(!isset($cond['state'])) $cond['state'] = 0;
         return  $this->table('room_participant')->field($field)->where($cond)->order($order)->limit($limit)->select();
     }
@@ -40,15 +40,19 @@ class roomModel extends Model
         $ret = $this->table('room_participant')->where(['room_id' => $room_id,'member_id' => $user])->update(['member_nick' => $member_nick]);
         return $ret;
     }
+
     ///群聊接口//////////////////////////////////////////////////////////////////////////////////////////////////////////
     public function create_room($type,$name,$creator,$owner,$owner_name,$max_user = 0) {
         $params = ['type' => $type,'room_name' => $name,'room_creator' => $creator,'room_owner' => $owner,'owner_name' => $owner_name,'max_user' => $max_user,'add_time' => time()];
         return $this->table('room')->insert($params);
     }
-    public function edit_room($cond,$update)
+    public function editRoom($cond,$update)
     {
         return $this->table('room')->where($cond)->update($update);
     }
+    public function edit($condition,$data) {
+        return $this->table('room')->where($condition)->update($data);
+    }
 
     public function getRoom($roomid) {
         return $this->table('room')->field('*')->where(['room_id' => $roomid])->limit(1)->find();
@@ -60,6 +64,7 @@ class roomModel extends Model
     public function getRooms($cond,$field = '*') {
         return $this->table('room')->field($field)->where($cond)->select();
     }
+
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     public function findChatid($left,$right,$lock=false)
     {

+ 1 - 1
helper/bonus/grab.php

@@ -67,7 +67,7 @@ class general_grab extends IGrab
                 {
                     $bonus_val = $user_bonus->bonus_value();
                     Model('bonus_type')->edit(array('type_id' => $type_id),
-                        array('grabed_num'    => array('exp', 'grabed_num+1'),
+                        array('grabed_num'  => array('exp', 'grabed_num+1'),
                             'binded_num'    => array('exp', 'binded_num+1'),
                             'remain_amount' => array('exp', "remain_amount-{$bonus_val}")));
                 }

+ 9 - 0
helper/model/member_info.php

@@ -65,6 +65,11 @@ class member_info
 
         return $name;
     }
+
+    public function hasNickname()
+    {
+        return !empty($this->member_info['member_nickname']) || !empty($this->member_info['member_truename']);
+    }
     public function mobile()
     {
         if($this->binded_mobile()) {
@@ -112,6 +117,10 @@ class member_info
             return $url;
         }
     }
+    public function hasAvatar() {
+        return !empty($this->member_info['member_avatar']);
+    }
+
     public function available_bonus()
     {
         if(is_null($this->member_info['available_bonus']) || empty($this->member_info['available_bonus'])) {

+ 17 - 10
helper/room/base_room.php

@@ -24,7 +24,6 @@ abstract class base_room
     public function __construct($cinfos, $participants = [])
     {
         $this->mRoomInfo = new room_info($cinfos);
-
         $this->mRoomid = $this->room_id();
 
         $this->mRelayMsgs['reply'] = [];        //转发回复包
@@ -46,10 +45,7 @@ abstract class base_room
     public function room_name() {
         return $this->mRoomInfo->name();
     }
-//    private function notify_change()
-//    {
-//        $name =
-//    }
+
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     public function invite($inviter,$invitees,&$newusers)
     {
@@ -58,11 +54,11 @@ abstract class base_room
         {
             $users = $this->add($inviter,$invitees,$newusers);
             if($users === false) {
-                $ret = ['room' => $this->mRoomid,'invitees' => []];
+                $ret = ['room' => $this->mRoomid,'invitees' => [],'newusers' => []];
             }
             else
             {
-                $ret = ['room' => $this->mRoomid,'invitees' => $users];
+                $ret = ['room' => $this->mRoomid,'invitees' => $users,'newusers' => $newusers];
                 if(!empty($newusers)) {
                     $content = $this->format_invite($inviter,$newusers);
                     $this->relay_broadcast('message',['msgid' => -1,'type' => proto_type::msg_stype_plain,'content' => $content,'send_time' => time()]);
@@ -75,6 +71,9 @@ abstract class base_room
         }
     }
 
+    public function usercount() {
+        return count($this->mParticipants);
+    }
     public function kickout($manager,$users)
     {
         $fadmin = $this->mRoomInfo->isAdmin($manager);
@@ -146,8 +145,7 @@ abstract class base_room
 
                 $ret = $this->mod_room->invite($this->room_id(),$invitee,$inviter);
                 if($ret == false) {
-                    Log::record(__METHOD__ . " room invite user fail on db Error",Log::ERR);
-                    return false;
+                    continue;
                 }
                 else {
                     $user = $users[$invitee];
@@ -161,9 +159,18 @@ abstract class base_room
             }
         }
 
-        return $result;
+        return empty($result) ? false : $result;
     }
 
+    public function change()
+    {
+        $mod_room = Model('room');
+        $item = $mod_room->getRoom($this->room_id());
+        if(empty($item)) return false;
+
+        $this->mRoomInfo = new room_info($item);
+        return true;
+    }
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     public function leave($userid)
     {

+ 14 - 0
helper/room/factory_client.php

@@ -128,6 +128,20 @@ class factory_client extends tcp_client
             return $result['data'];
         }
     }
+    public function change($roomid)
+    {
+        $param = ["act" => 'fcgi','op' => 'change','room' => $roomid];
+        $result = $this->request($param);
+        if(empty($result)) return false;
+
+        $code = intval($result['code']);
+        if($code != 200) {
+            return false;
+        }
+        else {
+            return $result['data'];
+        }
+    }
 
     public function push($content)
     {

+ 82 - 40
helper/room/factory_processor.php

@@ -105,7 +105,6 @@ class factory_processor implements IProcessor
         if($op == 'create')
         {
             $ret = $this->mFactory->create($input,$fnew);
-
             if($ret != false)
             {
                 $invite  = $input['invite'];
@@ -117,8 +116,11 @@ class factory_processor implements IProcessor
                     if($roomid <= 0 || $inviter <= 0) {
                         return $this->error(errcode::ErrRoomCreate);
                     }
+                    if($this->build($roomid,$fnew) == false) {
+                        return $this->error(errcode::ErrRoomBuild);
+                    }
 
-                    $result = $this->invite($roomid,$inviter,[$inviter],$fnew);
+                    $result = $this->invite($roomid,$inviter,[$inviter]);
                     if($result != false) {
                         $ret = array_merge($ret,$result);
                         return $this->success($ret);
@@ -127,10 +129,9 @@ class factory_processor implements IProcessor
                     }
                 }
                 else {
-                    return $this->success($ret);
+                    return $this->error(errcode::ErrRoomCreate);
                 }
             }
-
             return $this->error(errcode::ErrRoomCreate);
         }
         elseif($op == 'invite')
@@ -143,6 +144,11 @@ class factory_processor implements IProcessor
                 return $this->error(errcode::ErrRoomInvite);
             }
 
+            $client = $this->find_room($roomid,$bufid);
+            if($client == false) {
+                $this->build($roomid);
+            }
+
             $ret = $this->invite($roomid,$inviter,$invitees);
             if($ret != false) {
                 return $this->success($ret);
@@ -150,15 +156,37 @@ class factory_processor implements IProcessor
                 return $this->error(errcode::ErrRoomInvite);
             }
         }
+        elseif($op == 'change')
+        {
+            $roomid = intval($input['room']);
+            if($roomid <= 0) {
+                return $this->error(errcode::ErrRoomChange);
+            }
+
+            $client = $this->find_room($roomid,$bufid);
+            if($client == false) {
+                $this->build($roomid);
+            }
+            $ret = $this->change($roomid);
+            if($ret != false) {
+                return $this->success($ret);
+            } else {
+                return $this->error(errcode::ErrRoomChange);
+            }
+        }
         elseif($op == 'leave')
         {
             $roomid   = intval($input['room']);
             $user  = intval($input['user']);
 
             if($roomid <= 0 || $user <= 0) {
-                return $this->error(errcode::ErrRoomInvite);
+                return $this->error(errcode::ErrRoomLeave);
             }
 
+            $client = $this->find_room($roomid,$bufid);
+            if($client == false) {
+                $this->build($roomid);
+            }
             $ret = $this->leave($roomid,$user);
             if($ret != false) {
                 return $this->success($ret);
@@ -183,79 +211,93 @@ class factory_processor implements IProcessor
     private function onAccess($bufid,$input)
     {
         $op = $input['op'];
-        if($op == 'who') {
+        if($op == 'who')
+        {
             $this->mAccUniquer->add_value($bufid);
             return $this->success(['act' => proto_type::act_access,'op' => 'who']);
         }
-        elseif($op == 'build') {
+        elseif($op == 'build')
+        {
             $roomid = intval($input['room']);
-            $ret = $this->build($roomid);
+            $client = $this->find_room($roomid,$bufid);
+            if($client == false) {
+                $this->build($roomid);
+            }
             return $this->success(['act' => proto_type::act_access,'op' => $op,'room' => $roomid]);
         }
         else {
             return $this->error(errcode::ErrParamter);
         }
     }
+
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-    private function invite($roomid, $inviter,$invitees,$newroom)
+    private function find_room($roomid,&$outbufid)
     {
         foreach ($this->mBufidRooms as $bufid => $client)
         {
-            if($client->contain_room($roomid))
-            {
-                $this->block($bufid);
-                $ret = $client->invite($roomid,$inviter,$invitees,$newroom);
-                $this->unblock($bufid);
-
-                return $ret;
+            if($client->contain_room($roomid)) {
+                $outbufid = $bufid;
+                return $client;
             }
         }
 
+        return false;
+    }
+
+    private function build($roomid,$newroom = false)
+    {
+        $client = $this->find_room($roomid,$bufid);
+        if($client != false) {
+            $this->block($bufid);
+            $ret = $client->build($roomid,$newroom);
+            $this->unblock($bufid);
+
+            return $ret;
+        }
+
         $bufid = $this->room_bufid();
         if($bufid != false)
         {
             $client = $this->mBufidRooms[$bufid];
             $this->block($bufid);
-            $ret = $client->invite($roomid,$inviter,$invitees,$newroom);
+            $ret = $client->build($roomid,$newroom);
             $this->unblock($bufid);
 
             if($ret != false) {
                 $client->add_room($roomid);
             }
+            return $ret;
+        }
+        else {
+            return false;
         }
-
-        return $ret;
     }
-    private function build($roomid)
+
+    private function invite($roomid, $inviter,$invitees)
     {
-        foreach ($this->mBufidRooms as $bufid => $client)
-        {
-            if($client->contain_room($roomid))
-            {
-                $this->block($bufid);
-                $ret = $client->build($roomid);
-                $this->unblock($bufid);
+        $client = $this->find_room($roomid,$bufid);
+        if($client != false) {
+            $this->block($bufid);
+            $ret = $client->invite($roomid,$inviter,$invitees);
+            $this->unblock($bufid);
 
-                return $ret;
-            }
+            return $ret;
         }
 
-        $bufid = $this->room_bufid();
-        if($bufid != false)
-        {
-            $client = $this->mBufidRooms[$bufid];
+        return false;
+    }
+    private function change($roomid)
+    {
+        $client = $this->find_room($roomid,$bufid);
+        if($client != false) {
             $this->block($bufid);
-            $ret = $client->build($roomid);
+            $ret = $client->change($roomid);
             $this->unblock($bufid);
 
-            if($ret != false) {
-                $client->add_room($roomid);
-            }
             return $ret;
         }
-        else {
-            return false;
-        }
+
+        return false;
     }
 
     private function leave($roomid, $user)

+ 23 - 2
helper/room/msg_builder.php

@@ -53,8 +53,8 @@ class msg_builder
         $msg['op'] = "relay";
         $msg['relay_type'] = "users";
         $msg['receivers'] = $invitees;
-        $msg['room'] = 0;
-        $msg['receiver_type'] = proto_type::sroom_push;
+        $msg['room'] = $roomid;
+        $msg['receiver_type'] = proto_type::sroom_chat;
 
         $msg['body']['act'] = proto_type::act_room;
         $msg['body']['op'] = 'invited';
@@ -66,6 +66,27 @@ class msg_builder
         return $msg;
     }
 
+    public static function change_push($roomid, $room_info)
+    {
+        $msg = [];
+
+        $msg['msgtype'] = "message";
+        $msg['act'] = "room";
+        $msg['op'] = "relay";
+        $msg['relay_type'] = "room";
+        $msg['receivers'] = [];
+        $msg['room'] = $roomid;
+        $msg['receiver_type'] = proto_type::sroom_chat;
+
+        $msg['body']['act'] = proto_type::act_room;
+        $msg['body']['op'] = 'changed';
+        $msg['body']['msgtype'] = "message";
+        $msg['body']['room'] = $roomid;
+        $msg['body']['room_info'] = $room_info;
+
+        return $msg;
+    }
+
     public static function invite_message($roomid, $room_type, $invitees)
     {
         $msg['act'] = "room";

+ 125 - 0
helper/room/room_avatar.php

@@ -0,0 +1,125 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: stanley-king
+ * Date: 2018/8/14
+ * Time: 上午11:15
+ */
+
+namespace room;
+
+
+class room_avatar
+{
+    static $avatar_path = BASE_UPLOAD_PATH . '/room/avatars';
+    static $down_path  = BASE_UPLOAD_PATH . '/room/avatars/tmp';
+    static $avatar_url = BASE_SITE_URL . '/data/upload/room/avatars';
+
+    private $mRoomid;
+    private $mPath;
+    private $mDestImage;
+    private $mInImages;
+    private $mBaseName;
+    public function __construct($roomid)
+    {
+        $this->mRoomid = $roomid;
+        $this->mPath = self::$avatar_path . "/{$roomid}.png";
+        $this->mBaseName = "{$roomid}.png";
+        $this->mInImages = [];
+
+        $bgfile = self::$avatar_path . "/background.png";
+        $this->mDestImage = $this->create_image($bgfile);
+    }
+
+    public function make($avatars)
+    {
+        if(empty($avatars)) return false;
+        if(count($avatars) <= 0) return false;
+
+        foreach ($avatars as $avatar)
+        {
+            $pid = posix_getpid();
+            $filename = self::$down_path . "/{$pid}";
+            if(file_exists($filename)) unlink($filename);
+            exec("wget -O $filename $avatar");
+            $image = self::create_image($filename);
+            if(file_exists($filename)) unlink($filename);
+
+            if($image === false) continue;
+            $this->mInImages[] = $image;
+        }
+        $count = count($this->mInImages);
+        if($count <= 0) return false;
+
+        $posex = $this->layout($count);
+
+        $i = 0;
+        foreach ($this->mInImages as $image)
+        {
+            if($i >= count($posex)) break;
+            $pos = $posex[$i];
+            imagecopyresized($this->mDestImage, $image, $pos['x'], $pos['y'], 0, 0, $pos['cx'], $pos['cy'], imagesx($image),imagesy($image));
+            $i++;
+        }
+        $ret = imagepng($this->mDestImage, $this->mPath,0);
+        if($ret === false) return false;
+
+        return self::$avatar_url . "/{$this->mBaseName}";
+    }
+
+    private function layout($count)
+    {
+        $top_left = 0;
+        $top_right = 0;
+        $padding = 20;
+
+        $cx = 240;
+        $cy = 240;
+
+        $result = [];
+        $result[] = ["x" => $top_left + $padding,'y' => $top_right + $padding,'cx' => $cx,'cy' => $cy];
+        $result[] = ["x" => $top_left + $padding * 2 + $cx,'y' => $top_right + $padding,'cx' => $cx,'cy' => $cy];
+        $result[] = ["x" => $top_left + $padding * 3 + 2 * $cx,'y' => $top_right + $padding,'cx' => $cx,'cy' => $cy];
+
+        $result[] = ["x" => $top_left + $padding,'y' => $top_right + 2*$padding + $cy,'cx' => $cx,'cy' => $cy];
+        $result[] = ["x" => $top_left + $padding * 2 + $cx,'y' => $top_right + 2*$padding + $cy,'cx' => $cx,'cy' => $cy];
+        $result[] = ["x" => $top_left + $padding * 3 + 2 * $cx,'y' => $top_right + 2*$padding + $cy,'cx' => $cx,'cy' => $cy];
+
+        $result[] = ["x" => $top_left + $padding,'y' => $top_right + 3*$padding + 2*$cy,'cx' => $cx,'cy' => $cy];
+        $result[] = ["x" => $top_left + $padding * 2 + $cx,'y' => $top_right + 3*$padding + 2*$cy,'cx' => $cx,'cy' => $cy];
+        $result[] = ["x" => $top_left + $padding * 3 + 2 * $cx,'y' => $top_right + 3*$padding + 2*$cy,'cx' => $cx,'cy' => $cy];
+
+        return $result;
+    }
+
+
+    private static function create_image($file)
+    {
+
+        $imagetype = exif_imagetype($file);
+        if ($imagetype === false) {
+            return false;
+        }
+
+        switch ($imagetype)
+        {
+            case IMAGETYPE_GIF:
+                $image = @imagecreatefromgif($file);
+                break;
+            case IMAGETYPE_JPEG:
+            case IMAGETYPE_JPEG2000:
+                $image = @imagecreatefromjpeg($file);
+                break;
+            case IMAGETYPE_PNG:
+                $image = @imagecreatefrompng($file);
+                break;
+            case IMAGETYPE_BMP:
+                $image = @imagecreatefrombmp($file);
+                break;
+            default:
+                return false;
+        }
+
+        return $image;
+    }
+}

+ 20 - 4
helper/room/room_client.php

@@ -90,9 +90,9 @@ class room_client extends tcp_client
         return ['host' => $this->mHost,'port' => $this->mPort];
     }
 
-    public function build($roomid)
+    public function build($roomid,$newroom = false)
     {
-        $param = ["act" => 'factory','op' => 'build','room' => $roomid];
+        $param = ["act" => 'factory','op' => 'build','room' => $roomid,'newroom' => $newroom];
         $result = $this->request($param);
         if(empty($result)) return false;
 
@@ -104,9 +104,25 @@ class room_client extends tcp_client
             return $result['data'];
         }
     }
-    public function invite($roomid, $inviter,$invitees,$newroom = false)
+
+    public function change($roomid)
+    {
+        $param = ["act" => 'factory','op' => 'change','room' => $roomid];
+        $result = $this->request($param);
+        if(empty($result)) return false;
+
+        $code = intval($result['code']);
+        if($code != 200) {
+            return false;
+        }
+        else {
+            return $result['data'];
+        }
+    }
+
+    public function invite($roomid, $inviter,$invitees)
     {
-        $param = ["act" => 'factory','op' => 'invite','room' => $roomid,'inviter' => $inviter,'invitees' => $invitees,'newroom' => $newroom];
+        $param = ["act" => 'factory','op' => 'invite','room' => $roomid,'inviter' => $inviter,'invitees' => $invitees];
         $result = $this->request($param);
         if(empty($result)) return false;
 

+ 20 - 18
helper/room/room_info.php

@@ -21,28 +21,34 @@ class room_info
     public function type() {
         return intval($this->mParams['type']);
     }
-    public function avatar(){
+    public function avatar()
+    {
         $avatar = $this->mParams['avatar'];
         if(!empty($avatar)) return $avatar;
 
-        $tmp = $this->tmp_avatar();
-        if(!empty($tmp)) return $tmp;
+        return $this->tmp_avatar();
+    }
 
-        return "";
+    public function has_avatar() {
+        $avatar = $this->mParams['avatar'];
+        return (!empty($avatar));
     }
+    public function has_name() {
+        $name = $this->mParams['room_name'];
+        return (!empty($name));
+    }
+
     private function tmp_avatar(){
         return $this->mParams['tmp_avatar'];
     }
     public function name()
     {
-        $name = $this->mParams['room_name'];
-        if(!empty($name))
-            return $name;
+        if(!empty($this->mParams['room_name']))
+            return $this->mParams['room_name'];
         else
             return $this->tmp_name();
-
-//        return room_helper::use_tmp_name($this->mParams);
     }
+
     private function tmp_name() {
         return $this->mParams['tmp_name'];
     }
@@ -73,10 +79,10 @@ class room_info
         return intval($this->mParams['room_level']);
     }
     public function shared_bonus(){
-        return $this->mParams['shared_bonus'];
+        return doubleval($this->mParams['shared_bonus']);
     }
     public function notice(){
-        return $this->mParams['notice'];
+        return empty($this->mParams['notice']) ? "" : $this->mParams['notice'];
     }
     public function passwd(){
         return $this->mParams['passwd'];
@@ -88,14 +94,12 @@ class room_info
 
         return ($uid == $this->creator() || $uid == $this->owner());
     }
-
     public function format()
     {
         $ret = [];
 
         $ret['room_id'] = $this->room_id();
-        $ret['type']    = $this->type();
-        $ret['avatar'] = $this->avatar();
+        $ret['avatar']  = $this->avatar();
         $ret['name']    = $this->name();
         $ret['room_desc']    = $this->room_desc();
 
@@ -103,15 +107,13 @@ class room_info
         $ret['owner']    = $this->owner();
         $ret['owner_name']    = $this->owner_name();
 
-        $ret['max_user']    = $this->max_user();
-        $ret['room_time']    = $this->room_time();
         $ret['users']  = $this->user_count();
         $ret['level']  = $this->level();
 
         $ret['shared_bonus']    = $this->shared_bonus();
         $ret['notice']    = $this->notice();
-        $ret['passwd']    = $this->passwd();
 
         return $ret;
     }
-}
+}
+

+ 110 - 0
helper/room/room_parts.php

@@ -0,0 +1,110 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: stanley-king
+ * Date: 2018/8/13
+ * Time: 下午9:39
+ */
+
+namespace room;
+
+class part_info
+{
+    private $mParams;
+    public function __construct($params)
+    {
+        $this->mParams = $params;
+    }
+    public function inviter() {
+        return intval($this->mParams['inviter']);
+    }
+    public function member_id() {
+        return intval($this->mParams['member_id']);
+    }
+    public function room_nick() {
+        return intval($this->mParams['member_nick']);
+    }
+    public function room_id() {
+        return intval($this->mParams['room_id']);
+    }
+    public function format()
+    {
+        $ret['inviter'] = $this->inviter();
+        $ret['member_id'] = $this->member_id();
+        $ret['room_nick'] = $this->room_nick();
+        $ret['room_id']   = $this->room_id();
+
+        return $ret;
+    }
+}
+
+class room_parts
+{
+    private $mRoomID;
+    private $mModRoom;
+    public function __construct($roomid)
+    {
+        $this->mRoomID = $roomid;
+        $this->mModRoom = Model('room');
+    }
+
+    public function top_users($count)
+    {
+        $result = [];
+        $items = $this->mModRoom->getRoomParts(['room_id' => $this->mRoomID,'state' => 0],'*',$count);
+        foreach ($items as $part) {
+            $result[] = new part_info($part);
+        }
+
+        return $result;
+    }
+
+
+    public static function use_tmp_name($room)
+    {
+        $tmp_name = $room['tmp_name'];
+        $user_cnt = intval($room['users']);
+        //tmp_name can be use already
+        if (!empty($tmp_name)) {
+            $tmp_len = count(explode('、', $tmp_name));
+            if ($tmp_len > 3 || $tmp_len >= $user_cnt) {
+                return $tmp_name;
+            }
+        }
+
+        //create new tmp_name
+        $tmp_name = "";
+        $room_id = intval($room['room_id']);
+        $uids = self::room_uids($room_id, 4);
+        $names = Model('member')->field('member_nickname')->where(["member_id" => ["in", $uids]])->select();
+        foreach ($names as $name) {
+            $tmp_name .= $name['member_nickname'] . '、';
+        }
+        $tmp_name = trim($tmp_name, "、");
+
+        $cond = ["room_id" => $room['room_id']];
+        $update = ["tmp_name" => $tmp_name];
+
+        if (empty($ret)) $ret = '丽人丽妆';
+        $ret = Model("room")->editRoom($cond, $update);
+
+        if ($ret) {
+            return $tmp_name;
+        } else {
+            Log::record("room_name create faild room:" . json_encode($room));
+            return false;
+        }
+    }
+
+    public static function room_uids($roomid, $limit = false)
+    {
+        $uids = [];
+        $mod_room = Model('room');
+
+        $items = $mod_room->getRoomParts(["room_id" => $roomid, 'state' => 0], 'member_id', $limit);
+        foreach ($items as $item) {
+            $uids[] = $item['member_id'];
+        }
+        return $uids;
+    }
+}

+ 44 - 30
helper/room/room_processor.php

@@ -12,6 +12,7 @@ use event\IProcessor;
 use process_looper;
 use errcode;
 use algorithm;
+use QueueClient;
 
 class room_processor implements IProcessor
 {
@@ -85,6 +86,9 @@ class room_processor implements IProcessor
         elseif($op == 'invite') {
             return $this->factory_invite($input);
         }
+        elseif($op == 'change') {
+            return $this->factory_change($input);
+        }
         elseif($op == 'leave') {
             return $this->factory_leave($input);
         }
@@ -102,6 +106,8 @@ class room_processor implements IProcessor
     private function factory_build($input)
     {
         $roomid = intval($input['room']);
+        $newroom = boolval($input['newroom']);
+
         if ($roomid <= 0) {
             return $this->error(errcode::ErrRoomParam);
         }
@@ -112,9 +118,13 @@ class room_processor implements IProcessor
         $room = $this->mFactory->build($roomid);
         if ($room == false) {
             return $this->error(errcode::ErrRoomBuild);
-        } else {
+        }
+        else {
             $this->broad_access(msg_builder::build_message($roomid, $room->room_type()));
             $this->mRooms[$roomid] = $room;
+            if ($newroom) {
+                $this->broad_access(msg_builder::create_push($room->creator(), $roomid, $room->room_info()));
+            }
             return $this->success(['room' => $room->room_id()]);
         }
     }
@@ -124,29 +134,14 @@ class room_processor implements IProcessor
      */
     private function factory_invite($input)
     {
-        $roomid = intval($input['room']);
-        $newroom = boolval($input['newroom']);
+        $roomid  = intval($input['room']);
         $inviter = intval($input['inviter']);
 
         if ($roomid <= 0) {
             return $this->error(errcode::ErrRoomParam);
         }
 
-        if (!array_key_exists($roomid, $this->mRooms))
-        {
-            $room = $this->mFactory->build($roomid);
-            if ($room != false)
-            {
-                $this->mRooms[$roomid] = $room;
-                $this->broad_access(msg_builder::build_message($roomid, $room->room_type()));
-                if ($newroom) {
-                    $this->broad_access(msg_builder::create_push($inviter, $roomid, $room->room_info()));
-                }
-            }
-        } else {
-            $room = $this->room($roomid);
-        }
-
+        $room = $this->room($roomid);
         if ($room != false)
         {
             $invitees = $input['invitees'];
@@ -155,13 +150,22 @@ class room_processor implements IProcessor
                 $result = $room->invite($inviter, $invitees,$newusers);
                 if ($result != false)
                 {
-                    if (!empty($newusers)) {
+                    if (!empty($newusers))
+                    {
                         $room_info = $room->room_info();
                         $this->broad_access(msg_builder::invite_message($roomid, $room->room_type(), $newusers));
 
                         $inviter_info = $room->userinfos($inviter);
                         $this->broad_access(msg_builder::invited_push($roomid, $newusers,$inviter_info[0],$room_info));
                         $this->broadcast_roomsg($room);
+
+                        $last_count = $room->usercount() - count($newusers);
+                        if($last_count >= 0 && $last_count < 10) {
+                            QueueClient::push("OnUpdateRoom",['room_id' => $roomid]);
+                        } else {
+                            $count = count($newusers);
+                            Model('room')->editRoom(['room_id' => $roomid],['users' => ['users',"users+{$count}"]]);
+                        }
                     }
                     return $this->success($result);
                 }
@@ -171,6 +175,26 @@ class room_processor implements IProcessor
         return $this->error(errcode::ErrRoomInvite);
     }
 
+    private function factory_change($input)
+    {
+        $roomid = intval($input['room']);
+        if ($roomid <= 0) {
+            return $this->error(errcode::ErrRoomParam);
+        }
+
+        $room = $this->room($roomid);
+        if ($room != false)
+        {
+            $result = $room->change();
+            if ($result != false) {
+                $this->broad_access(msg_builder::change_push($roomid, $room->room_info()));
+                return $this->success($result);
+            }
+        }
+
+        return $this->error(errcode::ErrRoomChange);
+    }
+
     /**
      * @param $input
      * @return mixed|string
@@ -182,17 +206,7 @@ class room_processor implements IProcessor
             return $this->error(errcode::ErrRoomParam);
         }
 
-        if (!array_key_exists($roomid, $this->mRooms)) {
-            $room = $this->mFactory->build($roomid);
-            if ($room != false) {
-                $this->mRooms[$roomid] = $room;
-            } else {
-                $this->broad_access(msg_builder::build_message($roomid, $room->room_type()));
-            }
-        } else {
-            $room = $this->room($roomid);
-        }
-
+        $room = $this->room($roomid);
         if ($room != false) {
             $userid = intval($input['user']);
             if ($userid > 0) {

+ 1 - 58
helper/room/util.php

@@ -113,7 +113,7 @@ class talks_helper
     private function chatrooms($user, &$roomids)
     {
         $roomids = [];
-        $items = $this->mod_room->getPartRooms(['member_id' => $user,'state' => 0],'room_id');
+        $items = $this->mod_room->getRoomParts(['member_id' => $user,'state' => 0],'room_id');
 
         if(empty($items)) return [];
 
@@ -347,64 +347,8 @@ class members
     }
 }
 
-class room_helper
-{
-    public static function use_tmp_name($room)
-    {
-        $tmp_name = $room['tmp_name'];
-        $user_cnt = intval($room['users']);
-        //tmp_name can be use already
-        if(!empty($tmp_name))
-        {
-            $tmp_len = count(explode('、',$tmp_name));
-            if($tmp_len > 3 || $tmp_len >= $user_cnt){
-                return $tmp_name;
-            }
-        }
-
-        //create new tmp_name
-        $tmp_name = "";
-        $room_id = intval($room['room_id']);
-        $uids = self::room_uids($room_id,4);
-        $names = Model('member')->field('member_nickname')->where(["member_id" => ["in",$uids]])->select();
-        foreach ($names as $name){
-            $tmp_name .= $name['member_nickname'] .'、';
-        }
-        $tmp_name =  trim($tmp_name,"、");
-
-        $cond = ["room_id" => $room['room_id']];
-        $update = ["tmp_name" => $tmp_name];
-
-
-        //todo QueueClient::push()
-        if(empty($ret)) $ret = '丽人丽妆';
-        $ret = Model("room")->edit_room($cond,$update);
-
-        if($ret){
-            return $tmp_name;
-        }else{
-            Log::record("room_name create faild room:".json_encode($room));
-            return false;
-        }
-    }
-
-    public static function room_uids($roomid,$limit=false)
-    {
-        $uids = [];
-        $mod_room = Model('room');
-
-        $items = $mod_room->getPartRooms(["room_id" => $roomid,'state' => 0],'member_id',$limit);
-        foreach ($items as $item){
-            $uids[] = $item['member_id'];
-        }
-        return $uids;
-    }
-}
-
-
 class uploader
 {
-
     public function upfile($upload_dir,&$upload_info)
     {
         if(empty($upload_dir)) {
@@ -448,5 +392,4 @@ class uploader
         }
         return $file_path;
     }
-
 }

+ 107 - 0
helper/room_helper.php

@@ -18,3 +18,110 @@ require_once(BASE_ROOT_PATH . '/helper/room/factory_client.php');
 require_once(BASE_ROOT_PATH . '/helper/room/chat_room.php');
 require_once(BASE_ROOT_PATH . '/helper/room/room_client.php');
 require_once(BASE_ROOT_PATH . '/helper/room/bargain_manager.php');
+require_once(BASE_ROOT_PATH . '/helper/room/room_parts.php');
+require_once(BASE_ROOT_PATH . '/helper/room/room_avatar.php');
+
+
+class room_helper
+{
+    const room_name_usercount = 5;
+
+    public static function OnUpdateRoom($room)
+    {
+        if($room < 0) return false;
+
+        $mod_room = Model('room');
+        $item = $mod_room->getRoom($room);
+        if(empty($item)) return false;
+
+        $parts = new room\room_parts($room);
+        $partinfos = $parts->top_users(20);
+
+        $uids = [];
+        foreach ($partinfos as $part) {
+            $uids[] = $part->member_id();
+        }
+
+        $updata = [];
+        $room_info = new room\room_info($item);
+        if(!$room_info->has_avatar())
+        {
+            $avatar_maker = new room\room_avatar($room);
+            $avatars = self::avatarts($uids);
+            if(!empty($avatars))
+            {
+                $tmp_avatar = $avatar_maker->make($avatars);
+                if($tmp_avatar != false) {
+                    $updata['tmp_avatar'] = $tmp_avatar;
+                }
+            }
+        }
+
+        if(!$room_info->has_name())
+        {
+            $names = self::nickname($uids);
+            if(empty($names)) {
+                $tmp_name = implode('、', $names);
+                $updata['tmp_name'] = $tmp_name;
+            }
+        }
+
+        if(!empty($updata)) {
+            $mod_room->editRoom(['room_id' => $room],$updata);
+            room\factory_client::instance()->change($room);
+        }
+    }
+
+    public static function avatarts($uids)
+    {
+        if(empty($uids)) return false;
+
+        $result = [];
+        $uids = array_unique($uids);
+        $items = Model('member')->getMemberList(['member_id' => ['in',$uids]]);
+        foreach ($items as $item)
+        {
+            try
+            {
+                $info = new member_info($item);
+                if($info->hasAvatar()) {
+                    $result[] = $info->avatar();
+                }
+            }
+            catch (Exception $ex) {
+                Log::record($ex->getMessage(),Log::ERR);
+            }
+        }
+
+        return $result;
+    }
+
+    public static function nickname($uids)
+    {
+        $result = [];
+        if(empty($uids)) return $result;
+
+        $uids = array_unique($uids);
+        $items = Model('member')->getMemberList(['member_id' => ['in',$uids]]);
+
+        $i = 0;
+        foreach ($items as $item)
+        {
+            try
+            {
+                $info = new member_info($item);
+                if($info->hasNickname()) {
+                    $result[] = $info->nickname();
+                    $i++;
+                    if($i > self::room_name_usercount) break;
+                }
+            }
+            catch (Exception $ex) {
+                Log::record($ex->getMessage(),Log::ERR);
+            }
+        }
+
+        return $result;
+    }
+
+}

二进制
mac_webacc


+ 7 - 27
mobile/control/member_talk.php

@@ -297,27 +297,13 @@ class member_talkControl extends mbMemberControl
             return self::outerr(errcode::ErrParamter);
         }
 
-        $uids = room\room_helper::room_uids($room);
-
         $result = room\factory_client::instance()->invite($room,session_helper::memberid(),$invitees);
         if($result === false) {
             return self::outerr(errcode::ErrRoom,"邀请失败");
         }
-        else {
-            $newids = [];
-            foreach ($result['invitees'] as $invitee)
-            {
-                if(!in_array($invitee,$uids)){
-                    $newids[] = $invitee;
-                }
-            }
-
-            if(empty($newids)){
-                $members = [];
-            }else{
-                $members =  room\members::get_members($newids);
-            }
-
+        else
+        {
+            $members = room\members::get_members($result['newusers']);
             $result['invitees'] = $members;
             return self::outsuccess($result);
         }
@@ -349,7 +335,6 @@ class member_talkControl extends mbMemberControl
     }
 
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
     public function room_detailOp()
     {
 
@@ -408,7 +393,7 @@ class member_talkControl extends mbMemberControl
             return self::outerr(errcode::ErrParamter);
         }
 
-        $ret = Model('room')->edit_room($cond,$update);
+        $ret = Model('room')->editRoom($cond,$update);
 
         if($ret) {
             return self::outsuccess(null);
@@ -492,14 +477,10 @@ class member_talkControl extends mbMemberControl
         return self::outsuccess([
                 'friends' => $uids,
                 'count' => count($uids),
-                "mem_desc"=>$members,
-                'mobile_page' => mobile_page(1)
-            ]
-        );
+                "mem_desc" => $members,
+                'mobile_page' => mobile_page(1)]);
     }
 
-
-
     public function room_avatarOp()
     {
         $roomid = intval($_POST['room_id']);
@@ -513,7 +494,7 @@ class member_talkControl extends mbMemberControl
 
         $file_name = $info['msg'];
         $file_path = '/data/upload/'.$upload_dir . $file_name;
-        $ret = Model("room")->edit_room(['room_id' => $roomid],['avatar' => $file_path]);
+        $ret = Model("room")->editRoom(['room_id' => $roomid],['avatar' => $file_path]);
 
         if ($ret) {
             return self::outsuccess(['avatar' => $file_path]);
@@ -522,7 +503,6 @@ class member_talkControl extends mbMemberControl
         }
     }
 
-
     public function kickOp()
     {
         $room = intval($_GET['room_id']);

+ 2 - 0
mobile/util/errcode.php

@@ -97,6 +97,8 @@ class errcode extends SplEnum
     const ErrRoomFactoryOp  = 18006;
     const ErrRoomAccessOp  = 18007;
     const ErrRoomPush  = 18008;
+    const ErrRoomChange = 18009;
+
     const ErrAccess = 19000;
     const ErrTalk = 20000;
 

+ 4 - 0
test/TestRoom.php

@@ -32,5 +32,9 @@ class TestRoom extends PHPUnit_Framework_TestCase
             $values[$i] = $value['value'];
         }
     }
+    public function testGenRoomavatar()
+    {
+        room_helper::OnUpdateRoom(72);
+    }
 
 }