You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
yanzong/app/store/model/Payment.php

89 lines
2.8 KiB

11 months ago
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\store\model;
use think\facade\Cache;
use app\common\model\Payment as PaymentModel;
/**
* 模型类:支付方式记录
* Class Payment
* @package app\store\model
*/
class Payment extends PaymentModel
{
/**
* 更新支付方式设置
* @param array $form
* @return bool
*/
7 months ago
public function updateOptions(array $form, $merchantId = 0): bool
11 months ago
{
// 生成写入的数据
7 months ago
$dataList = $this->buildData($form, $merchantId);
11 months ago
// 删除所有的支付方式记录
static::deleteAll([]);
// 批量写入商品图片记录
static::increased($dataList);
// 删除系统设置缓存
Cache::delete('payment_' . self::$storeId);
return true;
}
/**
* 验证模板ID是否存在
* @param int $templateId
* @return bool
*/
public static function existsTemplateId(int $templateId): bool
{
return (bool)(new static)->where('template_id', '=', $templateId)->count();
}
/**
* 批量写入支付方式记录
* @param array[] $dataset
* @return void
*/
private static function increased(array $dataset): void
{
(new static)->addAll($dataset);
}
/**
* 将表单数据生成为数据库格式记录
* @param array $form
* @return array[]
*/
7 months ago
private function buildData(array $form, $merchantId = 0): array
11 months ago
{
$data = [];
foreach ($form as $item) {
foreach ($item['methods'] as $method) {
$data[] = [
'client' => $item['client'],
'method' => $method['method'],
'is_must_template' => (int)$method['is_must_template'],
'template_id' => $method['template_id'],
'is_enable' => (int)$method['is_enable'],
'is_default' => (int)$method['is_default'],
'others' => [],
'store_id' => self::$storeId,
7 months ago
'merchant_id' => $merchantId,
11 months ago
];
}
}
return $data;
}
}