CgItemController.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. namespace hd\controllers;
  3. use bizHd\product\classes\ProductClass;
  4. use bizHd\purchase\classes\PurchaseClass;
  5. use bizHd\purchase\classes\PurchaseItemClass;
  6. use common\components\imgUtil;
  7. use Yii;
  8. use common\components\util;
  9. class CgItemController extends BaseController
  10. {
  11. //预存价格 ssh 20230725
  12. public function actionSaveCgPrice()
  13. {
  14. $post = Yii::$app->request->post();
  15. $data = $post['data'] ?? '';
  16. if (empty($data)) {
  17. util::fail('没有修改');
  18. }
  19. $arr = json_decode($data, true);
  20. if (empty($arr)) {
  21. util::fail('没有修改哦');
  22. }
  23. $cgId = $post['cgId'] ?? 0;
  24. $cg = PurchaseClass::getById($cgId, true);
  25. if (empty($cg)) {
  26. util::fail('没有找到采购单');
  27. }
  28. if ($cg->mainId != $this->mainId) {
  29. util::fail('没有权限');
  30. }
  31. $orderSn = $cg->orderSn ?? '';
  32. $cgItemList = PurchaseItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
  33. if (empty($cgItemList)) {
  34. util::fail('没有找到花材');
  35. }
  36. $new = [];
  37. foreach ($arr as $product) {
  38. $currentId = $product['id'] ?? 0;
  39. $savePrice = $product['savePrice'] ?? 0;
  40. $saveSkPrice = $product['saveSkPrice'] ?? 0;
  41. $saveHjPrice = $product['saveHjPrice'] ?? 0;
  42. $new[$currentId]['savePrice'] = $savePrice;
  43. $new[$currentId]['saveSkPrice'] = $saveSkPrice;
  44. $new[$currentId]['saveHjPrice'] = $saveHjPrice;
  45. }
  46. foreach ($cgItemList as $cgItem) {
  47. $thisId = $cgItem->id ?? 0;
  48. if (isset($new[$thisId]) == false) {
  49. util::fail('有花材没有价格');
  50. }
  51. $info = $new[$thisId];
  52. $savePrice = $info['savePrice'] ?? 0;
  53. $saveSkPrice = $info['saveSkPrice'] ?? 0;
  54. $saveHjPrice = $info['saveHjPrice'] ?? 0;
  55. $cgItem->savePrice = $savePrice;
  56. $cgItem->saveSkPrice = $saveSkPrice;
  57. $cgItem->saveHjPrice = $saveHjPrice;
  58. $cgItem->save();
  59. }
  60. $cg->hasSavePrice = 1;
  61. $cg->save();
  62. util::complete();
  63. }
  64. //采购成功后改价时获取列表 ssh 2023311
  65. public function actionGetCgItemInfo()
  66. {
  67. $get = Yii::$app->request->get();
  68. $id = $get['id'] ?? 0;
  69. $cg = PurchaseClass::getById($id, true);
  70. if (empty($cg)) {
  71. util::fail('没有找到采购信息');
  72. }
  73. if ($cg->mainId != $this->mainId) {
  74. util::fail('无法操作');
  75. }
  76. $orderSn = $cg->orderSn ?? '';
  77. $list = PurchaseItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*');
  78. if (!empty($list)) {
  79. $productIdList = array_column($list, 'productId');
  80. $itemList = ProductClass::getByIds($productIdList, null, 'id');
  81. foreach ($list as $key => $item) {
  82. $productId = $item['productId'] ?? 0;
  83. $cost = $item['xhUnitPrice'] ?? 0;
  84. $cost = round($cost);
  85. $current = $itemList[$productId] ?? [];
  86. $addPrice = $current['addPrice'] ?? 0;
  87. $hjAddPrice = $current['hjAddPrice'] ?? 0;
  88. $skMore = $current['skMore'] ?? 0;
  89. if (isset($item['savePrice']) && $item['savePrice'] > 0) {
  90. $suggestPrice = $item['savePrice'] ?? 0;
  91. $suggestSkPrice = $item['saveSkPrice'] ?? 0;
  92. $suggestHjPrice = $item['saveHjPrice'] ?? 0;
  93. } else {
  94. $suggestPrice = bcadd($cost, $addPrice, 2);
  95. $suggestSkPrice = bcadd($cost, $skMore, 2);
  96. $suggestHjPrice = bcadd($cost, $hjAddPrice, 2);
  97. }
  98. $suggestPrice = floatval($suggestPrice);
  99. $suggestSkPrice = floatval($suggestSkPrice);
  100. $suggestHjPrice = floatval($suggestHjPrice);
  101. $list[$key]['suggestPrice'] = $suggestPrice;
  102. $list[$key]['suggestSkPrice'] = $suggestSkPrice;
  103. $list[$key]['suggestHjPrice'] = $suggestHjPrice;
  104. $list[$key]['skMore'] = $skMore;
  105. $list[$key]['addPrice'] = $addPrice;
  106. $list[$key]['hjAddPrice'] = $hjAddPrice;
  107. //修改之前的批发价
  108. $beforeModifyPrice = $current['price'] ?? 0;
  109. $list[$key]['beforeModifyPrice'] = $beforeModifyPrice;
  110. }
  111. }
  112. $shop = $this->shop;
  113. $onlyCg = $shop->onlyCg ?? 1;
  114. util::success(['list' => $list, 'onlyCg' => $onlyCg]);
  115. }
  116. }