MemberCouponService.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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\Api;
  12. use App\Models\MemberAddressModel;
  13. use App\Models\MemberCouponModel;
  14. use App\Services\BaseService;
  15. use App\Services\RedisService;
  16. use Illuminate\Support\Facades\DB;
  17. /**
  18. * 用户优惠券管理-服务类
  19. * @author laravel开发员
  20. * @since 2020/11/11
  21. * @package App\Services\Api
  22. */
  23. class MemberCouponService extends BaseService
  24. {
  25. // 静态对象
  26. protected static $instance = null;
  27. /**
  28. * 构造函数
  29. * @author laravel开发员
  30. * @since 2020/11/11
  31. */
  32. public function __construct()
  33. {
  34. $this->model = new MemberCouponModel();
  35. }
  36. /**
  37. * 静态入口
  38. * @return static|null
  39. */
  40. public static function make()
  41. {
  42. if (!self::$instance) {
  43. self::$instance = (new static());
  44. }
  45. return self::$instance;
  46. }
  47. /**
  48. * 列表数据
  49. * @param $params
  50. * @param int $pageSize
  51. * @return array
  52. */
  53. public function getDataList($params, $pageSize = 15)
  54. {
  55. $where = ['a.mark' => 1,'a.status'=>1];
  56. $status = isset($params['status']) ? $params['status'] : 0;
  57. if ($status > 0) {
  58. $where['a.status'] = $status;
  59. }
  60. $userId = isset($params['user_id']) ? $params['user_id'] : 0;
  61. if ($userId > 0) {
  62. $where['a.user_id'] = $userId;
  63. }
  64. $list = $this->model->from('member_coupons as a')
  65. ->where($where)
  66. ->where(function($query) use($params){
  67. $ids = isset($params['ids'])?$params['ids']:[];
  68. if($ids){
  69. $query->where(function($query) use($ids){
  70. $query->where('goods_ids','')
  71. ->orWhereRaw("FIND_IN_SET(?, goods_ids)",[implode(',', $ids)]);
  72. });
  73. }else{
  74. $query->where('goods_ids','=','');
  75. }
  76. $total = isset($params['total'])?$params['total']:0;
  77. if($total){
  78. $query->where(function($query) use($total){
  79. $query->whereIn('a.coupon_type',[20,30])
  80. ->orWhere(function($query) use($total){
  81. $query->where('a.coupon_type','=',10)
  82. ->where('a.min_price','<=', $total);
  83. });
  84. });
  85. }
  86. })
  87. ->select(['a.*'])
  88. ->orderBy('a.reduce_prices', 'desc')
  89. ->orderBy('a.id', 'desc')
  90. ->paginate($pageSize > 0 ? $pageSize : 9999999);
  91. $list = $list ? $list->toArray() : [];
  92. return [
  93. 'pageSize' => $pageSize,
  94. 'total' => isset($list['total']) ? $list['total'] : 0,
  95. 'list' => isset($list['data']) ? $list['data'] : []
  96. ];
  97. }
  98. /**
  99. * 可领取列表
  100. * @param $params
  101. * @param int $pageSize
  102. * @return array
  103. */
  104. public function getCouponList($params, $pageSize = 15)
  105. {
  106. $where = ['a.mark' => 1,'a.status'=>1];
  107. $status = isset($params['status']) ? $params['status'] : 0;
  108. if ($status > 0) {
  109. $where['a.status'] = $status;
  110. }
  111. $list = $this->model->from('coupons as a')
  112. ->where($where)
  113. ->where(function($query) use($params){
  114. $query->whereIn('a.coupon_type',[10,30])
  115. ->whereRaw('num > received_num')
  116. ->where('receive_at','<=', date('Y-m-d H:i:s'));
  117. })
  118. ->select(['a.*'])
  119. ->orderBy('a.id', 'desc')
  120. ->paginate($pageSize > 0 ? $pageSize : 9999999);
  121. $list = $list ? $list->toArray() : [];
  122. return [
  123. 'pageSize' => $pageSize,
  124. 'total' => isset($list['total']) ? $list['total'] : 0,
  125. 'list' => isset($list['data']) ? $list['data'] : []
  126. ];
  127. }
  128. }