作者 刘锟

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

@@ -74,15 +74,15 @@ class ProjectFilePDF extends Command @@ -74,15 +74,15 @@ class ProjectFilePDF extends Command
74 public function dataPush(array $items) 74 public function dataPush(array $items)
75 { 75 {
76 foreach ($items as $item) { 76 foreach ($items as $item) {
77 - $project_id = $item->project_id;  
78 - $application_id = $item->wx_id;  
79 - $wx_user_id = $item->wx_user_id; 77 + $project_id = $item->project_id;
  78 + $user_id = $item->user_id;
  79 + $friend_id = $item->friend_id;
80 // todo 根据项目查询数据 80 // todo 根据项目查询数据
81 $project_data = []; 81 $project_data = [];
82 $html = $this->html($project_data); 82 $html = $this->html($project_data);
83 - $filename = hash('md5', $this->time . '-' . $project_id . '-' . $application_id); 83 + $filename = hash('md5', $this->time . '-' . $project_id . '-' . $friend_id . '-' . $user_id);
84 $file_path = $this->savePDF($html, $filename); 84 $file_path = $this->savePDF($html, $filename);
85 - $this->DataFile->saveData(compact('project_id', 'application_id', 'file_path') + ['time' => $this->time]); 85 + $this->DataFile->saveData(compact('project_id', 'user_id', 'friend_id', 'file_path') + ['time' => $this->time]);
86 } 86 }
87 } 87 }
88 88
@@ -58,7 +58,8 @@ class WebsiteData extends Command @@ -58,7 +58,8 @@ class WebsiteData extends Command
58 public function post_data($data) 58 public function post_data($data)
59 { 59 {
60 $url = env('AICC_URL'); 60 $url = env('AICC_URL');
61 - return http_post("{$url}/api/save_file_data", json_encode(compact('data'))); 61 + $msg = http_post("{$url}/api/save_file_data", json_encode(compact('data')));
  62 + print_r($msg);
62 } 63 }
63 64
64 } 65 }
@@ -116,7 +116,13 @@ class NavController extends BaseController @@ -116,7 +116,13 @@ class NavController extends BaseController
116 * @author zbj 116 * @author zbj
117 * @date 2023/11/21 117 * @date 2023/11/21
118 */ 118 */
119 - public function import(){  
120 - 119 + public function import(NavLogic $navLogic){
  120 + $this->request->validate([
  121 + 'id'=>'required',
  122 + ],[
  123 + 'id.required' => 'ID不能为空',
  124 + ]);
  125 + $navLogic->importNav();
  126 + $this->response('success');
121 } 127 }
122 } 128 }
@@ -92,10 +92,11 @@ class KeywordController extends BaseController @@ -92,10 +92,11 @@ class KeywordController extends BaseController
92 */ 92 */
93 public function batchAdd(KeywordLogic $logic){ 93 public function batchAdd(KeywordLogic $logic){
94 $this->request->validate([ 94 $this->request->validate([
95 - 'title'=>['required','array'] 95 + 'title'=>['required','array', 'max:1000']
96 ],[ 96 ],[
97 'title.required' => 'title不能为空', 97 'title.required' => 'title不能为空',
98 - 'title.array' => 'title为数组' 98 + 'title.array' => 'title为数组',
  99 + 'title.max' => '批量操作不能超过1000条数据'
99 ]); 100 ]);
100 $logic->batchAdd(); 101 $logic->batchAdd();
101 $this->response('success'); 102 $this->response('success');
@@ -119,4 +120,22 @@ class KeywordController extends BaseController @@ -119,4 +120,22 @@ class KeywordController extends BaseController
119 $this->response('success'); 120 $this->response('success');
120 } 121 }
121 122
  123 + /**
  124 + * 批量删除
  125 + * @param KeywordLogic $logic
  126 + * @author zbj
  127 + * @date 2023/11/22
  128 + */
  129 + public function batchDel(KeywordLogic $logic){
  130 + $this->request->validate([
  131 + 'title'=>['required','array', 'max:1000']
  132 + ],[
  133 + 'title.required' => 'title不能为空',
  134 + 'title.array' => 'title为数组',
  135 + 'title.max' => '批量操作不能超过1000条数据'
  136 + ]);
  137 + $logic->batchDel();
  138 + $this->response('success');
  139 + }
  140 +
