正在显示
3 个修改的文件
包含
59 行增加
和
48 行删除
| @@ -155,7 +155,6 @@ class WebTraffic extends Command | @@ -155,7 +155,6 @@ class WebTraffic extends Command | ||
| 155 | //随机引流间隔 | 155 | //随机引流间隔 |
| 156 | $res_sjjg = $this->get_rand($this->sjjg); | 156 | $res_sjjg = $this->get_rand($this->sjjg); |
| 157 | if ($res_sjjg == 1) { | 157 | if ($res_sjjg == 1) { |
| 158 | - echo '跳过'; | ||
| 159 | continue; | 158 | continue; |
| 160 | } | 159 | } |
| 161 | 160 | ||
| @@ -189,33 +188,9 @@ class WebTraffic extends Command | @@ -189,33 +188,9 @@ class WebTraffic extends Command | ||
| 189 | 'url' => $project['visit_urls'][$j], | 188 | 'url' => $project['visit_urls'][$j], |
| 190 | 'device_port' => $this->get_rand($this->yddzb) | 189 | 'device_port' => $this->get_rand($this->yddzb) |
| 191 | ]; | 190 | ]; |
| 192 | - $query = [ | ||
| 193 | - 'action' => 'stats_init', | ||
| 194 | - 'assort' => 0, | ||
| 195 | - 'referrer' => $data['referer'], | ||
| 196 | - 'currweb' => $data['url'], | ||
| 197 | - 'firstshow' => 0, | ||
| 198 | - 'screenwidth' => 1920, | ||
| 199 | - 'screenheight' => 1080, | ||
| 200 | - 'screencolordepth' => 24, | ||
| 201 | - 'ranstr' => 0.7088574053447112, | ||
| 202 | - ]; | ||
| 203 | - $header = [ | ||
| 204 | - 'CLIENT-IP' => $data['ip'], | ||
| 205 | - 'X-FORWARDED-FOR' => $data['ip'], | ||
| 206 | - 'Referer' => $data['referer'], | ||
| 207 | - 'User-Agent' => $project['user_agent'] | ||
| 208 | - ]; | ||
| 209 | - $promises[] = $client->getAsync($project['domain'] . 'wp-admin/admin-ajax.php', ['headers' => $header, 'query' => $query]); | ||
| 210 | -// $promises[] = $client->postAsync($project['domain'] . 'api/customerVisit', ['form_params' => $data]); | ||
| 211 | - } | ||
| 212 | - $results = Utils::settle($promises)->wait(); | ||
| 213 | - | ||
| 214 | - foreach ($results as $key => $result) { | ||
| 215 | - if ($result['state'] != 'fulfilled') { | ||
| 216 | - dump($result); | ||
| 217 | - } | 191 | + $promises[] = $client->postAsync($project['domain'] . 'api/customerVisit', ['form_params' => $data]); |
| 218 | } | 192 | } |
| 193 | + Utils::settle($promises)->wait(); | ||
| 219 | 194 | ||
| 220 | //每个深度随机等待 | 195 | //每个深度随机等待 |
| 221 | sleep(rand(2, 10)); | 196 | sleep(rand(2, 10)); |
| @@ -228,13 +203,13 @@ class WebTraffic extends Command | @@ -228,13 +203,13 @@ class WebTraffic extends Command | ||
| 228 | * 不同项目 休眠 | 203 | * 不同项目 休眠 |
| 229 | */ | 204 | */ |
| 230 | protected function sleep($type){ | 205 | protected function sleep($type){ |
| 231 | -// if($type == 1){ //1-3个月的项目 | ||
| 232 | -// sleep(rand(5,480)); | ||
| 233 | -// }elseif($type == 2){ //4-8个月的项目 | ||
| 234 | -// sleep(rand(5,240)); | ||
| 235 | -// }elseif($type == 3){ // 大于9个月的项目 | ||
| 236 | -// sleep(rand(5,120)); | ||
| 237 | -// } | 206 | + if($type == 1){ //1-3个月的项目 |
| 207 | + sleep(rand(5,480)); | ||
| 208 | + }elseif($type == 2){ //4-8个月的项目 | ||
| 209 | + sleep(rand(5,240)); | ||
| 210 | + }elseif($type == 3){ // 大于9个月的项目 | ||
| 211 | + sleep(rand(5,120)); | ||
| 212 | + } | ||
| 238 | } | 213 | } |
| 239 | 214 | ||
| 240 | /** | 215 | /** |
| @@ -2,11 +2,15 @@ | @@ -2,11 +2,15 @@ | ||
| 2 | 2 | ||
| 3 | namespace App\Http\Logic\Bside\Product; | 3 | namespace App\Http\Logic\Bside\Product; |
| 4 | 4 | ||
| 5 | +use App\Exceptions\BsideGlobalException; | ||
| 5 | use App\Helper\Arr; | 6 | use App\Helper\Arr; |
| 6 | use App\Http\Logic\Bside\BaseLogic; | 7 | use App\Http\Logic\Bside\BaseLogic; |
| 7 | use App\Models\Product\Category; | 8 | use App\Models\Product\Category; |
| 8 | use App\Models\Product\CategoryRelated; | 9 | use App\Models\Product\CategoryRelated; |
| 10 | +use App\Models\Product\KeywordRelated; | ||
| 9 | use App\Models\Product\Product; | 11 | use App\Models\Product\Product; |
| 12 | +use App\Models\RouteMap; | ||
| 13 | +use Illuminate\Support\Facades\DB; | ||
| 10 | 14 | ||
| 11 | /** | 15 | /** |
| 12 | * Class CategoryLogic | 16 | * Class CategoryLogic |
| @@ -34,26 +38,54 @@ class CategoryLogic extends BaseLogic | @@ -34,26 +38,54 @@ class CategoryLogic extends BaseLogic | ||
| 34 | $this->fail('上级分类不存在'); | 38 | $this->fail('上级分类不存在'); |
| 35 | } | 39 | } |
| 36 | } | 40 | } |
| 37 | - return parent::save($param); | 41 | + DB::beginTransaction(); |
| 42 | + try { | ||
| 43 | + $res = parent::save($param); | ||
| 44 | + //路由映射 | ||
| 45 | + RouteMap::setRoute($param['title'], RouteMap::SOURCE_PRODUCT_CATE, $res['id'], $this->user['project_id']); | ||
| 46 | + DB::commit(); | ||
| 47 | + } catch (\Exception $e){ | ||
| 48 | + DB::rollBack(); | ||
| 49 | + errorLog('产品分类保存失败', $param, $e); | ||
| 50 | + $this->fail('保存失败'); | ||
| 51 | + } | ||
| 52 | + return $this->success(); | ||
| 38 | } | 53 | } |
| 39 | 54 | ||
| 40 | public function delete($ids, $map = []){ | 55 | public function delete($ids, $map = []){ |
| 41 | $ids= array_filter(Arr::splitFilterToArray($ids), 'intval'); | 56 | $ids= array_filter(Arr::splitFilterToArray($ids), 'intval'); |
| 42 | - foreach ($ids as $id){ | ||
| 43 | - $info = $this->getCacheInfo($id); | ||
| 44 | - if(!$info){ | ||
| 45 | - continue; | ||
| 46 | - } | ||
| 47 | - //是否有子分类 | ||
| 48 | - if(Category::where('project_id', $this->user['project_id'])->where('pid', $id)->count()){ | ||
| 49 | - $this->fail("分类{$info['title']}存在子分类,不能删除"); | ||
| 50 | - } | ||
| 51 | - //是否有对应商品 | ||
| 52 | - if(CategoryRelated::where('cate_id', $id)->count()){ | ||
| 53 | - $this->fail("分类{$info['title']}存在产品,不能删除"); | 57 | + |
| 58 | + DB::beginTransaction(); | ||
| 59 | + try { | ||
| 60 | + parent::delete($ids); | ||
| 61 | + | ||
| 62 | + foreach ($ids as $id){ | ||
| 63 | + $info = $this->getCacheInfo($id); | ||
| 64 | + if(!$info){ | ||
| 65 | + continue; | ||
| 66 | + } | ||
| 67 | + //是否有子分类 | ||
| 68 | + if(Category::where('project_id', $this->user['project_id'])->where('pid', $id)->count()){ | ||
| 69 | + $this->fail("分类{$info['title']}存在子分类,不能删除"); | ||
| 70 | + } | ||
| 71 | + //是否有对应商品 | ||
| 72 | + if(CategoryRelated::where('cate_id', $id)->count()){ | ||
| 73 | + $this->fail("分类{$info['title']}存在产品,不能删除"); | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + //删除路由映射 | ||
| 77 | + RouteMap::delRoute(RouteMap::SOURCE_PRODUCT_CATE, $id, $this->user['project_id']); | ||
| 54 | } | 78 | } |
| 79 | + | ||
| 80 | + DB::commit(); | ||
| 81 | + } catch (BsideGlobalException $e){ | ||
| 82 | + DB::rollBack(); | ||
| 83 | + $this->fail($e->getMessage()); | ||
| 84 | + } catch (\Exception $e){ | ||
| 85 | + DB::rollBack(); | ||
| 86 | + $this->fail('删除失败'); | ||
| 55 | } | 87 | } |
| 56 | - return parent::delete($ids); | 88 | + return $this->success(); |
| 57 | } | 89 | } |
| 58 | 90 | ||
| 59 | /** | 91 | /** |
| @@ -2,6 +2,7 @@ | @@ -2,6 +2,7 @@ | ||
| 2 | 2 | ||
| 3 | namespace App\Http\Logic\Bside\Product; | 3 | namespace App\Http\Logic\Bside\Product; |
| 4 | 4 | ||
| 5 | +use App\Exceptions\BsideGlobalException; | ||
| 5 | use App\Helper\Arr; | 6 | use App\Helper\Arr; |
| 6 | use App\Http\Logic\Bside\BaseLogic; | 7 | use App\Http\Logic\Bside\BaseLogic; |
| 7 | use App\Models\Product\KeywordRelated; | 8 | use App\Models\Product\KeywordRelated; |
| @@ -62,6 +63,9 @@ class KeywordLogic extends BaseLogic | @@ -62,6 +63,9 @@ class KeywordLogic extends BaseLogic | ||
| 62 | } | 63 | } |
| 63 | 64 | ||
| 64 | DB::commit(); | 65 | DB::commit(); |
| 66 | + } catch (BsideGlobalException $e){ | ||
| 67 | + DB::rollBack(); | ||
| 68 | + $this->fail($e->getMessage()); | ||
| 65 | }catch (\Exception $e){ | 69 | }catch (\Exception $e){ |
| 66 | DB::rollBack(); | 70 | DB::rollBack(); |
| 67 | $this->fail('删除失败'); | 71 | $this->fail('删除失败'); |
-
请 注册 或 登录 后发表评论