create_bargain($params); } elseif($type == proto_type::act_group) { return $this->create_group($params); } elseif($type == proto_type::act_shake_bonus) { return $this->create_shake_bonus($params); } else { return false; } } public function build($room_id) { $mod_room = Model('room'); $room_params = $mod_room->getRoom($room_id); if(empty($room_params)) return false; $participants = self::participants($room_id); $rinfo = new base_info($room_params); if($rinfo->type() == proto_type::room_bargain) { return new bargain_room($room_params,$participants); } elseif ($rinfo->type() == proto_type::room_group) { return new group_room($room_params,$participants); } elseif($rinfo->type() == proto_type::room_shake_bonus) { return new shake_room($room_params,$participants); } elseif ($rinfo->type() == proto_type::room_chatwo) { } else { return false; } } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// private function create_bargain($params) { $creator = intval($params['creator']); $good_id = intval($params['goods_id']); $usable_days = intval($params['usable_days']); $lowest_price = $params['lowest_price']; $type = $params['random']; $total_num = $params['total_num']; if($creator <= 0 || $good_id <= 0) return false; $mod_bargain = Model('room_bargain'); $ret = $mod_bargain->getBargainByUserGoods($creator,$good_id,true); if(!empty($ret)) { $bargain = new bargain($ret); return ['bargain_id' => $bargain->bargain_id(),'room' => $bargain->room(),'creator' => $bargain->creator()]; } $minfo = new member_info($creator); $room_id = $this->create_room(proto_type::room_bargain,"bargain",$minfo); if($room_id === false) return false; $helper = new goods_helper(); $summarys = $helper->summary([$good_id],$related_goods); if(empty($summarys) || empty($summarys['summary'])) return false; $summary = $summarys['summary'][0]; $bargain_id = $mod_bargain->create($room_id,$creator,$good_id,$summary['goods_price'],$lowest_price,$usable_days,$type,$total_num); return ['bargain_id' => $bargain_id,'room' => $room_id,'creator' => $creator]; } private function create_group($params) { try { $user = intval($params['creator']); if($user <= 0) return false; $creator = new member_info($user); $room_type = proto_type::room_group; $room_id = $this->create_room($room_type,'group',$creator); return ['room' => $room_id,'creator' => $user]; } catch (Exception $ex) { Log::record(__METHOD__ . " {$ex->getMessage()}",Log::ERR); return false; } } private function create_shake_bonus($params) { try { $user = intval($params['creator']); if($user <= 0) return false; $mod_room = Model('room'); $room = $mod_room->getRoomByType(proto_type::room_shake_bonus,$user); if(empty($room)) { $creator = new member_info($user); $room_type = proto_type::room_shake_bonus; $room_id = $this->create_room($room_type,'shake_bonus',$creator); } else { $room_id = intval($room['room_id']); } return ['room' => $room_id,'creator' => $user]; } catch (Exception $ex) { Log::record(__METHOD__ . " {$ex->getMessage()}",Log::ERR); return false; } } private function create_room($room_type,$name,member_info $creator) { $mod_room = Model('room'); $ret = $mod_room->create_room($room_type,$name,$creator->member_id(),$creator->member_id(),$creator->nickname()); return $ret; } private static function participants($roomid) { $roomid = intval($roomid); if($roomid <= 0) return false; $mod_room = Model('room'); $items = $mod_room->participants($roomid); $key_ids = []; $uids = []; foreach ($items as $item) { $uid = intval($item['member_id']); $room_key = $item['room_key']; $key_ids[$room_key] = $uid; $uids[] = $uid; } $uids = array_unique($uids,SORT_NUMERIC); $members = Model('member')->getMemberList(array('member_id' => array('in',$uids))); $uid_infos = []; foreach ($members as $member) { $uinfo = new member_info($member); $user = $uinfo->member_id(); $item = ['avatar' => $uinfo->avatar(),'nickname' => $uinfo->nickname(),'userid' => $uinfo->member_id(),'active' => false]; $uid_infos[$user] = $item; } $result = []; foreach ($key_ids as $key => $uid) { $result[$key] = $uid_infos[$uid]; } return $result; } }