作者 lyh

Merge branch 'master' of http://47.244.231.31:8099/zhl/globalso-v6 into master-server

1 <?php 1 <?php
2 namespace App\Console\Commands\Inquiry; 2 namespace App\Console\Commands\Inquiry;
3 3
  4 +use App\Models\Inquiry\ReInquiryCount;
4 use App\Models\Inquiry\ReInquiryDetail; 5 use App\Models\Inquiry\ReInquiryDetail;
5 use App\Models\Inquiry\ReInquiryDetailLog; 6 use App\Models\Inquiry\ReInquiryDetailLog;
6 use App\Models\Inquiry\ReInquiryForm; 7 use App\Models\Inquiry\ReInquiryForm;
@@ -186,6 +187,10 @@ class postInquiry extends Command @@ -186,6 +187,10 @@ class postInquiry extends Command
186 } 187 }
187 $log->status = ReInquiryDetailLog::STATUS_SUCCESS; 188 $log->status = ReInquiryDetailLog::STATUS_SUCCESS;
188 $log->save(); 189 $log->save();
  190 +
  191 + //统计
  192 + ReInquiryCount::addInquiryNum($detail['id'], $detail['re_website']);
  193 +
189 return true; 194 return true;
190 } 195 }
191 196
@@ -266,5 +266,25 @@ class QuanqiusouApi @@ -266,5 +266,25 @@ class QuanqiusouApi
266 return $res; 266 return $res;
267 } 267 }
268 268
  269 + /**
  270 + * 获取代理信息
  271 + * @param $domain
  272 + * @return array|mixed
  273 + * @author zbj
  274 + * @date 2024/10/26
  275 + */
  276 + public function getV5Agent($domain){
  277 + $token = md5($domain.'qqs');
  278 + try {
  279 + $client = new \GuzzleHttp\Client();
  280 + $res = $client->request('GET', 'https://quanqiusou.cn/extend_api/api/get_agent_by_domain.php?'.http_build_query(['token' => $token, 'domain' => $domain]), [
  281 + 'proxy' => env('CURL_PROXY'), // 代理服务器地址和端口号
  282 + ])->getBody()->getContents();
  283 + return Arr::s2a($res);
  284 + } catch (\Exception | GuzzleException $e) {
  285 + errorLog('获取代理失败', [$domain], $e);
  286 + return [];
  287 + }
  288 + }
269 289
270 } 290 }
@@ -9,9 +9,11 @@ namespace App\Http\Controllers\Aside\Task; @@ -9,9 +9,11 @@ namespace App\Http\Controllers\Aside\Task;
9 9
10 use App\Enums\Common\Code; 10 use App\Enums\Common\Code;
11 use App\Helper\Arr; 11 use App\Helper\Arr;
  12 +use App\Helper\QuanqiusouApi;
12 use App\Http\Controllers\Aside\BaseController; 13 use App\Http\Controllers\Aside\BaseController;
13 use App\Models\Channel\Channel; 14 use App\Models\Channel\Channel;
14 use App\Models\Domain\DomainInfo; 15 use App\Models\Domain\DomainInfo;
  16 +use App\Models\Inquiry\ReInquiryCount;
15 use App\Models\Inquiry\ReInquiryDetail; 17 use App\Models\Inquiry\ReInquiryDetail;
16 use App\Models\Inquiry\ReInquiryForm; 18 use App\Models\Inquiry\ReInquiryForm;
17 use App\Models\Inquiry\ReInquiryTask; 19 use App\Models\Inquiry\ReInquiryTask;
@@ -117,6 +119,9 @@ class AdsController extends BaseController @@ -117,6 +119,9 @@ class AdsController extends BaseController
117 } 119 }
118 $item['url'] = trim(str_replace(['http://', 'https://'], '', $item['url']), '/'); 120 $item['url'] = trim(str_replace(['http://', 'https://'], '', $item['url']), '/');
119 } 121 }
  122 + foreach ($target as $v){
  123 + ReInquiryCount::addInquiryNum($id, $v['url'], 0);
  124 + }
