|
@@ -17,25 +17,24 @@ class LinkService implements LinkServiceInterface
|
|
|
public function getLinkList(array $data): array
|
|
|
{
|
|
|
$where = [];
|
|
|
- if(isset($data['keyWord'])){
|
|
|
- $where = [
|
|
|
- ['link.title','like','%'.$data['keyWord'].'%']
|
|
|
- ];
|
|
|
+ if(isset($data['title']) && $data['title']!=''){
|
|
|
+ array_push($where, ['link.title','like','%'.$data['title'].'%']);
|
|
|
}
|
|
|
- $result = [];
|
|
|
- if(isset($data['pageSize'])){
|
|
|
- $rep = Link::where($where)
|
|
|
- ->leftJoin("website","website.id","link.website_id")
|
|
|
- ->select("link.*","website.website_name")
|
|
|
- ->limit($data['pageSize'])->offset(($data['page']-1)*$data['pageSize'])->orderBy("sort","asc")->get();
|
|
|
- $count = Link::where($where)->count();
|
|
|
- $result = [
|
|
|
- 'rows'=>$rep,
|
|
|
- 'count'=>$count
|
|
|
- ];
|
|
|
- }else{
|
|
|
- $result = Link::where($data)->orderBy("sort","asc")->get();
|
|
|
+ if(isset($data['website_id']) && $data['website_id']!=''){
|
|
|
+ array_push($where, ['link.website_id','=',$data['website_id']]);
|
|
|
}
|
|
|
+ $rep = Link::where($where)
|
|
|
+ ->leftJoin("website","website.id","link.website_id")
|
|
|
+ ->select("link.*","website.website_name")
|
|
|
+ ->limit($data['pageSize'])->offset(($data['page']-1)*$data['pageSize'])->orderBy("sort","desc")->get();
|
|
|
+ $count = Link::where($where)
|
|
|
+ ->leftJoin("website","website.id","link.website_id")
|
|
|
+ ->count();
|
|
|
+ $result = [
|
|
|
+ 'rows'=>$rep,
|
|
|
+ 'count'=>$count
|
|
|
+ ];
|
|
|
+
|
|
|
return $result?Result::success($result):Result::error("没有查到数据");
|
|
|
}
|
|
|
|
|
@@ -45,8 +44,6 @@ class LinkService implements LinkServiceInterface
|
|
|
*/
|
|
|
public function createLink(array $data): array
|
|
|
{
|
|
|
-
|
|
|
-
|
|
|
$result = Link::insertGetId($data);
|
|
|
if (empty($result)) {
|
|
|
return Result::error("创建失败", 0);
|
|
@@ -61,9 +58,6 @@ class LinkService implements LinkServiceInterface
|
|
|
*/
|
|
|
public function updateLink(array $data): array
|
|
|
{
|
|
|
- //website_name` = '三农市场网', `status_name` =
|
|
|
- unset($data['website_name']);
|
|
|
- unset($data['status_name']);
|
|
|
$result = Link::where('id', $data['id'])->update($data);
|
|
|
if (empty($result)) {
|
|
|
return Result::error("更新失败", 0);
|
|
@@ -76,9 +70,9 @@ class LinkService implements LinkServiceInterface
|
|
|
* @param int $id
|
|
|
* @return array
|
|
|
*/
|
|
|
- public function delLink(int $id): array
|
|
|
+ public function delLink(array $data): array
|
|
|
{
|
|
|
- $result = Link::where('id', $id)->delete();
|
|
|
+ $result = Link::where('id', $data['id'])->delete();
|
|
|
if (empty($result)) {
|
|
|
return Result::error("删除失败", 0);
|
|
|
} else {
|
|
@@ -86,5 +80,20 @@ class LinkService implements LinkServiceInterface
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取友情链接详情
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function getLinkInfo(array $data): array
|
|
|
+ {
|
|
|
+ $result = Link::where('id', $data['id'])->first();
|
|
|
+ if (empty($result)) {
|
|
|
+ return Result::error("获取友情链接详情失败", 0);
|
|
|
+ } else {
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|