| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- <?php
- // +----------------------------------------------------------------------
- // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
- // +----------------------------------------------------------------------
- // | 版权所有 2017~2021 LARAVEL研发中心
- // +----------------------------------------------------------------------
- // | 官方网站: http://www.laravel.cn
- // +----------------------------------------------------------------------
- // | Author: laravel开发员 <laravel.qq.com>
- // +----------------------------------------------------------------------
- namespace App\Services\Api;
- use App\Models\MemberAddressModel;
- use App\Models\MemberCouponModel;
- use App\Services\BaseService;
- use App\Services\RedisService;
- use Illuminate\Support\Facades\DB;
- /**
- * 用户优惠券管理-服务类
- * @author laravel开发员
- * @since 2020/11/11
- * @package App\Services\Api
- */
- class MemberCouponService extends BaseService
- {
- // 静态对象
- protected static $instance = null;
- /**
- * 构造函数
- * @author laravel开发员
- * @since 2020/11/11
- */
- public function __construct()
- {
- $this->model = new MemberCouponModel();
- }
- /**
- * 静态入口
- * @return static|null
- */
- public static function make()
- {
- if (!self::$instance) {
- self::$instance = (new static());
- }
- return self::$instance;
- }
- /**
- * 列表数据
- * @param $params
- * @param int $pageSize
- * @return array
- */
- public function getDataList($params, $pageSize = 15)
- {
- $where = ['a.mark' => 1,'a.status'=>1];
- $status = isset($params['status']) ? $params['status'] : 0;
- if ($status > 0) {
- $where['a.status'] = $status;
- }
- $userId = isset($params['user_id']) ? $params['user_id'] : 0;
- if ($userId > 0) {
- $where['a.user_id'] = $userId;
- }
- $list = $this->model->from('member_coupons as a')
- ->where(function($query) use($params){
- $ids = isset($params['ids'])?$params['ids']:[];
- if($ids){
- $query->where(function($query) use($ids){
- $query->where('a.goods_ids','');
- foreach ($ids as $id){
- $query->orWhere('a.goods_ids','like', "%{$id},%");
- }
- });
- }else{
- $query->where('goods_ids','=','');
- }
- $total = isset($params['total'])?$params['total']:0;
- if($total){
- $query->where(function($query) use($total){
- $query->whereIn('a.coupon_type',[20,30])
- ->orWhere(function($query) use($total){
- $query->where('a.coupon_type','=',10)
- ->where('a.min_price','<=', $total);
- });
- });
- }
- })
- ->where($where)
- ->select(['a.*'])
- ->orderBy('a.reduce_price', 'desc')
- ->orderBy('a.id', 'desc')
- ->paginate($pageSize > 0 ? $pageSize : 9999999);
- $list = $list ? $list->toArray() : [];
- return [
- 'pageSize' => $pageSize,
- 'total' => isset($list['total']) ? $list['total'] : 0,
- 'list' => isset($list['data']) ? $list['data'] : []
- ];
- }
- /**
- * 可领取列表
- * @param $params
- * @param int $pageSize
- * @return array
- */
- public function getCouponList($params, $pageSize = 15)
- {
- $where = ['a.mark' => 1,'a.status'=>1];
- $status = isset($params['status']) ? $params['status'] : 0;
- if ($status > 0) {
- $where['a.status'] = $status;
- }
- $list = $this->model->from('coupons as a')
- ->where($where)
- ->where(function($query) use($params){
- $query->whereIn('a.coupon_type',[10,30])
- ->whereRaw('num > received_num')
- ->where('receive_at','<=', date('Y-m-d H:i:s'));
- })
- ->select(['a.*'])
- ->orderBy('a.id', 'desc')
- ->paginate($pageSize > 0 ? $pageSize : 9999999);
- $list = $list ? $list->toArray() : [];
- return [
- 'pageSize' => $pageSize,
- 'total' => isset($list['total']) ? $list['total'] : 0,
- 'list' => isset($list['data']) ? $list['data'] : []
- ];
- }
- }
|