123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320 |
- <?php
- Doo::loadCore('db/DooModel');
- class QuestionDao extends DooModel{
-
- public $id;
- public $cid;
- public $cid1;
- public $cid2;
- public $cid3;
- public $price;
- public $author;
- public $authorid;
- public $title;
- public $description;
- public $supply;
- public $url;
- public $time;
- public $endtime;
- public $phone;
- public $hidden;
- public $answers;
- public $views;
- public $goods;
- public $status;
- public $ip;
- public $search_words;
-
- public $_table = 'zhask_question';
- public $_primarykey = "id";
- public $_fields = array ('id', 'cid', 'cid1', 'cid2', 'cid3', 'price', 'author', 'authorid', 'title', 'description', 'supply', 'url', 'time', 'endtime', 'hidden', 'answers', 'views', 'goods', 'status', 'ip', 'search_words' );
-
- function get_QA($field="*",$condition="limit 1"){
-
- //as a left join " . t_user . " as b on (a.authorid=b.uid) left join " . t_usergroup . " as c on (b.groupid=c.groupid) where id=" . $id
-
- $sql = "select ".$field." from ".$this->_table." as a left join ".t_answer." as b on (a.id=b.qid) where ".$condition;
- $query = Doo::db ()->query ( $sql );
- $result = $query->fetchAll ();
-
- return $result;
- }
-
- /**
- * 获取当天数据数
- */
- function get_today_question($condition=""){
-
- $sql = "select count(*) as times from ".$this->_table." where from_unixtime(time,'%Y-%m-%d')=curdate() ".$condition;
- $query = Doo::db ()->query ( $sql );
- $result = $query->fetch ();
-
- return $result;
-
- }
-
- /**
- * 获取一个问题
- * @param unknown_type $id
- */
- function get_question_by_id($id = 0) {
-
- $sql = "select * from " . t_question . " where id=" . $id;
- $query = Doo::db ()->query ( $sql );
- $result = $query->fetch ();
-
- return $result;
- }
-
- /**
- * 获得相关问题
- * @param unknown_type $id
- * @param unknown_type $cid
- */
- function get_like_questions_list($id = 0, $cid = 0, $status = "") {
- $limit = " order by time desc limit 5";
-
- if($status!="")
- $status=" and status =".$status;
-
- $condition = " and hidden=0 and cid =" . $cid . " and id!=" . $id.$status;
- $condition = ' where 1 ' . $condition . $limit;
- $sql = "select * from " . t_question . $condition;
- $query = Doo::db ()->query ( $sql );
- $result = $query->fetchAll ();
-
- return $result;
- }
-
- /**
- * 获取问题额记录数(需要修改)
- * @param unknown_type $param
- * @return
- */
- function get_questions_count($param) {
-
- $condition = "";
-
- foreach ( $param as $key => $value ) {
- if (is_numeric ( $value )) {
-
- //悬赏不等于0
- if ($value == 13)
-
- $condition .= " and price != 0";
- elseif ($value != 0) {
-
- $condition .= " and " . $key . " = " . $value;
- }
-
- } elseif (is_string ( $value )) {
-
- if ('auto' == $key)
- $condition .= $value;
- elseif ('' != $value)
- $condition .= " and " . $key . " like '%" . $value . "%'";
- }
- }
- $condition = ' where 1' . $condition;
- $sql = "select count(*) as count from " . t_question . $condition;
- $query = Doo::db ()->query ( $sql );
- $result = $query->fetch ();
-
- return $result;
- }
-
- /**
- * 删除某个用户的所以问题
- * @param unknown_type $uid
- */
- function delete_question_by_authorid($uid = 0) {
-
- $sql = "delete from " . t_question . " where authorid = " . $uid;
- Doo::db ()->query ( $sql );
- }
-
- /**
- * 批量删除问题
- * @param unknown_type $id
- */
- function delete_question_list($id = array()) {
-
- $id = implode ( ",", $id );
- $sql = "delete from " . t_question . " where id in ( " . $id . " )";
- Doo::db ()->query ( $sql );
- }
-
- /**
- * 获取问题数据
- * @param unknown_type $param
- * @param unknown_type $limit
- */
- function get_questions_list($param, $limit) {
-
- $condition = "";
-
- foreach ( $param as $key => $value ) {
- if (is_numeric ( $value )) {
-
- //悬赏不等于0
- if ($value == 13)
-
- $condition .= " and price != 0";
- elseif ($value != 0) {
-
- $condition .= " and " . $key . " = " . $value;
- } elseif ($key == "hidden") {
- $condition .= " and " . $key . " = " . $value;
- }
-
- } elseif (is_string ( $value )) {
-
- if ('' != $value)
- $condition .= " and " . $key . " like '%" . $value . "%'";
-
- }
- }
-
- $limit = " order by time desc limit " . $limit ['lower'] . ", " . $limit ['size'] . "";
-
- $condition = ' where 1 ' . $condition . $limit;
-
- $sql = "select * from " . t_question . $condition;
-
- $query = Doo::db ()->query ( $sql );
-
- $result = $query->fetchAll ();
-
- return $result;
- }
-
- /**
- * 获取问题用户信息
- * @param unknown_type $id
- */
- function get_question_user_info_by_id($id = 0) {
-
- $sql = "select *,a.answers as qanswers from " . t_question . " as a left join " . t_user . " as b on (a.authorid=b.uid) left join " . t_usergroup . " as c on (b.groupid=c.groupid) where id=" . $id;
-
- $query = Doo::db ()->query ( $sql );
-
- $result = $query->fetch ();
-
- return $result;
- }
-
- /**
- * 获取回答用户信息
- * @param unknown_type $id
- */
- function get_answer_user_info_by_id($id = 0) {
- $sql = "select * from " . t_question . " as a left join " . t_user . " as b on (a.authorid=b.uid) left join " . t_usergroup . " as c on (b.groupid=c.groupid) where a.id=" . $id;
-
- $query = Doo::db ()->query ( $sql );
-
- $result = $query->fetchAll ();
-
- return $result;
- }
-
- /**
- * 根据ID关闭问题
- * @param unknown_type $id
- */
- function close_question_by_id($id = 0) {
-
- $endtime = get_date ();
-
- $sql = "UPDATE `" . t_question . "` SET `status` = 9 , endtime =" . $endtime . " WHERE `id` = " . $id;
-
- $query = Doo::db ()->query ( $sql );
- }
-
- /**
- * 更新一条问题信息
- * @param unknown_type $data
- * @param unknown_type $condition
- */
- function update_question($data = array(), $condition = "") {
-
- $prams = array ();
-
- foreach ( $data as $key => $value ) {
-
- $value = mysql_escape_string ( $value );
-
- $src = $key . " = '" . $value . "' ";
-
- array_push ( $prams, $src );
- }
-
- $prams = implode ( ",", $prams );
-
- $sql = "UPDATE " . t_question . " SET " . $prams . " " . $condition;
-
- $query = Doo::db ()->query ( $sql );
- }
-
- /**
- * 更新悬赏值
- * @param unknown_type $qid
- * @param unknown_type $add_price
- */
- function do_up_price($qid = 0, $add_price = 0) {
- $sql = "UPDATE `" . t_question . "` SET `price` = `price` + " . $add_price . " WHERE `id` = " . $qid;
-
- $query = Doo::db ()->query ( $sql );
- }
-
- /**
- * 问题关闭
- * @param unknown_type $qid
- */
- function close_question($qid = 0) {
- $sql = "UPDATE `" . t_question . "` SET `status` = " . QUESTOIN_STATUS_CLOSE . " WHERE `id` = " . $qid;
-
- $query = Doo::db ()->query ( $sql );
- }
-
- /**
- * 设置赞标记
- * @param unknown_type $qid
- */
- function set_question_goods($qid = 0) {
- $sql = "UPDATE `" . t_question . "` SET `goods` = 1 WHERE `id` = " . $qid;
-
- $query = Doo::db ()->query ( $sql );
- }
-
- function get_questions_By_Idlist($id=""){
-
- $sql = "select * from " . $this->_table . " where id in ( " . $id . " )";
-
- $query = Doo::db ()->query ( $sql );
-
- $result = $query->fetchAll ();
-
- return $result;
-
- }
-
- /**
- * 根据问题ID和用户获得问题
- * @param unknown_type $qid
- * @param unknown_type $uid
- */
- function get_question_by_uqid($qid = 0, $uid = 0) {
-
- $sql = "select * from " . t_question . " where id=" . $qid . " and authorid=" . $uid;
-
- $query = Doo::db ()->query ( $sql );
-
- $result = $query->fetch ();
-
- return $result;
- }
- }
- ?>
|