getMessage()); self::setError($e->getMessage()); return false; } } /** * 工单统一处理 * @param $send_code * @param $params * @return bool * @author liugc <466014217@qq.com> * @date 2025/4/17 14:12 */ public static function generalServiceWork($send_code,$params) { try { $work = ServiceWork::where(['id'=>$params['work_id']])->findOrEmpty(); if($work->isEmpty()){ throw new \Exception('工单不存在'); } if($work->external_platform_id > 0){ $send_url = env('internal_api.api_url_host').'platf/performanceNotice'; $data = [ 'external_platform_id'=> $work->external_platform_id, 'send_code'=> $send_code, 'work_sn'=> $work->work_sn ]; // 通过内部SDK服务 对外通知 $res = http_request($send_url,http_build_query($data)); Log::info('generalServiceWork:' .'url:'.$send_url .'|data:'.json_encode($data,JSON_UNESCAPED_UNICODE) .'|res:'.json_encode([$res],JSON_UNESCAPED_UNICODE) ); } return true; } catch (\Exception $e) { Log::info('generalServiceWork-error:'.$e->getMessage()); return false; } } /** * 工单分账 * @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){ $order_sns = \app\common\model\orders\RechargeOrder::where('work_id',$model->id)->column('sn'); $goods_payment_type = OrderGoods::whereIn('sn',$order_sns)->value('goods_payment_type'); if(in_array($goods_payment_type,['2','3'])) throw new \Exception('固定价无需分账处理'); $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; } } }