|
|
@@ -3,6 +3,9 @@
|
|
|
namespace ghs\controllers;
|
|
|
|
|
|
use bizGhs\cp\classes\CpItemClass;
|
|
|
+use bizGhs\Cp\models\CpClass;
|
|
|
+use bizGhs\product\classes\ProductClass;
|
|
|
+use common\components\stringUtil;
|
|
|
use common\components\util;
|
|
|
use Yii;
|
|
|
|
|
|
@@ -40,4 +43,38 @@ class CpItemController extends BaseController
|
|
|
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('不是你的产品');
|
|
|
+ }
|
|
|
+ $product = ProductClass::getById($productId, true);
|
|
|
+ if (empty($product)) {
|
|
|
+ util::fail('没有找到花材');
|
|
|
+ }
|
|
|
+ if ($product->mainId != $this->mainId) {
|
|
|
+ util::fail('不是你的花材');
|
|
|
+ }
|
|
|
+ $relate = CpItemClass::getByCondition(['cpId' => $cpId, 'productId' => $productId], true);
|
|
|
+ if (!empty($relate)) {
|
|
|
+ util::fail('已经添加了');
|
|
|
+ }
|
|
|
+ $productName = $product->name ?? '';
|
|
|
+ $py = stringUtil::py($productName);
|
|
|
+ $data = ['cpId' => $cpId, 'productId' => $productId, 'name' => $productName, 'py' => $py, 'mainId' => $this->mainId];
|
|
|
+ $respond = CpItemClass::add($data, true);
|
|
|
+ if (empty($respond)) {
|
|
|
+ util::fail('添加失败');
|
|
|
+ }
|
|
|
+ util::complete('添加成功');
|
|
|
+ }
|
|
|
+
|
|
|
}
|