PtItemCatRelateController.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace pt\controllers;
  3. use biz\item\classes\PtItemCatClass;
  4. use biz\item\classes\PtItemCatRelateClass;
  5. use biz\item\classes\PtItemClass;
  6. use Yii;
  7. use common\components\util;
  8. class PtItemCatRelateController extends BaseController
  9. {
  10. //批量设置为建议花材 sssh 20240127
  11. public function actionBatchSet()
  12. {
  13. $post = Yii::$app->request->post();
  14. $str = $post['ids'] ?? '';
  15. $classId = $post['classId'] ?? 0;
  16. $class = PtItemCatClass::getById($classId, true);
  17. if (empty($class)) {
  18. util::fail('没有找到分类');
  19. }
  20. $ids = json_decode($str, true);
  21. if (empty($ids)) {
  22. util::fail('请选择花材21');
  23. }
  24. $list = PtItemClass::getByIds($ids);
  25. if (empty($list)) {
  26. util::fail('没有花材');
  27. }
  28. foreach ($list as $item) {
  29. $id = $item['id'] ?? 0;
  30. $has = PtItemCatRelateClass::getByCondition(['catId' => $classId, 'itemId' => $id], true);
  31. if (empty($has)) {
  32. PtItemCatRelateClass::add(['catId' => $classId, 'itemId' => $id], true);
  33. }
  34. }
  35. util::complete();
  36. }
  37. }