123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- namespace App\Service;
- use App\Models\AdPlacement;
- use App\Support\DouYinApi;
- class AdManageService
- {
- # 广告位列表
- public static function getAdList($appId, $type, $keyword, $status, $page, $pageSize) {
- # 获取广告位列表
- list($list, $count) = AdPlacement::searchData([
- 'app_id' => $appId, 'type' => $type, 'keyword' => $keyword, 'status' => $status
- ], $page, $pageSize);
- # 小程序名称信息
- $appConfig = config('douyin.app_info');
- # 广告位类型信息
- $typeArr = AdPlacement::AD_PLACEMENT_TYPE;
- # 数据格式化
- foreach($list as $value) {
- $typeName = $typeArr[$value->type] ?? '';
- $value->type_name = $typeName;
- $appName = $appConfig[$value->app_id]['app_name'] ?? '';
- $value->app_name = $appName;
- }
- return [$list, $count];
- }
- public static function adCreate($appId, $type, $adName) {
- $douRes = DouYinApi::adPlacementAdd($appId, $type, $adName);
- if(!$douRes) return 400;
- # 抖音平台不会直接返回广告位ID,因此需要主动同步
- $res = AdService::syncAdPlacement($appId);
- if(!$res) return 500;
- return 0;
- }
- public static function updateAdStatus($appId, $adPlacementId, $status) {
- $douRes = DouYinApi::adPlacementUpdate($appId, $adPlacementId, $status);
- if(!$douRes) return 400;
- # 更新本地数据
- $res = AdPlacement::updateData($appId, $adPlacementId, $status);
- if(!$res) return 500;
- return 0;
- }
- }
|