isAjax()) { $page = input('page', 1); $page_size = input('page_size', PAGE_LIST_ROWS); $status = input('status', ''); $name = input('name', ''); $condition = [ [ 'site_id', '=', $this->site_id ] ]; if ($status !== '') { $condition[] = [ 'status', '=', $status ]; } if (!empty($name)) { $condition[] = [ 'name', 'like', '%' . $name . '%' ]; } $start_time = input('start_time', ''); $end_time = input('end_time', ''); if ($start_time && !$end_time) { $condition[] = [ 'end_time', '>=', date_to_time($start_time) ]; } elseif (!$start_time && $end_time) { $condition[] = [ 'start_time', '<=', date_to_time($end_time) ]; } elseif ($start_time && $end_time) { $start_timestamp = date_to_time($start_time); $end_timestamp = date_to_time($end_time); $sql = "start_time between {$start_timestamp} and {$end_timestamp}"; $sql .= " or end_time between {$start_timestamp} and {$end_timestamp}"; $sql .= " or (start_time <= {$start_timestamp} and end_time >= {$end_timestamp})"; $condition[] = [ '', 'exp', \think\facade\Db::raw($sql) ]; } $bale = new BaleModel(); $list = $bale->getBalePageList($condition, $page, $page_size); return $list; } else { return $this->fetch("bale/lists"); } } /** * 添加活动 * @return mixed */ public function add() { if (request()->isAjax()) { $bale = new BaleModel(); $res = $bale->addBale([ 'site_id' => $this->site_id, 'name' => input('name', ''), 'num' => input('num', 0), 'price' => input('price', 0.00), 'goods_ids' => input('goods_ids', ''), 'sku_ids' => input('sku_ids', ''), 'start_time' => strtotime(input('start_time', 0)), 'end_time' => strtotime(input('end_time', 0)), 'shipping_fee_type' => input('shipping_fee_type', 0), ]); return $res; } return $this->fetch("bale/add"); } /** * 编辑活动 * @return mixed */ public function edit() { $bale = new BaleModel(); if (request()->isAjax()) { $res = $bale->editBale([ 'bale_id' => input('bale_id'), 'site_id' => $this->site_id, 'name' => input('name', ''), 'num' => input('num', 0), 'price' => input('price', 0.00), 'goods_ids' => input('goods_ids', ''), 'sku_ids' => input('sku_ids', ''), 'start_time' => strtotime(input('start_time', 0)), 'end_time' => strtotime(input('end_time', 0)), 'shipping_fee_type' => input('shipping_fee_type', 0), ]); return $res; } $bale_id = input('bale_id', ''); $info = $bale->getBaleDetail($bale_id, $this->site_id); if (empty($info[ 'data' ])) $this->error('未获取到活动信息'); $this->assign('bale_info', $info[ 'data' ]); return $this->fetch("bale/edit"); } /** * 详情 */ public function detail() { $bale_id = input('bale_id', ''); $bale = new BaleModel(); $info = $bale->getBaleDetail($bale_id, $this->site_id)[ 'data' ] ?? []; if (empty($info)) $this->error('未获取到活动信息'); $this->assign('info', $info); return $this->fetch("bale/detail"); } /** * 删除活动 * @return array */ public function delete() { if (request()->isAjax()) { $id = input('id', 0); $bale = new BaleModel(); $res = $bale->deleteBale($id, $this->site_id); return $res; } } /** * 商品推广 * return */ public function baleUrl() { $bale_id = input('bale_id', ''); $bale = new BaleModel(); $res = $bale->urlQrcode('/pages_promotion/bale/detail', [ 'id' => $bale_id ], 'bale', $this->site_id); return $res; } public function closeBale() { $bale_id = input('id', ''); $bale = new BaleModel(); $res = $bale->closeBale($bale_id); return $res; } }