123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- <?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
- {
- $where = [];
- if(isset($data['title']) && $data['title']!=''){
- array_push($where, ['link.title','like','%'.$data['title'].'%']);
- }
- 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("没有查到数据");
- }
- /**
- * @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
- {
- $result = Link::where('id', $data['id'])->update($data);
- if (empty($result)) {
- return Result::error("更新失败", 0);
- } else {
- return Result::success();
- }
- }
- /**
- * @param int $id
- * @return array
- */
- public function delLink(array $data): array
- {
- $result = Link::where('id', $data['id'])->delete();
- if (empty($result)) {
- return Result::error("删除失败", 0);
- } else {
- return Result::success();
- }
- }
- /**
- * 获取友情链接详情
- * @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);
- }
- }
- }
|