作者 赵彬吉

update

@@ -272,13 +272,23 @@ class RelayInquiry extends Command @@ -272,13 +272,23 @@ class RelayInquiry extends Command
272 { 272 {
273 $this->output('获取转发对象'); 273 $this->output('获取转发对象');
274 274
  275 + //是否有必选的
  276 + $require_data = [];
  277 + foreach ($task['target'] as $item){
  278 + if(!empty($item['is_require'])){
  279 + $require_data[] = $item;
  280 + }
  281 + }
275 //代理商组 一个组只发一个 282 //代理商组 一个组只发一个
276 - $agent_group = collect($task['target'])->groupBy('agent_group'); 283 + $agent_group = collect($task['target'])->whereNotIn('agent_group', array_column($require_data, 'agent_group'))->groupBy('agent_group');
277 // 获取转发对象 重置num数量, array_rand数量不足会报错 284 // 获取转发对象 重置num数量, array_rand数量不足会报错
  285 + $task['num'] = $task['num'] - count($require_data);
278 $num = $task['num'] > count($agent_group) ? count($agent_group) : $task['num']; 286 $num = $task['num'] > count($agent_group) ? count($agent_group) : $task['num'];
279 $random_data = $agent_group->keys()->random($num)->map(function ($group) use ($agent_group) { 287 $random_data = $agent_group->keys()->random($num)->map(function ($group) use ($agent_group) {
280 return $agent_group[$group]->random(); 288 return $agent_group[$group]->random();
281 })->all(); 289 })->all();
  290 + $random_data = array_merge($require_data, $random_data);
  291 +
282 if (empty($random_data)) { 292 if (empty($random_data)) {
283 $this->logChannel()->info('当前任务未发现转发对象!', ['广告任务ID:' . $task['id'], '询盘ID:' . $form->id]); 293 $this->logChannel()->info('当前任务未发现转发对象!', ['广告任务ID:' . $task['id'], '询盘ID:' . $form->id]);
284 $form->status = ReInquiryForm::STATUS_FORGO; 294 $form->status = ReInquiryForm::STATUS_FORGO;
@@ -109,6 +109,7 @@ class AdsController extends BaseController @@ -109,6 +109,7 @@ class AdsController extends BaseController
109 if(empty($target)){ 109 if(empty($target)){
110 return $this->response('请添加关联网站!', Code::USER_ERROR, []); 110 return $this->response('请添加关联网站!', Code::USER_ERROR, []);
111 } 111 }
  112 + $is_require_num = 0;
112 foreach ($target as &$item){ 113 foreach ($target as &$item){
113 if(empty($item['url'])){ 114 if(empty($item['url'])){
114 return $this->response('网站域名不能为空!', Code::USER_ERROR, []); 115 return $this->response('网站域名不能为空!', Code::USER_ERROR, []);
@@ -120,7 +121,14 @@ class AdsController extends BaseController @@ -120,7 +121,14 @@ class AdsController extends BaseController
120 return $this->response('代理商分组不能为空!', Code::USER_ERROR, []); 121 return $this->response('代理商分组不能为空!', Code::USER_ERROR, []);
121 } 122 }
122 $item['url'] = trim(str_replace(['http://', 'https://'], '', $item['url']), '/'); 123 $item['url'] = trim(str_replace(['http://', 'https://'], '', $item['url']), '/');
  124 + if(!empty($item['is_require'])){
  125 + $is_require_num++;
  126 + }
  127 + }
  128 + if($is_require_num > $task->num){
  129 + return $this->response('必选渠道不能大于转发数量!', Code::USER_ERROR, []);
123 } 130 }
  131 +
124 foreach ($target as $v){ 132 foreach ($target as $v){
125 ReInquiryCount::addInquiryNum($id, $v['url'], 0); 133 ReInquiryCount::addInquiryNum($id, $v['url'], 0);
126 } 134 }
@@ -66,6 +66,14 @@ class ReInquiryCount extends Model @@ -66,6 +66,14 @@ class ReInquiryCount extends Model
66 } 66 }
67 67
68 public function getTasksAttribute(){ 68 public function getTasksAttribute(){
69 - return ReInquiryTask::whereIn('id', $this->task_ids)->select(['title', 'industry'])->get(); 69 + $tasks = ReInquiryTask::whereIn('id', $this->task_ids)->select(['title', 'industry','target'])->get()->toArray();
  70 + foreach ($tasks as &$task){
  71 + $target = collect($task['target'])->where('url', $this->domain)->first();
  72 + $task['agent'] = $target['agent'] ?? '';
  73 + $task['is_v6'] = $target['is_v6'] ?? '';
  74 + $task['agent_group'] = $target['agent_group'] ?? '';
  75 + unset($task['target']);
  76 + }
  77 + return $tasks;
70 } 78 }
71 } 79 }
@@ -63,6 +63,13 @@ class ReInquiryTask extends Base @@ -63,6 +63,13 @@ class ReInquiryTask extends Base
63 */ 63 */
64 public function getTargetAttribute($value) 64 public function getTargetAttribute($value)
65 { 65 {
66 - return $value ? json_decode($value, true) : []; 66 + $value = $value ? json_decode($value, true) : [];
  67 + foreach ($value as &$item){
  68 + $item['url'] = $item['url'] ?? '';
  69 + $item['agent'] = $item['agent'] ?? '';
  70 + $item['agent_group'] = $item['agent_group'] ?? '';
  71 + $item['is_require'] = $item['is_require'] ?? 0;
  72 + }
  73 + return $value;
67 } 74 }
68 } 75 }