HelpController.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <?php
  2. /**
  3. * Created by 上海互教教育科技有限公司.
  4. * User: li
  5. * Date: 2018/9/16
  6. * Time: 下午 15:29
  7. */
  8. class HelpController extends Controller
  9. {
  10. public function actionIndex(){
  11. $result=array();
  12. //读取通知
  13. $res = json_decode(http('help/coach/notice', 'get', $this->authUsername),true);
  14. if(isset($res['errCode']) && $res['errCode']=='00' && isset($res['data']) && $res['data']){
  15. $result['Notice']['status']=1;
  16. $result['Notice']['data']=$res['data'];
  17. }else{
  18. $result['Notice']['status']=0;
  19. }
  20. //读取常见问题
  21. $res1 = json_decode(http('help/coach/familiar', 'get', $this->authUsername),true);
  22. if(isset($res1['errCode']) && $res1['errCode']=='00' && isset($res1['data']) && $res1['data']){
  23. $result['Familiar']['status']=1;
  24. $result['Familiar']['data']=$res1['data'];
  25. }else{
  26. $result['Familiar']['status']=0;
  27. }
  28. //热门问题
  29. $res2 = json_decode(http('help/coach/hot', 'get', $this->authUsername),true);
  30. if(isset($res2['errCode']) && $res2['errCode']=='00' && isset($res2['data']) && $res2['data']){
  31. $result['Hot']['data']=$res2['data'];
  32. $result['Hot']['status']=1;
  33. }else{
  34. $result['Hot']['status']=0;
  35. }
  36. $res = json_decode(http('help/coach/config', 'get', $this->authUsername),true);
  37. if(isset($res['errCode']) && $res['errCode']=='00' && isset($res['data']) && $res['data']){
  38. $result['HelpHello']['data']=$res['data'];
  39. $result['HelpHello']['status']=1;
  40. }else{
  41. $result['HelpHello']['status']=0;
  42. }
  43. if($result){
  44. exit(json_encode(array('status'=>1,'data'=>$result)));
  45. }else{
  46. exit(json_encode(array('status'=>0,'data'=>$result)));
  47. }
  48. }
  49. //提问
  50. public function actionSearch(){
  51. $alikeName=Req::post('keyword');
  52. $result=array('status'=>0);
  53. $param['alikeName']=$alikeName;
  54. $res = json_decode(http('help/coach/list-es', 'post', $this->authUsername,$param),true);
  55. if(isset($res['errCode']) && $res['errCode']=='00' && isset($res['data'])){
  56. $result['data']=$res['data'];
  57. $result['status']=1;
  58. }
  59. exit(json_encode($result));
  60. }
  61. //自助查询
  62. public function actionList(){
  63. //分类
  64. $result['status']=0;
  65. $res = json_decode(http('help/coach/list/tree', 'get', $this->authUsername),true);
  66. if(isset($res['errCode']) && $res['errCode']=='00' && isset($res['data'])){
  67. $result['data']['tree']=$res['data'];
  68. }
  69. $res = json_decode(http('help/coach/list', 'post', $this->authUsername),true);
  70. if(isset($res['errCode']) && $res['errCode']=='00' && isset($res['data'])){
  71. $result['status']=1;
  72. $result['data']['list']=$res['data'];
  73. }
  74. http('help/coach-count/auto', 'put', $this->authUsername);
  75. exit(json_encode($result));
  76. }
  77. //查看问题
  78. public function actionView(){
  79. $id=Req::post('id');
  80. $isAnswer=Req::post('isAnswer');
  81. $need_count=Req::post('needcount');
  82. $result['status']=0;
  83. $res = json_decode(http('help/coach/'.$id, 'get', $this->authUsername),true);
  84. if(isset($res['errCode']) && $res['errCode']=='00' && isset($res['data'])){
  85. if($need_count){
  86. if($isAnswer=='1') {
  87. http('help/coach-count/problem/1/' . $id, 'put', $this->authUsername); //查看为0,标准答案为1
  88. }elseif($isAnswer=='2'){
  89. http('help/coach-count/problem/2/' . $id, 'put', $this->authUsername); //查看为0,标准答案为1
  90. }else{
  91. http('help/coach-count/problem/0/'.$id, 'put', $this->authUsername); //查看为0,标准答案为1
  92. }
  93. }
  94. $result['status']=1;
  95. $result['data']=$res['data'];
  96. }
  97. exit(json_encode($result));
  98. }
  99. //有用、没有
  100. public function actionUse(){
  101. $id=Req::post('id');
  102. $name=Req::post('name');
  103. $type=Req::post('type');
  104. $suggest=Req::post('suggest');
  105. $result['status']=0;
  106. if($type==1){
  107. $res = json_decode(http('help/coach-count/use/'.$id.'/'.urlencode($name), 'put', $this->authUsername),true);
  108. if(isset($res['errCode']) && $res['errCode']=='00'){
  109. $result['status']=1;
  110. }
  111. exit(json_encode($result));
  112. }else{
  113. $res = json_decode(http('help/coach-count/useless/'.$id.'/'.urlencode($name), 'put', $this->authUsername),true);
  114. if(isset($res['errCode']) && $res['errCode']=='00' ){
  115. $result['status']=1;
  116. $param['hspName']=$name;
  117. $param['hspType']=1;
  118. $param['hpId']=$id;
  119. $param['source']=0;
  120. $res1 = json_decode(http('help/coach/add', 'post', $this->authUsername,$param),true);
  121. if(isset($res1['errCode']) && $res1['errCode']=='00' && isset($res1['data'])){
  122. $result['status']=1;
  123. }
  124. }
  125. exit(json_encode($result));
  126. }
  127. }
  128. public function actionNoAnswer(){
  129. $name=Req::post('name');
  130. $param['hspName']=$name;
  131. $param['hspType']=0;
  132. $param['source']=0;
  133. $res1 = json_decode(http('help/coach/add', 'post', $this->authUsername,$param),true);
  134. if(isset($res1['errCode']) && $res1['errCode']=='00' && isset($res1['data'])){
  135. $result['status']=1;
  136. }
  137. }
  138. //问题列表
  139. public function actionQuestion(){
  140. $pageNumber=Req::post('pnum');
  141. $typeId=Req::post('typeId');
  142. $result['status']=0;
  143. if(!$pageNumber) $pageNumber=1;
  144. $param['pageNum']=$pageNumber;
  145. if($typeId){
  146. $param['typeId']=$typeId;
  147. }
  148. $res = json_decode(http('help/coach/list', 'post', $this->authUsername,$param),true);
  149. if(isset($res['errCode']) && $res['errCode']=='00' && isset($res['data'])){
  150. $result['status']=1;
  151. $result['data']=$res['data'];
  152. }
  153. exit(json_encode($result));
  154. }
  155. //问题编辑
  156. public function actionAdd(){
  157. $param['hspName']=Req::post('name');
  158. $source=Req::post('source');
  159. if(!$source){
  160. $source=1;
  161. }else{
  162. $source=0;
  163. }
  164. $param['hspType']=2;
  165. $param['hpId']=Req::post('id');
  166. $param['suggest']=Req::post('suggest');
  167. $param['source']=$source;
  168. $result['status']=0;
  169. $res = json_decode(http('help/coach/add', 'post', $this->authUsername,$param),true);
  170. if(isset($res['errCode']) && $res['errCode']=='00'){
  171. $result['status']=1;
  172. }
  173. exit(json_encode($result));
  174. }
  175. public function actionHelper(){
  176. $this->render('help');
  177. }
  178. public function actionSelfHelp(){
  179. $this->render('selfHelp');
  180. }
  181. }