123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <?php
- namespace App\JsonRpc;
- use App\Model\Link;
- use Hyperf\RpcServer\Annotation\RpcService;
- use App\Tools\Result;
- #[RpcService(name: "LinkService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
- class LinkService implements LinkServiceInterface
- {
- /**
- * @param array $data
- * @return array
- */
- public function getLinkList(array $data): array
- {
- $result = Link::when($data, function ($query) use ($data) {
- if (isset($data['title']) && !empty($data['title'])) {
- $query->where('link.title', 'like', '%' . trim($data['title']) . '%');
- }
- if (isset($data['website_id']) && !empty($data['website_id'])) {
- $query->where('link.website_id', '=', $data['website_id']);
- }
- })
- ->leftJoin("website","website.id","link.website_id")
- ->select("link.*","website.website_name")
- ->limit($data['pageSize'])
- ->offset(($data['page']-1)*$data['pageSize'])
- ->orderBy("link.updated_at","desc")
- ->paginate(intval($data['pageSize']),
- [
- 'link.*',
- 'website.website_name'
- ],
- 'page', intval($data['page']));
- if(empty($result)){
- return Result::error("没有查到数据");
- }
- $result = [
- 'rows'=>$result->items(),
- 'count'=>$result->total()
- ];
- return Result::success($result);
- }
- /**
- * @param array $data
- * @return array
- */
- public function createLink(array $data): array
- {
- $result = Link::insertGetId($data);
- if (empty($result)) {
- return Result::error("创建失败", 0);
- } else {
- return Result::success(["id" => $result]);
- }
- }
- /**
- * @param array $data
- * @return array
- */
- 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);
- } else {
- return Result::success();
- }
- }
- /**
- * @param array $data
- * @return array
- */
- public function delLink(array $data): array
- {
- // return Result::success($data);
- $result = Link::where('id', $data['id'])->delete();
- // return Result::success($result);
- // var_dump($result);
- if (empty($result)) {
- return Result::error("删除失败", 0);
- } else {
- return Result::success($result);
- }
- }
- /**
- * 获取友情链接详情
- * @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);
- }
- }
- }
|