PlatformGoodsService.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace app\adminapi\service;
  3. use app\adminapi\logic\external\ExternalPlatformGoodsLogic;
  4. use app\api\service\DouYinService;
  5. use app\common\model\external\ExternalPlatform;
  6. use app\common\model\external\ExternalPlatformGoods;
  7. use think\facade\Log;
  8. class PlatformGoodsService
  9. {
  10. /**
  11. * 同步到外部平台
  12. * @param $lon
  13. * @param $lat
  14. * @param $resType
  15. * @param $ids
  16. * @author liugc <466014217@qq.com>
  17. * @date 2025/6/8 9:29
  18. */
  19. public static function synchronizeGoods($goods_id, $platform_id, $params = [])
  20. {
  21. try {
  22. $result = false;
  23. // 判断平台配置 是否同步商品库 is_synchronize 是否同步外部 is_synchronize_external
  24. $is_synchronize = ExternalPlatform::getPlatformConfig($platform_id,'is_synchronize');
  25. if($is_synchronize){
  26. $externalPlatformGoods = ExternalPlatformGoods::where('goods_id',$goods_id)->where('external_platform_id',$platform_id)->findOrEmpty();
  27. if($externalPlatformGoods->isEmpty()){
  28. $result = ExternalPlatformGoodsLogic::add([
  29. 'service_fee' => $params['service_fee']??0,
  30. 'goods_status' => 1,
  31. 'goods_id' => $goods_id,
  32. 'external_goods_sn' => '',
  33. 'external_platform_id' => $platform_id,
  34. ]);
  35. }else{
  36. $externalPlatformGoods->service_fee = $params['service_fee']??0;
  37. $externalPlatformGoods->save();
  38. $result = true;
  39. }
  40. }
  41. $is_synchronize_external = ExternalPlatform::getPlatformConfig($platform_id,'is_synchronize_external');
  42. if($is_synchronize && $is_synchronize_external){
  43. // tmp固定 - goods_category_id goods_id external_platform_id
  44. // TODO: tmp固定platform_id
  45. $platform_id == 6 && DouYinService::addProduct(['goods_category_id'=>$params['goods_category_id']??0,'goods_id'=>$goods_id,'external_platform_id'=>$platform_id]);
  46. }
  47. return true;
  48. } catch (\Exception $e) {
  49. Log::info('synchronizeGoods:'.$e->getMessage());
  50. return false;
  51. }
  52. }
  53. }