修复update状态
This commit is contained in:
parent
f45101b68d
commit
bf7b16c1e0
@ -230,15 +230,17 @@ $customerIds = [8452924576,6977154211,1401879025];
|
|||||||
3, // PAUSED
|
3, // PAUSED
|
||||||
4, // REMOVED
|
4, // REMOVED
|
||||||
];
|
];
|
||||||
$requestData = $request->all(); // 获取请求数据
|
$requestData = $request->all(); // 获取请求数据
|
||||||
$customerId = $requestData['customer_id'];
|
$requestData['refresh_token'] = $request->refresh_token;
|
||||||
$campaignId = $requestData['campaign_id'];
|
$requestData['login_customer_id'] = $request->login_customer_id;
|
||||||
$status = $requestData['status'];
|
// dump($requestData);
|
||||||
|
|
||||||
|
$status = $requestData['status'];
|
||||||
if (!in_array($status, $campaignStatus)) {
|
if (!in_array($status, $campaignStatus)) {
|
||||||
return $this->errorResponse(101, 'status参数错误');
|
return $this->errorResponse(101, 'status参数错误');
|
||||||
}
|
}
|
||||||
// try {
|
// try {
|
||||||
$reslut = $this->googleAdsCampaignService->updateCampaignStatus($customerId, $campaignId, $status);
|
$reslut = $this->googleAdsCampaignService->updateCampaignStatus($requestData);
|
||||||
if (!$reslut) {
|
if (!$reslut) {
|
||||||
return $this->errorResponse(101, 'Status update failed');
|
return $this->errorResponse(101, 'Status update failed');
|
||||||
}
|
}
|
||||||
@ -302,15 +304,17 @@ $customerIds = [8452924576,6977154211,1401879025];
|
|||||||
];
|
];
|
||||||
|
|
||||||
$requestData = $request->all(); // 获取请求数据
|
$requestData = $request->all(); // 获取请求数据
|
||||||
$customerId = $requestData['customer_id'];
|
$requestData['refresh_token'] = $request->refresh_token;
|
||||||
$groupId = $requestData['group_id'];
|
$requestData['login_customer_id'] = $request->login_customer_id;
|
||||||
|
// dump($requestData);
|
||||||
|
|
||||||
$status = $requestData['status'];
|
$status = $requestData['status'];
|
||||||
// $options['bid_micro_amount'] = $options['amount'] * 1000000 < 0 ? 0 : $options['amount'] * 1000000;
|
// $options['bid_micro_amount'] = $options['amount'] * 1000000 < 0 ? 0 : $options['amount'] * 1000000;
|
||||||
if (!in_array($status, $adGroupStatus)) {
|
if (!in_array($status, $adGroupStatus)) {
|
||||||
return $this->errorResponse(101, 'status参数错误');
|
return $this->errorResponse(101, 'status参数错误');
|
||||||
}
|
}
|
||||||
// try {
|
// try {
|
||||||
$result = $this->googleAdsGroupService->updateGroupStatus($customerId, $groupId, $status);
|
$result = $this->googleAdsGroupService->updateGroupStatus($requestData);
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
return $this->errorResponse(101, 'Status update failed');
|
return $this->errorResponse(101, 'Status update failed');
|
||||||
}
|
}
|
||||||
@ -334,15 +338,16 @@ $customerIds = [8452924576,6977154211,1401879025];
|
|||||||
];
|
];
|
||||||
|
|
||||||
$requestData = $request->all(); // 获取请求数据
|
$requestData = $request->all(); // 获取请求数据
|
||||||
$customerId = $requestData['customer_id'];
|
$requestData['refresh_token'] = $request->refresh_token;
|
||||||
$groupId = $requestData['group_id'];
|
$requestData['login_customer_id'] = $request->login_customer_id;
|
||||||
$adId = $requestData['ad_id'];
|
// dump($requestData);
|
||||||
|
|
||||||
$status = $requestData['status'];
|
$status = $requestData['status'];
|
||||||
if (!in_array($status, $adStatus)) {
|
if (!in_array($status, $adStatus)) {
|
||||||
return $this->errorResponse(101, 'status参数错误');
|
return $this->errorResponse(101, 'status参数错误');
|
||||||
}
|
}
|
||||||
// try {
|
// try {
|
||||||
$result = $this->googleAdsAdService->updateAdStatus($customerId, $groupId, $adId, $status);
|
$result = $this->googleAdsAdService->updateAdStatus($requestData);
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
return $this->errorResponse(101, 'Status update failed');
|
return $this->errorResponse(101, 'Status update failed');
|
||||||
}
|
}
|
||||||
|
@ -18,11 +18,12 @@ class OauthCheck implements MiddlewareInterface
|
|||||||
// $customerId = isset($requestData['ad_customer_id']) ? $requestData['ad_customer_id'] : getenv('GOOGLE_ADS_CUSTOMER_ID');
|
// $customerId = isset($requestData['ad_customer_id']) ? $requestData['ad_customer_id'] : getenv('GOOGLE_ADS_CUSTOMER_ID');
|
||||||
$uid = $request->jwtClaims['uid'];
|
$uid = $request->jwtClaims['uid'];
|
||||||
// 查询指定 user_id 的 ThirdUser
|
// 查询指定 user_id 的 ThirdUser
|
||||||
$thirdUser = ThirdUser::where('user_id', $uid)->find();
|
$thirdUser = ThirdUser::where('user_id', $uid)->where('third_type', 'google')->find();
|
||||||
|
// dump($uid, $thirdUser);
|
||||||
|
|
||||||
if ($thirdUser) {
|
if ($thirdUser) {
|
||||||
// 获取 access_token
|
// 获取 access_token
|
||||||
$request->access_token = $thirdUser->access_token;
|
$request->refresh_token = $thirdUser->access_token;
|
||||||
|
|
||||||
// 获取关联的广告主数据
|
// 获取关联的广告主数据
|
||||||
$advertiser = $thirdUser->advertisers()->find(); // 获取第一个广告主记录
|
$advertiser = $thirdUser->advertisers()->find(); // 获取第一个广告主记录
|
||||||
@ -30,6 +31,7 @@ class OauthCheck implements MiddlewareInterface
|
|||||||
if ($advertiser) {
|
if ($advertiser) {
|
||||||
// 获取 google_login_customer_id
|
// 获取 google_login_customer_id
|
||||||
$request->login_customer_id = $advertiser->google_login_customer_id;
|
$request->login_customer_id = $advertiser->google_login_customer_id;
|
||||||
|
// dump( $request->access_token,$request->login_customer_id);
|
||||||
} else {
|
} else {
|
||||||
return Json([
|
return Json([
|
||||||
'code' => 0,
|
'code' => 0,
|
||||||
|
@ -244,11 +244,12 @@ class GoogleAdsAdService extends BaseService
|
|||||||
public
|
public
|
||||||
function runUpdateAd($options): mixed
|
function runUpdateAd($options): mixed
|
||||||
{
|
{
|
||||||
|
// dump($options);
|
||||||
// $googleAdsClient = $this->googleAdsClient;
|
// $googleAdsClient = $this->googleAdsClient;
|
||||||
$googleAdsClient = new GoogleAdsClientService($options['refresh_token'],$options['login_customer_id']);
|
$googleAdsClient = new GoogleAdsClientService($options['refresh_token'],$options['login_customer_id']);
|
||||||
// Creates a single shared budget to be used by the campaigns added below.
|
// Creates a single shared budget to be used by the campaigns added below.
|
||||||
|
|
||||||
$resourceNames = self::updateAd($googleAdsClient->getGoogleAdsClient(), $options['customer_id'], $options['group_id'], $options['ad_id'], $options['status']);
|
$resourceNames = self::updateAd($googleAdsClient->getGoogleAdsClientWithloginCustomerId(), $options['customer_id'], $options['group_id'], $options['ad_id'], $options['status']);
|
||||||
|
|
||||||
return $resourceNames;
|
return $resourceNames;
|
||||||
}
|
}
|
||||||
@ -309,21 +310,21 @@ class GoogleAdsAdService extends BaseService
|
|||||||
* 更新广告状态
|
* 更新广告状态
|
||||||
*/
|
*/
|
||||||
public
|
public
|
||||||
function updateAdStatus(int $customerId, int $adGroupId, int $adId, int $status)
|
function updateAdStatus($options)
|
||||||
{
|
{
|
||||||
// 从数据库获取 Ad
|
// 从数据库获取 Ad
|
||||||
$ad = AdModel::find($adId);
|
$ad = AdModel::find($options['ad_id']);
|
||||||
if (!$ad) {
|
if (!$ad) {
|
||||||
// throw new ValidateException('Ad not found');
|
// throw new ValidateException('Ad not found');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// 更新数据库中的状态
|
// 更新数据库中的状态
|
||||||
// $ad->updateStatus($status);
|
// $ad->updateStatus($status);
|
||||||
if ($this->modifyDbAdStatus($adId, $status)) {
|
if ($this->modifyDbAdStatus($options['ad_id'], $options['status'])) {
|
||||||
// 更新 Google Ads 上的状态
|
// 更新 Google Ads 上的状态
|
||||||
// $googleAdsClient = $this->googleAdsClient;
|
// $googleAdsClient = $this->googleAdsClient;
|
||||||
$googleAdsClient = new GoogleAdsClientService($customerId);
|
$googleAdsClient = new GoogleAdsClientService($options['refresh_token'], $options['login_customer_id']);
|
||||||
$resourceName = self::updateAd($googleAdsClient->getGoogleAdsClient(), $customerId, $adGroupId, $adId, $status);
|
$resourceName = self::updateAd($googleAdsClient->getGoogleAdsClientWithloginCustomerId(), $options['customer_id'], $options['group_id'], $options['ad_id'], $options['status']);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -697,21 +697,21 @@ class GoogleAdsCampaignService extends BaseService
|
|||||||
/**
|
/**
|
||||||
* 更新广告系列状态
|
* 更新广告系列状态
|
||||||
*/
|
*/
|
||||||
public function updateCampaignStatus(int $customerId, int $campaignId, int $status)
|
public function updateCampaignStatus($options)
|
||||||
{
|
{
|
||||||
// 从数据库获取 Campaign 对象
|
// 从数据库获取 Campaign 对象
|
||||||
$campaign = CampaignModel::find($campaignId);
|
$campaign = CampaignModel::find($options['campaign_id']);
|
||||||
// dump($campaign);return;
|
// dump($campaign);return;
|
||||||
if (!$campaign) {
|
if (!$campaign) {
|
||||||
// throw new ValidateException('Campaign not found');
|
// throw new ValidateException('Campaign not found');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// 更新本地数据库的状态
|
// 更新本地数据库的状态
|
||||||
if ($this->modifyDbCampaignStatus($campaignId, $status)) {
|
if ($this->modifyDbCampaignStatus($options['campaign_id'], $options['status'])) {
|
||||||
// 更新 Google Ads 上的状态
|
// 更新 Google Ads 上的状态
|
||||||
// $googleAdsClient = $this->googleAdsClient;
|
// $googleAdsClient = $this->googleAdsClient;
|
||||||
$googleAdsClient = new GoogleAdsClientService($customerId);
|
$googleAdsClient = new GoogleAdsClientService($options['refresh_token'], $options['login_customer_id']);
|
||||||
$resourceName = self::updateCampaign($googleAdsClient->getGoogleAdsClient(), $customerId, $campaignId, $status);
|
$resourceName = self::updateCampaign($googleAdsClient->getGoogleAdsClientWithloginCustomerId(), $options['customer_id'], $options['campaign_id'], $options['status']);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -316,10 +316,10 @@ class GoogleAdsGroupService extends BaseService
|
|||||||
/**
|
/**
|
||||||
* 更新广告组状态
|
* 更新广告组状态
|
||||||
*/
|
*/
|
||||||
public function updateGroupStatus(int $customerId, int $adGroupId, int $status)
|
public function updateGroupStatus($options)
|
||||||
{
|
{
|
||||||
// 从数据库获取 AdGroup
|
// 从数据库获取 AdGroup
|
||||||
$adGroup = AdGroupModel::find($adGroupId);
|
$adGroup = AdGroupModel::find($options['group_id']);
|
||||||
if (!$adGroup) {
|
if (!$adGroup) {
|
||||||
return false;
|
return false;
|
||||||
// throw new ValidateException('AdGroup not found');
|
// throw new ValidateException('AdGroup not found');
|
||||||
@ -327,12 +327,12 @@ class GoogleAdsGroupService extends BaseService
|
|||||||
|
|
||||||
// 更新数据库中的状态
|
// 更新数据库中的状态
|
||||||
// $adGroup->updateStatus($status);
|
// $adGroup->updateStatus($status);
|
||||||
if ($this->modifyDbGroupStatus($adGroupId, $status)) {
|
if ($this->modifyDbGroupStatus($options['group_id'], $options['status'])) {
|
||||||
// 更新 Google Ads 上的状态
|
// 更新 Google Ads 上的状态
|
||||||
// $googleAdsClient = $this->googleAdsClient;
|
// $googleAdsClient = $this->googleAdsClient;
|
||||||
$googleAdsClient = new GoogleAdsClientService($customerId);
|
$googleAdsClient = new GoogleAdsClientService($options['refresh_token'], $options['login_customer_id']);
|
||||||
|
|
||||||
$resourceName = self::updateGroup($googleAdsClient->getGoogleAdsClient(), $customerId, $adGroupId, $status);
|
$resourceName = self::updateGroup($googleAdsClient->getGoogleAdsClientWithloginCustomerId(), $options['customer_id'], $options['group_id'], $options['status']);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user