| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- <?php
- // +----------------------------------------------------------------------
- // | likeadmin快速开发前后端分离管理后台(PHP版)
- // +----------------------------------------------------------------------
- // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
- // | 开源版本可自由商用,可去除界面版权logo
- // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
- // | github下载:https://github.com/likeshop-github/likeadmin
- // | 访问官网:https://www.likeadmin.cn
- // | likeadmin团队 版权所有 拥有最终解释权
- // +----------------------------------------------------------------------
- // | author: likeadminTeam
- // +----------------------------------------------------------------------
- namespace app\adminapi\lists\coupon;
- use app\adminapi\lists\BaseAdminDataLists;
- use app\common\model\coupon\CouponCategory;
- use app\common\model\coupon\CouponRules;
- use app\common\lists\ListsSearchInterface;
- use think\db\Query;
- /**
- * CouponRules列表
- * Class CouponRulesLists
- * @package app\adminapi\listscoupon
- */
- class CouponRulesLists extends BaseAdminDataLists implements ListsSearchInterface
- {
- /**
- * @notes 设置搜索条件
- * @return \string[][]
- * @author likeadmin
- * @date 2024/07/18 10:11
- */
- public function setSearch(): array
- {
- return [
- '=' => ['amount', 'amount_require', 'begin_use', 'discount_ratio', 'event_name', 'expire_time', 'max_deductible_price', 'mold_type', 'server_category_name', 'voucher_status', 'voucher_count'],
- ];
- }
- public function queryWhere()
- {
- $where = [];
- if(isset($this->params['begin_use']) && !empty($this->params['begin_use'])){
- $time = [strtotime($this->params['begin_use'][0]), strtotime($this->params['begin_use'][1])];
- $where[] = ['begin_use', 'between', $time];
- }
- if(isset($this->params['expire_time']) && !empty($this->params['expire_time'])){
- $time = [strtotime($this->params['expire_time'][0]), strtotime($this->params['expire_time'][1])];
- $where[] = ['expire_time', 'between', $time];
- }
- if(isset($this->params['goods_category_ids']) && !empty($this->params['goods_category_ids'])){
- $categoryIds =[];
- foreach($this->params['goods_category_ids'] as $v){
- $v = json_decode($v,true)?? (array)$v;
- $categoryIds[] = end($v);
- }
- $ids = CouponRules::alias('cr')
- ->join('coupon_category cc','cr.id = cc.coupon_id')
- ->whereIn('cc.goods_category_id',$categoryIds)->distinct(true)->field('cc.coupon_id')->column('cc.coupon_id');
- if(empty($ids)){
- $ids = [0];
- }
- $where[] = ['id','IN',$ids];
- }
- return $where;
- }
- /**
- * @notes 获取列表
- * @return array
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- * @author likeadmin
- * @date 2024/07/18 10:11
- */
- public function lists(): array
- {
- $data = CouponRules::with(['couponWithCategory'=>function(Query $query){
- $query->field('id,name');
- }])->where($this->searchWhere)
- ->where($this->queryWhere())
- ->field(['id', 'amount', 'amount_require', 'begin_use', 'discount_ratio', 'event_name', 'expire_time', 'max_deductible_price', 'mold_type', 'server_category_name', 'voucher_status', 'voucher_count'])
- ->limit($this->limitOffset, $this->limitLength)
- ->order(['id' => 'desc'])
- ->select()
- ->toArray();
- foreach($data as $k => $v){
- $v['goods_category_ids'] = array_column($v['couponWithCategory'],'id');
- $v['begin_use'] = $v['begin_use'] ? date('Y-m-d H:i:s',$v['begin_use']) :null;
- $v['expire_time'] = $v['begin_use'] ?date('Y-m-d H:i:s',$v['expire_time']) :null;
- $data[$k] = $v;
- }
- return $data;
- }
- /**
- * @notes 获取数量
- * @return int
- * @author likeadmin
- * @date 2024/07/18 10:11
- */
- public function count(): int
- {
- return CouponRules::where($this->searchWhere)->where($this->queryWhere())->count();
- }
- }
|