StatKdController.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace ghs\controllers;
  3. use bizGhs\order\classes\NextDayRefundClass;
  4. use bizGhs\shop\classes\ShopAdminClass;
  5. use bizGhs\stat\classes\StatKdClass;
  6. use common\components\dateUtil;
  7. use common\components\util;
  8. use Yii;
  9. class StatKdController extends BaseController
  10. {
  11. /**
  12. * 各渠道收入:ghsApp kdIncome、PC ghs /assets/kdIncome 共用。
  13. * timeType=bill 按账单日 payTime(默认);=send 按发货 sendTime(仅已付款)。
  14. */
  15. public function actionProfile()
  16. {
  17. ini_set('memory_limit', '5045M');
  18. set_time_limit(0);
  19. //查看财务的权限
  20. $lookMoney = ShopAdminClass::lookMoneyPower($this->shopAdmin, $this->shop);
  21. if ($lookMoney == 0) {
  22. util::fail('无法查看');
  23. }
  24. //惠雅鲜花员工不能看收入情况
  25. $shopAdmin = $this->shopAdmin;
  26. $adminId = $shopAdmin->adminId ?? 0;
  27. if (in_array($adminId, [2366, 2812, 4004, 3405, 3407])) {
  28. util::fail('暂无权限');
  29. }
  30. $get = Yii::$app->request->get();
  31. $contain = $get['contain'] ?? 0;
  32. $return = StatKdClass::eachChannelIncome($this->mainId, $this->shop, $contain);
  33. $incomeList = $return['incomeList'];
  34. $staffAmountList = $return['staffAmountList'];
  35. $payCodeIncome = $return['payCodeIncome'];
  36. $lsAfterSale = $return['lsAfterSale'];
  37. $totalIncome = 0;
  38. if (!empty($incomeList)) {
  39. foreach ($incomeList as $item) {
  40. $amount = $item['amount'] ?? 0;
  41. $totalIncome = bcadd($totalIncome, $amount, 2);
  42. $totalIncome = floatval($totalIncome);
  43. }
  44. }
  45. util::success(['list' => $incomeList, 'totalIncome' => $totalIncome, 'staffAmountList' => $staffAmountList, 'payCodeIncome' => $payCodeIncome]);
  46. }
  47. /**
  48. * 跨天售后影响:筛售后创建时间,按原单账单日汇总日/月金额。
  49. * PC /assets/nextDayAffect 使用;只计挂上 xhGhsOrder 的已通过跨天售后。
  50. */
  51. public function actionNextDayAffect()
  52. {
  53. $lookMoney = ShopAdminClass::lookMoneyPower($this->shopAdmin, $this->shop);
  54. if ($lookMoney == 0) {
  55. util::fail('无法查看');
  56. }
  57. $get = Yii::$app->request->get();
  58. $searchTime = isset($get['searchTime']) && !empty($get['searchTime']) ? $get['searchTime'] : 'today';
  59. $startTime = $get['startTime'] ?? '';
  60. $endTime = $get['endTime'] ?? '';
  61. // 自系统升级以来:跨天售后从 2026-08-18 起算,结束用当前时刻
  62. if ($searchTime === 'sinceUpgrade') {
  63. $period = [
  64. 'startTime' => '2026-08-18 00:00:00',
  65. 'endTime' => date('Y-m-d H:i:s'),
  66. ];
  67. } else {
  68. // 售后 addTime 用完整时分秒,不能走统计页的 Ymd
  69. $period = dateUtil::formatTime($searchTime, $startTime, $endTime, false);
  70. }
  71. $data = NextDayRefundClass::affectByOrderPayTime(
  72. $this->mainId,
  73. $period['startTime'],
  74. $period['endTime']
  75. );
  76. util::success($data);
  77. }
  78. }