Link.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace app\common\model;
  3. use think\facade\Db;
  4. /**
  5. *
  6. *
  7. * ----------------------------------------------------------------------------
  8. *
  9. * 数据层模型
  10. */
  11. class Link extends BaseModel
  12. {
  13. public $page_info;
  14. /**
  15. * 友情链接列表
  16. * @access public
  17. * @author csdeshang
  18. * @param type $condition 查询条件
  19. * @param type $pagesize 分页页数
  20. * @param type $order 排序
  21. * @return type 返回结果
  22. */
  23. public function getLinkList($condition = '', $pagesize = '', $order = 'link_sort asc')
  24. {
  25. if ($pagesize) {
  26. $result = Db::name('link')->where($condition)->order($order)->paginate(['list_rows' => $pagesize, 'query' => request()->param()], false);
  27. $this->page_info = $result;
  28. return $result->items();
  29. } else {
  30. return Db::name('link')->where($condition)->order($order)->select()->toArray();
  31. }
  32. }
  33. /**
  34. * 取单个友情链接
  35. * @access public
  36. * @author csdeshang
  37. * @param type $id 链接ID
  38. * @return type
  39. */
  40. public function getOneLink($id)
  41. {
  42. return Db::name('link')->where('link_id', $id)->find();
  43. }
  44. /**
  45. * 新增友情链接
  46. * @access public
  47. * @author csdeshang
  48. * @param type $data 参数内容
  49. * @return type
  50. */
  51. public function addLink($data)
  52. {
  53. return Db::name('link')->insertGetId($data);
  54. }
  55. /**
  56. * 更新友情链接
  57. * @access public
  58. * @author csdeshang
  59. * @param type $data 更新数据
  60. * @param type $link_id 链接id
  61. * @return type
  62. */
  63. public function editLink($data, $link_id)
  64. {
  65. return Db::name('link')->where('link_id', $link_id)->update($data);
  66. }
  67. /**
  68. * 删除
  69. * @access public
  70. * @author csdeshang
  71. * @param array $id 链接id
  72. * @return bool
  73. */
  74. public function delLink($id)
  75. {
  76. $link = $this->getOneLink($id);
  77. //删除友情链接图片
  78. @unlink(BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . DIR_ADMIN . DIRECTORY_SEPARATOR . 'link' . DIRECTORY_SEPARATOR . $link['link_pic']);
  79. return Db::name('link')->where('link_id', intval($id))->delete();
  80. }
  81. }