cloudEditionAjaxController.js 6.4 KB

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