|
@@ -18,15 +18,48 @@ class JuliangAccountController extends CatchController
|
|
|
public function list(Request $request) {
|
|
|
$advAccountId = $request->input('account_id');
|
|
|
$advAccountName = $request->input('account_name');
|
|
|
+ $unBind = $request->input('unbind', 0);
|
|
|
+ $alreadyBindConfigIds = null;
|
|
|
+ if($unBind) {
|
|
|
+ $alreadyBindConfigIds = DB::table('promotions')
|
|
|
+ ->where([
|
|
|
+ 'uid' => $this->getOptimizerUid(),
|
|
|
+ 'callback_type' => 1,
|
|
|
+ 'status' => 1,
|
|
|
+ 'is_enabled' => 1,
|
|
|
+ ])->where('callback_config_id' , '<>', 0)
|
|
|
+ ->distinct()
|
|
|
+ ->select('callback_config_id')
|
|
|
+ ->get()->pluck('callback_config_id')->toArray();
|
|
|
+ }
|
|
|
|
|
|
- return DB::table('juliang_account_callback_config')
|
|
|
+ $list = DB::table('juliang_account_callback_config')
|
|
|
->where(['company_uid' => $this->getOptimizerUid()])
|
|
|
->when($advAccountId, function ($query, $advAccountId) {
|
|
|
return $query->where('adv_account_id' , $advAccountId);
|
|
|
})->when($advAccountName, function ($query, $advAccountName) {
|
|
|
return $query->where('adv_account_name', 'like', '%'. $advAccountName. '%');
|
|
|
- })->orderBy('id', 'desc')
|
|
|
+ })->when($alreadyBindConfigIds, function ($query, $alreadyBindConfigIds) {
|
|
|
+ return $query->whereNotIn('id', $alreadyBindConfigIds);
|
|
|
+ })
|
|
|
+ ->orderBy('id', 'desc')
|
|
|
->paginate($request->input('limit', 30));
|
|
|
+ $ids = collect($list->items())->pluck('id');
|
|
|
+ $promotions = DB::table('promotions')
|
|
|
+ ->where([
|
|
|
+ 'uid' => $this->getOptimizerUid(),
|
|
|
+ 'callback_type' => 1,
|
|
|
+ 'status' => 1,
|
|
|
+ 'is_enabled' => 1,
|
|
|
+ ])->whereIn('callback_config_id', $ids)
|
|
|
+ ->select('name', 'id', 'callback_config_id')
|
|
|
+ ->get()->keyBy('callback_config_id');
|
|
|
+ foreach ($list as $item) {
|
|
|
+ $item->promotion_name = $promotions->get($item->id)->name ?? '';
|
|
|
+ $item->promotion_id = $promotions->get($item->id)->id ?? '';
|
|
|
+ }
|
|
|
+
|
|
|
+ return $list;
|
|
|
}
|
|
|
|
|
|
public function addAccount(Request $request) {
|
|
@@ -270,4 +303,65 @@ class JuliangAccountController extends CatchController
|
|
|
|
|
|
return 'ok';
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 解绑推广
|
|
|
+ * @param Request $request
|
|
|
+ */
|
|
|
+ public function unbindPromotion(Request $request) {
|
|
|
+ $this->validate($request, [
|
|
|
+ 'id' => 'required'
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $config = DB::table('juliang_account_callback_config')
|
|
|
+ ->where([
|
|
|
+ 'id' => $request->input('id'),
|
|
|
+ 'company_uid' => $this->getOptimizerUid(),
|
|
|
+ ])->first();
|
|
|
+
|
|
|
+ if(!$config) {
|
|
|
+ CommonBusinessException::throwError(Errors::JULIANG_ACCOUNT_CONFIG_NOT_EXISTS);
|
|
|
+ }
|
|
|
+ $now = date('Y-m-d H:i:s');
|
|
|
+ $affected = DB::table('promotions')
|
|
|
+ ->where([
|
|
|
+ 'callback_type' => 1,
|
|
|
+ 'callback_config_id' => $request->input('id'),
|
|
|
+ 'is_enabled' => 1,
|
|
|
+ 'status' => 1,
|
|
|
+ ])->update([
|
|
|
+ 'status' => 0,
|
|
|
+ 'updated_at' => $now,
|
|
|
+ ]);
|
|
|
+ if($affected) {
|
|
|
+ DB::table('juliang_account_rate_config_log')
|
|
|
+ ->where('company_uid', $this->getOptimizerUid())
|
|
|
+ ->where('account_id', $config->adv_account_id)
|
|
|
+ ->where('is_enabled', 1)
|
|
|
+ ->update(['is_enabled' => 0, 'updated_at' => $now]);
|
|
|
+ DB::table('juliang_account_promotion_protect_record')
|
|
|
+ ->where('optimizer_uid', $this->getOptimizerUid())
|
|
|
+ ->where('advertiser_id', $config->adv_account_id)
|
|
|
+ ->where('is_enabled', 1)
|
|
|
+ ->update(['is_enabled' => 0, 'updated_at' => $now]);
|
|
|
+ DB::table('juliang_account_rate_config_log')
|
|
|
+ ->insert([
|
|
|
+ 'company_uid' => $this->getOptimizerUid(),
|
|
|
+ 'account_id' => $config->adv_account_id,
|
|
|
+ 'config_per' => $config->default_rate,
|
|
|
+ 'created_at' => $now,
|
|
|
+ 'updated_at' => $now,
|
|
|
+ ]);
|
|
|
+ // 让所有的时间区间比例配置,在定时任务中,重新执行一遍
|
|
|
+ DB::table('juliang_account_promotion_config_time')
|
|
|
+ ->where('is_enable',1)
|
|
|
+ ->where('company_uid',$this->getOptimizerUid())
|
|
|
+ ->where('account_id',$config->adv_account_id)
|
|
|
+ ->update(['next_exec_time' => date('Y-m-d'), 'updated_at' => $now]);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return 'ok';
|
|
|
+ }
|
|
|
+
|
|
|
}
|