120 $task->target = json_encode($target); 125 $task->target = json_encode($target);
121 $task->save(); 126 $task->save();
122 return $this->response('success', Code::SUCCESS, []); 127 return $this->response('success', Code::SUCCESS, []);
@@ -141,19 +146,9 @@ class AdsController extends BaseController @@ -141,19 +146,9 @@ class AdsController extends BaseController
141 ]; 146 ];
142 return $this->response('success', Code::SUCCESS, $data); 147 return $this->response('success', Code::SUCCESS, $data);
143 } 148 }
144 -  
145 - $token = md5($domain.'qqs');  
146 - try {  
147 - $client = new \GuzzleHttp\Client();  
148 - $res = $client->request('GET', 'https://quanqiusou.cn/extend_api/api/get_agent_by_domain.php?'.http_build_query(['token' => $token, 'domain' => $domain]), [  
149 - 'proxy' => env('CURL_PROXY'), // 代理服务器地址和端口号  
150 - ])->getBody()->getContents();  
151 - $res = Arr::s2a($res);  
152 - } catch (\Exception | GuzzleException $e) {  
153 - return $this->response('验证失败,请稍后再试!', Code::USER_ERROR, []);  
154 - } 149 + $res = (new QuanqiusouApi())->getV5Agent($domain);
155 if(empty($res['status']) || $res['status'] != 200){ 150 if(empty($res['status']) || $res['status'] != 200){
156 - return $this->response($res['msg'], Code::USER_ERROR, []); 151 + return $this->response($res['msg'] ?? '验证失败,请稍后再试!', Code::USER_ERROR, []);
157 } 152 }
158 153
159 $agent = implode(',', array_map(function ($v){ 154 $agent = implode(',', array_map(function ($v){
@@ -231,23 +226,28 @@ class AdsController extends BaseController @@ -231,23 +226,28 @@ class AdsController extends BaseController
231 $task_id = intval($request->input('task_id')); 226 $task_id = intval($request->input('task_id'));
232 $domain = trim($request->input('domain')); 227 $domain = trim($request->input('domain'));
233 $company = trim($request->input('company')); 228 $company = trim($request->input('company'));
  229 + $operator = trim($request->input('operator'));
234 $num = trim($request->input('num')); 230 $num = trim($request->input('num'));
235 231
236 - $result = ReInquiryDetail::with('detailLog')  
237 - ->when($status, function ($query, $status) {  
238 - return $query->where('status', $status); 232 + $result = ReInquiryCount::when($task_id, function ($query, $task_id) {
  233 + return $query->WhereRaw("FIND_IN_SET({$task_id}, `task_ids`)");
239 }) 234 })
240 - ->when($form_id, function ($query, $form_id) {  
241 - return $query->where('form_id', $form_id); 235 + ->when($domain, function ($query, $domain) {
  236 + return $query->where('domain', 'like', '%'.$domain.'%');
242 }) 237 })
243 - ->when($task_id, function ($query, $task_id) {  
244 - return $query->where('task_id', $task_id); 238 + ->when($company, function ($query, $company) {
  239 + return $query->where('company', 'like', '%'.$company.'%');
245 }) 240 })
246 - ->when($country, function ($query, $country) {  
247 - return $query->where('country', 'like', '%'.$country.'%'); 241 + ->when($num, function ($query) use($num, $operator) {
  242 + return $query->where('num', $operator?:'=', $num);
248 }) 243 })
249 - ->orderBy('id', 'desc') 244 + ->orderBy('num', 'desc')
250 ->paginate(); 245 ->paginate();
  246 +
  247 + foreach ($result as $item){
  248 + $item->tasks = $item->tasks; //调用访问器
  249 + }
  250 +
251 return $this->response('success', Code::SUCCESS, $result); 251 return $this->response('success', Code::SUCCESS, $result);
252 } 252 }
253 } 253 }
1 <?php 1 <?php
2 -/**  
3 - * Created by PhpStorm.  
4 - * User: zhl  
5 - * Date: 2024/9/30  
6 - * Time: 14:56  
7 - */ 2 +
8 namespace App\Models\Inquiry; 3 namespace App\Models\Inquiry;
9 4
10 use App\Helper\Arr; 5 use App\Helper\Arr;
  6 +use App\Helper\QuanqiusouApi;
  7 +use App\Models\Domain\DomainInfo;
  8 +use App\Models\Project\Project;
  9 +use App\Models\Task\TaskOwner;
11 use Illuminate\Database\Eloquent\Model; 10 use Illuminate\Database\Eloquent\Model;
12 11
13 /** 12 /**
@@ -23,26 +22,50 @@ class ReInquiryCount extends Model @@ -23,26 +22,50 @@ class ReInquiryCount extends Model
23 */ 22 */
24 protected $table = 'gl_re_inquiry_count'; 23 protected $table = 'gl_re_inquiry_count';
25 24
26 - //`task_id` int(11) NOT NULL DEFAULT '0' COMMENT '转发任务ID',  
27 - // `company` varchar(255) NOT NULL DEFAULT '',  
28 - // `domain` varchar(200) NOT NULL DEFAULT '' COMMENT '广告名称',  
29 - // `num` int(2) NOT NU  
30 - public static function updateCount($task_id, $domain, $num = 0){ 25 + /**
  26 + * @param $task_id
  27 + * @param $domain
  28 + * @param int $num
  29 + * @author zbj
  30 + * @date 2024/10/26
  31 + */
  32 + public static function addInquiryNum($task_id, $domain, $num = 1)
  33 + {
31 $model = self::where('domain', $domain)->first(); 34 $model = self::where('domain', $domain)->first();
32 - if(!$model){ 35 +
  36 + if (!$model) {
  37 + //新增时获取公司名
  38 + $company = '';
  39 + $domain_info = DomainInfo::where('domain', $domain)->first();
  40 + if ($domain_info) {
  41 + $company = Project::where('id', $domain_info['project_id'])->value('company');
  42 + } else {
  43 + $res = (new QuanqiusouApi())->getV5Agent($domain);
  44 + if (!empty($res['status']) && $res['status'] == 200) {
  45 + $company = $res['company_name'];
  46 + }
  47 + }
  48 +
33 $model = new self(); 49 $model = new self();
34 $model->domain = $domain; 50 $model->domain = $domain;
35 - $model->company = 51 + $model->company = $company;
36 } 52 }
37 - $model->task_id = 53 + $model->task_ids = $model->task_ids + [$task_id];
  54 + $model->num = $model->num + $num;
  55 + $model->save();
38 } 56 }
39 57
40 - public function setTaskIdsAttribute($value){  
41 - $this->attributes['task_ids'] = Arr::a2s($value); 58 + public function setTaskIdsAttribute($value)
  59 + {
  60 + $this->attributes['task_ids'] = Arr::arrToSet($value);
42 } 61 }
43 62
44 - public function getTaskIdsAttribute($value){  
45 - return Arr::s2a($value); 63 + public function getTaskIdsAttribute($value)
  64 + {
  65 + return Arr::setToArr($value);
46 } 66 }
47 67
  68 + public function getTasksAttribute(){
  69 + return ReInquiryTask::whereIn('id', $this->task_ids)->select(['title', 'industry'])->get();
  70 + }
48 } 71 }