| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 | <?php/** * Created by PhpStorm. * User: Administrator * Date: 2019/4/29 0029 * Time: 17:16 */namespace App\Http\Logics\Admin;use App\Http\Models\LinkTask;use App\Http\Models\LinkTaskDetail;use App\Http\Models\LinkTaskUrl;use App\Http\Models\User;use \Illuminate\Database\Eloquent\Builder;use Illuminate\Http\Request;use Illuminate\Support\Facades\Auth;use Illuminate\Support\Facades\DB;class ReportLogic{    public function syncSummary($ym, $siteId, $validated)    {        $filter = ['ym' => $ym, 'project_id' => $siteId];        $summaryRecords = DB::connection('rank')->table('report_summary')->where($filter)->get()->toArray();        $summaryRecordsIdList = array_column($summaryRecords, 'id');        $summaryIdList = array_column($validated['dataList'], 'summaryId'); //传递过来的数据        // 数据同步        foreach ($summaryRecordsIdList as $item) { //如果已存在的记录中不在提交的数据中            if (!in_array($item, $summaryIdList)) {                DB::connection('rank')->table('report_summary')->delete($item);            }        };        foreach ($validated['dataList'] as $item) {            if (!in_array($item['summaryId'], $summaryRecordsIdList)) { //判断提价的数据在不在已存在的记录中                DB::connection('rank')->table('report_summary')->insert([                    'ym' => $ym,                    'val1' => $item['val1'],                    'val2' => $item['val2'],                    'val3' => $item['val3'],                    'project_id' => $siteId,                    'create_time' => time()                ]);            } else {                DB::connection('rank')->table('report_summary')->where(['id' => $item['summaryId']])->update([                    'val1' => $item['val1'],                    'val2' => $item['val2'],                    'val3' => $item['val3'],                ]);            }        }    }    public function syncFileExtend($ym, $siteId, $validated)    {//        $filter = ['ym' => $ym, 'project_id' => $siteId];        $selectItem=[            'manage'=>$validated['selectManageList']??[],            'customer'=>$validated['selectCustomerList']??[],        ];        DB::connection('rank')->table('report_extend')->updateOrInsert([            'ym' => $ym, 'project_id' => $siteId        ], [            'remark' => $validated['remark'],            'file_list' => json_encode($validated['fileList']),            'create_time' => time(),            'select_item'=>json_encode($selectItem)        ]);//        if (DB::connection('rank')->table('report_extend')->where($filter)->exists()) {//            DB::connection('rank')->table('report_extend')->insert([//                'remark' => $validated['remark'],//                'file_list' => json_encode($validated['fileList']),//                'ym' => $ym,//                'create_time' => time(),//                'project_id' => $siteId//            ]);//        } else {////            DB::connection('rank')->table('report_extend')->where($filter)->update([//                'remark' => $validated['remark'],//                'file_list' => json_encode($validated['fileList'])//            ]);//        }    }}
 |