MemberCouponService.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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\ActionLogModel;
  13. use App\Models\MemberCouponModel;
  14. use App\Services\BaseService;
  15. /**
  16. * 优惠券领取记录管理-服务类
  17. * @author laravel开发员
  18. * @since 2020/11/11
  19. * Class MemberCouponService
  20. * @package App\Services\Common
  21. */
  22. class MemberCouponService extends BaseService
  23. {
  24. // 静态对象
  25. protected static $instance = null;
  26. /**
  27. * 构造函数
  28. * @author laravel开发员
  29. * @since 2020/11/11
  30. */
  31. public function __construct()
  32. {
  33. $this->model = new MemberCouponModel();
  34. }
  35. /**
  36. * 静态入口
  37. */
  38. public static function make()
  39. {
  40. if (!self::$instance) {
  41. self::$instance = new static();
  42. }
  43. return self::$instance;
  44. }
  45. /**
  46. * 列表
  47. * @param $params
  48. * @param int $pageSize
  49. * @return array
  50. */
  51. public function getDataList($params, $pageSize = 15)
  52. {
  53. $where = ['a.mark' => 1];
  54. $list = $this->model->from('member_coupon as a')
  55. ->leftJoin('member as b','b.id','=','a.user_id')
  56. ->where($where)
  57. ->where(function ($query) use($params){
  58. $keyword = isset($params['keyword'])? $params['keyword'] : '';
  59. if($keyword){
  60. $query->where('a.name','like',"%{$keyword}%")
  61. ->orWhere('b.nickname','like',"%{$keyword}%")
  62. ->orWhere('b.mobile','like',"%{$keyword}%");
  63. }
  64. })
  65. ->where(function ($query) use($params){
  66. $status = isset($params['status'])? $params['status'] : 0;
  67. if($status>0 && is_array($status)){
  68. $query->whereIn('a.status', $status);
  69. }else if($status){
  70. $query->where('a.status', $status);
  71. }
  72. $type = isset($params['type'])? $params['type'] : 0;
  73. if($type>0){
  74. $query->where('a.type', $type);
  75. }
  76. $couponId = isset($params['coupon_id'])? $params['coupon_id'] : 0;
  77. if($couponId>0){
  78. $query->where('a.coupon_id', $couponId);
  79. }
  80. $couponType = isset($params['coupon_type'])? $params['coupon_type'] : 0;
  81. if($couponType>0){
  82. $query->where('a.coupon_type', $couponType);
  83. }
  84. })
  85. ->select(['a.*','b.nickname','b.mobile'])
  86. ->orderBy('a.create_time','desc')
  87. ->orderBy('a.id','desc')
  88. ->paginate($pageSize > 0 ? $pageSize : 9999999);
  89. $list = $list? $list->toArray() :[];
  90. if($list){
  91. foreach($list['data'] as &$item){
  92. $item['create_time'] = $item['create_time']? datetime($item['create_time'],'Y-m-d H.i.s') : '';
  93. $item['start_time'] = $item['start_time']? datetime($item['start_time'],'Y-m-d H.i.s') : '';
  94. $item['end_time'] = $item['end_time']? datetime($item['end_time'],'Y-m-d H.i.s') : '';
  95. $item['username'] = $item['nickname']? ($item['nickname'].($item['mobile']?'-'.$item['mobile']:'')) : '';
  96. $item['icon'] = $item['icon']? get_image_url($item['icon']) : '';
  97. }
  98. }
  99. return [
  100. 'pageSize'=> $pageSize,
  101. 'total'=>isset($list['total'])? $list['total'] : 0,
  102. 'list'=> isset($list['data'])? $list['data'] : []
  103. ];
  104. }
  105. /**
  106. * 编辑
  107. * @return array
  108. */
  109. public function edit()
  110. {
  111. $data = request()->post();
  112. // 设置日志标题
  113. ActionLogModel::setTitle("发放优惠券");
  114. ActionLogModel::record();
  115. return parent::edit($data);
  116. }
  117. }