123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631 |
- <?php
- namespace App\JsonRpc;
- use App\Model\TemplateClass;
- use App\Model\Template;
- use App\Model\WebsiteRole;
- use App\Model\WebsiteRoleUser;
- use App\Model\Website;
- use App\Model\WebsiteColumn;
- use Hyperf\RpcServer\Annotation\RpcService;
- use App\Tools\Result;
- use App\Model\WebsiteCategory;
- use function PHPUnit\Framework\isNull;
- #[RpcService(name: "WebsiteService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
- class WebsiteService implements WebsiteServiceInterface
- {
- /**
- * @param string $keyword
- * @param int $page
- * @param int $pageSize
- * @return array
- */
- public function getWebsitetList(array $data): array
- {
- $where = [];
- if(isset($data['keyword']) && !empty($data['keyword'])){
- array_push($where,['website.website_name','like','%'.$data['keyword'].'%']);
- }
- if(isset($data['website_column_id']) && !empty($data['website_column_id'])){
- array_push($where,['website.website_column_id','=',$data['website_column_id']]);
- }
- if(isset($data['city_id']) && !empty($data['city_id'])){
- array_push($where,['website.city_id','=',$data['city_id']]);
- }
- $result = Website::where($where)
- ->leftJoin("website_column","website.website_column_id","website_column.id")
- ->leftJoin("district","district.id","website.city_id")
- ->select("website.*","website_column.column_name","district.name as city_name")
- ->limit($data['pageSize'])->offset(($data['page']-1)*$data['pageSize'])->get();
- $count = Website::where($where)->count();
- if (empty($result)) {
- return Result::error("没有数据",0);
- }
- $data = [
- 'rows'=>$result->toArray(),
- 'count'=>$count
- ];
- return Result::success($data);
- }
- /**
- * @param array $data
- * @return array
- */
- public function createWebsite(array $data): array
- {
- var_dump("网站数据:",$data);
- $insertData = [
- 'website_name'=>$data['website_name'],
- 'logo'=>$data['logo']??'',
- 'website_url'=>$data['website_url']??'',
- 'city_id'=>$data['city_id']??0,
- 'website_column_id'=>$data['website_column_id'],
- 'title'=>$data['title']??'',
- 'keywords'=>$data['keywords']??'',
- 'description'=>$data['description']??'',
- 'status'=>$data['status']??0,
- 'website_column_arr_id'=>$data['website_column_arr_id'],
- 'city_arr_id'=>$data['city_arr_id']??[0],
- 'template_id' =>$data['template_id']??0,
- ];
- $result = Website::insertGetId($insertData);
- if(empty($result)){
- return Result::error("创建失败",0);
- }else{
- return Result::success(["id"=>$result]);
- }
- }
- /**
- * @param int $id
- * @param array $data
- * @return array
- */
- public function updateWebsite(int $id,array $data): array
- {
- $insertData = [
- 'website_name'=>$data['website_name'],
- 'logo'=>$data['logo']??'',
- 'website_url'=>$data['website_url']??'',
- 'city_id'=>$data['city_id']??0,
- 'website_column_id'=>$data['website_column_id'],
- 'title'=>$data['title']??'',
- 'keywords'=>$data['keywords']??'',
- 'description'=>$data['description']??'',
- 'status'=>$data['status']??0,
- 'website_column_arr_id'=>$data['website_column_arr_id'],
- 'city_arr_id'=>$data['city_arr_id']??[0],
- 'template_id' =>$data['template_id']??0,
- ];
- $result = Website::where('id',$id)->update($insertData);
- var_dump("更新站点",$result);
- if(empty($result)){
- return Result::error("更新失败",0);
- }else{
- return Result::success();
- }
- }
- /**
- * @param int $id
- * @return array
- */
- public function delWebsite(int $id): array
- {
- $result = Website::where('id',$id )->delete();
- var_dump("删除站点",$result);
- if(empty($result)){
- return Result::error("删除失败",0);
- }else{
- return Result::success();
- }
- }
- /**
- * @param int $id
- * @return array
- */
- public function getWebsiteInfo(int $id): array
- {
- $where = [
- ['website.id','=',$id]
- ];
- $result = Website::where($where )
- ->leftJoin("template","template.id","website.template_id")
- ->select("website.*","template.template_name","template.template_img")
- ->first();
- if(empty($result)){
- return Result::error("数据不存在",0);
- }else{
- return Result::success($result->toArray());
- }
- }
- /**
- * 查询所有的站点栏目
- * @return array
- */
- public function getWebsiteColumn(array $data): array
- {
- $result = WebsiteColumn::where($data)->get();
- if(empty($result)){
- return Result::error("数据不存在",0);
- }else{
- return Result::success($result->toArray());
- }
- }
- /**
- * @param string $keyword
- * @param int $page
- * @param int $pageSize
- * @return array
- */
- public function getWebsiteColumnList(string $keyword,int $page,int $pageSize):array
- {
- $where = [
- ['website_column.column_name','like','%'.$keyword.'%']
- ];
- $result = WebsiteColumn::where($where)
- ->leftJoin("website_column as wc","website_column.pid","wc.id")
- ->select("website_column.*","wc.column_name as parent_column_name")
- ->limit($pageSize)->offset(($page-1)*$pageSize)->get();
- $count = WebsiteColumn::where($where)->count();
- if (empty($result)) {
- return Result::error("没有数据",0);
- }
- $data = [
- 'rows'=>$result->toArray(),
- 'count'=>$count
- ];
- return Result::success($data);
- }
- /**
- * @param array $data
- * @return array
- */
- public function createWebsiteColumn(array $data): array
- {
- $insertData = [
- 'column_name'=>$data['column_name'],
- 'pid'=>$data['pid']??'',
- 'column_arr_id'=>$data['column_arr_id']??[0],
- 'sort'=>$data['sort']??0,
- 'remark'=>$data['remark']??'',
- ];
- $result = WebsiteColumn::insertGetId($insertData);
- if(empty($result)){
- return Result::error("创建失败",0);
- }else{
- return Result::success(["id"=>$result]);
- }
- }
- /**
- * @param int $id
- * @param array $data
- * @return array
- */
- public function updateWebsiteColumn(int $id,array $data): array
- {
- $insertData = [
- 'column_name'=>$data['column_name'],
- 'pid'=>$data['pid']??'',
- 'column_arr_id'=>$data['column_arr_id']??[0],
- 'sort'=>$data['sort']??0,
- 'remark'=>$data['remark']??'',
- ];
- $result = WebsiteColumn::where('id',$id)->update($insertData);
- if(empty($result)){
- return Result::error("更新失败",0);
- }else{
- return Result::success();
- }
- }
- /**
- * @param int $id
- * @return array
- */
- public function delWebsiteColumn(int $id): array
- {
- $result = WebsiteColumn::where('id',$id )->delete();
- if(empty($result)){
- return Result::error("删除失败",0);
- }else{
- return Result::success();
- }
- }
- /**
- * @param string $keyword
- * @param int $page
- * @param int $pageSize
- * @return array
- */
- public function getWebsiteRoleList(string $keyword,int $page,int $pageSize,int $websiteId):array
- {
- $where = [
- ['role.role_name','like','%'.$keyword.'%'],
- ['website_role.website_id','=',$websiteId],
- ];
- $result = WebsiteRole::where($where)
- ->leftJoin("role","role.id","website_role.role_id")
- ->select("role.*","website_role.type","website_role.role_id","website_role.id as website_role_id","website_role.website_id")
- ->limit($pageSize)->offset(($page-1)*$pageSize)->get();
- $count = WebsiteRole::where($where) ->leftJoin("role","role.id","website_role.role_id")->count();
- if (empty($result)) {
- return Result::error("没有数据",0);
- }
- $data = [
- 'rows'=>$result->toArray(),
- 'count'=>$count
- ];
- return Result::success($data);
- }
- /**
- * @param array $data
- * @return array
- */
- public function createWebsiteRole(array $data): array
- {
- $insertData = [
- 'website_id'=>$data['website_id'],
- 'role_id'=>$data['role_id']??''
- ];
- $info = WebsiteRole::where($insertData)->first();
- if($info){
- return Result::error("不能重复添加角色",0);
- }
- $insertData['admin_user_id'] = $data['admin_user_id']??'';
- $insertData['type'] = $data['type']??'';
- $result = WebsiteRole::insertGetId($insertData);
- if(empty($result)){
- return Result::error("创建失败",0);
- }else{
- return Result::success(["id"=>$result]);
- }
- }
- /**
- * 暂时用不上
- * @param int $id
- * @param array $data
- * @return array
- */
- public function updateWebsiteRole(int $id,array $data): array
- {
- $insertData = [
- 'website_id'=>$data['website_id'],
- 'type'=>$data['type']??'',
- ];
- $result = WebsiteRole::where('id',$id)->update($insertData);
- if(empty($result)){
- return Result::error("更新失败",0);
- }else{
- return Result::success();
- }
- }
- /**
- * @param int $id
- * @return array
- */
- public function delWebsiteRole(int $id): array
- {
- $result = WebsiteRole::where('id',$id )->delete();
- if(empty($result)){
- return Result::error("删除失败",0);
- }else{
- return Result::success();
- }
- }
- /**
- * @param string $keyword
- * @param int $page
- * @param int $pageSize
- * @return array
- */
- public function getWebsiteRoleUserList(string $keyword,int $page,int $pageSize,int $websiteId,int $roleId):array
- {
- $where = [
- ['website_role_user.website_id','=',$websiteId],
- ['website_role_user.role_id','=',$roleId],
- ];
- $count = WebsiteRoleUser::where($where)->count();
- $where[] = ['u.user_name','like','%'.$keyword.'%'];
- $result = WebsiteRoleUser::where($where)
- ->leftJoin("user as u","website_role_user.user_id","u.id")
- ->leftJoin("website as w","website_role_user.website_id","u.id")
- ->leftJoin("role as r","website_role_user.role_id","r.id")
- ->select("u.*","u.user_name",'w.website_name','r.role_name','website_role_user.id as website_role_user_id','website_role_user.updated_at as user_update_at')
- ->limit($pageSize)->offset(($page-1)*$pageSize)->get();
- if (empty($result)) {
- return Result::error("没有数据",0);
- }
- $data = [
- 'rows'=>$result->toArray(),
- 'count'=>$count
- ];
- return Result::success($data);
- }
- /**
- * @param array $data
- * @return array
- */
- public function createWebsiteRoleUser(array $data): array
- {
- $insertData = [
- 'website_id'=>$data['website_id'],
- 'user_id'=>$data['user_id']??'',
- ];
- $info = WebsiteRoleUser::where($insertData)->first();
- if($info){
- return Result::error("不能重复添加角色用户",0);
- }
- $insertData['role_id'] = $data['role_id']??'';
- $insertData['admin_user_id'] = $data['admin_user_id']??'';
- $insertData['type'] = $data['type']??'';
- $result = WebsiteRoleUser::insertGetId($insertData);
- if(empty($result)){
- return Result::error("创建失败",0);
- }else{
- return Result::success(["id"=>$result]);
- }
- }
- /**
- * @param int $id
- * @param array $data
- * @return array
- */
- public function updateWebsiteRoleUser(int $id,array $data): array
- {
- $insertData = [
- 'website_id'=>$data['website_id'],
- 'type'=>$data['type']??'',
- 'type_id'=>$data['type_id']??'',
- 'role_id'=>$data['role_id']??'',
- ];
- $result = WebsiteRoleUser::where('id',$id)->update($insertData);
- if(empty($result)){
- return Result::error("更新失败",0);
- }else{
- return Result::success();
- }
- }
- /**
- * @param int $id
- * @return array
- */
- public function delWebsiteRoleUser(int $id): array
- {
- $result = WebsiteRoleUser::where('id',$id )->delete();
- if(empty($result)){
- return Result::error("删除失败",0);
- }else{
- return Result::success();
- }
- }
- /**
- * 根据域名获取网站 站点id
- * @param array $data
- * @return array
- */
- public function getWebsiteId(array $data): array
- {
- $where = [
- 'website_url'=>$data['website_url']
- ];
- $result = Website::where($where)->first();
- if(empty($result)){
- return Result::error("查询站点失败",0);
- }else{
- return Result::success($result);
- }
- }
- /**
- * 查询网站下面的导航
- * @param array $data
- * @return array
- */
- public function getWebsiteCategory(array $data): array
- {
- $where = [
- 'website_id'=>$data['website_id'],
- 'pid'=>0
- ];
- $result = WebsiteCategory::where($where)->orderBy('sort','asc')->get();
- if(empty($result)){
- return Result::error("查询站点栏目失败",0);
- }else{
- return Result::success($result);
- }
- }
- /**
- * 网站首页数据统计, 管理员
- * @return void
- */
- public function getAdminIndex(array $data): array
- {
- return [];
- }
- /**
- * 获取模板类型
- * @return void
- */
- public function getTemplateClass(array $data): array
- {
- $result = TemplateClass::orderBy('sort','asc')->get();
- if(empty($result)){
- return Result::error("没有模板类型",0);
- }else{
- return Result::success($result);
- }
- }
- /**
- * 添加模板类型
- * @param
- * @return void
- */
- public function addTemplateClass(array $data): array
- {
- $insertData = [
- 'name'=>$data['name']
- ];
- $result = TemplateClass::insertGetId($insertData);
- if(empty($result)){
- return Result::error("创建失败",0);
- }else{
- return Result::success(["id"=>$result]);
- }
- }
- /**
- * 更新模板
- * @param array $data
- * @return array
- */
- public function upTemplateClass(array $data): array
- {
- $where = [
- 'id'=>$data['id']
- ];
- $insertData = [
- 'name'=>$data['name']
- ];
- $result = TemplateClass::where($where)->update($insertData);
- if(empty($result)){
- return Result::error("更新失败",0);
- }else{
- return Result::success();
- }
- }
- /**
- * 删除模板
- * @param array $data
- * @return array
- */
- public function delTemplateClass(array $data): array
- {
- $where = [
- 'id'=>$data['id']
- ];
- $result = TemplateClass::where($where)->delete();
- if(empty($result)){
- return Result::error("删除失败",0);
- }else{
- return Result::success();
- }
- }
- /**
- * 获取分类下的模板
- * @param array $data
- * @return array
- */
- public function getTemplate(array $data): array
- {
- $page = $data['page'];
- $pageSize = $data['pageSize'];
- $where = [
- 'template_class_id'=> $data['template_class_id']
- ];
- $result = Template::where($where)
- ->limit($pageSize)->offset(($page-1)*$pageSize)->get();
- $count = Template::where($where)->count();
- if (empty($result)) {
- return Result::error("没有数据",0);
- }
- $data = [
- 'rows'=>$result->toArray(),
- 'count'=>$count
- ];
- return Result::success($data);
- }
- /**
- * 创建模板
- * @param
- * @return void
- */
- public function addTemplate(array $data): array
- {
- $insertData = [
- 'template_name'=>$data['template_name'],
- 'template_img'=>json_encode($data['template_img']),
- 'template_class_id'=>$data['template_class_id'],
- ];
- $result = Template::insertGetId($insertData);
- if(empty($result)){
- return Result::error("创建模板失败",0);
- }else{
- return Result::success(["id"=>$result]);
- }
- }
- /**
- * 更新模板
- * @param array $data
- * @return array
- */
- public function upTemplate(array $data): array
- {
- $where = [
- 'id'=>$data['id']
- ];
- $insertData = [
- 'template_name'=>$data['template_name'],
- 'template_img'=>json_encode($data['template_img']),
- 'template_class_id'=>$data['template_class_id'],
- ];
- $result = Template::where($where)->update($insertData);
- if(empty($result)){
- return Result::error("更新模板失败",0);
- }else{
- return Result::success();
- }
- }
- /**
- * 删除模板
- * @param array $data
- * @return array
- */
- public function delTemplate(array $data): array
- {
- $where = [
- 'id'=>$data['id']
- ];
- $result = Template::where($where)->delete();
- if(empty($result)){
- return Result::error("删除模板失败",0);
- }else{
- return Result::success();
- }
- }
- }
|