PaymentService.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace app\api\service;
  3. use app\common\model\PaymentChannelModel;
  4. class PaymentService extends \app\BaseService
  5. {
  6. private $paymentChannel;
  7. public function __construct()
  8. {
  9. $this->paymentChannel = new PaymentChannelModel();
  10. }
  11. public function channels() {
  12. $channels = $this->paymentChannel->findAll()->toArray();
  13. return array_map(function ($channel) {
  14. $fmt = [
  15. "id" => $channel['id'],
  16. 'name' => $channel['name'],
  17. "index" => $channel['index'],
  18. 'icon' => $channel['icon'],
  19. 'type' => $channel['type'],
  20. 'is_upload_code' => $channel['is_upload_code'],
  21. 'credit_card_config' => [],
  22. ];
  23. if($channel['type'] == 2) {
  24. $fmt['zue_coin_exchange_rate'] = $channel['zue_coin_exchange_rate'];
  25. $fmt['zue_coin_consume_rate'] = $channel['zue_coin_consume_rate'];
  26. } else if($channel['type'] == 3) {
  27. $disposables = [];
  28. $stages = [];
  29. foreach ($channel['relation'] as $item) {
  30. $credit_config = [
  31. 'id' => $item['id'],
  32. 'bank' => $item['bank'],
  33. ];
  34. if($item['is_stage'] == 1) {
  35. $credit_config['periods'] = [];
  36. if($item['stage_6'][0] == 1) {
  37. array_push($credit_config['periods'], ['nper' => 6, 'service_charge_rate' => (int)$item['stage_6'][1]]);
  38. }
  39. if($item['stage_9'][0] == 1) {
  40. array_push($credit_config['periods'], ['nper' => 9, 'service_charge_rate' => (int)$item['stage_9'][1]]);
  41. }
  42. if($item['stage_12'][0] == 1) {
  43. array_push($credit_config['periods'], ['nper' => 12, 'service_charge_rate' => (int)$item['stage_12'][1]]);
  44. }
  45. if($item['stage_24'][0] == 1) {
  46. array_push($credit_config['periods'], ['nper' => 24, 'service_charge_rate' => (int)$item['stage_24'][1]]);
  47. }
  48. if($item['stage_36'][0] == 1) {
  49. array_push($credit_config['periods'], ['nper' => 36, 'service_charge_rate' => (int)$item['stage_36'][1]]);
  50. }
  51. array_push($stages, $credit_config);
  52. } else {
  53. array_push($disposables, $credit_config);
  54. }
  55. }
  56. $fmt['relation'] = ['disposables' =>$disposables, "stages" => $stages ];
  57. }
  58. return $fmt;
  59. }, $channels);
  60. }
  61. }