作者 赵彬吉

update

  1 +<?php
  2 +
  3 +
  4 +namespace App\Helper;
  5 +
  6 +use Illuminate\Support\Facades\Http;
  7 +
  8 +
  9 +/**
  10 + * 翻译接口
  11 + * Class Translate
  12 + * @package App\Service
  13 + * @author zbj
  14 + * @date 2023/2/7
  15 + */
  16 +class Translate
  17 +{
  18 + //接口地址
  19 + public static $url = 'https://translate.hbb618.cn/translates';
  20 +
  21 + public static $tls_list = [
  22 + 'en' => [
  23 + 'text' => '英语',
  24 + 'lang_text' => 'English',
  25 + 'con_flag' => 'con_flag/en.jfif',
  26 + 'shop_lang' => 'en-gb',
  27 + ],
  28 + 'zh' => [
  29 + 'text' => '中文',
  30 + 'lang_text' => '简体中文',
  31 + 'con_flag' => 'con_flag/zh.jfif',
  32 + 'shop_lang' => 'zh-cn',
  33 + ],
  34 + 'fr' => [
  35 + 'text' => '法语',
  36 + 'lang_text' => 'En français',
  37 + 'con_flag' => '',
  38 +
  39 + ],
  40 + 'de' => [
  41 + 'text' => '德语',
  42 + 'lang_text' => 'Das ist Deutsch.',
  43 + 'con_flag' => '',
  44 +
  45 + ],
  46 + 'ko' => [
  47 + 'text' => '韩语',
  48 + 'lang_text' => '',
  49 + 'con_flag' => '',
  50 +
  51 + ],
  52 + 'ja' => [
  53 + 'text' => '日语',
  54 + 'lang_text' => '',
  55 + 'con_flag' => '',
  56 +
  57 + ],
  58 + 'es' => [
  59 + 'text' => '西班牙语',
  60 + 'lang_text' => 'Español.',
  61 + 'con_flag' => '',
  62 +
  63 + ],
  64 + 'ar' => [
  65 + 'text' => '阿拉伯语',
  66 + 'lang_text' => '',
  67 + 'con_flag' => '',
  68 +
  69 + ],
  70 + 'pt' => [
  71 + 'text' => '葡萄牙语(葡萄牙、巴西)',
  72 + 'lang_text' => 'Língua portuguesa',
  73 + 'con_flag' => '',
  74 +
  75 + ],
  76 + 'ru' => [
  77 + 'text' => '俄语',
  78 + 'lang_text' => '',
  79 + 'con_flag' => '',
  80 +
  81 + ],
  82 + 'af' => [
  83 + 'text' => '南非荷兰语',
  84 + 'lang_text' => '',
  85 + 'con_flag' => '',
  86 +
  87 + ],
  88 + 'sq' => [
  89 + 'text' => '阿尔巴尼亚语',
  90 + 'lang_text' => '',
  91 + 'con_flag' => '',
  92 +
  93 + ],
  94 + 'am' => [
  95 + 'text' => '阿姆哈拉语',
  96 + 'lang_text' => '',
  97 + 'con_flag' => '',
  98 +
  99 + ],
  100 + 'hy' => [
  101 + 'text' => '亚美尼亚语',
  102 + 'lang_text' => '',
  103 + 'con_flag' => '',
  104 +
  105 + ],
  106 + 'az' => [
  107 + 'text' => '阿塞拜疆语',
  108 + 'lang_text' => '',
  109 + 'con_flag' => '',
  110 +
  111 + ],
  112 + 'eu' => [
  113 + 'text' => '巴斯克语',
  114 + 'lang_text' => '',
  115 + 'con_flag' => '',
  116 +
  117 + ],
  118 + 'be' => [
  119 + 'text' => '白俄罗斯语',
  120 + 'lang_text' => '',
  121 + 'con_flag' => '',
  122 +
  123 + ],
  124 + 'bn' => [
  125 + 'text' => '孟加拉语',
  126 + 'lang_text' => '',
  127 + 'con_flag' => '',
  128 +
  129 + ],
  130 + 'bs' => [
  131 + 'text' => '波斯尼亚语',
  132 + 'lang_text' => '',
  133 + 'con_flag' => '',
  134 +
  135 + ],
  136 + 'bg' => [
  137 + 'text' => '保加利亚语',
  138 + 'lang_text' => '',
  139 + 'con_flag' => '',
  140 +
  141 + ],
  142 + 'ca' => [
  143 + 'text' => '加泰罗尼亚语',
  144 + 'lang_text' => '',
  145 + 'con_flag' => '',
  146 +
  147 + ],
  148 + 'ceb' => [
  149 + 'text' => '宿务语',
  150 + 'lang_text' => '',
  151 + 'con_flag' => '',
  152 +
  153 + ],
  154 + 'zh-CN' => [
  155 + 'text' => '中文(简体)',
  156 + 'lang_text' => '简体中文',
  157 + 'con_flag' => 'con_flag/zh.jfif',
  158 + 'shop_lang' => 'zh-cn',
  159 + ],
  160 + 'zh-TW' => [
  161 + 'text' => '中文(繁体)',
  162 + 'lang_text' => '繁体中文',
  163 + 'con_flag' => 'con_flag/zh.jfif',
  164 +
  165 + ],
  166 + 'co' => [
  167 + 'text' => '科西嘉语',
  168 + 'lang_text' => '',
  169 + 'con_flag' => '',
  170 +
  171 + ],
  172 + 'hr' => [
  173 + 'text' => '克罗地亚语',
  174 + 'lang_text' => '',
  175 + 'con_flag' => '',
  176 +
  177 + ],
  178 + 'cs' => [
  179 + 'text' => '捷克语',
  180 + 'lang_text' => '',
  181 + 'con_flag' => '',
  182 +
  183 + ],
  184 + 'da' => [
  185 + 'text' => '丹麦语',
  186 + 'lang_text' => '',
  187 + 'con_flag' => '',
  188 +
  189 + ],
  190 + 'nl' => [
  191 + 'text' => '荷兰语',
  192 + 'lang_text' => '',
  193 + 'con_flag' => '',
  194 +
  195 + ],
  196 + 'eo' => [
  197 + 'text' => '世界语',
  198 + 'lang_text' => '',
  199 + 'con_flag' => '',
  200 +
  201 + ],
  202 + 'et' => [
  203 + 'text' => '爱沙尼亚语',
  204 + 'lang_text' => '',
  205 + 'con_flag' => '',
  206 +
  207 + ],
  208 + 'fi' => [
  209 + 'text' => '芬兰语',
  210 + 'lang_text' => '',
  211 + 'con_flag' => '',
  212 +
  213 + ],
  214 + 'fy' => [
  215 + 'text' => '弗里斯兰语',
  216 + 'lang_text' => '',
  217 + 'con_flag' => '',
  218 +
  219 + ],
  220 + 'gl' => [
  221 + 'text' => '加利西亚语',
  222 + 'lang_text' => '',
  223 + 'con_flag' => '',
  224 +
  225 + ],
  226 + 'ka' => [
  227 + 'text' => '格鲁吉亚语',
  228 + 'lang_text' => '',
  229 + 'con_flag' => '',
  230 +
  231 + ],
  232 + 'el' => [
  233 + 'text' => '希腊语',
  234 + 'lang_text' => '',
  235 + 'con_flag' => '',
  236 +
  237 + ],
  238 + 'gu' => [
  239 + 'text' => '古吉拉特语',
  240 + 'lang_text' => '',
  241 + 'con_flag' => '',
  242 +
  243 + ],
  244 + 'ht' => [
  245 + 'text' => '海地克里奥尔语',
  246 + 'lang_text' => '',
  247 + 'con_flag' => '',
  248 +
  249 + ],
  250 + 'ha' => [
  251 + 'text' => '豪萨语',
  252 + 'lang_text' => '',
  253 + 'con_flag' => '',
  254 +
  255 + ],
  256 + 'haw' => [
  257 + 'text' => '夏威夷语',
  258 + 'lang_text' => '',
  259 + 'con_flag' => '',
  260 +
  261 + ],
  262 + 'iw' => [
  263 + 'text' => '希伯来语',
  264 + 'lang_text' => '',
  265 + 'con_flag' => '',
  266 +
  267 + ],
  268 + 'hi' => [
  269 + 'text' => '印地语',
  270 + 'lang_text' => '',
  271 + 'con_flag' => '',
  272 +
  273 + ],
  274 + 'hmn' => [
  275 + 'text' => '苗语',
  276 + 'lang_text' => '',
  277 + 'con_flag' => '',
  278 +
  279 + ],
  280 + 'hu' => [
  281 + 'text' => '匈牙利语',
  282 + 'lang_text' => '',
  283 + 'con_flag' => '',
  284 +
  285 + ],
  286 + 'is' => [
  287 + 'text' => '冰岛语',
  288 + 'lang_text' => '',
  289 + 'con_flag' => '',
  290 +
  291 + ],
  292 + 'ig' => [
  293 + 'text' => '伊博语',
  294 + 'lang_text' => '',
  295 + 'con_flag' => '',
  296 +
  297 + ],
  298 + 'id' => [
  299 + 'text' => '印度尼西亚语',
  300 + 'lang_text' => 'Bahasa Indonesia',
  301 + 'con_flag' => 'con_flag/id.jfif',
  302 + 'shop_lang' => 'id',
  303 + ],
  304 + 'ga' => [
  305 + 'text' => '爱尔兰语',
  306 + 'lang_text' => '',
  307 + 'con_flag' => '',
  308 +
  309 + ],
  310 + 'it' => [
  311 + 'text' => '意大利语',
  312 + 'lang_text' => 'Lingua italiana',
  313 + 'con_flag' => '',
  314 +
  315 + ],
  316 + 'jw' => [
  317 + 'text' => '爪哇语',
  318 + 'lang_text' => '',
  319 + 'con_flag' => '',
  320 +
  321 + ],
  322 + 'kn' => [
  323 + 'text' => '卡纳达语',
  324 + 'lang_text' => '',
  325 + 'con_flag' => '',
  326 +
  327 + ],
  328 + 'kk' => [
  329 + 'text' => '哈萨克语',
  330 + 'lang_text' => '',
  331 + 'con_flag' => '',
  332 +
  333 + ],
  334 + 'km' => [
  335 + 'text' => '高棉语',
  336 + 'lang_text' => '',
  337 + 'con_flag' => '',
  338 +
  339 + ],
  340 + 'rw' => [
  341 + 'text' => '卢旺达语',
  342 + 'lang_text' => '',
  343 + 'con_flag' => '',
  344 +
  345 + ],
  346 + 'ku' => [
  347 + 'text' => '库尔德语',
  348 + 'lang_text' => '',
  349 + 'con_flag' => '',
  350 +
  351 + ],
  352 + 'ky' => [
  353 + 'text' => '吉尔吉斯语',
  354 + 'lang_text' => '',
  355 + 'con_flag' => '',
  356 +
  357 + ],
  358 + 'lo' => [
  359 + 'text' => '老挝文',
  360 + 'lang_text' => '',
  361 + 'con_flag' => '',
  362 +
  363 + ],
  364 + 'la' => [
  365 + 'text' => '拉丁文',
  366 + 'lang_text' => '',
  367 + 'con_flag' => '',
  368 +
  369 + ],
  370 + 'lv' => [
  371 + 'text' => '拉脱维亚语',
  372 + 'lang_text' => '',
  373 + 'con_flag' => '',
  374 +
  375 + ],
  376 + 'lt' => [
  377 + 'text' => '立陶宛语',
  378 + 'lang_text' => '',
  379 + 'con_flag' => '',
  380 +
  381 + ],
  382 + 'lb' => [
  383 + 'text' => '卢森堡语',
  384 + 'lang_text' => '',
  385 + 'con_flag' => '',
  386 +
  387 + ],
  388 + 'mk' => [
  389 + 'text' => '马其顿语',
  390 + 'lang_text' => '',
  391 + 'con_flag' => '',
  392 +
  393 + ],
  394 + 'mg' => [
  395 + 'text' => '马尔加什语',
  396 + 'lang_text' => '',
  397 + 'con_flag' => '',
  398 +
  399 + ],
  400 + 'ms' => [
  401 + 'text' => '马来语',
  402 + 'lang_text' => 'Bahasa Melayu',
  403 + 'con_flag' => 'con_flag/ms.jfif',
  404 + 'shop_lang' => 'ms-my',
  405 + ],
  406 + 'ml' => [
  407 + 'text' => '马拉雅拉姆文',
  408 + 'lang_text' => '',
  409 + 'con_flag' => '',
  410 +
  411 + ],
  412 + 'mt' => [
  413 + 'text' => '马耳他语',
  414 + 'lang_text' => '',
  415 + 'con_flag' => '',
  416 +
  417 + ],
  418 + 'mi' => [
  419 + 'text' => '毛利语',
  420 + 'lang_text' => '',
  421 + 'con_flag' => '',
  422 +
  423 + ],
  424 + 'mr' => [
  425 + 'text' => '马拉地语',
  426 + 'lang_text' => '',
  427 + 'con_flag' => '',
  428 +
  429 + ],
  430 + 'mn' => [
  431 + 'text' => '蒙古文',
  432 + 'lang_text' => '',
  433 + 'con_flag' => '',
  434 +
  435 + ],
  436 + 'my' => [
  437 + 'text' => '缅甸语',
  438 + 'lang_text' => '',
  439 + 'con_flag' => '',
  440 +
  441 + ],
  442 + 'ne' => [
  443 + 'text' => '尼泊尔语',
  444 + 'lang_text' => '',
  445 + 'con_flag' => '',
  446 +
  447 + ],
  448 + 'no' => [
  449 + 'text' => '挪威语',
  450 + 'lang_text' => '',
  451 + 'con_flag' => '',
  452 +
  453 + ],
  454 + 'ny' => [
  455 + 'text' => '尼杨扎语(齐切瓦语)',
  456 + 'lang_text' => '',
  457 + 'con_flag' => '',
  458 +
  459 + ],
  460 + 'or' => [
  461 + 'text' => '奥里亚语(奥里亚)',
  462 + 'lang_text' => '',
  463 + 'con_flag' => '',
  464 +
  465 + ],
  466 + 'ps' => [
  467 + 'text' => '普什图语',
  468 + 'lang_text' => '',
  469 + 'con_flag' => '',
  470 +
  471 + ],
  472 + 'fa' => [
  473 + 'text' => '波斯语',
  474 + 'lang_text' => '',
  475 + 'con_flag' => '',
  476 +
  477 + ],
  478 + 'pl' => [
  479 + 'text' => '波兰语',
  480 + 'lang_text' => '',
  481 + 'con_flag' => '',
  482 +
  483 + ],
  484 + 'pa' => [
  485 + 'text' => '旁遮普语',
  486 + 'lang_text' => '',
  487 + 'con_flag' => '',
  488 +
  489 + ],
  490 + 'ro' => [
  491 + 'text' => '罗马尼亚语',
  492 + 'lang_text' => '',
  493 + 'con_flag' => '',
  494 +
  495 + ],
  496 + 'sm' => [
  497 + 'text' => '萨摩亚语',
  498 + 'lang_text' => '',
  499 + 'con_flag' => '',
  500 +
  501 + ],
  502 + 'gd' => [
  503 + 'text' => '苏格兰盖尔语',
  504 + 'lang_text' => '',
  505 + 'con_flag' => '',
  506 +
  507 + ],
  508 + 'sr' => [
  509 + 'text' => '塞尔维亚语',
  510 + 'lang_text' => '',
  511 + 'con_flag' => '',
  512 +
  513 + ],
  514 + 'st' => [
  515 + 'text' => '塞索托语',
  516 + 'lang_text' => '',
  517 + 'con_flag' => '',
  518 +
  519 + ],
  520 + 'sn' => [
  521 + 'text' => '修纳语',
  522 + 'lang_text' => '',
  523 + 'con_flag' => '',
  524 +
  525 + ],
  526 + 'sd' => [
  527 + 'text' => '信德语',
  528 + 'lang_text' => '',
  529 + 'con_flag' => '',
  530 +
  531 + ],
  532 + 'si' => [
  533 + 'text' => '僧伽罗语',
  534 + 'lang_text' => '',
  535 + 'con_flag' => '',
  536 +
  537 + ],
  538 + 'sk' => [
  539 + 'text' => '斯洛伐克语',
  540 + 'lang_text' => '',
  541 + 'con_flag' => '',
  542 +
  543 + ],
  544 + 'sl' => [
  545 + 'text' => '斯洛文尼亚语',
  546 + 'lang_text' => '',
  547 + 'con_flag' => '',
  548 +
  549 + ],
  550 + 'so' => [
  551 + 'text' => '索马里语',
  552 + 'lang_text' => '',
  553 + 'con_flag' => '',
  554 +
  555 + ],
  556 + 'su' => [
  557 + 'text' => '巽他语',
  558 + 'lang_text' => '',
  559 + 'con_flag' => '',
  560 +
  561 + ],
  562 + 'sw' => [
  563 + 'text' => '斯瓦希里语',
  564 + 'lang_text' => '',
  565 + 'con_flag' => '',
  566 +
  567 + ],
  568 + 'sv' => [
  569 + 'text' => '瑞典语',
  570 + 'lang_text' => '',
  571 + 'con_flag' => '',
  572 +
  573 + ],
  574 + 'tl' => [
  575 + 'text' => '塔加路语(菲律宾语)',
  576 + 'lang_text' => 'Pilipino',
  577 + 'con_flag' => 'con_flag/tl.jfif',
  578 + 'shop_lang' => 'tl',
  579 + ],
  580 + 'tg' => [
  581 + 'text' => '塔吉克语',
  582 + 'lang_text' => '',
  583 + 'con_flag' => '',
  584 +
  585 + ],
  586 + 'ta' => [
  587 + 'text' => '泰米尔语',
  588 + 'lang_text' => '',
  589 + 'con_flag' => '',
  590 +
  591 + ],
  592 + 'tt' => [
  593 + 'text' => '鞑靼语',
  594 + 'lang_text' => '',
  595 + 'con_flag' => '',
  596 +
  597 + ],
  598 + 'te' => [
  599 + 'text' => '泰卢固语',
  600 + 'lang_text' => '',
  601 + 'con_flag' => '',
  602 +
  603 + ],
  604 + 'th' => [
  605 + 'text' => '泰文',
  606 + 'lang_text' => 'ไทย',
  607 + 'con_flag' => 'con_flag/th.jfif',
  608 + 'shop_lang' => 'th',
  609 + ],
  610 + 'tr' => [
  611 + 'text' => '土耳其语',
  612 + 'lang_text' => '',
  613 + 'con_flag' => '',
  614 +
  615 + ],
  616 + 'tk' => [
  617 + 'text' => '土库曼语',
  618 + 'lang_text' => '',
  619 + 'con_flag' => '',
  620 +
  621 + ],
  622 + 'uk' => [
  623 + 'text' => '乌克兰语',
  624 + 'lang_text' => '',
  625 + 'con_flag' => '',
  626 +
  627 + ],
  628 + 'ur' => [
  629 + 'text' => '乌尔都语',
  630 + 'lang_text' => '',
  631 + 'con_flag' => '',
  632 +
  633 + ],
  634 + 'ug' => [
  635 + 'text' => '维吾尔语',
  636 + 'lang_text' => '',
  637 + 'con_flag' => '',
  638 +
  639 + ],
  640 + 'uz' => [
  641 + 'text' => '乌兹别克语',
  642 + 'lang_text' => '',
  643 + 'con_flag' => '',
  644 +
  645 + ],
  646 + 'vi' => [
  647 + 'text' => '越南语',
  648 + 'lang_text' => '',
  649 + 'con_flag' => '',
  650 +
  651 + ],
  652 + 'cy' => [
  653 + 'text' => '威尔士语',
  654 + 'lang_text' => '',
  655 + 'con_flag' => '',
  656 +
  657 + ],
  658 + 'xh' => [
  659 + 'text' => '班图语',
  660 + 'lang_text' => '',
  661 + 'con_flag' => '',
  662 +
  663 + ],
  664 + 'yi' => [
  665 + 'text' => '意第绪语',
  666 + 'lang_text' => '',
  667 + 'con_flag' => '',
  668 +
  669 + ],
  670 + 'yo' => [
  671 + 'text' => '约鲁巴语',
  672 + 'lang_text' => '',
  673 + 'con_flag' => '',
  674 +
  675 + ],
  676 + 'zu' => [
  677 + 'text' => '祖鲁语',
  678 + 'lang_text' => '',
  679 + 'con_flag' => '',
  680 + ],
  681 + ];
  682 +
  683 + /**
  684 + * 获取语种列表
  685 + * @return array|string
  686 + * @author:dc
  687 + * @time 2022/3/30 13:52
  688 + */
  689 + public static function getTls($lang = null){
  690 + $tls = array_combine(array_keys(static::$tls_list),array_column(static::$tls_list, 'text'));
  691 +
  692 + if($lang === null){
  693 + return $tls;
  694 + }
  695 +
  696 + if (is_array($lang)){
  697 + foreach ($lang as $key=>$item){
  698 + unset($lang[$key]);
  699 + $lang[$item] = $tls[$item]??'';
  700 + }
  701 + return $lang;
  702 + }
  703 +
  704 + return $tls[$lang]??'';
  705 + }
  706 +
  707 + /**
  708 + * 翻译
  709 + * @param $texts
  710 + * @param $tls
  711 + * @return \Illuminate\Http\Client\Response
  712 + * @time 2022/3/30 15:58
  713 + */
  714 + public static function translate($texts, $tls)
  715 + {
  716 + if (is_string($texts)) {
  717 + $texts = [$texts];
  718 + }
  719 + if (is_string($tls)) {
  720 + $tls = [$tls];
  721 + }
  722 + $data = [
  723 + 'texts' => $texts,
  724 + 'sl' => 'auto',
  725 + 'tls' => $tls,
  726 + ];
  727 + return Http::post(self::$url, $data);
  728 + }
  729 +
  730 + /**
  731 + * @param $texts
  732 + * @param $tls
  733 + * @return string|array
  734 + * @author:dc
  735 + * @time 2022/3/30 15:59
  736 + */
  737 + public static function tran($texts, $tls)
  738 + {
  739 + if (!$texts) {
  740 + return '';
  741 + }
  742 +
  743 + $retsult = self::translate($texts, $tls)->json();
  744 +
  745 + return $retsult[0]['texts'] ?? '';
  746 +
  747 + }
  748 +
  749 +
  750 +}
