onlineUserId = $onlineUserId; $this->onlineEnterpriseId = $onlineEnterpriseId; $this->objDPaymentSetting = new DPaymentSetting('default'); $this->objDAdminSetting = new DAdminSetting('default'); $this->objDEnterpriseBindPayment = new DEnterpriseBindPayment('default'); $this->objMAccount = new MAccount($onlineEnterpriseId,$onlineUserId); } /** * 获取详情 * @param $id * @return ResultWrapper */ public function getPaymentInfoById($id) { //查询配置表里有没有这个配置 $dbResult = $this->objDEnterpriseBindPayment->get(['settingId' => $id, 'enterpriseId' => $this->onlineEnterpriseId]); if($dbResult === false){ return ResultWrapper::fail($this->objDEnterpriseBindPayment->error(), ErrorCode::$dberror); } $adminResult = $this->objDAdminSetting->get(['id' => $id]); if($adminResult === false){ return ResultWrapper::fail($this->objDAdminSetting->error(), ErrorCode::$dberror); } $returnData = [ 'id' => $id, 'defaultStatus' => StatusCode::$delete, 'enableStatus' => StatusCode::$delete, 'deleteStatus' => StatusCode::$standard, 'enterpriseId' => $this->onlineEnterpriseId, 'paymentData' => (object)[], 'logo' => null, 'title' => $adminResult['title'], ]; if($dbResult){ $returnData = [ 'id' => $id, 'defaultStatus' => $dbResult['defaultStatus'], 'enableStatus' => $dbResult['enableStatus'], 'deleteStatus' => $dbResult['deleteStatus'], 'enterpriseId' => $dbResult['enterpriseId'], 'paymentData' => !empty($dbResult['paymentData']) ? json_decode($dbResult['paymentData'], true) : (object)[], 'logo' => $dbResult['logo'], 'title' => $adminResult['title'], ]; } return ResultWrapper::success($returnData); } /** * 支付方式列表 * @param $selectParams * @return ResultWrapper */ public function getAllPayment($selectParams) { $limit = $selectParams['limit']; unset($selectParams['limit']); $offset = $selectParams['offset']; unset($selectParams['offset']); // 获取所有和支付相关的设置项 $dbResult = $this->objDAdminSetting->select(['type' => StatusCode::$adminSettingType['pay']], '*', 'createTime ASC', $limit, $offset); if ($dbResult === false) { return ResultWrapper::fail($this->objDAdminSetting->error(), ErrorCode::$dberror); } $total = $this->objDAdminSetting->count(['type' => StatusCode::$adminSettingType['pay']]); $ids = []; $titles = []; foreach ($dbResult as $value) { $ids[] = $value['id']; $titles[] = [ 'title' => $value['title'], 'id' => $value['id'], 'signId' => $value['signId'], ]; } unset($dbResult); if (empty($ids)){ return ResultWrapper::success(['data' =>[],'total' => 0]); } // 查询指定企业对设置项设置的内容 $dbResult = $this->objDEnterpriseBindPayment->select(['settingId' => $ids, 'enterpriseId' => $this->onlineEnterpriseId]); if ($dbResult === false) { return ResultWrapper::fail($this->objDEnterpriseBindPayment->error(), ErrorCode::$dberror); } $format = []; foreach ($dbResult as $value) { $format[$value['settingId']] = $value; } foreach ($titles as &$value) { $value['defaultStatus'] = StatusCode::$delete; $value['enableStatus'] = StatusCode::$delete; if (isset($format[$value['id']])) { $value['defaultStatus'] = $format[$value['id']]['defaultStatus']; $value['enableStatus'] = $format[$value['id']]['enableStatus']; } } unset($value); $returnData = [ 'data' => $titles, 'total' => ($total) ? intval($total) : 0, ]; return ResultWrapper::success($returnData); } /** * 支付方式,启用/禁用 * @param $params * @return ResultWrapper */ public function updateEnableStatus($params) { $finallyResult = false; if ($params['enableStatus'] == StatusCode::$standard) { //启用 //如果是要启用 查询配置表 该企业是否有此配置 $dbResult = $this->objDEnterpriseBindPayment->get(['settingId' => $params['id'], 'enterpriseId' => $this->onlineEnterpriseId]); if ($dbResult === false) { return ResultWrapper::fail($this->objDEnterpriseBindPayment->error(), ErrorCode::$dberror); } if ($dbResult) { //如果有而且是禁用状态 状态改为启用 默认状态改为关闭 if ($dbResult['enableStatus'] == StatusCode::$delete) { $finallyResult = $this->objDEnterpriseBindPayment->update(['defaultStatus' => StatusCode::$delete, 'enableStatus' => StatusCode::$standard], ['id' => $dbResult['id'], 'enterpriseId' => $this->onlineEnterpriseId]); } } else { //如果没有 从基础表里 查询该配置 添加到配置表 状态为启用 $adminSettingDbResult = $this->objDAdminSetting->get(['id' => $params['id']]); if ($adminSettingDbResult === false) { return ResultWrapper::fail($this->objDAdminSetting->error(), ErrorCode::$dberror); } $insertData = [ 'enterpriseId' => $this->onlineEnterpriseId, 'settingId' => $params['id'], 'defaultStatus' => StatusCode::$delete, 'enableStatus' => $params['enableStatus'], 'deleteStatus' => StatusCode::$standard, 'createTime' => time(), 'updateTime' => time(), 'paymentType' => $adminSettingDbResult['signId'] ]; $finallyResult = $this->objDEnterpriseBindPayment->insert($insertData); } } else { //禁用 //配置表里一定有这个配置 默认状态改为禁用 $finallyResult = $this->objDEnterpriseBindPayment->update(['enableStatus' => StatusCode::$delete, 'defaultStatus' => StatusCode::$delete, 'updateTime' => time()], ['settingId' => $params['id'], 'enterpriseId' => $this->onlineEnterpriseId]); } if ($finallyResult === false) { return ResultWrapper::fail($this->objDEnterpriseBindPayment->error(), ErrorCode::$dberror); } return ResultWrapper::success($finallyResult); } /** * 更新支付方式的默认状态 * @param $params * @return ResultWrapper */ public function updateDefaultStatus($params) { $finallyResult = false; if ($params['defaultStatus'] == StatusCode::$standard) { //启用默认 //如果配置是要启用默认 查询配置表 该企业是否有此配置 $dbResult = $this->objDEnterpriseBindPayment->get(['settingId' => $params['id'], 'enterpriseId' => $this->onlineEnterpriseId]); if ($dbResult === false) { return ResultWrapper::fail($this->objDEnterpriseBindPayment->error(), ErrorCode::$dberror); } if ($dbResult) { //如果有而且是关闭状态 状态改为启用 默认状态改为开启 if ($dbResult['defaultStatus'] == StatusCode::$delete) { //修改其他配置为不是默认 $upResult = $this->objDEnterpriseBindPayment->update(['defaultStatus' => StatusCode::$delete, 'updateTime' => time()], ['enterpriseId' => $this->onlineEnterpriseId, 'defaultStatus' => StatusCode::$standard]); if ($upResult === false) { return ResultWrapper::fail($this->objDEnterpriseBindPayment->error(), ErrorCode::$dberror); } $finallyResult = $this->objDEnterpriseBindPayment->update(['defaultStatus' => StatusCode::$standard, 'enableStatus' => StatusCode::$standard], ['id' => $dbResult['id']]); } } else { //如果没有 从基础表里 查询该配置 添加到配置表 状态为启用 $adminSettingDbResult = $this->objDAdminSetting->get(['id' => $params['id']]); if ($adminSettingDbResult === false) { return ResultWrapper::fail($this->objDAdminSetting->error(), ErrorCode::$dberror); } $insertData = [ 'enterpriseId' => $this->onlineEnterpriseId, 'settingId' => $params['id'], 'defaultStatus' => $params['defaultStatus'], 'enableStatus' => StatusCode::$standard, 'deleteStatus' => StatusCode::$standard, 'createTime' => time(), 'updateTime' => time(), 'paymentType' => $adminSettingDbResult['signId'] ]; $finallyResult = $this->objDEnterpriseBindPayment->insert($insertData); } } else { //关闭默认 //配置表里一定有这个配置 默认状态改为关闭 $finallyResult = $this->objDEnterpriseBindPayment->update(['defaultStatus' => StatusCode::$delete, 'updateTime' => time()], ['settingId' => $params['id'], $this->onlineEnterpriseId]); } if ($finallyResult === false) { return ResultWrapper::fail($this->objDEnterpriseBindPayment->error(), ErrorCode::$dberror); } return ResultWrapper::success($finallyResult); } /** * 编辑支付方式 * @param $params * @return ResultWrapper */ public function savePaySetting($params) { $settingId = $params['id']; unset($params['id']); $params['updateTime'] = time(); $paymentType = 0; // 查询配置表里有没有该配置 $paySettingResult = $this->objDEnterpriseBindPayment->get(['settingId' => $settingId, 'enterpriseId' => $this->onlineEnterpriseId]); if ($paySettingResult === false) { return ResultWrapper::fail($this->objDEnterpriseBindPayment->error(), ErrorCode::$dberror); } // 如果企业对应设置表中有数据则更新数据 否则做新增操作 if ($paySettingResult) { $returnResult = $this->objDEnterpriseBindPayment->update($params, ['settingId' => $settingId, 'enterpriseId' => $this->onlineEnterpriseId]); $paymentType = $paySettingResult['paymentType']; } else { $adminSettingData = $this->objDAdminSetting->get(['id' => $settingId]); if ($adminSettingData === false) { return ResultWrapper::fail($this->objDAdminSetting->error(), ErrorCode::$dberror); } if(empty($adminSettingData)){ return ResultWrapper::fail('配置信息错误', ErrorCode::$paramError); } $params['settingId'] = $settingId; $params['createTime'] = time(); $params['paymentType'] = $adminSettingData['signId']; $returnResult = $this->objDEnterpriseBindPayment->insert($params); $paymentType = $adminSettingData['signId']; } if ($returnResult === false) { return ResultWrapper::fail($this->objDEnterpriseBindPayment->error(), ErrorCode::$dberror); } //处理账户 $paymentData = json_decode($params['paymentData'], true); // 支付宝 微信 余额 支付自动创建对应的财务账号 if (in_array($paymentType,[StatusCode::$payType['wxPay'], StatusCode::$payType['aliPay'], StatusCode::$payType['balance']])) { $account = $this->objMAccount->getDefaultAccount($paymentType); if(!$account->isSuccess()) { return ResultWrapper::fail($account->getData(), $account->getErrorCode()); } $accountInfo = $account->getData(); if(empty($accountInfo)) { //新增一个账户 $name = ''; switch ($paymentType) { case StatusCode::$payType['wxPay']: $name = '微信支付'; break; case StatusCode::$payType['aliPay']: $name = '支付宝支付'; break; case StatusCode::$payType['balance']: $name = '余额支付'; break; default: break; } $accountData = [ 'enterpriseId' => $this->onlineEnterpriseId, 'name' => $name, 'accountNumber' => isset($paymentData['appid'])?$paymentData['appid']:$name, 'beginMoney' => isset($paymentData['beginMoney']) ? $paymentData['beginMoney'] : 0, 'shopId' => 0, 'shopName' => '企业', 'enableStatus' => StatusCode::$standard, 'isDefault' => StatusCode::$delete, 'remark' => $name.'收款默认进入该账户', 'money'=> isset($paymentData['beginMoney']) ? $paymentData['beginMoney'] : 0, 'createTime'=>time(), 'updateTime'=>time(), 'type'=>$paymentType ]; $result=$this->objMAccount->addAccount($accountData); if($result->isSuccess() == false) { return ResultWrapper::fail($result->getData(), $result->getErrorCode()); } } else{ //修改账户的账号 $accountData['id']= $accountInfo['id']; $accountData['accountNumber']= $paymentData['appid']; $result=$this->objMAccount->editAccount($accountData); if($result->isSuccess() == false) { return ResultWrapper::fail($result->getData(), $result->getErrorCode()); } } } return ResultWrapper::success($returnResult); } public function getPayData($paymentType) { $objDEnterpriseBindPayment = new DEnterpriseBindPayment(); $dbResult = $objDEnterpriseBindPayment->get(['enterpriseId'=>$this->onlineEnterpriseId,'paymentType'=>$paymentType],'paymentData,id'); if ($dbResult===false){ return ResultWrapper::fail($objDEnterpriseBindPayment->error(),ErrorCode::$dberror); } $pay = empty($dbResult['paymentData']) ? [] : json_decode($dbResult['paymentData'],true); return ResultWrapper::success($pay); } }