PaymentSetting.Class.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. /**
  3. * 支付方式设置
  4. * Created by PhpStorm.
  5. * User: XiaoMing
  6. * Date: 2019/10/31
  7. * Time: 15:46
  8. */
  9. namespace JinDouYun\Controller\System;
  10. use Mall\Framework\Core\ErrorCode;
  11. use JinDouYun\Controller\BaseController;
  12. use JinDouYun\Model\System\MPaymentSetting;
  13. use Mall\Framework\Core\StatusCode;
  14. class PaymentSetting extends BaseController
  15. {
  16. private $objMPaymentSetting;
  17. /**
  18. * PaymentSetting constructor.
  19. * @param bool $isCheckAcl
  20. * @param bool $isMustLogin
  21. * @throws \Exception
  22. */
  23. public function __construct($isCheckAcl = true, $isMustLogin = true)
  24. {
  25. parent::__construct($isCheckAcl, $isMustLogin);
  26. $this->objMPaymentSetting = new MPaymentSetting($this->onlineUserId, $this->onlineEnterpriseId);
  27. }
  28. /**
  29. * 添加,编辑支付方式公共数据
  30. * @return array
  31. */
  32. public function commonFieldFilter()
  33. {
  34. $params = $this->request->getRawJson();
  35. if (empty($params)) {
  36. $this->sendOutput('参数为空', ErrorCode::$paramError);
  37. }
  38. $data = [
  39. 'title' => isset($params['title']) ? $params['title'] : '',
  40. 'defaultStatus' => isset($params['defaultStatus']) ? $params['defaultStatus'] : '',
  41. 'enableStatus' => isset($params['enableStatus']) ? $params['enableStatus'] : '',
  42. ];
  43. foreach ($data as $key => $value) {
  44. if (empty($value) && $value !== 0) {
  45. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  46. }
  47. }
  48. return $data;
  49. }
  50. /**
  51. * 获取指定支付方式详情
  52. * @throws \Exception
  53. */
  54. public function getPaymentInfoById()
  55. {
  56. $id = $this->request->param('request_id');
  57. if (!$id) {
  58. $this->sendOutput('参数错误', ErrorCode::$paramError);
  59. }
  60. $result = $this->objMPaymentSetting->getPaymentInfoById($id);
  61. if ($result->isSuccess()) {
  62. parent::sendOutput($result->getData());
  63. } else {
  64. parent::sendOutput($result->getData(), $result->getErrorCode());
  65. }
  66. }
  67. /**
  68. * 获取支付方式列表
  69. * @throws \Exception
  70. */
  71. public function getAllPayment()
  72. {
  73. $page = $this->request->param('page') ?: 1;
  74. $pageSize = $this->request->param('pageSize') ?: 10;
  75. $offset = ($page - 1) * $pageSize;
  76. $selectParams = [
  77. 'limit' => $pageSize,
  78. 'offset' => $offset,
  79. ];
  80. $orderData = $this->objMPaymentSetting->getAllPayment($selectParams);
  81. if ($orderData->isSuccess()) {
  82. $returnData = $orderData->getData();
  83. $pageData = [
  84. 'pageIndex' => $page,
  85. 'pageSize' => $pageSize,
  86. 'pageTotal' => $returnData['total'],
  87. ];
  88. parent::sendOutput($returnData['data'], 0, $pageData);
  89. } else {
  90. parent::sendOutput($orderData->getData(), ErrorCode::$dberror);
  91. }
  92. }
  93. /**
  94. * 更新支付方式,启用/禁用
  95. * @throws \Exception
  96. */
  97. public function updateEnableStatus()
  98. {
  99. $params['id'] = $this->request->param('request_id');
  100. $params['enableStatus'] = $this->request->param('enableStatus');
  101. foreach ($params as $key => $value) {
  102. if (empty($value)) {
  103. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  104. }
  105. }
  106. $result = $this->objMPaymentSetting->updateEnableStatus($params);
  107. if ($result->isSuccess()) {
  108. parent::sendOutput($result->getData());
  109. } else {
  110. parent::sendOutput($result->getData(), $result->getErrorCode());
  111. }
  112. }
  113. /**
  114. * 更新支付方式的默认状态
  115. * @throws \Exception
  116. */
  117. public function updateDefaultStatus()
  118. {
  119. $params['id'] = $this->request->param('request_id');
  120. $params['defaultStatus'] = $this->request->param('defaultStatus');
  121. foreach ($params as $key => $value) {
  122. if (empty($value)) {
  123. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  124. }
  125. }
  126. $result = $this->objMPaymentSetting->updateDefaultStatus($params);
  127. if ($result->isSuccess()) {
  128. parent::sendOutput($result->getData());
  129. } else {
  130. parent::sendOutput($result->getData(), $result->getErrorCode());
  131. }
  132. }
  133. /**
  134. * 编辑支付方式
  135. */
  136. public function savePaySetting(){
  137. $id = $this->request->param('request_id');
  138. $params = $this->request->getRawJson();
  139. if(empty($params)){
  140. parent::sendOutput('参数为空', ErrorCode::$paramError);
  141. }
  142. $data = [
  143. 'id' => $id,
  144. 'paymentData' => isset($params['paymentData']) ? json_encode($params['paymentData']) : [],
  145. 'enableStatus' => isset($params['enableStatus']) ? $params['enableStatus'] : StatusCode::$delete,
  146. 'defaultStatus' => isset($params['defaultStatus']) ? $params['defaultStatus'] : StatusCode::$delete,
  147. 'enterpriseId' => $this->onlineEnterpriseId,
  148. ];
  149. foreach($data as $key => $value){
  150. if(empty($value)){
  151. parent::sendOutput($key.'参数错误', ErrorCode::$paramError);
  152. }
  153. }
  154. $modelResult = $this->objMPaymentSetting->savePaySetting($data);
  155. if (!$modelResult->isSuccess()) {
  156. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  157. }
  158. parent::sendOutput($modelResult->getData());
  159. }
  160. }