作者 刘锟

Merge remote-tracking branch 'origin/master' into akun

... ... @@ -257,4 +257,23 @@ class KeywordController extends BaseController
$id = $keywordPageModel->addReturnId($this->param);
$this->response('success',Code::SUCCESS,['id'=>$id]);
}
/**
* @remark :删除关联关系
* @name :delRelated
* @author :lyh
* @method :post
* @time :2024/11/28 10:30
*/
public function delRelated(KeywordLogic $logic){
$this->request->validate([
'keyword_id'=>'required',
'product_id'=>'required',
],[
'keyword_id.required' => '关键词id不能为空',
'product_id.required' => '产品id不为空',
]);
$logic->delRelated($this->param['keyword'],$this->param['product_id']);
$this->response('success');
}
}
... ...
... ... @@ -69,13 +69,11 @@ class EmailController extends BaseController
public function set_smtp(Smtp $smtp)
{
$this->request->validate([
'project_id' => ['required'],
'email' => ['required', 'email', 'max:200'],
'password' => ['required', 'max:200'],
'host' => ['required', 'max:200', 'regex:/[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+\.?/'],
'from_name' => ['required', 'max:200'],
], [
'project_id.required' => '参数异常',
'email.required' => '邮箱必须',
'email.email' => '邮箱格式错误',
'password.required' => '授权码/密码必须',
... ... @@ -83,7 +81,7 @@ class EmailController extends BaseController
'host.regex' => 'smtp格式错误',
'from_name.required' => '发信人昵称必须',
]);
$info = $smtp->read(['project_id' => $this->param['project_id']]);
$info = $smtp->read(['project_id' => $this->project['id']]);
if (!$info) {
$smtp->add($this->param);
} else {
... ... @@ -92,6 +90,11 @@ class EmailController extends BaseController
$this->response('success');
}
public function get_smtp(Smtp $smtp){
$info = $smtp->read(['project_id' => $this->project['id']]);
$this->response($info);
}
public function group_send(GroupSendTask $groupSendTask)
{
$this->request->validate([
... ...
... ... @@ -42,6 +42,7 @@ class KeywordLogic extends BaseLogic
if($info !== false){
$info['url'] = $this->user['domain'] . $info['route'];
$info['related_news_info'] = News::whereIn('id', $info['related_news_ids'])->select(['id', 'name'])->get();
$info['product_list'] = $this->getProduct($info['id']);
}
return $this->success($info);
}
... ... @@ -298,4 +299,41 @@ class KeywordLogic extends BaseLogic
}
return $this->success();
}
/**
* @remark :根据关键字获取产品
* @name :getProduct
* @author :lyh
* @method :post
* @time :2024/11/28 9:26
*/
public function getProduct($keyword_id){
$productList = [];
$keywordRelatedModel = new KeywordRelated();
$productIdArr = $keywordRelatedModel->selectField(['keyword_id'=>$keyword_id],'product_id');
if(!empty($productIdArr)){
$productModel = new Product();
$productList = $productModel->list(['id'=>['in',$productIdArr]],['id','title']);
}
return $this->success($productList);
}
/**
* @remark :对应删除关联关系
* @name :delRelated
* @author :lyh
* @method :post
* @time :2024/11/28 9:46
*/
public function delRelated($keyword_id,$product_id){
$productModel = new Product();
$productModel->where('id', $product_id)
->update(['keyword_id' => DB::raw("REPLACE(keyword_id, ',$keyword_id,' , ',')"),'keyword_video_id' => DB::raw("REPLACE(keyword_video_id, ',$keyword_id,' , ',')")]);
$productModel->where('id', $product_id)->where('keyword_id',',')->orWhere('keyword_video_id',',')
->update(['keyword_id' => DB::raw("REPLACE(keyword_id, ',' , '')"),'keyword_video_id' => DB::raw("REPLACE(keyword_video_id, ',' , '')")]);
$keywordRelatedModel = new KeywordRelated();
$keywordRelatedModel->del(['product_id'=>$product_id,'keyword_id'=>$keyword_id]);
return $this->success();
}
}
... ...
... ... @@ -43,6 +43,7 @@ class ProductLogic extends BaseLogic
$extend = $this->handleExtent();
//单独处理分类
$category_ids = $this->handleCategory();
$keyword_arr = $this->param['keyword_id'] ?? [];
//处理其他字段
$this->param = $this->handleSaveParam($this->param);
try {
... ... @@ -66,7 +67,7 @@ class ProductLogic extends BaseLogic
}
//产品分类关联
CategoryRelated::saveRelated($id, $category_ids);
KeywordRelated::saveRelated($id,$category_ids);
KeywordRelated::saveRelated($id,$keyword_arr);
//更新产品新描述
$detailLogic = new DetailLogic();
$detailLogic->saveDetail($id,$this->param['data'] ?? []);
... ...
... ... @@ -53,33 +53,6 @@ class QueryListener
$log = $log.' [ RunTime:'.$event->time.'ms ] ';
Log::debug($log);
}
//监听api_no是TM咋个被改的
if (Str::contains($event->sql, 'update') && Str::contains($event->sql, '`api_no` =')) {
//记录debug 根据这个溯源
$trace = debug_backtrace();
$traces = [];
foreach ($trace as $index => $caller) {
if ($index === 0) {
continue; // 跳过当前方法的调用信息
}
$file = $caller['file'];
$line = $caller['line'];
$class = $caller['class'];
$method = $caller['function'];
$traces[] = "Method $method called from $class in file $file at line $line\n";
}
//用户信息 哪个改的 还是脚本跑的
$token = request()->header('token');
Log::channel('test')->info('api_no updated', [
'sql' => $event->sql,
'bindings' => $event->bindings,
'route' => Route::current(),
'request' => request()->all(),
'a_info' => Cache::get(Common::MANAGE_TOKEN . $token),
'b_info' => Cache::get($token),
'trace' => $traces
]);
}
}catch (\Exception $exception){
Log::error('log sql error:'.$exception->getMessage());
}
... ...
... ... @@ -296,4 +296,5 @@ class Base extends Model
$data = $this->filterRequestData($data);
return $this->formatQuery($data)->pluck($filed)->toArray();
}
}
... ...
... ... @@ -281,6 +281,7 @@ Route::middleware(['bloginauth'])->group(function () {
Route::post('keyword/batchAdd', [\App\Http\Controllers\Bside\Product\KeywordController::class, 'batchAdd'])->name('product_keyword_batchAdd');
Route::post('keyword/batchDel', [\App\Http\Controllers\Bside\Product\KeywordController::class, 'batchDel'])->name('product_keyword_batchDel');
Route::any('keyword/delete', [\App\Http\Controllers\Bside\Product\KeywordController::class, 'delete'])->name('product_keyword_delete');
Route::any('keyword/delRelated', [\App\Http\Controllers\Bside\Product\KeywordController::class, 'delRelated'])->name('product_keyword_delRelated');
Route::any('keyword/batchUpdateKeyword', [\App\Http\Controllers\Bside\Product\KeywordController::class, 'batchUpdateKeyword'])->name('product_keyword_batchUpdateKeyword');
Route::any('keyword/batchKeywordIsVideo', [\App\Http\Controllers\Bside\Product\KeywordController::class, 'batchKeywordIsVideo'])->name('product_keyword_batchKeywordIsVideo');
Route::any('keyword/batchKeywordFiled', [\App\Http\Controllers\Bside\Product\KeywordController::class, 'batchKeywordFiled'])->name('product_keyword_batchKeywordFiled');
... ... @@ -632,6 +633,7 @@ Route::middleware(['bloginauth'])->group(function () {
Route::any('/del', [\App\Http\Controllers\Bside\Subscribe\EmailController::class, 'delete'])->name('subscribe_email_del');
Route::any('/export', [\App\Http\Controllers\Bside\Subscribe\EmailController::class, 'export'])->name('subscribe_email_export');
Route::any('/set_smtp', [\App\Http\Controllers\Bside\Subscribe\EmailController::class, 'set_smtp'])->name('subscribe_email_set_smtp');
Route::any('/get_smtp', [\App\Http\Controllers\Bside\Subscribe\EmailController::class, 'get_smtp'])->name('subscribe_email_get_smtp');
Route::any('/group_send', [\App\Http\Controllers\Bside\Subscribe\EmailController::class, 'group_send'])->name('subscribe_email_group_send');
});
... ...