BlogModel.class.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. * ==========================================================================
  6. * @link http://www.liofis.com/
  7. * @copyright Copyright (c) 2015 liofis.com.
  8. * @license http://www.liofis.com/license.html License
  9. * ==========================================================================
  10. *
  11. * @author fish
  12. *
  13. */
  14. namespace Admin\Model;
  15. use Think\Model;
  16. class BlogModel extends Model{
  17. public function del_blog($id){
  18. try{
  19. $image=M('Blog')->where(array('blog_id'=>$id))->field('image')->find();
  20. if(!empty($image)){
  21. A('Image')->del_image('blog',$image['image'],'blog');
  22. }
  23. $gallery=M('blog_image')->where(array('blog_id'=>$id))->field('image')->select();
  24. if(!empty($gallery)){
  25. foreach ($gallery as $key => $value) {
  26. A('Image')->del_image('blog_gallery',$value['image'],'blog_gallery');
  27. }
  28. }
  29. M('Blog')->where(array('blog_id'=>$id))->delete();
  30. M('blog_content')->where(array('blog_id'=>$id))->delete();
  31. M('blog_image')->where(array('blog_id'=>$id))->delete();
  32. return array(
  33. 'status'=>'success',
  34. 'message'=>'删除成功',
  35. 'jump'=>U('Blog/index')
  36. );
  37. }catch(Exception $e){
  38. return array(
  39. 'status'=>'fail',
  40. 'message'=>'删除失败,未知异常',
  41. 'jump'=>U('Blog/index')
  42. );
  43. }
  44. }
  45. //修改时,取得博客图片
  46. public function get_blog_data($id){
  47. $d=M('Blog')->find($id);
  48. $d['thumb_image']=resize($d['image'], 100, 100);
  49. return $d;
  50. }
  51. //修改时,取得博客图册图片
  52. public function get_blog_image_data($id){
  53. $d=M('blog_image')->where(array('blog_id'=>$id))->select();
  54. foreach ($d as $k => $v) {
  55. $d[$k]['thumb']=resize($v['image'], 100, 100);
  56. }
  57. return $d;
  58. }
  59. //修改时,取得博客分类
  60. public function get_blog_category_data($id){
  61. $sql='SELECT bc.title,bc.id FROM '.C('DB_PREFIX').'blog_category bc,'
  62. .C('DB_PREFIX').'blog b WHERE bc.id=b.category_id AND b.blog_id='.$id;
  63. $d=M()->query($sql);
  64. return $d[0];
  65. }
  66. public function show_blog_page($search = array()){
  67. $sql='SELECT * FROM '.C('DB_PREFIX').'blog ';
  68. if(!empty($search))
  69. {
  70. if( isset($search['type']) && $search['type'] == 'seller')
  71. {
  72. $sql .= " where type='".$search['type']."' ";
  73. }
  74. }
  75. $count=count(M()->query($sql));
  76. $Page = new \Think\Page($count,C('BACK_PAGE_NUM'));
  77. $show = $Page->show();// 分页显示输出
  78. $sql.=' order by blog_id desc LIMIT '.$Page->firstRow.','.$Page->listRows;
  79. $list=M()->query($sql);
  80. foreach ($list as $key => $value) {
  81. $list[$key]['image']=resize($value['image'], 100, 100);
  82. }
  83. return array(
  84. 'empty'=>'<tr><td colspan="20">~~暂无数据</td></tr>',
  85. 'list'=>$list,
  86. 'page'=>$show
  87. );
  88. }
  89. public function validate($data){
  90. $error=array();
  91. if(empty($data['title'])){
  92. $error='标题必填';
  93. }
  94. if($error){
  95. return array(
  96. 'status'=>'back',
  97. 'message'=>$error
  98. );
  99. }
  100. }
  101. public function edit_blog($data){
  102. $error=$this->validate($data);
  103. if($error){
  104. return $error;
  105. }
  106. $blog_id=$data['blog_id'];
  107. $blog['blog_id']=$blog_id;
  108. $blog['title']=$data['title'];
  109. $blog['author']=$data['author'];
  110. $blog['image']=$data['image'];
  111. $blog['type']=$data['type'];
  112. $blog['category_id']=1;
  113. $blog['allow_reply']=$data['allow_reply'];
  114. $blog['meta_description']=$data['meta_description'];
  115. $blog['meta_keywords']=$data['meta_keywords'];
  116. $blog['status']=$data['status'];
  117. $blog['update_time']=date('Y-m-d H:i:s',time());
  118. $r=M('Blog')->save($blog);
  119. if($r){
  120. try{
  121. M('blog_content')->where(array('blog_id'=>$blog_id))->delete();
  122. $blog_content['blog_id']=$blog_id;
  123. $blog_content['summary']=$data['summary'];
  124. $blog_content['content']=$data['content'];
  125. M('blog_content')->add($blog_content);
  126. return array(
  127. 'status'=>'success',
  128. 'message'=>'修改成功',
  129. 'blog_id' => $blog_id,
  130. 'jump'=>U('Blog/index')
  131. );
  132. }catch(Exception $e){
  133. return array(
  134. 'status'=>'fail',
  135. 'message'=>'修改失败,未知异常',
  136. 'jump'=>U('Blog/index')
  137. );
  138. }
  139. }else{
  140. return array(
  141. 'status'=>'fail',
  142. 'message'=>'修改失败',
  143. 'jump'=>U('Blog/index')
  144. );
  145. }
  146. }
  147. public function show_quan_page($search = array())
  148. {
  149. //group_id
  150. $sql='SELECT * FROM '.C('DB_PREFIX').'group_post ';
  151. if(!empty($search))
  152. {
  153. if( isset($search['group_id']) )
  154. {
  155. $sql .= " where group_id='".$search['group_id']."' ";
  156. }
  157. }
  158. $count=count(M()->query($sql));
  159. $Page = new \Think\Page($count,C('BACK_PAGE_NUM'));
  160. $show = $Page->show();// 分页显示输出
  161. $sql.=' order by id desc LIMIT '.$Page->firstRow.','.$Page->listRows;
  162. $list=M()->query($sql);
  163. foreach ($list as $key => $value) {
  164. //member_id uname avatar
  165. $list[$key]['title2'] = htmlspecialchars_decode($value['title']);
  166. if($value['is_vir'] == 1)
  167. {
  168. $list[$key]['uname'] = $value['user_name'];
  169. }else{
  170. $member_info = M('member')->field('uname,avatar')->where( array('member_id' => $value['member_id']) )->find();
  171. $list[$key]['uname'] = $member_info['uname'];
  172. $list[$key]['avatar'] = $member_info['avatar'];
  173. }
  174. $list[$key]['create_time'] = date('Y-m-d H:i:s', $value['create_time']);
  175. $content_arr = unserialize( $value['content'] );
  176. $content_arr = unserialize( $value['content'] );
  177. $list[$key]['contents'] = $content_arr;
  178. //$list[$key]['contents']=resize($value['image'], 100, 100);
  179. }
  180. return array(
  181. 'empty'=>'<tr><td colspan="20">~~暂无数据</td></tr>',
  182. 'list'=>$list,
  183. 'page'=>$show
  184. );
  185. }
  186. function show_quan_lzy_page($search)
  187. {
  188. //group_id
  189. $sql='SELECT * FROM '.C('DB_PREFIX').'group_lzl_reply ';
  190. if(!empty($search))
  191. {
  192. if( isset($search['post_id']) )
  193. {
  194. $sql .= " where post_id='".$search['post_id']."' ";
  195. }
  196. }
  197. $count=count(M()->query($sql));
  198. $Page = new \Think\Page($count,C('BACK_PAGE_NUM'));
  199. $show = $Page->show();// 分页显示输出
  200. $sql.=' order by id desc LIMIT '.$Page->firstRow.','.$Page->listRows;
  201. $list=M()->query($sql);
  202. foreach ($list as $key => $value) {
  203. //member_id uname avatar
  204. $list[$key]['content'] = htmlspecialchars_decode($value['content']);
  205. $member_info = M('member')->field('uname,avatar')->where( array('member_id' => $value['member_id']) )->find();
  206. $list[$key]['uname'] = $member_info['uname'];
  207. $list[$key]['avatar'] = $member_info['avatar'];
  208. $list[$key]['create_time'] = date('Y-m-d H:i:s', $value['create_time']);
  209. }
  210. return array(
  211. 'empty'=>'<tr><td colspan="20">~~暂无数据</td></tr>',
  212. 'list'=>$list,
  213. 'page'=>$show
  214. );
  215. }
  216. function add_blog($data){
  217. $error=$this->validate($data);
  218. if($error){
  219. return $error;
  220. }
  221. $blog['title']=$data['title'];
  222. $blog['author']=$data['author'];
  223. $blog['image']=$data['image'];
  224. $blog['type']=$data['type'];
  225. $blog['category_id']=1;
  226. $blog['allow_reply']=1;
  227. $blog['meta_description']=$data['meta_description'];
  228. $blog['meta_keywords']=$data['meta_keywords'];
  229. $blog['status']=$data['status'];
  230. $blog['create_time']=date('Y-m-d H:i:s',time());
  231. $blog_id=M('Blog')->add($blog);
  232. if($blog_id){
  233. try{
  234. $blog_content['blog_id']=$blog_id;
  235. $blog_content['summary']=$data['summary'];
  236. $blog_content['content']=$data['content'];
  237. M('blog_content')->add($blog_content);
  238. return array(
  239. 'status'=>'success',
  240. 'message'=>'新增成功',
  241. 'blog_id' => $blog_id,
  242. 'jump'=>U('Blog/index')
  243. );
  244. }catch(Exception $e){
  245. return array(
  246. 'status'=>'fail',
  247. 'message'=>'新增失败',
  248. 'jump'=>U('Blog/index')
  249. );
  250. }
  251. }else{
  252. return array(
  253. 'status'=>'fail',
  254. 'message'=>'新增失败',
  255. 'jump'=>U('Blog/index')
  256. );
  257. }
  258. }
  259. }
  260. ?>