ItemMsController.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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('请选择花材15');
  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. $relate = ItemMsClass::getByCondition(['motherId' => $motherId], true);
  30. if (empty($relate)) {
  31. $relate = ItemMsClass::add(['motherId' => $motherId], true);
  32. }
  33. $hasIdString = $relate->idList ?? '';
  34. $hasIds = [];
  35. if (!empty($hasIdString)) {
  36. $hasIds = explode(',', $hasIdString);
  37. }
  38. foreach ($ids as $current) {
  39. if (in_array($current, $hasIds) == false && $current != $motherId) {
  40. $hasIds[] = $current;
  41. }
  42. }
  43. $newString = implode(',', $hasIds);
  44. $relate->idList = $newString;
  45. $relate->save();
  46. util::complete();
  47. }
  48. //删除花材 ssh 20230718
  49. public function actionDelItem()
  50. {
  51. $get = Yii::$app->request->get();
  52. $motherId = $get['motherId'] ?? 0;
  53. $delId = $get['id'] ?? 0;
  54. $mother = ItemClass::getById($motherId, true);
  55. if (empty($mother) || $mother->mainId != $this->mainId) {
  56. util::fail('没有权限');
  57. }
  58. $relate = ItemMsClass::getByCondition(['motherId' => $motherId], true);
  59. if (empty($relate)) {
  60. util::fail('没有找到花材');
  61. }
  62. $idList = $relate->idList ?? '';
  63. if (!empty($idList)) {
  64. $ids = explode(',', $idList);
  65. $new = [];
  66. foreach ($ids as $current) {
  67. if ($current != $delId) {
  68. $new[] = $current;
  69. }
  70. }
  71. $idString = implode(',', $new);
  72. $relate->idList = $idString;
  73. $relate->save();
  74. }
  75. util::complete();
  76. }
  77. //获取子花材 ssh 20230718
  78. public function actionGetSonList()
  79. {
  80. $get = Yii::$app->request->get();
  81. $motherId = $get['motherId'] ?? 0;
  82. $item = ItemClass::getById($motherId, true);
  83. if (empty($item) || $item->mainId != $this->mainId) {
  84. util::fail('没有找到花材');
  85. }
  86. $ms = ItemMsClass::getByCondition(['motherId' => $motherId], true);
  87. $list = [];
  88. $idList = $ms->idList ?? '';
  89. if (!empty($idList)) {
  90. $ids = explode(',', $idList);
  91. $list = ItemClass::getAllByCondition(['id' => ['in', $ids], 'delStatus' => 0,], null, '*');
  92. if (!empty($list)) {
  93. foreach ($list as $key => $val) {
  94. $shortCover = $val['cover'] ?? '';
  95. $bigCover = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
  96. $smallCover = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
  97. $list[$key]['bigCover'] = $bigCover;
  98. $list[$key]['smallCover'] = $smallCover;
  99. $list[$key]['shortCover'] = $shortCover;
  100. $list[$key]['cover'] = $bigCover;
  101. $list[$key]['sendHyPrice'] = '';
  102. $list[$key]['sendSonStock'] = '';
  103. $list[$key]['sendLsPrice'] = '';
  104. $list[$key]['sendPfPrice'] = '';
  105. }
  106. }
  107. }
  108. util::success(['list' => $list]);
  109. }
  110. }