作者 李美松

逻辑 - 代码优化

@@ -75,14 +75,14 @@ class ProjectFilePDF extends Command @@ -75,14 +75,14 @@ class ProjectFilePDF extends Command
75 { 75 {
76 foreach ($items as $item) { 76 foreach ($items as $item) {
77 $project_id = $item->project_id; 77 $project_id = $item->project_id;
78 - $application_id = $item->wx_id;  
79 - $wx_user_id = $item->wx_user_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 }
@@ -32,18 +32,19 @@ class ProjectAssociationController extends BaseController @@ -32,18 +32,19 @@ class ProjectAssociationController extends BaseController
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 - 禁用 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) { 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 }
@@ -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 }
  20 + # AICC用户ID
  21 + $isRes->user_id = $data['user_id'];
  22 + # 第三方朋友ID
  23 + $isRes->friend_id = $data['friend_id'];
  24 + # 生成文件路径
19 $isRes->file_path = $data['file_path']; 25 $isRes->file_path = $data['file_path'];
20 - $isRes->application_id = $data['application_id'];  
21 return $isRes->save(); 26 return $isRes->save();
22 } 27 }
23 28
@@ -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();