123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <?php
- /**
- * Created by PhpStorm.
- * User: XiaoMing
- * Date: 2019/12/4
- * Time: 14:38
- */
- namespace JinDouYun\Model\System;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\ResultWrapper;
- use Mall\Framework\Core\StatusCode;
- use JinDouYun\Cache\SystemCache;
- use JinDouYun\Model\Finance\MAccount;
- use JinDouYun\Dao\System\DAdminSetting;
- use JinDouYun\Dao\System\DEnterpriseBindPayment;
- class MEnterpriseBindPayment
- {
- private $onlineUserId;
- private $onlineEnterpriseId;
- private $objDEnterpriseBindPayment;
- private $objSystemCache;
- private $objDAdminSetting;
- private $paymentData;
- public function __construct($onlineUserId, $enterpriseId)
- {
- $this->onlineUserId = $onlineUserId;
- $this->onlineEnterpriseId = $enterpriseId;
- $this->objDEnterpriseBindPayment = new DEnterpriseBindPayment('default');
- $this->objDAdminSetting = new DAdminSetting();
- $this->objSystemCache = new SystemCache();
- $this->paymentData = $this->objSystemCache->getPayment($this->onlineEnterpriseId);
- }
- /**
- * 获取企业的支付方式
- * @param $paramsData
- * @return ResultWrapper
- */
- public function getPaymentType($paramsData = [])
- {
- $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;
- $dbResult = $this->objDEnterpriseBindPayment->query($sql);
- if ($dbResult === false) {
- return ResultWrapper::fail($this->objDEnterpriseBindPayment->error(), ErrorCode::$dberror);
- }
- if(!empty($paramsData)){
- $dbResult['price'] = $paramsData['price'];
- }
- return ResultWrapper::success(self::formatPayment($dbResult));
- }
- /**
- * @param $data
- * @return array
- */
- private function formatPayment($data)
- {
- $totlPrice = getArrayItem($data,'price',0);
- unset($data['price']);
- if (empty($data)) return [];
- $return = [];
- foreach ($data as $key => $val) {
- $return[$key] = [
- 'id' => $val['signId'],
- 'title' => $val['title'],
- 'defaultStatus' => $val['defaultStatus'],
- 'limit' => 0,
- ];
- // 单独处理银行打款
- if( $val['signId'] == StatusCode::$payType['bankLoans'] ){
- $paymentData = !empty($val['paymentData']) ? json_decode($val['paymentData'], true) : [];
- $return[$key]['limit'] = $paymentData['limit'];
- if(!isset($paymentData['financeAccountId']) ){
- continue;
- }
- $objMAccount = new MAccount($this->onlineEnterpriseId, $this->onlineUserId);
- $accountData = $objMAccount->getAccountInfo($paymentData['financeAccountId']);
- if( $accountData->isSuccess() ){
- $accountData = $accountData->getData();
- $return[$key]['accountData'] = $accountData;
- }
- if($totlPrice < $return[$key]['limit'] && $totlPrice != 0){
- unset($return[$key]);
- }
- }
- }
- return array_values($return);
- }
- /**
- * 写入缓存
- */
- public function __destruct()
- {
- if (!empty($this->paymentData)) {
- $this->objSystemCache->cachePayment($this->paymentData, $this->onlineEnterpriseId);
- }
- }
- }
|