liugc 9 mesiacov pred
rodič
commit
8b321fb7fe

+ 79 - 0
app/common/logic/ExternalPlatformLogic.php

@@ -2,9 +2,15 @@
 
 
 namespace app\common\logic;
 namespace app\common\logic;
 
 
+use app\api\logic\PerformanceLogic;
 use app\common\model\external\ExternalPlatform;
 use app\common\model\external\ExternalPlatform;
+use app\common\model\master_commission\MasterWorkerCommissionConfig;
+use app\common\model\master_commission\MasterWorkerCommissionRatio;
+use app\common\model\performance\PerformanceRules;
+use app\common\model\recharge\OrderGoods;
 use app\common\model\recharge\RechargeOrder;
 use app\common\model\recharge\RechargeOrder;
 use app\common\model\works\ServiceWork;
 use app\common\model\works\ServiceWork;
+use app\common\model\works\ServiceWorkSpare;
 use think\facade\Log;
 use think\facade\Log;
 
 
 class ExternalPlatformLogic  extends BaseLogic
 class ExternalPlatformLogic  extends BaseLogic
@@ -23,6 +29,9 @@ class ExternalPlatformLogic  extends BaseLogic
                 case 1006:
                 case 1006:
                     self::generalServiceWork($params['send_code'],$params['params']);
                     self::generalServiceWork($params['send_code'],$params['params']);
                     break;
                     break;
+                case 1009:
+                    self::separateAccounts($params['send_code'],$params['params']);
+                    break;
                 default:
                 default:
                     throw new \Exception('场景不存在');
                     throw new \Exception('场景不存在');
             }
             }
@@ -72,5 +81,75 @@ class ExternalPlatformLogic  extends BaseLogic
         }
         }
     }
     }
 
 
+    /**
+     * 工单分账
+     * @param $send_code
+     * @param $params
+     * @return bool
+     * @author liugc <466014217@qq.com>
+     * @date 2025/4/17 14:12
+     */
+    public static function separateAccounts($send_code,$params)
+    {
+        try {
+            $model = ServiceWork::where(['id'=>$params['work_id']])->findOrEmpty();
+            if($model->isEmpty()){
+                throw new \Exception('工单不存在');
+            }
+            if($model->external_platform_id = 0){
 
 
+                $laborRatio = 0;
+                $ratio = 0;
+                $commissionConfig = MasterWorkerCommissionConfig::where('master_worker_id',$model->master_worker_id)->where('voucher_status',2)->findOrEmpty();
+                !$commissionConfig->isEmpty() && $ratio = MasterWorkerCommissionRatio::where('commission_config_id',$commissionConfig['id'])->where('goods_category_id',$model->goods_category_id)->value('ratio')?:0;
+                if($commissionConfig->isEmpty() || empty($ratio)){
+                    $order_sns = \app\common\model\orders\RechargeOrder::where('work_id',$model->id)->column('sn');
+                    $goods_id = OrderGoods::whereIn('sn',$order_sns)->value('goods_id');
+                    $rule = PerformanceRules::whereFindInSet('goods_id',$goods_id)->findOrEmpty();
+                    if(!$rule->isEmpty() && in_array($rule['type'],[0,1,2])){
+                        $laborRatio = $rule['rate'];
+                    }
+                }else{
+                    $commissionConfig = $commissionConfig->toArray();
+                    $laborRatio = MasterWorkerCommissionRatio::where('commission_config_id',$commissionConfig['id'])->where('goods_category_id',$model->goods_category_id)->value('ratio');
+                }
+                $workSpares = ServiceWorkSpare::where([
+                    ['service_work_id','=',$model->id],
+                    ['spare_number','>',0],
+                    //['status','=',1],
+                ])->select()->toArray();
+                $finalCompanyPartCost = 0;
+                $finalSelfPartCost = 0;
+                foreach ($workSpares as $workSpare) {
+                    if($workSpare['spare_part_id'] > 0) {
+                        $finalCompanyPartCost += ($workSpare['original_price'] * $workSpare['spare_number']);
+                    }else{
+                        $finalSelfPartCost += $workSpare['offering_price'];
+                    }
+                }
+
+                $send_url = env('internal_api.api_url_host').'platf/performanceNotice';
+                $data = [
+                    'external_platform_id'=> $model->external_platform_id,
+                    'send_code'=> $send_code,
+                    'work_sn'=> $model->work_sn,
+                    "finalSelfPartCost" => $finalSelfPartCost,//尾款自配件成本
+                    "finalCompanyPartCost" => $finalCompanyPartCost,//尾款公司配件成本
+                    "totalPayment" => $model->work_total,//总支付金额
+                    "laborRatio" => $laborRatio,//人工比例
+                ];
+                // 通过内部SDK服务 对外通知
+                $res = http_request($send_url,http_build_query($data));
+                Log::info('separateAccounts:'
+                    .'url:'.$send_url
+                    .'|data:'.json_encode($data,JSON_UNESCAPED_UNICODE)
+                    .'|res:'.json_encode([$res],JSON_UNESCAPED_UNICODE)
+                );
+            }
+            return true;
+        } catch (\Exception $e) {
+            Log::info('separateAccounts-error:'.$e->getMessage());
+            return false;
+        }
+    }
 }
 }

+ 7 - 0
app/common/model/works/ServiceWork.php

@@ -54,6 +54,13 @@ class ServiceWork extends BaseModel
                     'work_id' => $model->id,
                     'work_id' => $model->id,
                 ]
                 ]
             ]);
             ]);
+            $model->work_status == 7 &&
+            event('ExternalPlatform',  [
+                'send_code' => 1009,
+                'params' => [
+                    'work_id' => $model->id,
+                ]
+            ]);
         }
         }
 
 
         $is_settlement = false;
         $is_settlement = false;