PurchaseOrderItemController.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace ghs\controllers;
  3. use bizGhs\order\classes\PurchaseOrderClass;
  4. use bizGhs\order\classes\PurchaseOrderItemClass;
  5. use bizGhs\product\classes\ProductClass;
  6. use common\components\util;
  7. use Yii;
  8. class PurchaseOrderItemController extends BaseController
  9. {
  10. //获取采购单的明细
  11. public function actionGetItemList()
  12. {
  13. $get = Yii::$app->request->get();
  14. $id = $get['id'] ?? 0;
  15. $cg = PurchaseOrderClass::getById($id, true);
  16. if (isset($cg->mainId) == false || $cg->mainId != $this->mainId) {
  17. util::fail('没有权限');
  18. }
  19. $orderSn = $cg->orderSn ?? '';
  20. $list = PurchaseOrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*');
  21. if (!empty($list)) {
  22. $productIdList = array_column($list, 'productId');
  23. $itemList = ProductClass::getByIds($productIdList, null, 'id');
  24. foreach ($list as $key => $info) {
  25. $productId = $info['productId'] ?? 0;
  26. $cost = $info['cost'] ?? 0;
  27. $cost = round($cost);
  28. $current = $itemList[$productId] ?? [];
  29. $addPrice = $current['addPrice'] ?? 0;
  30. $skMore = $current['skMore'] ?? 0;
  31. $suggestPrice = bcadd($cost, $addPrice, 2);
  32. $suggestPrice = floatval($suggestPrice);
  33. $suggestSkPrice = bcadd($suggestPrice, $skMore, 2);
  34. $suggestSkPrice = floatval($suggestSkPrice);
  35. $list[$key]['suggestPrice'] = $suggestPrice;
  36. $list[$key]['suggestSkPrice'] = $suggestSkPrice;
  37. $list[$key]['skMore'] = $skMore;
  38. $list[$key]['addPrice'] = $addPrice;
  39. }
  40. }
  41. util::success(['list' => $list]);
  42. }
  43. }