TradeService.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2017~2021 LARAVEL研发中心
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://www.laravel.cn
  8. // +----------------------------------------------------------------------
  9. // | Author: laravel开发员 <laravel.qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace App\Services\Common;
  12. use App\Models\TradeModel;
  13. use App\Services\BaseService;
  14. /**
  15. * 交易管理-服务类
  16. * @author laravel开发员
  17. * @since 2020/11/11
  18. * Class TradeService
  19. * @package App\Services\Common
  20. */
  21. class TradeService extends BaseService
  22. {
  23. // 静态对象
  24. protected static $instance = null;
  25. /**
  26. * 构造函数
  27. * @author laravel开发员
  28. * @since 2020/11/11
  29. * TradeService constructor.
  30. */
  31. public function __construct()
  32. {
  33. $this->model = new TradeModel();
  34. }
  35. /**
  36. * 静态入口
  37. * @return static|null
  38. */
  39. public static function make()
  40. {
  41. if (!self::$instance) {
  42. self::$instance = (new static());
  43. }
  44. return self::$instance;
  45. }
  46. /**
  47. * 添加或编辑
  48. * @return array
  49. * @since 2020/11/11
  50. * @author laravel开发员
  51. */
  52. public function edit()
  53. {
  54. $data = request()->all();
  55. return parent::edit($data); // TODO: Change the autogenerated stub
  56. }
  57. /**
  58. * 获取店铺交易统计
  59. * @param $shopId
  60. * @param int $type
  61. * @param int $coinType
  62. * @return mixed
  63. */
  64. public function getShopTradeTotal($shopId, $status=0)
  65. {
  66. $where = ['shop_id'=>$shopId,'mark'=>1];
  67. if($status){
  68. $where['status'] = $status;
  69. }
  70. return $this->model->where($where)
  71. ->sum('price');
  72. }
  73. /**
  74. * 获取交易数
  75. * @param $shopId
  76. * @param int $type
  77. * @param int $coinType
  78. * @return mixed
  79. */
  80. public function getShopTradeCount($shopId, $status = 0)
  81. {
  82. $where = ['shop_id'=>$shopId,'mark'=>1];
  83. if($status){
  84. $where['status'] = $status;
  85. }
  86. return $this->model->where($where)
  87. ->count('id');
  88. }
  89. /**
  90. * 抢拍交易订单数
  91. * @param $userId 用户ID
  92. * @param int $status 状态
  93. * @return mixed
  94. */
  95. public function getNewTradeCountByStatus($userId, $status=0, $time=30)
  96. {
  97. $where = ['user_id'=>$userId,'mark'=>1,'is_read'=>1];
  98. return $this->model->where($where)
  99. ->where(function($query) use($status){
  100. $query->whereIn('status',is_array($status)? $status:[$status]);
  101. })
  102. ->where(function($query) use($time){
  103. if($time){
  104. $query->where('update_time','>', $time);
  105. }
  106. })
  107. ->groupBy('status')
  108. ->count();
  109. }
  110. }