StatIncomeService.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace bizHd\stat\services;
  3. use bizHd\base\services\BaseService;
  4. use bizHd\stat\classes\StatIncomeClass;
  5. use common\components\dateUtil;
  6. use common\components\util;
  7. use Yii;
  8. class StatIncomeService extends BaseService
  9. {
  10. public static $baseFile = '\bizHd\stat\classes\StatIncomeClass';
  11. //取今天的数据 ssh 2019.9.8
  12. public static function getTodayNum($mainId)
  13. {
  14. $today = date("Ymd");
  15. return StatIncomeClass::getByCondition(['time' => $today, 'mainId' => $mainId]);
  16. }
  17. public static function checkUp($id, $sjId)
  18. {
  19. $stat = self::getById($id, true);
  20. if ($stat->sjId != $sjId) {
  21. util::fail('你没有权限');
  22. }
  23. if ($stat->checkUp == 1) {
  24. util::fail('你已经对过帐了');
  25. }
  26. $stat->checkUp = 1;
  27. $stat->save();
  28. return true;
  29. }
  30. //获取最近的收入情况 ssh 2019.9.21
  31. public static function getLatestIncome($start, $end, $shopId)
  32. {
  33. $list = self::getAllList('*', ['shopId' => $shopId, 'time' => ['between', [$start, $end]]], 'time asc');
  34. return $list;
  35. }
  36. //最近7天收入情况 ssh 2020.2.2
  37. public static function getLatestSevenDay($shopId)
  38. {
  39. $return = dateUtil::getDate(2);
  40. $start = $return[0];
  41. $end = $return[1];
  42. $list = self::getLatestIncome($start, $end, $shopId);
  43. $data = [];
  44. if (!empty($list)) {
  45. foreach ($list as $key => $val) {
  46. $date = date('n-j', strtotime($val['time']));
  47. $income = $val['amount'];
  48. $data[$date] = $income;
  49. }
  50. }
  51. return $data;
  52. }
  53. }