Explorar el Código

在线客服bug

zhoufan %!s(int64=8) %!d(string=hace) años
padre
commit
c0c8a9abe6

+ 141 - 113
CallCenterCommon/CallCenter.WebChatServer/ChatServer.cs

@@ -132,9 +132,24 @@ namespace CallCenter.WebChatServer
132 132
                                 code = cs.GetCode();
133 133
                             }
134 134
                             msg.code = code;
135
-                            var cususer = cs.GetCusUser(code);//获取是否存在此客户
136
-                            if (cususer != null)
135
+
136
+                            var cusconn = Customers.Where(p => p.Code == code).FirstOrDefault();
137
+                            if (cusconn == null)
137 138
                             {
139
+                                var cususer = cs.GetCusUser(code);//获取是否存在此客户
140
+                                if (cususer == null)
141
+                                {
142
+                                    ChatSql.T_Chat_User user = new ChatSql.T_Chat_User();
143
+                                    user.F_OpenId = code;
144
+                                    user.F_Account = code;
145
+                                    user.F_Type = 1;
146
+                                    user.F_State = 0;
147
+                                    user.F_IsDelete = 0;
148
+                                    user.F_CreateTime = DateTime.Now;
149
+                                    user.F_Id = cs.AddUser(user);
150
+                                    cususer = user;
151
+                                }
152
+
138 153
                                 if (string.IsNullOrEmpty(cususer.F_Name))
139 154
                                 {
140 155
                                     cususer.F_Name = ConfigurationManager.AppSettings["anyname"];
@@ -148,86 +163,92 @@ namespace CallCenter.WebChatServer
148 163
 
149 164
                                 cus.Name = cususer.F_Name;
150 165
                                 cus.HeadImgUrl = cususer.F_HeadImgUrl;
151
-                            }
152
-
153
-                            msg.name = cus.Name;
154
-                            msg.headimgurl = cus.HeadImgUrl;
155 166
 
156
-                            cus.SessionID = session.SessionID;
157
-                            cus.Code = code;
158
-                            cus.IsSend = 0;
167
+                                msg.name = cus.Name;
168
+                                msg.headimgurl = cus.HeadImgUrl;
159 169
 
170
+                                cus.SessionID = session.SessionID;
171
+                                cus.Code = code;
172
+                                cus.IsSend = 0;
160 173
 
161
-                            //if (Servicers.Count <= 0)
162
-                            //{
163
-                            //    ChatClass.Message newmsg = new ChatClass.Message();
164
-                            //    newmsg.action = "ServicersAllOff";
165
-                            //    newmsg.msg = ConfigurationManager.AppSettings["busy"];
166
-                            //    session.Send(JsonConvert.SerializeObject(newmsg));//向客户发送客服不在线
167
-                            //}
168 174
 
169
-                            if (Servicers.Count > 0)
170
-                            {
171
-                                cus.ServicerSessionID = SplitCustomer(cus);
172
-                            }
175
+                                //if (Servicers.Count <= 0)
176
+                                //{
177
+                                //    ChatClass.Message newmsg = new ChatClass.Message();
178
+                                //    newmsg.action = "ServicersAllOff";
179
+                                //    newmsg.msg = ConfigurationManager.AppSettings["busy"];
180
+                                //    session.Send(JsonConvert.SerializeObject(newmsg));//向客户发送客服不在线
181
+                                //}
173 182
 
174
-                            
183
+                                if (Servicers.Count > 0)
184
+                                {
185
+                                    cus.ServicerSessionID = SplitCustomer(cus);
186
+                                }
175 187
 
176
-                            ChatSql.T_Chat_IPList ipmodel = new ChatSql.T_Chat_IPList();
177
-                            ipmodel = cs.GetIPInfo(ip, code);
178
-                            if (ipmodel == null)
179
-                            {
180
-                                #region ip记录
181
-                                ipmodel = new ChatSql.T_Chat_IPList();
182 188
 
183
-                                string ipinfojson = ChatCommon.HttpGet(ConfigurationManager.AppSettings["ipurl"] + "?ip=" + ip);
184
-                                var ipinfos = JsonConvert.DeserializeObject<JObject>(ipinfojson);
185
-                                var ipinfo = JsonConvert.DeserializeObject<JObject>(ipinfos["data"].ToString());
186 189
 
187
-                                ipmodel.F_IP = ip;
188
-                                ipmodel.F_OpenId = cus.Code;
189
-                                ipmodel.F_Type = 2;
190
-                                ipmodel.F_Country = ipinfo["country"].ToString();
191
-                                ipmodel.F_CountryCode = ipinfo["country_id"].ToString();
192
-                                ipmodel.F_Area = ipinfo["area"].ToString();
193
-                                ipmodel.F_AreaCode = ipinfo["area_id"].ToString();
194
-                                ipmodel.F_Region = ipinfo["region"].ToString();
195
-                                ipmodel.F_RegionCode = ipinfo["region_id"].ToString();
196
-                                ipmodel.F_City = ipinfo["city"].ToString();
197
-                                ipmodel.F_CityCode = ipinfo["city_id"].ToString();
198
-                                ipmodel.F_County = ipinfo["county"].ToString();
199
-                                ipmodel.F_CountyCode = ipinfo["county_id"].ToString();
200
-                                ipmodel.F_ISP = ipinfo["isp"].ToString();
201
-                                ipmodel.F_ISPCode = ipinfo["isp_id"].ToString();
202
-                                ipmodel.F_CreateTime = DateTime.Now;
203
-
204
-                                cs.AddIP(ipmodel);
205
-                                #endregion
206
-                            }
190
+                                ChatSql.T_Chat_IPList ipmodel = new ChatSql.T_Chat_IPList();
191
+                                ipmodel = cs.GetIPInfo(ip, code);
192
+                                if (ipmodel == null)
193
+                                {
194
+                                    #region ip记录
195
+                                    ipmodel = new ChatSql.T_Chat_IPList();
196
+
197
+                                    string ipinfojson = ChatCommon.HttpGet(ConfigurationManager.AppSettings["ipurl"] + "?ip=" + ip);
198
+                                    var ipinfos = JsonConvert.DeserializeObject<JObject>(ipinfojson);
199
+                                    var ipinfo = JsonConvert.DeserializeObject<JObject>(ipinfos["data"].ToString());
200
+
201
+                                    ipmodel.F_IP = ip;
202
+                                    ipmodel.F_OpenId = cus.Code;
203
+                                    ipmodel.F_Type = 2;
204
+                                    ipmodel.F_Country = ipinfo["country"].ToString();
205
+                                    ipmodel.F_CountryCode = ipinfo["country_id"].ToString();
206
+                                    ipmodel.F_Area = ipinfo["area"].ToString();
207
+                                    ipmodel.F_AreaCode = ipinfo["area_id"].ToString();
208
+                                    ipmodel.F_Region = ipinfo["region"].ToString();
209
+                                    ipmodel.F_RegionCode = ipinfo["region_id"].ToString();
210
+                                    ipmodel.F_City = ipinfo["city"].ToString();
211
+                                    ipmodel.F_CityCode = ipinfo["city_id"].ToString();
212
+                                    ipmodel.F_County = ipinfo["county"].ToString();
213
+                                    ipmodel.F_CountyCode = ipinfo["county_id"].ToString();
214
+                                    ipmodel.F_ISP = ipinfo["isp"].ToString();
215
+                                    ipmodel.F_ISPCode = ipinfo["isp_id"].ToString();
216
+                                    ipmodel.F_CreateTime = DateTime.Now;
217
+
218
+                                    cs.AddIP(ipmodel);
219
+                                    #endregion
220
+                                }
207 221
 
208
-                            msg.data = ipmodel;
222
+                                msg.data = ipmodel;
209 223
 
210
-                            #region 签入时间
211
-                            ChatSql.T_Chat_InOut inoutmodel = new ChatSql.T_Chat_InOut();
212
-                            inoutmodel.F_OpenId = cus.Code;
213
-                            inoutmodel.F_IP = ip;
214
-                            inoutmodel.F_Type = 2;
215
-                            inoutmodel.F_InTime = DateTime.Now;
224
+                                #region 签入时间
225
+                                ChatSql.T_Chat_InOut inoutmodel = new ChatSql.T_Chat_InOut();
226
+                                inoutmodel.F_OpenId = cus.Code;
227
+                                inoutmodel.F_IP = ip;
228
+                                inoutmodel.F_Type = 2;
229
+                                inoutmodel.F_InTime = DateTime.Now;
216 230
 
217
-                            cs.AddInOut(inoutmodel);
218
-                            #endregion
231
+                                cs.AddInOut(inoutmodel);
232
+                                #endregion
219 233
 
220
-                            cus.IPData = ipmodel;
221
-                            Customers.Add(cus);//将客户新增到在线客户列表
222
-
223
-                            ChatClass.Message serntcmsg = new ChatClass.Message();
224
-                            serntcmsg.action = "serreceive";
225
-                            serntcmsg.msg = cus.Name + " 上线";
226
-                            serntcmsg.code = cus.Code;
227
-                            serntcmsg.name = cus.Name;
228
-                            serntcmsg.data = ipmodel;
229
-                            serntcmsg.state = 0;
230
-                            SendMsgToRemotePoint(cus.ServicerSessionID, JsonConvert.SerializeObject(serntcmsg));
234
+                                cus.IPData = ipmodel;
235
+                                Customers.Add(cus);//将客户新增到在线客户列表
236
+
237
+                                ChatClass.Message serntcmsg = new ChatClass.Message();
238
+                                serntcmsg.action = "serreceive";
239
+                                serntcmsg.msg = cus.Name + " 上线";
240
+                                serntcmsg.code = cus.Code;
241
+                                serntcmsg.name = cus.Name;
242
+                                serntcmsg.data = ipmodel;
243
+                                serntcmsg.state = 0;
244
+                                SendMsgToRemotePoint(cus.ServicerSessionID, JsonConvert.SerializeObject(serntcmsg));
245
+                            }
246
+                            else
247
+                            {
248
+                                msg.code = "";
249
+                                msg.state = 0;
250
+                                msg.msg = "请不要打开多个聊天窗口";
251
+                            }
231 252
                         }
