sync.user.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  1. using BizCom;
  2. using SQLData;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Data;
  6. using System.Text;
  7. using Utils;
  8. namespace SiteCore.Handler
  9. {
  10. public partial class sync
  11. {
  12. #region 职位
  13. public void get_postsetting()
  14. {
  15. if (UrlParmsCheck("pId"))
  16. {
  17. int pId = GetInt("pId");
  18. DataTable dt = CeErpPost.SimpleQuery(0, "ID,DefaultPageModuleID as pmId,IndexPageReport as ipp", "", "ID=" + pId);
  19. returnSuccess(Utils.Serialization.JsonString.DataTable2AjaxJson(dt));
  20. }
  21. }
  22. public void save_postsetting()
  23. {
  24. if (UrlParmsCheck("pId,mId,index"))
  25. {
  26. int pId = GetInt("pId");
  27. int mId = GetInt("mId");
  28. int index = GetInt("index");
  29. string noshow = GetString("noshow");
  30. string[] sArr = noshow.Split(',');
  31. //using (new SessionScope())
  32. //{
  33. CeErpPost post = CeErpPost.Get(pId);
  34. if (post != null)
  35. {
  36. post.DefaultPageModuleID = mId;
  37. post.IndexPageReport = index;
  38. post.Update();
  39. }
  40. StringBuilder sql = new StringBuilder();
  41. sql.AppendFormat("delete from CE_ErpPostToIndexPage where postid={0} ;", pId);
  42. if (noshow != "" && sArr.Length > 0)
  43. {
  44. for (int i = 0; i < sArr.Length; i++)
  45. {
  46. sql.AppendFormat("insert into CE_ErpPostToIndexPage(postid,indexid) values({0},{1});", pId, sArr[i]);
  47. }
  48. }
  49. CeErpPost.ExecuteNonQuery(sql.ToString());
  50. //}
  51. returnSuccessMsg("保存配置成功!");
  52. }
  53. }
  54. public void get_post()
  55. {
  56. DataStruct dStruct = GetPostStruct();
  57. string path = GetPostString("path");
  58. int oId = GetPostInt("oId");
  59. if (path == "") dStruct.MainWhere = "OrgID=" + oId;
  60. else dStruct.MainWhere = "OrgID=" + oId + " or Path like '%|" + oId + "|%'";
  61. dStruct.Order = "path asc,sort asc";
  62. DataTable dt = WebCache.GetData("view_erppost", dStruct);
  63. writeGridDataTableJson(dStruct.TotalCount, dt);
  64. }
  65. public void save_post()
  66. {
  67. if (UrlParmsCheck("oId,name,sort,mId"))
  68. {
  69. int postId = GetInt("postId");
  70. int oId = GetInt("oId");
  71. string name = GetString("name");
  72. int sort = GetInt("sort");
  73. string code = GetString("code");
  74. int OrderAmountLimit = GetInt("OrderAmountLimit");
  75. int OrderDesignLimit = GetInt("OrderDesignLimit");
  76. int DayOrderLimit = GetInt("DayOrderLimit");
  77. int mId = GetInt("mId");
  78. CeErpPost post = null;
  79. if (postId > 0) post = CeErpPost.Get(postId);
  80. else post = new CeErpPost();
  81. post.Name = name;
  82. post.Code = code;
  83. post.OrderAmountLimit = OrderAmountLimit;
  84. post.OrderDesignLimit = OrderDesignLimit;
  85. post.DayOrderLimit = DayOrderLimit;
  86. post.Sort = sort;
  87. post.OrgID = oId;
  88. post.DefaultPageModuleID = mId;
  89. if (postId > 0) post.Update();
  90. else post.Create();
  91. returnSuccessMsg("保存成功!");
  92. }
  93. }
  94. public void del_post()
  95. {
  96. if (UrlParmsCheck("id,oId"))
  97. {
  98. int id = GetInt("id");
  99. int oId = GetInt("oId");
  100. string sql = "select count(0) from view_erpuser where postid=" + id;
  101. object res = CeErpOrganization.ExecuteScalar(sql);
  102. if (res != null && Convert.ToInt32(res) > 0)
  103. {
  104. returnErrorMsg("该职位已存在人员不允许删除!");
  105. return;
  106. }
  107. int result = CeErpPost.Del(id, oId);
  108. if (result > 0)
  109. {
  110. returnSuccessMsg("删除成功!");
  111. }
  112. else
  113. {
  114. returnSuccessMsg("删除失败!");
  115. }
  116. }
  117. }
  118. #endregion
  119. #region 员工
  120. public void get_employee()
  121. {
  122. DataStruct dStruct = GetPostStruct();
  123. string path = GetPostString("path");
  124. int oId = GetPostInt("oId");
  125. List<string> lw = new List<string>();
  126. if (oId > 0)
  127. {
  128. lw.Add("(OrgID=" + oId + " or Path like '%|" + oId + "|%')");
  129. //dStruct.MainWhere = "(OrgID=" + oId+" or Path like '%|"+oId+"|%')";
  130. //if (path == "") dStruct.MainWhere = "OrgID=" + oId;
  131. //else dStruct.MainWhere = "Path like '%|" + oId + "|%'";
  132. }
  133. string key = GetPostString("key");
  134. if (key != "")
  135. {
  136. lw.Add(string.Format(" (name like '%{0}%' or Account like '%{0}%' or (CHARINDEX( ','+convert(varchar,(select id from CE_ErpShop where Summary like '%{0}%'))+',' , ','+pemShop+',')>0 ))", key));
  137. //dStruct.SecondWhere = string.Format(" (PostName like '%{0}%' or name like '%{0}%' or Account like '%{0}%' )", key);
  138. }
  139. string orgIds = CurrentUser.User.ManageOrgIds;
  140. if (!string.IsNullOrEmpty(orgIds))
  141. {
  142. lw.Add(string.Format("OrgID in ({0})", orgIds));
  143. }
  144. else
  145. {
  146. lw.Add(string.Format("(OrgID =0)", orgIds));
  147. }
  148. if (lw.Count > 0)
  149. {
  150. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  151. }
  152. dStruct.Order = "isopen desc, createtime desc";
  153. DataTable dt = WebCache.GetData("view_erpuser", dStruct);
  154. foreach (DataRow dr in dt.Rows)
  155. {
  156. if (dr["password"].ToString() == "") continue;
  157. dr["password"] = SecurityHelper.DecryptSymmetric(dr["password"].ToString());
  158. }
  159. writeGridDataTableJson(dStruct.TotalCount, dt);
  160. }
  161. public void open_employee()
  162. {
  163. if (UrlParmsCheck("pid"))
  164. {
  165. int pId = GetInt("pId");
  166. CeErpUser.OpenAccount(pId, SecurityHelper.EncryptSymmetric("123456"));
  167. returnSuccessMsg("成功开通账户!");
  168. }
  169. }
  170. public void close_employee()
  171. {
  172. if (UrlParmsCheck("pid"))
  173. {
  174. int pId = GetInt("pId");
  175. int userId = GetInt("userId");
  176. CeErpUser ceErpUser = CeErpUser.Get(userId);
  177. if (ceErpUser == null || !ceErpUser.isOpen)
  178. {
  179. returnSuccessMsg("接收账号已关闭,无法转派!");
  180. return;
  181. }
  182. CeErpUser.FreezeAccount(pId);
  183. //设计师
  184. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpTradeCell set DesignUserId = {0} WHERE DesignUserId = {1} and OrderState > 0 and OrderState < 7", userId, pId));
  185. //客服
  186. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpTradeCell set CustomerUserId = {0} WHERE CustomerUserId = {1} and OrderState > 0 and OrderState < 7", userId, pId));
  187. //下单员
  188. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpTradeCell set PlaceUserId = {0} WHERE PlaceUserId = {1} and OrderState > 0 and OrderState < 7", userId, pId));
  189. //售后
  190. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpTradeCell set AfterSaleUserId = {0} WHERE AfterSaleUserId = {1} and AfterSaleState <> 4", userId, pId));
  191. returnSuccessMsg("成功关闭账户!");
  192. }
  193. }
  194. public void del_employee()
  195. {
  196. if (UrlParmsCheck("pid"))
  197. {
  198. string curPos = CurrentUser.UserPost.Post.Code;
  199. if (CurrentUser.User.State != 5) //超级管理员才能删除账号
  200. {
  201. returnSuccessMsg("您没有权限删除账号!");
  202. return;
  203. }
  204. int id = GetInt("pid");
  205. string code = GetString("code");
  206. int result = CeErpUser.RealDel(id);
  207. if (result > 0)
  208. {
  209. returnSuccessMsg("删除成功!");
  210. }
  211. else
  212. {
  213. returnSuccessMsg("删除失败!");
  214. }
  215. }
  216. }
  217. public void update_employee_pwd()
  218. {
  219. if (UrlParmsCheck("eid,pwd"))
  220. {
  221. int eid = GetInt("eid");
  222. string pwd = GetString("pwd");
  223. CeErpUser entity = CeErpUser.Get(eid);
  224. if (entity != null)
  225. {
  226. entity.PassWord = SecurityHelper.EncryptSymmetric(pwd);
  227. entity.Update();
  228. }
  229. returnSuccessMsg("修改成功!");
  230. }
  231. }
  232. public void update_employee_pwd2()
  233. {
  234. string tbxOldPwd = GetString("tbxOldPwd");
  235. string tbxNewPwd = GetString("tbxNewPwd");
  236. if (string.IsNullOrEmpty(tbxOldPwd) || string.IsNullOrEmpty(tbxNewPwd))
  237. {
  238. returnErrorMsg("参数有误");
  239. return;
  240. }
  241. int eid = CurrentUser.UserID;
  242. if (eid <= 0)
  243. {
  244. returnErrorMsg("未找到用户");
  245. return;
  246. }
  247. CeErpUser entity = CeErpUser.Get(eid);
  248. if (entity == null)
  249. {
  250. returnErrorMsg("未找到用户");
  251. return;
  252. }
  253. if (entity.PassWord != SecurityHelper.EncryptSymmetric(tbxOldPwd))
  254. {
  255. returnErrorMsg("原密码不正确");
  256. return;
  257. }
  258. entity.PassWord = SecurityHelper.EncryptSymmetric(tbxNewPwd);
  259. entity.Update();
  260. con.Session["isSimplePwd"] = null;
  261. returnSuccessMsg("修改成功!");
  262. }
  263. public void upd_user_onduty()
  264. {
  265. string uid = GetString("uid");
  266. if (uid.Length > 0)
  267. {
  268. //员工信息里面点上班
  269. int eUid = Convert.ToInt32(uid);
  270. string sql = "";
  271. sql = "update view_ErpUser set OnDuty=1 where id=" + eUid;
  272. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  273. CeErpUser entity = CeErpUser.Get(eUid);
  274. if (entity != null)
  275. {
  276. entity.OnDutyTime = DateTime.Now;
  277. entity.Update();
  278. }
  279. returnSuccessMsg("修改成功!");
  280. return;
  281. }
  282. else
  283. {
  284. //自己点上班
  285. string dutyStr = GetPostString("duty");
  286. CeErpUser entity = CeErpUser.Get(CurrentUser.UserID);
  287. if (entity != null)
  288. {
  289. int eUid = CurrentUser.UserID;
  290. string sql = "";
  291. if (dutyStr == "值班")
  292. {
  293. sql = "update view_ErpUser set OnDuty=1,BeOnDuty=1 where id=" + eUid;
  294. }
  295. else if (dutyStr == "晚班")
  296. {
  297. sql = "update view_ErpUser set OnDuty=1,BeOnDuty=2 where id=" + eUid;
  298. }
  299. else
  300. {
  301. sql = "update view_ErpUser set OnDuty=1 where id=" + eUid;
  302. }
  303. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  304. entity.OnDutyTime = DateTime.Now;
  305. entity.Update();
  306. returnSuccessMsg("修改成功!");
  307. return;
  308. }
  309. }
  310. returnErrorMsg("未找到用户");
  311. }
  312. public void upd_user_offduty()
  313. {
  314. string poscode = CurrentUser.UserPost.Post.Code;
  315. int orgID = CurrentUser.UserPost.OrgID;
  316. //string posname = CurrentUser.UserPost.Post.Name;
  317. //if (poscode != "SysAdmin")
  318. //{
  319. // returnErrorMsg("暂无下班权限");
  320. // return;
  321. //}
  322. string uid = GetString("uid");
  323. if (uid.Length > 0)
  324. {
  325. int eUid = Convert.ToInt32(uid);
  326. if (poscode != "SysAdmin" && poscode != "PlaceMr" && poscode != "Designerhd" && poscode != "DesignerMr" && poscode != "wxDesignerMr")
  327. {
  328. //31世纪天成 82商务板块
  329. if ((orgID == 31 || orgID == 82) && poscode == "Director")
  330. {
  331. //跳过
  332. }
  333. else
  334. {
  335. //p0设计师可以下班
  336. string ssql = "select * from view_ErpUser where PostName='设计师P0' and ID=" + eUid;
  337. DataTable dt = DbHelper.DbConn.ExecuteDataset(ssql.ToString()).Tables[0];
  338. if (dt.Rows.Count <= 0)
  339. {
  340. returnErrorMsg("暂无权限");
  341. return;
  342. }
  343. }
  344. }
  345. CeErpUser entity = CeErpUser.Get(eUid);
  346. string sql = "update view_ErpUser set OnDuty=0,BeOnDuty=0 where id=" + eUid;
  347. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  348. if (entity != null)
  349. {
  350. entity.OffDutyTime = DateTime.Now;
  351. entity.Update();
  352. }
  353. returnSuccessMsg("下班成功!");
  354. return;
  355. }
  356. else
  357. {
  358. CeErpUser entity = CeErpUser.Get(CurrentUser.UserID);
  359. if (entity != null)
  360. {
  361. int eUid = CurrentUser.UserID;
  362. string sql = "update view_ErpUser set OnDuty=0,BeOnDuty=0 where id=" + eUid;
  363. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  364. entity.OffDutyTime = DateTime.Now;
  365. entity.Update();
  366. returnSuccessMsg("下班成功!");
  367. return;
  368. }
  369. }
  370. returnErrorMsg("未找到用户");
  371. }
  372. public void upd_user_multilogin()
  373. {
  374. string uid = GetString("uid");
  375. CeErpUser entity = CeErpUser.Get(CurrentUser.UserID);
  376. if (entity != null)
  377. {
  378. int eUid = CurrentUser.UserID;
  379. if (uid.Length > 0)
  380. {
  381. eUid = Convert.ToInt32(uid);
  382. }
  383. string sql = "";
  384. sql = "update view_ErpUser set IsMultiLogin=1 where id=" + eUid;
  385. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  386. returnSuccessMsg("修改成功!");
  387. return;
  388. }
  389. returnErrorMsg("未找到用户");
  390. }
  391. public void upd_user_onelogin()
  392. {
  393. string uid = GetString("uid");
  394. CeErpUser entity = CeErpUser.Get(CurrentUser.UserID);
  395. if (entity != null)
  396. {
  397. int eUid = CurrentUser.UserID;
  398. if (uid.Length > 0)
  399. {
  400. eUid = Convert.ToInt32(uid);
  401. }
  402. string sql = "update view_ErpUser set IsMultiLogin=0 where id=" + eUid;
  403. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  404. returnSuccessMsg("操作成功!");
  405. return;
  406. }
  407. returnErrorMsg("未找到用户");
  408. }
  409. public void set_user_team()
  410. {
  411. string uids = GetPostString("ids");
  412. string names = GetPostString("names");
  413. StringBuilder sql = new StringBuilder();
  414. sql.AppendFormat("update ce_ErpUser set TeamIds='{0}',TeamNames='{1}' where id in ({0})", uids, names);
  415. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  416. returnSuccessMsg("设置成功!");
  417. return;
  418. }
  419. #endregion
  420. #region 账户
  421. public void get_account()
  422. {
  423. DataStruct dStruct = GetPostStruct();
  424. dStruct.MainWhere = "PersonID=0";
  425. DataTable dt = WebCache.GetData("ce_ErpUser", dStruct);
  426. writeGridDataTableJson(dStruct.TotalCount, dt);
  427. }
  428. public void save_account()
  429. {
  430. if (UrlParmsCheck("name,pwd"))
  431. {
  432. string name = GetString("name");
  433. if (CeErpUser.Exists(" Account=?", name))
  434. {
  435. returnErrorMsg("该账户名已经存在,请更换!");
  436. return;
  437. }
  438. string pwd = SecurityHelper.EncryptSymmetric(GetString("pwd"));
  439. CeErpUser user = new CeErpUser();
  440. user.Account = name;
  441. user.CreateTime = DateTime.Now;
  442. user.PassWord = pwd;
  443. user.Create();
  444. returnSuccessMsg("保存成功!");
  445. }
  446. }
  447. public void resetpwd_account()
  448. {
  449. int id = GetInt("id");
  450. int pId = GetInt("pid");
  451. if (id > 0) CeErpUser.ResetPwd(id, SecurityHelper.EncryptSymmetric("123456"));
  452. else if (pId > 0) CeErpUser.ResetPersonPwd(pId, SecurityHelper.EncryptSymmetric("123456"));
  453. returnSuccessMsg("密码重置成功!");
  454. }
  455. public void del_account()
  456. {
  457. if (UrlParmsCheck("id"))
  458. {
  459. int id = GetInt("id");
  460. CeErpUser.RealDel(id);
  461. returnSuccessMsg("删除成功!");
  462. }
  463. }
  464. public void open_account()
  465. {
  466. if (UrlParmsCheck("id,pid"))
  467. {
  468. int pId = GetInt("pid");
  469. int id = GetInt("id");
  470. CeErpUser.OpenAccount(id, SecurityHelper.EncryptSymmetric("123456"));
  471. returnSuccessMsg("成功开通账户!");
  472. }
  473. }
  474. public void close_account()
  475. {
  476. if (UrlParmsCheck("id,pid"))
  477. {
  478. int id = GetInt("id");
  479. CeErpUser.FreezeAccount(id);
  480. returnSuccessMsg("成功冻结账户!");
  481. }
  482. }
  483. #endregion
  484. }
  485. }