* @license GPL https://xxx.com * @link https://xxx.com * @ctime: 2020/4/16 9:36 */ namespace App\Repositories; use App\Models\Coupon; class CouponRepository extends BaseRepository { public function __construct(Coupon $coupon) { $this->model = $coupon; } /** * 根据获取区域的配置优惠券 * @param $user_id * Author: Mead */ public function getNewUserCoupons($area_id = 0) { if ($area_id) { $coupons = $this->model->query()->where('area_id', $area_id)->where('site', Coupon::SITE_NEW_USER)->where('status', Coupon::STATUS_OK)->orderBy('area_id')->get(); if ($coupons) { return $coupons; } } $coupons = $coupons = $this->model->query()->where('area_id', 0)->where('site', Coupon::SITE_NEW_USER)->where('status', Coupon::STATUS_OK)->orderBy('area_id')->get(); return $coupons; } /** * @param $ids * Author: Mead */ public function byIdsGetNewUserCoupons($ids) { if (is_string($ids)) { $ids = str2arr($ids); } return $this->model->query()->whereIn('id', $ids)->where('site', Coupon::SITE_NEW_USER)->where('status', Coupon::STATUS_OK)->get(); } }