diff --git a/app/api/model/PaymentTemplate.php b/app/api/model/PaymentTemplate.php index 95864be0..f76ba8d4 100644 --- a/app/api/model/PaymentTemplate.php +++ b/app/api/model/PaymentTemplate.php @@ -35,14 +35,4 @@ class PaymentTemplate extends PaymentTemplateModel 'create_time', 'update_time' ]; - - /** - * 根据微信支付V3平台证书序号查找记录 - * @param string $serial - * @return static|array|null - */ - public static function findByWechatpaySerial(string $serial) - { - return static::get(['method' => PaymentMethodEnum::WECHAT, 'wechatpay_serial' => $serial,'is_delete' => 0]); - } } diff --git a/app/common/model/PaymentTemplate.php b/app/common/model/PaymentTemplate.php index bb5b0c1d..79616563 100644 --- a/app/common/model/PaymentTemplate.php +++ b/app/common/model/PaymentTemplate.php @@ -30,6 +30,15 @@ class PaymentTemplate extends BaseModel // 定义主键 protected $pk = 'template_id'; + /** + * 根据微信支付V3平台证书序号查找记录 + * @param string $serial + * @return static|array|null + */ + public static function findByWechatpaySerial(string $serial) + { + return static::get(['method' => PaymentMethodEnum::WECHAT, 'wechatpay_serial' => $serial,'is_delete' => 0]); + } /** * 获取器:支付配置 * @param string $value diff --git a/app/store/controller/Store.php b/app/store/controller/Store.php index c9695d12..115fa011 100644 --- a/app/store/controller/Store.php +++ b/app/store/controller/Store.php @@ -23,6 +23,7 @@ use app\common\model\PriceSet; * Class Store * @package app\store\controller */ + class Store extends Controller { /** diff --git a/app/store/model/PaymentTemplate.php b/app/store/model/PaymentTemplate.php index 81c527fe..105d7e90 100644 --- a/app/store/model/PaymentTemplate.php +++ b/app/store/model/PaymentTemplate.php @@ -1,13 +1,4 @@ -// +---------------------------------------------------------------------- declare (strict_types=1); namespace app\store\model; @@ -60,6 +51,14 @@ class PaymentTemplate extends PaymentTemplateModel $data['store_id'] = self::$storeId; // 写入证书文件 $data['config'] = [$data['method'] => $this->certFileName($data['method'], $methodConfig)]; + // 记录微信支付v3平台证书序号 + if ($data['method'] === 'wechat' && $data['config']['wechat']['version'] === 'v3') { + $data['wechatpay_serial'] = $data['config']['wechat'][$data['config']['wechat']['mchType']]['platformCertSerial']; + $info = PaymentTemplateModel::findByWechatpaySerial($data['wechatpay_serial']); + if ($info) { + throwError("当前商户号已使用过了"); + } + } // 写入到数据库 return $this->save($data); } @@ -83,6 +82,11 @@ class PaymentTemplate extends PaymentTemplateModel // 记录微信支付v3平台证书序号 if ($data['method'] === 'wechat' && $data['config']['wechat']['version'] === 'v3') { $data['wechatpay_serial'] = $data['config']['wechat'][$data['config']['wechat']['mchType']]['platformCertSerial']; + $info = PaymentTemplateModel::findByWechatpaySerial($data['wechatpay_serial']); + if ($info && $info->template_id != $data['templateId']) { + throwError("当前商户号已使用过了"); + } + } // 更新到数据库 return $this->save($data) !== false;