| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- <?php
- namespace app\adminapi\service;
- use app\adminapi\logic\external\ExternalPlatformGoodsLogic;
- use app\api\service\DouYinService;
- use app\common\model\external\ExternalPlatform;
- use app\common\model\external\ExternalPlatformGoods;
- use think\facade\Log;
- class PlatformGoodsService
- {
- /**
- * 同步到外部平台
- * @param $lon
- * @param $lat
- * @param $resType
- * @param $ids
- * @author liugc <466014217@qq.com>
- * @date 2025/6/8 9:29
- */
- public static function synchronizeGoods($goods_id, $platform_id, $params = [])
- {
- try {
- $result = false;
- // 判断平台配置 是否同步商品库 is_synchronize 是否同步外部 is_synchronize_external
- $is_synchronize = ExternalPlatform::getPlatformConfig($platform_id,'is_synchronize');
- if($is_synchronize){
- $externalPlatformGoods = ExternalPlatformGoods::where('goods_id',$goods_id)->where('external_platform_id',$platform_id)->findOrEmpty();
- if($externalPlatformGoods->isEmpty()){
- $result = ExternalPlatformGoodsLogic::add([
- 'service_fee' => $params['service_fee']??0,
- 'goods_status' => 1,
- 'goods_id' => $goods_id,
- 'external_goods_sn' => '',
- 'external_platform_id' => $platform_id,
- ]);
- }else{
- $externalPlatformGoods->service_fee = $params['service_fee']??0;
- $externalPlatformGoods->save();
- $result = true;
- }
- }
- $is_synchronize_external = ExternalPlatform::getPlatformConfig($platform_id,'is_synchronize_external');
- if($is_synchronize && $is_synchronize_external){
- // tmp固定 - goods_category_id goods_id external_platform_id
- // TODO: tmp固定platform_id
- $platform_id == 6 && DouYinService::addProduct(['goods_category_id'=>$params['goods_category_id']??0,'goods_id'=>$goods_id,'external_platform_id'=>$platform_id]);
- }
- return true;
- } catch (\Exception $e) {
- Log::info('synchronizeGoods:'.$e->getMessage());
- return false;
- }
- }
- }
|