Payment.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2024 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\store\model;
  13. use think\facade\Cache;
  14. use app\common\model\Payment as PaymentModel;
  15. /**
  16. * 模型类:支付方式记录
  17. * Class Payment
  18. * @package app\store\model
  19. */
  20. class Payment extends PaymentModel
  21. {
  22. /**
  23. * 更新支付方式设置
  24. * @param array $form
  25. * @return bool
  26. */
  27. public function updateOptions(array $form): bool
  28. {
  29. // 生成写入的数据
  30. $dataList = $this->buildData($form);
  31. // 删除所有的支付方式记录
  32. static::deleteAll([]);
  33. // 批量写入商品图片记录
  34. static::increased($dataList);
  35. // 删除系统设置缓存
  36. Cache::delete('payment_' . self::$storeId);
  37. return true;
  38. }
  39. /**
  40. * 验证模板ID是否存在
  41. * @param int $templateId
  42. * @return bool
  43. */
  44. public static function existsTemplateId(int $templateId): bool
  45. {
  46. return (bool)(new static)->where('template_id', '=', $templateId)->count();
  47. }
  48. /**
  49. * 批量写入支付方式记录
  50. * @param array[] $dataset
  51. * @return void
  52. */
  53. private static function increased(array $dataset): void
  54. {
  55. (new static)->addAll($dataset);
  56. }
  57. /**
  58. * 将表单数据生成为数据库格式记录
  59. * @param array $form
  60. * @return array[]
  61. */
  62. private function buildData(array $form): array
  63. {
  64. $data = [];
  65. foreach ($form as $item) {
  66. foreach ($item['methods'] as $method) {
  67. $data[] = [
  68. 'client' => $item['client'],
  69. 'method' => $method['method'],
  70. 'is_must_template' => (int)$method['is_must_template'],
  71. 'template_id' => $method['template_id'],
  72. 'is_enable' => (int)$method['is_enable'],
  73. 'is_default' => (int)$method['is_default'],
  74. 'others' => [],
  75. 'store_id' => self::$storeId,
  76. ];
  77. }
  78. }
  79. return $data;
  80. }
  81. }