Link.php 2.7 KB

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