Jelajahi Sumber

梳理逻辑恢复正常参数

liugc 8 bulan lalu
induk
melakukan
35e956dd46

+ 5 - 0
app/adminapi/logic/goods/GoodsLogic.php

@@ -166,6 +166,7 @@ class GoodsLogic extends BaseLogic
                 $params['is_agent'] = 0;
                 $params['is_agent'] = 0;
                 $params['is_activity'] = 0;
                 $params['is_activity'] = 0;
             }
             }
+            $platform_value = $params['platform_value']??0;
             Goods::where('id', $params['id'])->update([
             Goods::where('id', $params['id'])->update([
                 'category_type' => GoodsCategory::where('id',$params['goods_category_id'])->value('category_type'),
                 'category_type' => GoodsCategory::where('id',$params['goods_category_id'])->value('category_type'),
                 'goods_category_ids' => json_encode($params['goods_category_ids'],true),
                 'goods_category_ids' => json_encode($params['goods_category_ids'],true),
@@ -229,6 +230,10 @@ class GoodsLogic extends BaseLogic
             $rule->save();
             $rule->save();
 
 
             Db::commit();
             Db::commit();
+
+            if($platform_value>0) {
+                PlatformGoodsService::synchronizeGoods($params['id'], $platform_value, $params);
+            }
             return true;
             return true;
         } catch (\Exception $e) {
         } catch (\Exception $e) {
             Db::rollback();
             Db::rollback();

+ 21 - 14
app/adminapi/service/PlatformGoodsService.php

@@ -5,6 +5,7 @@ namespace app\adminapi\service;
 use app\adminapi\logic\external\ExternalPlatformGoodsLogic;
 use app\adminapi\logic\external\ExternalPlatformGoodsLogic;
 use app\api\service\DouYinService;
 use app\api\service\DouYinService;
 use app\common\model\external\ExternalPlatform;
 use app\common\model\external\ExternalPlatform;
+use app\common\model\external\ExternalPlatformGoods;
 use think\facade\Log;
 use think\facade\Log;
 
 
 class PlatformGoodsService
 class PlatformGoodsService
@@ -21,25 +22,31 @@ class PlatformGoodsService
     public static function synchronizeGoods($goods_id, $platform_id, $params = [])
     public static function synchronizeGoods($goods_id, $platform_id, $params = [])
     {
     {
         try {
         try {
+            $result = false;
             // 判断平台配置 是否同步商品库 is_synchronize 是否同步外部 is_synchronize_external
             // 判断平台配置 是否同步商品库 is_synchronize 是否同步外部 is_synchronize_external
             $is_synchronize = ExternalPlatform::getPlatformConfig($platform_id,'is_synchronize');
             $is_synchronize = ExternalPlatform::getPlatformConfig($platform_id,'is_synchronize');
             if($is_synchronize){
             if($is_synchronize){
-                $result = ExternalPlatformGoodsLogic::add([
-                    'service_fee' => $params['service_fee']??0,
-                    'goods_status' => 1,
-                    'goods_id' => $goods_id,
-                    'external_goods_sn' => '',
-                    'external_platform_id' => $platform_id,
-                ]);
-                if (true === $result) {
-                    $is_synchronize_external = ExternalPlatform::getPlatformConfig($platform_id,'is_synchronize_external');
-                    if($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]);
-                    }
+                $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;
             return true;
         } catch (\Exception $e) {
         } catch (\Exception $e) {
             Log::info('synchronizeGoods:'.$e->getMessage());
             Log::info('synchronizeGoods:'.$e->getMessage());

+ 25 - 21
app/api/controller/DouYinController.php

@@ -128,10 +128,14 @@ class DouYinController extends BaseApiController
      */
      */
     public function goodsNotify()
     public function goodsNotify()
     {
     {
-        $params = $this->request->post();
-        // {"operate_type":"CREATE","product_id":"7527118921439119395","reason":"","status":"PASS"}
-        Log::info('goodsNotify:'.formatLogData($params));
-        return $this->success();
+        try {
+            $params = $this->request->post();
+            Log::info('goodsNotify:'.formatLogData($params));
+            DouYinService::goodsNotify($params);
+            return json(["err_no"=>0,"err_tips"=>""], 200);
+        } catch (\Exception $e) {
+            return json(["err_no"=>1001,"err_tips"=>$e->getMessage()], 200);
+        }
     }
     }
 
 
     /**
     /**
@@ -232,12 +236,14 @@ class DouYinController extends BaseApiController
             $params = $this->request->post();
             $params = $this->request->post();
             Log::info('submitOrderNotify:'.formatLogData($params));
             Log::info('submitOrderNotify:'.formatLogData($params));
             $msg = is_array($params['msg'])?$params['msg']:json_decode($params['msg'],true);
             $msg = is_array($params['msg'])?$params['msg']:json_decode($params['msg'],true);
-            if($params['type'] == 'pre_create_order') $res = DouYinService::submitOrderNotify($msg);
-            if($params['type'] == 'pre_create_refund') $res = DouYinService::refundOrderNotify($msg);
-            Log::info("submitOrderNotify:".formatLogData($res));
-            if($res){
-                return json(["err_no"=>0,"err_tips"=>"","data"=>$res], 200);
+            if($params['type'] == 'pre_create_order'){
+                $res = DouYinService::submitOrderNotify($msg);
+                Log::info("submitOrderNotify:".formatLogData($res));
+                if($res){
+                    return json(["err_no"=>0,"err_tips"=>"","data"=>$res], 200);
+                }
             }
             }
+            return json(["err_no"=>1001,"err_tips"=>''], 200);
         } catch (\Exception $e) {
         } catch (\Exception $e) {
             return json(["err_no"=>1001,"err_tips"=>$e->getMessage()], 200);
             return json(["err_no"=>1001,"err_tips"=>$e->getMessage()], 200);
         }
         }
@@ -258,9 +264,7 @@ class DouYinController extends BaseApiController
             if($params['type'] == 'payment' && DouYinService::payNotify($msg)){
             if($params['type'] == 'payment' && DouYinService::payNotify($msg)){
                 return json(["err_no"=>0,"err_tips"=>""], 200);
                 return json(["err_no"=>0,"err_tips"=>""], 200);
             }
             }
-            if($params['type'] == 'refund'){
-                return json(["err_no"=>0,"err_tips"=>""], 200);
-            }
+            return json(["err_no"=>1001,"err_tips"=>''], 200);
         } catch (\Exception $e) {
         } catch (\Exception $e) {
             return json(["err_no"=>1001,"err_tips"=>$e->getMessage()], 200);
             return json(["err_no"=>1001,"err_tips"=>$e->getMessage()], 200);
         }
         }
@@ -274,9 +278,7 @@ class DouYinController extends BaseApiController
             if($params['type'] == 'payment' && DouYinService::payTailNotify($msg)){
             if($params['type'] == 'payment' && DouYinService::payTailNotify($msg)){
                 return json(["err_no"=>0,"err_tips"=>""], 200);
                 return json(["err_no"=>0,"err_tips"=>""], 200);
             }
             }
-            if($params['type'] == 'refund'){
-                return json(["err_no"=>0,"err_tips"=>""], 200);
-            }
+            return json(["err_no"=>1001,"err_tips"=>''], 200);
         } catch (\Exception $e) {
         } catch (\Exception $e) {
             return json(["err_no"=>1001,"err_tips"=>$e->getMessage()], 200);
             return json(["err_no"=>1001,"err_tips"=>$e->getMessage()], 200);
         }
         }
@@ -369,12 +371,13 @@ class DouYinController extends BaseApiController
             $params = $this->request->post();
             $params = $this->request->post();
             Log::info('refundNotify:'.formatLogData($params));
             Log::info('refundNotify:'.formatLogData($params));
             $msg = is_array($params['msg'])?$params['msg']:json_decode($params['msg'],true);
             $msg = is_array($params['msg'])?$params['msg']:json_decode($params['msg'],true);
-            $res = DouYinService::refundNotify($msg);
-            if($res){
-                return json(["err_no"=>0,"err_tips"=>"success","data"=>$res], 200);
-            }else{
-                throw new \Exception('申请失败');
+            if($params['type'] == 'pre_create_refund'){
+                $res = DouYinService::refundNotify($msg);
+                if($res){
+                    return json(["err_no"=>0,"err_tips"=>"success","data"=>$res], 200);
+                }
             }
             }
+            return json(["err_no"=>1001,"err_tips"=>'申请失败'], 200);
         } catch (\Exception $e) {
         } catch (\Exception $e) {
             return json(["err_no"=>1001,"err_tips"=>$e->getMessage()], 200);
             return json(["err_no"=>1001,"err_tips"=>$e->getMessage()], 200);
         }
         }
@@ -387,9 +390,10 @@ class DouYinController extends BaseApiController
             $params = $this->request->post();
             $params = $this->request->post();
             Log::info('refundPassNotify:'.formatLogData($params));
             Log::info('refundPassNotify:'.formatLogData($params));
             $msg = is_array($params['msg'])?$params['msg']:json_decode($params['msg'],true);
             $msg = is_array($params['msg'])?$params['msg']:json_decode($params['msg'],true);
-            if(DouYinService::refundPassNotify($msg)){
+            if($params['type'] == 'refund' && DouYinService::refundPassNotify($msg)){
                 return json(["err_no"=>0,"err_tips"=>"success"], 200);
                 return json(["err_no"=>0,"err_tips"=>"success"], 200);
             }
             }
+            return json(["err_no"=>1001,"err_tips"=>''], 200);
         } catch (\Exception $e) {
         } catch (\Exception $e) {
             return json(["err_no"=>1001,"err_tips"=>$e->getMessage()], 200);
             return json(["err_no"=>1001,"err_tips"=>$e->getMessage()], 200);
         }
         }

+ 19 - 1
app/api/service/DouYinService.php

@@ -135,6 +135,23 @@ class DouYinService
         return $res?:[];
         return $res?:[];
     }
     }
 
 
+    public static function goodsNotify($params)
+    {
+        $externalPlatformGoods = ExternalPlatformGoods::where('external_goods_sn',$params['product_id']??'9999999999')->findOrEmpty();
+        if($externalPlatformGoods->isEmpty()) return false;
+        if($params['status'] == 'PASS'){
+            $externalPlatformGoods->goods_status = 1;
+        }else{
+            $externalPlatformGoods->goods_status = 0;
+            $extra = $externalPlatformGoods->extra?json_decode($externalPlatformGoods->extra,true):[];
+            $extra['status_reason'] = $params['reason']??'';
+            $externalPlatformGoods->extra = json_encode($extra);
+        }
+        $externalPlatformGoods->save();
+        return true;
+    }
+
+
     // ******************************** 订单业务
     // ******************************** 订单业务
     public static function getOrderDetail($params)
     public static function getOrderDetail($params)
     {
     {
@@ -431,6 +448,7 @@ class DouYinService
             }
             }
             return [
             return [
                 "out_order_no" => $order_number,
                 "out_order_no" => $order_number,
+                "code_source_type" => 1,
                 "order_entry_schema" => [
                 "order_entry_schema" => [
                     "path" => "pages/order/detail",
                     "path" => "pages/order/detail",
                     "params" => json_encode(['order_number' => $path_order_number])
                     "params" => json_encode(['order_number' => $path_order_number])
@@ -1064,7 +1082,7 @@ class DouYinService
             $orderInfo = $order->toArray();
             $orderInfo = $order->toArray();
             $douyinRefundOrder = DouyinRefundOrder::where('order_number', $order_number)->where('refund_number', $refund_number)->order('id', 'desc')->findOrEmpty();
             $douyinRefundOrder = DouyinRefundOrder::where('order_number', $order_number)->where('refund_number', $refund_number)->order('id', 'desc')->findOrEmpty();
 
 
-            //通过后向抖音申请退款
+            //同步退款审核结果
             $url = 'api/apps/trade/v2/refund/merchant_audit_callback';
             $url = 'api/apps/trade/v2/refund/merchant_audit_callback';
             $data = [
             $data = [
                 "out_refund_no" => (string)$douyinRefundOrder->refund_number,
                 "out_refund_no" => (string)$douyinRefundOrder->refund_number,