connect($host, $port); if($password != '') { $redis->auth($password); } } catch(\Exception $e) { return DataReturn(MyLang('common_service.site.redis_connect_fail_tips').'['.$e->getMessage().']', -1); } // 检测是否连接成功 if($redis->ping()) { return DataReturn(MyLang('common_service.site.redis_connect_success_tips'), 0); } return DataReturn(MyLang('common_service.site.redis_connect_fail_tips'), -1); } /** * 商品搜索 * @author Devil * @blog http://gong.gg/ * @version 1.0.0 * @date 2020-07-13 * @desc description * @param [array] $params [输入参数] */ public static function GoodsSearchList($params = []) { // 返回数据 $result = [ 'page_total' => 0, 'page_size' => 20, 'page' => max(1, isset($params['page']) ? intval($params['page']) : 1), 'total' => 0, 'data' => [], ]; // 条件 $where = [ ['g.is_delete_time', '=', 0], ['g.is_shelves', '=', 1] ]; // 关键字 if(!empty($params['keywords'])) { $where[] = ['g.title', 'like', '%'.$params['keywords'].'%']; } // 分类id if(!empty($params['category_id'])) { $category_ids = GoodsCategoryService::GoodsCategoryItemsIds([$params['category_id']], 1); $category_ids[] = $params['category_id']; $where[] = ['gci.category_id', 'in', $category_ids]; } // 获取商品总数 $result['total'] = GoodsService::CategoryGoodsTotal($where); // 获取商品列表 if($result['total'] > 0) { // 基础参数 $field = 'g.id,g.title,g.images'; $order_by = 'g.id desc'; // 分页计算 $m = intval(($result['page']-1)*$result['page_size']); $goods = GoodsService::CategoryGoodsList(['where'=>$where, 'm'=>$m, 'n'=>$result['page_size'], 'field'=>$field, 'order_by'=>$order_by]); $result['data'] = $goods['data']; $result['page_total'] = ceil($result['total']/$result['page_size']); // 数据处理 if(!empty($result['data']) && is_array($result['data']) && !empty($params['goods_ids']) && is_array($params['goods_ids'])) { foreach($result['data'] as &$v) { // 是否已添加 $v['is_exist'] = in_array($v['id'], $params['goods_ids']) ? 1 : 0; } } } return DataReturn(MyLang('handle_success'), 0, $result); } /** * 楼层自定义商品展示数据处理 * @author Devil * @blog http://gong.gg/ * @version 1.0.0 * @date 2020-11-25 * @desc description * @param [array] $data [配置数据] */ public static function FloorManualModeGoodsViewHandle($data) { $result = []; if(!empty($data) && is_array($data)) { // 商品id集合 $goods_ids = []; foreach($data as $gid) { $goods_ids = array_merge($goods_ids, $gid); } // 获取商品数据 $ret = GoodsService::GoodsList([ 'where' => [ ['id', 'in', array_unique($goods_ids)], ['is_shelves', '=', 1], ], 'field' => 'id,title,images', 'm' => 0, 'n' => 0, ]); // 使用商品id作为key返回 $goods = empty($ret['data']) ? [] : array_column($ret['data'], null, 'id'); // 数据组合 foreach($data as $k=>$v) { $temp = []; foreach($v as $vs) { if(array_key_exists($vs, $goods)) { $temp[] = $goods[$vs]; } } $result[$k] = $temp; } } return DataReturn(MyLang('handle_success'), 0, $result); } } ?>