cloudEditionAjaxController.js 6.4 KB

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