chataser.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2018/9/26 0026
  6. * Time: 下午 6:28
  7. */
  8. class ChataSer extends Mysqldb
  9. {
  10. private static $mysql;
  11. public $redis = null;
  12. private static $appid = null;
  13. protected $game_db_name = 'gank_activites';
  14. protected $redis_prefix = 'gank_wechat_activites';
  15. protected $activity_reward_table = 'app_user_reward';
  16. protected $redis_prize_key = null;
  17. protected static $activity_user_table = null;
  18. protected static $activity_prize_dbname = 'wechat_prize_config';
  19. protected $login_table = 'receivelogin';
  20. protected static $consignee_table = 'wechat_user_consignee';
  21. protected static $virtual_item_prize_table = 'wechat_virtual_item_prize';
  22. protected static $table = 'tb_user';
  23. public static $prize_info = null;
  24. protected static $wechat_stat_lottery_tab = 'wechat_stat_lottery_info';
  25. protected static $wechat_stat_webclick_tab = 'wechat_stat_web_click';
  26. const LIMIT_ONE = 1;
  27. const K_EXPICE_TIME = 3600;
  28. #----------------
  29. protected $user_table = "tb_user";
  30. protected static $friend_table = "tb_friendid";
  31. protected static $tb_topic_table = "tb_topic";
  32. function __construct()
  33. {
  34. self::$mysql = new Mysqldb();
  35. //$this->redis = new Xredis();
  36. }
  37. //登录获取
  38. public function getdbCharUserInfo($account, $password)
  39. {
  40. $sql = "SELECT * FROM tb_user WHERE account='" . $account . "' AND password='" . $password . "' limit 1 ";
  41. if (self::$mysql->query($sql)) {
  42. return self::$mysql->fetch_row();
  43. }
  44. return false;
  45. }
  46. public function getByIdUserinfo($id)
  47. {
  48. $sql = "SELECT * FROM tb_user WHERE id='" . $id . "' limit 1 ";
  49. if (self::$mysql->query($sql)) {
  50. return self::$mysql->fetch_row();
  51. }
  52. return false;
  53. }
  54. public function addUserInfo($data)
  55. {
  56. if (!self::$mysql->insert($this->user_table, $data)) {
  57. log_message::info('insert indo db saveuserinfo false');
  58. return false;
  59. }
  60. return true;
  61. }
  62. /***
  63. * 添加缓存消息
  64. * @param $data
  65. * @return bool
  66. */
  67. public function addTopitInfo($data)
  68. {
  69. if (!self::$mysql->insert(self::$tb_topic_table, $data)) {
  70. log_message::info('insert indo db tb_topic_table false');
  71. return false;
  72. }
  73. return true;
  74. }
  75. /***
  76. *
  77. * 更新用户信息
  78. */
  79. public function setUser($id, $applydata)
  80. {
  81. $res = self::$mysql->update2($this->user_table, $applydata, 'id=:id', array('id' => $id));
  82. if ($res) {
  83. return true;
  84. }
  85. log_message::info("用户变更false");
  86. return false;
  87. }
  88. /***
  89. *
  90. * 退出更新用户信息
  91. */
  92. public function setFdUser($fd, $applydata)
  93. {
  94. $res = self::$mysql->update2($this->user_table, $applydata, 'fd=:fd', array('fd' => $fd));
  95. if ($res) {
  96. return true;
  97. }
  98. log_message::info("用户变更false");
  99. return false;
  100. }
  101. /***
  102. * 更新用户管道
  103. */
  104. /***
  105. * Save Userinfo
  106. * @param $data ['openid']
  107. * @return array|bool|mixed|null
  108. */
  109. public function saveCharUserInfo($data)
  110. {
  111. //$openid = isset($data['openid']) ? $data['openid'] : ZERO;
  112. $account = isset($data['account']) ? $data['account'] : ZERO;
  113. $password = isset($data['password']) ? $data['password'] : ZERO;
  114. $db_user_info = $this->getdbCharUserInfo($account, $password);
  115. // 如果db 也不存在那么 cache 与 redis 都有进行录入set
  116. if (empty($db_user_info)) {
  117. // 没有该账户
  118. // 这个时候注意参数 $data 是客户端新用户第一次进来初始的参数
  119. /* if (!self::$mysql->insert(self::$table, $data)) {
  120. log_message::info('insert indo db saveuserinfo false');
  121. }
  122. $data['status'] = ONE;
  123. return $data;*/
  124. // 如果不存在或者密码不正确则进行提示
  125. // 缓存后期进行添加
  126. return false;
  127. }
  128. // 更新fd
  129. log_message::info("db user info id ", $db_user_info['id']);
  130. if (!$this->setUser($db_user_info['id'], $data)) {
  131. //
  132. log_message::info('user edit is false');
  133. }
  134. $db_user_info['status'] = TWO;
  135. // 存在账户
  136. return $db_user_info;
  137. }
  138. /***
  139. * add user
  140. */
  141. public function addFriend($data)
  142. {
  143. if (!self::$mysql->insert(self::$friend_table, $data)) {
  144. log_message::info('insert addFriend db addFriend false');
  145. return false;
  146. }
  147. return true;
  148. }
  149. /***
  150. * 好友列表
  151. */
  152. public function friendidInfo($uid)
  153. {
  154. $sql = "SELECT * FROM tb_user WHERE id in (SELECT friendid FROM tb_friendid WHERE uid='" . $uid . "')";
  155. if (self::$mysql->query($sql)) {
  156. return self::$mysql->fetch_all();
  157. }
  158. return false;
  159. }
  160. /***
  161. * 好友状态变更 1-申请中 2-已拒绝 3-已接收 4已拉黑
  162. * $applydata = ['apply_status' => $apply_status]
  163. */
  164. public function setFriendid($uid, $applydata)
  165. {
  166. $res = self::$mysql->update2(self::$friend_table, $applydata, 'uid=:uid', array('uid' => $uid));
  167. if ($res) {
  168. return true;
  169. }
  170. log_message::info("好友变更false");
  171. return false;
  172. }
  173. /**
  174. * 发送消息内容
  175. */
  176. public function addusersendMessage($data)
  177. {
  178. if (!self::$mysql->insert(self::$tb_topic_table, $data)) {
  179. log_message::info('insert addFriend db addFriend false');
  180. return false;
  181. }
  182. return true;
  183. }
  184. /***
  185. * 登录轮训缓存消息
  186. * @param $uid
  187. */
  188. public function usersendMessageinfo($uid)
  189. {
  190. $sql = "SELECT * FROM " . self::$tb_topic_table . " WHERE receiveuid='" . $uid . "'";
  191. if (self::$mysql->query($sql)) {
  192. return self::$mysql->fetch_all();
  193. }
  194. return false;
  195. }
  196. /***
  197. * 更改消息状态
  198. */
  199. public function setUserMessageStatus($message_status, $id)
  200. {
  201. $res = self::$mysql->update2(self::$tb_topic_table, ['message_status' => $message_status], 'id=:id', array('id' => $id));
  202. if ($res) {
  203. return true;
  204. }
  205. log_message::info("update message status false");
  206. return false;
  207. }
  208. }