|
@@ -1,6 +1,6 @@
|
|
|
<?php
|
|
|
|
|
|
-namespace Modules\Video\Http\Controllers;
|
|
|
+namespace Modules\Callback\Http\Controllers;
|
|
|
|
|
|
use Catch\Base\CatchController;
|
|
|
use Illuminate\Foundation\Validation\ValidatesRequests;
|
|
@@ -31,7 +31,7 @@ class JuliangAccountController extends CatchController
|
|
|
|
|
|
public function addAccount(Request $request) {
|
|
|
$this->validate($request, [
|
|
|
- 'account_id' => 'required|string|max:64',
|
|
|
+ 'account_id' => 'required',
|
|
|
'account_name' => 'required|string|max:64',
|
|
|
'callback_state' => 'required|integer|in:0,1',
|
|
|
'protect_num' => 'required|integer|min:0',
|
|
@@ -46,21 +46,36 @@ class JuliangAccountController extends CatchController
|
|
|
->exists()) {
|
|
|
CommonBusinessException::throwError(Errors::JULIANG_ACCOUNT_EXISTS);
|
|
|
}
|
|
|
+ if($request->input('callback_rate_time_config') &&
|
|
|
+ !$this->is_time_cross($request->input('callback_rate_time_config'))) {
|
|
|
+ CommonBusinessException::throwError(Errors::CALLBACK_RATE_TIME_RANGE_ERROR);
|
|
|
+ }
|
|
|
$now = date('Y-m-d H:i:s');
|
|
|
DB::table('juliang_account_callback_config')
|
|
|
->insert([
|
|
|
- 'adv_account_id' => $request->input('acccount_id'),
|
|
|
+ 'adv_account_id' => $request->input('account_id'),
|
|
|
'adv_account_name' => $request->input('account_name'),
|
|
|
'callback_state' => $request->input('callback_state'),
|
|
|
'protect_num' => $request->input('protect_num'),
|
|
|
'callback_default_rate' => $request->input('callback_default_rate'),
|
|
|
- 'callback_rate_time_config' => \json_encode($request->input('callback_rate_time_config', '[]')),
|
|
|
+ 'callback_rate_time_config' => \json_encode($request->input('callback_rate_time_config', [])),
|
|
|
'callback_min_money' => $request->input('callback_min_money'),
|
|
|
'callback_max_money' => $request->input('callback_max_money'),
|
|
|
'company_uid' => $this->getCompanyUid(),
|
|
|
'created_at' => $now,
|
|
|
'updated_at' => $now,
|
|
|
]);
|
|
|
+ DB::table('juliang_account_rate_config_log')
|
|
|
+ ->insert([
|
|
|
+ 'company_uid' => $this->getCompanyUid(),
|
|
|
+ 'account_id' => $request->input('account_id'),
|
|
|
+ 'config_per' => $request->input('callback_default_rate'),
|
|
|
+ 'created_at' => $now,
|
|
|
+ 'updated_at' => $now,
|
|
|
+ ]);
|
|
|
+ if($request->input('callback_rate_time_config')) {
|
|
|
+ $this->saveTimeConfig($this->getCompanyUid(), $request->input('account_id'), $request);
|
|
|
+ }
|
|
|
return 'ok';
|
|
|
}
|
|
|
|
|
@@ -74,6 +89,10 @@ class JuliangAccountController extends CatchController
|
|
|
'callback_min_money' => 'required|min:0',
|
|
|
'callback_max_money' => 'required|min:0'
|
|
|
]);
|
|
|
+ if($request->input('callback_rate_time_config') &&
|
|
|
+ !$this->is_time_cross($request->input('callback_rate_time_config'))) {
|
|
|
+ CommonBusinessException::throwError(Errors::CALLBACK_RATE_TIME_RANGE_ERROR);
|
|
|
+ }
|
|
|
$now = date('Y-m-d H:i:s');
|
|
|
foreach ($request->input('ids') as $id) {
|
|
|
DB::table('juliang_account_callback_config')
|
|
@@ -82,7 +101,7 @@ class JuliangAccountController extends CatchController
|
|
|
'callback_state' => $request->input('callback_state'),
|
|
|
'protect_num' => $request->input('protect_num'),
|
|
|
'callback_default_rate' => $request->input('callback_default_rate'),
|
|
|
- 'callback_rate_time_config' => \json_encode($request->input('callback_rate_time_config', '[]')),
|
|
|
+ 'callback_rate_time_config' => \json_encode($request->input('callback_rate_time_config', [])),
|
|
|
'callback_min_money' => $request->input('callback_min_money'),
|
|
|
'callback_max_money' => $request->input('callback_max_money'),
|
|
|
'updated_at' => $now,
|
|
@@ -93,11 +112,104 @@ class JuliangAccountController extends CatchController
|
|
|
->where('company_uid', $this->getCompanyUid())
|
|
|
->select('adv_account_id')->get()->pluck('adv_account_id');
|
|
|
if($advAccountIds->isNotEmpty()) {
|
|
|
- DB::table('juliang_account_recharge_report_records')
|
|
|
+ DB::table('juliang_account_rate_config_log')
|
|
|
+ ->where('company_uid', $this->getCompanyUid())
|
|
|
->whereIn('account_id', $advAccountIds)
|
|
|
- ->update(['is_eanbled' => 0, 'updated_at' => $now]);
|
|
|
+ ->where('is_enabled', 1)
|
|
|
+ ->update(['is_enabled' => 0, 'updated_at' => $now]);
|
|
|
+ foreach ($advAccountIds as $accountId) {
|
|
|
+ DB::table('juliang_account_rate_config_log')
|
|
|
+ ->insert([
|
|
|
+ 'company_uid' => $this->getCompanyUid(),
|
|
|
+ 'account_id' => $accountId,
|
|
|
+ 'config_per' => $request->input('callback_default_rate'),
|
|
|
+ 'created_at' => $now,
|
|
|
+ 'updated_at' => $now,
|
|
|
+ ]);
|
|
|
+ $this->saveTimeConfig($this->getCompanyUid(), $accountId, $request);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return 'ok';
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断时 设置的时间范围是否有交集
|
|
|
+ *
|
|
|
+ * @param string $config_time 开始时间1
|
|
|
+ * @return bool
|
|
|
+ */
|
|
|
+ protected function is_time_cross($config_time) {
|
|
|
+ $timeline = [];
|
|
|
+ foreach ($config_time as $key => $value) {
|
|
|
+ $start_time = $value['start_time'];
|
|
|
+ $start = explode(':', $start_time);
|
|
|
+ $cur_start = (int)$start[0] * 60 + $start[1];
|
|
|
+ $end_time = $value['end_time'];
|
|
|
+
|
|
|
+ $end = explode(':', $end_time);
|
|
|
+ $cur_end = (int)$end[0] * 60 + $end[1];
|
|
|
+ if ($cur_end <= $cur_start) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($timeline) {
|
|
|
+ foreach ($timeline as $k => $v) {
|
|
|
+ if ($cur_start >= $v['start'] && $cur_start <= $v['end']) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if ($cur_end >= $v['start'] && $cur_end <= $v['end']) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $timeline[] = ['start'=>$cur_start,'end'=>$cur_end];
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public function saveTimeConfig($companyUid, $accountId, $configInfo )
|
|
|
+ {
|
|
|
+ DB::table('juliang_account_promotion_config_time')
|
|
|
+ ->where('is_enable',1)
|
|
|
+ ->where('company_uid',$companyUid)
|
|
|
+ ->where('account_id',$accountId)->update(['is_enable'=>0]);
|
|
|
+ $time_config = $configInfo['callback_rate_time_config'];
|
|
|
+ if (empty($time_config)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ $is = $this->is_time_cross($time_config);
|
|
|
+ if (!$is) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ $data = [];
|
|
|
+ $temp['company_uid'] = $companyUid;
|
|
|
+
|
|
|
+ $temp['account_id'] = $accountId;
|
|
|
+ $temp['other_data']['callback_default_rate'] = $configInfo['callback_default_rate'];
|
|
|
+ $temp['other_data']['callback_min_money'] = $configInfo['callback_min_money'];
|
|
|
+ $temp['other_data']['callback_max_money'] = $configInfo['callback_max_money'];
|
|
|
+ $temp['other_data']['protect_num'] = $configInfo['protect_num'];
|
|
|
+ $temp['other_data']['callback_state'] = $configInfo['callback_state'];
|
|
|
+ $temp['other_data'] = json_encode($temp['other_data']);
|
|
|
+ $temp['next_exec_time'] = date('Y-m-d');
|
|
|
+
|
|
|
+ $temp['is_enable'] = 1;
|
|
|
+ $temp['created_at'] = date('Y-m-d H:i:s',time());
|
|
|
+
|
|
|
+ foreach ($time_config as $value) {
|
|
|
+ $start_time = $value['start_time'];
|
|
|
+ $end_time = $value['end_time'];
|
|
|
+ $temp['config_time'] = $start_time;
|
|
|
+ $temp['config_per'] = $value['config_per'];
|
|
|
+ $data[] = $temp;
|
|
|
+ //结束后 百分比改为默认的
|
|
|
+ $temp['config_time'] = $end_time;
|
|
|
+ $temp['config_per'] = $configInfo['callback_default_rate'];
|
|
|
+ $data[] = $temp;
|
|
|
+ }
|
|
|
+ //插入设置最新的时间段百分比
|
|
|
+ DB::table('juliang_account_promotion_config_time')->insert($data);
|
|
|
+ }
|
|
|
}
|