UserController.php 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069
  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. $description = stripcslashes ( $this->get_args ( 'description' ) );
  300. if (empty ( $title ) || empty ( $description ))
  301. $this->Messager ( "请填写相关信息", "/question/add_vip" );
  302. $phone = $this->get_args ( 'phone' );
  303. $qq = $this->get_args ( 'qq' );
  304. $this->userlogic->update_vip_question ( $rs ['id'], $title, $description, $this->userinfo ['uid'], $phone, $qq );
  305. header ( 'Content-Type:text/html;charset=utf-8' );
  306. @header ( "Location: " . WEB_SITE . "/messager?content=问题发起成功&url=/advisory_page/" . $rs ['id'] );
  307. }
  308. /**
  309. * 发起名师答疑1
  310. */
  311. public function do_add_vip_question() {
  312. require_once SITE_PATH . '/protected/config/auth_issue.conf.php';
  313. $auth = $auth ['GENERAL_USER_GROUP' . $this->userinfo ['groupid']];
  314. $issue = $this->asklogic->auth_question_issue ( $this->userinfo ['uid'], $this->userinfo ['groupid'], $auth );
  315. if ($issue == 2)
  316. $this->Messager ( "您今天提问条数(" . $auth ['DAY_TOTALS'] . ")已用完", "/" );
  317. elseif ($issue == 3)
  318. $this->Messager ( "每" . $auth ['TIME_INTERVAL']/60 . "分钟内只可以发布" . $auth ['TIME_TOTALS'] . "条", "/" );
  319. $price = $this->get_args ( 'price' );
  320. $price = is_numeric ( $price ) ? $price : 0;
  321. //已付款未填写
  322. $rs = $this->asklogic->get_vip_question_by_paid ( $this->userinfo ['uid'] );
  323. $data ['mod'] = 'askpost';
  324. $data ['price'] = $price;
  325. $data ['qq'] = $this->userinfo ['qq'];
  326. $data ['phone'] = $this->userinfo ['phone'];
  327. if (! empty ( $rs )) { //防止重复提交
  328. $data ['qid'] = $rs ['id'];
  329. $data ['message'] = "您上一次付款后没有发布问题,故本次提问不做重复扣费";
  330. $this->render ( 'askPost_pay_2', $data );
  331. die ();
  332. }
  333. if ($price <= 0)
  334. $this->Messager ( "金额不足,请充值", "/question/add_vip" );
  335. if ($price > $this->userinfo ['credit3'])
  336. $this->Messager ( "金额不足,请充值", "/question/add_vip" );
  337. if (($this->userinfo ['credit3'] - $price) < 0)
  338. $this->Messager ( "金额不足,请充值", "/question/add_vip" );
  339. if (! ($price == 500 || $price == 200 || $price == 100))
  340. $this->Messager ( "金额只能为500元,200元,100元", "/question/add_vip" );
  341. //确认付费
  342. $data ['author'] = $this->userinfo ['username'];
  343. $data ['authorid'] = $this->userinfo ['uid'];
  344. $id = $this->userlogic->add_vip_question ( $data );
  345. if ($id == 0)
  346. $this->Messager ( "操作失败-请重新操作", "/question/postenter" );
  347. $data ['qid'] = $id;
  348. $this->render ( 'askPost_pay_2', $data );
  349. }
  350. /**
  351. * 添加一条问题
  352. */
  353. public function do_add_question() {
  354. $start=strtotime(date("Y-m-d")." 23:00:00");
  355. $end=strtotime(date("Y-m-d")." 23:59:59");
  356. $one=strtotime(date("Y-m-d")." 00:00:00");
  357. $two=strtotime(date("Y-m-d")." 8:00:00");
  358. //$end=strtotime(date("Y-m-d",strtotime("+1 day"))." 8:00:00");
  359. if ($one<=time()&&$two>=time()){
  360. $this->render ( 'askPost_close' );
  361. die;
  362. }
  363. if ($start<=time()&&$end>=time()){
  364. $this->render ( 'askPost_close' );
  365. die;
  366. }
  367. session_start();
  368. require_once ('./protected/plugin/class.geetestlib.php');
  369. $GtSdk = new GeetestLib();
  370. if ($_SESSION['gtserver'] == 1) {
  371. $result = $GtSdk->validate($_POST['geetest_challenge'], $_POST['geetest_validate'], $_POST['geetest_seccode']);
  372. if ($result == TRUE) {
  373. //echo 'Yes!';
  374. } else if ($result == FALSE) {
  375. $this->Messager("请检查验证是否正确", "/question/add");
  376. } else {
  377. $this->Messager("请检查验证是否正确", "/question/add");
  378. }
  379. }else{
  380. if ($GtSdk->get_answer($_POST['geetest_validate'])) {
  381. //echo "yes";
  382. }else{
  383. $this->Messager("请检查验证是否正确", "/question/add");
  384. }
  385. }
  386. // die;
  387. // if(!isset($_POST['vc']) || ($_SESSION['vc']!=$_POST['vc'])){
  388. // $this->Messager("请检查验证是否正确", "/question/add");
  389. // }
  390. //检测问题数
  391. require_once SITE_PATH . '/protected/config/auth_issue.conf.php';
  392. $auth = $auth ['GENERAL_USER_GROUP' . $this->userinfo ['groupid']];
  393. $issue = $this->asklogic->auth_question_issue ( $this->userinfo ['uid'], $this->userinfo ['groupid'], $auth );
  394. if ($issue == 2)
  395. $this->Messager ( "您今天提问条数(" . $auth ['DAY_TOTALS'] . ")已用完", "/" );
  396. elseif ($issue == 3)
  397. $this->Messager ( "每" . $auth ['TIME_INTERVAL']/60 . "分钟内只可以发布" . $auth ['TIME_TOTALS'] . "条", "/" );
  398. $data ['title'] = $this->get_args ( 'title' );
  399. $data ['category_id'] = $this->get_args ( 'category_id' );
  400. $data ['description'] = stripcslashes ( $this->get_args ( 'description' ) );
  401. $data ['price'] = $this->get_args ( 'price' );
  402. if ($data ['price'] !== false) {
  403. $data ['price'] = is_numeric ( $data ['price'] ) ? $data ['price'] : 0;
  404. if ($this->userinfo ['credit3'] < $data ['price'])
  405. $this->Messager ( "财富值不足,请充值", "/question/add" );
  406. } else {
  407. $data ['price'] = 0;
  408. }
  409. $data ['authorid'] = $this->userinfo ['uid'];
  410. $data ['author'] = $this->userinfo ['username'];
  411. //|| empty ( $data ['description'] )
  412. if (empty ( $data ['title'] ) || (! is_numeric ( $data ['category_id'] )))
  413. $this->Messager ( "问题发起不成功,请重新填写", "/question/add" );
  414. $id = $this->userlogic->add_question ( $data );
  415. $_SESSION['vc']='NULL';
  416. if ($id) {
  417. header ( 'Content-Type:text/html;charset=utf-8' );
  418. @header ( "Location: " . WEB_SITE . "/messager?content=问题发起成功&url=/askpage/" . $id );
  419. } else {
  420. header ( 'Content-Type:text/html;charset=utf-8' );
  421. @header ( "Location: " . WEB_SITE . "/messager?content=问题发起不成功,请重新填写&url=/question/add" );
  422. }
  423. }
  424. /**
  425. * 回答一个问题--添加积分,财富
  426. */
  427. public function do_reply_question() {
  428. //include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  429. $answer_data = $this->get_args ( 'answer_data' );
  430. $content = stripcslashes ( $this->get_args ( 'content' ) );
  431. if (empty ( $content ))
  432. return false;
  433. $answer_data = explode ( ":", $answer_data );
  434. $data ['qid'] = $answer_data [0];
  435. $data ['title'] = $answer_data [1];
  436. $data ['author'] = $this->userinfo ['username'];
  437. $data ['authorid'] = $this->userinfo ['uid'];
  438. $data ['content'] = $content;
  439. if (! is_numeric ( $data ['qid'] ) || ! is_numeric ( $data ['authorid'] ))
  440. return false;
  441. $answer=$this->asklogic->get_answer_by_quid($data ['qid'],$this->userinfo ['uid']);
  442. if(!empty($answer))
  443. return false;
  444. //添加一个回答
  445. $id = $this->userlogic->add_answer ( $data );
  446. $question=$this->asklogic->get_question_by_qid($data ['qid']);
  447. $type="NEW_ANSWER";
  448. if($question['price']>0)
  449. $type="PAY_NEW_ANSWER";
  450. //发送邮件
  451. $this->userlogic->send_email($this->userinfo ['uid'],$type,$data ['qid'],$id);
  452. header ( 'Content-Type:text/html;charset=utf-8' );
  453. @header ( "Location: " . WEB_SITE . "/messager?content=回答成功&url=/askpage/" . $answer_data [0] );
  454. }
  455. /**
  456. * 追问一个回答
  457. */
  458. public function to_ask_question() {
  459. $id = $this->get_args ( 'id' );
  460. $id = explode ( ":", $id );
  461. $tag = stripcslashes ( $this->get_args ( 'tag' ) );
  462. if(!is_numeric($id [1])||!is_numeric($id[0]))
  463. $this->Messager ( "请输入正确的参数", "/askpage/". $id [1] );
  464. if(empty($tag))
  465. $this->Messager ( "请填写追问内容", "/askpage/". $id [1] );
  466. $data ['id'] = $id [0];
  467. $data ['tag'] = $tag;
  468. //添加一个回答
  469. $this->userlogic->to_ask_question ( $data );
  470. header ( 'Content-Type:text/html;charset=utf-8' );
  471. @header ( "Location: " . WEB_SITE . "/messager?content=追问成功&url=/askpage/" . $id [1] );
  472. }
  473. /**
  474. * 回答一个追问
  475. */
  476. public function answer_again() {
  477. $id = $this->get_args ( 'id' );
  478. $id = explode ( ":", $id );
  479. $tag = stripcslashes ( $this->get_args ( 'tag' ) );
  480. //回答ID
  481. $data ['id'] = $id [0];
  482. //再一次回答内容
  483. $data ['tag'] = $tag;
  484. //添加一个回答
  485. $this->userlogic->answer_again ( $data );
  486. header ( 'Content-Type:text/html;charset=utf-8' );
  487. @header ( "Location: " . WEB_SITE . "/messager?content=回答追问成功&url=/askpage/" . $id [1] );
  488. }
  489. /**
  490. * 更新一个用户的头像
  491. */
  492. public function do_update_avatar() {
  493. $data ['uid'] = $this->get_args ( 'uid' );
  494. $data ['avatar'] = $this->get_args ( 'avatar' );
  495. $this->userlogic->update_avatar ( $data );
  496. header ( 'Content-Type:text/html;charset=utf-8' );
  497. @header ( "Location: " . WEB_SITE . "/messager?content=头像修改成功&url=/home_avatar" );
  498. }
  499. /**
  500. * 更新一个用户信息
  501. */
  502. public function do_update_user_info() {
  503. $data ['uid'] = $this->get_args ( 'uid' );
  504. $data ['nickname'] = $this->get_args ( 'nickname' );
  505. $data ['phone'] = $this->get_args ( 'phone' );
  506. $data ['cids'] = json_encode($_POST['cids']);
  507. $this->userlogic->update_user_info ( $data );
  508. header ( 'Content-Type:text/html;charset=utf-8' );
  509. @header ( "Location: " . WEB_SITE . "/messager?content=用户信息修改成功&url=/home_per_info" );
  510. }
  511. /**
  512. * 名师答疑设置为满意
  513. */
  514. function set_vip_question_satisfy() {
  515. $id = $this->get_args ( 'id' );
  516. $id = is_numeric ( $id ) ? $id : 0;
  517. $vip_question = $this->asklogic->get_vip_question_by_quid ( $id, $this->userinfo ['uid'] );
  518. if (empty ( $vip_question ))
  519. $this->Messager ( "该问题未找到或该问题不属于你", "/advisory" );
  520. if ($vip_question ['status'] != PAID_FILL_IN)
  521. $this->Messager ( "不允许设置", "/advisory_page/" . $id );
  522. //设置满意
  523. $this->userlogic->set_vip_question_status ( $id, ANSWER_SATISFY );
  524. //设置退款
  525. if ($this->userinfo ['refunds'] != 1) {
  526. $params ['uid'] = $this->userinfo ['uid'];
  527. //退款机会为1
  528. $params ['refunds'] = 1;
  529. $this->userlogic->update_user_refunds ( $params );
  530. }
  531. //发送系统信息
  532. $subject = "名师答疑问题(" . $vip_question ['title'] . ")已经设置为满意";
  533. $content = "名师答疑&nbsp;<a href=/advisory_page/" . $vip_question ['id'] . ">" . $vip_question ['title'] . "</a>&nbsp;设置为满意";
  534. $this->userlogic->send_sys_message ( $subject, $content, $this->userinfo ['uid'] );
  535. header ( 'Content-Type:text/html;charset=utf-8' );
  536. @header ( "Location: " . WEB_SITE . "/messager?content=问题设置成功&url=/advisory_page/" . $id );
  537. }
  538. /**
  539. * 名师答疑添加一个追问--加入检索库已加入
  540. */
  541. function do_add_vip_tag() {
  542. $id = $this->get_args ( 'id' );
  543. $tag = stripcslashes ( $this->get_args ( 'to_ask_text' ) );
  544. $id = is_numeric ( $id ) ? $id : 0;
  545. if (empty ( $tag ))
  546. $this->Messager ( "请填写追问", "/advisory_page/" . $id );
  547. $vip_question = $this->asklogic->get_vip_question_by_quid ( $id, $this->userinfo ['uid'] );
  548. if (empty ( $vip_question ))
  549. $this->Messager ( "该问题未找到或该问题不属于你", "/advisory" );
  550. //添加追问
  551. $this->userlogic->do_add_vip_tag ( $id, $tag );
  552. //加入检索库
  553. $params ['vip_question'] = $vip_question;
  554. $answer = $this->asklogic->get_vip_answer_by_id ( $id );
  555. $ans ['aid'] = $answer ['id'];
  556. $ans ['time'] = $answer ['time'];
  557. $ans ['content'] = $answer ['content'];
  558. $ans ['comment'] = $answer ['comment'];
  559. $tag = serialize ( array (0 => $tag, 1 => get_date () ) );
  560. $ans ['tag'] = $tag;
  561. $answer = serialize ( array (0 => $ans ) );
  562. $params ['answer'] = $answer;
  563. $this->userlogic->update_vip_question_search ( $params );
  564. //设置满意
  565. $this->userlogic->set_vip_question_status ( $id, ANSWER_SATISFY );
  566. //设置退款
  567. if ($this->userinfo ['refunds'] != 1) {
  568. $params ['uid'] = $this->userinfo ['uid'];
  569. //退款机会为1
  570. $params ['refunds'] = 1;
  571. $this->userlogic->update_user_refunds ( $params );
  572. }
  573. //发送系统信息
  574. $subject = "您的名师答疑问题(" . $vip_question ['title'] . ")的追问";
  575. $content = "名师答疑&nbsp;<a href=/advisory_page/" . $vip_question ['id'] . ">" . $vip_question ['title'] . "</a>&nbsp追问成功,问题已经设置为满意";
  576. $this->userlogic->send_sys_message ( $subject, $content, $this->userinfo ['uid'] );
  577. header ( 'Content-Type:text/html;charset=utf-8' );
  578. @header ( "Location: " . WEB_SITE . "/messager?content=追问后,该提问自动设为‘满意’&url=/advisory_page/" . $id );
  579. }
  580. /**
  581. * 名师答疑设置为不满意
  582. */
  583. function set_vip_question_nosatisfy() {
  584. $id = $this->get_args ( 'id' );
  585. $id = is_numeric ( $id ) ? $id : 0;
  586. $refunds_description = $this->get_args ( 'refunds_description' );
  587. $vip_question = $this->asklogic->get_vip_question_by_quid ( $id, $this->userinfo ['uid'] );
  588. if (empty ( $vip_question ))
  589. $this->Messager ( "该问题未找到或该问题不属于你", "/advisory" );
  590. if ($vip_question ['status'] != PAID_FILL_IN || $this->userinfo ['refunds'] != 1)
  591. $this->Messager ( "不允许设置", "/advisory_page/" . $id );
  592. $content = "名师答疑&nbsp;<a href=/advisory_page/" . $vip_question ['id'] . " >" . $vip_question ['title'] . "</a>设置为不满意";
  593. $message = "问题设置成功";
  594. //设置退款
  595. if ($this->userinfo ['refunds'] == 1) {
  596. //设置不满意
  597. $this->userlogic->set_vip_question_status ( $id, ANSWER_NO_SATISFY, $refunds_description );
  598. //退款<span class="colRed">不满意,退款¥200元</span>
  599. $this->userlogic->set_credit3 ( + $vip_question ['price'], $this->userinfo ['uid'], RICH_ACTION_REFUNDS, SSO_UID );
  600. //退款流向记录
  601. $this->userlogic->set_credit3_refunds_log ( $vip_question );
  602. //发送邮件
  603. $this->userlogic->send_email($vip_question['authorid'],"VIP_MONEY_BACK",$id,0);
  604. $params ['uid'] = $this->userinfo ['uid'];
  605. $params ['refunds'] = 0;
  606. //退款机会为0
  607. $this->userlogic->update_user_refunds ( $params );
  608. $content = "名师答疑&nbsp;<a href=/advisory_page/" . $vip_question ['id'] . " >" . $vip_question ['title'] . "</a>设置为不满意,<span class=colRed>退款金额为" . $vip_question ['price'] . "</span>";
  609. $message = "退款成功";
  610. }
  611. //发送系统信息
  612. $subject = "您的名师答疑问题(" . $vip_question ['title'] . ")已经答案为不满意";
  613. $this->userlogic->send_sys_message ( $subject, $content, $this->userinfo ['uid'] );
  614. header ( 'Content-Type:text/html;charset=utf-8' );
  615. @header ( "Location: " . WEB_SITE . "/messager?content=" . $message . "&url=/advisory_page/" . $id );
  616. }
  617. /**
  618. * 添加讨论
  619. */
  620. function do_add_discuss() {
  621. $qid = $this->get_args ( 'qid' );
  622. $qid = is_numeric ( $qid ) ? $qid : 0;
  623. $cid = $this->get_args ( 'topid' );
  624. $cid = is_numeric ( $cid ) ? $cid : 0;
  625. $content = $this->get_args ( 'discuss_content' );
  626. if ($this->userinfo ['groupid'] == USER_VIP || $this->userinfo ['groupid'] == SUPER_ADMIN_ID || $this->userinfo ['groupid'] == ADMIN_ID)
  627. $vip_question = $this->asklogic->get_vip_questions_by_id ( $qid );
  628. else
  629. $vip_question = $this->asklogic->get_vip_question_by_quid ( $qid, $this->userinfo ['uid'] );
  630. if (empty ( $vip_question ))
  631. $this->Messager ( "该问题不存在", "/advisory_page/" . $qid . "#dis" );
  632. if (empty ( $content ))
  633. $this->Messager ( "请填写内容", "/advisory_page/" . $qid . "#dis" );
  634. $this->userlogic->add_discuss ( $qid, $this->userinfo ['uid'], $content, $cid );
  635. if ($cid > 0) {
  636. $this->userlogic->update_discuss ( $cid );
  637. }
  638. header ( 'Content-Type:text/html;charset=utf-8' );
  639. @header ( "Location: " . WEB_SITE . "/messager?content=添加讨论成功&url=/advisory_page/" . $qid . "#dis" );
  640. }
  641. /**
  642. * 添加邮件发送配置
  643. */
  644. function do_add_email_config() {
  645. $data['normal_question_mail'] = $this->get_args ( 'normal_question_mail' );
  646. $data['pay_question_mail'] = $this->get_args ( 'pay_question_mail' );
  647. $data['vip_question_mail'] = $this->get_args ( 'vip_question_mail' );
  648. $this->userlogic->add_email_config($data,$this->userinfo['uid']);
  649. header ( 'Content-Type:text/html;charset=utf-8' );
  650. @header ( "Location: " . WEB_SITE . "/home_per_info" );
  651. }
  652. /**
  653. * 获取get或者POST值
  654. * @param string $name 属性名称
  655. * @return fixed 值
  656. */
  657. function get_args($name) {
  658. if (isset ( $_GET [$name] )) {
  659. if (is_array ( $_GET [$name] ))
  660. return $_GET [$name];
  661. else
  662. return addslashes ( $_GET [$name] );
  663. } elseif (isset ( $_POST [$name] )) {
  664. if (is_array ( $_POST [$name] ))
  665. return $_POST [$name];
  666. else
  667. return addslashes ( $_POST [$name] );
  668. } else {
  669. return false;
  670. }
  671. }
  672. /**
  673. * 检测数据输入的非法字符和转义非法字符
  674. */
  675. function check_params($name = "") {
  676. if (isset ( $this->params [$name] )) {
  677. return addslashes ( $this->params [$name] );
  678. } else {
  679. return false;
  680. }
  681. }
  682. /**
  683. * 限时跳转
  684. * @param unknown_type $message
  685. * @param unknown_type $redirectto
  686. * @param unknown_type $time
  687. * @param unknown_type $return_msg
  688. * @param unknown_type $js
  689. */
  690. function Messager($message, $redirectto = '', $time = -1, $return_msg = false, $js = null) {
  691. global $rewriteHandler;
  692. $data ['redirectto'] = $redirectto;
  693. $data ['message'] = $message;
  694. if ($time === - 1) {
  695. //配置文件
  696. //$time=(is_numeric($this->Config['msg_time'])?$this->Config['msg_time']:5);
  697. $data ['time'] = 2;
  698. }
  699. $data ['to_title'] = ($data ['redirectto'] === '' or $data ['redirectto'] == - 1) ? "返回上一页" : "跳转到指定页面";
  700. if ($data ['redirectto'] === null) {
  701. $return_msg = $return_msg === false ? "&nbsp;" : $return_msg;
  702. } else {
  703. $data ['redirectto'] = ($data ['redirectto'] !== '') ? $data ['redirectto'] : ($from_referer = referer ());
  704. // if(str_exists($data['redirectto'],'mod=login','code=register','/login','/register'))
  705. // {
  706. // $referer='&referer='.urlencode('index.php?'.$_SERVER['QUERY_STRING']);
  707. // $this->CookieHandler->Setvar('referer','index.php?'.$_SERVER['QUERY_STRING']);
  708. // }
  709. if (is_numeric ( $data ['redirectto'] ) !== false and $data ['redirectto'] !== 0) {
  710. if ($data ['time'] !== null) {
  711. $data ['url_redirect'] = "<script language=\"JavaScript\" type=\"text/javascript\">\r\n";
  712. $data ['url_redirect'] .= sprintf ( "window.setTimeout(\"history.go(%s)\",%s);\r\n", $data ['redirectto'], $data ['time'] * 1000 );
  713. $data ['url_redirect'] .= "</script>\r\n";
  714. }
  715. $data ['redirectto'] = "javascript:history.go({$data['redirectto']})";
  716. } else {
  717. if ($rewriteHandler && null !== $data ['message']) {
  718. $data ['redirectto'] .= $referer;
  719. if (! $from_referer && ! $referer) {
  720. $data ['redirectto'] = $rewriteHandler->formatURL ( $data ['redirectto'], true );
  721. }
  722. }
  723. if ($data ['message'] === null) {
  724. $data ['redirectto'] = rawurldecode ( stripslashes ( ($data ['redirectto']) ) );
  725. @header ( "Location: " . $data ['redirectto'] ); #HEADER跳转
  726. }
  727. if ($data ['time'] !== null) {
  728. $data ['url_redirect'] = ($data ['redirectto'] ? '<meta http-equiv="refresh" content="' . $data ['time'] . '; URL=' . $data ['redirectto'] . '">' : null);
  729. }
  730. }
  731. }
  732. $title = "消息提示:" . (is_array ( $data ['message'] ) ? implode ( ',', $data ['message'] ) : $data ['message']);
  733. $title = strip_tags ( $title );
  734. if ($js != "") {
  735. $js = "<script language=\"JavaScript\" type=\"text/javascript\">{$js}</script>";
  736. }
  737. $additional_str = $data ['url_redirect'] . $js;
  738. $this->render ( 'messager', $data );
  739. exit ();
  740. }
  741. }
  742. ?>