setQueryFilter($param); // 查询列表数据 return $query->with([]) ->where("is_delete", '=', 0) ->where("status",'=',1) ->order(["id" => 'desc']) ->paginate(15); } /** * 检索查询条件 * @param array $param * @return \think\db\BaseQuery */ private function setQueryFilter(array $param) { // 实例化查询对象 $query = $this->getNewQuery(); // 查询参数 $params = $this->setQueryDefaultValue($param, [ 'name' => '', // 米卡名称 'status' => 0, // 评价状态 -1全部 0-已下架 1-上架中 ]); // 米卡名称 !empty($params['name']) && $query->where('name', 'like', "%{$params['name']}%"); // 米卡类型 $params['type'] > -1 && $query->where("type", '=', $params['type']); return $query; } /** * 获取详情 * @param int $id * @return Comment|array|null */ public function getDetail(int $id) { // 详情 $detail = static::detail($id, ['riceCardPriceValues']); return $detail; } /** * 验证商品是否可使用现金卡 */ public function validCashRiceCard($goodsInfo) { if (empty($goodsInfo)) { return false; } // 查询可用现金卡 $list = $this->with(['riceCardGoodsExcept']) ->where('type', 2) ->where('status', 1) ->where('is_delete', 0) ->select(); if (empty($list)) { return false; } foreach ($list as $item) { // 判断抵扣商品类目和除外商品 $exceptGoodsIds = helper::getArrayColumn($item['riceCardGoodsExcept'], 'goods_id'); if (empty($item['dk_cat_ids'])) { // 全部类目 if (!in_array($goodsInfo['goods_id'], $exceptGoodsIds)) { return true; } } else { // 指定类目 $dk_cat_ids = explode(',', $item['dk_cat_ids']); $goodsIds = GoodsCategoryRel::whereIn('category_id', $dk_cat_ids)->column('goods_id'); if (in_array($goodsInfo['goods_id'], $goodsIds) && !in_array($goodsInfo['goods_id'], $exceptGoodsIds)) { return true; } } } return false; } }