dao = $dao; } public function create($data) { return $this->dao->create($data); } /** * 写入贡献值记录 * @param ThirdPartyGoodCacheEntity $storeGroupOrderEntity * @return ThirdPartyGoodCacheEntity */ public function createByEntity(ThirdPartyGoodCacheEntity $storeGroupOrderEntity): ThirdPartyGoodCacheEntity { $result = $this->create($storeGroupOrderEntity->toUnderlineArray())->toArray(); /** @var ThirdPartyGoodCacheEntity $entity */ $entity = ThirdPartyGoodCacheEntity::newInstance($result); return $entity; } /** * @param $ids * @param $data * @return int * @throws \think\db\exception\DbException */ public function updates($ids, $data): int { return $this->dao->updates($ids, $data); } /** * @param ThirdPartyGoodCacheEntity $thirdPartyProductEntity * @return ThirdPartyGoodCacheEntity|false * @throws \think\db\exception\DbException */ public function updatesByEntity(ThirdPartyGoodCacheEntity $thirdPartyProductEntity) { $result = $this->updates([$thirdPartyProductEntity->getProductId()], $thirdPartyProductEntity->toUnderlineArray()); if (empty($result)) { return false; } return $thirdPartyProductEntity; } /** * @param string $productId * @return ThirdPartyGoodCacheEntity */ public function getThirdPartyGoodCacheEntityByProductId(string $productId): ThirdPartyGoodCacheEntity { $entityList = $this->getThirdPartyGoodCacheEntityListByProductIdList([$productId]); $entity = array_shift($entityList); if ($entity instanceof ThirdPartyGoodCacheEntity) { return $entity; } else { /** @var ThirdPartyGoodCacheEntity */ return ThirdPartyGoodCacheEntity::newInstance(); } } /** * @param array $productIdList * @return ThirdPartyGoodCacheEntity[] */ public function getThirdPartyGoodCacheEntityListByProductIdList(array $productIdList): array { return $this->dao->getThirdPartyGoodCacheEntityListByProductIdList($productIdList); } /** * @param $param * @return ThirdPartyGoodCacheEntity * @throws \think\db\exception\DbException */ public function saveGoodCacheByFit($param): ThirdPartyGoodCacheEntity { if (empty($param['skuId']) || empty($param['type'])) { throw new ValidateException('缺少必要参数'); } $skuId = $param['skuId']; $platform = ThirdPartyGoodCacheEnum::platformCodeMapByThirdPartyGoodEnumTypeCode($param['type']); /** @var ThirdPartyGoodCacheRepository $thirdPartyProductRepository */ $thirdPartyProductRepository = app()->make(ThirdPartyGoodCacheRepository::class); $thirdPartyProductEntity = $thirdPartyProductRepository->getThirdPartyGoodCacheEntityByProductId($skuId); if (empty($thirdPartyProductEntity->getProductId())) { /** @var ThirdPartyGoodCacheEntity $thirdPartyProductEntity */ $thirdPartyProductEntity = ThirdPartyGoodCacheEntity::newInstance(); $thirdPartyProductEntity ->setProductId($skuId) ->setPlatform($platform) ->setExtraContent($param); $thirdPartyProductEntity = $thirdPartyProductRepository->createByEntity($thirdPartyProductEntity); if (empty($thirdPartyProductEntity->getProductId())) { throw new ValidateException('保存失败'); } } else { $thirdPartyProductEntity ->setProductId($skuId) ->setPlatform($platform) ->setExtraContent($param); $thirdPartyProductRepository->updatesByEntity($thirdPartyProductEntity); } return $thirdPartyProductEntity; } }