coupon-admin/app/repository/CouponRepository.php

46 lines
1.1 KiB
PHP
Raw Normal View History

2021-11-18 09:57:04 +00:00
<?php
namespace app\repository;
use app\exception\RepositoryException;
2021-11-24 08:34:56 +00:00
use app\model\Coupon;
2021-11-18 09:57:04 +00:00
use app\model\CouponMain;
use app\service\Repository;
use think\Model;
/**
* 优惠券 相关操作
*
* Class CouponRepository
* @package app\repository
* @method self getInstance(Model $model = null) static
*/
class CouponRepository extends Repository
{
/**
2021-11-24 08:34:56 +00:00
* 优惠券持有信息列表
2021-11-18 09:57:04 +00:00
*
2021-11-24 08:34:56 +00:00
* @param $id
* @param $keyword
* @param $page
* @param $size
2021-11-18 09:57:04 +00:00
* @return array
2021-11-24 08:34:56 +00:00
* @throws \Exception
2021-11-18 09:57:04 +00:00
*/
2021-11-24 08:34:56 +00:00
public function couponMainHasList($id, $keyword, $page, $size)
2021-11-18 09:57:04 +00:00
{
2021-11-24 08:34:56 +00:00
return Coupon::findList(["id" => $id], [], $page, $size, function ($q) use ($keyword) {
if (!empty($keyword)) {
return $q::hasWhere('account', function ($q) use ($keyword) {
$q->where('nick_name', 'like', "%" . $keyword . "%")->field("nick_name,avatar_url");
});
} else {
return $q->with(["account" => function ($query) {
$query->field("nick_name,avatar_url");
}]);
}
}, ["id" => "desc"]);
2021-11-18 09:57:04 +00:00
}
}