// +---------------------------------------------------------------------- namespace App\Services\Common; use App\Models\ActionLogModel; use App\Models\MemberCouponModel; use App\Services\BaseService; /** * 优惠券领取记录管理-服务类 * @author laravel开发员 * @since 2020/11/11 * Class MemberCouponService * @package App\Services\Common */ class MemberCouponService extends BaseService { // 静态对象 protected static $instance = null; /** * 构造函数 * @author laravel开发员 * @since 2020/11/11 */ public function __construct() { $this->model = new MemberCouponModel(); } /** * 静态入口 */ 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]; $list = $this->model->from('member_coupon as a') ->leftJoin('member as b','b.id','=','a.user_id') ->where($where) ->where(function ($query) use($params){ $keyword = isset($params['keyword'])? $params['keyword'] : ''; if($keyword){ $query->where('a.name','like',"%{$keyword}%") ->orWhere('b.nickname','like',"%{$keyword}%") ->orWhere('b.mobile','like',"%{$keyword}%"); } }) ->where(function ($query) use($params){ $status = isset($params['status'])? $params['status'] : 0; if($status>0 && is_array($status)){ $query->whereIn('a.status', $status); }else if($status){ $query->where('a.status', $status); } $type = isset($params['type'])? $params['type'] : 0; if($type>0){ $query->where('a.type', $type); } $couponId = isset($params['coupon_id'])? $params['coupon_id'] : 0; if($couponId>0){ $query->where('a.coupon_id', $couponId); } $couponType = isset($params['coupon_type'])? $params['coupon_type'] : 0; if($couponType>0){ $query->where('a.coupon_type', $couponType); } }) ->select(['a.*','b.nickname','b.mobile']) ->orderBy('a.create_time','desc') ->orderBy('a.id','desc') ->paginate($pageSize > 0 ? $pageSize : 9999999); $list = $list? $list->toArray() :[]; if($list){ foreach($list['data'] as &$item){ $item['create_time'] = $item['create_time']? datetime($item['create_time'],'Y-m-d H.i.s') : ''; $item['start_time'] = $item['start_time']? datetime($item['start_time'],'Y-m-d H.i.s') : ''; $item['end_time'] = $item['end_time']? datetime($item['end_time'],'Y-m-d H.i.s') : ''; $item['username'] = $item['nickname']? ($item['nickname'].($item['mobile']?'-'.$item['mobile']:'')) : ''; $item['icon'] = $item['icon']? get_image_url($item['icon']) : ''; } } return [ 'pageSize'=> $pageSize, 'total'=>isset($list['total'])? $list['total'] : 0, 'list'=> isset($list['data'])? $list['data'] : [] ]; } /** * 编辑 * @return array */ public function edit() { $data = request()->post(); // 设置日志标题 ActionLogModel::setTitle("发放优惠券"); ActionLogModel::record(); return parent::edit($data); } }