122 } 141 }
@@ -31,19 +31,20 @@ class ProjectAssociationController extends BaseController @@ -31,19 +31,20 @@ class ProjectAssociationController extends BaseController
31 if (empty($project_id)) { 31 if (empty($project_id)) {
32 $this->fail('请选择项目!', Code::USER_PARAMS_ERROE); 32 $this->fail('请选择项目!', Code::USER_PARAMS_ERROE);
33 } 33 }
34 - $status = (bool)request()->post('status', 1); # 1 - 正常, 0 - 禁用  
35 - $wx_user_id = (int)request()->post('user_id', 0);  
36 - if (empty($wx_user_id) && $status) { 34 + $status = (bool)request()->post('status', 1); # 1 - 正常, 0 - 禁用
  35 +
  36 + $user_id = (int)request()->post('user_id', 0);
  37 + if (empty($user_id) && $status) {
37 $this->fail('请选择要绑定的AICC用户!', Code::USER_PARAMS_ERROE); 38 $this->fail('请选择要绑定的AICC用户!', Code::USER_PARAMS_ERROE);
38 } 39 }
39 - $wx_id = (int)request()->post('wx_id', 0);  
40 - if (empty($wx_id) && $status) {  
41 - $this->fail('请选择要绑定的AICC项目!', Code::USER_PARAMS_ERROE); 40 + $friend_id = (int)request()->post('friend_id', 0);
  41 + if (empty($friend_id) && $status) {
  42 + $this->fail('请选择要绑定的AICC用户列表!', Code::USER_PARAMS_ERROE);
42 } 43 }
43 - $wx_nickname = request()->post('nickname', '');  
44 - $wx_user_name = request()->post('user_name', '');  
45 - $wx_image = request()->post('image', '');  
46 - $data = compact('project_id', 'wx_id', 'wx_nickname', 'wx_user_id', 'wx_user_name', 'wx_image'); 44 + $nickname = request()->post('nickname', '');
  45 + $user_name = request()->post('user_name', '');
  46 + $image = request()->post('image', '');
  47 + $data = compact('project_id', 'user_id', 'friend_id', 'nickname', 'user_name', 'image');
47 $this->ProjectAssociationLogic->saveWeChatData($data); 48 $this->ProjectAssociationLogic->saveWeChatData($data);
48 $this->response('success'); 49 $this->response('success');
49 } 50 }
@@ -28,11 +28,11 @@ class BTemplateModuleController extends BaseController @@ -28,11 +28,11 @@ class BTemplateModuleController extends BaseController
28 } 28 }
29 $data = []; 29 $data = [];
30 $list = $BTemplateModuleLogic->ModuleList($this->map,$this->order); 30 $list = $BTemplateModuleLogic->ModuleList($this->map,$this->order);
31 -// $data['list'] = $list;  
32 -// $moduleProjectModel = new BModuleProject();  
33 -// $module_list = $moduleProjectModel->list(['project_id'=>$this->user['project_id']]);  
34 -// $data['module_list'] = $module_list;  
35 - $this->response('success',Code::SUCCESS,$list); 31 + $data['list'] = $list;
  32 + $moduleProjectModel = new BModuleProject();
  33 + $module_list = $moduleProjectModel->list(['project_id'=>$this->user['project_id']]);
  34 + $data['module_list'] = $module_list;
  35 + $this->response('success',Code::SUCCESS,$data);
