StatItemController.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace hd\controllers;
  3. use biz\stat\classes\StatItemClass;
  4. use bizGhs\product\classes\ProductClass;
  5. use common\components\arrayUtil;
  6. use common\components\dateUtil;
  7. use Yii;
  8. use common\components\util;
  9. class StatItemController extends BaseController
  10. {
  11. //花材销量 ssh 20211021
  12. public function actionProfile()
  13. {
  14. util::success(['list' => []]);
  15. //数据不准确,重新开发
  16. //查看财务的权限
  17. $lookMoney = \bizGhs\shop\classes\ShopAdminClass::lookMoneyPower($this->shopAdmin, $this->shop);
  18. if ($lookMoney == 0) {
  19. util::fail('无法查看');
  20. }
  21. $get = Yii::$app->request->get();
  22. $where = [];
  23. $where['shopId'] = $this->shopId;
  24. if (isset($get['shopId']) && !empty($get['shopId'])) {
  25. $where['shopId'] = $get['shopId'];
  26. }
  27. $searchTime = $get['searchTime'] ?? 'today';
  28. if (!empty($searchTime)) {
  29. $startTime = $get['startTime'] ?? '';
  30. $endTime = $get['endTime'] ?? '';
  31. $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
  32. $where['time'] = ['between', [$period['startTime'], $period['endTime']]];
  33. }
  34. $list = StatItemClass::getAllByCondition($where, null, '*');
  35. if (empty($list)) {
  36. util::success(['list' => $list]);
  37. }
  38. $ids = array_column($list, 'itemId');
  39. $ids = array_unique(array_filter($ids));
  40. $productInfo = ProductClass::getByIds($ids, null, 'id');
  41. $stat = [];
  42. foreach ($list as $key => $val) {
  43. $itemId = $val['itemId'] ?? 0;
  44. $idsData[$itemId] = 0;
  45. $num = bcsub($val['num'], $val['refundNum'], 2);
  46. $amount = bcsub($val['amount'], $val['refundAmount'], 2);
  47. $name = $productInfo[$itemId]['name'] ?? '';
  48. $py = $productInfo[$itemId]['py'] ?? '';
  49. $stat[$itemId]['productId'] = $itemId;
  50. $stat[$itemId]['name'] = $name;
  51. $stat[$itemId]['py'] = $py;
  52. if (isset($stat[$itemId]['num'])) {
  53. $stat[$itemId]['num'] = bcadd($stat[$itemId]['num'], $num, 2);
  54. } else {
  55. $stat[$itemId]['num'] = $num;
  56. }
  57. if (isset($stat[$itemId]['amount'])) {
  58. $stat[$itemId]['amount'] = bcadd($stat[$itemId]['amount'], $amount, 2);
  59. } else {
  60. $stat[$itemId]['amount'] = $amount;
  61. }
  62. }
  63. $stat = arrayUtil::arraySort($stat, 'num');
  64. util::success(['list' => $stat]);
  65. }
  66. }