You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

135 lines
6.2 KiB

  1. <?php
  2. header("Access-Control-Allow-Origin:*");
  3. $post = $_POST;
  4. $time = date("Y-m-d H:i:s",time());
  5. $tr = -1;
  6. if($post['user_type'] == 0){
  7. $post['channel_id'] = empty($post['channel_id'])?0:$post['channel_id'];
  8. $post['teamwork'] = empty($post['teamwork'])?0:$post['teamwork'];
  9. if(!empty($post['channel_name']) && !empty($post['linkman']) && !empty($post['com_tel']) && !empty($post['channel_admin'])){
  10. if($post['org_id'] == 0){
  11. $sql = "select ORG_NAME from base_organization where ORG_NAME = '$post[channel_name]'";
  12. $result = $pdo ->query($sql);
  13. $arr = $result->fetchAll(PDO::FETCH_ASSOC);
  14. if(count($arr) != 0){
  15. $code = -2;
  16. $info = '该渠道名已存在';
  17. $massge = '失败';
  18. }else{
  19. $sql = "select ID from base_organization order by ID desc limit 1";
  20. $result = $pdo ->query($sql);
  21. $org = $result->fetchAll(PDO::FETCH_ASSOC);
  22. $org = $org[0]['ID']+1;
  23. $sql = "insert base_organization(ID,ORG_ID,ORG_NAME,CREATE_USER_ID,CREATE_TIME)
  24. values($org,$org,'$post[channel_name]',$post[user_id],'$time')";
  25. $result = $pdo ->exec($sql);
  26. $sql = "update base_customer set ORG_ID = $org where CUST_ID = $post[cust_id]";
  27. $result1 = $pdo ->exec($sql);
  28. $sql = "update base_user set ORG_ID = $org,TOP_ORG_ID = $org,STATUS = 0 where ID = $post[user_id]";
  29. $result2 = $pdo ->exec($sql);
  30. if($result && $result1 && $result2){
  31. $tr = 1;
  32. }else{
  33. $tr = 0;
  34. }
  35. }
  36. }else{
  37. $sql = "select USER_NAME from base_user where USER_NAME = '$post[channel_name]' and ORG_ID != $post[org_id]";
  38. $result = $pdo ->query($sql);
  39. $arr = $result->fetchAll(PDO::FETCH_ASSOC);
  40. if(count($arr) != 0){
  41. $code = -2;
  42. $info = '该渠道名已存在';
  43. $massge = '失败';
  44. }else{
  45. $org = $post['org_id'];
  46. $sql = "update base_organization set ORG_NAME = '$post[channel_name]',UPDATE_USER_ID = $post[user_id],UPDATE_TIME = '$time' where ORG_ID = $post[org_id]";
  47. $result = $pdo ->exec($sql);
  48. if($result){
  49. $tr = 1;
  50. }else{
  51. $tr = 0;
  52. }
  53. }
  54. }
  55. if($tr == 1){
  56. $sql = "update base_customer set CHAN_QUALITY = 2,ORG_ID = $org,CHAN_NAME = '$post[channel_name]',CHAN_SHORT = '$post[teamwork]',CHAN_TYPE = $post[saleStyle_company],AREA_ID = $post[cantonal],LINKMAN = '$post[linkman]',LINK_TEL = $post[com_tel],RESMAN = '$post[channel_admin]', SELA_TYPE = $post[saleStyle],STATUS = 1,CHAN_AGREEMENT = $post[channel_id],USER_TYPE = 0,END_TIME = '$time'
  57. where CUST_ID = $post[cust_id]";
  58. $result = $pdo ->exec($sql);
  59. if($result){
  60. $code = 0;
  61. $info = 'success';
  62. $massge = '成功';
  63. }else{
  64. $code = -1;
  65. $info = 'fail';
  66. $massge = '4';
  67. }
  68. }elseif($tr == 0){
  69. $code = -3;
  70. $info = '添加渠道失败';
  71. $massge = '失败';
  72. }
  73. }else{
  74. $code = -1;
  75. $info = 'fail';
  76. $massge = '3';
  77. }
  78. }else{
  79. $sql_get_user_id = "SELECT USER_ID,ORG_ID FROM `base_customer` where CUST_ID =".$_POST['cust_id'];
  80. $result = $pdo ->query($sql_get_user_id);
  81. $user_id = $result->fetchAll(PDO::FETCH_ASSOC);
  82. if(!$user_id[0]['ORG_ID']){
  83. $sql = "select ID from base_organization order by ID desc limit 1";
  84. $result = $pdo ->query($sql);
  85. $org = $result->fetchAll(PDO::FETCH_ASSOC);
  86. $org = $org[0]['ID']+1;
  87. $sql = "insert base_organization(ID,ORG_ID,ORG_NAME,CREATE_USER_ID,CREATE_TIME)
  88. values($org,$org,'".$_POST['com_name']."_".$_POST['agency_name']."',".$user_id[0]['USER_ID'].",'". date('Y-m-d H:i:s', time())."')";
  89. $result = $pdo ->exec($sql);
  90. $sql = "update base_customer set ORG_ID = $org where CUST_ID =".$_POST['cust_id'];
  91. $result1 = $pdo ->exec($sql);
  92. $sql = "update base_user set ORG_ID = $org,STATUS = 0 where ID =".$user_id[0]['USER_ID'];
  93. $result2 = $pdo ->exec($sql);
  94. }
  95. //组织表
  96. if(!empty($post['agency_name']) && !empty($post['linkman_id']) && !empty($post['tel_personal']) && !empty($post['principal_personal'])){
  97. $post['com_name'] = empty($post['com_name'])?0:$post['com_name'];
  98. $sql = "update base_customer set CHAN_QUALITY = 0,CHAN_NAME = '$post[agency_name]',CHAN_TYPE = $post[saleStyle_personal_channel],AREA_ID = $post[cantonal],LINKMAN = '$post[agency_name]',LINK_TEL = $post[tel_personal],RESMAN = '$post[principal_personal]',SELA_TYPE = $post[saleStyle_personal],STATUS = 1,ID_CARD = '$post[linkman_id]',COM_NAME = '$post[com_name]',USER_TYPE = 1,END_TIME = '$time'
  99. where CUST_ID = $post[cust_id]";
  100. $result = $pdo ->exec($sql);
  101. if($result){
  102. $code = 0;
  103. $info = 'success';
  104. $massge = '成功';
  105. }else{
  106. $code = -1;
  107. $info = 'fail';
  108. $massge = $sql;
  109. }
  110. }else{
  111. $code = -1;
  112. $info = 'fail';
  113. $massge = '1';
  114. }
  115. }
  116. $json['code'] = $code;
  117. $json['info'] = $info;
  118. $json['massge'] = $massge;
  119. echo json_encode($json);
  120. ?>