settter
parent
0ea8988cf5
commit
f6597d885a
|
@ -41,8 +41,8 @@ class Coupon extends Base
|
|||
{
|
||||
|
||||
if ($this->request->isPost()) {
|
||||
$model = new CouponMain();
|
||||
$repo = CouponRepository::getInstance($model);
|
||||
$repo = new CouponMain();
|
||||
$repo = CouponRepository::getInstance($repo);
|
||||
$keyword = $this->request->param('keyword/s', '');
|
||||
$on_shelf = $this->request->param('on_shelf',CouponMain::on_shelf_off);
|
||||
$start_time = $this->request->param('start_time',);
|
||||
|
@ -51,52 +51,21 @@ class Coupon extends Base
|
|||
$size = $this->request->param('size/d', 30);
|
||||
|
||||
$whereMap = [];
|
||||
$orders = ['sort' => 'desc', "id" => "desc"];
|
||||
if (!empty($on_shelf) && in_array($on_shelf, [CouponMain::COMMON_ON, CouponMain::COMMON_OFF])) {
|
||||
$whereMap[] = ['on_shelf', '=', $on_shelf];
|
||||
$orders = ['a.sort' => 'desc', "a.id" => "desc"];
|
||||
if (in_array($on_shelf, [CouponMain::COMMON_ON, CouponMain::COMMON_OFF])) {
|
||||
$whereMap[] = ['a.on_shelf', '=', $on_shelf];
|
||||
}
|
||||
if (!empty($start_time)) {
|
||||
$whereMap[] = ['start_time', '>=', $start_time];
|
||||
$whereMap[] = ['a.start_time', '>= TIME' , $start_time];
|
||||
}
|
||||
if (!empty($end_time)) {
|
||||
$whereMap[] = ['end_time', '<=', $end_time];
|
||||
$whereMap[] = ['a.end_time', '<= TIME', $end_time];
|
||||
}
|
||||
if (!empty($keyword)) {
|
||||
$whereMap[] = ['name', 'like', "%" . $keyword . "%"];
|
||||
$whereMap[] = ['a.name|b.business_name', 'like', "%" . $keyword . "%"];
|
||||
}
|
||||
|
||||
$list = $repo->findList($whereMap, [], $page, $size, function ($q) {
|
||||
|
||||
if (!empty($keyword)) {
|
||||
return $q->hasWhere('business', function ($q) use ($keyword) {
|
||||
$q->where('business_name', 'like', "%" . $keyword . "%")
|
||||
//如果是渠道商或者工作人员 只查看自己的下级商家
|
||||
->when(MemberModel::is_agency($this->auth['roles']), function ($q) {
|
||||
$q->where('agency_code', '=', $this->auth['business_code']);
|
||||
})
|
||||
->field("code,business_name,business_subtitle,type,agency_code");
|
||||
//->with('category');
|
||||
});
|
||||
}
|
||||
|
||||
if (MemberModel::is_agency($this->auth['roles'])) {
|
||||
|
||||
return $q->hasWhere('business', function ($q) {
|
||||
$q//如果是渠道商或者工作人员 只查看自己的下级商家
|
||||
->where('agency_code', '=', $this->auth['business_code'])
|
||||
->field("code,business_name,business_subtitle,type,agency_code");
|
||||
//->with('category');
|
||||
});
|
||||
} else {
|
||||
return $q->with(["business" => function ($query) {
|
||||
$query->field("code,business_name,business_subtitle,type,agency_code");
|
||||
//->with('category');
|
||||
}]);
|
||||
}
|
||||
|
||||
}, $orders);
|
||||
$list =$repo->couponMainList($whereMap,$page,$size,$orders,$this->auth);
|
||||
$time = time();
|
||||
|
||||
$list['list']->each(function ($item) use ($time) {
|
||||
if (strtotime($item->start_time) > $time) {
|
||||
$item->state_text = '<span >未开始</span>';
|
||||
|
|
|
@ -4,8 +4,10 @@ namespace app\traits;
|
|||
|
||||
use app\exception\RepositoryException;
|
||||
use app\model\CouponMain;
|
||||
use app\model\Member as MemberModel;
|
||||
use app\model\UsingRule;
|
||||
use app\model\Coupon;
|
||||
use think\Collection;
|
||||
use think\facade\Db;
|
||||
|
||||
trait CouponMainTrait
|
||||
|
@ -212,4 +214,34 @@ trait CouponMainTrait
|
|||
'effectiveSize' => $effectiveSize,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 优惠券列表
|
||||
* @param $whereMap
|
||||
* @param $page
|
||||
* @param $size
|
||||
* @param $orders
|
||||
* @param $auth
|
||||
* @return array
|
||||
*/
|
||||
public function couponMainList($whereMap,$page,$size,$orders,$auth)
|
||||
{
|
||||
$data = [
|
||||
'total' => 0,
|
||||
'current' => $page,
|
||||
'size' => $size,
|
||||
'list' => new Collection(),
|
||||
];
|
||||
$rep = CouponMain::alias("a")
|
||||
->join("business b", "a.business_code = b.code")
|
||||
->where($whereMap)
|
||||
->when(MemberModel::is_agency($auth['roles'] ), function ($q)use($auth) {
|
||||
$q->where('b.agency_code', '=', $auth['business_code']);
|
||||
});
|
||||
|
||||
$data["total"] = $rep->count();
|
||||
$data["list"] = $rep->order($orders)->select();
|
||||
return $data;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue