| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- <?php
- namespace ghs\controllers;
- use bizGhs\cp\classes\CpClass;
- use bizGhs\cp\classes\CpItemClass;
- use bizGhs\product\classes\ProductClass;
- use common\components\stringUtil;
- use common\components\util;
- use Yii;
- class CpItemController extends BaseController
- {
- //根据集合id取花材,带分页 ssh 20231228
- public function actionList()
- {
- $get = Yii::$app->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('添加成功');
- }
- }
|