ReportLogic.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2019/4/29 0029
  6. * Time: 17:16
  7. */
  8. namespace App\Http\Logics\Admin;
  9. use App\Http\Models\LinkTask;
  10. use App\Http\Models\LinkTaskDetail;
  11. use App\Http\Models\LinkTaskUrl;
  12. use App\Http\Models\User;
  13. use \Illuminate\Database\Eloquent\Builder;
  14. use Illuminate\Http\Request;
  15. use Illuminate\Support\Facades\Auth;
  16. use Illuminate\Support\Facades\DB;
  17. class ReportLogic
  18. {
  19. public function syncSummary($ym, $siteId, $validated)
  20. {
  21. $filter = ['ym' => $ym, 'project_id' => $siteId];
  22. $summaryRecords = DB::connection('rank')->table('report_summary')->where($filter)->get()->toArray();
  23. $summaryRecordsIdList = array_column($summaryRecords, 'id');
  24. $summaryIdList = array_column($validated['dataList'], 'summaryId'); //传递过来的数据
  25. // 数据同步
  26. foreach ($summaryRecordsIdList as $item) { //如果已存在的记录中不在提交的数据中
  27. if (!in_array($item, $summaryIdList)) {
  28. DB::connection('rank')->table('report_summary')->delete($item);
  29. }
  30. };
  31. foreach ($validated['dataList'] as $item) {
  32. if (!in_array($item['summaryId'], $summaryRecordsIdList)) { //判断提价的数据在不在已存在的记录中
  33. DB::connection('rank')->table('report_summary')->insert([
  34. 'ym' => $ym,
  35. 'val1' => $item['val1'],
  36. 'val2' => $item['val2'],
  37. 'val3' => $item['val3'],
  38. 'project_id' => $siteId,
  39. 'create_time' => time()
  40. ]);
  41. } else {
  42. DB::connection('rank')->table('report_summary')->where(['id' => $item['summaryId']])->update([
  43. 'val1' => $item['val1'],
  44. 'val2' => $item['val2'],
  45. 'val3' => $item['val3'],
  46. ]);
  47. }
  48. }
  49. }
  50. public function syncFileExtend($ym, $siteId, $validated)
  51. {
  52. // $filter = ['ym' => $ym, 'project_id' => $siteId];
  53. $selectItem=[
  54. 'manage'=>$validated['selectManageList']??[],
  55. 'customer'=>$validated['selectCustomerList']??[],
  56. ];
  57. DB::connection('rank')->table('report_extend')->updateOrInsert([
  58. 'ym' => $ym, 'project_id' => $siteId
  59. ], [
  60. 'remark' => $validated['remark'],
  61. 'file_list' => json_encode($validated['fileList']),
  62. 'create_time' => time(),
  63. 'select_item'=>json_encode($selectItem)
  64. ]);
  65. // if (DB::connection('rank')->table('report_extend')->where($filter)->exists()) {
  66. // DB::connection('rank')->table('report_extend')->insert([
  67. // 'remark' => $validated['remark'],
  68. // 'file_list' => json_encode($validated['fileList']),
  69. // 'ym' => $ym,
  70. // 'create_time' => time(),
  71. // 'project_id' => $siteId
  72. // ]);
  73. // } else {
  74. //
  75. // DB::connection('rank')->table('report_extend')->where($filter)->update([
  76. // 'remark' => $validated['remark'],
  77. // 'file_list' => json_encode($validated['fileList'])
  78. // ]);
  79. // }
  80. }
  81. }