@@ -10,10 +10,15 @@ define('HTTP_OPENAI_URL','http://openai.waimaoq.com/'); @@ -10,10 +10,15 @@ define('HTTP_OPENAI_URL','http://openai.waimaoq.com/');
10 * @author zbj 10 * @author zbj
11 * @date 2023/4/15 11 * @date 2023/4/15
12 */ 12 */
13 -function generateRoute($string){  
14 - return trim(strtolower(preg_replace( '/[\W]+/', '-', trim($string))), '-'); 13 +
  14 +if (!function_exists('generateRoute')) {
  15 + function generateRoute($string)
  16 + {
  17 + return trim(strtolower(preg_replace('/[\W]+/', '-', trim($string))), '-');
  18 + }
15 } 19 }
16 20
  21 +
17 /** 22 /**
18 * 手动记录错误日志 23 * 手动记录错误日志
19 * @param $title 24 * @param $title
@@ -107,3 +112,31 @@ if(!function_exists('_get_child')){ @@ -107,3 +112,31 @@ if(!function_exists('_get_child')){
107 return $new_arr ? $new_arr : false; 112 return $new_arr ? $new_arr : false;
108 } 113 }
109 } 114 }
  115 +
  116 +
  117 +
  118 +if (!function_exists('checkDomain')) {
  119 + /**
  120 + * 检查并补全域名协议
  121 + * @return false|string
  122 + * @author zbj
  123 + * @date 2023/5/5
  124 + */
  125 + function checkDomain($value)
  126 + {
  127 + $urlParts = parse_url(strtolower($value));
  128 + if(empty($urlParts['host'])){
  129 + $urlParts = parse_url('https://' . $value);
  130 + }
  131 + $host = $urlParts['host'] ?? '';
  132 + $scheme = $urlParts['scheme'] ?? 'https';
  133 + if(!in_array($scheme, ['http', 'https'])){
  134 + return false;
  135 + }
  136 + if (preg_match('/^(?:[-A-Za-z0-9]+\.)+[A-Za-z]{2,6}$/', $host)) {
  137 + return $scheme . '://' . $host;
  138 + } else {
  139 + return false;
  140 + }
  141 + }
  142 +}
