diff --git a/app/admin/controller/Store.php b/app/admin/controller/Store.php index 8d681534..735df4e1 100644 --- a/app/admin/controller/Store.php +++ b/app/admin/controller/Store.php @@ -184,18 +184,38 @@ class Store extends Controller */ public function auth(int $storeId): Json { - SyncTask::where('store_id', $storeId)->delete(); $platformList = $this->request->param('platformList'); + $currItems = SyncTask::where('store_id', $storeId)->select()->toArray(); + if ($currItems) { + $delIds = []; + foreach ($currItems as $item) { + if (!in_array($item['channel'], $platformList)) { + $delIds[] = $item['id']; + } + } + unset($item); + //删除 + if ($delIds) { + SyncTask::whereIn('id', $delIds)->delete(); + } + } + $curr_channels = array_column($currItems, "channel"); $inData = []; - foreach ($platformList as $value) { + foreach ($platformList as $platform) { + if (in_array($platform, $curr_channels)) { + continue; + } $inData[] = [ 'store_id' => $storeId, - 'channel' => $value, + 'channel' => $platform, 'create_time' => time(), ]; } - $model = new SyncTask; - $model->addAll($inData); + if ($inData) { + $model = new SyncTask; + $model->addAll($inData); + + } return $this->renderSuccess('操作成功'); }