作者 赵彬吉

update

... ... @@ -155,7 +155,6 @@ class WebTraffic extends Command
//随机引流间隔
$res_sjjg = $this->get_rand($this->sjjg);
if ($res_sjjg == 1) {
echo '跳过';
continue;
}
... ... @@ -189,33 +188,9 @@ class WebTraffic extends Command
'url' => $project['visit_urls'][$j],
'device_port' => $this->get_rand($this->yddzb)
];
$query = [
'action' => 'stats_init',
'assort' => 0,
'referrer' => $data['referer'],
'currweb' => $data['url'],
'firstshow' => 0,
'screenwidth' => 1920,
'screenheight' => 1080,
'screencolordepth' => 24,
'ranstr' => 0.7088574053447112,
];
$header = [
'CLIENT-IP' => $data['ip'],
'X-FORWARDED-FOR' => $data['ip'],
'Referer' => $data['referer'],
'User-Agent' => $project['user_agent']
];
$promises[] = $client->getAsync($project['domain'] . 'wp-admin/admin-ajax.php', ['headers' => $header, 'query' => $query]);
// $promises[] = $client->postAsync($project['domain'] . 'api/customerVisit', ['form_params' => $data]);
}
$results = Utils::settle($promises)->wait();
foreach ($results as $key => $result) {
if ($result['state'] != 'fulfilled') {
dump($result);
}
$promises[] = $client->postAsync($project['domain'] . 'api/customerVisit', ['form_params' => $data]);
}
Utils::settle($promises)->wait();
//每个深度随机等待
sleep(rand(2, 10));
... ... @@ -228,13 +203,13 @@ class WebTraffic extends Command
* 不同项目 休眠
*/
protected function sleep($type){
// if($type == 1){ //1-3个月的项目
// sleep(rand(5,480));
// }elseif($type == 2){ //4-8个月的项目
// sleep(rand(5,240));
// }elseif($type == 3){ // 大于9个月的项目
// sleep(rand(5,120));
// }
if($type == 1){ //1-3个月的项目
sleep(rand(5,480));
}elseif($type == 2){ //4-8个月的项目
sleep(rand(5,240));
}elseif($type == 3){ // 大于9个月的项目
sleep(rand(5,120));
}
}
/**
... ...
... ... @@ -2,11 +2,15 @@
namespace App\Http\Logic\Bside\Product;
use App\Exceptions\BsideGlobalException;
use App\Helper\Arr;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Product\Category;
use App\Models\Product\CategoryRelated;
use App\Models\Product\KeywordRelated;
use App\Models\Product\Product;
use App\Models\RouteMap;
use Illuminate\Support\Facades\DB;
/**
* Class CategoryLogic
... ... @@ -34,11 +38,27 @@ class CategoryLogic extends BaseLogic
$this->fail('上级分类不存在');
}
}
return parent::save($param);
DB::beginTransaction();
try {
$res = parent::save($param);
//路由映射
RouteMap::setRoute($param['title'], RouteMap::SOURCE_PRODUCT_CATE, $res['id'], $this->user['project_id']);
DB::commit();
} catch (\Exception $e){
DB::rollBack();
errorLog('产品分类保存失败', $param, $e);
$this->fail('保存失败');
}
return $this->success();
}
public function delete($ids, $map = []){
$ids= array_filter(Arr::splitFilterToArray($ids), 'intval');
DB::beginTransaction();
try {
parent::delete($ids);
foreach ($ids as $id){
$info = $this->getCacheInfo($id);
if(!$info){
... ... @@ -52,8 +72,20 @@ class CategoryLogic extends BaseLogic
if(CategoryRelated::where('cate_id', $id)->count()){
$this->fail("分类{$info['title']}存在产品,不能删除");
}
//删除路由映射
RouteMap::delRoute(RouteMap::SOURCE_PRODUCT_CATE, $id, $this->user['project_id']);
}
DB::commit();
} catch (BsideGlobalException $e){
DB::rollBack();
$this->fail($e->getMessage());
} catch (\Exception $e){
DB::rollBack();
$this->fail('删除失败');
}
return parent::delete($ids);
return $this->success();
}
/**
... ...
... ... @@ -2,6 +2,7 @@
namespace App\Http\Logic\Bside\Product;
use App\Exceptions\BsideGlobalException;
use App\Helper\Arr;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Product\KeywordRelated;
... ... @@ -62,6 +63,9 @@ class KeywordLogic extends BaseLogic
}
DB::commit();
} catch (BsideGlobalException $e){
DB::rollBack();
$this->fail($e->getMessage());
}catch (\Exception $e){
DB::rollBack();
$this->fail('删除失败');
... ...