@@ -55,7 +55,7 @@ class ProductController extends BaseController @@ -55,7 +55,7 @@ class ProductController extends BaseController
55 ]); 55 ]);
56 $data = $logic->getInfo($this->param['id']); 56 $data = $logic->getInfo($this->param['id']);
57 return $this->success(Arr::twoKeepKeys($data, ['id', 'title', 'gallery', 'attrs', 'category_id', 'keyword_id', 'attr_id', 'describe_id', 'intro', 'content', 57 return $this->success(Arr::twoKeepKeys($data, ['id', 'title', 'gallery', 'attrs', 'category_id', 'keyword_id', 'attr_id', 'describe_id', 'intro', 'content',
58 - 'describe', 'seo_mate', 'related_product_id', 'status', 'category_id_text', 'keyword_id_text', 'status_text', 'created_uid', 'created_uid_text'])); 58 + 'describe', 'seo_mate', 'related_product_id', 'status', 'category_id_text', 'keyword_id_text', 'status_text', 'created_uid', 'created_uid_text', 'route']));
59 } 59 }
60 60
61 public function save(ProductRequest $request, ProductLogic $logic) 61 public function save(ProductRequest $request, ProductLogic $logic)
  1 +<?php
  2 +
  3 +
  4 +namespace App\Http\Controllers\Bside;
  5 +
  6 +
  7 +use App\Helper\Translate;
  8 +use App\Models\RouteMap;
  9 +use App\Rules\Ids;
  10 +use Illuminate\Http\Request;
  11 +
  12 +class RouteController extends BaseController
  13 +{
  14 +
  15 + /**
  16 + * 生成路由
  17 + * @param Request $request
  18 + * @return \Illuminate\Http\JsonResponse
  19 + * @author zbj
  20 + * @date 2023/5/5
  21 + */
  22 + public function create(Request $request){
  23 + $title = $request->input('title');
  24 + $source = $request->input('source');
  25 + $source_id = $request->input('source_id');
  26 + $project_id = $this->user['project_id'];
  27 +
  28 + //有中文先翻译
  29 + if(preg_match('/[\x{4e00}-\x{9fa5}]/u', $title)){
  30 + $title = Translate::tran($title, 'en');
  31 + }
  32 +
  33 + $route = RouteMap::generateRoute($title, $source, $source_id, $project_id);
  34 + return $this->success(['route' => $route]);
  35 + }
  36 +}
