From f6597d885ad059bf5c48d160f90a9335230f79bb Mon Sep 17 00:00:00 2001 From: wangxinglong <2371974647@qq.com> Date: Thu, 23 Dec 2021 10:23:10 +0800 Subject: [PATCH] settter --- app/controller/manager/Coupon.php | 49 ++++++------------------------- app/traits/CouponMainTrait.php | 32 ++++++++++++++++++++ 2 files changed, 41 insertions(+), 40 deletions(-) diff --git a/app/controller/manager/Coupon.php b/app/controller/manager/Coupon.php index 12420fd..0bc7687 100644 --- a/app/controller/manager/Coupon.php +++ b/app/controller/manager/Coupon.php @@ -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 = '未开始'; diff --git a/app/traits/CouponMainTrait.php b/app/traits/CouponMainTrait.php index 31c8a67..104bb29 100644 --- a/app/traits/CouponMainTrait.php +++ b/app/traits/CouponMainTrait.php @@ -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; + } } \ No newline at end of file