UserController.php 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073
  1. <?php
  2. /**
  3. * 用户操作业务
  4. * @author cp
  5. *
  6. */
  7. if (! defined ( 'IN_ZHASK' )) {
  8. exit ( 'invalid request' );
  9. }
  10. class UserController 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. public function index() {
  24. //$this->userlogic->test_send_gmail("",$this->userinfo['uid'],"NEW_ANSWER");
  25. //$this->userlogic->sendmail("","cpthought@vip.qq.com");
  26. $this->userlogic->delete_search_index(array('17847', '17846', '17845'));
  27. // require_once (SITE_PATH . '/protected/plugin/client.php');
  28. //
  29. // $client = new client ( ZHSSO );
  30. //
  31. // $is_succes = $client->zhsso_member_madd ( 88,5,"ask" );
  32. //
  33. // $is_succes=explode("\r",$is_succes);
  34. //
  35. // $ts = json_decode ( $is_succes['1'], true );
  36. //
  37. // var_dump($ts);
  38. }
  39. function user_exit() {
  40. $sid = $_COOKIE ['sid'];
  41. $this->userlogic->delete_session ( $sid );
  42. setcookie ( "auth", "", time () + 3600 * 24, "/", COOKIE_WEB_SITE );
  43. setcookie ( "sid", "", time () + 3600 * 24, "/", COOKIE_WEB_SITE );
  44. setcookie ( "tuid", "", time () + 3600 * 24, "/", COOKIE_WEB_SITE );
  45. setcookie ( "e", '1', time () + 3600 * 24, "/", COOKIE_WEB_SITE );
  46. $this->Messager ( "登出成功", "/" );
  47. }
  48. public function sysLoginOut(){
  49. $sid = $_COOKIE ['sid'];
  50. $this->userlogic->delete_session ( $sid );
  51. setcookie ( "auth", "", time () + 3600 * 24, "/", COOKIE_WEB_SITE );
  52. setcookie ( "sid", "", time () + 3600 * 24, "/", COOKIE_WEB_SITE );
  53. setcookie ( "tuid", "", time () + 3600 * 24, "/", COOKIE_WEB_SITE );
  54. }
  55. /**
  56. * 同步登陆
  57. */
  58. public function synLogin() {
  59. $uid=$this->params['username'];
  60. require_once (SITE_PATH . '/protected/plugin/client.php');
  61. $client = new client(ZHSSO);
  62. //检测认证
  63. $auth=$client->zhsso_checkauth($uid);
  64. $a = explode ( "\r", $auth );
  65. // var_dump($a);
  66. // exit();
  67. if($a!='1')
  68. return false;
  69. $user=$client->zhsso_getuserinfo_by_uid ( $uid );
  70. $u = explode ( "\r", $user );
  71. $user = json_decode($u[0]);
  72. //同步通行证用户
  73. $us = $this->userlogic->get_users_by_name ( $user[0]->username );
  74. if (empty ( $us )) {
  75. $uid = $this->userlogic->add_user2 ( $user[0] );
  76. $us = $this->userlogic->get_users_information ( $uid );
  77. } else {
  78. $uid = $this->userlogic->update_user2 ( $us['uid'], $user[0] );
  79. }
  80. $userinfo = authcode ( $user[0]->username, "tr" );
  81. $sessionID = random ( 8 );
  82. //写入session
  83. //默认生命周期1天
  84. $lifetime = get_date ( 1 );
  85. $this->userlogic->set_session ( $sessionID, $us ['uid'], $user[0]->username, $lifetime );
  86. header('P3P: CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE GOV"');//p3p
  87. setcookie ( "auth", $userinfo, time () + 3600 * 24, "/", COOKIE_WEB_SITE );
  88. setcookie ( "sid", $sessionID, time () + 3600 * 24, "/", COOKIE_WEB_SITE );
  89. setcookie ( "tuid", $user[0]->id, time () + 3600 * 24, "/", COOKIE_WEB_SITE );
  90. }
  91. // 检测手机格式
  92. function checkMobile($mobile) {
  93. if(preg_match("/^1[34578]{1}\d{9}$/",$mobile)){
  94. return TRUE;
  95. } else {
  96. return FALSE;
  97. }
  98. }
  99. /**
  100. * 用户登录处理--session和用户日志后期可以改成写入文件
  101. */
  102. function do_login() {
  103. $username = $this->get_args ( "username" );
  104. $password = $this->get_args ( "password" );
  105. $day = is_numeric ( $this->get_args ( "day" ) ) ? $this->get_args ( "day" ) : 1;
  106. $lifetime = $day < 0 ? 0 : $day;
  107. if (empty ( $username ) || empty ( $password )) {
  108. $this->Messager ( "请输入正确的参数", "/login" );
  109. }
  110. require_once (SITE_PATH . '/protected/plugin/client.php');
  111. $client = new client ( ZHSSO );
  112. if(filter_var($username, FILTER_VALIDATE_EMAIL)){
  113. $is_login = $client->zhsso_member_login ( $username, $password ,1);
  114. }else if($this->checkMobile($username)) {
  115. $is_login = $client->zhsso_member_login( $username, $password, 2 );
  116. }else{
  117. $is_login = $client->zhsso_member_login ( $username, $password );
  118. }
  119. $is_login = explode ( "\r", $is_login );
  120. if (is_numeric ( $is_login [0] )) {
  121. if ($is_login [0] == USERNAME_ONFINE) {
  122. $this->Messager ( "您输入的帐号或者密码有误", "/login" );
  123. //删除用户相关记录--是否有同步删除功能
  124. //if ($user) {
  125. //$this->userlogic->delete_user_tem( $user['uid']);
  126. //}
  127. } elseif ($is_login [0] == PASSWORD_ERROR)
  128. $this->Messager ( "您输入的帐号或者密码有误", "/login" );
  129. elseif ($is_login [0] == - 3) //USER_NOACTION
  130. $this->Messager ( "用户未激活", "http://sso.smartcost.com.cn/" );
  131. else
  132. $this->Messager ( "您输入的帐号或者密码有误", "/login" );
  133. } elseif (! empty ( $is_login [0] )) {
  134. $ts = json_decode ( $is_login [0], true );
  135. if (empty ( $ts ))
  136. $this->Messager ( "通信异常", "/login" );
  137. $user = $this->userlogic->get_users_by_name ( $ts [0] ['username'] );
  138. //同步通行证用户
  139. if (empty ( $user )) {
  140. $uid = $this->userlogic->add_user2 ( $ts [0]);
  141. $user = $this->userlogic->get_users_information ( $uid );
  142. }else{
  143. $uid = $this->userlogic->update_user2 ( $user['uid'], $ts [0]);
  144. }
  145. Doo::loadModel ( 'MessageDao' );
  146. $messagedao = new MessageDao ();
  147. $message_count = $messagedao->get_message_count_by_touid ( $user ['uid'] );
  148. $sessionID = random ( 8 );
  149. $ip = client_ip ();
  150. //默认生命周期1天
  151. $lifetime = get_date ( $lifetime );
  152. $userinfo = authcode ( $user ['username'], "tr" );
  153. //写入session
  154. $this->userlogic->set_session ( $sessionID, $user ['uid'], $user ['username'], $lifetime );
  155. //写入用户日志
  156. $this->userlogic->set_userlog ( $user ['uid'], $user ['username'] );
  157. //积分值增加-做今天登陆判断
  158. $s_status = $this->userlogic->get_crontab_status ( $user ['uid'], SYSTEM_DAILY_LOGIN );
  159. if ($s_status != COMPLETE||$s_status===0) {
  160. $this->userlogic->set_credit1 ( 'add', $user ['uid'], CREDIT_POINT_LOGIN, CREDIT_ACTION_LOGIN );
  161. $this->userlogic->complete_daily_crontab ( $user ['uid'], SYSTEM_DAILY_LOGIN );
  162. }
  163. if($user['is_email']!=1){
  164. $this->userlogic->set_email_config($user['uid']);
  165. }
  166. $avatar = $client->ps_getavatar ( $ts [0] ['id'] );
  167. foreach ($avatar as $key=>$value){
  168. if(!file_get_contents($value,0,null,0,1))
  169. $avatar[$key]=DEF_AVATAR;
  170. }
  171. $avatar=json_encode($avatar);
  172. $this->userlogic->update_user_avatar_by_id($user ['uid'],$avatar);
  173. define ( "MASTER_ID", $user ['uid'] );
  174. define ( 'MEMBER_NAME', $user ['username'] );
  175. define ( "MESSAGE_COUNT", $message_count ['count'] );
  176. setcookie ( "auth", $userinfo, time () + 3600 * 24, "/", COOKIE_WEB_SITE );
  177. setcookie ( "sid", $sessionID, time () + 3600 * 24, "/", COOKIE_WEB_SITE );
  178. setcookie ( "tuid", $ts [0] ['id'], time () + 3600 * 24, "/", COOKIE_WEB_SITE );
  179. setcookie ( "d", $ts [0] ['keys_auth'], time () + 3600 * 24, "/", COOKIE_WEB_SITE );
  180. //define("SYS_LOGIN",'<script src="http://zhzdwk.com/api/text_cook"></script>');
  181. } else {
  182. $this->Messager ( "通信异常", "/login" );
  183. }
  184. //http://localzhask.com/login http://zhzdwd.com/login
  185. if($_SERVER['HTTP_REFERER']=="http://zhzdwd.com/login")
  186. return "/";
  187. else
  188. return $_SERVER['HTTP_REFERER'];
  189. }
  190. function getquestion(){
  191. $condition = " and price != 0 ";
  192. $limit = " order by time desc limit 3";
  193. $question= $this->asklogic->get_questions_list_tem ( array (), $condition, $limit );
  194. $page['question']=array();
  195. $t=array();
  196. foreach ($question as $key=>$value){
  197. $t['id']=$value['id'];
  198. $t['price']=$value['price'];
  199. $t['title']=$value['title'];
  200. array_push($page['question'], $t);
  201. }
  202. /*
  203. $QA=$this->asklogic->get_QA();
  204. $page['QA']=$QA;
  205. */
  206. echo json_encode($page);
  207. }
  208. /**
  209. * 删除回答
  210. */
  211. function do_delete_answer() {
  212. $aid = $this->check_params ( 'aid' );
  213. $qid = $this->check_params ( 'qid' );
  214. $aid = is_numeric ( $aid ) ? $aid : 0;
  215. $qid = is_numeric ( $qid ) ? $qid : 0;
  216. if ($aid <= 0 || $qid <= 0)
  217. $this->Messager ( "请输入正确的参数", "/askpage/" . $qid );
  218. //用户组
  219. if ($this->userinfo ['groupid'] != SUPER_ADMIN_ID && $this->userinfo ['groupid'] != ADMIN_ID)
  220. $this->Messager ( "权限不足,请联系管理员", "/askpage/" . $qid );
  221. $this->userlogic->delete_answer ( $aid ,$qid);
  222. header ( 'Content-Type:text/html;charset=utf-8' );
  223. @header ( "Location: " . WEB_SITE . "/messager?content=问题已经成功删除&url=/askpage/" . $qid );
  224. }
  225. /**
  226. * 删除问题
  227. */
  228. function do_delete_question() {
  229. $qid = $this->check_params ( 'qid' );
  230. $qid = is_numeric ( $qid ) ? $qid : 0;
  231. if ($qid <= 0)
  232. $this->Messager ( "请输入正确的参数", "/askpage/" . $qid );
  233. //用户组
  234. if ($this->userinfo ['groupid'] != SUPER_ADMIN_ID && $this->userinfo ['groupid'] != ADMIN_ID)
  235. $this->Messager ( "权限不足,请联系管理员", "/askpage/" . $qid );
  236. $this->userlogic->delete_question ( $qid );
  237. header ( 'Content-Type:text/html;charset=utf-8' );
  238. @header ( "Location: " . WEB_SITE . "/messager?content=问题已经成功删除&url=/" );
  239. }
  240. /**
  241. * 关闭问题
  242. */
  243. public function do_question_close() {
  244. $qid = is_numeric ( $this->params ['qid'] ) ? $this->params ['qid'] : 0;
  245. $rs = $this->asklogic->get_question_by_uqid ( $qid, $this->userinfo ['uid'] );
  246. if ($qid <= 0)
  247. $this->Messager ( "请输入正确的参数", "/" );
  248. //删除权限的判定
  249. if ($this->userinfo ['groupid'] != SUPER_ADMIN_ID && $this->userinfo ['groupid'] != ADMIN_ID) {
  250. if (empty ( $rs ))
  251. $this->Messager ( "操作有误", "/" );
  252. }
  253. $this->userlogic->close_question ( $qid );
  254. $type="CLOSE_QUESTION";
  255. if($rs['price']>0)
  256. $type="PAY_CLOSE_QUESTION";
  257. $this->userlogic->send_email($this->userinfo ['uid'],$type,$qid,0);
  258. header ( 'Content-Type:text/html;charset=utf-8' );
  259. @header ( "Location: " . WEB_SITE . "/messager?content=问题已经成功关闭&url=/askpage/" . $qid );
  260. }
  261. /**
  262. * 设置最佳答案--管理员也使用
  263. */
  264. public function do_best_answer() {
  265. $data ['qid'] = $this->get_args ( 'qid' );
  266. $data ['aid'] = $this->get_args ( 'aid' );
  267. $data ['comment'] = $this->get_args ( 'comment' );
  268. $rs = $this->asklogic->get_question_by_uqid ( $data ['qid'], $this->userinfo ['uid'] );
  269. $ans = $this->asklogic->get_answer_by_aqid ( $data ['aid'], $data ['qid'] );
  270. //操作权限的判定
  271. if ($this->userinfo ['groupid'] != SUPER_ADMIN_ID && $this->userinfo ['groupid'] != ADMIN_ID) {
  272. if (empty ( $rs ))
  273. $this->Messager ( "权限不足,请联系管理员", "/" );
  274. }
  275. if($rs['status']!=QUESTOIN_STATUS_UNRESOLVED){
  276. $this->Messager ( "该问题已进行相关操作", "/" );
  277. }
  278. if (empty ( $ans ))
  279. $this->Messager ( "没有相关问题", "/" );
  280. if (! is_numeric ( $data ['qid'] ) || ! is_numeric ( $data ['aid'] ))
  281. $this->Messager ( "请输入正确的值", "/" );
  282. $data ['quid'] = $rs ['authorid'];
  283. $data ['auid'] = $ans ['authorid'];
  284. $data ['title'] = $rs ['title'];
  285. $data ['price'] = $rs ['price'];
  286. $data ['username'] = $ans ['author'];
  287. $this->userlogic->set_best_answer ( $data );
  288. header ( 'Content-Type:text/html;charset=utf-8' );
  289. @header ( "Location: " . WEB_SITE . "/messager?content=答案采纳成功&url=/askpage/" . $data ['qid'] );
  290. }
  291. /**
  292. * 发起名师答疑2
  293. */
  294. public function do_update_vip_question() {
  295. $rs = $this->asklogic->get_vip_question_by_paid ( $this->userinfo ['uid'] );
  296. if (empty ( $rs ))
  297. $this->Messager ( "请先付款", "/question/add_vip" );
  298. $title = $this->get_args ( 'title' );
  299. // xxs过滤
  300. $title = htmlspecialchars($title);
  301. $description = stripcslashes ( $this->get_args ( 'description' ) );
  302. if (empty ( $title ) || empty ( $description ))
  303. $this->Messager ( "请填写相关信息", "/question/add_vip" );
  304. $phone = $this->get_args ( 'phone' );
  305. $qq = $this->get_args ( 'qq' );
  306. $this->userlogic->update_vip_question ( $rs ['id'], $title, $description, $this->userinfo ['uid'], $phone, $qq );
  307. header ( 'Content-Type:text/html;charset=utf-8' );
  308. @header ( "Location: " . WEB_SITE . "/messager?content=问题发起成功&url=/advisory_page/" . $rs ['id'] );
  309. }
  310. /**
  311. * 发起名师答疑1
  312. */
  313. public function do_add_vip_question() {
  314. require_once SITE_PATH . '/protected/config/auth_issue.conf.php';
  315. $auth = $auth ['GENERAL_USER_GROUP' . $this->userinfo ['groupid']];
  316. $issue = $this->asklogic->auth_question_issue ( $this->userinfo ['uid'], $this->userinfo ['groupid'], $auth );
  317. if ($issue == 2)
  318. $this->Messager ( "您今天提问条数(" . $auth ['DAY_TOTALS'] . ")已用完", "/" );
  319. elseif ($issue == 3)
  320. $this->Messager ( "每" . $auth ['TIME_INTERVAL']/60 . "分钟内只可以发布" . $auth ['TIME_TOTALS'] . "条", "/" );
  321. $price = $this->get_args ( 'price' );
  322. $price = is_numeric ( $price ) ? $price : 0;
  323. //已付款未填写
  324. $rs = $this->asklogic->get_vip_question_by_paid ( $this->userinfo ['uid'] );
  325. $data ['mod'] = 'askpost';
  326. $data ['price'] = $price;
  327. $data ['qq'] = $this->userinfo ['qq'];
  328. $data ['phone'] = $this->userinfo ['phone'];
  329. if (! empty ( $rs )) { //防止重复提交
  330. $data ['qid'] = $rs ['id'];
  331. $data ['message'] = "您上一次付款后没有发布问题,故本次提问不做重复扣费";
  332. $this->render ( 'askPost_pay_2', $data );
  333. die ();
  334. }
  335. if ($price <= 0)
  336. $this->Messager ( "金额不足,请充值", "/question/add_vip" );
  337. if ($price > $this->userinfo ['credit3'])
  338. $this->Messager ( "金额不足,请充值", "/question/add_vip" );
  339. if (($this->userinfo ['credit3'] - $price) < 0)
  340. $this->Messager ( "金额不足,请充值", "/question/add_vip" );
  341. if (! ($price == 500 || $price == 200 || $price == 100))
  342. $this->Messager ( "金额只能为500元,200元,100元", "/question/add_vip" );
  343. //确认付费
  344. $data ['author'] = $this->userinfo ['username'];
  345. $data ['authorid'] = $this->userinfo ['uid'];
  346. $id = $this->userlogic->add_vip_question ( $data );
  347. if ($id == 0)
  348. $this->Messager ( "操作失败-请重新操作", "/question/postenter" );
  349. $data ['qid'] = $id;
  350. $this->render ( 'askPost_pay_2', $data );
  351. }
  352. /**
  353. * 添加一条问题
  354. */
  355. public function do_add_question() {
  356. $start=strtotime(date("Y-m-d")." 23:00:00");
  357. $end=strtotime(date("Y-m-d")." 23:59:59");
  358. $one=strtotime(date("Y-m-d")." 00:00:00");
  359. $two=strtotime(date("Y-m-d")." 8:00:00");
  360. //$end=strtotime(date("Y-m-d",strtotime("+1 day"))." 8:00:00");
  361. if ($one<=time()&&$two>=time()){
  362. $this->render ( 'askPost_close' );
  363. die;
  364. }
  365. if ($start<=time()&&$end>=time()){
  366. $this->render ( 'askPost_close' );
  367. die;
  368. }
  369. session_start();
  370. require_once ('./protected/plugin/class.geetestlib.php');
  371. $GtSdk = new GeetestLib();
  372. if ($_SESSION['gtserver'] == 1) {
  373. $result = $GtSdk->validate($_POST['geetest_challenge'], $_POST['geetest_validate'], $_POST['geetest_seccode']);
  374. if ($result == TRUE) {
  375. //echo 'Yes!';
  376. } else if ($result == FALSE) {
  377. $this->Messager("请检查验证是否正确", "/question/add");
  378. } else {
  379. $this->Messager("请检查验证是否正确", "/question/add");
  380. }
  381. }else{
  382. if ($GtSdk->get_answer($_POST['geetest_validate'])) {
  383. //echo "yes";
  384. }else{
  385. $this->Messager("请检查验证是否正确", "/question/add");
  386. }
  387. }
  388. // die;
  389. // if(!isset($_POST['vc']) || ($_SESSION['vc']!=$_POST['vc'])){
  390. // $this->Messager("请检查验证是否正确", "/question/add");
  391. // }
  392. //检测问题数
  393. require_once SITE_PATH . '/protected/config/auth_issue.conf.php';
  394. $auth = $auth ['GENERAL_USER_GROUP' . $this->userinfo ['groupid']];
  395. $issue = $this->asklogic->auth_question_issue ( $this->userinfo ['uid'], $this->userinfo ['groupid'], $auth );
  396. if ($issue == 2)
  397. $this->Messager ( "您今天提问条数(" . $auth ['DAY_TOTALS'] . ")已用完", "/" );
  398. elseif ($issue == 3)
  399. $this->Messager ( "每" . $auth ['TIME_INTERVAL']/60 . "分钟内只可以发布" . $auth ['TIME_TOTALS'] . "条", "/" );
  400. $data ['title'] = $this->get_args ( 'title' );
  401. // 防止xxs攻击
  402. $data['title'] = htmlspecialchars($data['title']);
  403. $data ['category_id'] = $this->get_args ( 'category_id' );
  404. $data ['description'] = stripcslashes ( $this->get_args ( 'description' ) );
  405. $data ['price'] = $this->get_args ( 'price' );
  406. if ($data ['price'] !== false) {
  407. $data ['price'] = is_numeric ( $data ['price'] ) ? $data ['price'] : 0;
  408. if ($this->userinfo ['credit3'] < $data ['price'])
  409. $this->Messager ( "财富值不足,请充值", "/question/add" );
  410. } else {
  411. $data ['price'] = 0;
  412. }
  413. $data ['authorid'] = $this->userinfo ['uid'];
  414. $data ['author'] = $this->userinfo ['username'];
  415. //|| empty ( $data ['description'] )
  416. if (empty ( $data ['title'] ) || (! is_numeric ( $data ['category_id'] )))
  417. $this->Messager ( "问题发起不成功,请重新填写", "/question/add" );
  418. $id = $this->userlogic->add_question ( $data );
  419. $_SESSION['vc']='NULL';
  420. if ($id) {
  421. header ( 'Content-Type:text/html;charset=utf-8' );
  422. @header ( "Location: " . WEB_SITE . "/messager?content=问题发起成功&url=/askpage/" . $id );
  423. } else {
  424. header ( 'Content-Type:text/html;charset=utf-8' );
  425. @header ( "Location: " . WEB_SITE . "/messager?content=问题发起不成功,请重新填写&url=/question/add" );
  426. }
  427. }
  428. /**
  429. * 回答一个问题--添加积分,财富
  430. */
  431. public function do_reply_question() {
  432. //include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  433. $answer_data = $this->get_args ( 'answer_data' );
  434. $content = stripcslashes ( $this->get_args ( 'content' ) );
  435. if (empty ( $content ))
  436. return false;
  437. $answer_data = explode ( ":", $answer_data );
  438. $data ['qid'] = $answer_data [0];
  439. $data ['title'] = $answer_data [1];
  440. $data ['author'] = $this->userinfo ['username'];
  441. $data ['authorid'] = $this->userinfo ['uid'];
  442. $data ['content'] = $content;
  443. if (! is_numeric ( $data ['qid'] ) || ! is_numeric ( $data ['authorid'] ))
  444. return false;
  445. $answer=$this->asklogic->get_answer_by_quid($data ['qid'],$this->userinfo ['uid']);
  446. if(!empty($answer))
  447. return false;
  448. //添加一个回答
  449. $id = $this->userlogic->add_answer ( $data );
  450. $question=$this->asklogic->get_question_by_qid($data ['qid']);
  451. $type="NEW_ANSWER";
  452. if($question['price']>0)
  453. $type="PAY_NEW_ANSWER";
  454. //发送邮件
  455. $this->userlogic->send_email($this->userinfo ['uid'],$type,$data ['qid'],$id);
  456. header ( 'Content-Type:text/html;charset=utf-8' );
  457. @header ( "Location: " . WEB_SITE . "/messager?content=回答成功&url=/askpage/" . $answer_data [0] );
  458. }
  459. /**
  460. * 追问一个回答
  461. */
  462. public function to_ask_question() {
  463. $id = $this->get_args ( 'id' );
  464. $id = explode ( ":", $id );
  465. $tag = stripcslashes ( $this->get_args ( 'tag' ) );
  466. if(!is_numeric($id [1])||!is_numeric($id[0]))
  467. $this->Messager ( "请输入正确的参数", "/askpage/". $id [1] );
  468. if(empty($tag))
  469. $this->Messager ( "请填写追问内容", "/askpage/". $id [1] );
  470. $data ['id'] = $id [0];
  471. $data ['tag'] = $tag;
  472. //添加一个回答
  473. $this->userlogic->to_ask_question ( $data );
  474. header ( 'Content-Type:text/html;charset=utf-8' );
  475. @header ( "Location: " . WEB_SITE . "/messager?content=追问成功&url=/askpage/" . $id [1] );
  476. }
  477. /**
  478. * 回答一个追问
  479. */
  480. public function answer_again() {
  481. $id = $this->get_args ( 'id' );
  482. $id = explode ( ":", $id );
  483. $tag = stripcslashes ( $this->get_args ( 'tag' ) );
  484. //回答ID
  485. $data ['id'] = $id [0];
  486. //再一次回答内容
  487. $data ['tag'] = $tag;
  488. //添加一个回答
  489. $this->userlogic->answer_again ( $data );
  490. header ( 'Content-Type:text/html;charset=utf-8' );
  491. @header ( "Location: " . WEB_SITE . "/messager?content=回答追问成功&url=/askpage/" . $id [1] );
  492. }
  493. /**
  494. * 更新一个用户的头像
  495. */
  496. public function do_update_avatar() {
  497. $data ['uid'] = $this->get_args ( 'uid' );
  498. $data ['avatar'] = $this->get_args ( 'avatar' );
  499. $this->userlogic->update_avatar ( $data );
  500. header ( 'Content-Type:text/html;charset=utf-8' );
  501. @header ( "Location: " . WEB_SITE . "/messager?content=头像修改成功&url=/home_avatar" );
  502. }
  503. /**
  504. * 更新一个用户信息
  505. */
  506. public function do_update_user_info() {
  507. $data ['uid'] = $this->get_args ( 'uid' );
  508. $data ['nickname'] = $this->get_args ( 'nickname' );
  509. $data ['phone'] = $this->get_args ( 'phone' );
  510. $data ['cids'] = json_encode($_POST['cids']);
  511. $this->userlogic->update_user_info ( $data );
  512. header ( 'Content-Type:text/html;charset=utf-8' );
  513. @header ( "Location: " . WEB_SITE . "/messager?content=用户信息修改成功&url=/home_per_info" );
  514. }
  515. /**
  516. * 名师答疑设置为满意
  517. */
  518. function set_vip_question_satisfy() {
  519. $id = $this->get_args ( 'id' );
  520. $id = is_numeric ( $id ) ? $id : 0;
  521. $vip_question = $this->asklogic->get_vip_question_by_quid ( $id, $this->userinfo ['uid'] );
  522. if (empty ( $vip_question ))
  523. $this->Messager ( "该问题未找到或该问题不属于你", "/advisory" );
  524. if ($vip_question ['status'] != PAID_FILL_IN)
  525. $this->Messager ( "不允许设置", "/advisory_page/" . $id );
  526. //设置满意
  527. $this->userlogic->set_vip_question_status ( $id, ANSWER_SATISFY );
  528. //设置退款
  529. if ($this->userinfo ['refunds'] != 1) {
  530. $params ['uid'] = $this->userinfo ['uid'];
  531. //退款机会为1
  532. $params ['refunds'] = 1;
  533. $this->userlogic->update_user_refunds ( $params );
  534. }
  535. //发送系统信息
  536. $subject = "名师答疑问题(" . $vip_question ['title'] . ")已经设置为满意";
  537. $content = "名师答疑&nbsp;<a href=/advisory_page/" . $vip_question ['id'] . ">" . $vip_question ['title'] . "</a>&nbsp;设置为满意";
  538. $this->userlogic->send_sys_message ( $subject, $content, $this->userinfo ['uid'] );
  539. header ( 'Content-Type:text/html;charset=utf-8' );
  540. @header ( "Location: " . WEB_SITE . "/messager?content=问题设置成功&url=/advisory_page/" . $id );
  541. }
  542. /**
  543. * 名师答疑添加一个追问--加入检索库已加入
  544. */
  545. function do_add_vip_tag() {
  546. $id = $this->get_args ( 'id' );
  547. $tag = stripcslashes ( $this->get_args ( 'to_ask_text' ) );
  548. $id = is_numeric ( $id ) ? $id : 0;
  549. if (empty ( $tag ))
  550. $this->Messager ( "请填写追问", "/advisory_page/" . $id );
  551. $vip_question = $this->asklogic->get_vip_question_by_quid ( $id, $this->userinfo ['uid'] );
  552. if (empty ( $vip_question ))
  553. $this->Messager ( "该问题未找到或该问题不属于你", "/advisory" );
  554. //添加追问
  555. $this->userlogic->do_add_vip_tag ( $id, $tag );
  556. //加入检索库
  557. $params ['vip_question'] = $vip_question;
  558. $answer = $this->asklogic->get_vip_answer_by_id ( $id );
  559. $ans ['aid'] = $answer ['id'];
  560. $ans ['time'] = $answer ['time'];
  561. $ans ['content'] = $answer ['content'];
  562. $ans ['comment'] = $answer ['comment'];
  563. $tag = serialize ( array (0 => $tag, 1 => get_date () ) );
  564. $ans ['tag'] = $tag;
  565. $answer = serialize ( array (0 => $ans ) );
  566. $params ['answer'] = $answer;
  567. $this->userlogic->update_vip_question_search ( $params );
  568. //设置满意
  569. $this->userlogic->set_vip_question_status ( $id, ANSWER_SATISFY );
  570. //设置退款
  571. if ($this->userinfo ['refunds'] != 1) {
  572. $params ['uid'] = $this->userinfo ['uid'];
  573. //退款机会为1
  574. $params ['refunds'] = 1;
  575. $this->userlogic->update_user_refunds ( $params );
  576. }
  577. //发送系统信息
  578. $subject = "您的名师答疑问题(" . $vip_question ['title'] . ")的追问";
  579. $content = "名师答疑&nbsp;<a href=/advisory_page/" . $vip_question ['id'] . ">" . $vip_question ['title'] . "</a>&nbsp追问成功,问题已经设置为满意";
  580. $this->userlogic->send_sys_message ( $subject, $content, $this->userinfo ['uid'] );
  581. header ( 'Content-Type:text/html;charset=utf-8' );
  582. @header ( "Location: " . WEB_SITE . "/messager?content=追问后,该提问自动设为‘满意’&url=/advisory_page/" . $id );
  583. }
  584. /**
  585. * 名师答疑设置为不满意
  586. */
  587. function set_vip_question_nosatisfy() {
  588. $id = $this->get_args ( 'id' );
  589. $id = is_numeric ( $id ) ? $id : 0;
  590. $refunds_description = $this->get_args ( 'refunds_description' );
  591. $vip_question = $this->asklogic->get_vip_question_by_quid ( $id, $this->userinfo ['uid'] );
  592. if (empty ( $vip_question ))
  593. $this->Messager ( "该问题未找到或该问题不属于你", "/advisory" );
  594. if ($vip_question ['status'] != PAID_FILL_IN || $this->userinfo ['refunds'] != 1)
  595. $this->Messager ( "不允许设置", "/advisory_page/" . $id );
  596. $content = "名师答疑&nbsp;<a href=/advisory_page/" . $vip_question ['id'] . " >" . $vip_question ['title'] . "</a>设置为不满意";
  597. $message = "问题设置成功";
  598. //设置退款
  599. if ($this->userinfo ['refunds'] == 1) {
  600. //设置不满意
  601. $this->userlogic->set_vip_question_status ( $id, ANSWER_NO_SATISFY, $refunds_description );
  602. //退款<span class="colRed">不满意,退款¥200元</span>
  603. $this->userlogic->set_credit3 ( + $vip_question ['price'], $this->userinfo ['uid'], RICH_ACTION_REFUNDS, SSO_UID );
  604. //退款流向记录
  605. $this->userlogic->set_credit3_refunds_log ( $vip_question );
  606. //发送邮件
  607. $this->userlogic->send_email($vip_question['authorid'],"VIP_MONEY_BACK",$id,0);
  608. $params ['uid'] = $this->userinfo ['uid'];
  609. $params ['refunds'] = 0;
  610. //退款机会为0
  611. $this->userlogic->update_user_refunds ( $params );
  612. $content = "名师答疑&nbsp;<a href=/advisory_page/" . $vip_question ['id'] . " >" . $vip_question ['title'] . "</a>设置为不满意,<span class=colRed>退款金额为" . $vip_question ['price'] . "</span>";
  613. $message = "退款成功";
  614. }
  615. //发送系统信息
  616. $subject = "您的名师答疑问题(" . $vip_question ['title'] . ")已经答案为不满意";
  617. $this->userlogic->send_sys_message ( $subject, $content, $this->userinfo ['uid'] );
  618. header ( 'Content-Type:text/html;charset=utf-8' );
  619. @header ( "Location: " . WEB_SITE . "/messager?content=" . $message . "&url=/advisory_page/" . $id );
  620. }
  621. /**
  622. * 添加讨论
  623. */
  624. function do_add_discuss() {
  625. $qid = $this->get_args ( 'qid' );
  626. $qid = is_numeric ( $qid ) ? $qid : 0;
  627. $cid = $this->get_args ( 'topid' );
  628. $cid = is_numeric ( $cid ) ? $cid : 0;
  629. $content = $this->get_args ( 'discuss_content' );
  630. if ($this->userinfo ['groupid'] == USER_VIP || $this->userinfo ['groupid'] == SUPER_ADMIN_ID || $this->userinfo ['groupid'] == ADMIN_ID)
  631. $vip_question = $this->asklogic->get_vip_questions_by_id ( $qid );
  632. else
  633. $vip_question = $this->asklogic->get_vip_question_by_quid ( $qid, $this->userinfo ['uid'] );
  634. if (empty ( $vip_question ))
  635. $this->Messager ( "该问题不存在", "/advisory_page/" . $qid . "#dis" );
  636. if (empty ( $content ))
  637. $this->Messager ( "请填写内容", "/advisory_page/" . $qid . "#dis" );
  638. $this->userlogic->add_discuss ( $qid, $this->userinfo ['uid'], $content, $cid );
  639. if ($cid > 0) {
  640. $this->userlogic->update_discuss ( $cid );
  641. }
  642. header ( 'Content-Type:text/html;charset=utf-8' );
  643. @header ( "Location: " . WEB_SITE . "/messager?content=添加讨论成功&url=/advisory_page/" . $qid . "#dis" );
  644. }
  645. /**
  646. * 添加邮件发送配置
  647. */
  648. function do_add_email_config() {
  649. $data['normal_question_mail'] = $this->get_args ( 'normal_question_mail' );
  650. $data['pay_question_mail'] = $this->get_args ( 'pay_question_mail' );
  651. $data['vip_question_mail'] = $this->get_args ( 'vip_question_mail' );
  652. $this->userlogic->add_email_config($data,$this->userinfo['uid']);
  653. header ( 'Content-Type:text/html;charset=utf-8' );
  654. @header ( "Location: " . WEB_SITE . "/home_per_info" );
  655. }
  656. /**
  657. * 获取get或者POST值
  658. * @param string $name 属性名称
  659. * @return fixed 值
  660. */
  661. function get_args($name) {
  662. if (isset ( $_GET [$name] )) {
  663. if (is_array ( $_GET [$name] ))
  664. return $_GET [$name];
  665. else
  666. return addslashes ( $_GET [$name] );
  667. } elseif (isset ( $_POST [$name] )) {
  668. if (is_array ( $_POST [$name] ))
  669. return $_POST [$name];
  670. else
  671. return addslashes ( $_POST [$name] );
  672. } else {
  673. return false;
  674. }
  675. }
  676. /**
  677. * 检测数据输入的非法字符和转义非法字符
  678. */
  679. function check_params($name = "") {
  680. if (isset ( $this->params [$name] )) {
  681. return addslashes ( $this->params [$name] );
  682. } else {
  683. return false;
  684. }
  685. }
  686. /**
  687. * 限时跳转
  688. * @param unknown_type $message
  689. * @param unknown_type $redirectto
  690. * @param unknown_type $time
  691. * @param unknown_type $return_msg
  692. * @param unknown_type $js
  693. */
  694. function Messager($message, $redirectto = '', $time = -1, $return_msg = false, $js = null) {
  695. global $rewriteHandler;
  696. $data ['redirectto'] = $redirectto;
  697. $data ['message'] = $message;
  698. if ($time === - 1) {
  699. //配置文件
  700. //$time=(is_numeric($this->Config['msg_time'])?$this->Config['msg_time']:5);
  701. $data ['time'] = 2;
  702. }
  703. $data ['to_title'] = ($data ['redirectto'] === '' or $data ['redirectto'] == - 1) ? "返回上一页" : "跳转到指定页面";
  704. if ($data ['redirectto'] === null) {
  705. $return_msg = $return_msg === false ? "&nbsp;" : $return_msg;
  706. } else {
  707. $data ['redirectto'] = ($data ['redirectto'] !== '') ? $data ['redirectto'] : ($from_referer = referer ());
  708. // if(str_exists($data['redirectto'],'mod=login','code=register','/login','/register'))
  709. // {
  710. // $referer='&referer='.urlencode('index.php?'.$_SERVER['QUERY_STRING']);
  711. // $this->CookieHandler->Setvar('referer','index.php?'.$_SERVER['QUERY_STRING']);
  712. // }
  713. if (is_numeric ( $data ['redirectto'] ) !== false and $data ['redirectto'] !== 0) {
  714. if ($data ['time'] !== null) {
  715. $data ['url_redirect'] = "<script language=\"JavaScript\" type=\"text/javascript\">\r\n";
  716. $data ['url_redirect'] .= sprintf ( "window.setTimeout(\"history.go(%s)\",%s);\r\n", $data ['redirectto'], $data ['time'] * 1000 );
  717. $data ['url_redirect'] .= "</script>\r\n";
  718. }
  719. $data ['redirectto'] = "javascript:history.go({$data['redirectto']})";
  720. } else {
  721. if ($rewriteHandler && null !== $data ['message']) {
  722. $data ['redirectto'] .= $referer;
  723. if (! $from_referer && ! $referer) {
  724. $data ['redirectto'] = $rewriteHandler->formatURL ( $data ['redirectto'], true );
  725. }
  726. }
  727. if ($data ['message'] === null) {
  728. $data ['redirectto'] = rawurldecode ( stripslashes ( ($data ['redirectto']) ) );
  729. @header ( "Location: " . $data ['redirectto'] ); #HEADER跳转
  730. }
  731. if ($data ['time'] !== null) {
  732. $data ['url_redirect'] = ($data ['redirectto'] ? '<meta http-equiv="refresh" content="' . $data ['time'] . '; URL=' . $data ['redirectto'] . '">' : null);
  733. }
  734. }
  735. }
  736. $title = "消息提示:" . (is_array ( $data ['message'] ) ? implode ( ',', $data ['message'] ) : $data ['message']);
  737. $title = strip_tags ( $title );
  738. if ($js != "") {
  739. $js = "<script language=\"JavaScript\" type=\"text/javascript\">{$js}</script>";
  740. }
  741. $additional_str = $data ['url_redirect'] . $js;
  742. $this->render ( 'messager', $data );
  743. exit ();
  744. }
  745. }
  746. ?>