AjaxUserController.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. <?php
  2. /**
  3. * 问答显示业务ajax
  4. * @author cp
  5. *
  6. */
  7. if (! defined ( 'IN_ZHASK' )) {
  8. exit ( 'invalid request' );
  9. }
  10. class AjaxUserController extends DooController {
  11. private $userlogic;
  12. private $asklogic;
  13. private $userinfo = array ('uid' => '0' );
  14. function __construct() {
  15. Load::controller ( "BaseController" );
  16. $base = new BaseController ();
  17. $this->userinfo = $base->init ();
  18. Load::logic ( 'User' );
  19. Load::logic ( 'Ask' );
  20. $this->userlogic = new UserLogic ();
  21. $this->asklogic = new AskLogic ();
  22. }
  23. /**
  24. * 获取分词
  25. */
  26. function get_search_works(){
  27. $keywork = isset($_GET['term']) ? $_GET['term'] : '';
  28. require_once (XUNSEARCH_URL);
  29. $xs = new XS ( SEARCH_INI );
  30. $words = $xs->search->addDb ( SEARCH_WD_DB )->getExpandedQuery($keywork);
  31. if (!empty($words)) {
  32. echo json_encode($words);
  33. }
  34. }
  35. /**
  36. * 设置赞同数
  37. */
  38. function do_support_answer() {
  39. $aid = $this->get_args ( 'aid' );
  40. $aid = is_numeric ( $aid ) ? $aid : 0;
  41. if ($aid < 0) {
  42. echo "{false}";
  43. return false;
  44. }
  45. $re = $this->userlogic->update_support_answer ( $aid, $this->userinfo ['uid'] );
  46. $json = '{"success": true}';
  47. if (! $re) {
  48. echo "{false}";
  49. return false;
  50. }
  51. echo $json;
  52. }
  53. /**
  54. * 编辑回答
  55. */
  56. function do_edit_answer() {
  57. $aid = is_numeric ( $this->get_args ( 'aid' ) ) ? $this->get_args ( 'aid' ) : 0;
  58. $data ['content'] = stripcslashes ( $this->get_args ( 'content' ) );
  59. if ($aid < 0 || empty ( $data ['content'] )) {
  60. echo "{false}";
  61. return false;
  62. }
  63. $this->userlogic->update_answer_content ( $aid, $data );
  64. $json = '{"success": true}';
  65. echo $json;
  66. }
  67. /**
  68. * 编辑问题
  69. */
  70. function do_edit_question() {
  71. $qid = is_numeric ( $this->get_args ( 'qid' ) ) ? $this->get_args ( 'qid' ) : 0;
  72. $data ['description'] = stripcslashes ( $this->get_args ( 'content' ) );
  73. if ($qid < 0 || empty ( $data ['description'] )) {
  74. echo "{false}";
  75. return false;
  76. }
  77. $this->userlogic->update_queston_description ( $qid, $data );
  78. $json = '{"success": true}';
  79. echo $json;
  80. }
  81. /**
  82. * 提高悬赏值
  83. */
  84. function do_up_price() {
  85. $qid = $this->get_args ( 'qid' );
  86. $add_price = $this->get_args ( 'add_price' );
  87. $qid = is_numeric ( $qid ) ? $qid : 0;
  88. $data ['add_price'] = is_numeric ( $add_price ) ? $add_price : 0;
  89. if ($qid < 0 || $data ['add_price'] < 0) {
  90. echo "{false}";
  91. return false;
  92. }
  93. $reslut = $this->asklogic->get_question_user_info ( $qid );
  94. //判断是否是该用户操作
  95. if ($reslut ['uid'] != $this->userinfo ['uid'] || $data ['add_price'] > $reslut ['credit3'] || $reslut ['status'] == QUESTOIN_STATUS_CLOSE) {
  96. echo "{false}";
  97. return false;
  98. }
  99. //减少用户财富总值-记录到日常操作类
  100. $is=$this->userlogic->set_credit3 ( - $data ['add_price'], $reslut ['uid'], RICH_ACTION_OFFER,SSO_UID );
  101. if($is==0){
  102. echo "{false}";
  103. return false;
  104. }
  105. //记录流向
  106. $this->userlogic->set_credit3_log ( $reslut, $data ['add_price'] );
  107. //提高悬赏值
  108. $this->userlogic->do_up_price ( $qid, $data ['add_price'] );
  109. $json = '{"success": true}';
  110. echo $json;
  111. }
  112. /**
  113. * 添加补充问题内容
  114. */
  115. function do_add_supply() {
  116. $qid = is_numeric ( $this->get_args ( 'qid' ) ) ? $this->get_args ( 'qid' ) : 0;
  117. $data ['supply'] = stripcslashes ( $this->get_args ( 'supply' ) );
  118. if ($qid == 0)
  119. return false;
  120. $this->userlogic->update_queston_supply ( $data, $qid );
  121. $json = '{"success": true}';
  122. echo $json;
  123. }
  124. /**
  125. * 上次图片
  126. */
  127. public function upload_avatar() {
  128. if (isset ( $_FILES ['Filedata'] ['name'] )) {
  129. $file = $_FILES ['Filedata'] ['tmp_name'];
  130. $error = false;
  131. if (! is_uploaded_file ( $file )) {
  132. $error = '400 Bad Request';
  133. }
  134. if ($error) {
  135. header ( 'HTTP/1.0 ' . $error );
  136. die ( 'Error ' . $error );
  137. } else {
  138. Load::lib ( "io" );
  139. $IoHandler = new IoHandler ();
  140. $dateline = get_date ();
  141. $filedir = date ( 'y/m/d' );
  142. //调用定义物理路径
  143. $t = ROOT_PATH . "global/upload/" . $filedir;
  144. $li = $IoHandler->MakeDir ( $t );
  145. $filename = _GetFileEXT ( $_FILES ['Filedata'] ['name'] );
  146. $upload_dir = $t . "/" . $dateline . "." . $filename;
  147. $k = move_uploaded_file ( $file, $upload_dir );
  148. //存储相对的视频路径
  149. $upload_video = "<input type='hidden' name='avatar' value='/global/upload/" . $filedir . "/" . $dateline . "." . $filename . "' /><img src='/global/upload/" . $filedir . "/" . $dateline . "." . $filename . "' height='100' width='100' /> <a href='javascript:void(0)'>删除图片</a>";
  150. if ($k) {
  151. echo $upload_video;
  152. } else {
  153. echo "";
  154. }
  155. }
  156. }
  157. }
  158. /**
  159. * 编辑名师答疑问题
  160. */
  161. function do_edit_vip_question() {
  162. $qid = is_numeric ( $this->get_args ( 'qid' ) ) ? $this->get_args ( 'qid' ) : 0;
  163. $data ['description'] = stripcslashes ( $this->get_args ( 'description' ) );
  164. //检测该问题是否是该用户
  165. if ($this->userinfo ['groupid'] == USER_VIP || $this->userinfo ['groupid'] == SUPER_ADMIN_ID || $this->userinfo ['groupid'] == ADMIN_ID)
  166. $vip_question = $this->asklogic->get_vip_questions_by_id ( $qid );
  167. else
  168. $vip_question = $this->asklogic->get_vip_question_by_quid ( $qid, $this->userinfo ['uid'] );
  169. if (empty ( $vip_question )) {
  170. echo '{"success": false}';
  171. die ();
  172. }
  173. $this->asklogic->update_vip_question_description ( $qid, $data ['description'] );
  174. $json = '{"success": true}';
  175. echo $json;
  176. }
  177. /**
  178. * 对名师答疑的回答进行评价
  179. */
  180. function do_comment_vip_answer(){
  181. $qid = is_numeric ( $this->get_args ( 'qid' ) ) ? $this->get_args ( 'qid' ) : 0;
  182. $data ['comment'] = stripcslashes ( $this->get_args ( 'comment' ) );
  183. //检测该问题是否是该用户
  184. if ($this->userinfo ['groupid'] == USER_VIP || $this->userinfo ['groupid'] == SUPER_ADMIN_ID || $this->userinfo ['groupid'] == ADMIN_ID)
  185. $vip_question = $this->asklogic->get_vip_questions_by_id ( $qid );
  186. else
  187. $vip_question = $this->asklogic->get_vip_question_by_quid ( $qid, $this->userinfo ['uid'] );
  188. if (empty ( $vip_question )) {
  189. echo '{"success": false}';
  190. die ();
  191. }
  192. $this->userlogic->update_vip_answer_comment($qid,$data ['comment']);
  193. $json = '{"success": true}';
  194. echo $json;
  195. }
  196. /**
  197. * 获取用户的退款次数
  198. */
  199. function get_vip_refunds(){
  200. $qid = is_numeric ( $this->get_args ( 'qid' ) ) ? $this->get_args ( 'qid' ) : 0;
  201. $vip_question = $this->asklogic->get_vip_question_by_quid ( $qid, $this->userinfo ['uid'] );
  202. if(empty($vip_question)){
  203. echo '{"message": false}';
  204. die ();
  205. }elseif($vip_question['status']!=PAID_FILL_IN){
  206. echo '{"message": false}';
  207. die ();
  208. }
  209. if($this->userinfo['refunds']==1)
  210. echo '{"message":"确定后,我们将为您这次答疑退款;<br><a href=javascript:void(0) >关于\"退款\"</a>","refunds":1}';
  211. else
  212. echo '{"message":"您无法进行不满意\"操作\";无法退款!<br><a href=javascript:void(0) >关于退款</a>","refunds":0}';
  213. }
  214. /**
  215. * 用户登录处理--session和用户日志后期可以改成写入文件
  216. */
  217. function do_login_index() {
  218. $username = $this->get_args ( "username" );
  219. $password = $this->get_args ( "password" );
  220. $day = is_numeric ( $this->get_args ( "day" ) ) ? $this->get_args ( "day" ) : 1;
  221. $lifetime = $day < 0 ? 0 : $day;
  222. if (empty ( $username ) || empty ( $password )) {
  223. echo '{"is_login":false,"message":""}';die;
  224. }
  225. $user = $this->userlogic->get_users_by_name ( $username );
  226. require_once (SITE_PATH . '/protected/plugin/client.php');
  227. $client = new client ( ZHSSO );
  228. $is_login = $client->zhsso_member_login ( $username, $password );
  229. if (is_numeric ( $is_login )) {
  230. if ($is_login == USERNAME_ONFINE) {
  231. echo '{"is_login":false}';die;
  232. } elseif ($is_login == PASSWORD_ERROR){
  233. echo '{"is_login":false}';die;
  234. }
  235. }
  236. echo '{"is_login":true}';
  237. }
  238. /**
  239. * 获取get或者POST值
  240. * @param string $name 属性名称
  241. * @return fixed 值
  242. */
  243. function get_args($name) {
  244. if (isset ( $_GET [$name] )) {
  245. if (is_array ( $_GET [$name] ))
  246. return $_GET [$name];
  247. else
  248. return addslashes ( $_GET [$name] );
  249. } elseif (isset ( $_POST [$name] )) {
  250. if (is_array ( $_POST [$name] ))
  251. return $_POST [$name];
  252. else
  253. return addslashes ( $_POST [$name] );
  254. } else {
  255. return false;
  256. }
  257. }
  258. /**
  259. * 检测数据输入的非法字符和转义非法字符
  260. */
  261. function check_params($name = "") {
  262. if (isset ( $this->params [$name] )) {
  263. return addslashes ( $this->params [$name] );
  264. } else {
  265. return false;
  266. }
  267. }
  268. public function askUpdate(){
  269. $creditlist = $this->asklogic->get_credit_log();
  270. require_once (SITE_PATH . '/protected/plugin/client.php');
  271. $client = new client ( ZHSSO );
  272. foreach($creditlist as $k => $v){
  273. $type = $v['amount'] < 0 ? 2 : 1;
  274. $is_succes = $client->zhsso_member_askupdate($v['username'], $type, abs($v['amount']), $v['time']);
  275. $is_succes = explode ( "\r", $is_succes );
  276. $ts = json_decode ( $is_succes ['0'], true );
  277. if($ts != 1){
  278. exit($k);
  279. }
  280. }
  281. exit('success');
  282. }
  283. }
  284. ?>