$this->mall_id]); $log = SplitbillItem::getLogById($id); if (empty($log)) throw new Exception('记录%s不存在'); if ($log->hasAgentOrder()) return false; $service->setStoreId($log->store_id); list($name, $bank_account, $bank_account_type) = $this->getStoreBankInfo($log->store_id); $trans = new AgentTrans( 'SW' . date('YmdHis') . mt_rand(1000, 9999), $log->amount, $bank_account, $name, '门店分账快速到账' ); // 如果设置账户类型 if (!empty($bank_account_type)) { $trans->setAcctType($bank_account_type); } // 执行代付 $res = $service->sendPayRq($trans); // 添加代付记录 $reqData = $service->getReqData(); /** * @var AgentOrder */ $model = AgentOrder::addLog([ 'type' => 2, 'mall_id' => $this->mall_id, 'user_id' => $log->store_id, 'withdraw_id' => $log->id, 'trans_amount' => $reqData['transAmt'], 'order_no' => $reqData['outOrderId'], 'acct_number' => $reqData['settleAcct'], 'acct_name' => $reqData['settleAcctNm'], 'acct_type' => $trans->getAcctType(), 'req_data' => $reqData, 'res_data' => $res, 'status' => $res['transStatus'] ?? '', ]); // 申请失败 if ($res['respCode'] != '0000') { $msg = $res['respMsg']; $model->failByStore(); return $this->error($msg); } else { // 打款失败 if ($res['transStatus'] == '102') { $msg = $res['respMsg']; $model->failByStore(); return $this->error($msg); } // 打款成功 if ($res['transStatus'] == '100') { $model->successByStore(); return $log->id; } } } /** * 获取门店银行卡信息 * * @param integer $store_id * @return array * @throws Exception */ public function getStoreBankInfo(int $store_id) { $merchant = new MerchantService(['mall_id' => $this->mall_id, 'store_id' => $store_id]); $bank_info = $merchant->getBankInfo(); if (empty($bank_info['bank_account'])) throw new Exception(sprintf('门店%s未设置银行卡信息', $store_id)); return [ $bank_info['name'], $bank_info['bank_account'], $bank_info['bank_account_type'] ]; } }