cloudEditionAjaxController.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. /**
  82. * 异步获得养护用户信息详情
  83. */
  84. getCuringBySsoid: async function(req, res){
  85. var params = url.parse(req.url, true).query;
  86. if(!hash.isExistence(params.ssoid)){
  87. res.json({ 'status': 0,'msg':'error ssoid' });
  88. return ;
  89. }
  90. var detail= await cloudService.getCuringBySsoid(params.ssoid,params.client_id);
  91. //console.log(detail);
  92. if(hash.isExistence(detail)) {
  93. res.json({ 'status': 1,'detail':detail });
  94. }else{
  95. res.json({ 'status': 3,'msg':'该号码未注册养护项目' });
  96. }
  97. },
  98. upCuringDo: async function(req, res){
  99. //post数据获得
  100. var ssoid=req.body.ssoid;//通行证ID
  101. var compilationId=req.body.compilationId;//编办ID
  102. if(hash.isExistence(ssoid)&&hash.isExistence(compilationId)) {
  103. var flag= await cloudService.upCuringDo(req.body);
  104. if(flag){
  105. res.json({ 'status': 1,'msg':'升级成功' });
  106. }else{
  107. res.json({ 'status': 3,'msg':'升级失败' });
  108. }
  109. }else{
  110. res.json({ 'status': 3,'msg':'数据不正确' });
  111. }
  112. },
  113. //养护绑定CLD客户
  114. relevanceClientDo: async function(req, res){
  115. //post数据获得
  116. var cidKey=req.body.cidKey;//客户ID
  117. var id=req.body.id;//养护用户ID
  118. if(hash.isExistence(cidKey)&&hash.isExistence(id)) {
  119. var flag= await cloudService.relevanceClientDo(req.body);
  120. if(flag){
  121. //获得绑定的CLD客户信息
  122. var detail= await models.CLD_client.findById(cidKey);
  123. var operateLogList=await models.operate_log.findByCondition(1,hash.hashDecode(id));
  124. res.json({ 'status': 1,'detail':detail,'operateLogList':operateLogList,'msg':'绑定CLD客户成功' });
  125. }else{
  126. res.json({ 'status': 2,'msg':'绑定失败' });
  127. }
  128. }else{
  129. res.json({ 'status': 3,'msg':'参数不正确' });
  130. }
  131. },
  132. //养护移除CLD客户
  133. relieveClientDo: async function(req, res){
  134. //post数据获得
  135. var id=req.body.id;//养护用户ID
  136. if(hash.isExistence(id)) {
  137. var flag= await cloudService.relieveClientDo(req.body);
  138. if(flag){
  139. var operateLogList=await models.operate_log.findByCondition(1,hash.hashDecode(id));
  140. //获得绑定的CLD客户信息
  141. res.json({ 'status': 1,'operateLogList':operateLogList,'msg':'解绑CLD客户成功' });
  142. }else{
  143. res.json({ 'status': 2,'msg':'解绑失败' });
  144. }
  145. }else{
  146. res.json({ 'status': 3,'msg':'参数不正确' });
  147. }
  148. },
  149. //养护详情页 数据
  150. getCuringById: async function(req, res){
  151. if(!hash.isExistence(req.params.id)){
  152. res.json({ 'status': 0,'msg':'error id' });
  153. return ;
  154. }
  155. var id=hash.hashDecode(req.params.id);
  156. if(!hash.isNotANumber(id)){
  157. res.json({ 'status': 0,'msg':'error id' });
  158. return ;
  159. }
  160. res.json({ 'status': 3,'msg':'数据不正确' });
  161. },
  162. }
  163. module.exports = cloudEditionAjaxController;