232 253
                         else
233 254
                         {
@@ -241,56 +262,63 @@ namespace CallCenter.WebChatServer
241 262
                         if (!cs.IsBlack(ip))
242 263
                         {
243 264
                             var cussend = Customers.Where(p => p.SessionID == session.SessionID).FirstOrDefault();
244
-
245
-                            if (Servicers.Count <= 0)
265
+                            if (cussend != null)
246 266
                             {
247
-                                cussend.IsSend = 1;
248
-
249
-                                msg.state = 0;
250
-                                msg.msg = ConfigurationManager.AppSettings["busy"];
251
-                            }
252
-                            else
253
-                            {
254
-                                if (string.IsNullOrEmpty(cussend.ServicerSessionID))
267
+                                if (Servicers.Count <= 0)
255 268
                                 {
256
-                                    cussend.ServicerSessionID = SplitCustomer(cussend);
257
-                                }
258
-                                ChatClass.Message serrecmsg = new ChatClass.Message();
259
-                                serrecmsg.action = "serreceive";
260
-                                serrecmsg.msg = msg.msg;
261
-                                serrecmsg.code = cussend.Code;
262
-                                serrecmsg.name = cussend.Name;
263
-                                serrecmsg.headimgurl = cussend.HeadImgUrl;
264
-                                serrecmsg.state = 1;
265
-                                if (SendMsgToRemotePoint(cussend.ServicerSessionID, JsonConvert.SerializeObject(serrecmsg)))
266
-                                {
267
-                                    var serreceive = Servicers.Where(p => p.SessionID == cussend.ServicerSessionID).FirstOrDefault();
268
-
269
-                                    ChatSql.T_Chat_Message cusmsg = new ChatSql.T_Chat_Message();
270
-                                    cusmsg.F_FromUser = cussend.Code;
271
-                                    cusmsg.F_ToUser = serreceive.Code;
272
-                                    cusmsg.F_Message = msg.msg;
273
-                                    cusmsg.F_IP = ip;
274
-                                    cusmsg.F_SourceType = 1;
275
-                                    cusmsg.F_MessageType = 1;
276
-                                    cusmsg.F_State = 0;
277
-                                    cusmsg.F_IsDelete = 0;
278
-                                    cusmsg.F_CreateTime = DateTime.Now;
279
-                                    cusmsg.F_CreateUser = serreceive.Code;
280
-
281
-                                    cs.AddMsg(cusmsg);
269
+                                    cussend.IsSend = 1;
270
+
271
+                                    msg.state = 0;
272
+                                    msg.msg = ConfigurationManager.AppSettings["busy"];
282 273
                                 }
283 274
                                 else
284 275
                                 {
285
-                                    //ChatClass.Message newmsg = new ChatClass.Message();
286
-                                    //newmsg.action = "CusSendError";
287
-                                    //newmsg.msg = "发送失败";
288
-                                    //session.Send(JsonConvert.SerializeObject(newmsg));
289
-
290
-                                    msg.state = 0;
291
-                                    msg.msg = "发送失败";
276
+                                    if (string.IsNullOrEmpty(cussend.ServicerSessionID))
277
+                                    {
278
+                                        cussend.ServicerSessionID = SplitCustomer(cussend);
279
+                                    }
280
+                                    ChatClass.Message serrecmsg = new ChatClass.Message();
281
+                                    serrecmsg.action = "serreceive";
282
+                                    serrecmsg.msg = msg.msg;
283
+                                    serrecmsg.code = cussend.Code;
284
+                                    serrecmsg.name = cussend.Name;
285
+                                    serrecmsg.headimgurl = cussend.HeadImgUrl;
286
+                                    serrecmsg.state = 1;
287
+                                    if (SendMsgToRemotePoint(cussend.ServicerSessionID, JsonConvert.SerializeObject(serrecmsg)))
288
+                                    {
289
+                                        var serreceive = Servicers.Where(p => p.SessionID == cussend.ServicerSessionID).FirstOrDefault();
290
+
291
+                                        ChatSql.T_Chat_Message cusmsg = new ChatSql.T_Chat_Message();
292
+                                        cusmsg.F_FromUser = cussend.Code;
293
+                                        cusmsg.F_ToUser = serreceive.Code;
294
+                                        cusmsg.F_Message = msg.msg;
295
+                                        cusmsg.F_IP = ip;
296
+                                        cusmsg.F_SourceType = 1;
297
+                                        cusmsg.F_MessageType = 1;
298
+                                        cusmsg.F_State = 0;
299
+                                        cusmsg.F_IsDelete = 0;
300
+                                        cusmsg.F_CreateTime = DateTime.Now;
301
+                                        cusmsg.F_CreateUser = serreceive.Code;
302
+
303
+                                        cs.AddMsg(cusmsg);
304
+                                    }
305
+                                    else
306
+                                    {
307
+                                        //ChatClass.Message newmsg = new ChatClass.Message();
308
+                                        //newmsg.action = "CusSendError";
309
+                                        //newmsg.msg = "发送失败";
310
+                                        //session.Send(JsonConvert.SerializeObject(newmsg));
311
+
312
+                                        msg.state = 0;
313
+                                        msg.msg = "发送失败";
314
+                                    }
292 315
                                 }
293 316
                             }
317
+                            else
318
+                            {
319
+                                msg.state = 0;
320
+                                msg.msg = "发送失败";
321
+                            }
294 322
                         }
295 323
                         else
296 324
                         {

+ 1 - 1
CallCenterCommon/CallCenter.WebChatServer/Program.cs

@@ -41,7 +41,7 @@ namespace CallCenter.WebChatServer
41 41
                             foreach (var cus in sr.Customers)
42 42
                             {
43 43
                                 var ser = sr.Servicers.Where(p => p.SessionID == cus.ServicerSessionID).FirstOrDefault();
44
-                                Console.WriteLine(cus.Name + "--" + (ser == null ? "未分配" : ser.Name + "(" + ser.Code + ")"));
44
+                                Console.WriteLine(cus.Name + "(" + cus.Code + ")--" + (ser == null ? "未分配" : ser.Name + "(" + ser.Code + ")"));
45 45
                             }
46 46
                             break;
47 47
                         case "4":