StatCgGhsController.php 3.2 KB

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