StatKhCgController.php 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\stat\classes\StatKhCgClass;
  4. use bizGhs\custom\classes\CustomClass;
  5. use common\components\arrayUtil;
  6. use common\components\dateUtil;
  7. use Yii;
  8. use common\components\util;
  9. class StatKhCgController extends BaseController
  10. {
  11. //客户采购列表 ssh 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 = StatKhCgClass::getAllByCondition($where, null, '*');
  28. $customIds = [];
  29. $arr = [];
  30. if (!empty($list)) {
  31. foreach ($list as $ke => $item) {
  32. $customId = $item['customId'] ?? 0;
  33. $num = $item['num'] ?? 0;
  34. $refundNum = $item['refundNum'] ?? 0;
  35. $amount = $item['amount'] ?? 0;
  36. $refundAmount = $item['refundAmount'] ?? 0;
  37. $customIds[$customId] = 1;
  38. if (isset($arr[$customId]['num'])) {
  39. $arr[$customId]['num'] = bcadd($arr[$customId]['num'], $num, 2);
  40. } else {
  41. $arr[$customId]['num'] = $num;
  42. }
  43. if (isset($arr[$customId]['refundNum'])) {
  44. $arr[$customId]['refundNum'] = bcadd($arr[$customId]['refundNum'], $refundNum, 2);
  45. } else {
  46. $arr[$customId]['refundNum'] = $refundNum;
  47. }
  48. if (isset($arr[$customId]['amount'])) {
  49. $arr[$customId]['amount'] = bcadd($arr[$customId]['amount'], $amount, 2);
  50. } else {
  51. $arr[$customId]['amount'] = $amount;
  52. }
  53. if (isset($arr[$customId]['refundAmount'])) {
  54. $arr[$customId]['refundAmount'] = bcadd($arr[$customId]['refundAmount'], $refundAmount, 2);
  55. } else {
  56. $arr[$customId]['refundAmount'] = $refundAmount;
  57. }
  58. }
  59. }
  60. $customIds = array_keys($customIds);
  61. $customData = CustomClass::getByIds($customIds);
  62. $map = CustomClass::$levelMap;
  63. $cg = [];
  64. foreach ($customData as $custom) {
  65. $customId = $custom['id'] ?? 0;
  66. $customName = $custom['name'] ?? '';
  67. $customPy = $custom['py'] ?? '';
  68. $num = $arr[$customId]['num'] ?? 0;
  69. $refundNum = $arr[$customId]['refundNum'] ?? 0;
  70. $amount = $arr[$customId]['amount'] ?? 0;
  71. $refundAmount = $arr[$customId]['refundAmount'] ?? 0;
  72. $lastAmount = bcsub($amount, $refundAmount, 2);
  73. $lastNum = bcsub($num, $refundNum, 2);
  74. $level = $custom['level'] ?? 0;
  75. $levelName = $map[$level] ?? '';
  76. $cg[] = [
  77. 'customId' => $customId,
  78. 'customName' => $customName,
  79. 'py' => $customPy,
  80. 'num' => $lastNum,
  81. 'amount' => $lastAmount,
  82. 'levelName' => $levelName,
  83. ];
  84. }
  85. $cg = arrayUtil::arraySort($cg, 'num');
  86. util::success(['list' => $cg]);
  87. }
  88. }