cloudEditionAjaxController.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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_id=req.params.compilation_id;
  49. var curingList= await cloudService.getCuringList(compilation_id);
  50. res.json({ 'status': 1,'curingList':curingList.curingList,'pageData':curingList.pageData });
  51. },
  52. //养护激活用户分页
  53. getCuringPage: async function(req, res){
  54. var currentPage=req.params.currentPage;
  55. if(!hash.isNotANumber(currentPage)){
  56. res.json({ 'status': 2,'msg':'currentPage error' });return ;
  57. }
  58. //get获得方式
  59. var params = url.parse(req.url, true).query;
  60. var curingList= await cloudService.getCuringList(params.compilation_id,currentPage);
  61. res.json({ 'status': 1,'curingList':curingList.curingList,'pageData':curingList.pageData });
  62. },
  63. //搜索手机号,防止由于改号码导致数据不全问题
  64. checkMobile: async function(req, res){
  65. if(!hash.isNotANumber(req.params.mobile)){
  66. res.json({ 'status': 0,'msg':'error mobile' });
  67. return ;
  68. }
  69. var data= await cloudService.getCuringByMobile(req.params.mobile);
  70. if(hash.isExistence(data)) {
  71. var curingDetail=await models.cloud_curing.getCuringBySsoid(data['userInfo']['ssoId']);
  72. var client_id='';
  73. if(hash.isExistence(curingDetail)&&hash.isExistence(curingDetail['client_id'])){
  74. client_id=curingDetail['client_id'];
  75. }
  76. res.json({ 'status': 1,'data':{'id':data['userInfo']['ssoId'],'client_id':client_id} });
  77. }else{
  78. res.json({ 'status': 3,'msg':'该号码未注册养护项目' });
  79. }
  80. },
  81. getCuringBySsoid: async function(req, res){
  82. var params = url.parse(req.url, true).query;
  83. if(!hash.isExistence(params.ssoid)){
  84. res.json({ 'status': 0,'msg':'error ssoid' });
  85. return ;
  86. }
  87. var detail= await cloudService.getCuringBySsoid(params.ssoid,params.client_id);
  88. //console.log(detail);
  89. if(hash.isExistence(detail)) {
  90. res.json({ 'status': 1,'detail':detail });
  91. }else{
  92. res.json({ 'status': 3,'msg':'该号码未注册养护项目' });
  93. }
  94. },
  95. upCuringDo: async function(req, res){
  96. //post数据获得
  97. var ssoid=req.body.ssoid;//通行证ID
  98. var compilationId=req.body.compilationId;//编办ID
  99. if(hash.isExistence(ssoid)&&hash.isExistence(compilationId)) {
  100. var flag= await cloudService.upCuringDo(req.body);
  101. if(flag){
  102. res.json({ 'status': 1,'msg':'升级成功' });
  103. }else{
  104. res.json({ 'status': 3,'msg':'升级失败' });
  105. }
  106. }else{
  107. res.json({ 'status': 3,'msg':'数据不正确' });
  108. }
  109. },
  110. //养护绑定CLD客户
  111. relevanceClientDo: async function(req, res){
  112. //post数据获得
  113. var cidKey=req.body.cidKey;//客户ID
  114. var id=req.body.id;//养护用户ID
  115. if(hash.isExistence(cidKey)&&hash.isExistence(id)) {
  116. var flag= await cloudService.relevanceClientDo(req.body);
  117. if(flag){
  118. //获得绑定的CLD客户信息
  119. var detail= await models.CLD_client.findById(cidKey);
  120. var operateLogList=await models.operate_log.findByCondition(1,hash.hashDecode(id));
  121. res.json({ 'status': 1,'detail':detail,'operateLogList':operateLogList,'msg':'绑定CLD客户成功' });
  122. }else{
  123. res.json({ 'status': 2,'msg':'绑定失败' });
  124. }
  125. }else{
  126. res.json({ 'status': 3,'msg':'参数不正确' });
  127. }
  128. },
  129. //养护移除CLD客户
  130. relieveClientDo: async function(req, res){
  131. //post数据获得
  132. var id=req.body.id;//养护用户ID
  133. if(hash.isExistence(id)) {
  134. var flag= await cloudService.relieveClientDo(req.body);
  135. if(flag){
  136. var operateLogList=await models.operate_log.findByCondition(1,hash.hashDecode(id));
  137. //获得绑定的CLD客户信息
  138. res.json({ 'status': 1,'operateLogList':operateLogList,'msg':'解绑CLD客户成功' });
  139. }else{
  140. res.json({ 'status': 2,'msg':'解绑失败' });
  141. }
  142. }else{
  143. res.json({ 'status': 3,'msg':'参数不正确' });
  144. }
  145. },
  146. //养护详情页 数据
  147. getCuringById: async function(req, res){
  148. if(!hash.isExistence(req.params.id)){
  149. res.json({ 'status': 0,'msg':'error id' });
  150. return ;
  151. }
  152. var id=hash.hashDecode(req.params.id);
  153. if(!hash.isNotANumber(id)){
  154. res.json({ 'status': 0,'msg':'error id' });
  155. return ;
  156. }
  157. res.json({ 'status': 3,'msg':'数据不正确' });
  158. },
  159. }
  160. module.exports = cloudEditionAjaxController;