| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- <?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;
- $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('删除成功');
- }
- }
|