diff --git a/app/controller/manager/Coupon.php b/app/controller/manager/Coupon.php index 764de30..1397ee8 100644 --- a/app/controller/manager/Coupon.php +++ b/app/controller/manager/Coupon.php @@ -90,10 +90,54 @@ class Coupon extends Base return $this->json(4001, "优惠券不存在"); } - if (in_array($on_shelf, [CouponMain::COMMON_OFF, CouponMain::COMMON_ON])) { + if (!in_array($on_shelf, [CouponMain::COMMON_OFF, CouponMain::COMMON_ON])) { return $this->json(4001, "状态错误"); } - $coupon->save(["on_shelf"=>$on_shelf]); + $coupon->save(["on_shelf" => $on_shelf]); return $this->json(); } + + /** + * 列表 + * + * @return Json|View + * @throws Exception + */ + public function info() + { + + if ($this->request->isPost()) { + $model = new CouponMain(); + $repo = CouponRepository::getInstance($model); + $id = input("id/d"); + $keyword = $this->request->param('keyword/s', ''); + $page = $this->request->param('page/d', 1); + $size = $this->request->param('size/d', 30); + + $list = $repo->couponMainHasList($id, $keyword, $page, $size); + $time = time(); + $list["list"]->each(function ($item) use ($time) { + if (strtotime($item['end_time']) < $time) { + $item->time_state = '已过期'; + } else { + $item->time_state = '未过期'; + } + + }); + return $this->json(0, 'success', $list); + } + $id = input("id/d"); + $model = new CouponMain(); + $repo = CouponRepository::getInstance($model); + $coupon = $repo->getModel()->with(["business" => function ($query) { + $query->field("code,business_name,business_subtitle,type") + ->with('category'); + }, "couponType"])->where("id", $id)->find(); + if (empty($coupon)) { + return $this->error("优惠券不存在"); + } + $this->data["coupon"] = $coupon; + return $this->view(); + } + } \ No newline at end of file diff --git a/app/model/Coupon.php b/app/model/Coupon.php index 553f34b..a5a7c80 100644 --- a/app/model/Coupon.php +++ b/app/model/Coupon.php @@ -23,4 +23,13 @@ class Coupon extends Base { return $this->hasOne(CouponBill::class,"coupon_id","id"); } + public function account() + { + return $this->hasOne(Account::class,"user_code","consumer_code"); + } + + public function business() + { + return $this->hasOne(Business::class,"code","business_code"); + } } \ No newline at end of file diff --git a/app/model/CouponMain.php b/app/model/CouponMain.php index ec114f2..9333cd2 100644 --- a/app/model/CouponMain.php +++ b/app/model/CouponMain.php @@ -23,4 +23,8 @@ class CouponMain extends Base { return $this->hasOne(Business::class, 'code',"business_code"); } + public function couponType() + { + return $this->hasOne(CouponType::class, 'id',"type_id"); + } } \ No newline at end of file diff --git a/app/repository/CouponRepository.php b/app/repository/CouponRepository.php index bbe516a..ec0b21c 100644 --- a/app/repository/CouponRepository.php +++ b/app/repository/CouponRepository.php @@ -3,6 +3,7 @@ namespace app\repository; use app\exception\RepositoryException; +use app\model\Coupon; use app\model\CouponMain; use app\service\Repository; use think\Model; @@ -17,16 +18,29 @@ use think\Model; class CouponRepository extends Repository { /** - * 优惠券列表 + * 优惠券持有信息列表 * - * @param string $businessCode 商家code - * @param array $order + * @param $id + * @param $keyword + * @param $page + * @param $size * @return array - * @throws RepositoryException + * @throws \Exception */ - public function businessCouponModel($where) + public function couponMainHasList($id, $keyword, $page, $size) { - return CouponMain::where($where); + + 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"]); } } \ No newline at end of file diff --git a/public/static/manager/js/consumer/info.js b/public/static/manager/js/consumer/info.js index a06ccd3..8f784a3 100644 --- a/public/static/manager/js/consumer/info.js +++ b/public/static/manager/js/consumer/info.js @@ -42,7 +42,6 @@ layui.use(['laytpl', 'table', 'jquery', 'form', 'miniTab', 'xmSelect'], function {templet: '#row-received_map', title: '领取位置'}, {field: 'money', title: '金额'}, {field: 'business_name', title: '商家名称'}, - {field: 'business_name', title: '商家名称'}, {templet: '#row-sign_map', title: '签到位置'}, {templet: '#row-state', title: '状态'}, ]], diff --git a/public/static/manager/js/coupon/index.js b/public/static/manager/js/coupon/index.js index e0bc76f..f3db3c1 100644 --- a/public/static/manager/js/coupon/index.js +++ b/public/static/manager/js/coupon/index.js @@ -92,7 +92,30 @@ layui.use(['laytpl', 'table', 'jquery', 'form', 'miniTab', 'xmSelect','laydate'] elem: '#end_time' ,type: 'date' }); + //监听工具条 + table.on('tool(table-container)', function (obj) { + let data = obj.data; + let layEvent = obj.event; + let url = $($(this).context).data('href'); + let title = $($(this).context).data('title'); + let width = $($(this).context).data('width') ? $($(this).context).data('width') : '100%'; + let height = $($(this).context).data('height') ? $($(this).context).data('height') : '100%'; + let insTb = Tools.getInsTb(); + if (layEvent === 'shelf') { + $.post(url, null, function (res) { + layer.msg(res.msg) + if (res.code === 0) { + insTb.reload(); + } + }) + return false; + } + if (layEvent === 'info') { + openLayer(url, title, width, height); + return false; + } + }); } /*** index end ***/ diff --git a/public/static/manager/js/coupon/info.js b/public/static/manager/js/coupon/info.js index a06ccd3..08599d1 100644 --- a/public/static/manager/js/coupon/info.js +++ b/public/static/manager/js/coupon/info.js @@ -37,14 +37,19 @@ layui.use(['laytpl', 'table', 'jquery', 'form', 'miniTab', 'xmSelect'], function cols: [[ // {type: 'checkbox'}, {field: 'id' , width: 80, title: 'ID'}, - {field: 'name', title: '名称'}, - {field: 'type_name', title: '优惠券类型'}, - {templet: '#row-received_map', title: '领取位置'}, - {field: 'money', title: '金额'}, - {field: 'business_name', title: '商家名称'}, - {field: 'business_name', title: '商家名称'}, - {templet: '#row-sign_map', title: '签到位置'}, + {templet: '#row-cover', title: '头像'}, + {templet:function(d){ + if(d.account!=undefined&&d.account){ + return d.account.nick_name; + } + return d.consumer_name; + }, title: '昵称'}, + + {field: 'received_time', title: '领取时间'}, + + {templet: '#row-state', title: '状态'}, + {field: 'verificate_time', title: '验证时间'}, ]], done: function () { Tools.setInsTb(insTb); diff --git a/view/manager/coupon/index.html b/view/manager/coupon/index.html index 0e8091f..40533b8 100644 --- a/view/manager/coupon/index.html +++ b/view/manager/coupon/index.html @@ -87,7 +87,7 @@ @@ -130,5 +154,11 @@ + + - \ No newline at end of file + \ No newline at end of file