| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- <?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
- {
- $query = 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', 'link.website_id', '=', 'website.id')
- ->select("link.*",'website.website_name')
- ->orderBy("link.updated_at","desc")
- ->orderBy("link.id");
- $result['count'] = $query->count();
- $result['rows'] = $query->offset(($data['page']-1)*$data['pageSize'])
- ->limit($data['pageSize'])
- ->get()
- ->all();
- if($result['count'] == 0){
- return Result::error("没有查到数据");
- }
- 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);
- }
- }
- }
|