|
...
|
...
|
@@ -136,17 +136,16 @@ class KeywordLogic extends BaseLogic |
|
|
|
* @time :2023/8/28 14:03
|
|
|
|
*/
|
|
|
|
public function batchAdd(){
|
|
|
|
// $route_array = Translate::tran($this->param['title'], 'en');
|
|
|
|
// if (empty($route_array)) {
|
|
|
|
// $this->fail('路由生成失败,请稍后重试!');
|
|
|
|
// }
|
|
|
|
$route_array = Translate::tran($this->param['title'], 'en');
|
|
|
|
if (empty($route_array)) {
|
|
|
|
$this->fail('路由生成失败,请稍后重试!');
|
|
|
|
}
|
|
|
|
$num = count($this->param['title']);
|
|
|
|
if($num > 1000){
|
|
|
|
$this->fail('最大数量不能超过1000');
|
|
|
|
}
|
|
|
|
foreach ($this->param['title'] as $k=>$v) {
|
|
|
|
DB::connection('custom_mysql')->beginTransaction();
|
|
|
|
try {
|
|
|
|
$data = [];
|
|
|
|
if (empty($v)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
...
|
...
|
@@ -160,17 +159,14 @@ class KeywordLogic extends BaseLogic |
|
|
|
$param['updated_at'] = $param['created_at'];
|
|
|
|
$param['title'] = $v;
|
|
|
|
$id = $this->model->insertGetId($param);
|
|
|
|
$route = RouteMap::setRoute($v, RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $this->user['project_id']);
|
|
|
|
$data[$k] = $id;
|
|
|
|
}
|
|
|
|
foreach ($data as $k=>$ids){
|
|
|
|
$route = RouteMap::setRoute($route_array[$k], RouteMap::SOURCE_PRODUCT_KEYWORD, $ids, $this->user['project_id']);
|
|
|
|
if (empty($route)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$this->model->edit(['route' => $route], ['id' => $id]);
|
|
|
|
DB::connection('custom_mysql')->commit();
|
|
|
|
}catch (\Exception $e){
|
|
|
|
$this->fail('系统错误请联系管理员');
|
|
|
|
DB::connection('custom_mysql')->rollBack();
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->model->edit(['route' => $route], ['id' => $ids]);
|
|
|
|
}
|
|
|
|
return $this->success();
|
|
|
|
}
|
...
|
...
|
|