|
|
@@ -9,6 +9,7 @@ using System.Model;
|
|
9
|
9
|
using System.Threading.Tasks;
|
|
10
|
10
|
using Microsoft.AspNetCore.Authorization;
|
|
11
|
11
|
using Microsoft.AspNetCore.Mvc;
|
|
|
12
|
+using NPOI.SS.Formula.Atp;
|
|
12
|
13
|
using SqlSugar;
|
|
13
|
14
|
using TVShoppingCallCenter_ZLJ.Models.Inputs;
|
|
14
|
15
|
|
|
|
@@ -151,7 +152,7 @@ namespace TVShoppingCallCenter_ZLJ.Controllers.SMS
|
|
151
|
152
|
/// <param name="input"></param>
|
|
152
|
153
|
/// <returns></returns>
|
|
153
|
154
|
[HttpPost("gettemplatebypage")]
|
|
154
|
|
- public async Task<IActionResult> ProductClassList(SMSTemplateInput input)
|
|
|
155
|
+ public async Task<IActionResult> GetTemplateByPage(SMSTemplateInput input)
|
|
155
|
156
|
{
|
|
156
|
157
|
|
|
157
|
158
|
List<IConditionalModel> conModels = new List<IConditionalModel>();
|
|
|
@@ -164,9 +165,13 @@ namespace TVShoppingCallCenter_ZLJ.Controllers.SMS
|
|
164
|
165
|
{
|
|
165
|
166
|
conModels.Add(new ConditionalModel() { FieldName = "F_Tel", ConditionalType = ConditionalType.Like, FieldValue = input.F_Tel });
|
|
166
|
167
|
}
|
|
|
168
|
+ if (input.F_Id>0)
|
|
|
169
|
+ {
|
|
|
170
|
+ conModels.Add(new ConditionalModel() { FieldName = "F_Id", ConditionalType = ConditionalType.Equal, FieldValue = input.F_Id.ToString() });
|
|
|
171
|
+ }
|
|
167
|
172
|
|
|
168
|
173
|
#endregion
|
|
169
|
|
- int count = 0;
|
|
|
174
|
+ RefAsync<int> count = 0;
|
|
170
|
175
|
PageData<T_Bus_SMSTemplate> productClasselist = await bus_SMSTemplateRepository.GetListByPage(conModels, new MyPageModel() { PageIndex = input.pageindex, PageSize = input.pagesize, PageCount = count });
|
|
171
|
176
|
|
|
172
|
177
|
return Success("成功", productClasselist);
|
|
|
@@ -175,6 +180,246 @@ namespace TVShoppingCallCenter_ZLJ.Controllers.SMS
|
|
175
|
180
|
|
|
176
|
181
|
#endregion
|
|
177
|
182
|
|
|
|
183
|
+ #region 短信记录
|
|
|
184
|
+
|
|
|
185
|
+ /// <summary>
|
|
|
186
|
+ /// 新增
|
|
|
187
|
+ /// </summary>
|
|
|
188
|
+ /// <param name="input"></param>
|
|
|
189
|
+ /// <returns></returns>
|
|
|
190
|
+ [HttpPost("addsmslog")]
|
|
|
191
|
+ public async Task<IActionResult> AddSMSLog(SMSLogInput input)
|
|
|
192
|
+ {
|
|
|
193
|
+
|
|
|
194
|
+ #region 验证 参数
|
|
|
195
|
+
|
|
|
196
|
+
|
|
|
197
|
+ if (string.IsNullOrEmpty(input.F_Content))
|
|
|
198
|
+ return Error("没有内容");
|
|
|
199
|
+ if (string.IsNullOrEmpty(input.F_Name))
|
|
|
200
|
+ input.F_Name = DateTime.Now.ToString("yyyyMMddhhmmss");
|
|
|
201
|
+ if (input.F_Type == 1 || input.F_Type == 2)
|
|
|
202
|
+ {
|
|
|
203
|
+ if(input.F_TemplateId<1)
|
|
|
204
|
+ return Error("请选择模板");
|
|
178
|
205
|
|
|
|
206
|
+ }
|
|
|
207
|
+ if (input.F_Type == 2 || input.F_Type == 4)
|
|
|
208
|
+ {
|
|
|
209
|
+ if (input.F_PlanSendTime <= DateTime.Now)
|
|
|
210
|
+ { return Error("定时发送时间无效"); }
|
|
|
211
|
+ } else
|
|
|
212
|
+ {
|
|
|
213
|
+ input.F_PlanSendTime = DateTime.Now;
|
|
|
214
|
+ }
|
|
|
215
|
+ if (string.IsNullOrEmpty(input.F_Tel))
|
|
|
216
|
+ return Error("请输入手机号码");
|
|
|
217
|
+
|
|
|
218
|
+
|
|
|
219
|
+ #endregion
|
|
|
220
|
+ List<T_Bus_SMSLog> modelAddList = new List<T_Bus_SMSLog>();
|
|
|
221
|
+
|
|
|
222
|
+ T_Bus_SMSLog ModelAdd = new T_Bus_SMSLog();
|
|
|
223
|
+ ModelConvertHelper<T_Bus_SMSLog, SMSLogInput>.ModeToModelDefault(ModelAdd, input);
|
|
|
224
|
+ ModelAdd.F_Content = input.F_Content.Replace("{phone}", input.F_Tel).Replace("{name}","");
|
|
|
225
|
+ ModelAdd.F_AddUser = UserLogin.UserId.ObjToInt();
|
|
|
226
|
+ ModelAdd.F_AddUserName = UserLogin.UserName;
|
|
|
227
|
+ ModelAdd.F_AddTime = DateTime.Now;
|
|
|
228
|
+ ModelAdd.F_Id=Guid.NewGuid().ToString().Replace("-","");
|
|
|
229
|
+ ModelAdd.F_Message = "";
|
|
|
230
|
+ ModelAdd.F_State = 0;
|
|
|
231
|
+
|
|
|
232
|
+ //ModelAdd.F_Tel = input.F_Tel;
|
|
|
233
|
+ //ModelAdd.F_PlanSendTime = input.F_PlanSendTime;
|
|
|
234
|
+ //ModelAdd.F_TemplateId = input.F_TemplateId;
|
|
|
235
|
+ //ModelAdd.F_Type = input.F_Type;
|
|
|
236
|
+ //modelAddList.Add(ModelAdd);
|
|
|
237
|
+ string retstr =await SendSMSLog(modelAddList);
|
|
|
238
|
+ if (retstr.StartsWith("成功"))
|
|
|
239
|
+ {
|
|
|
240
|
+ return Success(retstr);
|
|
|
241
|
+ }
|
|
|
242
|
+
|
|
|
243
|
+ return Error(retstr);
|
|
|
244
|
+
|
|
|
245
|
+ }
|
|
|
246
|
+
|
|
|
247
|
+
|
|
|
248
|
+ /// <summary>
|
|
|
249
|
+ /// 更新
|
|
|
250
|
+ /// </summary>
|
|
|
251
|
+ /// <param name="input"></param>
|
|
|
252
|
+ /// <returns></returns>
|
|
|
253
|
+ [HttpPost("updatesmslog")]
|
|
|
254
|
+ public async Task<IActionResult> UpdateSMSLog(SMSTemplateInput input)
|
|
|
255
|
+ {
|
|
|
256
|
+
|
|
|
257
|
+ #region 验证 参数
|
|
|
258
|
+
|
|
|
259
|
+
|
|
|
260
|
+ if (string.IsNullOrEmpty(input.F_Content))
|
|
|
261
|
+ return Error("请输入模板内容");
|
|
|
262
|
+ if (string.IsNullOrEmpty(input.F_ModelName))
|
|
|
263
|
+ return Error("请输入模板名称");
|
|
|
264
|
+ if (string.IsNullOrEmpty(input.F_Tel))
|
|
|
265
|
+ return Error("请输入要绑定400电话");
|
|
|
266
|
+ if (input.F_Id < 1)
|
|
|
267
|
+ return Error("参数缺失");
|
|
|
268
|
+
|
|
|
269
|
+ #endregion
|
|
|
270
|
+
|
|
|
271
|
+ if (await bus_SMSTemplateRepository.GetCount(q => q.F_ModelName == input.F_ModelName && q.F_Id != input.F_Id) > 0)
|
|
|
272
|
+ {
|
|
|
273
|
+ return Error("模板名称不能重复");
|
|
|
274
|
+ }
|
|
|
275
|
+ input.F_AddTime = DateTime.Now;
|
|
|
276
|
+ T_Bus_SMSTemplate ModelAdd = await bus_SMSTemplateRepository.GetSingle(q => q.F_Id == input.F_Id);
|
|
|
277
|
+ ModelConvertHelper<T_Bus_SMSTemplate, SMSTemplateInput>.ModeToModelDefault(ModelAdd, input);
|
|
|
278
|
+ ModelAdd.F_AddUser = UserLogin.UserId.ObjToInt();
|
|
|
279
|
+ ModelAdd.F_AddUserName = UserLogin.UserName;
|
|
|
280
|
+
|
|
|
281
|
+ if (await bus_SMSTemplateRepository.Update(ModelAdd))
|
|
|
282
|
+ {
|
|
|
283
|
+ return Success("保存成功");
|
|
|
284
|
+ }
|
|
|
285
|
+
|
|
|
286
|
+ return Error("保存失败,请重试!");
|
|
|
287
|
+
|
|
|
288
|
+ }
|
|
|
289
|
+
|
|
|
290
|
+ /// <summary>
|
|
|
291
|
+ /// 删除
|
|
|
292
|
+ /// </summary>
|
|
|
293
|
+ /// <param name="ids">格式 1,2,3,4</param>
|
|
|
294
|
+ /// <returns></returns>
|
|
|
295
|
+ [HttpPost("deletesmslog")]
|
|
|
296
|
+ public async Task<IActionResult> DeleteSMSLog(string ids)
|
|
|
297
|
+ {
|
|
|
298
|
+ if (string.IsNullOrEmpty(ids))
|
|
|
299
|
+ return Error("请输入删除id");
|
|
|
300
|
+ ids = ids.Trim(',');
|
|
|
301
|
+ if (string.IsNullOrEmpty(ids))
|
|
|
302
|
+ return Error("请输入删除id");
|
|
|
303
|
+ string[] idsArry = ids.Split(',');
|
|
|
304
|
+ if (await bus_SMSTemplateRepository.Delete(q => idsArry.Contains(q.F_Id.ToString())))
|
|
|
305
|
+ {
|
|
|
306
|
+ return Success("删除成功");
|
|
|
307
|
+ }
|
|
|
308
|
+ else
|
|
|
309
|
+ {
|
|
|
310
|
+ return Error("删除失败,请重试!");
|
|
|
311
|
+ }
|
|
|
312
|
+ }
|
|
|
313
|
+
|
|
|
314
|
+ /// <summary>
|
|
|
315
|
+ /// 分页查询
|
|
|
316
|
+ /// </summary>
|
|
|
317
|
+ /// <param name="input"></param>
|
|
|
318
|
+ /// <returns></returns>
|
|
|
319
|
+ [HttpPost("getsmslogbypage")]
|
|
|
320
|
+ public async Task<IActionResult> GetSMSLogByPage(SMSLogInput input)
|
|
|
321
|
+ {
|
|
|
322
|
+
|
|
|
323
|
+ List<IConditionalModel> conModels = new List<IConditionalModel>();
|
|
|
324
|
+ #region 条件筛选
|
|
|
325
|
+ if (!string.IsNullOrEmpty(input.F_Name))
|
|
|
326
|
+ {
|
|
|
327
|
+ conModels.Add(new ConditionalModel() { FieldName = "F_Name", ConditionalType = ConditionalType.Like, FieldValue = input.F_Name });
|
|
|
328
|
+ }
|
|
|
329
|
+ if (!string.IsNullOrEmpty(input.F_Tel))
|
|
|
330
|
+ {
|
|
|
331
|
+ conModels.Add(new ConditionalModel() { FieldName = "F_Tel", ConditionalType = ConditionalType.Like, FieldValue = input.F_Tel });
|
|
|
332
|
+ }
|
|
|
333
|
+ if (input.SearchEndTime != null)
|
|
|
334
|
+ {
|
|
|
335
|
+ conModels.Add(new ConditionalModel() { FieldName = "F_AddTime", ConditionalType = ConditionalType.LessThan, FieldValue = input.SearchEndTime.GetValueOrDefault().ToString("yyyy-MM-dd 23:59:59") });
|
|
|
336
|
+ }
|
|
|
337
|
+ if (input.F_TemplateId >0)
|
|
|
338
|
+ {
|
|
|
339
|
+ conModels.Add(new ConditionalModel() { FieldName = "F_TemplateId", ConditionalType = ConditionalType.Equal, FieldValue = input.F_TemplateId.ToString() });
|
|
|
340
|
+ }
|
|
|
341
|
+ if (input.SearchStartTime != null)
|
|
|
342
|
+ {
|
|
|
343
|
+ conModels.Add(new ConditionalModel() { FieldName = "F_AddTime", ConditionalType = ConditionalType.GreaterThan, FieldValue = input.SearchStartTime.GetValueOrDefault().ToString("yyyy-MM-dd 00:00:01") });
|
|
|
344
|
+ }
|
|
|
345
|
+ if (input.F_State > 0)
|
|
|
346
|
+ {
|
|
|
347
|
+ conModels.Add(new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.Equal, FieldValue = input.F_State.ToString() });
|
|
|
348
|
+ }
|
|
|
349
|
+
|
|
|
350
|
+ #endregion
|
|
|
351
|
+ RefAsync<int> count = 0;
|
|
|
352
|
+ PageData<T_Bus_SMSLog> productClasselist = await bus_SMSLogRepository.GetListByPage(conModels, new MyPageModel() { PageIndex = input.pageindex, PageSize = input.pagesize, PageCount = count });
|
|
|
353
|
+
|
|
|
354
|
+ return Success("成功", productClasselist);
|
|
|
355
|
+ }
|
|
|
356
|
+
|
|
|
357
|
+
|
|
|
358
|
+ #endregion
|
|
|
359
|
+
|
|
|
360
|
+
|
|
|
361
|
+ #region 方法
|
|
|
362
|
+
|
|
|
363
|
+ private async Task<string> SendSMSLog(List<T_Bus_SMSLog> list)
|
|
|
364
|
+ {
|
|
|
365
|
+ if (list != null && list.Count > 0)
|
|
|
366
|
+ {
|
|
|
367
|
+ int n = list.Count;
|
|
|
368
|
+ int n1 = 0;
|
|
|
369
|
+ int n2 = 0;
|
|
|
370
|
+ bool bl = await bus_SMSLogRepository.AddMany(list);
|
|
|
371
|
+ //记录短信 可暂时不发 放任务中
|
|
|
372
|
+ if (bl)
|
|
|
373
|
+ {
|
|
|
374
|
+ List<T_Bus_SMSLog> templist = new List<T_Bus_SMSLog>();
|
|
|
375
|
+ foreach (T_Bus_SMSLog m in list)
|
|
|
376
|
+ {
|
|
|
377
|
+
|
|
|
378
|
+ string ret = SendMessage(m.F_Tel, m.F_Content);
|
|
|
379
|
+ m.F_Message = ret;
|
|
|
380
|
+ m.F_SendTime = DateTime.Now;
|
|
|
381
|
+ if (ret == "success")
|
|
|
382
|
+ {
|
|
|
383
|
+ n1++;
|
|
|
384
|
+ m.F_State = 1;
|
|
|
385
|
+ }
|
|
|
386
|
+ else
|
|
|
387
|
+ {
|
|
|
388
|
+ n2++;
|
|
|
389
|
+ m.F_State = 2;
|
|
|
390
|
+ }
|
|
|
391
|
+ templist.Add(m);
|
|
|
392
|
+ if (templist.Count > 10)
|
|
|
393
|
+ {
|
|
|
394
|
+ if (!await bus_SMSLogRepository.UpdateListToColumns(templist, s => new { s.F_State, s.F_SendTime, s.F_Message }))
|
|
|
395
|
+ {
|
|
|
396
|
+ templist = new List<T_Bus_SMSLog>();
|
|
|
397
|
+ return string.Format("失败:全部/成功/失败-{0}/{1}/{2}", n, n1, n2);
|
|
|
398
|
+ }
|
|
|
399
|
+ templist = new List<T_Bus_SMSLog>();
|
|
|
400
|
+ }
|
|
|
401
|
+
|
|
|
402
|
+ }
|
|
|
403
|
+ if (templist.Count > 0)
|
|
|
404
|
+ {
|
|
|
405
|
+ await bus_SMSLogRepository.UpdateListToColumns(templist, s => new { s.F_State, s.F_SendTime, s.F_Message });
|
|
|
406
|
+ }
|
|
|
407
|
+ return string.Format("成功:全部/成功/失败-{0}/{1}/{2}", n, n1, n2);
|
|
|
408
|
+ }
|
|
|
409
|
+ else
|
|
|
410
|
+ {
|
|
|
411
|
+ return "失败:短信插入失败";
|
|
|
412
|
+ }
|
|
|
413
|
+ }
|
|
|
414
|
+
|
|
|
415
|
+ return "成功:" + 0;
|
|
|
416
|
+ }
|
|
|
417
|
+
|
|
|
418
|
+
|
|
|
419
|
+ private string SendMessage(string phone,string content)
|
|
|
420
|
+ {
|
|
|
421
|
+ return "success";
|
|
|
422
|
+ }
|
|
|
423
|
+ #endregion
|
|
179
|
424
|
}
|
|
180
|
425
|
}
|