PayWayLogic.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop100%开源免费商用商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | 商业版本务必购买商业授权,以免引起法律纠纷
  8. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  9. // | gitee下载:https://gitee.com/likeshop_gitee
  10. // | github下载:https://github.com/likeshop-github
  11. // | 访问官网:https://www.likeshop.cn
  12. // | 访问社区:https://home.likeshop.cn
  13. // | 访问手册:http://doc.likeshop.cn
  14. // | 微信公众号:likeshop技术社区
  15. // | likeshop团队 版权所有 拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshopTeam
  18. // +----------------------------------------------------------------------
  19. namespace app\adminapi\logic\settings\pay;
  20. use app\common\enum\PayEnum;
  21. use app\common\enum\YesNoEnum;
  22. use app\common\logic\BaseLogic;
  23. use app\common\model\PayConfig;
  24. use app\common\model\PayWay;
  25. use app\common\service\FileService;
  26. use think\facade\Db;
  27. class PayWayLogic extends BaseLogic
  28. {
  29. /**
  30. * @notes 查看支付方式配置
  31. * @return array
  32. * @throws \think\db\exception\DataNotFoundException
  33. * @throws \think\db\exception\DbException
  34. * @throws \think\db\exception\ModelNotFoundException
  35. * @author ljj
  36. * @date 2021/7/28 4:02 下午
  37. */
  38. public function getPayWay()
  39. {
  40. $pay_way = PayWay::select();
  41. $pay_way = $pay_way->append(['pay_way_name'])->toArray();
  42. if (empty($pay_way)) {
  43. return [];
  44. }
  45. $lists = [];
  46. for ($i=1;$i<=max(array_column($pay_way,'scene'));$i++) {
  47. foreach ($pay_way as $val) {
  48. if ($val['scene'] == $i) {
  49. $val['icon'] = FileService::getFileUrl(PayConfig::where('id',$val['dev_pay_id'])->value('icon'));
  50. $lists[$i][] = $val;
  51. }
  52. }
  53. }
  54. return $lists;
  55. }
  56. /**
  57. * @notes 设置支付方式
  58. * @param $params
  59. * @return bool
  60. * @throws \think\db\exception\DataNotFoundException
  61. * @throws \think\db\exception\DbException
  62. * @throws \think\db\exception\ModelNotFoundException
  63. * @author ljj
  64. * @date 2021/7/28 5:23 下午
  65. */
  66. public function setPayWay($params)
  67. {
  68. $pay_way = new PayWay;
  69. $data = [];
  70. foreach ($params as $key=>$value) {
  71. $is_default = array_column($value,'is_default');
  72. $is_default_num = array_count_values($is_default);
  73. $status = array_column($value,'status');
  74. $scene_name = PayEnum::getPaySceneDesc($key);
  75. if (!in_array(YesNoEnum::YES,$is_default)) {
  76. return $scene_name.'支付场景缺少默认支付';
  77. }
  78. if ($is_default_num[YesNoEnum::YES] > 1) {
  79. return $scene_name.'支付场景的默认值只能存在一个';
  80. }
  81. if (!in_array(YesNoEnum::YES,$status)) {
  82. return $scene_name.'支付场景至少开启一个支付状态';
  83. }
  84. foreach ($value as $val) {
  85. $result = PayWay::where('id',$val['id'])->findOrEmpty();
  86. if ($result->isEmpty()) {
  87. continue;
  88. }
  89. if ($val['is_default'] == YesNoEnum::YES && $val['status'] == YesNoEnum::NO) {
  90. return $scene_name.'支付场景的默认支付未开启支付状态';
  91. }
  92. $data[] = [
  93. 'id' => $val['id'],
  94. 'is_default' => $val['is_default'],
  95. 'status' => $val['status'],
  96. ];
  97. }
  98. }
  99. $pay_way->saveAll($data);
  100. return true;
  101. }
  102. }