作者 刘锟

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

... ... @@ -74,15 +74,15 @@ class ProjectFilePDF extends Command
public function dataPush(array $items)
{
foreach ($items as $item) {
$project_id = $item->project_id;
$application_id = $item->wx_id;
$wx_user_id = $item->wx_user_id;
$project_id = $item->project_id;
$user_id = $item->user_id;
$friend_id = $item->friend_id;
// todo 根据项目查询数据
$project_data = [];
$html = $this->html($project_data);
$filename = hash('md5', $this->time . '-' . $project_id . '-' . $application_id);
$filename = hash('md5', $this->time . '-' . $project_id . '-' . $friend_id . '-' . $user_id);
$file_path = $this->savePDF($html, $filename);
$this->DataFile->saveData(compact('project_id', 'application_id', 'file_path') + ['time' => $this->time]);
$this->DataFile->saveData(compact('project_id', 'user_id', 'friend_id', 'file_path') + ['time' => $this->time]);
}
}
... ...
... ... @@ -58,7 +58,8 @@ class WebsiteData extends Command
public function post_data($data)
{
$url = env('AICC_URL');
return http_post("{$url}/api/save_file_data", json_encode(compact('data')));
$msg = http_post("{$url}/api/save_file_data", json_encode(compact('data')));
print_r($msg);
}
}
... ...
... ... @@ -116,7 +116,13 @@ class NavController extends BaseController
* @author zbj
* @date 2023/11/21
*/
public function import(){
public function import(NavLogic $navLogic){
$this->request->validate([
'id'=>'required',
],[
'id.required' => 'ID不能为空',
]);
$navLogic->importNav();
$this->response('success');
}
}
... ...
... ... @@ -92,10 +92,11 @@ class KeywordController extends BaseController
*/
public function batchAdd(KeywordLogic $logic){
$this->request->validate([
'title'=>['required','array']
'title'=>['required','array', 'max:1000']
],[
'title.required' => 'title不能为空',
'title.array' => 'title为数组'
'title.array' => 'title为数组',
'title.max' => '批量操作不能超过1000条数据'
]);
$logic->batchAdd();
$this->response('success');
... ... @@ -119,4 +120,22 @@ class KeywordController extends BaseController
$this->response('success');
}
/**
* 批量删除
* @param KeywordLogic $logic
* @author zbj
* @date 2023/11/22
*/
public function batchDel(KeywordLogic $logic){
$this->request->validate([
'title'=>['required','array', 'max:1000']
],[
'title.required' => 'title不能为空',
'title.array' => 'title为数组',
'title.max' => '批量操作不能超过1000条数据'
]);
$logic->batchDel();
$this->response('success');
}
}
... ...
... ... @@ -31,19 +31,20 @@ class ProjectAssociationController extends BaseController
if (empty($project_id)) {
$this->fail('请选择项目!', Code::USER_PARAMS_ERROE);
}
$status = (bool)request()->post('status', 1); # 1 - 正常, 0 - 禁用
$wx_user_id = (int)request()->post('user_id', 0);
if (empty($wx_user_id) && $status) {
$status = (bool)request()->post('status', 1); # 1 - 正常, 0 - 禁用
$user_id = (int)request()->post('user_id', 0);
if (empty($user_id) && $status) {
$this->fail('请选择要绑定的AICC用户!', Code::USER_PARAMS_ERROE);
}
$wx_id = (int)request()->post('wx_id', 0);
if (empty($wx_id) && $status) {
$this->fail('请选择要绑定的AICC项目!', Code::USER_PARAMS_ERROE);
$friend_id = (int)request()->post('friend_id', 0);
if (empty($friend_id) && $status) {
$this->fail('请选择要绑定的AICC用户列表!', Code::USER_PARAMS_ERROE);
}
$wx_nickname = request()->post('nickname', '');
$wx_user_name = request()->post('user_name', '');
$wx_image = request()->post('image', '');
$data = compact('project_id', 'wx_id', 'wx_nickname', 'wx_user_id', 'wx_user_name', 'wx_image');
$nickname = request()->post('nickname', '');
$user_name = request()->post('user_name', '');
$image = request()->post('image', '');
$data = compact('project_id', 'user_id', 'friend_id', 'nickname', 'user_name', 'image');
$this->ProjectAssociationLogic->saveWeChatData($data);
$this->response('success');
}
... ...
... ... @@ -28,11 +28,11 @@ class BTemplateModuleController extends BaseController
}
$data = [];
$list = $BTemplateModuleLogic->ModuleList($this->map,$this->order);
// $data['list'] = $list;
// $moduleProjectModel = new BModuleProject();
// $module_list = $moduleProjectModel->list(['project_id'=>$this->user['project_id']]);
// $data['module_list'] = $module_list;
$this->response('success',Code::SUCCESS,$list);
$data['list'] = $list;
$moduleProjectModel = new BModuleProject();
$module_list = $moduleProjectModel->list(['project_id'=>$this->user['project_id']]);
$data['module_list'] = $module_list;
$this->response('success',Code::SUCCESS,$data);
}
/**
... ...
... ... @@ -116,4 +116,79 @@ class NavLogic extends BaseLogic
}
return $this->success();
}
/**
* 一键导入 对应分类
* @throws \App\Exceptions\AsideGlobalException
* @throws \App\Exceptions\BsideGlobalException
*/
public function importNav(){
$nav = $this->getInfo($this->param['id']);
if(!in_array($nav['url'], array_keys(BNav::ableImportMap()))){
$this->fail('该菜单不支持一键导入');
}
$class = BNav::ableImportMap($nav['url']);
$category = new $class();
$fields = ['id', 'name', 'pid', 'alias'];
if($nav['url'] == 'products'){
$fields = ['id', 'title as name', 'pid', 'route as alias'];
}
$this->addByPid($category, $nav, $fields);
return $this->success();
}
/**
* 一级一级的加
* @author zbj
* @date 2023/11/22
*/
protected function addByPid($category, $nav, $fields, $pid = 0)
{
$nav_pid = $nav['id'];
if($pid){
$p_cate = $category->where('id', $pid)->select($fields)->first();
if($p_cate){
$nav_pid = $this->model->where('import_id', $nav['id'])->where('url', $p_cate['alias'])->value('id');
}
}
$list = $category->list(['pid' => $pid], 'id', $fields, 'asc');
$data = [];
$time = date('Y-m-d H:i:s');
foreach ($list as $item) {
$exists_info = $this->model->where('import_id', $nav['id'])->where('url', $item['alias'])->first();
if($exists_info){
continue;
}
$data[] = [
'pid' => $nav_pid,
'name' => $item['name'],
'url' => $item['alias'],
'project_id' => $this->project['id'],
'location' => $nav['location'],
'group_id' => $nav['group_id'],
'status' => BNav::STATUS_ACTIVE,
'import_id' => $nav['id'],
'created_at' => $time,
'updated_at' => $time,
];
}
//每500条更一次
$data_chunk = array_chunk($data,500);
foreach ($data_chunk as $chunk){
$this->model->insert($chunk);
}
foreach ($list as $item) {
$this->addByPid($category, $nav, $fields, $item['id']);
}
}
}
... ...
... ... @@ -6,6 +6,7 @@ use App\Exceptions\BsideGlobalException;
use App\Helper\Arr;
use App\Helper\Common;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\News\News;
use App\Models\Product\Keyword;
use App\Models\Product\KeywordRelated;
use App\Models\Product\Product;
... ... @@ -38,6 +39,8 @@ class KeywordLogic extends BaseLogic
{
$info = $this->model->read($this->param);
$info['url'] = $this->user['domain'] . $info['route'];
$info['related_news_info'] = News::whereIn('id', $info['related_news_ids'])->select(['id', 'name'])->get();
return $this->success($info);
}
... ... @@ -209,4 +212,29 @@ class KeywordLogic extends BaseLogic
Common::del_user_cache('product_keyword',$project_id);
return ','.implode(',',$return).',';
}
/**
* 批量删除
* @return array
* @throws BsideGlobalException
* @throws \App\Exceptions\AsideGlobalException
* @author zbj
* @date 2023/11/22
*/
public function batchDel(){
try {
foreach ($this->param['title'] as $v){
$info = $this->model->read(['title'=>$v]);
if($info){
$this->delRoute($info['id']);
$this->model->del(['id'=>$info['id']]);
}
}
//清除缓存
Common::del_user_cache('product_keyword',$this->user['project_id']);
}catch (\Exception $e){
$this->fail('error');
}
return $this->success();
}
}
... ...
... ... @@ -10,14 +10,19 @@ class DataFile extends Base
public function saveData(array $data): bool
{
# v6项目ID
$project_id = (int)$data['project_id'] ?? 0;
$isRes = self::query()->where('project_id', $project_id)->where('created_at', 'like', $data['time'] . '%')->first();
if (!$isRes) {
$isRes = new self();
$isRes->project_id = $project_id;
}
$isRes->file_path = $data['file_path'];
$isRes->application_id = $data['application_id'];
# AICC用户ID
$isRes->user_id = $data['user_id'];
# 第三方朋友ID
$isRes->friend_id = $data['friend_id'];
# 生成文件路径
$isRes->file_path = $data['file_path'];
return $isRes->save();
}
... ...
... ... @@ -35,6 +35,21 @@ class BNav extends Base
const STATUS_DISABLED = 0;
/**
* @author zbj
* @date 2023/11/22
*/
public static function ableImportMap($url=''){
$map = [
'products' => '\\App\\Models\\Product\\Category',
'news' => '\\App\\Models\\News\\NewsCategory',
'blog' => '\\App\\Models\\Blog\\BlogCategory',
];
if ($url){
return $map[$url] ?:"";
}
return $map;
}
/**
... ... @@ -85,7 +100,7 @@ class BNav extends Base
*/
public function getAbleImportAttribute($value)
{
if(in_array($this->url, ['products','news','blogs'])){
if(in_array($this->url, array_keys(self::ableImportMap()))){
return 1;
}
return 0;
... ...
... ... @@ -67,7 +67,7 @@ class Keyword extends Base
if(!empty($value)){
$value = Arr::setToArr($value);
}
return $value;
return $value ?: [];
}
/**
... ... @@ -80,6 +80,6 @@ class Keyword extends Base
if(!empty($value)){
$value = Arr::setToArr($value);
}
return $value;
return $value ?: [];
}
}
... ...
... ... @@ -16,17 +16,23 @@ class ProjectAssociation extends Model
*/
public function saveData(array $data): bool
{
# V6项目ID
$project_id = (int)$data['project_id'] ?? 0;
$isRes = self::query()->where('project_id', $project_id)->first();
if (!$isRes) {
$isRes = new self();
$isRes->project_id = $project_id;
}
$isRes->wx_id = $data['wx_id'];
$isRes->wx_nickname = $data['wx_nickname'];
$isRes->wx_user_id = $data['wx_user_id'];
$isRes->wx_user_name = $data['wx_user_name'];
$isRes->wx_image = $data['wx_image'];
# AICC朋友ID
$isRes->friend_id = $data['friend_id'] ?? 0;
# AICC朋友昵称
$isRes->nickname = $data['nickname'] ?? 0;
# AICC用户ID
$isRes->user_id = $data['user_id'] ?? 0;
# AICC用户姓名
$isRes->user_name = $data['user_name'] ?? '';
# AICC朋友头像
$isRes->image = $data['image'] ?? '';
return $isRes->save();
}
... ... @@ -50,8 +56,9 @@ class ProjectAssociation extends Model
$status = 1; # 1 - 正常, 0 - 禁用
$lists = self::query()->where('status', $status)
->whereNotNull('project_id')
->whereNotNull('wx_user_id')
->paginate($perPage, ['project_id', 'wx_id', 'wx_user_id'], 'page', $page);
->whereNotNull('friend_id')
->whereNotNull('user_id')
->paginate($perPage, ['project_id', 'friend_id', 'user_id'], 'page', $page);
$items = $lists->Items();
$totalPage = $lists->lastPage();
$total = $lists->total();
... ...
... ... @@ -219,6 +219,7 @@ Route::middleware(['bloginauth'])->group(function () {
Route::get('keyword/info', [\App\Http\Controllers\Bside\Product\KeywordController::class, 'info'])->name('product_keyword_info');
Route::post('keyword/save', [\App\Http\Controllers\Bside\Product\KeywordController::class, 'save'])->name('product_keyword_save');
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');
//产品参数
... ... @@ -365,6 +366,7 @@ Route::middleware(['bloginauth'])->group(function () {
Route::delete('/delete', [\App\Http\Controllers\Bside\Nav\NavController::class, 'delete'])->name('nav_delete');
Route::get('/default-urls', [\App\Http\Controllers\Bside\Nav\NavController::class, 'urls'])->name('nav_default-urls');
Route::post('/sort', [\App\Http\Controllers\Bside\Nav\NavController::class, 'sort'])->name('nav_sort');
Route::post('/import', [\App\Http\Controllers\Bside\Nav\NavController::class, 'import'])->name('nav_import');
});
//排名数据
... ...