$val) { $shortCover = $val['cover'] ?? ''; $cover = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_130,w_130"; $bigCover = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_700,w_700"; $list[$key]['smallCover'] = $cover; $list[$key]['bigCover'] = $bigCover; } $data['list'] = $list; return $data; } //新增花材分类 public static function addGhsItemClass($masterShop, $data) { $mainId = $masterShop->mainId ?? 0; $name = $data['name'] ?? ''; if (empty($name)) { util::fail("请输入花材分类"); } $has = self::getByCondition(['mainId' => $mainId, 'name' => $name]); if ($has) { util::fail("花材分类名称已存在"); } $res = self::add($data); //在首店添加,则父级下所有直营和加盟店,同步添加分类 if (isset($masterShop->default) && $masterShop->default == 1) { $sjId = $masterShop->sjId ?? 0; $shopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true); foreach ($shopList as $shop) { $shopId = $shop->id ?? 0; if ($shopId == $masterShop->id) { //前面已经添加过了 continue; } $thisMainId = $shop->mainId ?? 0; $data['shopId'] = $shopId; $data['mainId'] = $thisMainId; $has = self::getByCondition(['mainId' => $thisMainId, 'name' => $name]); if (!empty($has)) { continue; } self::add($data); } } return $res; } //批量新增花材分类 public static function batchAddGhsItemClass($data) { self::batchAdd($data); return true; } //修改 public static function updateGhsItemClass($data) { $id = $data['id'] ?? 0; $sjId = $data['sjId'] ?? 0; $name = $data['name'] ?? ''; if (!$sjId) { util::fail("请选择供货商"); } if (!$name) { util::fail("花材分类名称不能为空"); } $model = self::getById($id); if (!$model) { util::fail("该花材分类不存在"); } if ($model['sjId'] !== $data['sjId']) { util::fail("参数错误"); } self::updateById($id, $data); return true; } //花材列表页分类,包含今日特价分类 ssh 20220315 public static function getShopClass($mainId) { $class = self::getAllList('id,name,cover', ['mainId' => $mainId], 'inTurn desc'); $itemList = ProductClass::getAllByCondition(['mainId' => $mainId, 'delStatus' => 0, 'status' => 1], null, 'id,name,reachNum,reachNumDiscount,presell,discountPrice', null, true); if (!empty($itemList)) { $arr = []; //有多处需要同步修改,show_my_item_class_list ssh 20260107 foreach ($itemList as $item) { $reachNum = $item->reachNum ?? 0; $reachNumDiscount = $item->reachNumDiscount ?? 0; if (isset($item->presell) && $item->presell == 1) { $arr[3] = [ 'id' => -3, 'name' => '预售专区', 'shortCover' => 'item_class/mrfl.png', 'cover' => imgUtil::groupImg('item_class/mrfl.png') . "?x-oss-process=image/resize,m_fill,h_130,w_130" ]; } if (isset($item->discountPrice) && $item->discountPrice > 0) { $arr[1] = [ 'id' => -1, 'name' => '今日推荐', 'shortCover' => 'item_class/tj.jpg', 'cover' => imgUtil::groupImg('item_class/tj.jpg') . "?x-oss-process=image/resize,m_fill,h_130,w_130" ]; } if ($reachNum > 0 && $reachNumDiscount > 0) { $arr[2] = [ 'id' => -2, 'name' => '满减活动', 'shortCover' => 'item_class/mrfl.png', 'cover' => imgUtil::groupImg('item_class/mrfl.png') . "?x-oss-process=image/resize,m_fill,h_130,w_130" ]; } } $arr = array_values($arr); $class = array_merge($arr, $class); } foreach ($class as $key => $item) { $class[$key]['cover'] = imgUtil::groupImg($item['cover']) . "?x-oss-process=image/resize,m_fill,h_130,w_130"; } return $class; } //获取开单页所有的分类 //这里不能取出className,否则会影响前端显示,重要注意事项,请搜索关键词import_class_name!!!!!!!!!!!!!! public static function getGhsItemClassAll($mainId) { $where = ['mainId' => $mainId]; $data = self::getAllList('id,name,cover,print,isDefault', $where, 'inTurn desc'); if (!empty($data)) { foreach ($data as $key => $val) { $shortCover = $val['cover'] ?? ''; $data[$key]['shortCover'] = $shortCover; $data[$key]['cover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_80,w_80"; } } return $data; } //获取当前供货商下的所有class public static function getAll($sjId, $select = "*") { $where = [ 'sjId' => $sjId ]; $data = self::getAllList($select, $where); return $data; } //验证分类 ssh 20211015 public static function valid($class, $mainId) { if ($class->mainId == $mainId) { return true; } //util::fail('分类不正确'); } //获取当前商家下默认分类id public static function getDefaultClassId($mainId) { $where = ['mainId' => $mainId, 'isDefault' => 1]; $res = self::getByCondition($where, true); if (!$res) { //没有则新增 $classData = ['mainId' => $mainId, 'name' => '默认分类', 'inTurn' => -1, 'isDefault' => 1]; $res = self::add($classData, true); } return $res->id ?? 0; } }