xj ?? ''; $ids = json_decode($xj, true); $list = self::getAllByCondition(['id' => ['in', $ids]], null, '*', null); return self::groupInfo($list); } public static function groupInfo($list) { if (empty($list)) { return []; } foreach ($list as $key => $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]['cover'] = $cover; $list[$key]['shortCover'] = $shortCover; $list[$key]['bigCover'] = $bigCover; } return $list; } // 获取当前门店小菊的总数 public static function getXjCount($shopId) { $where = []; $where['shopId'] = $shopId; $where['delStatus'] = 0; return self::getCount($where); } //新增小菊 public static function addXj($shopId, $cover, $shopExt) { $count = self::getXjCount($shopId); if ($count < 10) { $count++; $count = "0" . $count; } $name = "小菊" . $count; $data = []; $data['cover'] = $cover; $data['name'] = $name; $data['shopId'] = $shopId; $data['status'] = 1; $res = self::add($data); $id = $res['id']; //启用 $xj = $shopExt->xj; $hasIds = []; if (!empty($xj)) { $hasIds = json_decode($xj, true); } if (in_array($id, $hasIds) == false) { $hasIds[] = $id; $shopExt->xj = json_encode($hasIds); $shopExt->save(); } } //批量添加 ssh 20211210 public static function batchAddXj($arr, $shop, $itemInfo) { $shopId = $shop->id ?? 0; $sjId = $shop->sjId ?? 0; $mainId = $shop->mainId ?? 0; $itemId = $itemInfo->id ?? 0; $ptItemId = $itemInfo->itemId ?? 0; $max = self::getByCondition(['shopId' => $shopId, 'delStatus' => 0], true, 'no DESC'); $maxId = $max->no ?? 0; $itemName = $itemInfo->name ?? ''; $stock = $itemInfo->stock ? floatval($itemInfo->stock) : 0; foreach ($arr as $key => $imgUrl) { $maxId++; $name = $itemName . $maxId; $data = [ 'cover' => $imgUrl, 'name' => $name, 'no' => $maxId, 'status' => 1, 'shopId' => $shopId, 'sjId' => $sjId, 'mainId' => $mainId, 'itemId' => $itemId, 'ptItemId' => $ptItemId, 'stock' => $stock, ]; self::add($data); } } //获取当前门店下所有的xj public static function getShopXj($shopId) { $where = []; $where['shopId'] = $shopId; $where['status'] = 1; $where['delStatus'] = 0; $list = self::getAllByCondition($where, null, '*', null); return self::groupInfo($list); } }