123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 |
- <?php
- /**
- * Created by PhpStorm.
- * User: stanley-king
- * Date: 2017/12/18
- * Time: 下午9:18
- */
- require_once(BASE_ROOT_PATH . '/helper/room/proto_type.php');
- class roomModel extends Model
- {
- public function __construct() {
- parent::__construct();
- }
- ///群聊接口//////////////////////////////////////////////////////////////////////////////////////////////////////////
- public function participants($room_id)
- {
- return $this->table('room_participant')->field('*')->where(['room_id' => $room_id,'state' => 0])->order('invite_time asc')->limit(false)->select();
- }
- public function getRoomParts($cond,$field = '*',$per_page = false,$order='invite_time asc') {
- return $this->table('room_participant')->field($field)->where($cond)->page($per_page)->order($order)->limit($per_page)->select();
- }
- public function editRoomParts($cond,$updata) {
- $ret = $this->table('room_participant')->where($cond)->update($updata);
- return $ret;
- }
- public function countParts($cond) {
- $ret = $this->table('room_participant')->where($cond)->count();
- return $ret;
- }
- public function invite($room_id,$user,$inviter) {
- $ret = $this->table('room_participant')->insert(['room_id' => $room_id,'member_id' => $user,'inviter' => $inviter,'invite_time' => time(),'join_time' => 0,'jointimes' => 0,'state' => 0],true);
- return $ret;
- }
- public function leave($room_id,$user) {
- $ret = $this->table('room_participant')->where(['room_id' => $room_id,'member_id' => $user])->update(['leave_time' => time(),'state' => 1]);
- return $ret;
- }
- public function kickout($room_id,$user) {
- $ret = $this->table('room_participant')->where(['room_id' => $room_id,'member_id' => $user])->update(['leave_time' => time(),'state' => 2]);
- 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 editRoom($cond,$updata)
- {
- return $this->table('room')->where($cond)->update($updata);
- }
- 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();
- }
- public function getRoomByType($room_type,$user) {
- $room = $this->table('room')->field('*')->where(['type' => $room_type, 'room_creator' => $user])->limit(1)->find();
- return $room;
- }
- public function getRooms($cond,$field = '*',$order = 'room_id asc',$limit = 0,$page = false) {
- return $this->table('room')->field($field)->where($cond)->page($page)->order($order)->limit($limit)->select();
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- public function findChatid($left,$right,$lock=false)
- {
- if($left > $right) {
- $tmp = $left;
- $left = $right;
- $right = $tmp;
- }
- $item = $this->table('room_chatwo')->field('*')->where(['user_left' => $left,'user_right' => $right])->master($lock)->find();
- if(empty($item)) {
- return false;
- } else {
- return intval($item['chat_id']);
- }
- }
- public function addChatwo($left,$right)
- {
- if($left > $right) {
- $tmp = $left;
- $left = $right;
- $right = $tmp;
- }
- return $this->table('room_chatwo')->insert(['user_left' => $left,'user_right' => $right,'add_time' => time()]);
- }
- public function getChatwoRooms($cond,$field = '*') {
- return $this->table('room_chatwo')->field($field)->where($cond)->select();
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- public function getRoomMsg($room_id,$msg_type) {
- return $this->table('room_msg')->field('*')->where(['room_id' => $room_id, 'type' => $msg_type])->order('add_time desc')->select();
- }
- public function getRoomsgList($condition, $limit = false, $field = '*', $order = 'msg_id desc',$master = false) {
- return $this->table('room_msg')->field($field)->where($condition)->order($order)->limit($limit)->master($master)->select();
- }
- public function getMssage($cond)
- {
- return $this->table('room_msg')->field('*')->where($cond)->select();
- }
- public function getLastRoomMsgs($cond,$order='msg_id desc')
- {
- $items = $this->table('room_msg')->field("MAX(msg_id) as msg_id,room_id")->where($cond)->group('room_id')->order($order)->select();
- if(empty($items)) return [];
- $msg_ids = [];
- foreach ($items as $item) {
- $msg_ids[] = intval($item['msg_id']);
- }
- return $this->table('room_msg')->field("*")->where(['msg_id' => ['in',$msg_ids]])->limit(count($msg_ids))->limit(false)->select();
- }
- public function addRoomMsg($datas)
- {
- return $this->table('room_msg')->insert($datas);
- }
- public function getRoomMsgsCount($cond){
- return $this->table('room_msg')->where($cond)->count();
- }
- public function getUserRoomMsg($room_id,$userid,$msg_type)
- {
- return $this->table('room_msg')->field('*')->where(['room_id' => $room_id,'member_id' => $userid,'type' => $msg_type])->order('add_time desc')->select();
- }
- public function updateMsg($msgid,$data) {
- if($msgid <= 0) return false;
- return $this->table('room_msg')->where(['msg_id' => $msgid])->update($data);
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- public function getRoomExtend($userid,$lock=false)
- {
- $item = $this->table('room_extend')->field('*')->where(['userid' => $userid])->master($lock)->find();
- return $item;
- }
- public function addExtend($userid,$datas)
- {
- $datas['userid'] = $userid;
- return $this->table('room_extend')->insert($datas);
- }
- public function editExtend($userid,$datas)
- {
- return $this->table('room_extend')->where(['userid' => $userid])->update($datas);
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- public function findFace($cond) {
- return $this->table('room_face')->where($cond)->master(true)->find();
- }
- public function createFace($lochash,$code)
- {
- return $this->table('room_face')->insert(['lochash' => $lochash,'check_code' => $code,'add_time' => time()]);
- }
- public function editFace($cond,$data)
- {
- return $this->table('room_face')->where($cond)->update($data);
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- public function roomSteps($cond,$field="*",$page=20,$order='steps_id desc') {
- return $this->table('room_steps')->field($field)->where($cond)->page($page)->order($order)->limit($page)->select();
- }
- public function findSteps($cond,$field="*"){
- return $this->table('room_steps')->field($field)->where($cond)->find();
- }
- public function addSteps($room,$member,$steps,$datetime){
- return $this->table('room_steps')->insert(['room_id' => $room,'member_id' => $member,'steps' => $steps,"date_stamp"=>$datetime]);
- }
- public function editSteps($cond,$updata){
- return $this->table('room_steps')->where($cond)->update($updata);
- }
- public function totalSteps($room,$member){
- return $this->table('room_steps')->where(['room_id' => $room,'member_id' => $member])->sum('steps');
- }
- public function totalRoomSteps($room){
- return $this->table('room_participant')->where(['room_id' => $room])->sum('steps');
- }
- /////////////////
- public function roomCerts($cond,$field='*',$page=20,$order='cert_id desc')
- {
- return $this->table('room_certs')->field($field)->where($cond)->page($page)->order($order)->limit($page)->select();
- }
- public function findCert($cond,$field='*')
- {
- return $this->table('room_certs')->field($field)->where($cond)->find();
- }
- public function addCert($ctype,$room_id,$short_name,$full_name,$cname,$cmobile,$cmail,$cinfo,$cimage)
- {
- $insertData = [
- "ctype" =>$ctype,
- "room_id" => $room_id,
- "short_name" => $short_name,
- "full_name" => $full_name,
- "cname" => $cname,
- "cmobile" => $cmobile,
- "cmail" => $cmail,
- "cinfo" => $cinfo,
- "cimage" => $cimage,
- "cstatus" => 0,
- "add_time" => time()
- ];
- return $this->table('room_certs')->insert($insertData);
- }
- public function editCerts($cond,$updata)
- {
- return $this->table('room_certs')->where($cond)->update($updata);
- }
- }
|