room.model.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: stanley-king
  5. * Date: 2017/12/18
  6. * Time: 下午9:18
  7. */
  8. require_once(BASE_ROOT_PATH . '/helper/room/proto_type.php');
  9. class roomModel extends Model
  10. {
  11. public function __construct() {
  12. parent::__construct();
  13. }
  14. ///群聊接口//////////////////////////////////////////////////////////////////////////////////////////////////////////
  15. public function participants($room_id)
  16. {
  17. return $this->table('room_participant')->field('*')->where(['room_id' => $room_id,'state' => 0])->limit(false)->select();
  18. }
  19. public function getRoomParts($cond,$field = '*',$per_page = false,$order='invite_time asc') {
  20. return $this->table('room_participant')->field($field)->where($cond)->page($per_page)->order($order)->limit($per_page)->select();
  21. }
  22. public function editRoomParts($cond,$updata) {
  23. $ret = $this->table('room_participant')->where($cond)->update($updata);
  24. return $ret;
  25. }
  26. public function countParts($cond) {
  27. $ret = $this->table('room_participant')->where($cond)->count();
  28. return $ret;
  29. }
  30. public function invite($room_id,$user,$inviter) {
  31. $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);
  32. return $ret;
  33. }
  34. public function leave($room_id,$user) {
  35. $ret = $this->table('room_participant')->where(['room_id' => $room_id,'member_id' => $user])->update(['leave_time' => time(),'state' => 1]);
  36. return $ret;
  37. }
  38. public function kickout($room_id,$user) {
  39. $ret = $this->table('room_participant')->where(['room_id' => $room_id,'member_id' => $user])->update(['leave_time' => time(),'state' => 2]);
  40. return $ret;
  41. }
  42. ///群聊接口//////////////////////////////////////////////////////////////////////////////////////////////////////////
  43. public function create_room($type,$name,$creator,$owner,$owner_name,$max_user = 0) {
  44. $params = ['type' => $type,'room_name' => $name,'room_creator' => $creator,'room_owner' => $owner,'owner_name' => $owner_name,'max_user' => $max_user,'add_time' => time()];
  45. return $this->table('room')->insert($params);
  46. }
  47. public function editRoom($cond,$updata)
  48. {
  49. return $this->table('room')->where($cond)->update($updata);
  50. }
  51. public function edit($condition,$data) {
  52. return $this->table('room')->where($condition)->update($data);
  53. }
  54. public function getRoom($roomid) {
  55. return $this->table('room')->field('*')->where(['room_id' => $roomid])->limit(1)->find();
  56. }
  57. public function getRoomByType($room_type,$user) {
  58. $room = $this->table('room')->field('*')->where(['type' => $room_type, 'room_creator' => $user])->limit(1)->find();
  59. return $room;
  60. }
  61. public function getRooms($cond,$field = '*',$order = 'room_id asc',$limit = 0) {
  62. return $this->table('room')->field($field)->where($cond)->order($order)->limit($limit)->select();
  63. }
  64. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  65. public function findChatid($left,$right,$lock=false)
  66. {
  67. if($left > $right) {
  68. $tmp = $left;
  69. $left = $right;
  70. $right = $tmp;
  71. }
  72. $item = $this->table('room_chatwo')->field('*')->where(['user_left' => $left,'user_right' => $right])->lock($lock)->find();
  73. if(empty($item)) {
  74. return false;
  75. } else {
  76. return intval($item['chat_id']);
  77. }
  78. }
  79. public function addChatwo($left,$right)
  80. {
  81. if($left > $right) {
  82. $tmp = $left;
  83. $left = $right;
  84. $right = $tmp;
  85. }
  86. return $this->table('room_chatwo')->insert(['user_left' => $left,'user_right' => $right,'add_time' => time()]);
  87. }
  88. public function getChatwoRooms($cond,$field = '*') {
  89. return $this->table('room_chatwo')->field($field)->where($cond)->select();
  90. }
  91. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  92. public function getRoomMsg($room_id,$msg_type) {
  93. return $this->table('room_msg')->field('*')->where(['room_id' => $room_id, 'type' => $msg_type])->order('add_time desc')->select();
  94. }
  95. public function getRoomsgList($condition, $limit = false, $field = '*', $order = 'msg_id desc',$master = false) {
  96. return $this->table('room_msg')->field($field)->where($condition)->order($order)->limit($limit)->master($master)->select();
  97. }
  98. public function getLastRoomMsgs($cond,$order='msg_id desc')
  99. {
  100. $items = $this->table('room_msg')->field("MAX(msg_id) as msg_id,room_id")->where($cond)->group('room_id')->order($order)->select();
  101. if(empty($items)) return [];
  102. $msg_ids = [];
  103. foreach ($items as $item) {
  104. $msg_ids[] = intval($item['msg_id']);
  105. }
  106. return $this->table('room_msg')->field("*")->where(['msg_id' => ['in',$msg_ids]])->limit(count($msg_ids))->limit(false)->select();
  107. }
  108. public function addRoomMsg($datas)
  109. {
  110. return $this->table('room_msg')->insert($datas);
  111. }
  112. public function getRoomMsgsCount($cond){
  113. return $this->table('room_msg')->where($cond)->count();
  114. }
  115. public function getUserRoomMsg($room_id,$userid,$msg_type)
  116. {
  117. return $this->table('room_msg')->field('*')->where(['room_id' => $room_id,'member_id' => $userid,'type' => $msg_type])->order('add_time desc')->select();
  118. }
  119. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  120. public function getRoomExtend($userid,$lock=false)
  121. {
  122. $item = $this->table('room_extend')->field('*')->where(['userid' => $userid])->lock($lock)->find();
  123. return $item;
  124. }
  125. public function addExtend($userid,$datas)
  126. {
  127. $datas['userid'] = $userid;
  128. return $this->table('room_extend')->insert($datas);
  129. }
  130. public function editExtend($userid,$datas)
  131. {
  132. return $this->table('room_extend')->where(['userid' => $userid])->update($datas);
  133. }
  134. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  135. public function findFace($cond) {
  136. return $this->table('room_face')->where($cond)->lock(true)->find();
  137. }
  138. public function createFace($lochash,$code)
  139. {
  140. return $this->table('room_face')->insert(['lochash' => $lochash,'check_code' => $code,'add_time' => time()]);
  141. }
  142. public function editFace($cond,$data)
  143. {
  144. return $this->table('room_face')->where($cond)->update($data);
  145. }
  146. /////////////////////////////////////////////
  147. public function applyCnts($cond){
  148. return $this->table('room_apply')->where($cond)->count();
  149. }
  150. public function roomApplys($cond,$field="*",$page=20,$order='apply_id desc')
  151. {
  152. return $this->table('room_apply')->field($field)->where($cond)->page($page)->order($order)->select();
  153. }
  154. public function findApply($apply_id){
  155. return $this->table('room_apply')->field('*')->where(['apply_id' => $apply_id])->find();
  156. }
  157. public function addApply($room,$member,$msg,$viewer=0){
  158. return $this->table('room_apply')->insert(['room_id' => $room,'member_id' => $member,'msg' => $msg,'viewer'=>$viewer,'add_time'=>time()]);
  159. }
  160. public function editApply($apply,$viewer,$step){
  161. return $this->table('room_apply')->where(['apply_id' => $apply])->update(["viewer"=> $viewer,"step" => $step]);
  162. }
  163. ////////////////////////////////////////////
  164. public function roomSteps($cond,$field="*",$page=20,$order='steps_id desc') {
  165. return $this->table('room_steps')->field($field)->where($cond)->page($page)->order($order)->limit($page)->select();
  166. }
  167. public function findSteps($cond,$field="*"){
  168. return $this->table('room_steps')->field($field)->where($cond)->find();
  169. }
  170. public function addSteps($room,$member,$steps,$datetime){
  171. return $this->table('room_steps')->insert(['room_id' => $room,'member_id' => $member,'steps' => $steps,"date_stamp"=>$datetime]);
  172. }
  173. public function editSteps($cond,$updata){
  174. return $this->table('room_steps')->where($cond)->update($updata);
  175. }
  176. public function totalSteps($room,$member){
  177. return $this->table('room_steps')->where(['room_id' => $room,'member_id' => $member])->sum('steps');
  178. }
  179. public function totalRoomSteps($room){
  180. return $this->table('room_participant')->where(['room_id' => $room])->sum('steps');
  181. }
  182. /////////////////
  183. public function roomCerts($cond,$field='*',$page=20,$order='cert_id desc')
  184. {
  185. return $this->table('room_certs')->field($field)->where($cond)->page($page)->order($order)->limit($page)->select();
  186. }
  187. public function findCert($cond,$field='*')
  188. {
  189. return $this->table('room_certs')->field($field)->where($cond)->find();
  190. }
  191. public function addCert($ctype,$room_id,$short_name,$full_name,$cname,$cmobile,$cmail,$cinfo,$cimage)
  192. {
  193. $insertData = [
  194. "ctype" =>$ctype,
  195. "room_id" => $room_id,
  196. "short_name" => $short_name,
  197. "full_name" => $full_name,
  198. "cname" => $cname,
  199. "cmobile" => $cmobile,
  200. "cmail" => $cmail,
  201. "cinfo" => $cinfo,
  202. "cimage" => $cimage,
  203. "cstatus" => 0,
  204. "add_time" => time()
  205. ];
  206. return $this->table('room_certs')->insert($insertData);
  207. }
  208. public function editCerts($cond,$updata)
  209. {
  210. return $this->table('room_certs')->where($cond)->update($updata);
  211. }
  212. }