| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204 | 
							- <?php
 
- /**
 
-  * 用户操作逻辑
 
-  * @author cp
 
-  */
 
- class UserLogic extends BaseLogic {
 
- 	
 
- 	private $categorydao;
 
- 	private $userdao;
 
- 	private $questiondao;
 
- 	private $answerdao;
 
- 	private $messagedao;
 
- 	private $group;
 
- 	private $creditdao;
 
- 	private $sessiondao;
 
- 	private $userlogdao;
 
- 	private $crontadstatusdao;
 
- 	private $credit3logdao;
 
- 	private $authissuedao;
 
- 	private $vipquestiondao;
 
- 	private $vipanswerdao;
 
- 	private $examinedao;
 
- 	
 
- 	function __construct() {
 
- 		
 
- 		Doo::loadModel ( 'CategoryDao' );
 
- 		Doo::loadModel ( 'UserDao' );
 
- 		Doo::loadModel ( 'QuestionDao' );
 
- 		Doo::loadModel ( 'CreditDao' );
 
- 		Doo::loadModel ( 'AnswerDao' );
 
- 		Doo::loadModel ( 'MessageDao' );
 
- 		Doo::loadModel ( 'GroupDao' );
 
- 		Doo::loadModel ( 'SessionDao' );
 
- 		Doo::loadModel ( 'UserlogDao' );
 
- 		Doo::loadModel ( 'CrontadstatusDao' );
 
- 		Doo::loadModel ( 'Credit3logDao' );
 
- 		Doo::loadModel ( 'AuthissueDao' );
 
- 		Doo::loadModel ( 'VipquestionDao' );
 
- 		Doo::loadModel ( 'VipanswerDao' );
 
- 		
 
- 		$this->categorydao = new CategoryDao ();
 
- 		$this->userdao = new UserDao ();
 
- 		$this->questiondao = new QuestionDao ();
 
- 		$this->creditdao = new CreditDao ();
 
- 		$this->answerdao = new AnswerDao ();
 
- 		$this->messagedao = new MessageDao ();
 
- 		$this->groupdao = new GroupDao ();
 
- 		$this->sessiondao = new SessionDao ();
 
- 		$this->userlogdao = new UserlogDao ();
 
- 		$this->crontadstatusdao = new CrontadstatusDao ();
 
- 		$this->credit3logdao = new Credit3logDao ();
 
- 		$this->authissuedao = new AuthissueDao ();
 
- 		$this->vipquestiondao = new VipquestionDao ();
 
- 		$this->vipanswerdao = new VipanswerDao ();
 
- 		
 
- 		Doo::loadModel ( 'ExamineDao' );
 
- 		$this->examinedao = new ExamineDao ();
 
- 		
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 完善名师问题
 
- 	 * @param unknown_type $id
 
- 	 * @param unknown_type $title
 
- 	 * @param unknown_type $description
 
- 	 */
 
- 	function update_vip_question($id = 0, $title = "", $description = "", $uid = 0, $phone = "", $qq = "") {
 
- 		$this->vipquestiondao->id = $id;
 
- 		$this->vipquestiondao->title = $title;
 
- 		
 
- 		$this->vipquestiondao->description = $description;
 
- 		
 
- 		$this->vipquestiondao->time = get_date ();
 
- 		
 
- 		$this->vipquestiondao->status = PAID_FILL_IN;
 
- 		
 
- 		$result = $this->db ()->update ( $this->vipquestiondao );
 
- 		
 
- 		//更新今天发布数--需要修改每时间段的更新次数-setp2
 
- 		$this->authissuedao->set_authissue_totals ( $uid );
 
- 		
 
- 		//添加积分值-setp2
 
- 		$this->set_credit1 ( 'add', $uid, CREDIT_POINT_ADD, CREDIT_ACTION_ADD );
 
- 		
 
- 		$que_rs = $this->vipquestiondao->get_vip_question_by_id ( $id );
 
- 		
 
- 		//加入检索索引-分词还未加入-数据配置--等待搜索页面
 
- 		//$pams = array ('id' => $id, 'price' => $que_rs ['price'], 'author' => $que_rs ['author'], 'authorid' => $uid, 'title' => $title, 'description' => $description, 'supply' => '', 'time' => $this->vipquestiondao->time, 'hot' => 0, 'status' => PAID_FILL_IN, 'answers' => 0, 'answer' => '' );
 
- 		
 
- 		//$this->add_search_index ( $pams, SEARCH_WD_DB, SEARCH_VIP_INI );
 
- 		
 
- 		$this->userdao->uid = $uid;
 
- 		
 
- 		if (! empty ( $phone ))
 
- 			$this->userdao->phone = $phone;
 
- 		
 
- 		if (! empty ( $qq ))
 
- 			$this->userdao->qq = $qq;
 
- 		
 
- 		$result = $this->db ()->update ( $this->userdao );
 
- 		
 
- 		if($result){
 
- 			include SITE_PATH . '/protected/config/set_email_to_admin.conf.php';
 
- 			
 
- 			$list=explode("-", $sys ['set_email']);
 
- 			
 
- 			foreach ($list as $value){
 
- 				if(filter_var($value, FILTER_VALIDATE_EMAIL))
 
- 					$this->_mail("有用户发布了名师答疑,赶紧去后台查看:<a href='http://zhzdwd.com/'>问答后台</a>","有新的名师答疑提问",$value);
 
- 			}	
 
- 		}
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 添加名师问题
 
- 	 * @param unknown_type $data
 
- 	 */
 
- 	function add_vip_question($data = array()) {
 
- 		$this->vipquestiondao->status = PAID_NO_FILL_IN;
 
- 		
 
- 		$price = abs ( $data ['price'] );
 
- 		
 
- 		$this->vipquestiondao->price = $price;
 
- 		$this->credit3logdao->amount = $price;
 
- 		
 
- 		$this->vipquestiondao->author = $data ['author'];
 
- 		$this->credit3logdao->username = $data ['author'];
 
- 		
 
- 		$this->vipquestiondao->authorid = $data ['authorid'];
 
- 		
 
- 		$time = get_date ();
 
- 		$this->vipquestiondao->time = $time;
 
- 		$this->credit3logdao->time = $time;
 
- 		
 
- 		$ip = client_ip ();
 
- 		$this->vipquestiondao->ip = $ip;
 
- 		$this->credit3logdao->ip = $ip;
 
- 		
 
- 		$this->vipquestiondao->refunds = 1;
 
- 		
 
- 		//扣除通行证金额
 
- 		if ($data ['price'] > 0) {
 
- 			//扣除通行证的钱	//用户表和记录表
 
- 			$is = $this->set_credit3 ( - $data ['price'], $data ['authorid'], RICH_ACTION_OFFER, SSO_UID );
 
- 			if (!$is)
 
- 				return 0;
 
- 		}
 
- 		
 
- 		$result = $this->db ()->insert ( $this->vipquestiondao );
 
- 		
 
- 		//发邮件
 
- 		$this->send_email ( $data ['authorid'], "VIP_PAY_FORMONEY", $result, 0 );
 
- 		
 
- 		if ($result) {
 
- 			//扣除财富值--财富值记录
 
- 			if ($data ['price'] > 0) {
 
- 				
 
- 				$this->credit3logdao->qid = $result;
 
- 				
 
- 				$action = $this->credit3logdao->set_ACTION_ADD_VIP_QUESTION ();
 
- 				
 
- 				$this->credit3logdao->add_credit3_log ( $data ['authorid'], $data ['author'], $result, $action, - $price, $ip, 1 );
 
- 			}
 
- 			
 
- 			//发布系统信息
 
- 			$subject = "您的新问题(" . $result ['title'] . ")";
 
- 			
 
- 			$content = $this->messagedao->set_MESSAGE_ADD_VIP_PAID ();
 
- 			
 
- 			$this->messagedao->send_message ( ADMIN_NAME, 0, $data ['authorid'], $subject, $content );
 
- 		}
 
- 		
 
- 		return $result;
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 会话推出
 
- 	 * @param unknown_type $sid
 
- 	 */
 
- 	function delete_session($sid = "") {
 
- 		
 
- 		$rs = $this->sessiondao->get_seesion ( $sid );
 
- 		
 
- 		$this->userlogdao->uid = $rs ['uid'];
 
- 		
 
- 		$this->userlogdao->username = $rs ['username'];
 
- 		
 
- 		$this->userlogdao->ip = client_ip ();
 
- 		
 
- 		$this->userlogdao->time = get_date ();
 
- 		
 
- 		$action = $this->userlogdao->set_USER_EXIT ();
 
- 		
 
- 		$this->userlogdao->set_userlog ( $rs ['uid'], $rs ['username'], $action, client_ip () );
 
- 		
 
- 		$this->sessiondao->sid = $sid;
 
- 		
 
- 		$this->db ()->delete ( $this->sessiondao );
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 完成任务
 
- 	 * @param unknown_type $uid
 
- 	 * @param unknown_type $mission_type
 
- 	 */
 
- 	function complete_daily_crontab($uid = 0, $mission_type = 0) {
 
- 		
 
- 		$this->crontadstatusdao->complete_crontab ( $uid, $mission_type );
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 获取任务进行状态
 
- 	 * @param unknown_type $uid
 
- 	 * @param unknown_type $mission_type
 
- 	 */
 
- 	function get_crontab_status($uid = 0, $mission_type = 0) {
 
- 		
 
- 		$time = get_date ();
 
- 		//$this->crontadstatusdao->delete_crontab();
 
- 		
 
- 		//每日登录任务
 
- 		if ($mission_type == SYSTEM_DAILY_LOGIN) {
 
- 			
 
- 			$rs = $this->crontadstatusdao->get_crontab_status ( $uid, $mission_type );
 
- 			
 
- 			$day = get_today ();
 
- 			
 
- 			if (empty ( $rs )) {
 
- 				
 
- 				$this->crontadstatusdao->uid = $uid;
 
- 				
 
- 				$this->crontadstatusdao->cid = $mission_type;
 
- 				
 
- 				$this->crontadstatusdao->status = NOT_COMPLETED;
 
- 				
 
- 				$this->crontadstatusdao->time = $time;
 
- 				
 
- 				$this->db ()->insert ( $this->crontadstatusdao );
 
- 				
 
- 				return NOT_COMPLETED;
 
- 			} elseif ($rs ['time'] < $day ['start'])
 
- 				return DOING;
 
- 			elseif ($rs ['status'] != 2 && $rs ['time'] > $day ['start']) {
 
- 				return DOING;
 
- 			} else
 
- 				return COMPLETE;
 
- 		}
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 记录用户日志
 
- 	 * @param unknown_type $uid
 
- 	 * @param unknown_type $username
 
- 	 */
 
- 	function set_userlog($uid = 0, $username = "") {
 
- 		
 
- 		$this->userlogdao->uid = $uid;
 
- 		
 
- 		$this->userlogdao->username = $username;
 
- 		
 
- 		$this->userlogdao->ip = client_ip ();
 
- 		
 
- 		$this->userlogdao->time = get_date ();
 
- 		
 
- 		$this->userlogdao->action = $this->userlogdao->set_USER_LOGIN_LOG ();
 
- 		
 
- 		//设置用户日志
 
- 		$result = $this->db ()->insert ( $this->userlogdao );
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 设置会话
 
- 	 * @param unknown_type $sessionID
 
- 	 * @param unknown_type $uid
 
- 	 * @param unknown_type $username
 
- 	 * @param unknown_type $lifetime
 
- 	 */
 
- 	function set_session($sessionID = "", $uid = 0, $username = "", $lifetime = 0) {
 
- 		
 
- 		$this->sessiondao->sid = $sessionID;
 
- 		
 
- 		$this->sessiondao->uid = $uid;
 
- 		
 
- 		$this->sessiondao->username = $username;
 
- 		
 
- 		$this->sessiondao->islogin = 1;
 
- 		
 
- 		$this->sessiondao->ip = client_ip ();
 
- 		
 
- 		$this->sessiondao->time = get_date ();
 
- 		
 
- 		$this->sessiondao->lifetime = $lifetime;
 
- 		
 
- 		//设置会话
 
- 		$result = $this->db ()->insert ( $this->sessiondao );
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 添加用户--是否要发系统信息
 
- 	 */
 
- 	function add_user($username = "", $password = "") {
 
- 		
 
- 		$this->userdao->username = $username;
 
- 		
 
- 		$this->userdao->password = $password;
 
- 		
 
- 		$this->userdao->groupid = USER_LV1;
 
- 		
 
- 		$this->userdao->credits = POINT_REGISTER;
 
- 		
 
- 		$this->userdao->credit1 = POINT_REGISTER;
 
- 		
 
- 		$this->userdao->regip = client_ip ();
 
- 		
 
- 		$this->userdao->regtime = get_date ();
 
- 		
 
- 		//添加用户
 
- 		$result = $this->db ()->insert ( $this->userdao );
 
- 		
 
- 		//注册加20分
 
- 		$this->creditdao->set_credit_log ( $result, ACTION_REGISTER, POINT_REGISTER, 0, 0 );
 
- 		
 
- 		return $result;
 
- 	}
 
- 	/**
 
- 	 * 添加用户--是否要发系统信息
 
- 	 */
 
- 	function add_user2($param) {
 
- 		$this->userdao->username = $param['username'];
 
- 		$this->userdao->password = $param['password'];
 
- 		$this->userdao->email = $param['email'];
 
- 		$this->userdao->phone = $param['mobile'];
 
- 		$this->userdao->groupid = USER_LV1;
 
- 		$this->userdao->credits = POINT_REGISTER;
 
- 		$this->userdao->credit1 = POINT_REGISTER;
 
- 		$this->userdao->regip = client_ip ();
 
- 		$this->userdao->regtime = get_date ();
 
- 		//添加用户
 
- 		$result = $this->db ()->insert ( $this->userdao );
 
- 		//注册加20分
 
- 		$this->creditdao->set_credit_log ( $result, ACTION_REGISTER, POINT_REGISTER, 0, 0 );
 
- 		return $result;
 
- 	}
 
- 	/**
 
- 	 * 更新用户信息
 
- 	 * @param unknown_type $params
 
- 	 */
 
- 	function update_user2($id,$params) {
 
- 		$this->userdao->uid = $id;
 
- 		$this->userdao->phone = $params ['phone'];
 
- 		$this->userdao->password = md5 ( $params ['password'] );
 
- 		$this->userdao->email = $params ['email'];
 
- 		$this->userdao->groupid = $params ['groupid'];
 
- 		$this->userdao->credits = $params ['credits'];
 
- 		$this->userdao->credit1 = $params ['credit1'];
 
- 		$this->userdao->gender = $params ['gender'];
 
- 		$this->userdao->bday = $params ['bday'];
 
- 		$this->userdao->qq = $params ['qq'];
 
- 		$this->userdao->msn = $params ['msn'];
 
- 		$this->userdao->signature = $params ['signature'];
 
- 		$this->userdao->expert = $params ['expert'];
 
- 		$this->userdao->cids=$params['cids'];
 
- 		$result = $this->db ()->update ( $this->userdao );
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 根据用户ID删除,和删除相关信息
 
- 	 */
 
- 	function delete_user_tem($uid = 0) {
 
- 		
 
- 		//删除问题
 
- 		$this->questiondao->delete_question_by_authorid ( $uid );
 
- 		
 
- 		//删除回答
 
- 		$this->answerdao->delete_answer_by_authorid ( $uid );
 
- 		
 
- 		//删除用户积分记录--之后还有财富记录
 
- 		$this->creditdao->delete_credit_by_uid ( $uid );
 
- 		
 
- 		$this->userdao->uid = $uid;
 
- 		
 
- 		$this->db ()->delete ( $this->userdao );
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 将问题设置为未解决-值针对已关闭
 
- 	 * @param unknown_type $id
 
- 	 */
 
- 	function update_question_list($id = array()) {
 
- 		
 
- 		$id=implode(",", $id);
 
- 		
 
- 		$queList=array();
 
- 		
 
- 		if(!empty($id))
 
- 			$queList=$this->questiondao->get_questions_By_Idlist($id);
 
- 			
 
- 		foreach ($queList as $key=>$value){
 
- 			
 
- 			$question = new QuestionDao ();
 
- 			
 
- 			$question->id=$value['id'];
 
- 			
 
- 			$question->status=QUESTOIN_STATUS_UNRESOLVED;
 
- 			
 
- 			$question->time=time();
 
- 			
 
- 			$question->update();
 
- 		}	
 
- 		
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 删除选中问题
 
- 	 * @param unknown_type $id
 
- 	 */
 
- 	function delete_question_list($id = array()) {
 
- 		
 
- 		$this->questiondao->delete_question_list ( $id );
 
- 		
 
- 		//删除索引
 
- 		$this->delete_search_index ( $id, SEARCH_WD_DB, SEARCH_INI );
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 删除选中问题
 
- 	 * @param unknown_type $id
 
- 	 */
 
- 	function delete_answer_list($id = array()) {
 
- 		
 
- 		$this->answerdao->delete_answer_list ( $id );
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 删除一个用户组
 
- 	 * @param unknown_type $groupid
 
- 	 */
 
- 	function delete_group($groupid = 0) {
 
- 		if ($groupid <= GROUPIDLIMIT)
 
- 			return false;
 
- 		
 
- 		$this->groupdao->groupid = $groupid;
 
- 		
 
- 		$this->db ()->delete ( $this->groupdao );
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 添加一条用户组
 
- 	 * @param unknown_type $params
 
- 	 */
 
- 	function add_group($params = array()) {
 
- 		if (empty ( $params ))
 
- 			return false;
 
- 		
 
- 		$this->groupdao->grouptitle = $params ['grouptitle'];
 
- 		
 
- 		$this->groupdao->grouptype = 2;
 
- 		
 
- 		$result = $this->db ()->insert ( $this->groupdao );
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 批量更新用户组
 
- 	 * @param unknown_type $params
 
- 	 */
 
- 	function update_group_list($params) {
 
- 		$pa = array ();
 
- 		
 
- 		$co = array ();
 
- 		
 
- 		$wh = array ();
 
- 		
 
- 		$count = count ( $params ['groupid'] );
 
- 		
 
- 		foreach ( $params as $key => $value ) {
 
- 			array_push ( $pa, $key );
 
- 			
 
- 			if ($key != "groupid") {
 
- 				array_push ( $wh, $key . "=VALUES(" . $key . ")" );
 
- 			}
 
- 		}
 
- 		//获取更新内容
 
- 		for($i = 0; $i < $count; $i ++) {
 
- 			
 
- 			$tm = array ();
 
- 			
 
- 			foreach ( $pa as $k ) {
 
- 				
 
- 				array_push ( $tm, "'" . $params [$k] [$i] . "'" );
 
- 			}
 
- 			
 
- 			$tm = implode ( ",", $tm );
 
- 			
 
- 			array_push ( $co, "(" . $tm . ")" );
 
- 		}
 
- 		
 
- 		$pa = implode ( ",", $pa );
 
- 		
 
- 		$wh = implode ( ",", $wh );
 
- 		
 
- 		$co = implode ( ",", $co );
 
- 		
 
- 		$this->groupdao->update_group_list ( $pa, $co, $wh );
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 删除用户和问答
 
- 	 * @param unknown_type $uid
 
- 	 */
 
- 	function delete_user_and_QA($uid = array()) {
 
- 		
 
- 		$this->userdao->delete_user_and_QA ( $uid );
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 删除用户
 
- 	 * @param unknown_type $uid
 
- 	 */
 
- 	function delete_user($uid = array()) {
 
- 		
 
- 		$this->userdao->delete_user ( $uid );
 
- 	}
 
- 	
 
- 	function update_user_avatar_by_id($uid, $avatar) {
 
- 		Doo::loadModel ( 'UserDao' );
 
- 		
 
- 		$userdao = new UserDao ();
 
- 		
 
- 		$userdao->uid = $uid;
 
- 		
 
- 		$userdao->avatar = $avatar;
 
- 		
 
- 		$userdao->lastlogin = time ();
 
- 		
 
- 		$result = $this->db ()->update ( $userdao );
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 更新用户信息
 
- 	 * @param unknown_type $params
 
- 	 */
 
- 	function update_user($params) {
 
- 		$this->userdao->uid = $params ['uid'];
 
- 		
 
- 		$this->userdao->phone = $params ['phone'];
 
- 		
 
- 		$this->userdao->password = md5 ( $params ['password'] );
 
- 		
 
- 		$this->userdao->email = $params ['email'];
 
- 		
 
- 		$this->userdao->groupid = $params ['groupid'];
 
- 		
 
- 		$this->userdao->credits = $params ['credits'];
 
- 		
 
- 		$this->userdao->credit1 = $params ['credit1'];
 
- 		
 
- 		$this->userdao->gender = $params ['gender'];
 
- 		
 
- 		$this->userdao->bday = $params ['bday'];
 
- 		
 
- 		$this->userdao->qq = $params ['qq'];
 
- 		
 
- 		$this->userdao->msn = $params ['msn'];
 
- 		
 
- 		$this->userdao->signature = $params ['signature'];
 
- 		
 
- 		$this->userdao->expert = $params ['expert'];
 
- 		
 
- 		$this->userdao->cids=$params['cids'];
 
- 		
 
- 		$result = $this->db ()->update ( $this->userdao );
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 更新退款机会
 
- 	 * @param unknown_type $refunds
 
- 	 */
 
- 	function update_user_refunds($refunds = array()) {
 
- 		$this->userdao->uid = $refunds ['uid'];
 
- 		
 
- 		$this->userdao->refunds = $refunds ['refunds'];
 
- 		
 
- 		$result = $this->db ()->update ( $this->userdao );
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 获取用户组
 
- 	 */
 
- 	function get_group() {
 
- 		$result = $this->groupdao->get_group ();
 
- 		
 
- 		$re = array ('sys' => array (), 'user' => array (), 'vip_user' => array () );
 
- 		
 
- 		foreach ( $result as $value ) {
 
- 			
 
- 			if ($value ['grouptype'] == 1)
 
- 				array_push ( $re ['sys'], $value );
 
- 			elseif ($value ['grouptype'] == 2)
 
- 				array_push ( $re ['user'], $value );
 
- 			elseif ($value ['grouptype'] == 3)
 
- 				array_push ( $re ['vip_user'], $value );
 
- 		}
 
- 		
 
- 		return $re;
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 设置赞同数
 
- 	 * @param unknown_type $aid
 
- 	 * @param unknown_type $uid 登录者UID
 
- 	 */
 
- 	function update_support_answer($aid = 0, $uid = 0) {
 
- 		$user = $this->userdao->get_userinfo_by_uid ( $uid );
 
- 		
 
- 		$aids_ar = explode ( ",", $user ['aids'] );
 
- 		
 
- 		if (in_array ( $aid, $aids_ar ))
 
- 			return false;
 
- 		
 
- 		//记录谁赞同
 
- 		$data ['aids'] = $user ['aids'] . "," . $aid;
 
- 		if (empty ( $user ['aids'] ))
 
- 			$data ['aids'] = $aid;
 
- 		
 
- 		$condition = " ,elect=elect+1 where uid = " . $uid;
 
- 		
 
- 		$this->userdao->update_user ( $data, $condition );
 
- 		
 
- 		//更新赞同数
 
- 		$this->answerdao->update_support_answer ( $aid );
 
- 		
 
- 		//更新赞同操作
 
- 		$rs = $this->answerdao->get_answer_by_id ( $aid );
 
- 		
 
- 		$this->questiondao->set_question_goods ( $rs ['qid'] );
 
- 		
 
- 		//加积分
 
- 		$this->set_credit1 ( 'add', $user ['uid'], POINT_SUPPORT, ACTION_SUPPORT );
 
- 		
 
- 		return true;
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 设置最佳答案--整理
 
- 	 * @param unknown_type $qid
 
- 	 */
 
- 	function set_best_answer($data = array()) {
 
- 		
 
- 		$type = "ADOPT_ANSWER";
 
- 		
 
- 		if ($data ['price'] > 0) {
 
- 			//获取回答用户的通行证ID
 
- 			$sso_info = $this->get_sso_user_info_by_name ( $data ['username'] );
 
- 			
 
- 			$is = $this->set_credit3 ( + $data ['price'], $data ['auid'], RICH_ACTION_ADOPT, $sso_info [0] ['id'] );
 
- 			
 
- 			$type = "PAY_ADOPT_ANSWER";
 
- 			
 
- 			if ($is == 0)
 
- 				return $is;
 
- 		}
 
- 		
 
- 		//更新问题
 
- 		$data_question ['endtime'] = get_date ();
 
- 		
 
- 		$data_question ['status'] = ADOPT;
 
- 		
 
- 		$condition = " where id = " . $data ['qid'];
 
- 		
 
- 		$this->questiondao->update_question ( $data_question, $condition );
 
- 		
 
- 		//更新答案
 
- 		$data_answer ['adopttime'] = $data_question ['endtime'];
 
- 		
 
- 		$data_answer ['comment'] = $data ['comment'];
 
- 		
 
- 		$data_answer ['status'] = ADOPT;
 
- 		
 
- 		$condition = " where id = " . $data ['aid'];
 
- 		
 
- 		$this->answerdao->update_answer ( $data_answer, $condition );
 
- 		
 
- 		//发送邮件
 
- 		$this->send_email ( $data ['auid'], $type, $data ['qid'], $data ['aid'] );
 
- 		
 
- 		//更新回答用户信息积分信息
 
- 		$this->userdao->add_credit1 ( POINT_ADOPT, $data ['auid'], ACTION_ADOPT );
 
- 		
 
- 		if ($data ['price'] > 0) {
 
- 			//财富操作记录, 将用户财富划到回答方
 
- 			//$this->userdao->add_credit3 ( + $data ['price'], $data ['auid'], RICH_ACTION_ADOPT );
 
- 			
 
- 			//财富流向表
 
- 			$this->credit3logdao->qid = $data ['qid'];
 
- 			
 
- 			$this->credit3logdao->ip = client_ip ();
 
- 			
 
- 			$this->credit3logdao->amount = $data ['price'];
 
- 			
 
- 			$this->credit3logdao->username = $data ['username'];
 
- 			
 
- 			$this->credit3logdao->time = get_date ();
 
- 			
 
- 			$action = $this->credit3logdao->set_ACTION_ADOPT_QUESTION ();
 
- 			
 
- 			$this->credit3logdao->add_credit3_log ( $data ['auid'], $data ['username'], $data ['qid'], $action, $data ['price'], $this->credit3logdao->ip );
 
- 		}
 
- 		
 
- 		//更新该用户的采纳数
 
- 		$this->userdao->add_adopts ( $data ['auid'], 1 );
 
- 		
 
- 		$p = "";
 
- 		if ($data ['price'] > 0)
 
- 			$p = "<span class=colOrange >获得¥" . $data ['price'] . "元</span>";
 
- 		
 
- 		//发送系统信息-发送给发回答用户  
 
- 		$subject = "回答 <a href=/askpage/" . $data ['qid'] . " >" . $data ['title'] . "</a> 被采纳为最佳答案 " . $p;
 
- 		
 
- 		$content = "回答 <a href=/askpage/" . $data ['qid'] . " >" . $data ['title'] . "</a> 被采纳为最佳答案 " . $p;
 
- 		
 
- 		$this->messagedao->send_message ( ADMIN_NAME, 0, $data ['auid'], $subject, $content );
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 获取通行证用户头像--
 
- 	 * @param unknown_type $username
 
- 	 */
 
- 	function get_user_avatar_by_username($username = "", $client = "") {
 
- 		if (empty ( $client )) {
 
- 			require_once (SITE_PATH . '/protected/plugin/client.php');
 
- 			
 
- 			$client = new client ( ZHSSO );
 
- 		}
 
- 		$avatar = array ('180' => DEF_AVATAR, '30' => DEF_AVATAR, '90' => DEF_AVATAR, '45' => DEF_AVATAR );
 
- 		
 
- 		$userinfo = $client->zhsso_getUserbyName ( $username );
 
- 		
 
- 		$userinfo = explode ( "\r", $userinfo );
 
- 		
 
- 		$ts = json_decode ( $userinfo ['1'], true );
 
- 		//$avatar = $client->url_exists($client->ps_getavatar($ts[0]['id'])) ? $client->ps_getavatar($ts[0]['id']) : DEF_AVATAR;
 
- 		if (isset ( $ts ) && ! empty ( $ts )) {
 
- 			$avatar = $client->ps_getavatar ( $ts [0] ['id'] );
 
- 		}
 
- 		
 
- 		return $avatar;
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 获取用户相关信息
 
- 	 * @param unknown_type $data
 
- 	 * @param unknown_type $condition
 
- 	 * @param unknown_type $limit
 
- 	 */
 
- 	function get_users_list($data = array(), $condition = "", $limit = "") {
 
- 		
 
- 		$result = $this->userdao->get_users_list ( $data, $condition, $limit );
 
- 		
 
- 		$src = "";
 
- 		
 
- 		$now = 1;
 
- 		
 
- 		foreach ( $result as $key => $value ) {
 
- 			$lv = get_lv ( $value ['credit1'] );
 
- 			
 
- 			$result [$key] ['lv'] = $lv [0];
 
- 			
 
- 			$result [$key] ['lv_max'] = $lv [1];
 
- 			
 
- 			$result [$key] ['lv_need'] = $lv [1] - $value ['credit1'];
 
- 			
 
- 			$result [$key] ['lv_percent'] = $value ['credit1'] / $lv [1] * 100;
 
- 			
 
- 			$result [$key] ['category'] = "";
 
- 			
 
- 			$result [$key] ['question'] = "";
 
- 			
 
- 			$result [$key] ['lastlogin'] = my_date_format2 ( $value ['lastlogin'], "Y-m-d H:i:s" );
 
- 			
 
- 			//$avatar = $this->get_user_avatar_by_username ( $value ['username'] );
 
- 			
 
- 			$avatar = json_decode ( $value ['avatar'], true );
 
- 			
 
- 			if (empty ( $avatar ))
 
- 				$avatar = array ('180' => DEF_AVATAR, '30' => DEF_AVATAR, '90' => DEF_AVATAR, '45' => DEF_AVATAR );
 
- 			
 
- 			$result [$key] ['avatar'] = $avatar;
 
- 			
 
- 			$cidsList = json_decode ( $value ['cids'] );
 
- 		
 
- 			if(!empty($cidsList)){
 
- 				foreach ( $cidsList as $c_key => $values ) {
 
- 					
 
- 					$list = explode ( ":", $values );
 
- 					
 
- 					$src .= "<a href='/index_c/" . $list[0] . "'>" .$list[1] . "</a> ";
 
- 					
 
- 				}
 
- 				
 
- 				$result [$key] ['category'] = $src;
 
- 			}
 
- 			
 
- 			//读取专家分类
 
- //			if (! empty ( $value ['cids'] )) {
 
- //				$condition = " and id in (" . $value ['cids'] . ") ";
 
- //				
 
- //				$c_result = $this->categorydao->get_category_list ( array (), $condition, "" );
 
- //				
 
- //				$src = "";
 
- //				
 
- //				foreach ( $c_result as $c_key => $c_value ) {
 
- //					
 
- //					$src .= "<a href='/index_c/" . $c_value ['id'] . "'>" . $c_value ['name'] . "</a> ";
 
- //				}
 
- //				$result [$key] ['category'] = $src;
 
- //			}
 
- 			
 
- 			$result [$key] ['now'] = $now;
 
- 			
 
- 			//获取相关问题
 
- 			$param ['authorid'] = $value ['uid'];
 
- 			
 
- 			$limit = " order by time desc limit 0 , 3 ";
 
- 			
 
- 			$q_result = $this->get_list ( $param, "", $limit, t_answer );
 
- 			
 
- 			$src = "";
 
- 			
 
- 			if (! empty ( $q_result )) {
 
- 				foreach ( $q_result as $q_key => $q_value ) {
 
- 					
 
- 					$src .= "<a href='/askpage/" . $q_value ['qid'] . "'>" . $q_value ['title'] . "</a>";
 
- 				}
 
- 				$result [$key] ['question'] = $src;
 
- 			}
 
- 			
 
- 			$now ++;
 
- 		}
 
- 		
 
- 		return $result;
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 根据用户名获取信息
 
- 	 */
 
- 	function get_users_by_name($username = "") {
 
- 		
 
- 		$result = $this->userdao->get_users_by_name ( $username );
 
- 		
 
- 		return $result;
 
- 	}
 
- 	
 
- 	function get_group_by_id($id = 0) {
 
- 		$rs = $this->groupdao->get_group_by_id ( $id );
 
- 		
 
- 		return $rs;
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 获取用户基本信息
 
- 	 * @param unknown_type $uid
 
- 	 * @return $result array;
 
- 	 */
 
- 	function get_users_information($uid = 0) {
 
- 		
 
- 		if ($uid == 0 || (! is_numeric ( $uid )))
 
- 			return array ();
 
- 		
 
- 		$result = $this->userdao->get_userinfo_by_uid ( $uid );
 
- 		
 
- 		if (empty ( $result ))
 
- 			return array ();
 
- 		
 
- 		$lv = get_lv ( $result ['credit1'] );
 
- 		
 
- 		$result ['lv'] = $lv [0];
 
- 		
 
- 		$result ['lv_max'] = $lv [1];
 
- 		
 
- 		$result ['lv_need'] = $lv [1] - $result ['credit1'];
 
- 		
 
- 		$result ['lv_percent'] = $result ['credit1'] / $lv [1] * 100;
 
- 		
 
- 		$result ['credit3'] = 0;
 
- 		
 
- 		if (defined ( 'CREDIT3' ))
 
- 			$result ['credit3'] = CREDIT3;
 
- 		
 
- 		$result ['email'] = "";
 
- 		
 
- 		if (defined ( 'EMAIL' ))
 
- 			$result ['email'] = EMAIL;
 
- 		
 
- 		$cidsList = json_decode ( $result ['cids'] );
 
- 		
 
- 		$cids=array();
 
- 		
 
- 		$cids_key = array ();
 
- 		
 
- 		$cids_name = array ();
 
- 		
 
- 		if(!empty($cidsList)){
 
- 			foreach ( $cidsList as $key => $value ) {
 
- 				
 
- 				$list = explode ( ":", $value );
 
- 				
 
- 				array_push ( $cids_key, $list [0] );
 
- 				
 
- 				array_push ( $cids_name, $list [1] );
 
- 			}
 
- 			
 
- 			$result ['cids'] = implode(",", $cids_key);
 
- 			
 
- 			$cids = array_combine($cids_key, $cids_name);  
 
- 			
 
- 			$result ['cids_json'] = $cids;
 
- 		}
 
- 		return $result;
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 添加一个问题
 
- 	 * @param unknown_type $data
 
- 	 * @return $result 问题ID;
 
- 	 */
 
- 	function add_examine_question($data = array()) {
 
- 	
 
- 		$this->examinedao->title = $data ['title'];
 
- 		$this->examinedao->cid = $data ['category_id'];
 
- 		$this->examinedao->description = $data ['description'];
 
- 		//取绝对值
 
- 		$price = abs ( $data ['price'] );
 
- 		$this->examinedao->price = $price;
 
- 		
 
- 		$this->examinedao->author = $data ['author'];
 
- 		$this->examinedao->authorid = $data ['authorid'];
 
- 		$this->examinedao->time = get_date ();
 
- 		$this->examinedao->endtime = get_date ( 15 );
 
- 		$this->examinedao->ip = client_ip ();
 
- 		
 
- 		$result = $this->db ()->insert ( $this->examinedao );
 
- 		
 
- 		//添加提问数
 
- 		//$this->set_questions ( 'add', $data ['authorid'], $data ['category_id'] );
 
- 		
 
- 		return $result;
 
- 		
 
- 		/**
 
- 		 * --------------------
 
- 		
 
- 		//审批成功后 才记录一下相关信息
 
- 		
 
- 		$this->credit3logdao->ip = $this->questiondao->ip;
 
- 		$this->credit3logdao->amount = $price;
 
- 		$this->credit3logdao->username = $data ['author'];
 
- 		$this->credit3logdao->uid = $data ['authorid'];
 
- 		$this->credit3logdao->time = $this->questiondao->time;
 
- 		
 
- 		//扣除金额后才可以添加问题
 
- 		if ($data ['price'] > 0) {
 
- 			$is = $this->set_credit3 ( - $data ['price'], $data ['authorid'], RICH_ACTION_OFFER, SSO_UID );	
 
- 			if ($is == 0)
 
- 				return 0;
 
- 		}
 
- 	
 
- 		//推广手段
 
- 		if($data['price']==0){
 
- 			$fundstr=file_get_contents(SITE_PATH . '/protected/config/fund.conf.php') ;
 
- 			if($fundstr){
 
- 				//获取基金
 
- 				Doo::loadModel ( 'FundDao' );
 
- 				$funddao = new FundDao ();
 
- 				$fund=$funddao->get_fund_by_amount();
 
- 				if(!empty($fund)){
 
- 					$funddao->set_fund_amount_spread("-1",$fund['id']);
 
- 					$this->questiondao->price=1;
 
- 				}
 
- 			}
 
- 		}
 
- 	
 
- 		//发送邮件
 
- 		if ($data ['price'] > 0) {
 
- 				
 
- 			$this->send_email ( $data ['authorid'], "PAY_FORMONEY", $result, 0 );
 
- 		}
 
- 	
 
- 		//是否需要优化
 
- 		if ($result) {
 
- 			//扣除财富值--财富值记录
 
- 			if ($data ['price'] > 0) {
 
- 				$this->credit3logdao->qid = $result;
 
- 	
 
- 				$action = $this->credit3logdao->set_ACTION_OFFER_QUESTION ();
 
- 	
 
- 				$this->credit3logdao->add_credit3_log ( $data ['authorid'], $data ['author'], $result, $action, - $price, $this->questiondao->ip );
 
- 			}
 
- 				
 
- 			//更新今天发布数--需要修改每时间段的更新次数
 
- 			$this->authissuedao->set_authissue_totals ( $data ['authorid'] );
 
- 			
 
- 			//添加积分值
 
- 			$this->set_credit1 ( 'add', $data ['authorid'], CREDIT_POINT_ADD, CREDIT_ACTION_ADD );
 
- 		}
 
- 	
 
- 		return $result;
 
- 		 */
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 添加一个问题
 
- 	 * @param unknown_type $data
 
- 	 * @return $result 问题ID;
 
- 	 */
 
- 	function add_question($data = array()) {
 
- 		
 
- 		$this->questiondao->title = $data ['title'];
 
- 		
 
- 		$this->questiondao->cid = $data ['category_id'];
 
- 		
 
- 		$this->questiondao->description = $data ['description'];
 
- 		//取绝对值
 
- 		$price = abs ( $data ['price'] );
 
- 		$this->questiondao->price = $price;
 
- 		$this->credit3logdao->amount = $price;
 
- 		
 
- 		$this->questiondao->author = $data ['author'];
 
- 		$this->credit3logdao->username = $data ['author'];
 
- 		
 
- 		$this->questiondao->authorid = $data ['authorid'];
 
- 		$this->credit3logdao->uid = $data ['authorid'];
 
- 		
 
- 		$this->questiondao->time = get_date ();
 
- 		$this->credit3logdao->time = $this->questiondao->time;
 
- 		
 
- 		$this->questiondao->endtime = get_date ( 15 );
 
- 		
 
- 		$this->questiondao->ip = client_ip ();
 
- 		$this->credit3logdao->ip = $this->questiondao->ip;
 
- 		
 
- 		//扣除金额后才可以添加问题
 
- 		if ($data ['price'] > 0) {
 
- 			
 
- 			$is = $this->set_credit3 ( - $data ['price'], $data ['authorid'], RICH_ACTION_OFFER, SSO_UID );
 
- 			
 
- 			if ($is == 0)
 
- 				return 0;
 
- 		}
 
- 		
 
- 		//推广手段
 
- 		if($data['price']==0){
 
- 			$fundstr=file_get_contents(SITE_PATH . '/protected/config/fund.conf.php') ;
 
- 			if($fundstr){
 
- 				//获取基金
 
- 				Doo::loadModel ( 'FundDao' );
 
- 				
 
- 				$funddao = new FundDao ();
 
- 				
 
- 				$fund=$funddao->get_fund_by_amount();
 
- 				
 
- 				if(!empty($fund)){
 
- 					
 
- 					$funddao->set_fund_amount_spread("-1",$fund['id']);
 
- 					
 
- 					$this->questiondao->price=1;
 
- 				}
 
- 			}
 
- 		}
 
- 		
 
- 		$result = $this->db ()->insert ( $this->questiondao );
 
- 		
 
- 		//发送邮件
 
- 		if ($data ['price'] > 0) {
 
- 			
 
- 			$this->send_email ( $data ['authorid'], "PAY_FORMONEY", $result, 0 );
 
- 		}
 
- 		
 
- 		//是否需要优化
 
- 		if ($result) {
 
- 			
 
- 			//加入检索索引-分词还未加入-数据配置
 
- 			//$pams = array ('id' => $result, 'cid' => $data ['category_id'], 'price' => $price, 'authorid' => $data ['authorid'], 'author' => $data ['author'], 'title' => $data ['title'], 'description' => $data ['description'], 'time' => $this->questiondao->time, 'status' => QUESTOIN_STATUS_UNRESOLVED );
 
- 			
 
- 			//$this->add_search_index ( $pams );
 
- 			
 
- 			//扣除财富值--财富值记录
 
- 			if ($data ['price'] > 0) {
 
- 				$this->credit3logdao->qid = $result;
 
- 				
 
- 				$action = $this->credit3logdao->set_ACTION_OFFER_QUESTION ();
 
- 				
 
- 				$this->credit3logdao->add_credit3_log ( $data ['authorid'], $data ['author'], $result, $action, - $price, $this->questiondao->ip );
 
- 			}
 
- 			
 
- 			//更新今天发布数--需要修改每时间段的更新次数
 
- 			$this->authissuedao->set_authissue_totals ( $data ['authorid'] );
 
- 			
 
- 			//发布系统信息 
 
- 			//$subject = "问题  " . $result ['title'] . " 新的问题";
 
- 			//			
 
- 			//$content = $this->messagedao->set_MESSAGE_ADD_QUESTION ( $data ['title'], $result );
 
- 			//			
 
- 			//$this->messagedao->send_message ( ADMIN_NAME, 0, $data ['authorid'], $subject, $content );
 
- 			//			
 
- 			//添加提问数
 
- 			$this->set_questions ( 'add', $data ['authorid'], $data ['category_id'] );
 
- 			
 
- 			//添加积分值
 
- 			$this->set_credit1 ( 'add', $data ['authorid'], CREDIT_POINT_ADD, CREDIT_ACTION_ADD );
 
- 		}
 
- 		
 
- 		return $result;
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 更新检索库
 
- 	 * @param unknown_type $params
 
- 	 */
 
- 	function update_vip_question_search($params) {
 
- 		
 
- 		//$pams = array ('id' => $params ['vip_question'] ['id'], 'answers' => 1, 'answer' => $params ['answer'], 'title' => $params ['vip_question'] ['title'], 'price' => $params ['vip_question'] ['price'], 'author' => $params ['vip_question'] ['author'], 'authorid' => $params ['vip_question'] ['authorid'], 'description' => $params ['vip_question'] ['description'], 'supply' => $params ['vip_question'] ['supply'], 'time' => $params ['vip_question'] ['time_stamp'], 'hot' => $params ['vip_question'] ['hot'] );
 
- 		
 
- 		//$this->update_search_index ( $pams, SEARCH_VWD_DB, SEARCH_VIP_INI );
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 设置积分值
 
- 	 * @param unknown_type $type add or take_out
 
- 	 * @param unknown_type $uid
 
- 	 * @param unknown_type $point
 
- 	 * @param unknown_type $action_type
 
- 	 */
 
- 	function set_credit1($type = 'add', $uid = 0, $point = 0, $action_type = "") {
 
- 		
 
- 		if ("add" == $type)
 
- 			return $this->userdao->add_credit1 ( $point, $uid, $action_type );
 
- 		
 
- 		else if ("take_out" == $type)
 
- 			return $this->userdao->take_out_credit1 ( $point, $uid, $action_type );
 
- 		
 
- 		else
 
- 			return false;
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 设置财富值
 
- 	 * @param unknown_type $type	add or take_out
 
- 	 * @param unknown_type $price
 
- 	 * @return error_message
 
- 	 */
 
- 	function set_credit3($price = 0, $uid = 0, $action_type = "", $sso_uid = 0) {
 
- 		if ($sso_uid == 0)
 
- 			return 0;
 
- 		$sso_price = abs ( $price );
 
- 		//扣除或者增加通行证金额
 
- 		if ($price < 0)
 
- 			$is = $this->offer_price_by_sso ( $sso_price, $sso_uid );
 
- 		else
 
- 			$is = $this->add_price_by_sso ( $sso_price, $sso_uid );
 
- 		if ($is <= 0)
 
- 			return 0;
 
- 		$this->userdao->add_credit3 ( $price, $uid, $action_type );
 
- 		
 
- 		return $is;
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 设置提问数
 
- 	 * @param unknown_type $type
 
- 	 * @param unknown_type $uid
 
- 	 */
 
- 	function set_questions($type = 'add', $uid = 0, $category_id = 0) {
 
- 		
 
- 		if ("add" == $type)
 
- 			return $this->userdao->add_questions ( $uid, $category_id );
 
- 		
 
- 		else if ("take_out" == $type)
 
- 			return $this->userdao->take_out_questions ( $uid, $category_id );
 
- 		
 
- 		else
 
- 			return false;
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 设置回答数
 
- 	 * @param unknown_type $type
 
- 	 * @param unknown_type $uid	回答问题人UID
 
- 	 * @param unknown_type $qid	回答问题ID
 
- 	 */
 
- 	function set_answers($type = 'add', $uid = 0, $qid = 0) {
 
- 		
 
- 		if ("add" == $type)
 
- 			return $this->userdao->add_answers ( $uid, $qid );
 
- 		
 
- 		else if ("take_out" == $type)
 
- 			return $this->userdao->take_out_answers ( $uid, $qid );
 
- 		
 
- 		else
 
- 			return false;
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 添加一个回答
 
- 	 * @param unknown_type $data
 
- 	 */
 
- 	function add_answer($data = array()) {
 
- 		
 
- 		$this->answerdao->qid = $data ['qid'];
 
- 		
 
- 		$this->answerdao->title = $data ['title'];
 
- 		
 
- 		$this->answerdao->author = $data ['author'];
 
- 		
 
- 		$this->answerdao->authorid = $data ['authorid'];
 
- 		
 
- 		$this->answerdao->content = $data ['content'];
 
- 		
 
- 		$this->answerdao->time = get_date ();
 
- 		
 
- 		$this->answerdao->status = 1;
 
- 		
 
- 		$this->answerdao->ip = client_ip ();
 
- 		
 
- 		$result = $this->db ()->insert ( $this->answerdao );
 
- 		
 
- 		if ($result > 0) {
 
- 			
 
- 			$question = $this->questiondao->get_question_by_id ( $data ['qid'] );
 
- 			
 
- 			//添加回答数
 
- 			$this->set_answers ( 'add', $data ['authorid'], $data ['qid'] );
 
- 			
 
- 			//添加积分值
 
- 			$this->set_credit1 ( 'add', $data ['authorid'], CREDIT_POINT_ANSWER, CREDIT_ACTION_ANSWER );
 
- 			
 
- 			$subject = "问题 <a href=/askpage/" . $data ['qid'] . " >" . $data ['title'] . "</a> 有新的回答";
 
- 			
 
- 			$content = "问题 <a href=/askpage/" . $data ['qid'] . " >" . $data ['title'] . "</a> 有新的回答";
 
- 			
 
- 			$this->messagedao->send_message ( ADMIN_NAME, 0, $question ['authorid'], $subject, $content );
 
- 			
 
- 			$answer_list = $this->answerdao->get_answer_user_info_by_id ( $data ['qid'] );
 
- 			
 
- 			$answer = array ();
 
- 			
 
- 			foreach ( $answer_list as $key => $value ) {
 
- 				$ans = array ();
 
- 				
 
- 				$ans ['id'] = $value ['id'];
 
- 				
 
- 				$ans ['qid'] = $value ['qid'];
 
- 				
 
- 				$ans ['title'] = $value ['title'];
 
- 				
 
- 				$ans ['authorid'] = $value ['authorid'];
 
- 				
 
- 				$ans ['author'] = $value ['author'];
 
- 				
 
- 				$ans ['time'] = get_date ();
 
- 				
 
- 				$ans ['adopttime'] = $value ['adopttime'];
 
- 				
 
- 				$ans ['content'] = $value ['content'];
 
- 				
 
- 				$ans ['comment'] = $value ['comment'];
 
- 				
 
- 				array_push ( $answer, $ans );
 
- 			}
 
- 			
 
- 			$ans = array ();
 
- 			
 
- 			$ans ['id'] = $result;
 
- 			
 
- 			$ans ['qid'] = $data ['qid'];
 
- 			
 
- 			$ans ['title'] = $data ['title'];
 
- 			
 
- 			$ans ['authorid'] = $data ['authorid'];
 
- 			
 
- 			$ans ['author'] = $data ['author'];
 
- 			
 
- 			$ans ['time'] = $this->answerdao->time;
 
- 			
 
- 			$ans ['content'] = $data ['content'];
 
- 			
 
- 			array_push ( $answer, $ans );
 
- 			
 
- 			$answer = serialize ( $answer );
 
- 			
 
- 			//更新检索库
 
- 			//$pams = array ('id' => $data ['qid'], 'cid' => $question ['cid'], 'cid1' => $question ['cid1'], 'cid2' => $question ['cid2'], 'price' => $question ['price'], 'authoid' => $data ['authorid'], 'author' => $data ['author'], 'title' => $data ['title'], 'description' => $question ['description'], 'supply' => $question ['supply'], 'time' => $question ['time'], 'status' => QUESTOIN_STATUS_UNRESOLVED, 'answers' => $question ['answers'], 'answer' => $answer );
 
- 			//$this->update_search_index ( $pams );
 
- 		
 
- 		}
 
- 		return $result;
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 删除一个回答
 
- 	 * @param unknown_type $aid
 
- 	 */
 
- 	function delete_answer($aid = 0, $qid = 0) {
 
- 		$this->answerdao->id = $aid;
 
- 		
 
- 		$rs = $this->answerdao->get_answer_by_id ( $aid );
 
- 		
 
- 		$subject = "回答 " . $rs ['title'] . " 违规被删除";
 
- 		
 
- 		$content = "回答 " . $rs ['title'] . " <span class=colRed >违规被删除</span>";
 
- 		
 
- 		$this->messagedao->send_message ( ADMIN_NAME, 0, $rs ['authorid'], $subject, $content );
 
- 		
 
- 		$this->db ()->delete ( $this->answerdao );
 
- 		
 
- 		$question = $this->questiondao->get_question_by_id ( $qid );
 
- 		
 
- 		//回答数更新
 
- 		$this->set_answers ( 'take_out', $question ['authorid'], $qid );
 
- 		
 
- 		//扣除积分
 
- 		$this->set_credit1 ( 'take_out', $rs ['authorid'], POINT_DELETE_ANSWER, ACTION_DELETE_ANSWER );
 
- 	
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 删除一个问题
 
- 	 * @param unknown_type $qid
 
- 	 */
 
- 	function delete_question($qid) {
 
- 		$condition = " where id = " . $qid;
 
- 		
 
- 		$data ['hidden'] = 1;
 
- 		
 
- 		$this->questiondao->update_question ( $data, $condition );
 
- 		
 
- 		$rs = $this->questiondao->get_question_by_id ( $qid );
 
- 		
 
- 		//扣除积分
 
- 		$this->set_credit1 ( 'take_out', $rs ['authorid'], POINT_DELETE_QUESTION, ACTION_DELETE_QUESTION );
 
- 		
 
- 		$question = $this->questiondao->get_question_by_id ( $qid );
 
- 		
 
- 		$subject = "问题 <a href=/askpage/" . $question ['id'] . ">" . $question ['title'] . "</a> <span class=colRed>违规被删除</span>";
 
- 		
 
- 		$content = "问题 <a href=/askpage/" . $question ['id'] . ">" . $question ['title'] . "</a> <span class=colRed>违规被删除</span>";
 
- 		
 
- 		$this->send_sys_message ( $subject, $content, $question ['authorid'] );
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 修改回答内容
 
- 	 * @param unknown_type $aid
 
- 	 * @param unknown_type $data
 
- 	 */
 
- 	function update_answer_content($aid = 0, $data) {
 
- 		$condition = " where id = " . $aid;
 
- 		
 
- 		$this->answerdao->update_answer ( $data, $condition );
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 修改问题内容
 
- 	 * @param unknown_type $qid
 
- 	 * @param unknown_type $data
 
- 	 */
 
- 	function update_queston_description($qid, $data) {
 
- 		
 
- 		$condition = " where id = " . $qid;
 
- 		
 
- 		$this->questiondao->update_question ( $data, $condition );
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 添加一个追问
 
- 	 * @param unknown_type $data
 
- 	 */
 
- 	function to_ask_question($data = array()) {
 
- 		
 
- 		$data ['tag'] = serialize ( array (0 => $data ['tag'] ) );
 
- 		
 
- 		$data ['tagtime'] = get_date ();
 
- 		
 
- 		$this->answerdao->update_taginfo_by_id ( $data );
 
- 		
 
- 		$rs = $this->answerdao->get_answer_by_id ( $data ['id'] );
 
- 		
 
- 		$question = $this->questiondao->get_question_by_id ( $rs ['qid'] );
 
- 		
 
- 		$type = "FOLLOW_QUESTION";
 
- 		
 
- 		if ($question ['price'] > 0)
 
- 			$type = "PAY_FOLLOW_QUESTION";
 
- 		
 
- 		$this->send_email ( $rs ['authorid'], $type, $rs ['qid'], $rs ['id'] );
 
- 		
 
- 		//发送系统信息-发送给发回答用户  
 
- 		$subject = "回答 <a href=/askpage/" . $rs ['qid'] . " >" . $rs ['title'] . "</a> 提问者向您追问";
 
- 		
 
- 		$content = "回答 <a href=/askpage/" . $rs ['qid'] . " >" . $rs ['title'] . "</a> 提问者向您追问";
 
- 		
 
- 		$this->messagedao->send_message ( ADMIN_NAME, 0, $rs ['authorid'], $subject, $content );
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 添加一个在回答
 
- 	 * @param unknown_type $data
 
- 	 */
 
- 	function answer_again($data = array()) {
 
- 		
 
- 		$rs = $this->answerdao->get_answer_by_id ( $data ['id'] );
 
- 		
 
- 		//追问和回答
 
- 		$tag_array = unserialize ( $rs ['tag'] );
 
- 		
 
- 		array_push ( $tag_array, $data ['tag'] );
 
- 		
 
- 		array_push ( $tag_array, get_date () );
 
- 		
 
- 		$tag = serialize ( $tag_array );
 
- 		
 
- 		$data ['tag'] = $tag;
 
- 		
 
- 		$data ['tagtime'] = $rs ['tagtime'];
 
- 		
 
- 		$this->answerdao->update_taginfo_by_id ( $data );
 
- 		
 
- 		$rs = $this->answerdao->get_answer_by_id ( $data ['id'] );
 
- 		
 
- 		$question = $this->questiondao->get_question_by_id ( $rs ['qid'] );
 
- 		
 
- 		$type = "FOLLOW_ANSWER";
 
- 		
 
- 		if ($question ['price'] > 0)
 
- 			$type = "PAY_FOLLOW_ANSWER";
 
- 		
 
- 		$this->send_email ( $question ['authorid'], $type, $rs ['qid'], $data ['id'] );
 
- 		
 
- 		//发送系统信息-发送给发回答用户  
 
- 		$subject = "回答 <a href=/askpage/" . $rs ['qid'] . " >" . $rs ['title'] . "</a> 追问后有新的回答";
 
- 		
 
- 		$content = "回答 <a href=/askpage/" . $rs ['qid'] . " >" . $rs ['title'] . "</a> 追问后有新的回答";
 
- 		
 
- 		$this->messagedao->send_message ( ADMIN_NAME, 0, $question ['authorid'], $subject, $content );
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 更新用户头像
 
- 	 * @param unknown_type $data
 
- 	 */
 
- 	function update_avatar($data = array()) {
 
- 		
 
- 		$this->userdao->update_avatar ( $data );
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 关闭问题
 
- 	 * @param unknown_type $qid
 
- 	 */
 
- 	function close_question($qid = 0) {
 
- 		$this->questiondao->close_question ( $qid );
 
- 		
 
- 		$result = $this->questiondao->get_question_user_info_by_id ( $qid );
 
- 		
 
- 		$subject = "问题 <a href=/askpage/" . $result ['id'] . " >" . $result ['title'] . "</a> 已经关闭";
 
- 		
 
- 		$content = "问题 <a href=/askpage/" . $result ['id'] . " >" . $result ['title'] . "</a> 已经关闭";
 
- 		
 
- 		$this->messagedao->send_message ( ADMIN_NAME, 0, $result ['authorid'], $subject, $content );
 
- 		
 
- 		//扣除RMB到基金中
 
- 		if ($result ['price'] > 0)
 
- 			$this->_set_fund ( $result ['authorid'], $result ['id'], $result ['price'] );
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 添加悬赏值
 
- 	 * @param unknown_type $qid
 
- 	 * @param unknown_type $add_price
 
- 	 */
 
- 	function do_up_price($qid = 0, $add_price = 0) {
 
- 		
 
- 		$this->questiondao->do_up_price ( $qid, $add_price );
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 更新问题补充信息
 
- 	 */
 
- 	function update_queston_supply($data = array(), $qid = 0) {
 
- 		
 
- 		$question = $this->questiondao->get_question_by_id ( $qid );
 
- 		
 
- 		if (! empty ( $question ['supply'] ))
 
- 			return false;
 
- 		
 
- 		$condition = " where id = " . $qid;
 
- 		
 
- 		$supply [0] ['content'] = $data ['supply'];
 
- 		
 
- 		$supply [0] ['time'] = get_date ();
 
- 		
 
- 		$data ['supply'] = serialize ( $supply );
 
- 		
 
- 		$this->questiondao->update_question ( $data, $condition );
 
- 		
 
- 		$type = "REPLENISH_QUESTION";
 
- 		
 
- 		if ($question ['price'] > 0)
 
- 			$type = "PAY_REPLENISH_QUESTION";
 
- 		
 
- 		$this->send_email ( $question ['authorid'], $type, $qid, 0 );
 
- 	
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 更新用户信息-仅电话和昵称
 
- 	 * @param unknown_type $data
 
- 	 */
 
- 	function update_user_info($data = array()) {
 
- 		
 
- 		Doo::loadModel ( 'UserDao' );
 
- 		
 
- 		$userdao = new UserDao ();
 
- 		
 
- 		$userdao->uid = $data ['uid'];
 
- 		
 
- 		if (isset ( $data ['phone'] ))
 
- 			$userdao->phone = $data ['phone'];
 
- 		
 
- 		if (isset ( $data ['nickname'] ))
 
- 			$userdao->nickname = $data ['nickname'];
 
- 		
 
- 		if (isset ( $data ['cids'] ))
 
- 			$userdao->cids = $data ['cids'];
 
- 		
 
- 		if (isset ( $data ['is_email'] ))
 
- 			$userdao->is_email = $data ['is_email'];
 
- 		
 
- 		$result = $this->db ()->update ( $userdao );
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 记录财富流向
 
- 	 * @param unknown_type $data
 
- 	 */
 
- 	function set_credit3_log($data = array(), $price = 0) {
 
- 		
 
- 		$this->credit3logdao->qid = $data ['id'];
 
- 		
 
- 		$this->credit3logdao->username = $data ['username'];
 
- 		
 
- 		$this->credit3logdao->time = get_date ();
 
- 		
 
- 		$this->credit3logdao->ip = client_ip ();
 
- 		
 
- 		$this->credit3logdao->amount = $price;
 
- 		
 
- 		$action = $this->credit3logdao->set_ACTION_OFFER_QUESTION ();
 
- 		
 
- 		$this->credit3logdao->add_credit3_log ( $data ['uid'], $data ['username'], $data ['id'], $action, - $price, $this->credit3logdao->ip );
 
- 	
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 记录退款
 
- 	 */
 
- 	function set_credit3_refunds_log($data = array()) {
 
- 		$this->credit3logdao->qid = $data ['id'];
 
- 		
 
- 		$this->credit3logdao->username = $data ['author'];
 
- 		
 
- 		$this->credit3logdao->time = get_date ();
 
- 		
 
- 		$this->credit3logdao->ip = client_ip ();
 
- 		
 
- 		$this->credit3logdao->amount = $data ['price'];
 
- 		
 
- 		$action = $this->credit3logdao->set_ACTION_REFUNDS_QUESTION ();
 
- 		
 
- 		$this->credit3logdao->add_credit3_log ( $data ['authorid'], $data ['author'], $data ['id'], $action, + $data ['price'], $this->credit3logdao->ip, 1 );
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 将名师答疑的问题设置成满意
 
- 	 * @param unknown_type $id
 
- 	 */
 
- 	function set_vip_question_status($id = 0, $status = 0, $refunds_description = "") {
 
- 		
 
- 		if ($status == 0)
 
- 			return false;
 
- 		
 
- 		$this->vipquestiondao->set_vip_question_status ( $id, $status, $refunds_description );
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 发送系统信息
 
- 	 * @param unknown_type $subject
 
- 	 * @param unknown_type $content
 
- 	 * @param unknown_type $uid
 
- 	 */
 
- 	function send_sys_message($subject, $content, $uid) {
 
- 		
 
- 		$this->messagedao->send_message ( ADMIN_NAME, 0, $uid, $subject, $content );
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 追加一个名师答疑的追问
 
- 	 * @param unknown_type $id
 
- 	 * @param unknown_type $tag
 
- 	 */
 
- 	function do_add_vip_tag($id = 0, $tag = "") {
 
- 		
 
- 		$tag = serialize ( array (0 => $tag, 1 => get_date () ) );
 
- 		
 
- 		$this->vipanswerdao->do_add_vip_tag ( $id, $tag );
 
- 	
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 更新名师答疑回答数
 
- 	 * @param unknown_type $id
 
- 	 */
 
- 	function update_vip_question_by_answers($id) {
 
- 		
 
- 		$this->vipquestiondao->update_vip_question_by_answers ( $id );
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 添加追问答案
 
- 	 * @param unknown_type $id
 
- 	 * @param unknown_type $content
 
- 	 */
 
- 	function update_vip_answer($content = "", $aid = 0, $tag = "") {
 
- 		$this->vipanswerdao->id = $aid;
 
- 		
 
- 		//追问和回答
 
- 		$tag_array = unserialize ( $tag );
 
- 		
 
- 		$tag_array ['2'] = $content;
 
- 		
 
- 		$tag = serialize ( $tag_array );
 
- 		
 
- 		$this->vipanswerdao->tag = $tag;
 
- 		
 
- 		$result = $this->db ()->update ( $this->vipanswerdao );
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 添加一个公告
 
- 	 * @param unknown_type $params
 
- 	 */
 
- 	function add_article($params = array()) {
 
- 		Doo::loadModel ( 'ArticleDao' );
 
- 		
 
- 		$articledao = new ArticleDao ();
 
- 		
 
- 		$articledao->title = $params ['title'];
 
- 		
 
- 		$articledao->content = $params ['content'];
 
- 		
 
- 		$articledao->time = time ();
 
- 		
 
- 		$result = $this->db ()->insert ( $articledao );
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 获取一个文章
 
- 	 * @param unknown_type $id
 
- 	 */
 
- 	function get_article_by_id($id = 0) {
 
- 		Doo::loadModel ( 'ArticleDao' );
 
- 		
 
- 		$articledao = new ArticleDao ();
 
- 		
 
- 		$articledao->aid = $id;
 
- 		
 
- 		$rs = $this->db ()->find ( $articledao, array ('limit' => 1 ) );
 
- 		
 
- 		$rs->time = format_date ( $rs->time );
 
- 		
 
- 		return $rs;
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 更新一篇文章
 
- 	 * @param unknown_type $params
 
- 	 */
 
- 	function update_article($params) {
 
- 		Doo::loadModel ( 'ArticleDao' );
 
- 		
 
- 		$articledao = new ArticleDao ();
 
- 		
 
- 		$articledao->aid = $params ['id'];
 
- 		
 
- 		$articledao->title = $params ['title'];
 
- 		
 
- 		$articledao->content = $params ['content'];
 
- 		
 
- 		$this->db ()->update ( $articledao );
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 删除文档
 
- 	 * @param unknown_type $uid
 
- 	 */
 
- 	function delete_article($id = array()) {
 
- 		
 
- 		Doo::loadModel ( 'ArticleDao' );
 
- 		
 
- 		$articledao = new ArticleDao ();
 
- 		
 
- 		$articledao->delete_article ( $id );
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 添加名师答疑评价
 
- 	 * @param unknown_type $qid
 
- 	 * @param unknown_type $comment
 
- 	 */
 
- 	function update_vip_answer_comment($qid = 0, $comment = "") {
 
- 		
 
- 		$this->vipanswerdao->update_vip_answer_comment ( $qid, $comment );
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 添加讨论
 
- 	 * @param unknown_type $qid
 
- 	 * @param unknown_type $uid
 
- 	 * @param unknown_type $content
 
- 	 * @param unknown_type $cid
 
- 	 */
 
- 	function add_discuss($qid = 0, $uid = 0, $content = "", $cid = 0) {
 
- 		Doo::loadModel ( 'DiscussDao' );
 
- 		
 
- 		$discussdao = new DiscussDao ();
 
- 		
 
- 		$discussdao->uid = $uid;
 
- 		
 
- 		$discussdao->qid = $qid;
 
- 		
 
- 		$discussdao->cid = $cid;
 
- 		
 
- 		$discussdao->content = $content;
 
- 		
 
- 		$discussdao->time = get_date ();
 
- 		
 
- 		$discussdao->discuss = 0;
 
- 		
 
- 		$result = $this->db ()->insert ( $discussdao );
 
- 		
 
- 		return $result;
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 更新讨论数
 
- 	 * @param unknown_type $cid
 
- 	 */
 
- 	function update_discuss($cid = 0) {
 
- 		Doo::loadModel ( 'DiscussDao' );
 
- 		
 
- 		$discussdao = new DiscussDao ();
 
- 		
 
- 		$discussdao->update_discuss ( $cid );
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 添加一个公告
 
- 	 * @param unknown_type $params
 
- 	 */
 
- 	function add_category($params = array()) {
 
- 		Doo::loadModel ( 'CategoryDao' );
 
- 		
 
- 		$categorydao = new CategoryDao ();
 
- 		
 
- 		$categorydao->name = $params ['name'];
 
- 		
 
- 		$categorydao->pid = $params ['pid'];
 
- 		
 
- 		$categorydao->grade = 1;
 
- 		
 
- 		$result = $this->db ()->insert ( $categorydao );
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 删除选中问题
 
- 	 * @param unknown_type $id
 
- 	 */
 
- 	function delete_category_list($id = array()) {
 
- 		
 
- 		$this->categorydao->delete_category_list ( $id );
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 更新分类信息
 
- 	 * @param unknown_type $id
 
- 	 * @param unknown_type $name
 
- 	 * @param unknown_type $pid
 
- 	 */
 
- 	function update_category($id = 0, $name = "", $pid = 0) {
 
- 		$this->categorydao->id = $id;
 
- 		
 
- 		$this->categorydao->name = $name;
 
- 		
 
- 		$this->categorydao->pid = $pid;
 
- 		
 
- 		$result = $this->db ()->update ( $this->categorydao );
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 设置为默认发送邮件
 
- 	 * @param unknown_type $uid
 
- 	 */
 
- 	function set_email_config($uid = 0) {
 
- 		
 
- 		if ($uid == 0)
 
- 			return false;
 
- 		
 
- 		$data ['normal_question_mail'] = array ("0" => "NEW_ANSWER", "1" => "CLOSE_QUESTION", "2" => "FOLLOW_ANSWER", "3" => "FOLLOW_QUESTION", "4" => "REPLENISH_QUESTION", "5" => "ADOPT_ANSWER" );
 
- 		
 
- 		$data ['pay_question_mail'] = array ("1" => "PAY_NEW_ANSWER", "2" => "PAY_CLOSE_QUESTION", "3" => "PAY_FOLLOW_ANSWER", "4" => "PAY_FOLLOW_QUESTION", "5" => "PAY_REPLENISH_QUESTION", "6" => "PAY_ADOPT_ANSWER", "7" => "PAY_FORMONEY" );
 
- 		
 
- 		$data ['vip_question_mail'] = array ("1" => "VIP_PAY_FORMONEY", "2" => "VIP_MONEY_BACK", "3" => "VIP_NEW_ANSWER", "4" => "VIP_FOLLOW_ANSWER" );
 
- 		
 
- 		$this->add_email_config ( $data, $uid );
 
- 		
 
- 		$data ['uid'] = $uid;
 
- 		
 
- 		$data ['is_email'] = 1;
 
- 		
 
- 		$this->update_user_info ( $data );
 
- 	
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 获取个人email配置
 
- 	 * @param unknown_type $uid
 
- 	 */
 
- 	function get_email_config($uid = 0) {
 
- 		Doo::loadModel ( 'EmailconfigDao' );
 
- 		
 
- 		$emailconfigdao = new EmailconfigDao ();
 
- 		
 
- 		$result = $emailconfigdao->get_emailconfig_by_uid ( $uid );
 
- 		
 
- 		$is_email = array ();
 
- 		
 
- 		foreach ( $result as $key => $value ) {
 
- 			array_push ( $is_email, $value ['action_id'] );
 
- 		}
 
- 		
 
- 		return $is_email;
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 添加email配置
 
- 	 * @param unknown_type $data
 
- 	 * @param unknown_type $uid
 
- 	 */
 
- 	function add_email_config($data = array(), $uid = 0) {
 
- 		Doo::loadModel ( 'EmailconfigDao' );
 
- 		
 
- 		$emailconfigdao = new EmailconfigDao ();
 
- 		
 
- 		$emailconfigdao->delete_emailconfig_by_uid ( $uid );
 
- 		
 
- 		$normal = $pay = $vip = array ();
 
- 		
 
- 		//添加普通问答配置
 
- 		foreach ( $data ['normal_question_mail'] as $key => $value ) {
 
- 			
 
- 			array_push ( $normal, "(" . $uid . ",'" . $value . "')" );
 
- 		}
 
- 		
 
- 		if (! empty ( $normal )) {
 
- 			
 
- 			$normal = implode ( ",", $normal );
 
- 			
 
- 			$emailconfigdao->add_emailconfig ( $normal );
 
- 		}
 
- 		
 
- 		//悬赏问答
 
- 		foreach ( $data ['pay_question_mail'] as $key => $value ) {
 
- 			
 
- 			array_push ( $pay, "(" . $uid . ",'" . $value . "')" );
 
- 		}
 
- 		
 
- 		if (! empty ( $pay )) {
 
- 			$pay = implode ( ",", $pay );
 
- 			
 
- 			$emailconfigdao->add_emailconfig ( $pay );
 
- 		}
 
- 		
 
- 		//名师答疑
 
- 		foreach ( $data ['vip_question_mail'] as $key => $value ) {
 
- 			
 
- 			array_push ( $vip, "(" . $uid . ",'" . $value . "')" );
 
- 		}
 
- 		
 
- 		if (! empty ( $vip )) {
 
- 			$vip = implode ( ",", $vip );
 
- 			
 
- 			$emailconfigdao->add_emailconfig ( $vip );
 
- 		}
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 实现接口
 
- 	 * (non-PHPdoc)
 
- 	 * @see BaseLogic::format_email_content()
 
- 	 */
 
- 	protected function format_email_content($html_templete, $templete_name, $qid = 0, $aid = 0) {
 
- 		
 
- 		if ($templete_name == "VIP_PAY_FORMONEY" || $templete_name == "VIP_MONEY_BACK" || $templete_name == "VIP_NEW_ANSWER" || $templete_name == "VIP_FOLLOW_ANSWER") {
 
- 			
 
- 			$question = $this->vipquestiondao->get_vip_question_by_id ( $qid );
 
- 			
 
- 			$answer = $this->vipanswerdao->get_vip_answer_by_qid ( $qid );
 
- 		} else {
 
- 			$question = $this->questiondao->get_question_by_id ( $qid );
 
- 			
 
- 			$answer = $this->answerdao->get_answer_by_id ( $aid );
 
- 		}
 
- 		
 
- 		$userinfo = $this->get_sso_user_info_by_name ( $question ['author'] );
 
- 		
 
- 		$result = array ();
 
- 		
 
- 		if ($templete_name == "NEW_ANSWER" || $templete_name == "PAY_NEW_ANSWER") { //提问有新的回答
 
- 			
 
- 			$str = str_replace ( "%username%", $question ['author'], $html_templete );
 
- 			
 
- 			$str = str_replace ( "%uid%", $answer ['authorid'], $str );
 
- 			
 
- 			$str = str_replace ( "%answer_username%", $answer ['author'], $str );
 
- 			
 
- 			$str = str_replace ( "%answer_time%", format_date ( $answer ['time'], "Y年m月d日" ), $str );
 
- 			
 
- 			$str = str_replace ( "%qid%", $question ['id'], $str );
 
- 			
 
- 			$str = str_replace ( "%question_title%", $question ['title'], $str );
 
- 			
 
- 			$str = str_replace ( "%answer_content%", $answer ['content'], $str );
 
- 			
 
- 			$result ['templete'] = $str;
 
- 			
 
- 			$result ['subject'] = "=?UTF-8?B?" . base64_encode ( '纵横知道·问答提醒您:你的提问有新的回答' ) . "?=";
 
- 			
 
- 			//$result ['subject'] = "";
 
- 			
 
- 			$result ['toemail'] = $userinfo [0] ['useremail'];
 
- 			
 
- 			//$result ['toemail'] = "cpthought@vip.qq.com";
 
- 			
 
- 			return $result;
 
- 		} elseif ($templete_name == "CLOSE_QUESTION" || $templete_name == "PAY_CLOSE_QUESTION") { //问题被关闭
 
- 			
 
- 			$str = str_replace ( "%username%", $question ['author'], $html_templete );
 
- 			
 
- 			$str = str_replace ( "%qid%", $question ['id'], $str );
 
- 			
 
- 			$str = str_replace ( "%question_title%", $question ['title'], $str );
 
- 			
 
- 			$str = str_replace ( "%question_time%", format_date ( time (), "Y年m月d日" ), $str );
 
- 			
 
- 			$result ['templete'] = $str;
 
- 			
 
- 			$result ['subject'] = "=?UTF-8?B?" . base64_encode ( '纵横知道·问答提醒您:你的问题被关闭' ) . "?=";
 
- 			
 
- 			$result ['toemail'] = $userinfo [0] ['useremail'];
 
- 			
 
- 			return $result;
 
- 		} elseif ($templete_name == "FOLLOW_ANSWER" || $templete_name == "PAY_FOLLOW_ANSWER") { //追问有新的回答
 
- 			
 
- 			$str = str_replace ( "%username%", $question ['author'], $html_templete );
 
- 			
 
- 			$str = str_replace ( "%qid%", $question ['id'], $str );
 
- 			
 
- 			$str = str_replace ( "%answer_username%", $answer ['author'], $str );
 
- 			
 
- 			$str = str_replace ( "%time%", format_date ( time (), "Y年m月d日" ), $str );
 
- 			
 
- 			$str = str_replace ( "%question_title%", $question ['title'], $str );
 
- 			
 
- 			$tag_array = unserialize ( $answer ['tag'] );
 
- 			
 
- 			$str = str_replace ( "%ask2%", $tag_array [0], $str );
 
- 			
 
- 			$str = str_replace ( "%answer2%", $tag_array [1], $str );
 
- 			
 
- 			$result ['templete'] = $str;
 
- 			
 
- 			$result ['subject'] = "=?UTF-8?B?" . base64_encode ( '纵横知道·问答提醒您:你的追问有新的回答' ) . "?=";
 
- 			
 
- 			$result ['toemail'] = $userinfo [0] ['useremail'];
 
- 			
 
- 			return $result;
 
- 		} elseif ($templete_name == "FOLLOW_QUESTION" || $templete_name == "PAY_FOLLOW_QUESTION") { //提问者向您追问
 
- 			
 
- 			$str = str_replace ( "%answer_username%", $answer ['author'], $html_templete );
 
- 			
 
- 			$str = str_replace ( "%qid%", $question ['id'], $str );
 
- 			
 
- 			$str = str_replace ( "%username%", $question ['author'], $str );
 
- 			
 
- 			$str = str_replace ( "%time%", format_date ( time (), "Y年m月d日" ), $str );
 
- 			
 
- 			$str = str_replace ( "%question_title%", $question ['title'], $str );
 
- 			
 
- 			$str = str_replace ( "%answer_content%", $answer ['content'], $str );
 
- 			
 
- 			$tag_array = unserialize ( $answer ['tag'] );
 
- 			
 
- 			$str = str_replace ( "%ask2%", $tag_array [0], $str );
 
- 			
 
- 			$result ['templete'] = $str;
 
- 			
 
- 			$result ['subject'] = "=?UTF-8?B?" . base64_encode ( '纵横知道·问答提醒您:提问者向您追问' ) . "?=";
 
- 			
 
- 			$result ['toemail'] = $userinfo [0] ['useremail'];
 
- 			
 
- 			return $result;
 
- 		} elseif ($templete_name == "REPLENISH_QUESTION" || $templete_name == "PAY_REPLENISH_QUESTION") { //提问这对问题进行了补充
 
- 			
 
- 			$str = str_replace ( "%username%", $question ['author'], $html_templete );
 
- 			
 
- 			$str = str_replace ( "%qid%", $question ['id'], $str );
 
- 			
 
- 			$str = str_replace ( "%question_title%", $question ['title'], $str );
 
- 			
 
- 			$tag_array = unserialize ( $question ['supply'] );
 
- 			
 
- 			$str = str_replace ( "%supply%", $tag_array [0] ['content'], $str );
 
- 			
 
- 			$str = str_replace ( "%time%", format_date ( time (), "Y年m月d日" ), $str );
 
- 			
 
- 			$result ['templete'] = $str;
 
- 			
 
- 			$result ['subject'] = "=?UTF-8?B?" . base64_encode ( '纵横知道·问答提醒您:提问者对问题进行了补充' ) . "?=";
 
- 			
 
- 			$result ['toemail'] = $userinfo [0] ['useremail'];
 
- 			
 
- 			return $result;
 
- 		} elseif ($templete_name == "ADOPT_ANSWER" || $templete_name == "PAY_ADOPT_ANSWER") { //回答被采纳了
 
- 			
 
- 			$str = str_replace ( "%answer_username%", $answer ['author'], $html_templete );
 
- 			
 
- 			$str = str_replace ( "%qid%", $answer ['qid'], $str );
 
- 			
 
- 			$str = str_replace ( "%username%", $question ['author'], $str );
 
- 			
 
- 			$str = str_replace ( "%time%", format_date ( time (), "Y年m月d日" ), $str );
 
- 			
 
- 			$str = str_replace ( "%question_title%", $question ['title'], $str );
 
- 			
 
- 			$str = str_replace ( "%answer_content%", $answer ['content'], $str );
 
- 			
 
- 			$result ['templete'] = $str;
 
- 			
 
- 			$result ['subject'] = "=?UTF-8?B?" . base64_encode ( '纵横知道·问答提醒您:您的回答被采纳了!' ) . "?=";
 
- 			
 
- 			$userinfo = $this->get_sso_user_info_by_name ( $answer ['author'] );
 
- 			
 
- 			$result ['toemail'] = $userinfo [0] ['useremail'];
 
- 			
 
- 			return $result;
 
- 		} elseif ($templete_name == "PAY_FORMONEY") {
 
- 			
 
- 			$str = str_replace ( "%username%", $question ['author'], $html_templete );
 
- 			
 
- 			$str = str_replace ( "%price%", $question ['price'], $str );
 
- 			
 
- 			$str = str_replace ( "%qid%", $question ['id'], $str );
 
- 			
 
- 			$str = str_replace ( "%time%", format_date ( time (), "Y年m月d日" ), $str );
 
- 			
 
- 			$result ['templete'] = $str;
 
- 			
 
- 			$result ['subject'] = "=?UTF-8?B?" . base64_encode ( '纵横知道·问答提醒您:您进行了一项付费操作' ) . "?=";
 
- 			
 
- 			$result ['toemail'] = $userinfo [0] ['useremail'];
 
- 			
 
- 			return $result;
 
- 		} elseif ($templete_name == "VIP_PAY_FORMONEY") { //名师答疑付费提醒
 
- 			
 
- 			$str = str_replace ( "%username%", $question ['author'], $html_templete );
 
- 			
 
- 			$str = str_replace ( "%price%", $question ['price'], $str );
 
- 			
 
- 			$str = str_replace ( "%uid%", $question ['authorid'], $str );
 
- 			
 
- 			$result ['templete'] = $str;
 
- 			
 
- 			$result ['subject'] = "=?UTF-8?B?" . base64_encode ( '纵横知道·问答提醒您:您进行了一项付费操作' ) . "?=";
 
- 			
 
- 			$result ['toemail'] = $userinfo [0] ['useremail'];
 
- 			
 
- 			return $result;
 
- 		} elseif ($templete_name == "VIP_NEW_ANSWER") { //名师答疑有回答提醒
 
- 			
 
- 			$str = str_replace ( "%username%", $question ['author'], $html_templete );
 
- 			
 
- 			$str = str_replace ( "%time%", format_date ( time (), "Y年m月d日" ), $str );
 
- 			
 
- 			$str = str_replace ( "%vqid%", $question ['id'], $str );
 
- 			
 
- 			$str = str_replace ( "%vipquestion_title%", $question ['title'], $str );
 
- 			
 
- 			$str = str_replace ( "%vanswer_content%", $answer ['content'], $str );
 
- 			
 
- 			$result ['templete'] = $str;
 
- 			
 
- 			$result ['subject'] = "=?UTF-8?B?" . base64_encode ( '纵横知道·问答提醒您:你的名师答疑有新的回答' ) . "?=";
 
- 			
 
- 			$result ['toemail'] = $userinfo [0] ['useremail'];
 
- 			
 
- 			return $result;
 
- 		} elseif ($templete_name == "VIP_MONEY_BACK") { //名师答疑退费提醒
 
- 			
 
- 			$str = str_replace ( "%username%", $question ['author'], $html_templete );
 
- 			
 
- 			$str = str_replace ( "%price%", $question ['price'], $str );
 
- 			
 
- 			$str = str_replace ( "%uid%", $question ['authorid'], $str );
 
- 			
 
- 			$str = str_replace ( "%time%", format_date ( time (), "Y年m月d日" ), $str );
 
- 			
 
- 			$result ['templete'] = $str;
 
- 			
 
- 			$result ['subject'] = "=?UTF-8?B?" . base64_encode ( '纵横知道·问答提醒您:向您退费成功' ) . "?=";
 
- 			
 
- 			$result ['toemail'] = $userinfo [0] ['useremail'];
 
- 			
 
- 			return $result;
 
- 		} elseif ($templete_name == "VIP_FOLLOW_ANSWER") { //名师答疑追问有了新的回答
 
- 			
 
- 			$str = str_replace ( "%username%", $question ['author'], $html_templete );
 
- 			
 
- 			$str = str_replace ( "%time%", format_date ( time (), "Y年m月d日" ), $str );
 
- 			
 
- 			$str = str_replace ( "%vipquestion_title%", $question ['title'], $str );
 
- 			
 
- 			$str = str_replace ( "%vanswer_content%", $answer ['content'], $str );
 
- 			
 
- 			$str = str_replace ( "%vqid%", $question ['id'], $str );
 
- 			
 
- 			$result ['templete'] = $str;
 
- 			
 
- 			$result ['subject'] = "=?UTF-8?B?" . base64_encode ( '纵横知道·问答提醒您:你在名师答疑中追问有新的回答' ) . "?=";
 
- 			
 
- 			$result ['toemail'] = $userinfo [0] ['useremail'];
 
- 			
 
- 			//$result ['toemail'] = "cpthought@vip.qq.com";
 
- 			return $result;
 
- 		}
 
- 	}
 
- }
 
- ?>
 
 
  |