36 } 36 }
37 37
38 /** 38 /**
@@ -116,4 +116,79 @@ class NavLogic extends BaseLogic @@ -116,4 +116,79 @@ class NavLogic extends BaseLogic
116 } 116 }
117 return $this->success(); 117 return $this->success();
118 } 118 }
  119 +
  120 +
  121 +
  122 + /**
  123 + * 一键导入 对应分类
  124 + * @throws \App\Exceptions\AsideGlobalException
  125 + * @throws \App\Exceptions\BsideGlobalException
  126 + */
  127 + public function importNav(){
  128 + $nav = $this->getInfo($this->param['id']);
  129 + if(!in_array($nav['url'], array_keys(BNav::ableImportMap()))){
  130 + $this->fail('该菜单不支持一键导入');
  131 + }
  132 +
  133 + $class = BNav::ableImportMap($nav['url']);
  134 + $category = new $class();
  135 + $fields = ['id', 'name', 'pid', 'alias'];
  136 + if($nav['url'] == 'products'){
  137 + $fields = ['id', 'title as name', 'pid', 'route as alias'];
  138 + }
  139 + $this->addByPid($category, $nav, $fields);
  140 + return $this->success();
  141 + }
  142 +
  143 + /**
  144 + * 一级一级的加
  145 + * @author zbj
  146 + * @date 2023/11/22
  147 + */
  148 + protected function addByPid($category, $nav, $fields, $pid = 0)
  149 + {
  150 + $nav_pid = $nav['id'];
  151 + if($pid){
  152 + $p_cate = $category->where('id', $pid)->select($fields)->first();
  153 + if($p_cate){
  154 + $nav_pid = $this->model->where('import_id', $nav['id'])->where('url', $p_cate['alias'])->value('id');
  155 + }
  156 + }
  157 + $list = $category->list(['pid' => $pid], 'id', $fields, 'asc');
  158 + $data = [];
  159 + $time = date('Y-m-d H:i:s');
  160 + foreach ($list as $item) {
  161 + $exists_info = $this->model->where('import_id', $nav['id'])->where('url', $item['alias'])->first();
  162 + if($exists_info){
  163 + continue;
  164 + }
  165 + $data[] = [
  166 + 'pid' => $nav_pid,
  167 + 'name' => $item['name'],
  168 + 'url' => $item['alias'],
  169 + 'project_id' => $this->project['id'],
  170 + 'location' => $nav['location'],
  171 + 'group_id' => $nav['group_id'],
  172 + 'status' => BNav::STATUS_ACTIVE,
  173 + 'import_id' => $nav['id'],
  174 + 'created_at' => $time,
  175 + 'updated_at' => $time,
  176 + ];
  177 + }
  178 + //每500条更一次
  179 + $data_chunk = array_chunk($data,500);
  180 + foreach ($data_chunk as $chunk){
  181 + $this->model->insert($chunk);
  182 + }
  183 +
  184 + foreach ($list as $item) {
  185 + $this->addByPid($category, $nav, $fields, $item['id']);
  186 + }
  187 + }
  188 +
  189 +
  190 +
  191 +
  192 +
  193 +
119 } 194 }
@@ -6,6 +6,7 @@ use App\Exceptions\BsideGlobalException; @@ -6,6 +6,7 @@ use App\Exceptions\BsideGlobalException;
6 use App\Helper\Arr; 6 use App\Helper\Arr;
7 use App\Helper\Common; 7 use App\Helper\Common;
8 use App\Http\Logic\Bside\BaseLogic; 8 use App\Http\Logic\Bside\BaseLogic;
  9 +use App\Models\News\News;
9 use App\Models\Product\Keyword; 10 use App\Models\Product\Keyword;
10 use App\Models\Product\KeywordRelated; 11 use App\Models\Product\KeywordRelated;
11 use App\Models\Product\Product; 12 use App\Models\Product\Product;
@@ -38,6 +39,8 @@ class KeywordLogic extends BaseLogic @@ -38,6 +39,8 @@ class KeywordLogic extends BaseLogic
38 { 39 {
39 $info = $this->model->read($this->param); 40 $info = $this->model->read($this->param);
40 $info['url'] = $this->user['domain'] . $info['route']; 41 $info['url'] = $this->user['domain'] . $info['route'];
  42 + $info['related_news_info'] = News::whereIn('id', $info['related_news_ids'])->select(['id', 'name'])->get();
  43 +
41 return $this->success($info); 44 return $this->success($info);
42 } 45 }
43 46
@@ -209,4 +212,29 @@ class KeywordLogic extends BaseLogic @@ -209,4 +212,29 @@ class KeywordLogic extends BaseLogic
209 Common::del_user_cache('product_keyword',$project_id); 212 Common::del_user_cache('product_keyword',$project_id);
210 return ','.implode(',',$return).','; 213 return ','.implode(',',$return).',';
211 } 214 }
  215 +
  216 + /**
  217 + * 批量删除
  218 + * @return array
  219 + * @throws BsideGlobalException
  220 + * @throws \App\Exceptions\AsideGlobalException
  221 + * @author zbj
  222 + * @date 2023/11/22
  223 + */
  224 + public function batchDel(){
  225 + try {
  226 + foreach ($this->param['title'] as $v){
  227 + $info = $this->model->read(['title'=>$v]);
  228 + if($info){
  229 + $this->delRoute($info['id']);
  230 + $this->model->del(['id'=>$info['id']]);
  231 + }
  232 + }
  233 + //清除缓存
  234 + Common::del_user_cache('product_keyword',$this->user['project_id']);
  235 + }catch (\Exception $e){
  236 + $this->fail('error');
  237 + }
  238 + return $this->success();
  239 + }
