MEnterpriseBindPayment.Class.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: XiaoMing
  5. * Date: 2019/12/4
  6. * Time: 14:38
  7. */
  8. namespace JinDouYun\Model\System;
  9. use Mall\Framework\Core\ErrorCode;
  10. use Mall\Framework\Core\ResultWrapper;
  11. use Mall\Framework\Core\StatusCode;
  12. use JinDouYun\Cache\SystemCache;
  13. use JinDouYun\Model\Finance\MAccount;
  14. use JinDouYun\Dao\System\DAdminSetting;
  15. use JinDouYun\Dao\System\DEnterpriseBindPayment;
  16. class MEnterpriseBindPayment
  17. {
  18. private $onlineUserId;
  19. private $onlineEnterpriseId;
  20. private $objDEnterpriseBindPayment;
  21. private $objSystemCache;
  22. private $objDAdminSetting;
  23. private $paymentData;
  24. public function __construct($onlineUserId, $enterpriseId)
  25. {
  26. $this->onlineUserId = $onlineUserId;
  27. $this->onlineEnterpriseId = $enterpriseId;
  28. $this->objDEnterpriseBindPayment = new DEnterpriseBindPayment('default');
  29. $this->objDAdminSetting = new DAdminSetting();
  30. $this->objSystemCache = new SystemCache();
  31. $this->paymentData = $this->objSystemCache->getPayment($this->onlineEnterpriseId);
  32. }
  33. /**
  34. * 获取企业的支付方式
  35. * @param $paramsData
  36. * @return ResultWrapper
  37. */
  38. public function getPaymentType($paramsData = [])
  39. {
  40. $sql="SELECT a.title,p.defaultStatus,a.signId,p.paymentData FROM qianniao_enterprise_bind_payment as p INNER JOIN qianniao_admin_setting AS a ON p.paymentType=a.signId WHERE a.type=".StatusCode::$adminSettingType['pay']." AND p.enterpriseId=".$this->onlineEnterpriseId." AND p.deleteStatus=".StatusCode::$standard." AND p.enableStatus=".StatusCode::$standard;
  41. $dbResult = $this->objDEnterpriseBindPayment->query($sql);
  42. if ($dbResult === false) {
  43. return ResultWrapper::fail($this->objDEnterpriseBindPayment->error(), ErrorCode::$dberror);
  44. }
  45. if(!empty($paramsData)){
  46. $dbResult['price'] = $paramsData['price'];
  47. }
  48. return ResultWrapper::success(self::formatPayment($dbResult));
  49. }
  50. /**
  51. * @param $data
  52. * @return array
  53. */
  54. private function formatPayment($data)
  55. {
  56. $totlPrice = getArrayItem($data,'price',0);
  57. unset($data['price']);
  58. if (empty($data)) return [];
  59. $return = [];
  60. foreach ($data as $key => $val) {
  61. $return[$key] = [
  62. 'id' => $val['signId'],
  63. 'title' => $val['title'],
  64. 'defaultStatus' => $val['defaultStatus'],
  65. 'limit' => 0,
  66. ];
  67. // 单独处理银行打款
  68. if( $val['signId'] == StatusCode::$payType['bankLoans'] ){
  69. $paymentData = !empty($val['paymentData']) ? json_decode($val['paymentData'], true) : [];
  70. $return[$key]['limit'] = $paymentData['limit'];
  71. if(!isset($paymentData['financeAccountId']) ){
  72. continue;
  73. }
  74. $objMAccount = new MAccount($this->onlineEnterpriseId, $this->onlineUserId);
  75. $accountData = $objMAccount->getAccountInfo($paymentData['financeAccountId']);
  76. if( $accountData->isSuccess() ){
  77. $accountData = $accountData->getData();
  78. $return[$key]['accountData'] = $accountData;
  79. }
  80. if($totlPrice < $return[$key]['limit'] && $totlPrice != 0){
  81. unset($return[$key]);
  82. }
  83. }
  84. }
  85. return array_values($return);
  86. }
  87. /**
  88. * 写入缓存
  89. */
  90. public function __destruct()
  91. {
  92. if (!empty($this->paymentData)) {
  93. $this->objSystemCache->cachePayment($this->paymentData, $this->onlineEnterpriseId);
  94. }
  95. }
  96. }