@@ -39,6 +39,19 @@ class ProjectLogic extends BaseLogic @@ -39,6 +39,19 @@ class ProjectLogic extends BaseLogic
39 } 39 }
40 40
41 public function save($param){ 41 public function save($param){
  42 + if(!empty($param['test_domain'])){
  43 + $param['test_domain'] = checkDomain($param['test_domain']);
  44 + if(!$param['test_domain']){
  45 + $this->fail('测试域名格式不正确');
  46 + }
  47 + }
  48 + if(!empty($param['domain'])){
  49 + $param['domain'] = checkDomain($param['domain']);
  50 + if(!$param['domain']){
  51 + $this->fail('正式域名格式不正确');
  52 + }
  53 + }
  54 +
42 DB::beginTransaction(); 55 DB::beginTransaction();
43 try { 56 try {
44 $res = parent::save($param); 57 $res = parent::save($param);
@@ -37,7 +37,7 @@ class ProductRequest extends FormRequest @@ -37,7 +37,7 @@ class ProductRequest extends FormRequest
37 { 37 {
38 return [ 38 return [
39 'title' => 'required|max:200', 39 'title' => 'required|max:200',
40 - 'route' => 'required|max:100', 40 + 'route' => 'required|max:200',
41 'gallery' => ['required', 'array', function ($attribute, $value, $fail) { 41 'gallery' => ['required', 'array', function ($attribute, $value, $fail) {
42 foreach ($value as $v) { 42 foreach ($value as $v) {
43 if (empty($v['url'])) { 43 if (empty($v['url'])) {
@@ -88,7 +88,7 @@ class ProductRequest extends FormRequest @@ -88,7 +88,7 @@ class ProductRequest extends FormRequest
88 'title.required' => '请输入产品标题', 88 'title.required' => '请输入产品标题',
89 'title.max' => '产品标题不能超过20个字符', 89 'title.max' => '产品标题不能超过20个字符',
90 'route.required' => '请输入产品链接', 90 'route.required' => '请输入产品链接',
91 - 'route.max' => '产品链接不能超过100个字符', 91 + 'route.max' => '产品链接不能超过200个字符',
92 'gallery.required' => '请上传产品图片', 92 'gallery.required' => '请上传产品图片',
93 'gallery.array' => '产品图片格式异常', 93 'gallery.array' => '产品图片格式异常',
94 'attrs.required' => '请添加产品参数', 94 'attrs.required' => '请添加产品参数',
@@ -4,6 +4,7 @@ namespace App\Models\Product; @@ -4,6 +4,7 @@ namespace App\Models\Product;
4 4
5 use App\Helper\Arr; 5 use App\Helper\Arr;
6 use App\Models\Base; 6 use App\Models\Base;
  7 +use App\Models\RouteMap;
7 use App\Services\Facades\Upload; 8 use App\Services\Facades\Upload;
8 use Illuminate\Database\Eloquent\SoftDeletes; 9 use Illuminate\Database\Eloquent\SoftDeletes;
9 10
@@ -18,6 +19,7 @@ class Product extends Base @@ -18,6 +19,7 @@ class Product extends Base
18 const STATUS_ON = 1; 19 const STATUS_ON = 1;
19 const STATUS_RECYCLE = 2; 20 const STATUS_RECYCLE = 2;
20 21
  22 + protected $appends = ['route'];
21 23
22 public static function statusMap(){ 24 public static function statusMap(){
23 return [ 25 return [
@@ -117,4 +119,8 @@ class Product extends Base @@ -117,4 +119,8 @@ class Product extends Base
117 return Arr::setToArr($value); 119 return Arr::setToArr($value);
118 } 120 }
119 121
  122 + public function getRouteAttribute(){
  123 + return RouteMap::getRoute(RouteMap::SOURCE_PRODUCT, $this->id, $this->project_id);
  124 + }
  125 +
120 } 126 }
@@ -188,6 +188,11 @@ Route::middleware(['bloginauth'])->group(function () { @@ -188,6 +188,11 @@ Route::middleware(['bloginauth'])->group(function () {
188 Route::get('/info', [\App\Http\Controllers\Bside\InquiryController::class, 'info'])->name('inquiry_info'); 188 Route::get('/info', [\App\Http\Controllers\Bside\InquiryController::class, 'info'])->name('inquiry_info');
189 Route::any('/delete', [\App\Http\Controllers\Bside\InquiryController::class, 'delete'])->name('inquiry_delete'); 189 Route::any('/delete', [\App\Http\Controllers\Bside\InquiryController::class, 'delete'])->name('inquiry_delete');
190 }); 190 });
  191 +
  192 + //生成路由
  193 + Route::prefix('route')->group(function () {
  194 + Route::any('/create', [\App\Http\Controllers\Bside\RouteController::class, 'create'])->name('create_route');
  195 + });
191 }); 196 });
192 197
193 //无需登录验证的路由组 198 //无需登录验证的路由组
@@ -196,7 +201,4 @@ Route::group([], function () { @@ -196,7 +201,4 @@ Route::group([], function () {
196 Route::any('/', [\App\Http\Controllers\Bside\ComController::class, 'get_country'])->name('get_country'); 201 Route::any('/', [\App\Http\Controllers\Bside\ComController::class, 'get_country'])->name('get_country');
197 Route::get('/file/download', [\App\Http\Controllers\Bside\FileController::class, 'download'])->name('file_download'); 202 Route::get('/file/download', [\App\Http\Controllers\Bside\FileController::class, 'download'])->name('file_download');
198 Route::any('/image/{hash}/{w?}/{h?}', [\App\Http\Controllers\ImageController::class,'index'])->name('image_show'); 203 Route::any('/image/{hash}/{w?}/{h?}', [\App\Http\Controllers\ImageController::class,'index'])->name('image_show');
199 -  
200 - //添加询盘信息  
201 - Route::post('/inquiry/save', [\App\Http\Controllers\Bside\InquiryController::class, 'save'])->name('inquiry_save');  
202 }); 204 });