|
@@ -1,240 +1,240 @@
|
|
|
-<?php
|
|
|
-namespace App\JsonRpc;
|
|
|
-use App\Model\Ad;
|
|
|
-use App\Model\AdPlace;
|
|
|
-use Hyperf\RpcServer\Annotation\RpcService;
|
|
|
-use App\Tools\Result;
|
|
|
-#[RpcService(name: "AdService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
|
|
|
-class AdService implements AdServiceInterface
|
|
|
-{
|
|
|
- /**
|
|
|
- * @param array $data
|
|
|
- * @return string
|
|
|
- */
|
|
|
- public function createAd(array $data): array
|
|
|
- {
|
|
|
- $insertData = [
|
|
|
- 'name'=>$data['name']??'',
|
|
|
- 'pid'=>$data['pid']??0,
|
|
|
- 'areaid'=>$data['areaid']??0,
|
|
|
- 'amount'=>$data['amount']??0,//浏览数量
|
|
|
- 'introduce'=>$data['introduce']??'',
|
|
|
- 'hits'=>$data['hits']??0, //点击数量
|
|
|
- 'fromtime'=>$data['f_t_date'][0]??0,
|
|
|
- 'totime'=>$data['f_t_date'][1]??0,
|
|
|
- 'text_name'=>$data['text_name']??'',
|
|
|
- 'text_url'=>$data['text_url']??'',
|
|
|
- 'text_title'=>$data['text_title']??'',
|
|
|
- 'image_src'=>$data['image_src']??'',
|
|
|
- 'image_url'=>$data['image_url']??'',
|
|
|
- 'image_alt'=>$data['image_alt']??'',
|
|
|
- 'video_src'=>$data['video_src']??'',//视频
|
|
|
- 'video_url'=>$data['video_url']??'',
|
|
|
- 'video_auto'=>$data['video_auto'] ??0,
|
|
|
- 'video_loop'=>$data['video_loop'] ??0,
|
|
|
- 'status'=>$data['status']??2,
|
|
|
- 'remark'=>$data['remark']??'',
|
|
|
- ];
|
|
|
- $result = Ad::query()->insertGetId($insertData);
|
|
|
- if($result){
|
|
|
- return Result::success();
|
|
|
- }else{
|
|
|
- return Result::error("创建广告失败",500);
|
|
|
- }
|
|
|
- }
|
|
|
- /**
|
|
|
- * @param int $id
|
|
|
- * @return array
|
|
|
- */
|
|
|
- public function getAdInfo(int $id): array
|
|
|
- {
|
|
|
- $adInfo = Ad::query()->find($id);
|
|
|
- if (empty($adInfo)) {
|
|
|
- return Result::error("没有数据",0);
|
|
|
- }
|
|
|
- return Result::success($adInfo->toArray());
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @param array $data
|
|
|
- * @return array
|
|
|
- */
|
|
|
- public function getAdList(array $data): array
|
|
|
- {
|
|
|
- if(isset($data['pid'])){
|
|
|
- $where[] = ['ad.pid','=',$data['pid']];
|
|
|
- }
|
|
|
- $rep = Ad::where($where)
|
|
|
- ->leftJoin("ad_place","ad.pid","ad_place.id")
|
|
|
- ->leftJoin("website","website.id","ad_place.website_id")
|
|
|
- ->select("ad.*","ad_place.name as place_name","ad_place.typeid","website.website_name")
|
|
|
- ->limit($data['pageSize'])->orderBy("ad.id","desc")->offset(($data['page']-1)*$data['pageSize'])->get();
|
|
|
- $count = Ad::where($where)
|
|
|
- ->leftJoin("ad_place","ad.pid","ad_place.id")
|
|
|
- ->leftJoin("website","website.id","ad_place.website_id")
|
|
|
- ->count();
|
|
|
- $data = [
|
|
|
- 'rows'=>$rep->toArray(),
|
|
|
- 'count'=>$count
|
|
|
- ];
|
|
|
- if(empty($rep->toArray())){
|
|
|
- return Result::error("没有数据");
|
|
|
- }
|
|
|
- return Result::success($data);
|
|
|
- }
|
|
|
-
|
|
|
- public function updateAd(array $data): array
|
|
|
- {
|
|
|
- $where = [
|
|
|
- 'id'=>$data['id']
|
|
|
- ];
|
|
|
- $insertData = [
|
|
|
- 'name'=>$data['name']??'',
|
|
|
- 'pid'=>$data['pid']??0,
|
|
|
- 'areaid'=>$data['areaid']??0,
|
|
|
- 'amount'=>$data['amount']??0,//浏览数量
|
|
|
- 'introduce'=>$data['introduce']??'',
|
|
|
- 'hits'=>$data['hits']??0, //点击数量
|
|
|
- 'fromtime'=>$data['f_t_date'][0]??0,
|
|
|
- 'totime'=>$data['f_t_date'][1]??0,
|
|
|
- 'text_name'=>$data['text_name']??'',
|
|
|
- 'text_url'=>$data['text_url']??'',
|
|
|
- 'text_title'=>$data['text_title']??'',
|
|
|
- 'image_src'=>$data['image_src']??'',
|
|
|
- 'image_url'=>$data['image_url']??'',
|
|
|
- 'image_alt'=>$data['image_alt']??'',
|
|
|
- 'video_src'=>$data['video_src']??'',//视频
|
|
|
- 'video_url'=>$data['video_url']??'',
|
|
|
- 'video_auto'=>isset($data['video_auto']) && empty($data['video_auto'])?0:$data['video_auto'],
|
|
|
- 'video_loop'=>isset($data['video_loop']) && empty($data['video_loop'])?0:$data['video_loop'],
|
|
|
- 'status'=>$data['status']??2,
|
|
|
- 'remark'=>$data['remark']??'',
|
|
|
- ];
|
|
|
- $result = Ad::where($where)->update($insertData);
|
|
|
- if($result){
|
|
|
- return Result::success($result);
|
|
|
- }else{
|
|
|
- return Result::error("更新失败");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public function delAd(array $data): array
|
|
|
- {
|
|
|
- $result = Ad::where($data)->delete();
|
|
|
- if(!$result){
|
|
|
- return Result::error("删除失败");
|
|
|
- }
|
|
|
- return Result::success($result);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 广告位列表
|
|
|
- * @param array $data
|
|
|
- * @return array
|
|
|
- */
|
|
|
- public function getAdPlaceList(array $data): array
|
|
|
- {
|
|
|
-
|
|
|
- $where = [];
|
|
|
- if(isset($data['name']) && $data['name']){
|
|
|
- array_push($where,['ad_place.name','like','%'.$data['name'].'%']);
|
|
|
- }
|
|
|
- if(isset($data['website_id']) && $data['website_id']){
|
|
|
- array_push($where,['ad_place.website_id','=',$data['website_id']]);
|
|
|
- }
|
|
|
- $rep = AdPlace::where($where)
|
|
|
- ->leftJoin("ad_size","ad_place.ad_size_id","ad_size.id")
|
|
|
- ->leftJoin("website","website.id","ad_place.website_id")
|
|
|
- ->limit($data['pageSize'])
|
|
|
- ->orderBy("id","desc")
|
|
|
- ->offset(($data['page']-1)*$data['pageSize'])
|
|
|
- ->select("ad_place.*","ad_size.width","ad_size.height","website.website_name")
|
|
|
- ->get();
|
|
|
- $count = AdPlace::where($where)->count();
|
|
|
- $reponse = [
|
|
|
- 'rows'=>$rep->toArray(),
|
|
|
- 'count'=>$count
|
|
|
- ];
|
|
|
- if(empty($rep->toArray())){
|
|
|
- return Result::error("没有数据");
|
|
|
- }
|
|
|
- return Result::success($reponse);
|
|
|
- }
|
|
|
-
|
|
|
- public function createAdPlace(array $data): array
|
|
|
- {
|
|
|
- unset($data['size']);
|
|
|
- $result = AdPlace::query()->insertGetId($data);
|
|
|
- if($result){
|
|
|
- return Result::success();
|
|
|
- }else{
|
|
|
- return Result::error("创建广告位失败",500);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 'name' => 'required', //广告位名称
|
|
|
- * 'website_id' => 'required',//关联的网站id
|
|
|
- * 'price' => 'required',//价格
|
|
|
- * 'thumb'=>'required', //广告示意图
|
|
|
- * 'typeid'=>'required', //广告类型
|
|
|
- * 'ad_size_id'=>'required', //广告位大小
|
|
|
- * 'status'=>'required', //状态
|
|
|
- * @param array $data
|
|
|
- * @return array
|
|
|
- */
|
|
|
- public function updateAdPlace(array $data): array
|
|
|
- {
|
|
|
- $where = [
|
|
|
- 'id'=>$data['id']
|
|
|
- ];
|
|
|
- $Insdata = [
|
|
|
- 'website_id'=>$data['website_id']??'',
|
|
|
- 'typeid'=>$data['typeid']??1,
|
|
|
- 'status'=>$data['status']??2,
|
|
|
- 'name'=>$data['name']??'',
|
|
|
- 'thumb'=>$data['thumb']??'',
|
|
|
- 'introduce'=>$data['introduce']??'',
|
|
|
- 'code'=>$data['code']??'',
|
|
|
- 'price'=>$data['price']??0,
|
|
|
- 'ad_size_id'=>$data['ad_size_id']??0,
|
|
|
- ];
|
|
|
- $result = AdPlace::where($where)->update($Insdata);
|
|
|
- if($result){
|
|
|
- return Result::success($result);
|
|
|
- }else{
|
|
|
- return Result::error("更新失败");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 删除广告位
|
|
|
- * @param array $data
|
|
|
- * @return array
|
|
|
- */
|
|
|
- public function delAdPlace(array $data): array
|
|
|
- {
|
|
|
- $adList = Ad::where(['pid'=>$data['id']])->get();
|
|
|
- if($adList->toArray()){
|
|
|
- return Result::error("广告位里面还有广告,不能删除广告位");
|
|
|
- }
|
|
|
- $result = AdPlace::where($data)->delete();
|
|
|
- if(!$result){
|
|
|
- return Result::error("删除失败");
|
|
|
- }
|
|
|
- return Result::success($result);
|
|
|
- }
|
|
|
- /**
|
|
|
- * @param int $id
|
|
|
- * @return array
|
|
|
- */
|
|
|
- public function getAdPlaceInfo(int $id): array
|
|
|
- {
|
|
|
- $adInfo = AdPlace::query()->find($id);
|
|
|
- if (empty($adInfo)) {
|
|
|
- return Result::error("没有数据",0);
|
|
|
- }
|
|
|
- return Result::success($adInfo->toArray());
|
|
|
- }
|
|
|
-
|
|
|
+<?php
|
|
|
+namespace App\JsonRpc;
|
|
|
+use App\Model\Ad;
|
|
|
+use App\Model\AdPlace;
|
|
|
+use Hyperf\RpcServer\Annotation\RpcService;
|
|
|
+use App\Tools\Result;
|
|
|
+#[RpcService(name: "AdService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
|
|
|
+class AdService implements AdServiceInterface
|
|
|
+{
|
|
|
+ /**
|
|
|
+ * @param array $data
|
|
|
+ * @return string
|
|
|
+ */
|
|
|
+ public function createAd(array $data): array
|
|
|
+ {
|
|
|
+ $insertData = [
|
|
|
+ 'name'=>$data['name']??'',
|
|
|
+ 'pid'=>$data['pid']??0,
|
|
|
+ 'areaid'=>$data['areaid']??0,
|
|
|
+ 'amount'=>$data['amount']??0,//浏览数量
|
|
|
+ 'introduce'=>$data['introduce']??'',
|
|
|
+ 'hits'=>$data['hits']??0, //点击数量
|
|
|
+ 'fromtime'=>$data['f_t_date'][0]??0,
|
|
|
+ 'totime'=>$data['f_t_date'][1]??0,
|
|
|
+ 'text_name'=>$data['text_name']??'',
|
|
|
+ 'text_url'=>$data['text_url']??'',
|
|
|
+ 'text_title'=>$data['text_title']??'',
|
|
|
+ 'image_src'=>$data['image_src']??'',
|
|
|
+ 'image_url'=>$data['image_url']??'',
|
|
|
+ 'image_alt'=>$data['image_alt']??'',
|
|
|
+ 'video_src'=>$data['video_src']??'',//视频
|
|
|
+ 'video_url'=>$data['video_url']??'',
|
|
|
+ 'video_auto'=>$data['video_auto'] ??0,
|
|
|
+ 'video_loop'=>$data['video_loop'] ??0,
|
|
|
+ 'status'=>$data['status']??2,
|
|
|
+ 'remark'=>$data['remark']??'',
|
|
|
+ ];
|
|
|
+ $result = Ad::query()->insertGetId($insertData);
|
|
|
+ if($result){
|
|
|
+ return Result::success();
|
|
|
+ }else{
|
|
|
+ return Result::error("创建广告失败",500);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * @param int $id
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function getAdInfo(int $id): array
|
|
|
+ {
|
|
|
+ $adInfo = Ad::query()->find($id);
|
|
|
+ if (empty($adInfo)) {
|
|
|
+ return Result::error("没有数据",0);
|
|
|
+ }
|
|
|
+ return Result::success($adInfo->toArray());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function getAdList(array $data): array
|
|
|
+ {
|
|
|
+ if(isset($data['pid'])){
|
|
|
+ $where[] = ['ad.pid','=',$data['pid']];
|
|
|
+ }
|
|
|
+ $rep = Ad::where($where)
|
|
|
+ ->leftJoin("ad_place","ad.pid","ad_place.id")
|
|
|
+ ->leftJoin("website","website.id","ad_place.website_id")
|
|
|
+ ->select("ad.*","ad_place.name as place_name","ad_place.typeid","website.website_name")
|
|
|
+ ->limit($data['pageSize'])->orderBy("ad.id","desc")->offset(($data['page']-1)*$data['pageSize'])->get();
|
|
|
+ $count = Ad::where($where)
|
|
|
+ ->leftJoin("ad_place","ad.pid","ad_place.id")
|
|
|
+ ->leftJoin("website","website.id","ad_place.website_id")
|
|
|
+ ->count();
|
|
|
+ $data = [
|
|
|
+ 'rows'=>$rep->toArray(),
|
|
|
+ 'count'=>$count
|
|
|
+ ];
|
|
|
+ if(empty($rep->toArray())){
|
|
|
+ return Result::error("没有数据");
|
|
|
+ }
|
|
|
+ return Result::success($data);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function updateAd(array $data): array
|
|
|
+ {
|
|
|
+ $where = [
|
|
|
+ 'id'=>$data['id']
|
|
|
+ ];
|
|
|
+ $insertData = [
|
|
|
+ 'name'=>$data['name']??'',
|
|
|
+ 'pid'=>$data['pid']??0,
|
|
|
+ 'areaid'=>$data['areaid']??0,
|
|
|
+ 'amount'=>$data['amount']??0,//浏览数量
|
|
|
+ 'introduce'=>$data['introduce']??'',
|
|
|
+ 'hits'=>$data['hits']??0, //点击数量
|
|
|
+ 'fromtime'=>$data['f_t_date'][0]??0,
|
|
|
+ 'totime'=>$data['f_t_date'][1]??0,
|
|
|
+ 'text_name'=>$data['text_name']??'',
|
|
|
+ 'text_url'=>$data['text_url']??'',
|
|
|
+ 'text_title'=>$data['text_title']??'',
|
|
|
+ 'image_src'=>$data['image_src']??'',
|
|
|
+ 'image_url'=>$data['image_url']??'',
|
|
|
+ 'image_alt'=>$data['image_alt']??'',
|
|
|
+ 'video_src'=>$data['video_src']??'',//视频
|
|
|
+ 'video_url'=>$data['video_url']??'',
|
|
|
+ 'video_auto'=>isset($data['video_auto']) && empty($data['video_auto'])?0:$data['video_auto'],
|
|
|
+ 'video_loop'=>isset($data['video_loop']) && empty($data['video_loop'])?0:$data['video_loop'],
|
|
|
+ 'status'=>$data['status']??2,
|
|
|
+ 'remark'=>$data['remark']??'',
|
|
|
+ ];
|
|
|
+ $result = Ad::where($where)->update($insertData);
|
|
|
+ if($result){
|
|
|
+ return Result::success($result);
|
|
|
+ }else{
|
|
|
+ return Result::error("更新失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function delAd(array $data): array
|
|
|
+ {
|
|
|
+ $result = Ad::where($data)->delete();
|
|
|
+ if(!$result){
|
|
|
+ return Result::error("删除失败");
|
|
|
+ }
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 广告位列表
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function getAdPlaceList(array $data): array
|
|
|
+ {
|
|
|
+
|
|
|
+ $where = [];
|
|
|
+ if(isset($data['name']) && $data['name']){
|
|
|
+ array_push($where,['ad_place.name','like','%'.$data['name'].'%']);
|
|
|
+ }
|
|
|
+ if(isset($data['website_id']) && $data['website_id']){
|
|
|
+ array_push($where,['ad_place.website_id','=',$data['website_id']]);
|
|
|
+ }
|
|
|
+ $rep = AdPlace::where($where)
|
|
|
+ ->leftJoin("ad_size","ad_place.ad_size_id","ad_size.id")
|
|
|
+ ->leftJoin("website","website.id","ad_place.website_id")
|
|
|
+ ->limit($data['pageSize'])
|
|
|
+ ->orderBy("id","desc")
|
|
|
+ ->offset(($data['page']-1)*$data['pageSize'])
|
|
|
+ ->select("ad_place.*","ad_size.width","ad_size.height","website.website_name")
|
|
|
+ ->get();
|
|
|
+ $count = AdPlace::where($where)->count();
|
|
|
+ $reponse = [
|
|
|
+ 'rows'=>$rep->toArray(),
|
|
|
+ 'count'=>$count
|
|
|
+ ];
|
|
|
+ if(empty($rep->toArray())){
|
|
|
+ return Result::error("没有数据");
|
|
|
+ }
|
|
|
+ return Result::success($reponse);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function createAdPlace(array $data): array
|
|
|
+ {
|
|
|
+ unset($data['size']);
|
|
|
+ $result = AdPlace::query()->insertGetId($data);
|
|
|
+ if($result){
|
|
|
+ return Result::success();
|
|
|
+ }else{
|
|
|
+ return Result::error("创建广告位失败",500);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 'name' => 'required', //广告位名称
|
|
|
+ * 'website_id' => 'required',//关联的网站id
|
|
|
+ * 'price' => 'required',//价格
|
|
|
+ * 'thumb'=>'required', //广告示意图
|
|
|
+ * 'typeid'=>'required', //广告类型
|
|
|
+ * 'ad_size_id'=>'required', //广告位大小
|
|
|
+ * 'status'=>'required', //状态
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function updateAdPlace(array $data): array
|
|
|
+ {
|
|
|
+ $where = [
|
|
|
+ 'id'=>$data['id']
|
|
|
+ ];
|
|
|
+ $Insdata = [
|
|
|
+ 'website_id'=>$data['website_id']??'',
|
|
|
+ 'typeid'=>$data['typeid']??1,
|
|
|
+ 'status'=>$data['status']??2,
|
|
|
+ 'name'=>$data['name']??'',
|
|
|
+ 'thumb'=>$data['thumb']??'',
|
|
|
+ 'introduce'=>$data['introduce']??'',
|
|
|
+ 'code'=>$data['code']??'',
|
|
|
+ 'price'=>$data['price']??0,
|
|
|
+ 'ad_size_id'=>$data['ad_size_id']??0,
|
|
|
+ ];
|
|
|
+ $result = AdPlace::where($where)->update($Insdata);
|
|
|
+ if($result){
|
|
|
+ return Result::success($result);
|
|
|
+ }else{
|
|
|
+ return Result::error("更新失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除广告位
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function delAdPlace(array $data): array
|
|
|
+ {
|
|
|
+ $adList = Ad::where(['pid'=>$data['id']])->get();
|
|
|
+ if($adList->toArray()){
|
|
|
+ return Result::error("广告位里面还有广告,不能删除广告位");
|
|
|
+ }
|
|
|
+ $result = AdPlace::where($data)->delete();
|
|
|
+ if(!$result){
|
|
|
+ return Result::error("删除失败");
|
|
|
+ }
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * @param int $id
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function getAdPlaceInfo(int $id): array
|
|
|
+ {
|
|
|
+ $adInfo = AdPlace::query()->find($id);
|
|
|
+ if (empty($adInfo)) {
|
|
|
+ return Result::error("没有数据",0);
|
|
|
+ }
|
|
|
+ return Result::success($adInfo->toArray());
|
|
|
+ }
|
|
|
+
|
|
|
}
|