StatCgGhsController.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace hd\controllers;
  3. use biz\ghs\classes\GhsClass;
  4. use biz\stat\classes\StatCgGhsClass;
  5. use common\components\arrayUtil;
  6. use common\components\dateUtil;
  7. use Yii;
  8. use common\components\util;
  9. class StatCgGhsController extends BaseController
  10. {
  11. //采购列表 ssh 20211017
  12. public function actionProfile()
  13. {
  14. $get = Yii::$app->request->get();
  15. $where = [];
  16. $where['mainId'] = $this->mainId;
  17. $searchTime = $get['searchTime'] ?? 'today';
  18. if (!empty($searchTime)) {
  19. $startTime = $get['startTime'] ?? '';
  20. $endTime = $get['endTime'] ?? '';
  21. $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
  22. $where['time'] = ['between', [$period['startTime'], $period['endTime']]];
  23. }
  24. $list = StatCgGhsClass::getAllByCondition($where, null, '*');
  25. $ghsIds = [];
  26. $arr = [];
  27. if (!empty($list)) {
  28. foreach ($list as $ke => $item) {
  29. $ghsId = $item['ghsId'] ?? 0;
  30. $num = $item['num'] ?? 0;
  31. $refundNum = $item['refundNum'] ?? 0;
  32. $amount = $item['amount'] ?? 0;
  33. $refundAmount = $item['refundAmount'] ?? 0;
  34. $ghsIds[$ghsId] = 1;
  35. if (isset($arr[$ghsId]['num'])) {
  36. $arr[$ghsId]['num'] = bcadd($arr[$ghsId]['num'], $num, 2);
  37. } else {
  38. $arr[$ghsId]['num'] = $num;
  39. }
  40. if (isset($arr[$ghsId]['refundNum'])) {
  41. $arr[$ghsId]['refundNum'] = bcadd($arr[$ghsId]['refundNum'], $refundNum, 2);
  42. } else {
  43. $arr[$ghsId]['refundNum'] = $refundNum;
  44. }
  45. if (isset($arr[$ghsId]['amount'])) {
  46. $arr[$ghsId]['amount'] = bcadd($arr[$ghsId]['amount'], $amount, 2);
  47. } else {
  48. $arr[$ghsId]['amount'] = $amount;
  49. }
  50. if (isset($arr[$ghsId]['refundAmount'])) {
  51. $arr[$ghsId]['refundAmount'] = bcadd($arr[$ghsId]['refundAmount'], $refundAmount, 2);
  52. } else {
  53. $arr[$ghsId]['refundAmount'] = $refundAmount;
  54. }
  55. }
  56. }
  57. $ghsIds = array_keys($ghsIds);
  58. $ghsData = GhsClass::getByIds($ghsIds);
  59. $cg = [];
  60. foreach ($ghsData as $ghs) {
  61. $ghsId = $ghs['id'] ?? 0;
  62. $ghsName = $ghs['name'] ?? '';
  63. $ghsPy = $ghs['py'] ?? '';
  64. $num = $arr[$ghsId]['num'] ?? 0;
  65. $refundNum = $arr[$ghsId]['refundNum'] ?? 0;
  66. $amount = $arr[$ghsId]['amount'] ?? 0;
  67. $refundAmount = $arr[$ghsId]['refundAmount'] ?? 0;
  68. $lastAmount = bcsub($amount, $refundAmount, 2);
  69. $lastNum = bcsub($num, $refundNum, 2);
  70. $cg[] = [
  71. 'ghsId' => $ghsId,
  72. 'ghsName' => $ghsName,
  73. 'py' => $ghsPy,
  74. 'num' => $lastNum,
  75. 'amount' => $lastAmount,
  76. ];
  77. }
  78. $cg = arrayUtil::arraySort($cg, 'num');
  79. util::success(['list' => $cg]);
  80. }
  81. }