StatCgGhsController.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. util::success(['list' => []]);
  15. //数据不准确,重新开发
  16. $get = Yii::$app->request->get();
  17. $where = [];
  18. $where['mainId'] = $this->mainId;
  19. $searchTime = $get['searchTime'] ?? 'today';
  20. if (!empty($searchTime)) {
  21. $startTime = $get['startTime'] ?? '';
  22. $endTime = $get['endTime'] ?? '';
  23. $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
  24. $where['time'] = ['between', [$period['startTime'], $period['endTime']]];
  25. }
  26. $list = StatCgGhsClass::getAllByCondition($where, null, '*');
  27. $ghsIds = [];
  28. $arr = [];
  29. if (!empty($list)) {
  30. foreach ($list as $ke => $item) {
  31. $ghsId = $item['ghsId'] ?? 0;
  32. $num = $item['num'] ?? 0;
  33. $refundNum = $item['refundNum'] ?? 0;
  34. $amount = $item['amount'] ?? 0;
  35. $refundAmount = $item['refundAmount'] ?? 0;
  36. $ghsIds[$ghsId] = 1;
  37. if (isset($arr[$ghsId]['num'])) {
  38. $arr[$ghsId]['num'] = bcadd($arr[$ghsId]['num'], $num, 2);
  39. } else {
  40. $arr[$ghsId]['num'] = $num;
  41. }
  42. if (isset($arr[$ghsId]['refundNum'])) {
  43. $arr[$ghsId]['refundNum'] = bcadd($arr[$ghsId]['refundNum'], $refundNum, 2);
  44. } else {
  45. $arr[$ghsId]['refundNum'] = $refundNum;
  46. }
  47. if (isset($arr[$ghsId]['amount'])) {
  48. $arr[$ghsId]['amount'] = bcadd($arr[$ghsId]['amount'], $amount, 2);
  49. } else {
  50. $arr[$ghsId]['amount'] = $amount;
  51. }
  52. if (isset($arr[$ghsId]['refundAmount'])) {
  53. $arr[$ghsId]['refundAmount'] = bcadd($arr[$ghsId]['refundAmount'], $refundAmount, 2);
  54. } else {
  55. $arr[$ghsId]['refundAmount'] = $refundAmount;
  56. }
  57. }
  58. }
  59. $ghsIds = array_keys($ghsIds);
  60. $ghsData = GhsClass::getByIds($ghsIds);
  61. $cg = [];
  62. foreach ($ghsData as $ghs) {
  63. $ghsId = $ghs['id'] ?? 0;
  64. $ghsName = $ghs['name'] ?? '';
  65. $ghsPy = $ghs['py'] ?? '';
  66. $num = $arr[$ghsId]['num'] ?? 0;
  67. $refundNum = $arr[$ghsId]['refundNum'] ?? 0;
  68. $amount = $arr[$ghsId]['amount'] ?? 0;
  69. $refundAmount = $arr[$ghsId]['refundAmount'] ?? 0;
  70. $lastAmount = bcsub($amount, $refundAmount, 2);
  71. $lastNum = bcsub($num, $refundNum, 2);
  72. $cg[] = [
  73. 'ghsId' => $ghsId,
  74. 'ghsName' => $ghsName,
  75. 'py' => $ghsPy,
  76. 'num' => $lastNum,
  77. 'amount' => $lastAmount,
  78. ];
  79. }
  80. $cg = arrayUtil::arraySort($cg, 'num');
  81. util::success(['list' => $cg]);
  82. }
  83. }