212 } 240 }
@@ -10,14 +10,19 @@ class DataFile extends Base @@ -10,14 +10,19 @@ class DataFile extends Base
10 10
11 public function saveData(array $data): bool 11 public function saveData(array $data): bool
12 { 12 {
  13 + # v6项目ID
13 $project_id = (int)$data['project_id'] ?? 0; 14 $project_id = (int)$data['project_id'] ?? 0;
14 $isRes = self::query()->where('project_id', $project_id)->where('created_at', 'like', $data['time'] . '%')->first(); 15 $isRes = self::query()->where('project_id', $project_id)->where('created_at', 'like', $data['time'] . '%')->first();
15 if (!$isRes) { 16 if (!$isRes) {
16 $isRes = new self(); 17 $isRes = new self();
17 $isRes->project_id = $project_id; 18 $isRes->project_id = $project_id;
18 } 19 }
19 - $isRes->file_path = $data['file_path'];  
20 - $isRes->application_id = $data['application_id']; 20 + # AICC用户ID
  21 + $isRes->user_id = $data['user_id'];
  22 + # 第三方朋友ID
  23 + $isRes->friend_id = $data['friend_id'];
  24 + # 生成文件路径
  25 + $isRes->file_path = $data['file_path'];
21 return $isRes->save(); 26 return $isRes->save();
22 } 27 }
23 28
@@ -35,6 +35,21 @@ class BNav extends Base @@ -35,6 +35,21 @@ class BNav extends Base
35 const STATUS_DISABLED = 0; 35 const STATUS_DISABLED = 0;
36 36
37 37
  38 + /**
  39 + * @author zbj
  40 + * @date 2023/11/22
  41 + */
  42 + public static function ableImportMap($url=''){
  43 + $map = [
  44 + 'products' => '\\App\\Models\\Product\\Category',
  45 + 'news' => '\\App\\Models\\News\\NewsCategory',
  46 + 'blog' => '\\App\\Models\\Blog\\BlogCategory',
  47 + ];
  48 + if ($url){
  49 + return $map[$url] ?:"";
  50 + }
  51 + return $map;
  52 + }
38 53
39 54
40 /** 55 /**
@@ -85,7 +100,7 @@ class BNav extends Base @@ -85,7 +100,7 @@ class BNav extends Base
85 */ 100 */
86 public function getAbleImportAttribute($value) 101 public function getAbleImportAttribute($value)
87 { 102 {
88 - if(in_array($this->url, ['products','news','blogs'])){ 103 + if(in_array($this->url, array_keys(self::ableImportMap()))){
89 return 1; 104 return 1;
90 } 105 }
91 return 0; 106 return 0;
@@ -67,7 +67,7 @@ class Keyword extends Base @@ -67,7 +67,7 @@ class Keyword extends Base
67 if(!empty($value)){ 67 if(!empty($value)){
68 $value = Arr::setToArr($value); 68 $value = Arr::setToArr($value);
69 } 69 }
70 - return $value; 70 + return $value ?: [];
71 } 71 }
72 72
73 /** 73 /**
@@ -80,6 +80,6 @@ class Keyword extends Base @@ -80,6 +80,6 @@ class Keyword extends Base
80 if(!empty($value)){ 80 if(!empty($value)){
81 $value = Arr::setToArr($value); 81 $value = Arr::setToArr($value);
82 } 82 }
83 - return $value; 83 + return $value ?: [];
84 } 84 }
85 } 85 }
@@ -16,17 +16,23 @@ class ProjectAssociation extends Model @@ -16,17 +16,23 @@ class ProjectAssociation extends Model
16 */ 16 */
17 public function saveData(array $data): bool 17 public function saveData(array $data): bool
18 { 18 {
  19 + # V6项目ID
19 $project_id = (int)$data['project_id'] ?? 0; 20 $project_id = (int)$data['project_id'] ?? 0;
20 $isRes = self::query()->where('project_id', $project_id)->first(); 21 $isRes = self::query()->where('project_id', $project_id)->first();
21 if (!$isRes) { 22 if (!$isRes) {
22 $isRes = new self(); 23 $isRes = new self();
23 $isRes->project_id = $project_id; 24 $isRes->project_id = $project_id;
24 } 25 }
25 - $isRes->wx_id = $data['wx_id'];  
26 - $isRes->wx_nickname = $data['wx_nickname'];  
27 - $isRes->wx_user_id = $data['wx_user_id'];  
28 - $isRes->wx_user_name = $data['wx_user_name'];  
29 - $isRes->wx_image = $data['wx_image']; 26 + # AICC朋友ID
  27 + $isRes->friend_id = $data['friend_id'] ?? 0;
  28 + # AICC朋友昵称
  29 + $isRes->nickname = $data['nickname'] ?? 0;
  30 + # AICC用户ID
  31 + $isRes->user_id = $data['user_id'] ?? 0;
  32 + # AICC用户姓名
  33 + $isRes->user_name = $data['user_name'] ?? '';
  34 + # AICC朋友头像
  35 + $isRes->image = $data['image'] ?? '';
30 return $isRes->save(); 36 return $isRes->save();
31 } 37 }
32 38
@@ -50,8 +56,9 @@ class ProjectAssociation extends Model @@ -50,8 +56,9 @@ class ProjectAssociation extends Model
50 $status = 1; # 1 - 正常, 0 - 禁用 56 $status = 1; # 1 - 正常, 0 - 禁用
51 $lists = self::query()->where('status', $status) 57 $lists = self::query()->where('status', $status)
52 ->whereNotNull('project_id') 58 ->whereNotNull('project_id')
53 - ->whereNotNull('wx_user_id')  
54 - ->paginate($perPage, ['project_id', 'wx_id', 'wx_user_id'], 'page', $page); 59 + ->whereNotNull('friend_id')
  60 + ->whereNotNull('user_id')
  61 + ->paginate($perPage, ['project_id', 'friend_id', 'user_id'], 'page', $page);
