request->get(); $cpId = $get['cpId'] ?? 0; $search = $get['search'] ?? ''; $mainId = $this->mainId ?? 0; $where = []; $where['mainId'] = $mainId; if (!empty($cpId)) { $where['cpId'] = $cpId; } if (!empty($search)) { if (stringUtil::isLetter($search)) { $where['py'] = ['like', $search]; } else { $where['name'] = ['like', $search]; } } $respond = CpItemClass::getItemList($where); util::success($respond); } //删除关系 ssh 20240115 public function actionDel() { $get = Yii::$app->request->get(); $id = $get['id'] ?? 0; $item = CpItemClass::getById($id, true); if (empty($item)) { util::fail('没有找到'); } if ($item->mainId != $this->mainId) { util::fail('不是你的产品'); } $productId = $item->productId ?? 0; $count = CpItemClass::getCount(['productId' => $productId]); if ($count <= 1) { util::fail('最少要保留一个'); } $item->delete(); util::complete('删除成功'); } //添加关系 ssh 20240115 public function actionAdd() { $get = Yii::$app->request->get(); $cpId = $get['cpId'] ?? 0; $productId = $get['productId'] ?? 0; $cp = CpClass::getById($cpId, true); if (empty($cp)) { util::fail('没有找到产品'); } if ($cp->mainId != $this->mainId) { util::fail('不是你的产品'); } $ptCpId = $cp->ptCpId ?? 0; $product = ProductClass::getById($productId, true); if (empty($product)) { util::fail('没有找到花材'); } if ($product->mainId != $this->mainId) { util::fail('不是你的花材'); } $ptItemId = $product->itemId ?? 0; $relate = CpItemClass::getByCondition(['cpId' => $cpId, 'productId' => $productId], true); if (!empty($relate)) { util::fail('已经添加了'); } $productName = $product->name ?? ''; $py = stringUtil::py($productName); $data = [ 'cpId' => $cpId, 'ptCpId' => $ptCpId, 'ptItemId' => $ptItemId, 'productId' => $productId, 'name' => $productName, 'py' => $py, 'mainId' => $this->mainId ]; $respond = CpItemClass::add($data, true); if (empty($respond)) { util::fail('添加失败'); } util::complete('添加成功'); } }