|
|
@ -1128,8 +1128,13 @@ class ContentController extends BaseController |
|
|
$reqParam = request()->param(); |
|
|
$reqParam = request()->param(); |
|
|
$from_cate_id = $reqParam['from_cate_id']; |
|
|
$from_cate_id = $reqParam['from_cate_id']; |
|
|
$to_cate_id = $reqParam['to_cate_id']; |
|
|
$to_cate_id = $reqParam['to_cate_id']; |
|
|
var_dump($reqParam); |
|
|
|
|
|
exit(); |
|
|
|
|
|
|
|
|
if($from_cate_id == -1 && $to_cate_id == -1){ |
|
|
|
|
|
// 迁移数据 交易及市场日历(calendar)
|
|
|
|
|
|
$res = $this->dealDataToNewCalendar($reqParam); |
|
|
|
|
|
return $res; |
|
|
|
|
|
} |
|
|
|
|
|
// var_dump($reqParam);
|
|
|
|
|
|
// exit();
|
|
|
// var_dump($reqParam);exit;
|
|
|
// var_dump($reqParam);exit;
|
|
|
// 直接定义目标数据库连接参数
|
|
|
// 直接定义目标数据库连接参数
|
|
|
$otherDbConfig = [ |
|
|
$otherDbConfig = [ |
|
|
@ -1283,5 +1288,168 @@ class ContentController extends BaseController |
|
|
var_dump('操作的条数为: ', $opNum); |
|
|
var_dump('操作的条数为: ', $opNum); |
|
|
exit; |
|
|
exit; |
|
|
} |
|
|
} |
|
|
|
|
|
// 交易及市场日历(calendar)
|
|
|
|
|
|
public function dealDataToNewCalendar($reqParam) |
|
|
|
|
|
{ |
|
|
|
|
|
// $reqParam = $reqParam;
|
|
|
|
|
|
// $from_cate_id = $reqParam['from_cate_id'];
|
|
|
|
|
|
// $to_cate_id = $reqParam['to_cate_id'];
|
|
|
|
|
|
$to_cate_id = 215; |
|
|
|
|
|
// var_dump($reqParam);
|
|
|
|
|
|
// exit();
|
|
|
|
|
|
// var_dump($reqParam);exit;
|
|
|
|
|
|
// 直接定义目标数据库连接参数
|
|
|
|
|
|
$otherDbConfig = [ |
|
|
|
|
|
'type' => 'mysql', |
|
|
|
|
|
'hostname' => '192.168.217.131', // 目标IP
|
|
|
|
|
|
'database' => 'changcheng_mylinux', // 数据库名
|
|
|
|
|
|
'username' => 'root', |
|
|
|
|
|
'password' => '6sNcy4H8Ss6YB3Rh', |
|
|
|
|
|
'hostport' => '13306', |
|
|
|
|
|
'charset' => 'utf8mb4', |
|
|
|
|
|
'prefix' => '', |
|
|
|
|
|
'debug' => true, |
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
// 动态注册到 connections 中
|
|
|
|
|
|
$dbConfig = config('database'); |
|
|
|
|
|
$dbConfig['connections']['temp_remote_conn'] = $otherDbConfig; |
|
|
|
|
|
config($dbConfig, 'database'); |
|
|
|
|
|
// 验证分类
|
|
|
|
|
|
// $fromCateInfo = Db::connect('temp_remote_conn')
|
|
|
|
|
|
// ->table('yy_module_article_category')
|
|
|
|
|
|
// ->where('state', 1)
|
|
|
|
|
|
// ->where('id', $from_cate_id)
|
|
|
|
|
|
// ->findOrEmpty();
|
|
|
|
|
|
//
|
|
|
|
|
|
// if(empty($fromCateInfo)){
|
|
|
|
|
|
// var_dump('$fromCateInfo 不存在');
|
|
|
|
|
|
// exit();
|
|
|
|
|
|
// }
|
|
|
|
|
|
// $toCateInfo = Db::table('hc_category')
|
|
|
|
|
|
// ->where('id', $to_cate_id)->findOrEmpty();
|
|
|
|
|
|
// if(empty($toCateInfo)){
|
|
|
|
|
|
// var_dump('$toCateInfo 不存在');
|
|
|
|
|
|
// exit();
|
|
|
|
|
|
// }
|
|
|
|
|
|
// if($fromCateInfo['title'] != $toCateInfo['title']){
|
|
|
|
|
|
// var_dump('分类名称不对应');
|
|
|
|
|
|
// exit();
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// 通过连接名使用
|
|
|
|
|
|
$listTmp = Db::connect('temp_remote_conn') |
|
|
|
|
|
->table('yy_module_article') |
|
|
|
|
|
->where('state', 1) |
|
|
|
|
|
->where('category_id', 0) |
|
|
|
|
|
->where('channel_id', 25) // calendar 交易及市场日历
|
|
|
|
|
|
// ->limit(3)
|
|
|
|
|
|
->select(); |
|
|
|
|
|
if(empty($listTmp)){ |
|
|
|
|
|
var_dump('数据为空!'); |
|
|
|
|
|
exit; |
|
|
|
|
|
} |
|
|
|
|
|
$listArr = $listTmp->toArray(); |
|
|
|
|
|
// var_dump($listTmp->toArray());
|
|
|
|
|
|
// exit();
|
|
|
|
|
|
if(empty($listArr)){ |
|
|
|
|
|
var_dump('数据为空!'); |
|
|
|
|
|
exit; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$opNum = 0; |
|
|
|
|
|
foreach ($listArr as $k=>$oneOrigin){ |
|
|
|
|
|
$param = []; |
|
|
|
|
|
// 手动拼接参数 $param
|
|
|
|
|
|
$param['module_id'] = 1; |
|
|
|
|
|
$param['category_id'][0] = $to_cate_id; // 分类ID
|
|
|
|
|
|
$param['lang'] = 'zh'; |
|
|
|
|
|
$param['main_content']['sub_title'] = ''; |
|
|
|
|
|
$param['main_content']['more_file'] = ''; |
|
|
|
|
|
|
|
|
|
|
|
$param['sub_content']['title'] = $oneOrigin['title']; |
|
|
|
|
|
$param['sub_content']['sub_title'] = ''; |
|
|
|
|
|
$param['sub_content']['detail_tpl'] = ''; |
|
|
|
|
|
$param['sub_content']['description'] = ''; |
|
|
|
|
|
$param['sub_content']['thumbnail'] = 0; // 缩略图
|
|
|
|
|
|
$param['sub_content']['cover'] = ''; |
|
|
|
|
|
$param['sub_content']['hits'] = $oneOrigin['views']; // 浏览量
|
|
|
|
|
|
$param['sub_content']['author'] = ''; |
|
|
|
|
|
$param['sub_content']['status'] = ''; |
|
|
|
|
|
$param['sub_content']['url'] = ''; |
|
|
|
|
|
$param['sub_content']['is_top'] = ''; |
|
|
|
|
|
$param['sub_content']['is_recommend'] = ''; |
|
|
|
|
|
$param['sub_content']['sort'] = ''; |
|
|
|
|
|
$param['sub_content']['seo_title'] = ''; |
|
|
|
|
|
$param['sub_content']['seo_keyword'] = ''; |
|
|
|
|
|
$param['sub_content']['seo_description'] = ''; |
|
|
|
|
|
$param['sub_content']['tag'] = ''; // 标签
|
|
|
|
|
|
$param['sub_content']['publish_time'] = ''; |
|
|
|
|
|
$param['sub_content']['content'] = $oneOrigin['content']; // 富文本内容
|
|
|
|
|
|
$param['sub_content']['category_id'] = $to_cate_id; // 分类ID
|
|
|
|
|
|
$param['sub_content']['sub_category_ids'] = ''; //
|
|
|
|
|
|
if(!empty($oneOrigin['image_url'])){ |
|
|
|
|
|
$fullName = basename($oneOrigin['image_url']); // 16a67b...png
|
|
|
|
|
|
$ext = explode('.', $fullName); |
|
|
|
|
|
$extension = end($ext); // 结果:png
|
|
|
|
|
|
$filename = substr($fullName, 0, strrpos($fullName, '.')); |
|
|
|
|
|
// 将图片资源插入数据库
|
|
|
|
|
|
$fileData = [ |
|
|
|
|
|
'seller_id'=>1, |
|
|
|
|
|
'name'=>$filename, |
|
|
|
|
|
'attachment_cate_id'=>0, |
|
|
|
|
|
'url'=>$oneOrigin['image_url'], |
|
|
|
|
|
'mime_type'=>$extension, |
|
|
|
|
|
]; |
|
|
|
|
|
$fileID = Db::table('hc_attachment') |
|
|
|
|
|
->insertGetId($fileData); |
|
|
|
|
|
$param['sub_content']['thumbnail'] = $fileID; // 缩略图
|
|
|
|
|
|
} |
|
|
|
|
|
if(!empty($oneOrigin['create_time'])){ |
|
|
|
|
|
$param['sub_content']['publish_time'] = date('Y-m-d H:i:s',$oneOrigin['create_time']); |
|
|
|
|
|
} |
|
|
|
|
|
try{ |
|
|
|
|
|
validate(ContentValidate::class)->scene('save')->check($param); |
|
|
|
|
|
}catch (ValidateException $e){ |
|
|
|
|
|
return jsonReturn(422, $e->getError()); |
|
|
|
|
|
} |
|
|
|
|
|
$param['admin'] = $this->admin; |
|
|
|
|
|
unset($param['main_content']['id']);//添加接口以防冲突不需要id
|
|
|
|
|
|
unset($param['sub_content']['id']);//添加接口以防冲突不需要id
|
|
|
|
|
|
if(empty($param['sub_content']['publish_time'])){ |
|
|
|
|
|
$param['sub_content']['publish_time'] = date('Y-m-d H:i:s',time()); |
|
|
|
|
|
} |
|
|
|
|
|
if(!isset($param['main_content'])){ |
|
|
|
|
|
$param['main_content'] = []; |
|
|
|
|
|
} |
|
|
|
|
|
$contentService = new ContentService(); |
|
|
|
|
|
try { |
|
|
|
|
|
$res = $contentService->saveContent($param); |
|
|
|
|
|
// 更改创建时间 ================= START
|
|
|
|
|
|
$newSubContentID = $res['id'] ?? '0'; |
|
|
|
|
|
if($newSubContentID <= 0){ |
|
|
|
|
|
var_dump('ID为空, 新增失败'); |
|
|
|
|
|
exit(); |
|
|
|
|
|
} |
|
|
|
|
|
if(!empty($oneOrigin['create_time'])){ |
|
|
|
|
|
Db::table('hc_sub_content') |
|
|
|
|
|
->where('id', $newSubContentID) |
|
|
|
|
|
->update(['status'=>1,'create_time' => $oneOrigin['create_time']]); |
|
|
|
|
|
|
|
|
|
|
|
Db::table('hc_article') |
|
|
|
|
|
->where('sub_id', $newSubContentID) |
|
|
|
|
|
->update(['create_time' => $oneOrigin['create_time']]); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 更改创建时间 ================= END
|
|
|
|
|
|
} catch (ModelEmptyException | ModelException $e) { |
|
|
|
|
|
return jsonReturn(-3,$e->getMessage()); |
|
|
|
|
|
} |
|
|
|
|
|
$opNum ++; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var_dump('操作的条数为: ', $opNum); |
|
|
|
|
|
exit; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |