ItemMsController.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. namespace ghs\controllers;
  3. use bizGhs\item\classes\ItemClass;
  4. use bizGhs\item\classes\ItemMsClass;
  5. use common\components\imgUtil;
  6. use common\components\util;
  7. use Yii;
  8. class ItemMsController extends BaseController
  9. {
  10. //分配库存和改价 ssh 20230719
  11. public function actionSendStock()
  12. {
  13. util::complete();
  14. }
  15. //批量添加子花材 ssh 20230719
  16. public function actionBatchAddItem()
  17. {
  18. $post = Yii::$app->request->post();
  19. $idsList = $post['ids'] ?? '';
  20. $ids = json_decode($idsList, true);
  21. if (empty($ids)) {
  22. util::fail('请选择花材');
  23. }
  24. $motherId = $post['motherId'] ?? 0;
  25. $mother = ItemClass::getById($motherId, true);
  26. if (empty($mother) || $mother->mainId != $this->mainId) {
  27. util::fail('没有权限');
  28. }
  29. $hasIdString = $mother->idList ?? '';
  30. $hasIds = [];
  31. if (!empty($hasIdString)) {
  32. $hasIds = explode(',', $hasIdString);
  33. }
  34. foreach ($ids as $current) {
  35. if (in_array($current, $hasIds) == false) {
  36. $hasIds[] = $current;
  37. }
  38. }
  39. $newString = implode(',', $hasIds);
  40. $mother->idList = $newString;
  41. $mother->save();
  42. util::complete();
  43. }
  44. //删除花材 ssh 20230718
  45. public function actionDelItem()
  46. {
  47. $get = Yii::$app->request->get();
  48. $motherId = $get['motherId'] ?? 0;
  49. $delId = $get['id'] ?? 0;
  50. $mother = ItemClass::getById($motherId, true);
  51. if (empty($mother) || $mother->mainId != $this->mainId) {
  52. util::fail('没有权限');
  53. }
  54. $relate = ItemMsClass::getByCondition(['motherId' => $motherId], true);
  55. if (empty($relate)) {
  56. util::fail('没有找到花材');
  57. }
  58. $idList = $relate->idList ?? '';
  59. if (!empty($idList)) {
  60. $ids = explode(',', $idList);
  61. $new = [];
  62. foreach ($ids as $current) {
  63. if ($current != $delId) {
  64. $new[] = $current;
  65. }
  66. }
  67. $idString = implode(',', $new);
  68. $relate->idList = $idString;
  69. $relate->save();
  70. }
  71. util::complete();
  72. }
  73. //获取子花材 ssh 20230718
  74. public function actionGetSonList()
  75. {
  76. $get = Yii::$app->request->get();
  77. $motherId = $get['motherId'] ?? 0;
  78. $item = ItemClass::getById($motherId, true);
  79. if (empty($item) || $item->mainId != $this->mainId) {
  80. util::fail('没有找到花材');
  81. }
  82. $ms = ItemMsClass::getByCondition(['motherId' => $motherId], true);
  83. $list = [];
  84. $idList = $ms->idList ?? '';
  85. if (!empty($idList)) {
  86. $ids = explode(',', $idList);
  87. $list = ItemClass::getAllByCondition(['id' => ['in', $ids]], null, '*');
  88. if (!empty($list)) {
  89. foreach ($list as $key => $val) {
  90. $shortCover = $val['cover'] ?? '';
  91. $bigCover = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
  92. $smallCover = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
  93. $list[$key]['bigCover'] = $bigCover;
  94. $list[$key]['smallCover'] = $smallCover;
  95. $list[$key]['shortCover'] = $shortCover;
  96. $list[$key]['cover'] = $bigCover;
  97. $list[$key]['sendHyPrice'] = '';
  98. $list[$key]['sendSonStock'] = '';
  99. $list[$key]['sendLsPrice'] = '';
  100. $list[$key]['sendPfPrice'] = '';
  101. }
  102. }
  103. }
  104. util::success(['list' => $list]);
  105. }
  106. }