StatController.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace ghs\controllers;
  3. use bizGhs\order\classes\StockWastageOrderItemClass;
  4. use bizGhs\stat\classes\StatSaleClass;
  5. use common\components\arrayUtil;
  6. use common\components\imgUtil;
  7. use Yii;
  8. use common\components\util;
  9. use common\components\dateUtil;
  10. class StatController extends BaseController
  11. {
  12. public function actionProfit()
  13. {
  14. ini_set('memory_limit', '2045M');
  15. set_time_limit(0);
  16. $shopAdmin = $this->shopAdmin;
  17. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  18. util::fail('超管才能查看');
  19. }
  20. //惠雅鲜花员工不能看利润表
  21. $shopAdmin = $this->shopAdmin;
  22. $adminId = $shopAdmin->adminId ?? 0;
  23. if (in_array($adminId, [3405, 2812, 4004,2812])) {
  24. util::fail('暂无权限');
  25. }
  26. $mainId = $this->mainId;
  27. $respond = StatSaleClass::profile($mainId);
  28. $income = $respond['income'] ?? 0;
  29. $expend = $respond['expend'] ?? 0;
  30. $balance = $respond['balance'] ?? 0;
  31. util::success(['income' => $income, 'expend' => $expend, 'balance' => floatval($balance)]);
  32. }
  33. public function actionWastage()
  34. {
  35. $get = Yii::$app->request->get();
  36. $where = [];
  37. $where['mainId'] = $this->mainId;
  38. $searchTime = $get['searchTime'] ?? 'today';
  39. if (!empty($searchTime)) {
  40. $startTime = $get['startTime'] ?? '';
  41. $endTime = $get['endTime'] ?? '';
  42. $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
  43. $start = date("Y-m-d 00:00:00", strtotime($period['startTime']));
  44. $end = date("Y-m-d 23:59:59", strtotime($period['endTime']));
  45. $where['addTime'] = ['between', [$start, $end]];
  46. }
  47. $wastageList = StockWastageOrderItemClass::getAllByCondition($where, null, '*', null, true);
  48. $stat = [];
  49. $totalCost = 0;
  50. $totalNum = 0;
  51. if (!empty($wastageList)) {
  52. foreach ($wastageList as $waste) {
  53. $name = $waste->name ?? '';
  54. $shortCover = $waste->cover ?? '';
  55. $cover = imgUtil::groupImg($shortCover);
  56. $num = $waste->itemNum ?? 0;
  57. $cost = $waste->itemCost ?? 0;
  58. $currentCost = bcmul($cost, $num, 2);
  59. $productId = $waste->productId ?? 0;
  60. if (isset($stat[$productId]) == false) {
  61. $stat[$productId]['name'] = $name;
  62. $stat[$productId]['cover'] = $cover;
  63. $stat[$productId]['num'] = 0;
  64. $stat[$productId]['amount'] = 0;
  65. }
  66. $stat[$productId]['num'] = bcadd($stat[$productId]['num'], $num, 2);
  67. $stat[$productId]['amount'] = bcadd($stat[$productId]['amount'], $currentCost, 2);
  68. $totalNum = bcadd($totalNum, $num, 2);
  69. $totalCost = bcadd($totalCost, $currentCost, 2);
  70. }
  71. $stat = array_values($stat);
  72. $stat = arrayUtil::arraySort($stat, 'num');
  73. }
  74. util::success(['stat' => $stat, 'totalNum' => $totalNum, 'totalCost' => $totalCost]);
  75. }
  76. }