StatCgController.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 StatCgController extends BaseController
  10. {
  11. //一整年采购了哪些花材
  12. //还可以选择供货商
  13. //做一个需求反馈的入口
  14. public function actionProfile()
  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. }