|
@@ -3,8 +3,6 @@
|
|
namespace General\Services\LandingPage;
|
|
namespace General\Services\LandingPage;
|
|
|
|
|
|
use App\Consts\BaseConst;
|
|
use App\Consts\BaseConst;
|
|
-use Exception;
|
|
|
|
-use General\Models\User\QappUser;
|
|
|
|
use General\Models\Order\Order;
|
|
use General\Models\Order\Order;
|
|
use General\Models\LandingPage\LandingPageDomain;
|
|
use General\Models\LandingPage\LandingPageDomain;
|
|
use General\Models\LandingPage\LandingPageLink;
|
|
use General\Models\LandingPage\LandingPageLink;
|
|
@@ -15,7 +13,6 @@ use General\Models\Report\ReportUserBindRecord;
|
|
use General\Models\Report\ReportUserChargeRecord;
|
|
use General\Models\Report\ReportUserChargeRecord;
|
|
use General\Services\Report\BaseReport;
|
|
use General\Services\Report\BaseReport;
|
|
use General\Services\Config\ConfigService;
|
|
use General\Services\Config\ConfigService;
|
|
-use GuzzleHttp\Client;
|
|
|
|
use Illuminate\Support\Collection;
|
|
use Illuminate\Support\Collection;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Redis;
|
|
use Redis;
|
|
@@ -85,7 +82,7 @@ class LandingPageLinkService
|
|
self::baidu,
|
|
self::baidu,
|
|
];
|
|
];
|
|
|
|
|
|
- public static function saveLink(array $data)
|
|
|
|
|
|
+ public function saveLink(array $data)
|
|
{
|
|
{
|
|
if (isset($data['id'])) {
|
|
if (isset($data['id'])) {
|
|
$data['updated_at'] = now();
|
|
$data['updated_at'] = now();
|
|
@@ -95,12 +92,12 @@ class LandingPageLinkService
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public static function deleteLink(int $id)
|
|
|
|
|
|
+ public function deleteLink(int $id)
|
|
{
|
|
{
|
|
LandingPageLink::where('id', $id)->delete();
|
|
LandingPageLink::where('id', $id)->delete();
|
|
}
|
|
}
|
|
|
|
|
|
- public static function updateLinkStatus(int $id, int $status, string $remark)
|
|
|
|
|
|
+ public function updateLinkStatus(int $id, int $status, string $remark)
|
|
{
|
|
{
|
|
if ($status) {
|
|
if ($status) {
|
|
self::saveLink(['id' => $id, 'status' => $status, 'remark' => $remark]);
|
|
self::saveLink(['id' => $id, 'status' => $status, 'remark' => $remark]);
|
|
@@ -108,7 +105,7 @@ class LandingPageLinkService
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public static function findLinks(array $query_params = [], bool $is_page = false)
|
|
|
|
|
|
+ public function findLinks(array $query_params = [], bool $is_page = false)
|
|
{
|
|
{
|
|
$sql = LandingPageLink::orderBy('id', 'desc');
|
|
$sql = LandingPageLink::orderBy('id', 'desc');
|
|
if (isset($query_params['name']) && $query_params['name']) {
|
|
if (isset($query_params['name']) && $query_params['name']) {
|
|
@@ -133,12 +130,12 @@ class LandingPageLinkService
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public static function findDomains()
|
|
|
|
|
|
+ public function findDomains()
|
|
{
|
|
{
|
|
return LandingPageDomain::where('is_enabled', 1)->get();
|
|
return LandingPageDomain::where('is_enabled', 1)->get();
|
|
}
|
|
}
|
|
|
|
|
|
- public static function findOfficialAccounts(int $distribution_channel_id)
|
|
|
|
|
|
+ public function findOfficialAccounts(int $distribution_channel_id)
|
|
{
|
|
{
|
|
return OfficialAccount::select('nickname', 'appid', 'alias', 'head_img')
|
|
return OfficialAccount::select('nickname', 'appid', 'alias', 'head_img')
|
|
->where('distribution_channel_id', $distribution_channel_id)
|
|
->where('distribution_channel_id', $distribution_channel_id)
|
|
@@ -150,7 +147,7 @@ class LandingPageLinkService
|
|
/**
|
|
/**
|
|
* 获取付费回传配置信息
|
|
* 获取付费回传配置信息
|
|
*/
|
|
*/
|
|
- public static function getChargeFeedBackConfig(int $channel_id, int $channel_user_id)
|
|
|
|
|
|
+ public function getChargeFeedBackConfig(int $channel_id, int $channel_user_id)
|
|
{
|
|
{
|
|
$switch_status = (new NormalChargeFeedBack)->getSwitchStatus($channel_id);
|
|
$switch_status = (new NormalChargeFeedBack)->getSwitchStatus($channel_id);
|
|
$orange_switch_status = (new OrangeChargeFeedBack)->getSwitchStatus($channel_id);
|
|
$orange_switch_status = (new OrangeChargeFeedBack)->getSwitchStatus($channel_id);
|
|
@@ -182,22 +179,22 @@ class LandingPageLinkService
|
|
return $result;
|
|
return $result;
|
|
}
|
|
}
|
|
|
|
|
|
- private static function getService(bool $is_orange)
|
|
|
|
|
|
+ private function getService(bool $is_orange)
|
|
{
|
|
{
|
|
return $is_orange ? new OrangeChargeFeedBack : new NormalChargeFeedBack;
|
|
return $is_orange ? new OrangeChargeFeedBack : new NormalChargeFeedBack;
|
|
}
|
|
}
|
|
|
|
|
|
- public static function setSwitchStatus(int $channel_id, int $status, bool $is_orange = false)
|
|
|
|
|
|
+ public function setSwitchStatus(int $channel_id, int $status, bool $is_orange = false)
|
|
{
|
|
{
|
|
- self::getService($is_orange)->setSwitchStatus($channel_id, $status);
|
|
|
|
|
|
+ $this->getService($is_orange)->setSwitchStatus($channel_id, $status);
|
|
}
|
|
}
|
|
|
|
|
|
- public static function syncSwitchStatus(array $channel_ids, int $status, bool $is_orange = false)
|
|
|
|
|
|
+ public function syncSwitchStatus(array $channel_ids, int $status, bool $is_orange = false)
|
|
{
|
|
{
|
|
- self::getService($is_orange)->syncSwitchStatus($channel_ids, $status);
|
|
|
|
|
|
+ $this->getService($is_orange)->syncSwitchStatus($channel_ids, $status);
|
|
}
|
|
}
|
|
|
|
|
|
- public static function findUserReportInfos(int $channel_id, array $params, bool $is_page = true)
|
|
|
|
|
|
+ public function findUserReportInfos(int $channel_id, array $params, bool $is_page = true)
|
|
{
|
|
{
|
|
$sql = Order::where('distribution_channel_id', $channel_id)
|
|
$sql = Order::where('distribution_channel_id', $channel_id)
|
|
->where('status', 'PAID')
|
|
->where('status', 'PAID')
|
|
@@ -226,7 +223,7 @@ class LandingPageLinkService
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public static function setReportType(int $channel_id, string $type, int $molecule, int $eligible_count)
|
|
|
|
|
|
+ public function setReportType(int $channel_id, string $type, int $molecule, int $eligible_count)
|
|
{
|
|
{
|
|
if (in_array($type, LandingPageLinkService::REPORT_TYPE)) {
|
|
if (in_array($type, LandingPageLinkService::REPORT_TYPE)) {
|
|
Redis::hset('channel:setting:' . $channel_id, 'tiktok_report_type', $type);
|
|
Redis::hset('channel:setting:' . $channel_id, 'tiktok_report_type', $type);
|
|
@@ -245,7 +242,7 @@ class LandingPageLinkService
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public static function addBaiduAdAccount(array $data, int $channel_user_id)
|
|
|
|
|
|
+ public function addBaiduAdAccount(array $data, int $channel_user_id)
|
|
{
|
|
{
|
|
$model = BaiDuAdAccount::create(
|
|
$model = BaiDuAdAccount::create(
|
|
[
|
|
[
|
|
@@ -255,20 +252,20 @@ class LandingPageLinkService
|
|
'is_enabled' => 1,
|
|
'is_enabled' => 1,
|
|
]
|
|
]
|
|
);
|
|
);
|
|
- self::baiDuAdAccountReport($model);
|
|
|
|
|
|
+ $this->baiDuAdAccountReport($model);
|
|
}
|
|
}
|
|
|
|
|
|
- public static function delBaiduAdAccount(int $id, int $channel_user_id)
|
|
|
|
|
|
+ public function delBaiduAdAccount(int $id, int $channel_user_id)
|
|
{
|
|
{
|
|
$model = BaiDuAdAccount::where('id', $id)->where('channel_user_id', $channel_user_id)->first();
|
|
$model = BaiDuAdAccount::where('id', $id)->where('channel_user_id', $channel_user_id)->first();
|
|
if ($model) {
|
|
if ($model) {
|
|
$model->is_enabled = 0;
|
|
$model->is_enabled = 0;
|
|
$model->save();
|
|
$model->save();
|
|
- self::baiDuAdAccountReport($model);
|
|
|
|
|
|
+ $this->baiDuAdAccountReport($model);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private static function baiDuAdAccountReport(BaiDuAdAccount $model)
|
|
|
|
|
|
+ private function baiDuAdAccountReport(BaiDuAdAccount $model)
|
|
{
|
|
{
|
|
$service = new Report;
|
|
$service = new Report;
|
|
$service->report('api/report/baidu/token', [
|
|
$service->report('api/report/baidu/token', [
|
|
@@ -279,12 +276,12 @@ class LandingPageLinkService
|
|
]);
|
|
]);
|
|
}
|
|
}
|
|
|
|
|
|
- public static function findBaiduAdAccounts(int $channel_user_id): Collection
|
|
|
|
|
|
+ public function findBaiduAdAccounts(int $channel_user_id): Collection
|
|
{
|
|
{
|
|
return BaiDuAdAccount::where('is_enabled', 1)->where('channel_user_id', $channel_user_id)->get();
|
|
return BaiDuAdAccount::where('is_enabled', 1)->where('channel_user_id', $channel_user_id)->get();
|
|
}
|
|
}
|
|
|
|
|
|
- public static function reportInstance(bool $is_qapp, string $link_source): BaseReport
|
|
|
|
|
|
+ public function reportInstance(string $link_source, bool $is_qapp): BaseReport
|
|
{
|
|
{
|
|
$name = $is_qapp ? 'Qapp' . ucfirst($link_source) . 'Report' : ucfirst($link_source) . 'Report';
|
|
$name = $is_qapp ? 'Qapp' . ucfirst($link_source) . 'Report' : ucfirst($link_source) . 'Report';
|
|
$namespace = "\\General\\Services\\Report\\{$name}";
|
|
$namespace = "\\General\\Services\\Report\\{$name}";
|
|
@@ -292,12 +289,11 @@ class LandingPageLinkService
|
|
return $instance;
|
|
return $instance;
|
|
}
|
|
}
|
|
|
|
|
|
- public static function reReport(int $bind_id, float $amount, string $order_no)
|
|
|
|
|
|
+ public function reReport(int $bind_id, float $amount, string $order_no, bool $is_qapp = false)
|
|
{
|
|
{
|
|
$report_user = ReportUserBindRecord::find($bind_id);
|
|
$report_user = ReportUserBindRecord::find($bind_id);
|
|
if ($report_user) {
|
|
if ($report_user) {
|
|
- $is_qapp = QappUser::where('uid', $report_user->uid)->exists();
|
|
|
|
- $instance = self::reportInstance($is_qapp, $report_user->platform);
|
|
|
|
|
|
+ $instance = $this->reportInstance($report_user->platform, $is_qapp);
|
|
$result = $instance->reportCharge($report_user, $amount);
|
|
$result = $instance->reportCharge($report_user, $amount);
|
|
ReportUserChargeRecord::updateOrCreate(
|
|
ReportUserChargeRecord::updateOrCreate(
|
|
[
|
|
[
|
|
@@ -312,97 +308,3 @@ class LandingPageLinkService
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
-/**
|
|
|
|
- * 橙子建站回传
|
|
|
|
- */
|
|
|
|
-class OrangeChargeFeedBack extends ChargeFeedBack
|
|
|
|
-{
|
|
|
|
- public function __construct()
|
|
|
|
- {
|
|
|
|
- $this->type = 'orange_site_report';
|
|
|
|
- parent::__construct();
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-/**
|
|
|
|
- * 一般回传
|
|
|
|
- */
|
|
|
|
-class NormalChargeFeedBack extends ChargeFeedBack
|
|
|
|
-{
|
|
|
|
- public function __construct()
|
|
|
|
- {
|
|
|
|
- $this->type = 'tiktok_report';
|
|
|
|
- parent::__construct();
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-/**
|
|
|
|
- * 付费回传
|
|
|
|
- */
|
|
|
|
-class ChargeFeedBack
|
|
|
|
-{
|
|
|
|
- protected $service;
|
|
|
|
- protected $type;
|
|
|
|
-
|
|
|
|
- public function __construct()
|
|
|
|
- {
|
|
|
|
- $this->service = new ConfigService;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 设置开关状态
|
|
|
|
- */
|
|
|
|
- public function setSwitchStatus(int $channel_id, int $status)
|
|
|
|
- {
|
|
|
|
- $this->service->saveConfig($channel_id, $this->type, $status);
|
|
|
|
- Redis::hSet('channel:setting:' . $channel_id, $this->type, $status);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 获取开关状态
|
|
|
|
- */
|
|
|
|
- public function getSwitchStatus(int $channel_id)
|
|
|
|
- {
|
|
|
|
- $status = Redis::hGet('channel:setting:' . $channel_id, $this->type);
|
|
|
|
- if (!$status) {
|
|
|
|
- $status = $this->service->hasAuth($channel_id, $this->type);
|
|
|
|
- if ($status) {
|
|
|
|
- $this->setSwitchStatus($channel_id, $status);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return $status;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 同步开关状态
|
|
|
|
- */
|
|
|
|
- public function syncSwitchStatus(array $channel_ids, int $status)
|
|
|
|
- {
|
|
|
|
- foreach ($channel_ids as $channel_id) {
|
|
|
|
- $this->setSwitchStatus($channel_id, $status);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-class Report
|
|
|
|
-{
|
|
|
|
- public function report(string $path, array $query_params)
|
|
|
|
- {
|
|
|
|
- $client = new Client(['timeout' => 3]);
|
|
|
|
- $query_params['sign'] = _sign($query_params, BaseConst::TIKTOK_KEY);
|
|
|
|
- try {
|
|
|
|
- $response = $client->post(env('TRACK_API_DOMAIN') . '/' . $path, ['form_params' => $query_params]);
|
|
|
|
- if ($response->getStatusCode() == 200) {
|
|
|
|
- $result = $response->getBody()->getContents();
|
|
|
|
- myLog('track_api')->info($result);
|
|
|
|
- return json_decode($result, true);
|
|
|
|
- } else {
|
|
|
|
- return [];
|
|
|
|
- }
|
|
|
|
- } catch (Exception $e) {
|
|
|
|
- myLog('track_api')->error($e->getMessage());
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-}
|
|
|