You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

807 lines
33 KiB

  1. using System;
  2. using Learun.Application.Base.SystemModule;
  3. using Learun.Application.Organization;
  4. using Learun.Application.TwoDevelopment.EducationalAdministration;
  5. using Learun.Util;
  6. using Learun.Util.Operat;
  7. using Nancy;
  8. using System.Collections.Generic;
  9. using System.Configuration;
  10. using System.Linq;
  11. using Learun.Application.TwoDevelopment.LR_Desktop;
  12. using Learun.Cache.Base;
  13. using Learun.Cache.Factory;
  14. using Quanjiang.DigitalScholl.SendSms;
  15. namespace Learun.Application.WebApi
  16. {
  17. /// <summary>
  18. /// 版 本 Learun-ADMS V7.0.0 数字化智慧校园
  19. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  20. /// 创建人:数字化智慧校园-框架开发组
  21. /// 日 期:2017.05.12
  22. /// 描 述:用户信息
  23. /// </summary>
  24. public class UserApi : BaseApi
  25. {
  26. /// <summary>
  27. /// 注册接口
  28. /// </summary>
  29. public UserApi()
  30. : base("/learun/adms/user")
  31. {
  32. Post["/login"] = Login;
  33. Post["/logincodeverify"] = LoginCodeVerify;
  34. Post["/modifypw"] = ModifyPassword;
  35. Post["/modifypwiden"] = ModifyPasswordiden;
  36. Post["/unbundWeiXin"] = DoUnbundWeiXin;
  37. Post["/loginbyIdCard"] = LoginByIdCard;
  38. Get["/info"] = Info;
  39. Get["/onedrivelogin"] = onedrivelogin;
  40. Get["/map"] = GetMap;
  41. Get["/img"] = GetImg;
  42. Get["/imgfordc"] = GetImgForDC;
  43. Get["/saveMap"] = GetSaveClassMap;
  44. Get["/checkupdate"] = CheckUpdate;
  45. }
  46. private UserIBLL userIBLL = new UserBLL();
  47. //private logibll userIBLL = new UserBLL();
  48. private PostIBLL postIBLL = new PostBLL();
  49. private RoleIBLL roleIBLL = new RoleBLL();
  50. private StuInfoBasicIBLL stuInfoBasicIBLL = new StuInfoBasicBLL();
  51. private EmpInfoIBLL empInfoIBLL = new EmpInfoBLL();
  52. CdMajorIBLL majorIbll = new CdMajorBLL();
  53. private readonly ISms yixintongSms = new YixintongSms();
  54. private ICache redisCache = CacheFactory.CaChe();
  55. private Sys_UpdateRecordIBLL sysUpdateRecordIbll = new Sys_UpdateRecordBLL();
  56. AnnexesFileIBLL annexesFileIbll=new AnnexesFileBLL();
  57. /// <summary>
  58. /// 检查更新
  59. /// </summary>
  60. /// <param name="_"></param>
  61. /// <returns></returns>
  62. private Response CheckUpdate(dynamic _)
  63. {
  64. var update=sysUpdateRecordIbll.GetNewest();
  65. if (update!=null&&!string.IsNullOrEmpty(update.AppUrl))
  66. {
  67. var downurl = annexesFileIbll.GetEntityByFolderId(update.AppUrl);
  68. if (downurl.F_FilePath.Contains("Resource"))
  69. {
  70. return Success(new { version = update.VersionNum, content = update.Content, url ="/"+ downurl.F_FilePath.Substring(downurl.F_FilePath.IndexOf("Resource")) });
  71. }
  72. return Success(new { version = update.VersionNum, content = update.Content, url = "" });
  73. }
  74. return Success(new {version="1.0.0",content="",url=""});
  75. }
  76. /// <summary>
  77. /// 登录二次短信验证
  78. /// </summary>
  79. /// <param name="_"></param>
  80. /// <returns></returns>
  81. private Response LoginCodeVerify(dynamic _)
  82. {
  83. MobileVerify mobileVerify = this.GetReqData<MobileVerify>();
  84. var code = redisCache.Read<string>("studentuserlogin_" + mobileVerify.mobile);
  85. if (!string.IsNullOrEmpty(code) && code == mobileVerify.verifycode)
  86. {
  87. return Success("验证成功。");
  88. }
  89. else
  90. {
  91. return Fail("验证失败,验证码错误或已失效。");
  92. }
  93. }
  94. /// <summary>
  95. /// 忘记密码,发送验证码
  96. /// </summary>
  97. /// <param name="_"></param>
  98. /// <returns></returns>
  99. private Response Sendcode(dynamic _)
  100. {
  101. LoginModel loginModel = this.GetReqData<LoginModel>();
  102. UserEntity userEntity = userIBLL.GetEntityByMobile(loginModel.username);
  103. #region 写入日志
  104. LogEntity logEntity = new LogEntity();
  105. logEntity.F_CategoryId = 1;
  106. logEntity.F_OperateTypeId = ((int)OperationType.Login).ToString();
  107. logEntity.F_OperateType = EnumAttribute.GetDescription(OperationType.Login);
  108. logEntity.F_OperateAccount = loginModel.username + "(" + userEntity.F_RealName + ")";
  109. logEntity.F_OperateUserId = !string.IsNullOrEmpty(userEntity.F_UserId) ? userEntity.F_UserId : loginModel.username;
  110. logEntity.F_Module = Config.GetValue("SoftName");
  111. logEntity.F_Description = "移动端";
  112. #endregion
  113. string raRndNum = Learun.Util.CommonHelper.RndNum(6);
  114. var listStr = new List<string>();
  115. var str1 = $"欢迎使用智慧校园,您本次登录的验证码是 " + raRndNum + "。";
  116. listStr.Add(str1);
  117. var result = yixintongSms.SendSmsToSingle(userEntity.F_Mobile, SmsType.LoginBind, listStr);
  118. if (result.Result.code == "0")
  119. {
  120. redisCache.Write<string>("studentuserlogin_" + userEntity.F_Mobile, raRndNum, new TimeSpan(0, 5, 0));
  121. //日志
  122. logEntity = new LogEntity();
  123. logEntity.F_CategoryId = 3;
  124. logEntity.F_OperateTypeId = "sms";
  125. logEntity.F_OperateType = "sms";
  126. logEntity.F_OperateAccount = "system";
  127. logEntity.F_ExecuteResult = 200;
  128. logEntity.F_ExecuteResultJson = "短信发送成功:" + result.Result.message;
  129. logEntity.F_Description = "短信发送:" + userEntity.F_Mobile;
  130. logEntity.WriteLog();
  131. return Success("短信发送成功:" + result.Result.message);
  132. }
  133. else
  134. {
  135. logEntity = new LogEntity();
  136. logEntity.F_CategoryId = 4;
  137. logEntity.F_OperateTypeId = "sms";
  138. logEntity.F_OperateType = "sms";
  139. logEntity.F_OperateAccount = "system";
  140. logEntity.F_ExecuteResult = 400;
  141. logEntity.F_ExecuteResultJson = "短信发送失败:" + result.Result.message + result.Result.errorType;
  142. logEntity.F_Description = "短信发送:" + userEntity.F_Mobile;
  143. logEntity.WriteLog();
  144. return Success("短信发送失败:" + result.Result.message + result.Result.errorType);
  145. }
  146. }
  147. /// <summary>
  148. /// 忘记密码修改密码
  149. /// </summary>
  150. /// <param name="_"></param>
  151. /// <returns></returns>
  152. private Response forgetpass(dynamic _)
  153. {
  154. ModifyModel modifyModel = this.GetReqData<ModifyModel>();
  155. UserEntity userEntity = userIBLL.GetEntityByMobile(modifyModel.phone);
  156. userIBLL.setPassword(userEntity.F_UserId, modifyModel.newpassword);
  157. return Success("密码修改成功");
  158. }
  159. /// <summary>
  160. /// 登录接口
  161. /// </summary>
  162. /// <param name="_"></param>
  163. /// <returns></returns>
  164. private Response Login(dynamic _)
  165. {
  166. LoginModel loginModel = this.GetReqData<LoginModel>();
  167. #region 内部账户验证
  168. UserEntity userEntity = userIBLL.CheckLogin(loginModel.username, loginModel.password);
  169. #region 写入日志
  170. LogEntity logEntity = new LogEntity();
  171. logEntity.F_CategoryId = 1;
  172. logEntity.F_OperateTypeId = ((int)OperationType.Login).ToString();
  173. logEntity.F_OperateType = EnumAttribute.GetDescription(OperationType.Login);
  174. logEntity.F_OperateAccount = loginModel.username + "(" + userEntity.F_RealName + ")";
  175. logEntity.F_OperateUserId = !string.IsNullOrEmpty(userEntity.F_UserId) ? userEntity.F_UserId : loginModel.username;
  176. logEntity.F_Module = Config.GetValue("SoftName");
  177. logEntity.F_Description = "移动端";
  178. #endregion
  179. if (!userEntity.LoginOk)//登录失败
  180. {
  181. //写入日志
  182. logEntity.F_ExecuteResult = 0;
  183. logEntity.F_ExecuteResultJson = "登录失败:" + userEntity.LoginMsg;
  184. logEntity.WriteLog();
  185. return Fail(userEntity.LoginMsg);
  186. }
  187. else
  188. {
  189. //记录ip
  190. userIBLL.UpdateIp(GetIP(), userEntity.F_UserId);
  191. string token = OperatorHelper.Instance.AddLoginUser(userEntity.F_Account, "Learun_ADMS_6.1_App", this.loginMark, false);//写入缓存信息
  192. //写入日志
  193. logEntity.F_ExecuteResult = 1;
  194. logEntity.F_ExecuteResultJson = "登录成功";
  195. logEntity.WriteLog();
  196. //保存用户设备号
  197. userIBLL.UpdateDeviceId(userEntity.F_UserId, loginModel.deviceid);
  198. OperatorResult res = OperatorHelper.Instance.IsOnLine(token, this.loginMark);
  199. res.userInfo.password = null;
  200. res.userInfo.secretkey = null;
  201. string verifyonelogin = Util.Config.GetValue("verifyonelogin");
  202. if (string.IsNullOrEmpty(verifyonelogin) || verifyonelogin != "true")
  203. {
  204. res.userInfo.logTime = null;
  205. }
  206. //是否强密码验证
  207. bool pwd = false;
  208. if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["verifypwd"]) && ConfigurationManager.AppSettings["verifypwd"] == "true" && loginModel.up == false)
  209. {
  210. pwd = true;
  211. }
  212. //是否发送短信了
  213. bool whethersendsms = false;
  214. if (!pwd)
  215. {
  216. //增加短信发送验证
  217. var studententity = stuInfoBasicIBLL.GetStuInfoBasicEntityByStuNo(userEntity.F_Account);
  218. if (studententity != null)
  219. {
  220. res.userInfo.grade = studententity.Grade;
  221. var majorinfo = majorIbll.GetCdMajorEntityByMajorNo(studententity.MajorNo);
  222. if (majorinfo != null)
  223. {
  224. res.userInfo.majorno = majorinfo.ID ?? "";
  225. }
  226. #region 判断是否需要发短信
  227. string queryjson = "{\"keywords\":\"" + userEntity.F_Mobile + "\"}";
  228. LogEntity lastsendlog = LogBLL.GetlikeList(queryjson);
  229. if (lastsendlog != null)
  230. {
  231. var aa = ((DateTime)lastsendlog.F_OperateTime - DateTime.Now).TotalMinutes;
  232. //大于30天就要发短信了
  233. if (Math.Abs(aa) > 30 * 24 * 60 )
  234. {
  235. whethersendsms = true;
  236. }
  237. }
  238. else
  239. {
  240. whethersendsms = true;
  241. }
  242. #endregion
  243. try
  244. {
  245. if (whethersendsms)
  246. {
  247. //学生增加短信发送验证
  248. string raRndNum = Learun.Util.CommonHelper.RndNum(6);
  249. var listStr = new List<string>();
  250. var str1 = $"欢迎使用智慧校园,您本次登录的验证码是 " + raRndNum + "。";
  251. listStr.Add(str1);
  252. var result = yixintongSms.SendSmsToSingle(userEntity.F_Mobile, SmsType.LoginBind, listStr);
  253. if (result.Result.code == "0")
  254. {
  255. redisCache.Write<string>("studentuserlogin_" + userEntity.F_Mobile, raRndNum, new TimeSpan(0, 5, 0));
  256. //日志
  257. logEntity = new LogEntity();
  258. logEntity.F_CategoryId = 3;
  259. logEntity.F_OperateTypeId = "sms";
  260. logEntity.F_OperateType = "sms";
  261. logEntity.F_OperateAccount = "system";
  262. logEntity.F_ExecuteResult = 200;
  263. logEntity.F_ExecuteResultJson = "短信发送成功:" + result.Result.message;
  264. logEntity.F_Description = "短信发送:" + userEntity.F_Mobile;
  265. logEntity.WriteLog();
  266. }
  267. else
  268. {
  269. logEntity = new LogEntity();
  270. logEntity.F_CategoryId = 4;
  271. logEntity.F_OperateTypeId = "sms";
  272. logEntity.F_OperateType = "sms";
  273. logEntity.F_OperateAccount = "system";
  274. logEntity.F_ExecuteResult = 400;
  275. logEntity.F_ExecuteResultJson = "短信发送失败:" + result.Result.message + result.Result.errorType;
  276. logEntity.F_Description = "短信发送:" + userEntity.F_Mobile;
  277. logEntity.WriteLog();
  278. }
  279. }
  280. }
  281. catch (Exception e)
  282. {
  283. logEntity = new LogEntity();
  284. logEntity.F_CategoryId = 4;
  285. logEntity.F_OperateTypeId = "sms";
  286. logEntity.F_OperateType = "sms";
  287. logEntity.F_OperateAccount = "system";
  288. logEntity.F_ExecuteResult = 400;
  289. logEntity.F_ExecuteResultJson = "短信发送失败:" + e.Message;
  290. logEntity.F_Description = "短信发送:" + userEntity.F_Mobile;
  291. logEntity.WriteLog();
  292. }
  293. }
  294. var teacherentity = empInfoIBLL.GetEmpInfoEntityByEmpNo(userEntity.F_Account);
  295. if (teacherentity != null)
  296. {
  297. #region 判断是否需要发短信
  298. string queryjson = "{\"keywords\":\"" + userEntity.F_Mobile + "\"}";
  299. LogEntity lastsendlog = LogBLL.GetlikeList(queryjson);
  300. if (lastsendlog != null)
  301. {
  302. var aa = ((DateTime)lastsendlog.F_OperateTime - DateTime.Now).TotalMinutes;
  303. //大于30天就要发短信了
  304. if (Math.Abs(aa) > 7 * 24 * 60 )
  305. {
  306. whethersendsms = true;
  307. }
  308. }
  309. else
  310. {
  311. whethersendsms = true;
  312. }
  313. #endregion
  314. try
  315. {
  316. if (whethersendsms)
  317. {
  318. //学生增加短信发送验证
  319. string raRndNum = Learun.Util.CommonHelper.RndNum(6);
  320. var listStr = new List<string>();
  321. var str1 = $"欢迎使用智慧校园,您本次登录的验证码是 " + raRndNum + "。";
  322. listStr.Add(str1);
  323. var result = yixintongSms.SendSmsToSingle(userEntity.F_Mobile, SmsType.LoginBind, listStr);
  324. if (result.Result.code == "0")
  325. {
  326. redisCache.Write<string>("studentuserlogin_" + userEntity.F_Mobile, raRndNum, new TimeSpan(0, 5, 0));
  327. //日志
  328. logEntity = new LogEntity();
  329. logEntity.F_CategoryId = 3;
  330. logEntity.F_OperateTypeId = "sms";
  331. logEntity.F_OperateType = "sms";
  332. logEntity.F_OperateAccount = "system";
  333. logEntity.F_ExecuteResult = 200;
  334. logEntity.F_ExecuteResultJson = "短信发送成功:" + result.Result.message;
  335. logEntity.F_Description = "短信发送:" + userEntity.F_Mobile;
  336. logEntity.WriteLog();
  337. }
  338. else
  339. {
  340. logEntity = new LogEntity();
  341. logEntity.F_CategoryId = 4;
  342. logEntity.F_OperateTypeId = "sms";
  343. logEntity.F_OperateType = "sms";
  344. logEntity.F_OperateAccount = "system";
  345. logEntity.F_ExecuteResult = 400;
  346. logEntity.F_ExecuteResultJson = "短信发送失败:" + result.Result.message + result.Result.errorType;
  347. logEntity.F_Description = "短信发送:" + userEntity.F_Mobile;
  348. logEntity.WriteLog();
  349. }
  350. }
  351. }
  352. catch (Exception e)
  353. {
  354. logEntity = new LogEntity();
  355. logEntity.F_CategoryId = 4;
  356. logEntity.F_OperateTypeId = "sms";
  357. logEntity.F_OperateType = "sms";
  358. logEntity.F_OperateAccount = "system";
  359. logEntity.F_ExecuteResult = 400;
  360. logEntity.F_ExecuteResultJson = "短信发送失败:" + e.Message;
  361. logEntity.F_Description = "短信发送:" + userEntity.F_Mobile;
  362. logEntity.WriteLog();
  363. }
  364. }
  365. if (studententity==null &&teacherentity==null)
  366. {
  367. return Fail("请维护手机号信息");
  368. }
  369. }
  370. var jsonData = new
  371. {
  372. baseinfo = res.userInfo,
  373. post = postIBLL.GetListByPostIds(res.userInfo.postIds),
  374. role = roleIBLL.GetListByRoleIds(res.userInfo.roleIds),
  375. pwd = pwd,
  376. sendresult=whethersendsms
  377. };
  378. return Success(jsonData);
  379. }
  380. #endregion
  381. }
  382. /// <summary>
  383. /// 身份验证-登录接口
  384. /// </summary>
  385. /// <param name="_"></param>
  386. /// <returns></returns>
  387. private Response LoginByIdCard(dynamic _)
  388. {
  389. LoginModel loginModel = this.GetReqData<LoginModel>();
  390. #region 内部账户验证
  391. UserEntity userEntity = userIBLL.CheckLoginByIdCard(loginModel.username, loginModel.password);
  392. #region 写入日志
  393. LogEntity logEntity = new LogEntity();
  394. logEntity.F_CategoryId = 1;
  395. logEntity.F_OperateTypeId = ((int)OperationType.Login).ToString();
  396. logEntity.F_OperateType = EnumAttribute.GetDescription(OperationType.Login);
  397. logEntity.F_OperateAccount = loginModel.username + "(" + userEntity.F_RealName + ")";
  398. logEntity.F_OperateUserId = !string.IsNullOrEmpty(userEntity.F_UserId) ? userEntity.F_UserId : loginModel.username;
  399. logEntity.F_Module = Config.GetValue("SoftName");
  400. logEntity.F_Description = "移动端";
  401. #endregion
  402. if (!userEntity.LoginOk)//登录失败
  403. {
  404. //写入日志
  405. logEntity.F_ExecuteResult = 0;
  406. logEntity.F_ExecuteResultJson = "登录失败:" + userEntity.LoginMsg;
  407. logEntity.WriteLog();
  408. return Fail(userEntity.LoginMsg);
  409. }
  410. else
  411. {
  412. //新增新生判断
  413. var stuinfobasic = stuInfoBasicIBLL.GetStuInfoBasicEntityByStuNo(userEntity.F_EnCode);
  414. if (stuinfobasic != null && stuinfobasic.Grade != "21")
  415. {
  416. userEntity.LoginMsg = "只有新生支持身份证方式登录";
  417. return Fail(userEntity.LoginMsg);
  418. }
  419. //记录ip
  420. userIBLL.UpdateIp(GetIP(), userEntity.F_UserId);
  421. string token = OperatorHelper.Instance.AddLoginUser(userEntity.F_Account, "Learun_ADMS_6.1_App", this.loginMark, false);//写入缓存信息
  422. //写入日志
  423. logEntity.F_ExecuteResult = 1;
  424. logEntity.F_ExecuteResultJson = "登录成功";
  425. logEntity.WriteLog();
  426. //保存用户设备号
  427. userIBLL.UpdateDeviceId(userEntity.F_UserId, loginModel.deviceid);
  428. OperatorResult res = OperatorHelper.Instance.IsOnLine(token, this.loginMark);
  429. res.userInfo.password = null;
  430. res.userInfo.secretkey = null;
  431. var studententity = stuInfoBasicIBLL.GetStuInfoBasicEntityByStuNo(userEntity.F_Account);
  432. if (studententity != null)
  433. {
  434. res.userInfo.grade = studententity.Grade;
  435. var majorinfo = majorIbll.GetCdMajorEntityByMajorNo(studententity.MajorNo);
  436. if (majorinfo != null)
  437. {
  438. res.userInfo.majorno = majorinfo.ID ?? "";
  439. }
  440. }
  441. //是否强密码验证
  442. bool pwd = false;
  443. if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["verifypwd"]) && ConfigurationManager.AppSettings["verifypwd"] == "true" && loginModel.up == false)
  444. {
  445. pwd = true;
  446. }
  447. var jsonData = new
  448. {
  449. baseinfo = res.userInfo,
  450. post = postIBLL.GetListByPostIds(res.userInfo.postIds),
  451. role = roleIBLL.GetListByRoleIds(res.userInfo.roleIds),
  452. pwd = pwd
  453. };
  454. return Success(jsonData);
  455. }
  456. #endregion
  457. }
  458. private Response onedrivelogin(dynamic _)
  459. {
  460. //多客户端登录判断
  461. string logintime = redisCache.Read<string>("logintime" + userInfo.account, CacheId.loginInfo);
  462. return Success(new {
  463. logintime
  464. });
  465. }
  466. /// <summary>
  467. /// 获取用户信息
  468. /// </summary>
  469. /// <param name="_"></param>
  470. /// <returns></returns>
  471. private Response Info(dynamic _)
  472. {
  473. var data = userInfo;
  474. data.password = null;
  475. data.secretkey = null;
  476. var jsonData = new
  477. {
  478. baseinfo = data,
  479. post = postIBLL.GetListByPostIds(data.postIds),
  480. role = roleIBLL.GetListByRoleIds(data.roleIds)
  481. };
  482. return Success(jsonData);
  483. }
  484. /// <summary>
  485. /// 修改密码
  486. /// </summary>
  487. /// <param name="_"></param>
  488. /// <returns></returns>
  489. private Response ModifyPassword(dynamic _)
  490. {
  491. ModifyModel modifyModel = this.GetReqData<ModifyModel>();
  492. if (userInfo.isSystem)
  493. {
  494. return Fail("当前账户不能修改密码");
  495. }
  496. else
  497. {
  498. bool res = userIBLL.RevisePassword(modifyModel.newpassword, modifyModel.oldpassword);
  499. if (!res)
  500. {
  501. return Fail("原密码错误,请重新输入");
  502. }
  503. else
  504. {
  505. return Success("密码修改成功");
  506. }
  507. }
  508. }
  509. private Response ModifyPasswordiden(dynamic _)
  510. {
  511. ModifyModel modifyModel = this.GetReqData<ModifyModel>();
  512. if (userInfo.isSystem)
  513. {
  514. return Fail("当前账户不能修改密码");
  515. }
  516. else
  517. {
  518. bool res = userIBLL.RevisePasswordiden(modifyModel.newpassword, modifyModel.oldpassword);
  519. if (!res)
  520. {
  521. return Fail("原密码错误,请重新输入");
  522. }
  523. else
  524. {
  525. return Success("密码修改成功");
  526. }
  527. }
  528. }
  529. /// <summary>
  530. /// 解绑微信
  531. /// </summary>
  532. /// <param name="_"></param>
  533. /// <returns></returns>
  534. private Response DoUnbundWeiXin(dynamic _)
  535. {
  536. userIBLL.DoUnbundWeiXin(userInfo.userId);
  537. return Success("解绑成功");
  538. }
  539. /// <summary>
  540. /// 获取所有员工账号列表
  541. /// </summary>
  542. /// <param name="_"></param>
  543. /// <returns></returns>
  544. private Response GetList(dynamic _)
  545. {
  546. var data = userInfo;
  547. data.password = null;
  548. data.secretkey = null;
  549. var jsonData = new
  550. {
  551. baseinfo = data,
  552. post = postIBLL.GetListByPostIds(data.postIds),
  553. role = roleIBLL.GetListByRoleIds(data.roleIds)
  554. };
  555. return Success(jsonData);
  556. }
  557. /// <summary>
  558. /// 获取用户映射表
  559. /// </summary>
  560. /// <param name="_"></param>
  561. /// <returns></returns>
  562. public Response GetMap(dynamic _)
  563. {
  564. string ver = this.GetReqData();// 获取模板请求数据
  565. var data = userIBLL.GetModelMap();
  566. string md5 = Md5Helper.Encrypt(data.ToJson(), 32);
  567. if (md5 == ver)
  568. {
  569. return Success("no update");
  570. }
  571. else
  572. {
  573. var jsondata = new
  574. {
  575. data = data,
  576. ver = md5
  577. };
  578. return Success(jsondata);
  579. }
  580. }
  581. public Response GetSaveClassMap(dynamic _)
  582. {
  583. string account = this.GetReqData<UserAccount>().account;
  584. var data = userIBLL.GetSaveClassMap();
  585. var students = stuInfoBasicIBLL.GetSaveClassStudents(account);
  586. data = data.Where(a => students.Contains(a.F_Account) && a.F_Account != account).ToList();
  587. var dic = new Dictionary<string, UserModel>();
  588. foreach (var item in data)
  589. {
  590. UserModel model = new UserModel()
  591. {
  592. companyId = item.F_CompanyId,
  593. departmentId = item.F_DepartmentId,
  594. name = item.F_RealName,
  595. id = item.F_UserId,
  596. };
  597. string img = "";
  598. if (!string.IsNullOrEmpty(item.F_HeadIcon))
  599. {
  600. string fileHeadImg = Config.GetValue("fileHeadImg");
  601. string fileImg = string.Format("{0}/{1}{2}", fileHeadImg, item.F_UserId, item.F_HeadIcon);
  602. if (DirFileHelper.IsExistFile(fileImg))
  603. {
  604. img = item.F_HeadIcon;
  605. }
  606. }
  607. if (string.IsNullOrEmpty(img))
  608. {
  609. if (item.F_Gender == 0)
  610. {
  611. img = "0";
  612. }
  613. else
  614. {
  615. img = "1";
  616. }
  617. }
  618. model.img = img;
  619. dic.Add(item.F_UserId, model);
  620. }
  621. string md5 = Md5Helper.Encrypt(dic.ToJson(), 32);
  622. var jsondata = new
  623. {
  624. data = dic,
  625. var = md5
  626. };
  627. return Success(jsondata);
  628. }
  629. /// <summary>
  630. /// 获取人员头像图标
  631. /// </summary>
  632. /// <param name="_"></param>
  633. /// <returns></returns>
  634. public Response GetImg(dynamic _)
  635. {
  636. string userId = this.GetReqData();// 获取模板请求数据
  637. userIBLL.GetImg(userId);
  638. return Success("获取成功");
  639. }
  640. /// <summary>
  641. /// 获取人员头像图标
  642. /// </summary>
  643. /// <param name="_"></param>
  644. /// <returns></returns>
  645. public Response GetImgForDC(dynamic _)
  646. {
  647. string userId = this.GetReqData();// 获取模板请求数据
  648. userIBLL.GetImgForDC(userId);
  649. return Success("获取成功");
  650. }
  651. /// <summary>
  652. /// 获取IP
  653. /// </summary>
  654. /// <returns></returns>
  655. private string GetIP()
  656. {
  657. //string ip = string.Empty;
  658. //if (!string.IsNullOrEmpty(System.Web.HttpContext.Current.Request.ServerVariables["HTTP_VIA"]))
  659. // ip = Convert.ToString(System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]);
  660. //if (string.IsNullOrEmpty(ip))
  661. // ip = Convert.ToString(System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]);
  662. //return ip;
  663. string userIP = "未获取用户IP";
  664. try
  665. {
  666. if (System.Web.HttpContext.Current == null
  667. || System.Web.HttpContext.Current.Request == null
  668. || System.Web.HttpContext.Current.Request.ServerVariables == null)
  669. {
  670. return "";
  671. }
  672. string CustomerIP = "";
  673. //CDN加速后取到的IP simone 090805
  674. CustomerIP = System.Web.HttpContext.Current.Request.Headers["Cdn-Src-Ip"];
  675. if (!string.IsNullOrEmpty(CustomerIP))
  676. {
  677. return CustomerIP;
  678. }
  679. CustomerIP = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
  680. if (!string.IsNullOrEmpty(CustomerIP))
  681. {
  682. return CustomerIP;
  683. }
  684. if (System.Web.HttpContext.Current.Request.ServerVariables["HTTP_VIA"] != null)
  685. {
  686. CustomerIP = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
  687. if (CustomerIP == null)
  688. {
  689. CustomerIP = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
  690. }
  691. }
  692. else
  693. {
  694. CustomerIP = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
  695. }
  696. if (string.Compare(CustomerIP, "unknown", true) == 0 || string.IsNullOrEmpty(CustomerIP))
  697. {
  698. return System.Web.HttpContext.Current.Request.UserHostAddress;
  699. }
  700. return CustomerIP;
  701. }
  702. catch { }
  703. return userIP;
  704. }
  705. }
  706. /// <summary>
  707. /// 登录信息
  708. /// </summary>
  709. public class LoginModel
  710. {
  711. /// <summary>
  712. /// 账号
  713. /// </summary>
  714. public string username { get; set; }
  715. /// <summary>
  716. /// 密码
  717. /// </summary>
  718. public string password { get; set; }
  719. /// <summary>
  720. /// 是否强密码
  721. /// </summary>
  722. public bool up { get; set; }
  723. /// <summary>
  724. /// 设备号
  725. /// </summary>
  726. public string deviceid { get; set; }
  727. public string openid { get; set; }
  728. }
  729. /// <summary>
  730. /// 修改密码
  731. /// </summary>
  732. public class ModifyModel
  733. {
  734. public string phone { set; get; }
  735. /// <summary>
  736. /// 新密码
  737. /// </summary>
  738. public string newpassword { get; set; }
  739. /// <summary>
  740. /// 旧密码
  741. /// </summary>
  742. public string oldpassword { get; set; }
  743. }
  744. public class MobileVerify
  745. {
  746. public string mobile { get; set; }
  747. public string verifycode { get; set; }
  748. }
  749. public class UserAccount
  750. {
  751. public string account { get; set; }
  752. }
  753. }