cloudEditionAjaxController.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /**
  2. * Created by MyPC on 2019/11/5.
  3. */
  4. const hash=require('../class/hash');
  5. const cloudService=require('../service/cloudEditionService');
  6. const operateLogService=require('../service/operateLogService');
  7. const url=require("url");
  8. var models=require('../models');
  9. var cloudEditionAjaxController={
  10. //------------用户列表界面相关----------------
  11. /**
  12. * 用户列表刷新
  13. */
  14. refreshCuringPage: async function(req, res){
  15. var curingList= await cloudService.getCuringList(req, res);
  16. res.json({ 'status': 1,'curingList':curingList.curingList,'pageData':curingList.pageData });
  17. },
  18. //------------用户详情页界面相关----------------
  19. /**
  20. * 获得养护用户信息详情
  21. */
  22. getCuringBySsoid: async function(req, res){
  23. var params = url.parse(req.url, true).query;
  24. if(!hash.isExistence(params.ssoid)){
  25. res.json({ 'status': 0,'msg':'error ssoid' });
  26. return ;
  27. }
  28. var detail= await cloudService.getCuringBySsoid(params.ssoid,params.client_id);
  29. //console.log(detail);
  30. if(hash.isExistence(detail)) {
  31. res.json({ 'status': 1,'detail':detail });
  32. }else{
  33. res.json({ 'status': 3,'msg':'该号码未注册养护项目' });
  34. }
  35. },
  36. //养护绑定CLD客户
  37. /**
  38. * 用户关联CLD客户
  39. */
  40. relevanceClientDo: async function(req, res){
  41. //post数据获得
  42. var cidKey=req.body.cidKey;//客户ID
  43. var ssoId=req.body.ssoId;//养护用户ID
  44. console.log(cidKey);
  45. console.log(ssoId);
  46. if(hash.isExistence(cidKey)&&hash.isExistence(ssoId)) {
  47. var flag= await cloudService.relevanceClientDo(req.body);
  48. if(flag){
  49. //获得绑定的CLD客户信息
  50. var detail= await models.CLD_client.findById(cidKey);
  51. var operateLogList=await models.operate_log.findByCondition(1,hash.hashDecode(id));
  52. res.json({ 'status': 1,'detail':detail,'operateLogList':operateLogList,'msg':'绑定CLD客户成功' });
  53. }else{
  54. res.json({ 'status': 2,'msg':'绑定失败' });
  55. }
  56. }else{
  57. res.json({ 'status': 3,'msg':'参数不正确' });
  58. }
  59. },
  60. /**
  61. * 养护用户分页---废弃
  62. */
  63. /* getCuringPage: async function(req, res){
  64. var currentPage=req.params.currentPage;
  65. if(!hash.isNotANumber(currentPage)){
  66. res.json({ 'status': 2,'msg':'currentPage error' });return ;
  67. }
  68. //get获得方式
  69. var params = url.parse(req.url, true).query;
  70. var curingList= await cloudService.getCuringList(req, res);
  71. res.json({ 'status': 1,'curingList':curingList.curingList,'pageData':curingList.pageData });
  72. },
  73. //获得养护信息--废弃
  74. getCuringInfo: async function(req, res){
  75. if(!hash.isNotANumber(req.params.mobile)){
  76. res.json({ 'status': 0,'msg':'error mobile' });
  77. return ;
  78. }
  79. //获得本地绑定CLD客户用户
  80. var bcDetail= await cloudService.getBindCuringByMobile(req.params.mobile);
  81. var cDetail= await cloudService.getCuringByMobile(req.params.mobile);
  82. if(!hash.isExistence(bcDetail)){//没有绑定CLD客户
  83. if(!hash.isExistence(cDetail)){
  84. res.header("Content-Type", "application/json; charset=utf-8")
  85. res.json({ 'status': 3,'msg':'该号码未注册养护项目' });
  86. return ;
  87. }
  88. res.json({ 'status': 2,'msg':'已升级用户列表不存在' });//未绑定CLD客户
  89. }else{
  90. res.json({ 'status': 1,'detail':bcDetail });
  91. }
  92. },
  93. */
  94. //搜索手机号,防止由于改号码导致数据不全问题
  95. checkMobile: async function(req, res){
  96. if(!hash.isNotANumber(req.params.mobile)){
  97. res.json({ 'status': 0,'msg':'error mobile' });
  98. return ;
  99. }
  100. var data= await cloudService.getCuringByMobile(req.params.mobile);
  101. if(hash.isExistence(data)) {
  102. var curingDetail=await models.cloud_curing.getCuringBySsoid(data['userInfo']['ssoId']);
  103. var client_id='';
  104. if(hash.isExistence(curingDetail)&&hash.isExistence(curingDetail['client_id'])){
  105. client_id=curingDetail['client_id'];
  106. }
  107. res.json({ 'status': 1,'data':{'id':data['userInfo']['ssoId'],'client_id':client_id} });
  108. }else{
  109. res.json({ 'status': 3,'msg':'该号码未注册养护项目' });
  110. }
  111. },
  112. upCuringDo: async function(req, res){
  113. //post数据获得
  114. var ssoid=req.body.ssoid;//通行证ID
  115. var compilationId=req.body.compilationId;//编办ID
  116. if(hash.isExistence(ssoid)&&hash.isExistence(compilationId)) {
  117. var flag= await cloudService.upCuringDo(req.body);
  118. if(flag){
  119. res.json({ 'status': 1,'msg':'升级成功' });
  120. }else{
  121. res.json({ 'status': 3,'msg':'升级失败' });
  122. }
  123. }else{
  124. res.json({ 'status': 3,'msg':'数据不正确' });
  125. }
  126. },
  127. //养护移除CLD客户
  128. relieveClientDo: async function(req, res){
  129. //post数据获得
  130. var id=req.body.id;//养护用户ID
  131. if(hash.isExistence(id)) {
  132. var flag= await cloudService.relieveClientDo(req.body);
  133. if(flag){
  134. var operateLogList=await models.operate_log.findByCondition(1,hash.hashDecode(id));
  135. //获得绑定的CLD客户信息
  136. res.json({ 'status': 1,'operateLogList':operateLogList,'msg':'解绑CLD客户成功' });
  137. }else{
  138. res.json({ 'status': 2,'msg':'解绑失败' });
  139. }
  140. }else{
  141. res.json({ 'status': 3,'msg':'参数不正确' });
  142. }
  143. },
  144. //养护详情页 数据
  145. getCuringById: async function(req, res){
  146. if(!hash.isExistence(req.params.id)){
  147. res.json({ 'status': 0,'msg':'error id' });
  148. return ;
  149. }
  150. var id=hash.hashDecode(req.params.id);
  151. if(!hash.isNotANumber(id)){
  152. res.json({ 'status': 0,'msg':'error id' });
  153. return ;
  154. }
  155. res.json({ 'status': 3,'msg':'数据不正确' });
  156. },
  157. }
  158. module.exports = cloudEditionAjaxController;