抖音小程序

AdManageService.php 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace App\Service;
  3. use App\Models\AdPlacement;
  4. use App\Support\DouYinApi;
  5. class AdManageService
  6. {
  7. # 广告位列表
  8. public static function getAdList($appId, $type, $keyword, $status, $page, $pageSize) {
  9. # 获取广告位列表
  10. list($list, $count) = AdPlacement::searchData([
  11. 'app_id' => $appId, 'type' => $type, 'keyword' => $keyword, 'status' => $status
  12. ], $page, $pageSize);
  13. # 小程序名称信息
  14. $appConfig = config('douyin.app_info');
  15. # 广告位类型信息
  16. $typeArr = AdPlacement::AD_PLACEMENT_TYPE;
  17. # 数据格式化
  18. foreach($list as $value) {
  19. $typeName = $typeArr[$value->type] ?? '';
  20. $value->type_name = $typeName;
  21. $appName = $appConfig[$value->app_id]['app_name'] ?? '';
  22. $value->app_name = $appName;
  23. }
  24. return [$list, $count];
  25. }
  26. public static function adCreate($appId, $type, $adName) {
  27. $douRes = DouYinApi::adPlacementAdd($appId, $type, $adName);
  28. if(!$douRes) return 400;
  29. # 抖音平台不会直接返回广告位ID,因此需要主动同步
  30. $res = AdService::syncAdPlacement($appId);
  31. if(!$res) return 500;
  32. return 0;
  33. }
  34. public static function updateAdStatus($appId, $adPlacementId, $status) {
  35. $douRes = DouYinApi::adPlacementUpdate($appId, $adPlacementId, $status);
  36. if(!$douRes) return 400;
  37. # 更新本地数据
  38. $res = AdPlacement::updateData($appId, $adPlacementId, $status);
  39. if(!$res) return 500;
  40. return 0;
  41. }
  42. }