AskLogic.php 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301
  1. <?php
  2. /**
  3. * 问答显示逻辑
  4. * @author cp
  5. */
  6. class AskLogic extends BaseLogic {
  7. private $categorydao;
  8. private $questiondao;
  9. private $creditdao;
  10. private $answerdao;
  11. private $messagedao;
  12. private $authissuedao;
  13. private $vipquestiondao;
  14. private $vipanswerdao;
  15. private $userdao;
  16. private $credit3logdao;
  17. private $funddao;
  18. function __construct() {
  19. Doo::loadModel ( 'CategoryDao' );
  20. Doo::loadModel ( 'QuestionDao' );
  21. Doo::loadModel ( 'CreditDao' );
  22. Doo::loadModel ( 'AnswerDao' );
  23. Doo::loadModel ( 'MessageDao' );
  24. Doo::loadModel ( 'AuthissueDao' );
  25. Doo::loadModel ( 'VipquestionDao' );
  26. Doo::loadModel ( 'VipanswerDao' );
  27. Doo::loadModel ( 'UserDao' );
  28. Doo::loadModel ( 'Credit3logDao' );
  29. Doo::loadModel ( 'FundDao' );
  30. $this->funddao = new FundDao ();
  31. $this->messagedao = new MessageDao ();
  32. $this->categorydao = new CategoryDao ();
  33. $this->questiondao = new QuestionDao ();
  34. $this->creditdao = new CreditDao ();
  35. $this->answerdao = new AnswerDao ();
  36. $this->authissuedao = new AuthissueDao ();
  37. $this->vipquestiondao = new VipquestionDao ();
  38. $this->vipanswerdao = new VipanswerDao ();
  39. $this->userdao = new UserDao ();
  40. $this->credit3logdao = new Credit3logDao ();
  41. }
  42. /**
  43. * 获取今日发布数
  44. */
  45. function get_today_question($condition = "") {
  46. $result = $this->questiondao->get_today_question ( $condition );
  47. if ($result ['times'] > 20)
  48. $result ['times'] = 20;
  49. return $result ['times'];
  50. }
  51. /**
  52. * 获取基金金额数
  53. */
  54. function get_fund() {
  55. $result = $this->funddao->get_fund ();
  56. if (empty ( $result ['allmoney'] ))
  57. $result ['allmoney'] = 0;
  58. return $result;
  59. }
  60. /**
  61. * 获取已付款,为填写
  62. * @param unknown_type $uid
  63. */
  64. function get_vip_question_by_paid($uid = 0) {
  65. $rs = $this->vipquestiondao->get_vip_question_by_paid ( $uid );
  66. return $rs;
  67. }
  68. /**
  69. *
  70. * 认证问题发布
  71. * @param unknown_type $uid
  72. * @return int 1:可以发布 ; 2:今天发布数**条已用完 ; 3:在*小时内只可以发布*条
  73. */
  74. function auth_question_issue($uid = 0, $groupid = 7, $auth = array()) {
  75. $rs = $this->authissuedao->get_auth_issue ( $uid );
  76. //获取今天结束时间
  77. $day = get_today ();
  78. //获取几个小时后的时间
  79. $time = get_seconds ( $auth ['TIME_INTERVAL'] );
  80. $nowtime = time ();
  81. $opt ['where'] = " uid=" . $uid . " ";
  82. //当天未记录
  83. if (empty ( $rs )) {
  84. $this->authissuedao->uid = $uid;
  85. $this->authissuedao->day_time = $day ['end'];
  86. $this->authissuedao->time_interval = $time;
  87. $this->db ()->insert ( $this->authissuedao );
  88. return 1;
  89. } else {
  90. //判断今天发布总数
  91. if ($rs ['day_time'] > $nowtime) {
  92. //今天发布总算在容许范围内
  93. if ($rs ['day_totals'] < $auth ['DAY_TOTALS']) {
  94. //*小时后时间大于现在时间
  95. if ($rs ['time_interval'] > $nowtime) {
  96. //发布数量小于限制数
  97. if ($rs ['time_totals'] < $auth ['TIME_TOTALS'])
  98. return 1;
  99. else
  100. return 3;
  101. } else { //设置数量为0,时间设置为新当前结束时间
  102. $this->authissuedao->uid = $uid;
  103. $this->authissuedao->time_totals = 0;
  104. $this->authissuedao->time_interval = $time;
  105. $this->db ()->update ( $this->authissuedao, $opt );
  106. return 1;
  107. }
  108. } else //今天发布总算超过限制
  109. return 2;
  110. } else { //不是当天时间更新,总算清0
  111. $this->authissuedao->uid = $uid;
  112. $this->authissuedao->day_totals = 0;
  113. $this->authissuedao->time_totals = 0;
  114. $this->authissuedao->day_time = $day ['end'];
  115. $this->authissuedao->time_interval = $time;
  116. $this->db ()->update ( $this->authissuedao, $opt );
  117. return 1;
  118. }
  119. }
  120. }
  121. /**
  122. * 根据问题ID,用户ID获取回答
  123. * @param unknown_type $qid
  124. * @param unknown_type $uid
  125. */
  126. function get_answer_by_quid($qid = 0, $uid = 0) {
  127. $result = $this->answerdao->get_answer_by_quid ( $qid, $uid );
  128. return $result;
  129. }
  130. /**
  131. * 搜索问答
  132. * @param unknown_type $keywork
  133. * @param unknown_type $on_page
  134. * @param unknown_type $page_size
  135. */
  136. function search($keywork = "", $status = 0, $on_page = 1, $page_size = 20) {
  137. $result = array ();
  138. $ask_info = array ();
  139. $result ['on_page'] = $on_page;
  140. $result ['status'] = $status;
  141. $result ['search_info'] = array ();
  142. $page = "";
  143. $status1 = null;
  144. $status2 = null;
  145. try {
  146. $result ['previous'] = $on_page != 0 ? $on_page - 1 : $on_page;
  147. $pa = $on_page;
  148. $limit_lower = (-- $pa) * $page_size;
  149. $D="";
  150. if ($status == 1) {
  151. $D=" and status =1";
  152. $status1 = 1;
  153. } elseif ($status == 2) {
  154. $D=" and status =2";
  155. $status2 = 2;
  156. }
  157. $docs=$this->questiondao->find(array('where' => "title like '%".$keywork."%' ".$D,'limit'=>$limit_lower.','.$page_size));
  158. $counts=$this->questiondao->count(array('where' => "title like '%".$keywork."%' ".$D ,'asArray' => TRUE));
  159. //$docs =$xs->search->setQuery('12')->setLimit($page_size, $limit_lower)->search();
  160. //$docs = $xs->search->addDb ( SEARCH_WD_DB )->setQuery ( $keywork )->addRange ( 'status', $status2, $status1 )->setLimit ( $page_size, $limit_lower )->setSort ( 'time' )->search ();
  161. //$docs = $xs->search->setQuery ( $keywork )->search ();
  162. //总记录数
  163. $result ['total_data'] = $counts;
  164. $total = intval ( $result ['total_data'] / $page_size );
  165. //总页数
  166. $result ['total_page'] = ($result ['total_data'] % $page_size) == 0 ? $total : $total + 1;
  167. $result ['next'] = $on_page == $result ['total_page'] ? $result ['total_page'] : $on_page + 1;
  168. $i = 0;
  169. $page_max = 1;
  170. if ($on_page > 10) {
  171. $page_max = intval ( $on_page / 10 ) + 1;
  172. $i = intval ( $on_page / 10 ) * 10;
  173. }
  174. foreach ( $docs as $doc ) {
  175. //结果集
  176. $ask_info ['qid'] = $doc->id;
  177. $ask_info ['cid'] = $doc->cid;
  178. $ask_info ['cid1'] = $doc->cid1;
  179. $ask_info ['cid2'] = $doc->cid2;
  180. $ask_info ['price'] = $doc->price;
  181. $ask_info ['author'] = $doc->author;
  182. $ask_info ['authorid'] = $doc->authorid;
  183. $ask_info ['title'] = $doc->title ;
  184. $ask_info ['description'] = cutstr(strip_tags( $doc->description ),300,"...");
  185. $ask_info ['time'] = my_date_format2 ( $doc->time, "Y-m-d" );
  186. $ask_info ['status'] = format_question_status ( $doc->status, 'other' );
  187. $ask_info ['answers'] = $doc->answers;
  188. //$ask_info ['answer'] = $doc->answer;
  189. $result ['search_info'] [$i] = $ask_info;
  190. $i ++;
  191. }
  192. $action = '/question/search/?keywork=' . $keywork . '&status=' . $status . '&on_page=';
  193. $i = 1;
  194. for(; $i <= $result ['total_page']; $i ++) {
  195. if ($i == $on_page)
  196. $page .= '<a href="javascript:void(0);" class="current">' . $i . '</a>';
  197. else
  198. $page .= '<a href="' . $action . $i . '" class="paginate">' . $i . '</a>';
  199. if ($i == (10 * $page_max))
  200. break;
  201. }
  202. $result ['page'] = $page;
  203. return $result;
  204. } catch ( XSException $e ) {
  205. //print $e->getMessage(); die;
  206. return array ();
  207. }
  208. }
  209. /**
  210. * 搜索名师答疑问答
  211. * @param unknown_type $keywork
  212. * @param unknown_type $on_page
  213. * @param unknown_type $page_size
  214. */
  215. function search_advisory($keywork = "", $type = "new", $on_page = 1, $page_size = 10) {
  216. $result = array ();
  217. $vip_questions = array ();
  218. $result ['vip_questions'] = array ();
  219. try {
  220. $xs = new XS ( SEARCH_VIP_INI );
  221. $limit_lower = ($on_page - 1) * $page_size;
  222. $search = " NOT status:1 ";
  223. if ($type == "answer")
  224. $search .= " NOT answers:0 ";
  225. if ($type == "hot")
  226. $search .= " NOT hot:0 ";
  227. $docs = $xs->search->addDb ( SEARCH_WD_DB )->setLimit ( $page_size, $limit_lower )->setSort ( 'time' )->search ( $keywork . $search );
  228. $action = '/search_advisory?type=' . $type . '&keywork_advisory=' . $keywork . '&on_page=';
  229. $page = $this->_get_page_search ( $on_page, $page_size, $xs->search->lastCount, $action );
  230. $i = 0;
  231. foreach ( $docs as $doc ) {
  232. //结果集
  233. $vip_questions ['id'] = $doc->id;
  234. $vip_questions ['price'] = $doc->price;
  235. $vip_questions ['author'] = $doc->author;
  236. $vip_questions ['authorid'] = $doc->authorid;
  237. $vip_questions ['title'] = $xs->search->highlight ( $doc->title );
  238. $vip_questions ['description'] = $xs->search->highlight ( $doc->description );
  239. $vip_questions ['time'] = my_date_format2 ( $doc->time, "Y-m-d H:i:s" );
  240. $vip_questions ['status'] = format_question_status ( $doc->status, 'other' );
  241. $vip_questions ['answers'] = $doc->answers;
  242. $vip_questions ['hot'] = $doc->hot;
  243. $vip_questions ['answer'] = $xs->search->highlight ( $doc->answer );
  244. //获取用户信息
  245. $rs = $this->userdao->get_userinfo_by_uid ( $doc->authorid );
  246. // if (empty ( $rs ['avatar'] ))
  247. // $rs ['avatar'] = DEF_AVATAR;
  248. $rs ['avatar'] = $this->get_user_avatar_by_username ( $doc->author );
  249. $vip_questions ['user'] = $rs;
  250. $result ['vip_questions'] [$i] = $vip_questions;
  251. $i ++;
  252. }
  253. $result ['page'] = $page;
  254. return $result;
  255. } catch ( XSException $e ) {
  256. return array ();
  257. }
  258. }
  259. function _get_page_search($on_page = 1, $page_size = 20, $total_count = 0, $action = "", $get = "", $other = "page") {
  260. $page_c = "";
  261. $page ['previous'] = get_previous ( $on_page );
  262. $page ['on_page'] = $on_page;
  263. $total = intval ( $total_count / $page_size );
  264. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  265. $page ['total_data'] = $total_count;
  266. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  267. $i = 1;
  268. $page_max = 1;
  269. if ($on_page > 10) {
  270. $page_max = intval ( $on_page / 10 ) + 1;
  271. $i = intval ( $on_page / 10 ) * 10 - 1;
  272. }
  273. for(; $i <= $page ['total_page']; $i ++) {
  274. if ($i == $on_page) {
  275. if ($other == "page")
  276. $page_c .= '<a href="javascript:void(0);" class="current">' . $i . '</a>';
  277. else
  278. $page_c .= '&nbsp;<span class="current">' . $i . '</span>&nbsp;';
  279. } else if ($other == "page")
  280. $page_c .= '<a href="' . $action . $i . $get . '" class="paginate">' . $i . '</a>';
  281. else
  282. $page_c .= '&nbsp;<a href="' . $action . $i . $get . '" class="paginate">' . $i . '</a>&nbsp;';
  283. if ($i == (10 * $page_max))
  284. break;
  285. }
  286. $page ['page'] = $page_c;
  287. $page ['lower'] = (-- $on_page) * $page_size;
  288. return $page;
  289. }
  290. /**
  291. * 获取相关问答动态
  292. * @param unknown_type $uid
  293. */
  294. function get_related_que_ans($uid = 0) {
  295. if ($uid == 0)
  296. return array ();
  297. $param ['authorid'] = $uid;
  298. $limit ['lower'] = 0;
  299. $limit ['size'] = 3;
  300. $result ['question'] = $this->questiondao->get_questions_list ( $param, $limit );
  301. $result ['answer'] = $this->answerdao->get_answer_list ( $uid, $limit );
  302. $data = $this->_format_related_data ( $result ['question'], $result ['answer'] );
  303. return $data;
  304. }
  305. /**
  306. * 格式化相关问答动态
  307. * @param unknown_type $question
  308. * @param unknown_type $answer
  309. */
  310. function _format_related_data($question, $answer) {
  311. $data = array ();
  312. foreach ( $question as $key => $value ) {
  313. $value ['description'] = strip_tags ( $value ['description'] );
  314. $data [$value ['time']] = $value;
  315. $data [$value ['time']] ['adopttime'] = 0;
  316. $data [$value ['time']] ['type'] = "问题";
  317. }
  318. foreach ( $answer as $key => $value ) {
  319. $value ['title'] = strip_tags ( $value ['title'] );
  320. $data [$value ['time']] = $value;
  321. $data [$value ['time']] ['title'] = $value ['title'];
  322. $data [$value ['time']] ['type'] = "回答";
  323. }
  324. krsort ( $data );
  325. foreach ( $data as $key => $value ) {
  326. $data [$key] ['time'] = my_date_format2 ( $value ['time'] );
  327. }
  328. return $data;
  329. }
  330. /**
  331. * 获取擅长分析信息
  332. * @param unknown_type $cids
  333. */
  334. function get_expert_category_list($cids = "") {
  335. if (empty ( $cids ))
  336. return array ();
  337. $result = $this->categorydao->get_expert_category_list ( $cids );
  338. return $result;
  339. }
  340. /**
  341. * 获取相关问题--看具体需求
  342. * @param unknown_type $id
  343. */
  344. function get_like_questions_list($id = 0, $cid = 0, $status = "") {
  345. $result = $this->questiondao->get_like_questions_list ( $id, $cid, $status );
  346. return $result;
  347. }
  348. /**
  349. * 获取问题分类内容
  350. * @return $result array;
  351. */
  352. function get_category_list() {
  353. $result = $this->db ()->find ( $this->categorydao );
  354. $data ['top'] = array ();
  355. $data ['second'] = array ();
  356. foreach ( $result as $key => $value ) {
  357. if ($value->grade == 1)
  358. array_push ( $data ['top'], $value );
  359. if ($value->grade == 2)
  360. array_push ( $data ['second'], $value );
  361. }
  362. return $data;
  363. }
  364. /**
  365. * 获取分类 根据ID
  366. * @param unknown_type $id
  367. */
  368. function get_category_by_id($id = 0) {
  369. $result = $this->categorydao->get_category_by_id ( $id );
  370. return $result;
  371. }
  372. /**
  373. * 获取采纳率(效率问题--可以优化地方)
  374. */
  375. function get_adopt_percentage($uid = 0) {
  376. if ($uid != 0)
  377. $param ['authorid'] = $uid;
  378. $total = $this->questiondao->get_questions_count ( array () );
  379. $param ['auto'] = " and status in (1) and hidden =0 ";
  380. $w = $this->questiondao->get_questions_count ( $param );
  381. $param ['auto'] = " and status in (2) ";
  382. $y = $this->questiondao->get_questions_count ( $param );
  383. $data ['adopt'] = 0;
  384. if ($total ['count'] != 0)
  385. $data ['adopt'] = round ( ($y ['count'] / $total ['count'] * 100), 2 );
  386. $data ['unresolved'] = $w ['count'];
  387. $data ['resolved'] = $y ['count'];
  388. return $data;
  389. }
  390. /**
  391. * 获取问题列表
  392. * @param unknown_type $data
  393. * @param unknown_type $condition
  394. * @param unknown_type $limit
  395. */
  396. function get_questions_list_tem($data = array(), $condition = "", $limit = "", $type = "index", $time_type = "Y-m-d H:i:s") {
  397. $result = $this->get_list ( $data, $condition, $limit, t_question );
  398. //加入15天自动关闭问题--发送系统信息
  399. foreach ( $result as $key => $value ) {
  400. $this->auto_set_status_question ( $value );
  401. }
  402. $result = $this->_format_question_data ( $result, $type, $time_type );
  403. return $result;
  404. }
  405. function get_QA(){
  406. $field=" a.id,a.title,b.content ";
  407. $condition=" a.status =2 limit 5";
  408. $rs=$this->questiondao->get_QA($field,$condition);
  409. return $rs;
  410. }
  411. /**
  412. * 获取文章列表
  413. * @param unknown_type $data
  414. * @param unknown_type $condition
  415. * @param unknown_type $limit
  416. * @param unknown_type $type
  417. */
  418. function get_article_list($data = array(), $condition = "", $limit = "", $format = "Y-m-d H:i:s", $type = "index") {
  419. $result = $this->get_list ( $data, $condition, $limit, t_article );
  420. foreach ( $result as $key => $value ) {
  421. $result [$key] ['time'] = format_date ( $value ['time'], $format );
  422. }
  423. return $result;
  424. }
  425. /**
  426. * 格式化问题数据
  427. * @param unknown_type $data
  428. */
  429. function _format_question_data($data = array(), $type = "index", $time_type = "Y-m-d H:i:s") {
  430. foreach ( $data as $key => $value ) {
  431. $data [$key] ['time'] = my_date_format2 ( $value ['time'], $time_type );
  432. $data [$key] ['status'] = format_question_status ( $value ['status'], $type );
  433. }
  434. return $data;
  435. }
  436. /**
  437. * 格式化名师答疑问题数据
  438. * @param unknown_type $data
  439. */
  440. function _format_vip_question_data($data = array()) {
  441. foreach ( $data as $key => $value ) {
  442. $data [$key] ['time'] = my_date_format2 ( $value ['time'], "Y-m-d H:i:s" );
  443. $data [$key] ['status_num'] = $data [$key] ['status'];
  444. $data [$key] ['status'] = format_question_status ( $value ['status'], "vip" );
  445. }
  446. return $data;
  447. }
  448. /**
  449. * 获取积分详细
  450. */
  451. function get_credit_details($uid){
  452. $result = $this->creditdao->get_credit_info_by_uid ( $uid );
  453. foreach ($result as $key=>$value){
  454. $result[$key]['time']=format_date($value['time']);
  455. }
  456. return $result;
  457. }
  458. /**
  459. * 获取积分,财富日常操作信息
  460. * @param unknown_type $uid
  461. */
  462. function get_credit_info($uid) {
  463. $result = $this->creditdao->get_credit_info_by_uid ( $uid );
  464. $data ['usually_point'] = 0;
  465. $data ['add_point'] = 0;
  466. $data ['reply_point'] = 0;
  467. $data ['punish_point'] = 0;
  468. $data ['rich_adopt'] = 0;
  469. $data ['rich_refunds'] = 0;
  470. //财富
  471. $data ['rich_offer'] = 0;
  472. foreach ( $result as $key => $value ) {
  473. if ($value ['operation'] == CREDIT_ACTION_LOGIN || $value ['operation'] == ACTION_REGISTER) //日常操作积分
  474. $data ['usually_point'] += $value ['credit1'];
  475. elseif ($value ['operation'] == CREDIT_ACTION_ADD) //添加问题积分
  476. $data ['add_point'] += $value ['credit1'];
  477. //回答获得
  478. elseif ($value ['operation'] == CREDIT_ACTION_ANSWER || $value ['operation'] == ACTION_ADOPT || $value ['operation'] == ACTION_SUPPORT)
  479. $data ['reply_point'] += $value ['credit1'];
  480. //处罚积分
  481. elseif ($value ['operation'] == ACTION_DELETE_QUESTION || $value ['operation'] == ACTION_DELETE_ANSWER)
  482. $data ['punish_point'] += $value ['credit1'];
  483. //财富付出
  484. if ($value ['operation'] == RICH_ACTION_OFFER)
  485. $data ['rich_offer'] += $value ['credit3'];
  486. //财富获得
  487. if ($value ['operation'] == RICH_ACTION_ADOPT || $value ['operation'] == RICH_ACTION_REFUNDS)
  488. $data ['rich_adopt'] += $value ['credit3'];
  489. //财富退款
  490. if ($value ['operation'] == RICH_ACTION_REFUNDS)
  491. $data ['rich_refunds'] += $value ['credit3'];
  492. }
  493. return $data;
  494. }
  495. /**
  496. * 问题和用户信息
  497. * @param unknown_type $id
  498. */
  499. function get_question_user_info($id = 0) {
  500. $result = $this->questiondao->get_question_user_info_by_id ( $id );
  501. if (empty ( $result ))
  502. return false;
  503. $lv = get_lv ( $result ['credit1'] );
  504. $result ['lv'] = $lv [0];
  505. $result ['status_num'] = $result ['status'];
  506. $result ['last_close_day'] = get_last_close_day ( $result ['time'] );
  507. $su = unserialize ( $result ['supply'] );
  508. $result ['supply'] = $su [0] ['content'];
  509. //获取头像
  510. $result ['avatar'] = json_decode($result ['avatar'],true);//$this->get_user_avatar_by_username ( $result ['author'] );
  511. $result ['supply_time'] = my_date_format2 ( $su [0] ['time'] );
  512. //条件满足-关闭问题
  513. $this->auto_set_status_question ( $result );
  514. $result ['status'] = format_question_status ( $result ['status'], 'page' );
  515. if (defined ( "CREDIT3" ))
  516. $result ['credit3'] = CREDIT3;
  517. else
  518. $result ['credit3'] = 0;
  519. return $result;
  520. }
  521. /**
  522. * 关闭问题
  523. * @param unknown_type $id
  524. */
  525. function close_question($id) {
  526. $this->questiondao->close_question_by_id ( $id );
  527. }
  528. /**
  529. * 获取回答列表
  530. * @param unknown_type $data
  531. * @param unknown_type $condition
  532. * @param unknown_type $limit
  533. */
  534. function get_answers_list_tem($data = array(), $condition = "", $limit = "") {
  535. $result = $this->get_list ( $data, $condition, $limit, t_answer );
  536. $result = $this->_format_answer_data ( $result );
  537. return $result;
  538. }
  539. /**
  540. * 格式化回答 // '#<a.+?href="(.+?)".*?>(.+?)</a>#'
  541. * @param unknown_type $data
  542. */
  543. function _format_message_data($data = array()) {
  544. foreach ( $data as $key => $value ) {
  545. preg_match ( '#<a.*?>(.+?)</a>#', $value ['content'], $match );
  546. $msg = cutstr ( $match [0], 90, '...' );
  547. $data [$key] ['content'] = str_replace ( $match [1], $msg, $value ['content'] );
  548. $data [$key] ['time'] = my_date_format2 ( $value ['time'], "Y-m-d" );
  549. }
  550. return $data;
  551. }
  552. /**
  553. * 格式化回答
  554. * @param unknown_type $data
  555. */
  556. function _format_answer_data($data = array()) {
  557. foreach ( $data as $key => $value ) {
  558. $data [$key] ['time'] = my_date_format2 ( $value ['time'], "Y-m-d" );
  559. }
  560. return $data;
  561. }
  562. /**
  563. * 回答和用户信息
  564. * @param unknown_type $id 问题id
  565. */
  566. function get_answer_user_info($id = 0) {
  567. $result = $this->answerdao->get_answer_user_info_by_id ( $id );
  568. foreach ( $result as $key => $value ) {
  569. $lv = get_lv ( $value ['credit1'] );
  570. $result [$key] ['lv'] = $lv [0];
  571. $result [$key] ['time'] = format_date ( intval ( $value ['time'] ) );
  572. if (defined ( "CREDIT3" ))
  573. $result [$key] ['credit3'] = CREDIT3;
  574. else
  575. $result [$key] ['credit3'] = 0;
  576. //追问和回答
  577. $tag_array = unserialize ( $value ['tag'] );
  578. // if (empty ( $value ['avatar'] ))
  579. // $result [$key] ['avatar'] = "/global/img/avatarNormal.png";
  580. //获取头像
  581. $result [$key] ['avatar'] = json_decode($value ['avatar'],true);//$this->get_user_avatar_by_username ( $value ['author'] );
  582. $result [$key] ['to_ask'] = $tag_array [0];
  583. if (isset ( $tag_array [1] ))
  584. $result [$key] ['answer_again'] = $tag_array [1];
  585. $result [$key] ['to_ask_time'] = my_date_format2 ( $value ['tagtime'] );
  586. $result [$key] ['answer_again_time'] = 0;
  587. if (isset ( $tag_array [2] ))
  588. $result [$key] ['answer_again_time'] = my_date_format2 ( $tag_array [2] );
  589. }
  590. return $result;
  591. }
  592. /**
  593. * 获取系统信息
  594. * @param unknown_type $uid
  595. * @param unknown_type $fromuid
  596. * @param unknown_type $time
  597. * @param unknown_type $on_page
  598. * @param unknown_type $page_size
  599. */
  600. function get_messages_list($uid = 0, $fromuid = 1, $time = 7, $on_page = 1, $page_size = 10) {
  601. $page = "";
  602. $muid = $fromuid;
  603. $fromuid = " type=" . $fromuid . " and ";
  604. $total_count = $this->messagedao->get_message_count ( $uid, $fromuid, $time );
  605. //可否抽象出分页类
  606. $data ['total_page'] = intval ( $total_count ['count'] / $page_size ) + 1;
  607. $data ['total_data'] = $total_count ['count'];
  608. $data ['on_page'] = $on_page;
  609. $data ['previous'] = $on_page != 0 ? $on_page - 1 : $on_page;
  610. $data ['next'] = $on_page == $data ['total_page'] ? $data ['total_page'] : $on_page + 1;
  611. $i = 1;
  612. $page_max = 1;
  613. if ($on_page > 10) {
  614. $page_max = intval ( $on_page / 10 ) + 1;
  615. $i = intval ( $on_page / 10 ) * 10 - 1;
  616. }
  617. for(; $i <= $data ['total_page']; $i ++) {
  618. if ($i == $on_page)
  619. $page .= '<a href="javascript:void(0);" class="current">' . $i . '</a>';
  620. else
  621. $page .= '<a href="javascript:void(0);" id="get_msg_' . $i . '" data="' . $muid . '_' . $i . '" class="paginate">' . $i . '</a>';
  622. if ($i == (10 * $page_max))
  623. break;
  624. }
  625. $data ['page'] = $page;
  626. $limit ['lower'] = (-- $on_page) * $page_size;
  627. $limit ['size'] = $page_size;
  628. $data ['messages'] = $this->messagedao->get_message_list ( $uid, $fromuid, $time, $limit );
  629. $data ['messages'] = $this->_format_message_data ( $data ['messages'] );
  630. $this->messagedao->update_message_new ( $uid );
  631. return $data;
  632. }
  633. /**
  634. * 根据问题ID,用户ID
  635. * @param unknown_type $qid
  636. * @param unknown_type $uid
  637. */
  638. function get_question_by_uqid($qid = 0, $uid = 0) {
  639. $rs = $this->questiondao->get_question_by_uqid ( $qid, $uid );
  640. return $rs;
  641. }
  642. /**
  643. * 根据回答ID,问题ID
  644. * @param unknown_type $aid
  645. * @param unknown_type $qid
  646. */
  647. function get_answer_by_aqid($aid = 0, $qid = 0) {
  648. $rs = $this->answerdao->get_answer_by_aqid ( $aid, $qid );
  649. return $rs;
  650. }
  651. /**
  652. * 获取名师答疑问题
  653. */
  654. function get_vip_questions_list($data = array (), $condition = "", $limit = "", $type = "vip") {
  655. $result = $this->get_list ( $data, $condition, $limit, t_vipquestion );
  656. foreach ( $result as $key => $value ) {
  657. $rs = $this->userdao->get_userinfo_by_uid ( $value ['authorid'] );
  658. $rs ['avatar'] = $this->get_user_avatar_by_username ( $value ['author'] );
  659. $result [$key] ['description'] = strip_tags ( $value ['description'] );
  660. $result [$key] ['user'] = $rs;
  661. }
  662. $result = $this->_format_vip_question_data ( $result );
  663. return $result;
  664. }
  665. /**
  666. * 根据ID获取名师答疑问题
  667. * @param unknown_type $id
  668. */
  669. function get_vip_questions_by_id($id = 0) {
  670. $rs = $this->vipquestiondao->get_vip_question_by_id ( $id );
  671. $rs ['time_stamp'] = $rs ['time'];
  672. $rs ['time_10'] = $rs ['time_stamp'] + 10 * 60;
  673. $rs ['time'] = my_date_format2 ( $rs ['time'], "Y-m-d H:i:s" );
  674. return $rs;
  675. }
  676. /**
  677. * 根据ID获取名师回答
  678. * @param unknown_type $id
  679. */
  680. function get_vip_answer_by_id($id = 0) {
  681. $rs = $this->vipanswerdao->get_vip_answer_by_qid ( $id );
  682. if (empty ( $rs ))
  683. return array ();
  684. $rs ['answer_again'] = "";
  685. //追问和回答
  686. $tag_array = unserialize ( $rs ['tag'] );
  687. $rs ['to_ask'] = $tag_array [0];
  688. if (isset ( $tag_array [1] ))
  689. $rs ['to_ask_time'] = my_date_format2 ( $tag_array [1] );
  690. if (isset ( $tag_array [2] ))
  691. $rs ['answer_again'] = $tag_array [2];
  692. return $rs;
  693. }
  694. /**
  695. * 获取该用户指定的名师问题
  696. * @param unknown_type $qid
  697. * @param unknown_type $uid
  698. */
  699. function get_vip_question_by_quid($qid = 0, $uid = 0) {
  700. $rs = $this->vipquestiondao->get_vip_question_by_quid ( $qid, $uid );
  701. if (! empty ( $rs )) {
  702. $rs ['time_stamp'] = $rs ['time'];
  703. $rs ['time_10'] = $rs ['time_stamp'] + 10 * 60;
  704. $rs ['time'] = my_date_format2 ( $rs ['time'], "Y-m-d H:i:s" );
  705. }
  706. return $rs;
  707. }
  708. /**
  709. * 更新名师答疑问题详情
  710. * @param unknown_type $qid
  711. * @param unknown_type $description
  712. */
  713. function update_vip_question_description($qid = 0, $description = "") {
  714. $this->vipquestiondao->update_vip_question_description ( $qid, $description );
  715. }
  716. /**
  717. * 获取某个用户的名师答疑
  718. * @param unknown_type $uid
  719. */
  720. function get_vip_questions_by_uid($uid) {
  721. $rs = $this->vipquestiondao->get_vip_question_by_uid ( $uid );
  722. foreach ( $rs as $key => $value ) {
  723. $rs [$key] ['time'] = format_date ( $value ['time'] );
  724. }
  725. return $rs;
  726. }
  727. /**
  728. * 后台获取名师答疑问题
  729. */
  730. function get_vip_questions_list_admin($data = array (), $condition = "", $limit = "", $type = "vip") {
  731. $result = $this->get_list ( $data, $condition, $limit, t_vipquestion );
  732. $nowtime = get_date ();
  733. foreach ( $result as $key => $value ) {
  734. $result [$key] ['do_answer_time'] = $value ['time'];
  735. if ($value ['price'] == 100) {
  736. $do_answer_time = $value ['time'] + 432000 - $nowtime;
  737. $result [$key] ['do_answer_time'] = do_vip_answer_time ( $do_answer_time );
  738. } elseif ($value ['price'] == 200) {
  739. $do_answer_time = $value ['time'] + 259200 - $nowtime;
  740. $result [$key] ['do_answer_time'] = do_vip_answer_time ( $do_answer_time );
  741. } elseif ($value ['price'] == 500) {
  742. $do_answer_time = $value ['time'] + 172800 - $nowtime;
  743. $result [$key] ['do_answer_time'] = do_vip_answer_time ( $do_answer_time );
  744. }
  745. $rs = $this->vipanswerdao->get_vip_answer_by_qid ( $value ['id'] );
  746. $result [$key] ['aid'] = $rs ['id'];
  747. //追问和回答
  748. $tag_array = unserialize ( $rs ['tag'] );
  749. $result [$key] ['to_ask'] = $tag_array [0];
  750. if (isset ( $tag_array [1] ))
  751. $result [$key] ['to_ask_time'] = my_date_format2 ( $tag_array [1] );
  752. if (isset ( $tag_array [2] ))
  753. $result [$key] ['answer_again'] = $tag_array [2];
  754. }
  755. $result = $this->_format_vip_question_data ( $result );
  756. return $result;
  757. }
  758. /**
  759. * 获取用户财富明细列表
  760. * @param unknown_type $uid
  761. */
  762. function get_credit3_list($data = array(), $condition = "", $limit = "") {
  763. $rs = $this->get_list ( $data, $condition, $limit, t_credit3log );
  764. foreach ( $rs as $key => $value ) {
  765. if ($value ['is_vip'] == 0)
  766. $rs [$key] ['question'] = $this->questiondao->get_question_by_id ( $value ['qid'] );
  767. else
  768. $rs [$key] ['question'] = $this->vipquestiondao->get_vip_question_by_id ( $value ['qid'] );
  769. $rs [$key] ['date'] = format_date ( $value ['time'] );
  770. }
  771. return $rs;
  772. }
  773. /**
  774. * 获取其他相关公告
  775. * @param unknown_type $id
  776. */
  777. function get_article_other($id = 0) {
  778. Doo::loadModel ( 'ArticleDao' );
  779. $articledao = new ArticleDao ();
  780. $rs = $articledao->get_article_other ( $id );
  781. foreach ( $rs as $key => $value ) {
  782. $rs [$key] ['time'] = format_date ( $value ['time'] );
  783. }
  784. return $rs;
  785. }
  786. /**
  787. * 获取名师讨论
  788. * @param unknown_type $id
  789. */
  790. function get_discuss_by_qid($id) {
  791. Doo::loadModel ( 'DiscussDao' );
  792. $discussdao = new DiscussDao ();
  793. $rs ['discuss_list'] = $discussdao->get_discuss_by_qid ( $id );
  794. $uid = array ();
  795. foreach ( $rs ['discuss_list'] as $key => $value ) {
  796. $user = $this->userdao->get_userinfo_by_uid ( $value ['uid'] );
  797. array_push ( $uid, $user ['uid'] );
  798. $rs ['discuss_list'] [$key] ['user'] = $user;
  799. $rs ['discuss_list'] [$key] ['user'] ['avatar'] = $this->get_user_avatar_by_username ( $user ['username'] );
  800. $rs ['discuss_list'] [$key] ['time'] = format_date ( $value ['time'] );
  801. $chir_discuss = $discussdao->get_discuss_by_cid ( $value ['id'] );
  802. foreach ( $chir_discuss as $keys => $values ) {
  803. $user = $this->userdao->get_userinfo_by_uid ( $values ['uid'] );
  804. $chir_discuss [$keys] ['user'] = $user;
  805. $chir_discuss [$keys] ['user'] ['avatar'] = $this->get_user_avatar_by_username ( $user ['username'] );
  806. }
  807. $rs ['discuss_list'] [$key] ['chir_discuss'] = $chir_discuss;
  808. }
  809. $uid = array_unique ( $uid );
  810. $rs ['user_num'] = count ( $uid );
  811. return $rs;
  812. }
  813. /**
  814. * 获取充值日志
  815. * @param unknown_type $uid
  816. */
  817. function get_bank_jorunal_list($data = array(), $condition = "", $limit = "") {
  818. $rs = $this->get_list ( $data, $condition, $limit, t_bankjorunal );
  819. foreach ( $rs as $key => $value ) {
  820. $rs [$key] ['time'] = format_date ( $value ['time'] );
  821. }
  822. return $rs;
  823. }
  824. /**
  825. * 获取金额
  826. * @param unknown_type $username
  827. */
  828. function get_bank_by_username($username = "") {
  829. $bank = 0;
  830. require_once (SITE_PATH . '/protected/plugin/client.php');
  831. $client = new client ( ZHSSO );
  832. $userinfo = $client->zhsso_getUserbyName ( $username );
  833. $userinfo = explode ( "\r", $userinfo );
  834. $ts = json_decode ( $userinfo ['0'], true );
  835. $bank = $ts [0] ['bank'];
  836. return $bank;
  837. }
  838. /**
  839. * 获取通行证用户头像--
  840. * @param unknown_type $username
  841. */
  842. function get_user_avatar_by_username($username = "") {
  843. require_once (SITE_PATH . '/protected/plugin/client.php');
  844. $client = new client ( ZHSSO );
  845. $avatar = array ('180' => DEF_AVATAR, '30' => DEF_AVATAR, '90' => DEF_AVATAR, '45' => DEF_AVATAR );
  846. $userinfo = $client->zhsso_getUserbyName ( $username );
  847. $userinfo = explode ( "\r", $userinfo );
  848. $ts = json_decode ( $userinfo ['0'], true );
  849. if (isset ( $ts ) && ! empty ( $ts )) {
  850. $avatar = $client->ps_getavatar ( $ts [0] ['id'] );
  851. }
  852. return $avatar;
  853. }
  854. /**
  855. * 获取充值信息
  856. * @param unknown_type $uid
  857. */
  858. function get_recharge($username = "") {
  859. $statusArray = array ('succ' => '<span class="colGreen">充值完成</span>', 'failed' => '充值失败', 'error' => '充值错误', 'progress' => '<span class="colOrange">等待付款</span>', 'timeout' => '超时', 'cancel' => '关闭', 'waitting' => '<span class="colOrange">等待付款</span>', 'unpay' => '交易未支付' );
  860. require_once (SITE_PATH . '/protected/plugin/client.php');
  861. $client = new client ( ZHSSO );
  862. $userinfo = $client->zhsso_getUserbyName ( $username );
  863. $userinfo = explode ( "\r", $userinfo );
  864. $ts = json_decode ( $userinfo ['0'], true );
  865. $recharge_info = explode ( "\r", $client->getPayOrder ( $ts [0] ['id'] ) );
  866. $PayOrderArray = json_decode ( $recharge_info ['1'], true );
  867. $this->data ['v_mid'] = '22544863'; // 商户号,这里为测试商户号1001,替换为自己的商户号(老版商户号为4位或5位,新版为8位)即可
  868. $this->data ['v_url'] = Doo::conf ()->APP_URL . 'Receive'; // 请填写返回url,地址应为绝对路径,带有http协议
  869. $this->data ['key'] = 'smartcost@)!@onlinepaychinabank'; // 如果您还没有设置MD5密钥请登陆我们为您提供商户后台,地址:https://merchant3.chinabank.com.cn/
  870. $this->data ['v_moneytype'] = "CNY";
  871. if (! empty ( $PayOrderArray )) {
  872. foreach ( $PayOrderArray as $value ) {
  873. $tmpArray [] = ( array ) $value;
  874. }
  875. foreach ( $tmpArray as $key => $value ) {
  876. if ($value ['status'] == 'unpay')
  877. $tmpArray [$key] ['md5info'] = strtoupper ( md5 ( $value ['money'] . $this->data ['v_moneytype'] . $value ['trade_sn'] . $this->data ['v_mid'] . $this->data ['v_url'] . $this->data ['key'] ) );
  878. $tmpArray [$key] ['statusname'] = $statusArray [$value ['status']];
  879. $tmpArray [$key] ['addtime'] = format_date ( $value ['addtime'] );
  880. }
  881. } else {
  882. $tmpArray = null;
  883. }
  884. sort ( $tmpArray );
  885. return $tmpArray;
  886. }
  887. public function payOrder() {
  888. //
  889. // $this->data['v_mid'] = '22544863'; // 商户号,这里为测试商户号1001,替换为自己的商户号(老版商户号为4位或5位,新版为8位)即可
  890. // $this->data['v_url'] = Doo::conf()->APP_URL . 'Receive'; // 请填写返回url,地址应为绝对路径,带有http协议
  891. // $this->data['key'] = 'smartcost@)!@onlinepaychinabank'; // 如果您还没有设置MD5密钥请登陆我们为您提供商户后台,地址:https://merchant3.chinabank.com.cn/
  892. // $this->data['v_moneytype'] = "CNY";
  893. // if (!empty($PayOrderArray)) {
  894. // foreach ($PayOrderArray as $value) {
  895. // $tmpArray[] = (array) $value;
  896. // }
  897. // foreach ($tmpArray as $key => $value) {
  898. // if ($value['status'] == 'unpay')
  899. // $tmpArray[$key]['md5info'] = strtoupper(md5($value['money'] . $this->data['v_moneytype'] . $value['trade_sn'] . $this->data['v_mid'] . $this->data['v_url'] . $this->data['key']));
  900. // $tmpArray[$key]['statusname'] = $statusArray[$value['status']];
  901. // }
  902. // } else {
  903. // $tmpArray = null;
  904. // }
  905. // $this->data['PayOrderArray'] = $tmpArray;
  906. // $this->data['leftmenu'] = 'payOrder';
  907. // $this->data['extmenu'] = 0;
  908. // $this->data['curlink'] = __FUNCTION__;
  909. // $this->render('myHome - rechargeOrder', $this->data, TRUE);
  910. }
  911. /**
  912. *
  913. * Enter description here ...
  914. * @param unknown_type $qid
  915. */
  916. function get_question_by_qid($qid) {
  917. $result = $this->questiondao->get_question_by_id ( $qid );
  918. return $result;
  919. }
  920. /**
  921. * 实现接口
  922. * (non-PHPdoc)
  923. * @see BaseLogic::format_email_content()
  924. */
  925. protected function format_email_content($html_templete, $templete_name, $qid, $aid) {
  926. }
  927. function get_credit_log(){
  928. $result = $this->credit3logdao->get_all_list();
  929. return $result;
  930. }
  931. }
  932. ?>