diff --git a/app/api/service/cashier/Payment.php b/app/api/service/cashier/Payment.php index ae22bd74..1c251d26 100644 --- a/app/api/service/cashier/Payment.php +++ b/app/api/service/cashier/Payment.php @@ -122,7 +122,7 @@ class Payment extends BaseService // 订单支付事件 $this->orderPayEvent(); // 构建第三方支付请求的参数 - $payment = $this->unifiedorder($extra); + $payment = $this->unifiedorder($extra,$this->orderInfo['merchantId']); // 记录第三方交易信息 $this->recordPaymentTrade($payment); // 返回结果 @@ -221,7 +221,7 @@ class Payment extends BaseService * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ - private function unifiedorder(array $extra = []): array + private function unifiedorder(array $extra = [], int $merchantId = null): array { // 判断支付方式是否合法 if (!in_array($this->method, [PaymentMethodEnum::WECHAT, PaymentMethodEnum::ALIPAY])) { @@ -230,7 +230,7 @@ class Payment extends BaseService // 生成第三方交易订单号 (并非主订单号) $outTradeNo = OrderService::createOrderNo(); // 获取支付方式的配置信息 - $options = $this->getPaymentConfig(); + $options = $this->getPaymentConfig($merchantId); // 整理下单接口所需的附加数据 $extra = $this->extraAsUnify($extra); // 构建支付模块 @@ -251,10 +251,10 @@ class Payment extends BaseService * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ - private function getPaymentConfig() + private function getPaymentConfig(int $merchantId = null) { $PaymentModel = new PaymentModel; - $templateInfo = $PaymentModel->getPaymentInfo($this->method, $this->client, $this->getStoreId()); + $templateInfo = $PaymentModel->getPaymentInfo($this->method, $this->client, $this->getStoreId(), $merchantId); return $templateInfo['template']['config'][$this->method]; } diff --git a/app/common/model/Payment.php b/app/common/model/Payment.php index e1ac78b0..45f3d843 100644 --- a/app/common/model/Payment.php +++ b/app/common/model/Payment.php @@ -85,11 +85,11 @@ class Payment extends BaseModel $model = new static; // 默认的支付方式数据 $defaultData = $model->defaultData(); - if (!$data = Cache::get("payment_{$storeId}_{$merchantId}")) { + if (!$data = Cache::get("11payment_{$storeId}_{$merchantId}")) { // 获取所有支付方式 $data = $model->dataByStorage($storeId, $defaultData, $merchantId); // 写入缓存中 - Cache::tag('cache')->set("payment_{$storeId}_{$merchantId}", $data); + Cache::tag('cache')->set("11payment_{$storeId}_{$merchantId}", $data); } // 重组缓存数据 (多维) return static::reorganize2($defaultData, $data); @@ -104,9 +104,9 @@ class Payment extends BaseModel * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ - public static function getItem(string $client, int $storeId): array + public static function getItem(string $client, int $storeId, int $merchantId = null): array { - return static::getAll($storeId)[$client]; + return static::getAll($storeId, $merchantId)[$client]; } /** @@ -288,10 +288,10 @@ class Payment extends BaseModel * @throws \think\db\exception\ModelNotFoundException * @throws BaseException */ - public function getMethodsByClient(string $client, bool $balance = true, int $storeId = null): array + public function getMethodsByClient(string $client, bool $balance = true, int $storeId = null, int $merchantId = null): array { $storeId = $storeId ?: self::$storeId; - $group = static::getItem($client, $storeId); + $group = static::getItem($client, $storeId, $merchantId); $methods = []; foreach ($group['methods'] as $method) { if ($method['is_enable'] && ($balance || $method['method'] !== PaymentMethodEnum::BALANCE)) { @@ -315,10 +315,10 @@ class Payment extends BaseModel * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ - public function getPaymentInfo(string $method, string $client, int $storeId = null) + public function getPaymentInfo(string $method, string $client, int $storeId = null, int $merchantId = null) { // 获取当前指定的支付方式 - $methodInfo = $this->getCurrentMethod($method, $client, $storeId); + $methodInfo = $this->getCurrentMethod($method, $client, $storeId, $merchantId); // 获取支付模板信息 $methodInfo['template'] = !$methodInfo['is_must_template'] ? [] : $this->getTemplateInfo($methodInfo['template_id']); return $methodInfo; @@ -346,9 +346,9 @@ class Payment extends BaseModel * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ - private function getCurrentMethod(string $method, string $client, int $storeId = null) + private function getCurrentMethod(string $method, string $client, int $storeId = null, int $merchantId = null) { - $methods = $this->getMethodsByClient($client, true, $storeId); + $methods = $this->getMethodsByClient($client, true, $storeId, $merchantId); $method = helper::arraySearch($methods, 'method', $method); if (empty($method)) { throwError('很抱歉,当前未找到指定的支付方式');