where('name','like', '%' .$value . '%'); } /** * @notes 商品分类等级搜索器 * @param $query * @param $value * @param $data * @author ljj * @date 2021/7/21 12:04 下午 */ public function searchLevelAttr($query, $value, $data) { $query->where('level','<=',$value); } /** * @notes 获取完整分类名称 * @param $value * @return string * @author Tab * @date 2021/7/23 11:45 */ public function getCompleteNameAttr($value, $data) { return GoodsCategoryLogic::getCompleteName($data['id']); } /** * @notes 状态获取器 * @param $value * @param $data * @return string * @author ljj * @date 2021/7/31 3:26 下午 */ public function getIsShowDescAttr($value, $data) { return YesNoEnum::getIsShowDesc($data['is_show']); } /** * @notes 商品数量 * @param $value * @param $data * @return string|string[] * @author ljj * @date 2023/5/5 6:24 下午 */ public function getGoodsNumAttr($value, $data) { $categoryIds = []; switch ($data['level']) { case 1: $categoryIds = GoodsCategory::alias('A') ->join('goods_category B', 'A.id = B.pid') ->where(['A.pid' => $data['id']]) ->field('A.id as aid,B.id as bid') ->select()->toArray(); $categoryIds = array_merge(array_column($categoryIds, 'aid'), array_column($categoryIds, 'bid')); break; case 2: $categoryIds = GoodsCategory::where(['pid' => $value]) ->column('id'); break; } $categoryIds[] = $data['id']; return GoodsCategoryIndex::alias('gci') ->join('goods g', 'g.id = gci.goods_id') ->where(['gci.category_id'=>$categoryIds]) ->where('g.delete_time','null') ->group('gci.goods_id') ->count(); } }