55 $items = $lists->Items(); 62 $items = $lists->Items();
56 $totalPage = $lists->lastPage(); 63 $totalPage = $lists->lastPage();
57 $total = $lists->total(); 64 $total = $lists->total();
@@ -219,6 +219,7 @@ Route::middleware(['bloginauth'])->group(function () { @@ -219,6 +219,7 @@ Route::middleware(['bloginauth'])->group(function () {
219 Route::get('keyword/info', [\App\Http\Controllers\Bside\Product\KeywordController::class, 'info'])->name('product_keyword_info'); 219 Route::get('keyword/info', [\App\Http\Controllers\Bside\Product\KeywordController::class, 'info'])->name('product_keyword_info');
220 Route::post('keyword/save', [\App\Http\Controllers\Bside\Product\KeywordController::class, 'save'])->name('product_keyword_save'); 220 Route::post('keyword/save', [\App\Http\Controllers\Bside\Product\KeywordController::class, 'save'])->name('product_keyword_save');
221 Route::post('keyword/batchAdd', [\App\Http\Controllers\Bside\Product\KeywordController::class, 'batchAdd'])->name('product_keyword_batchAdd'); 221 Route::post('keyword/batchAdd', [\App\Http\Controllers\Bside\Product\KeywordController::class, 'batchAdd'])->name('product_keyword_batchAdd');
  222 + Route::post('keyword/batchDel', [\App\Http\Controllers\Bside\Product\KeywordController::class, 'batchDel'])->name('product_keyword_batchDel');
222 Route::any('keyword/delete', [\App\Http\Controllers\Bside\Product\KeywordController::class, 'delete'])->name('product_keyword_delete'); 223 Route::any('keyword/delete', [\App\Http\Controllers\Bside\Product\KeywordController::class, 'delete'])->name('product_keyword_delete');
223 224
224 //产品参数 225 //产品参数
@@ -365,6 +366,7 @@ Route::middleware(['bloginauth'])->group(function () { @@ -365,6 +366,7 @@ Route::middleware(['bloginauth'])->group(function () {
365 Route::delete('/delete', [\App\Http\Controllers\Bside\Nav\NavController::class, 'delete'])->name('nav_delete'); 366 Route::delete('/delete', [\App\Http\Controllers\Bside\Nav\NavController::class, 'delete'])->name('nav_delete');
366 Route::get('/default-urls', [\App\Http\Controllers\Bside\Nav\NavController::class, 'urls'])->name('nav_default-urls'); 367 Route::get('/default-urls', [\App\Http\Controllers\Bside\Nav\NavController::class, 'urls'])->name('nav_default-urls');
367 Route::post('/sort', [\App\Http\Controllers\Bside\Nav\NavController::class, 'sort'])->name('nav_sort'); 368 Route::post('/sort', [\App\Http\Controllers\Bside\Nav\NavController::class, 'sort'])->name('nav_sort');
  369 + Route::post('/import', [\App\Http\Controllers\Bside\Nav\NavController::class, 'import'])->name('nav_import');
368 }); 370 });
369 371
370 //排名数据 372 //排名数据