|
|
@@ -0,0 +1,85 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace pt\controllers;
|
|
|
+
|
|
|
+use biz\cp\classes\PtCpClass;
|
|
|
+use biz\cp\classes\PtCpItemClass;
|
|
|
+use biz\item\classes\PtItemClass;
|
|
|
+use Yii;
|
|
|
+use common\components\util;
|
|
|
+
|
|
|
+class PtCpItemController extends BaseController
|
|
|
+{
|
|
|
+
|
|
|
+ //多个花材设置产品 ssh 20240120
|
|
|
+ public function actionSetCp()
|
|
|
+ {
|
|
|
+ $post = Yii::$app->request->post();
|
|
|
+ $str = $post['ids'] ?? '';
|
|
|
+ $cpId = $post['cpId'] ?? 0;
|
|
|
+ $ids = json_decode($str, true);
|
|
|
+ if (empty($ids)) {
|
|
|
+ util::fail('请选择花材');
|
|
|
+ }
|
|
|
+ $cp = PtCpClass::getById($cpId, true);
|
|
|
+ if (empty($cp)) {
|
|
|
+ util::fail('没有找到产品');
|
|
|
+ }
|
|
|
+ $cpAuth = $cp->auth ?? 0;
|
|
|
+ $cpPy = $cp->py ?? '';
|
|
|
+ $cpName = $cp->name ?? '';
|
|
|
+ $itemList = PtItemClass::getByIds($ids);
|
|
|
+ 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;
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ $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('请选择花材');
|
|
|
+ }
|
|
|
+ $cp = PtCpClass::getById($cpId, true);
|
|
|
+ if (empty($cp)) {
|
|
|
+ util::fail('没有找到产品');
|
|
|
+ }
|
|
|
+ $itemList = PtItemClass::getByIds($ids);
|
|
|
+ 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();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ util::complete('删除成功');
|
|
|
+ }
|
|
|
+
|
|
|
+}
|