Link.php 2.5 KB

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