PaymentLogic.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace app\admin\logic;
  3. use app\common\model\PaymentModel;
  4. use app\common\model\ShopGoods;
  5. use think\facade\Cache;
  6. /**
  7. * 充值购买记录
  8. * Class ShopGoodsLogic
  9. * @package app\admin\logic
  10. */
  11. class PaymentLogic
  12. {
  13. /**
  14. * 支付统计
  15. * @param array $orderType 支付类型如:[4,5]
  16. * @param string $time 时间节点如:2023-03-01
  17. * @return mixed
  18. * @throws \think\db\exception\DbException
  19. */
  20. public static function getTotal(array $orderType, $time='0')
  21. {
  22. $cacheKey = "caches:payment:total_{$time}";
  23. if(!Cache::has($cacheKey)){
  24. $data = PaymentModel::whereIn('order_type', $orderType)
  25. ->where('state', 6)
  26. ->where(function($query) use($time){
  27. if($time){
  28. $query->where('creat_at','>=', $time);
  29. }
  30. })->sum('total_fee');
  31. if($data){
  32. Cache::set($cacheKey, $data, rand(3,5));
  33. }
  34. return $data;
  35. }
  36. return Cache::get($cacheKey);
  37. }
  38. }