StatController.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\stat\classes\StatCgClass;
  4. use biz\stat\classes\StatPdAddClass;
  5. use biz\stat\classes\StatPdSubClass;
  6. use biz\stat\classes\StatRefundClass;
  7. use biz\stat\classes\StatSaleClass;
  8. use biz\stat\classes\StatStockInClass;
  9. use biz\stat\classes\StatStockOutClass;
  10. use biz\stat\classes\StatWastClass;
  11. use common\components\dateUtil;
  12. use Yii;
  13. use common\components\util;
  14. class StatController extends BaseController
  15. {
  16. //利润表 shish 20210829
  17. public function actionProfit()
  18. {
  19. $get = Yii::$app->request->get();
  20. $where = [];
  21. $where['shopId'] = $this->shopId;
  22. if (isset($get['shopId']) && !empty($get['shopId'])) {
  23. $where['shopId'] = $get['shopId'];
  24. }
  25. $selectTime = $get['selectTime'] ?? '';
  26. if (!empty($selectTime)) {
  27. $startTime = $get['startTime'] ?? '';
  28. $endTime = $get['endTime'] ?? '';
  29. $period = dateUtil::formatTime($selectTime, $startTime, $endTime, true);
  30. $where['time'] = ['between', [$period['startTime'], $period['endTime']]];
  31. }
  32. //开单
  33. $sale = StatSaleClass::getSum($where);
  34. //调拨出库
  35. $stockOut = StatStockOutClass::getSum($where);
  36. //盘盈
  37. $pdAdd = StatPdAddClass::getSum($where);
  38. //采购入库
  39. $cg = StatCgClass::getSum($where);
  40. //报损
  41. $wast = StatWastClass::getSum($where);
  42. //调拨入库
  43. $stockIn = StatStockInClass::getSum($where);
  44. //盘亏
  45. $pdSub = StatPdSubClass::getSum($where);
  46. //退款
  47. $refund = StatRefundClass::getSum($where);
  48. $balance = ($sale * 100 + $stockOut * 100 + $pdAdd * 100 - $cg * 100 - $wast * 100 - $stockIn * 100 - $pdSub * 100 - $refund * 100) / 100;
  49. $out = [
  50. 'income' => [
  51. ['name' => '销售', 'amount' => $sale],
  52. ['name' => '调拨出库', 'amount' => $stockOut],
  53. ['name' => '盘盈', 'amount' => $pdAdd],
  54. ],
  55. 'expend' => [
  56. ['name' => '采购', 'amount' => $cg],
  57. ['name' => '报损', 'amount' => $wast],
  58. ['name' => '调拨入库', 'amount' => $stockIn],
  59. ['name' => '盘亏', 'amount' => $pdSub],
  60. ['name' => '退款', 'amount' => $refund],
  61. ],
  62. 'balance' => $balance,
  63. ];
  64. util::success($out);
  65. }
  66. //统计列表 ssh 2020.1.5
  67. public function actionList()
  68. {
  69. $incomeStat = [
  70. 'total' => (185 + 381 + 662 + 443),
  71. 'list' => [
  72. ['name' => '2.6', 'num' => 185],
  73. ['name' => '2.7', 'num' => 381],
  74. ['name' => '2.8', 'num' => 662],
  75. ['name' => '2.9', 'num' => 443],
  76. ],
  77. ];
  78. $visitStat = [
  79. 'total' => (115 + 341 + 622 + 423),
  80. 'list' => [
  81. ['name' => '2.6', 'num' => 115],
  82. ['name' => '2.7', 'num' => 341],
  83. ['name' => '2.8', 'num' => 622],
  84. ['name' => '2.9', 'num' => 423],
  85. ],
  86. ];
  87. $userStat = [
  88. 'total' => (185 + 341 + 622 + 423),
  89. 'list' => [
  90. ['name' => '2.6', 'num' => 185],
  91. ['name' => '2.7', 'num' => 341],
  92. ['name' => '2.8', 'num' => 622],
  93. ['name' => '2.9', 'num' => 423],
  94. ],
  95. ];
  96. $fansStat = [
  97. 'total' => (185 + 241 + 322 + 553),
  98. 'list' => [
  99. ['name' => '2.6', 'num' => 185],
  100. ['name' => '2.7', 'num' => 241],
  101. ['name' => '2.8', 'num' => 322],
  102. ['name' => '2.9', 'num' => 553],
  103. ],
  104. ];
  105. $incomeSourceStat = [
  106. 'total' => (299 + 366 + 2995),
  107. 'list' => [
  108. ['name' => '门店', 'num' => 299],
  109. ['name' => '微信朋友圈', 'num' => 366],
  110. ['name' => '美团', 'num' => 2995],
  111. ],
  112. ];
  113. $categoryStat = [
  114. 'total' => (552 + 155 + 295 + 365 + 600 + 504),
  115. 'list' => [
  116. ['name' => '花束', 'num' => 552],
  117. ['name' => '花篮', 'num' => 155],
  118. ['name' => '蝴蝶兰', 'num' => 295],
  119. ['name' => '绿植', 'num' => 365],
  120. ['name' => '永生花', 'num' => 600],
  121. ['name' => '散花', 'num' => 504],
  122. ],
  123. ];
  124. $useStat = [
  125. 'total' => (552 + 155 + 295 + 365 + 600 + 504),
  126. 'list' => [
  127. ['name' => '年销花', 'num' => 552],
  128. ['name' => '送爱人', 'num' => 155],
  129. ['name' => '婚庆', 'num' => 295],
  130. ['name' => '开业', 'num' => 365],
  131. ['name' => '送母亲', 'num' => 600],
  132. ['name' => '生日', 'num' => 504],
  133. ]
  134. ];
  135. $data = ['incomeStat' => $incomeStat,
  136. 'visitStat' => $visitStat,
  137. 'userStat' => $userStat,
  138. 'fansStat' => $fansStat,
  139. 'incomeSourceStat' => $incomeSourceStat,
  140. 'categoryStat' => $categoryStat,
  141. 'useStat' => $useStat,
  142. ];
  143. util::success($data);
  144. }
  145. }