message_mail_box.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. package service
  2. import (
  3. quitl "app.yhyue.com/moapp/jybase/common"
  4. util "bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/entity"
  5. . "bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/rpc/messagecenter/init"
  6. "bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/rpc/messagecenter/messagecenter"
  7. "database/sql"
  8. "fmt"
  9. "log"
  10. "time"
  11. )
  12. type MessaggeService struct{}
  13. func (b MessaggeService) Table() string {
  14. return "socialize_message_mailbox"
  15. }
  16. func (b MessaggeService) Count(newUserId, userType, entUserId int64) (count int, err error) {
  17. v := make([]interface{}, 0)
  18. sqlStr := "select count(id) from socialize_message_mailbox where own_id=? and isread=0"
  19. if userType == 1 {
  20. sqlStr = "select count(b.id) from socialize_chat_session a left join socialize_message_mailbox b ON a.id=b.own_id where b.type=5 and a.customer_service_id=? and b.isread=0 and own_type = 1 order by create_time"
  21. v = append(v, entUserId)
  22. } else {
  23. sqlStr = "select count(b.id) from socialize_message_mailbox b where b.own_id=? and b.isread=0 and own_type = 2 order by create_time"
  24. v = append(v, newUserId)
  25. }
  26. fmt.Println(sqlStr, v)
  27. rs := Mysql.CountBySql(sqlStr, v...)
  28. log.Println(rs)
  29. count = int(rs)
  30. return
  31. }
  32. func (b MessaggeService) UserList(in *messagecenter.UserReq) (data *[]map[string]interface{}, err error) {
  33. v := make([]interface{}, 0)
  34. sqlStr := ""
  35. if in.UserType == 2 {
  36. //用户最后一次信息查询
  37. userSql := "SELECT MAX( c.id ) as messageId FROM socialize_message_mailbox c WHERE c.own_id = ? AND c.type = 2 AND c.own_type = 2 GROUP BY ( CASE WHEN c.send_user_id > c.receive_user_id THEN CONCAT( c.send_user_id, c.receive_user_id ) WHEN c.send_user_id < c.receive_user_id THEN CONCAT( c.receive_user_id, c.send_user_id ) END ) "
  38. data = Mysql.SelectBySql(userSql, in.NewUserId)
  39. userMessageId := Inhandle(data)
  40. //客服最后一次信息查询
  41. customerSql := " SELECT max( c.id ) as messageId FROM socialize_message_mailbox c LEFT JOIN socialize_chat_session d ON IF ( c.send_user_type = 1, d.id = c.send_user_id, d.id = c.receive_user_id ) WHERE c.own_id = ? AND ( c.type = 4 OR c.type = 5 ) AND c.own_type = 2 and d.user_id=c.own_id GROUP BY d.ent_id "
  42. data = Mysql.SelectBySql(customerSql, in.NewUserId)
  43. customerMessageId := Inhandle(data)
  44. //用户的列表
  45. sqlStr = "SELECT IF ( b.nickname = '', REPLACE(b.phone,SUBSTR(b.phone,4,4),'****'), b.nickname ) AS name, b.id, e.title, b.headimg, e.type, e.link, e.content, 2 AS userType, a.create_time, a.type AS itemType, ( SELECT count( h.id ) FROM socialize_message_mailbox h WHERE h.type = 2 AND h.own_id = ? AND h.own_type = 2 AND h.receive_user_id = ? and h.send_user_id=b.id AND h.isread = 0 ) AS number FROM socialize_message_mailbox a LEFT JOIN base_user b ON b.id = a.receive_user_id or b.id = a.send_user_id LEFT JOIN socialize_message e ON e.id = a.messag_id WHERE a.id IN ( " + userMessageId + " ) AND b.id != ? UNION ALL SELECT f.nickname AS name, b.ent_id AS id, e.title,f.headimage AS headimg, e.type, e.link, e.content, 1 AS userType, a.create_time, a.type AS itemType, ( SELECT count( h.id ) FROM socialize_message_mailbox h WHERE ( h.type = 4 OR h.type = 5 ) AND h.own_id = ? AND h.own_type = 2 AND h.send_user_type = 1 and h.receive_user_id = ? AND h.isread = 0 ) AS number FROM socialize_message_mailbox a LEFT JOIN socialize_chat_session b ON IF ( a.send_user_type = 1, b.id = a.send_user_id, b.id = a.receive_user_id ) LEFT JOIN socialize_message e ON e.id = a.messag_id left join socialize_tenant_robot f on f.ent_id=b.ent_id WHERE a.id IN ( " + customerMessageId + " ) ORDER BY create_time DESC"
  46. v = append(v, in.NewUserId, in.NewUserId, in.NewUserId, in.NewUserId, in.NewUserId)
  47. } else {
  48. phoneSql := ""
  49. if in.Phone != "" {
  50. phoneSql = "and b.phone='" + in.Phone + "'"
  51. }
  52. startTimeSql := ""
  53. if in.StartTime != "" {
  54. startTimeSql = " and DATE_FORMAT(c.create_time,'%Y-%m-%d') >= '" + in.StartTime + "' "
  55. }
  56. endTimeSql := ""
  57. if in.EndTime != "" {
  58. endTimeSql = " and DATE_FORMAT(c.create_time,'%Y-%m-%d') <= '" + in.EndTime + "' "
  59. }
  60. //先获取每个用户最后聊天记录
  61. userSql := " SELECT MAX( c.id ) as messageId FROM socialize_message_mailbox c LEFT JOIN socialize_chat_session d ON IF ( c.send_user_type = 1, d.id = c.send_user_id, d.id = c.receive_user_id ) WHERE c.own_type = 1 AND d.customer_service_id = ? and ( c.type = 4 OR c.type = 5 ) AND d.customer_service_id !=0 " + startTimeSql + endTimeSql + " GROUP BY ( CASE WHEN c.send_user_type =2 THEN CONCAT( c.send_user_id ) WHEN c.send_user_type =1 THEN CONCAT( c.receive_user_id ) END ) "
  62. v = append(v, in.EntUserId)
  63. log.Println(userSql, v)
  64. data = Mysql.SelectBySql(userSql, v...)
  65. if data != nil {
  66. customerMessageId := Inhandle(data)
  67. //客服的用户列表
  68. sqlStr = "SELECT IF ( b.nickname = '', REPLACE(b.phone,SUBSTR(b.phone,4,4),'****'), b.nickname ) AS name, b.id, e.title, b.headimg, e.type, e.link, e.content, a.create_time, ( SELECT count( h.id ) FROM socialize_message_mailbox h WHERE ( h.type = 4 OR h.type = 5 ) AND h.own_type = 1 AND IF ( h.send_user_type = 1, h.send_user_id = f.id, h.receive_user_id = f.id ) AND h.isread = 0 ) AS number FROM socialize_message_mailbox a LEFT JOIN base_user b ON IF ( a.send_user_type = 1, b.id = a.receive_user_id, b.id = a.send_user_id ) LEFT JOIN socialize_message e ON e.id = a.messag_id LEFT JOIN socialize_chat_session f ON IF ( a.send_user_type = 1, f.id = a.send_user_id, f.id = a.receive_user_id ) WHERE a.id IN (" + customerMessageId + ")" + phoneSql + " ORDER BY a.create_time DESC"
  69. fmt.Println(in.EntUserId)
  70. v = make([]interface{}, 0)
  71. }
  72. }
  73. if sqlStr != "" {
  74. fmt.Println(sqlStr, v)
  75. data = Mysql.SelectBySql(sqlStr, v...)
  76. }
  77. return
  78. }
  79. func (b MessaggeService) SaveMessage(in *messagecenter.MessageEntity) (errorCode int64) {
  80. //先插入信息表
  81. fool := Mysql.ExecTx("聊天信息保存", func(tx *sql.Tx) bool {
  82. //先插入信息表
  83. message := map[string]interface{}{
  84. "appid": in.Appid,
  85. "title": in.Title,
  86. "content": in.Content,
  87. "item": in.ItemType,
  88. "type": in.Type,
  89. "link": in.Link,
  90. "create_time": time.Now().Local().Format(util.Date_Full_Layout),
  91. "create_person": in.SendId,
  92. }
  93. ok := Mysql.InsertByTx(tx, "socialize_message", message)
  94. if ok <= 0 {
  95. return false
  96. }
  97. //在插入邮箱表socialize_message_mailbox
  98. messageMailBox := map[string]interface{}{
  99. "appid": in.Appid,
  100. "messag_id": ok,
  101. "type": in.ItemType,
  102. "create_time": time.Now().Local().Format(util.Date_Full_Layout),
  103. "isread": 0,
  104. "send_isdel": 0,
  105. "receive_isdel": 0,
  106. "iswithdraw": 0,
  107. }
  108. //系统信息处理
  109. if in.ItemType == 6 {
  110. messageMailBox = map[string]interface{}{
  111. "appid": in.Appid,
  112. "messag_id": ok,
  113. "type": in.ItemType,
  114. "create_time": time.Now().Local().Format(util.Date_Full_Layout),
  115. "read_time": time.Now().Local().Format(util.Date_Full_Layout),
  116. "isread": 1,
  117. "send_isdel": 0,
  118. "receive_isdel": 0,
  119. "iswithdraw": 0,
  120. }
  121. if in.OwnType == 1 {
  122. //用户接受系统信息
  123. messageMailBox["own_type"] = 2
  124. messageMailBox["send_user_type"] = 1
  125. messageMailBox["receive_user_type"] = 2
  126. messageMailBox["own_id"] = in.NewUserId
  127. messageMailBox["send_user_id"] = in.ReceiveId
  128. messageMailBox["receive_user_id"] = in.NewUserId
  129. } else {
  130. //客服接受系统信息
  131. messageMailBox["own_type"] = 1
  132. messageMailBox["send_user_type"] = 2
  133. messageMailBox["receive_user_type"] = 1
  134. messageMailBox["own_id"] = in.SendId
  135. messageMailBox["send_user_id"] = in.ReceiveId
  136. messageMailBox["receive_user_id"] = in.SendId
  137. }
  138. receiveOk := Mysql.InsertByTx(tx, "socialize_message_mailbox", messageMailBox)
  139. if receiveOk == 0 {
  140. return false
  141. } else {
  142. return true
  143. }
  144. }
  145. if in.ItemType == 4 || in.ItemType == 5 {
  146. //客服或者机器人聊天
  147. if in.OwnType == 1 {
  148. // (用户发送)客服接受
  149. messageMailBox["own_type"] = 1
  150. messageMailBox["send_user_type"] = 2
  151. messageMailBox["receive_user_type"] = 1
  152. messageMailBox["own_id"] = in.ReceiveId
  153. messageMailBox["send_user_id"] = in.NewUserId
  154. messageMailBox["receive_user_id"] = in.ReceiveId
  155. } else {
  156. //客服发送(用户接收信息)
  157. messageMailBox["own_type"] = 2
  158. messageMailBox["send_user_type"] = 1
  159. messageMailBox["receive_user_type"] = 2
  160. messageMailBox["own_id"] = in.ReceiveId
  161. messageMailBox["send_user_id"] = in.SendId
  162. messageMailBox["receive_user_id"] = in.ReceiveId
  163. if in.ItemType == 4 {
  164. messageMailBox["receive_user_id"] = in.NewUserId
  165. messageMailBox["own_id"] = in.NewUserId
  166. }
  167. }
  168. } else {
  169. messageMailBox["own_type"] = 2
  170. messageMailBox["send_user_type"] = 2
  171. messageMailBox["receive_user_type"] = 2
  172. messageMailBox["own_id"] = in.ReceiveId
  173. messageMailBox["send_user_id"] = in.NewUserId
  174. messageMailBox["receive_user_id"] = in.ReceiveId
  175. }
  176. sendOk := Mysql.InsertByTx(tx, "socialize_message_mailbox", messageMailBox)
  177. if sendOk == 0 {
  178. return false
  179. }
  180. messageMailBox = map[string]interface{}{
  181. "appid": in.Appid,
  182. "messag_id": ok,
  183. "type": in.ItemType,
  184. "create_time": time.Now().Local().Format(util.Date_Full_Layout),
  185. "read_time": time.Now().Local().Format(util.Date_Full_Layout),
  186. "isread": 1,
  187. "send_isdel": 0,
  188. "receive_isdel": 0,
  189. "iswithdraw": 0,
  190. }
  191. if in.ItemType == 4 || in.ItemType == 5 {
  192. //客服或者机器人聊天
  193. if in.OwnType == 1 {
  194. //用户发送(用户接受)
  195. messageMailBox["own_type"] = 2
  196. messageMailBox["send_user_type"] = 2
  197. messageMailBox["receive_user_type"] = 1
  198. messageMailBox["own_id"] = in.NewUserId
  199. messageMailBox["send_user_id"] = in.NewUserId
  200. messageMailBox["receive_user_id"] = in.ReceiveId
  201. } else {
  202. //客服发送信息(用户接受)
  203. messageMailBox["own_type"] = 1
  204. messageMailBox["send_user_type"] = 1
  205. messageMailBox["receive_user_type"] = 2
  206. messageMailBox["own_id"] = in.SendId
  207. messageMailBox["send_user_id"] = in.SendId
  208. messageMailBox["receive_user_id"] = in.ReceiveId
  209. if in.ItemType == 4 {
  210. messageMailBox["receive_user_id"] = in.NewUserId
  211. }
  212. }
  213. } else {
  214. messageMailBox["own_type"] = 2
  215. messageMailBox["send_user_type"] = 2
  216. messageMailBox["receive_user_type"] = 2
  217. messageMailBox["own_id"] = in.NewUserId
  218. messageMailBox["send_user_id"] = in.NewUserId
  219. messageMailBox["receive_user_id"] = in.ReceiveId
  220. }
  221. receiveOk := Mysql.InsertByTx(tx, "socialize_message_mailbox", messageMailBox)
  222. if receiveOk == 0 {
  223. return false
  224. }
  225. return true
  226. })
  227. if fool {
  228. return 0
  229. } else {
  230. return 1
  231. }
  232. }
  233. func (b MessaggeService) FindMessage(in *messagecenter.MessageReq) (*[]map[string]interface{}, int64) {
  234. sqlStr := ""
  235. countSql := ""
  236. v := make([]interface{}, 0)
  237. countV := make([]interface{}, 0)
  238. lastStr := " "
  239. if in.LastId > 0 {
  240. lastStr = " and a.messag_id < " + quitl.InterfaceToStr(in.LastId)
  241. }
  242. switch in.MsgType {
  243. case 2: //点对点聊天
  244. sqlStr = "SELECT a.messag_id as messageId,b.* ,if(a.own_id = a.send_user_id,1,2) as fool FROM socialize_message_mailbox a LEFT JOIN socialize_message b on a.messag_id=b.id left join base_user c on c.id=a.send_user_id left join base_user d on d.id=a.receive_user_id where a.own_id=? and ((a.send_user_id=? and a.receive_user_id=?) or (a.send_user_id=? and a.receive_user_id=?)) and a.type=2 " + lastStr + " ORDER BY a.create_time desc ,a.id asc limit ? , ? "
  245. countSql = "SELECT count(b.id) FROM socialize_message_mailbox a LEFT JOIN socialize_message b on a.messag_id=b.id left join base_user c on c.id=a.send_user_id left join base_user d on d.id=a.receive_user_id where a.own_id=? and ((a.send_user_id=? and a.receive_user_id=?) or (a.send_user_id=? and a.receive_user_id=?)) and a.type=2 " + lastStr
  246. v = append(v, in.NewUserId, in.NewUserId, in.SendId, in.SendId, in.NewUserId, 0, in.PageSize)
  247. countV = append(countV, in.NewUserId, in.NewUserId, in.SendId, in.SendId, in.NewUserId)
  248. break
  249. case 4, 5, 6, 7: //客服聊天
  250. if in.UserType == 1 {
  251. //客服聊天记录查看
  252. sqlStr = "SELECT a.messag_id as messageId,b.*, IF ( a.own_id = a.send_user_id, 1, 2 ) AS fool, a.send_user_type, a.type AS itemType, d.nickname AS robotName, d.headimage AS robotImg, c.customer_service_name AS setName , c.user_id FROM socialize_message_mailbox a LEFT JOIN socialize_message b ON a.messag_id = b.id LEFT JOIN socialize_chat_session c ON IF ( a.send_user_type = 1, c.id = a.send_user_id, c.id = a.receive_user_id ) LEFT JOIN socialize_tenant_robot d ON c.ent_id = d.ent_id WHERE a.own_type = 1 AND c.ent_id = ? AND c.user_id = ? AND (a.type = 5 or a.type=4 or a.type=6 or a.type=7) " + lastStr + " ORDER BY a.create_time desc ,a.id asc limit ? , ? "
  253. v = append(v, in.EntId, in.SendId, 0, in.PageSize)
  254. countSql = "SELECT count(b.id) FROM socialize_message_mailbox a LEFT JOIN socialize_message b ON a.messag_id = b.id LEFT JOIN socialize_chat_session c ON IF ( a.send_user_type = 1, c.id = a.send_user_id, c.id = a.receive_user_id ) LEFT JOIN socialize_tenant_robot d ON c.ent_id = d.ent_id WHERE a.own_type = 1 AND c.ent_id = ? AND c.user_id = ? AND (a.type = 5 or a.type=4) " + lastStr
  255. countV = append(countV, in.EntId, in.SendId)
  256. } else {
  257. //用户聊天记录查看
  258. sqlStr = "SELECT a.messag_id as messageId, b.*, IF ( a.own_id = a.send_user_id, 1, 2 ) AS fool , a.send_user_type, a.type as itemType, d.nickname as robotName, d.headimage as robotImg, c.customer_service_name as setName FROM socialize_message_mailbox a LEFT JOIN socialize_message b ON a.messag_id = b.id LEFT JOIN socialize_chat_session c ON IF ( a.send_user_type = 1, c.id = a.send_user_id, c.id = a.receive_user_id ) left join socialize_tenant_robot d on c.ent_id=d.ent_id WHERE a.own_type = 2 AND c.ent_id =? AND a.own_id =? AND ( a.type = 4 OR a.type = 5 or a.type=6 or a.type=7) " + lastStr + " ORDER BY a.create_time desc ,a.id asc limit ? , ? "
  259. v = append(v, in.SendId, in.NewUserId, 0, in.PageSize)
  260. countSql = "SELECT count(a.id) FROM socialize_message_mailbox a LEFT JOIN socialize_message b ON a.messag_id = b.id LEFT JOIN socialize_chat_session c ON IF ( a.send_user_type = 1, c.id = a.send_user_id, c.id = a.receive_user_id ) left join socialize_tenant_robot d on c.ent_id=d.ent_id WHERE a.own_type = 2 AND c.ent_id =? AND a.own_id =? AND ( a.type = 4 OR a.type = 5 or a.type=6 or a.type=7) " + lastStr
  261. countV = append(countV, in.SendId, in.NewUserId)
  262. }
  263. break
  264. }
  265. fmt.Println(sqlStr, v)
  266. fmt.Println(countSql, countV)
  267. data := Mysql.SelectBySql(sqlStr, v...)
  268. count := Mysql.CountBySql(countSql, countV...)
  269. //自己头像处理
  270. if in.UserType == 2 && count > 0 {
  271. userData := Mysql.FindOne("base_user", map[string]interface{}{"id": in.NewUserId}, "headimg", "")
  272. if userData != nil {
  273. for key := range *data {
  274. (*data)[key]["ownImg"] = (*userData)["headimg"]
  275. }
  276. }
  277. }
  278. updateMap := map[string]interface{}{}
  279. if len(*data) > 0 {
  280. //未读信息修改
  281. switch in.MsgType {
  282. case 2: //点对点聊天
  283. updateMap = map[string]interface{}{
  284. "own_type": 2,
  285. "own_id": in.NewUserId,
  286. "type": 2,
  287. "isread": 0,
  288. }
  289. Mysql.Update("socialize_message_mailbox", updateMap, map[string]interface{}{"isread": 1, "read_time": time.Now().Local().Format(util.Date_Full_Layout)})
  290. break
  291. case 4, 5:
  292. if in.UserType == 1 {
  293. Mysql.UpdateOrDeleteBySql("UPDATE socialize_message_mailbox a SET a.isread = 1, a.read_time = now( ) WHERE a.own_type = 1 AND a.type IN ( 4, 5,6,7) AND a.isread = 0 AND a.own_id IN ( SELECT b.id FROM socialize_chat_session b WHERE b.customer_service_id=? and b.user_id=? )", in.EntUserId, in.SendId)
  294. } else {
  295. Mysql.UpdateOrDeleteBySql("UPDATE socialize_message_mailbox a SET a.isread = 1, a.read_time = now( ) WHERE a.own_type = 2 AND a.type IN ( 4, 5,6,7 ) AND a.isread = 0 AND a.own_id =?", in.NewUserId)
  296. }
  297. break
  298. }
  299. }
  300. return data, count
  301. }
  302. func (b MessaggeService) CreateChatSession(in *messagecenter.ChatSessionReq) (errorCode, sessionId int64) {
  303. fool := Mysql.ExecTx("会话新建", func(tx *sql.Tx) bool {
  304. chatMession := map[string]interface{}{
  305. "handle_status": 0,
  306. "start_time": time.Now().Local().Format(util.Date_Full_Layout),
  307. "appid": in.AppId,
  308. "ent_id": in.EntId,
  309. "customer_service_id": in.CustomerServiceId,
  310. "user_id": in.UserId,
  311. "customer_service_name": in.CustomerserviceName,
  312. }
  313. sessionId = Mysql.InsertByTx(tx, "socialize_chat_session", chatMession)
  314. return sessionId > 0
  315. })
  316. if fool {
  317. return 0, sessionId
  318. } else {
  319. return 1, sessionId
  320. }
  321. }
  322. func (b MessaggeService) CloseChatSession(in *messagecenter.CloseSessionReq) (errorCode int64) {
  323. fool := Mysql.ExecTx("关闭会话", func(tx *sql.Tx) bool {
  324. updateMap := map[string]interface{}{
  325. "id": in.SessionId,
  326. }
  327. fool := Mysql.Update("socialize_chat_session", updateMap, map[string]interface{}{"start_time": time.Now().Local().Format(util.Date_Full_Layout)})
  328. return fool
  329. })
  330. if fool {
  331. return 0
  332. } else {
  333. return 1
  334. }
  335. }
  336. //in数据处理
  337. func Inhandle(data *[]map[string]interface{}) (messId string) {
  338. if len(*data) == 0 {
  339. messId = "''"
  340. return
  341. }
  342. for k, m := range *data {
  343. if k > 0 {
  344. messId += `,`
  345. }
  346. messId += "'" + quitl.InterfaceToStr(m["messageId"]) + "'"
  347. }
  348. return
  349. }
  350. func (m *MessaggeService) SaveAutoReplyMsg(userType, entId, entUserId, userId int64, content, appId, nowFormat string) bool {
  351. return Mysql.ExecTx("保存自动回复消息", func(tx *sql.Tx) bool {
  352. entUserName := ""
  353. if entUserId > 0 {
  354. list := Mysql.SelectBySql(`select customer_service_name from socialize_tenant_seat where appid=? and ent_id=? and customer_service_id=?`, appId, entId, entUserId)
  355. if list != nil && len(*list) > 0 {
  356. entUserName, _ = (*list)[0]["customer_service_name"].(string)
  357. }
  358. }
  359. messageId := Mysql.InsertBySqlByTx(tx, `insert into socialize_message (appid,content,item,type,create_time,create_person) values (?,?,?,?,?,?)`, appId, content, 8, 1, nowFormat, "admin")
  360. sessionId := Mysql.InsertBySqlByTx(tx, `insert into socialize_chat_session (appid,type,ent_id,customer_service_id,customer_service_name,user_id,start_time,end_time) values (?,?,?,?,?,?,?,?)`, appId, 1, entId, entUserId, entUserName, userId, nowFormat, nowFormat)
  361. ok := false
  362. if userType == 1 {
  363. if Mysql.InsertBySqlByTx(tx, `insert into socialize_message_mailbox (appid,messag_id,type,send_user_id,send_user_type,receive_user_id,receive_user_type,own_id,own_type,create_time) values (?,?,?,?,?,?,?,?,?,?)`, appId, messageId, 7, sessionId, 1, userId, 2, sessionId, 1, nowFormat) > 0 {
  364. ok = true
  365. }
  366. } else if userType == 2 {
  367. if Mysql.InsertBySqlByTx(tx, `insert into socialize_message_mailbox (appid,messag_id,type,send_user_id,send_user_type,receive_user_id,receive_user_type,own_id,own_type,create_time) values (?,?,?,?,?,?,?,?,?,?)`, appId, messageId, 7, sessionId, 1, userId, 2, userId, 2, nowFormat) > 0 {
  368. ok = true
  369. }
  370. }
  371. return messageId > 0 && sessionId > 0 && ok
  372. })
  373. }