request->post(); $str = $post['ids'] ?? ''; $cpId = $post['cpId'] ?? 0; $currentAuth = $post['auth'] ?? 0; $ids = json_decode($str, true); if (empty($ids)) { util::fail('请选择花材23'); } $cp = PtCpClass::getById($cpId, true); if (empty($cp)) { util::fail('没有找到产品'); } if ($currentAuth == 1) { $cp->auth = 1; $cp->save(); } $cpAuth = $cp->auth ?? 0; $cpPy = $cp->py ?? ''; $cpName = $cp->name ?? ''; $itemList = PtItemClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true); if (empty($itemList)) { util::fail('没有花材'); } foreach ($itemList as $item) { $itemId = $item->id ?? 0; $delStatus = $item->delStatus ?? 0; $name = $item->name ?? ''; $py = $item->py ?? ''; $itemAuth = $item->auth ?? 0; $item->hasCpId = 1; if ($currentAuth == 1) { $item->auth = 1; } $item->save(); if ($delStatus == 1) { util::fail("【{$name}】已删除"); } $has = PtCpItemClass::getByCondition(['cpId' => $cpId, 'itemId' => $itemId], true); if (empty($has)) { $auth = 0; if ($itemAuth == 1 && $cpAuth == 1) { $auth = 1; } if ($currentAuth == 1) { $auth = 1; } $relate = [ 'itemId' => $itemId, 'cpId' => $cpId, 'name' => $name, 'py' => $py, 'auth' => $auth, 'cpName' => $cpName, 'cpPy' => $cpPy ]; PtCpItemClass::add($relate); } } util::complete('设置成功'); } //删除花材和产品的对应关系 ssh 20240120 public function actionDelCp() { $post = Yii::$app->request->post(); $str = $post['ids'] ?? ''; $cpId = $post['cpId'] ?? 0; $ids = json_decode($str, true); if (empty($ids)) { util::fail('请选择花材22'); } $cp = PtCpClass::getById($cpId, true); if (empty($cp)) { util::fail('没有找到产品'); } $itemList = PtItemClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true); if (empty($itemList)) { util::fail('没有花材'); } foreach ($itemList as $item) { $itemId = $item->id ?? 0; $has = PtCpItemClass::getByCondition(['cpId' => $cpId, 'itemId' => $itemId], true); if (!empty($has)) { $has->delete(); } $hasCp = PtCpItemClass::getByCondition(['itemId' => $itemId], true); if (empty($hasCp)) { $item->hasCpId = 0; $item->save(); } } util::complete('删除成功'); } }