Payment.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <?php
  2. namespace app\admin\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. *
  8. * ============================================================================
  9. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  10. * 网站地址: https://www.valimart.net/
  11. * ----------------------------------------------------------------------------
  12. *
  13. * ============================================================================
  14. * 控制器
  15. */
  16. class Payment extends AdminControl {
  17. public function initialize() {
  18. parent::initialize();
  19. Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/payment.lang.php');
  20. }
  21. /**
  22. * 支付方式
  23. */
  24. public function index() {
  25. $payment_model = model('payment');
  26. //获取数据库中已安装的支付方式
  27. $install_payment_list = $payment_model->getPaymentList(array(array('payment_code', '<>', 'predeposit')));
  28. $install_payment_list = ds_change_arraykey($install_payment_list, 'payment_code');
  29. //获取已存在的支付列表文件
  30. $file_payment_list = $payment_model->get_builtin();
  31. $payment_platform = input('param.payment_platform');
  32. if (!in_array($payment_platform, array('pc', 'h5', 'app'))) {
  33. $payment_platform = 'pc';
  34. }
  35. foreach ($file_payment_list as $key => $value) {
  36. if ($value['payment_platform'] != $payment_platform) {
  37. unset($file_payment_list[$key]);
  38. continue;
  39. }
  40. if (array_key_exists($key, $install_payment_list)) {
  41. $file_payment_list[$key]['install'] = 1;
  42. //已安装的支付,配置信息使用数据库中配置信息
  43. $file_payment_list[$key]['payment_config'] = $install_payment_list[$key]['payment_config'];
  44. $file_payment_list[$key]['payment_state'] = $install_payment_list[$key]['payment_state'];
  45. } else {
  46. $file_payment_list[$key]['install'] = 0;
  47. $file_payment_list[$key]['payment_state'] = 0;
  48. }
  49. }
  50. View::assign('payment_list', $file_payment_list);
  51. $this->setAdminCurItem('index_' . $payment_platform);
  52. return View::fetch();
  53. }
  54. /**
  55. * 安装支付方式
  56. */
  57. function install() {
  58. $payment_code = input('param.payment_code');
  59. $payment_mod = model('payment');
  60. //如果是小程序支付、微信JS支付、微信H5支付、微信APP支付则必须先开启微信扫码支付
  61. if (in_array($payment_code, array('wxpay_minipro', 'wxpay_jsapi', 'wxpay_h5', 'wxpay_app'))) {
  62. $payment = model('payment')->getPaymentInfo(array('payment_code' => 'wxpay_native'));
  63. if (empty($payment) || empty(unserialize($payment['payment_config']))) {
  64. ds_json_encode('10001', lang('please_open_wechat_payment'));
  65. }
  66. }
  67. //如果是支付宝H5支付则开启支付宝支付
  68. if (in_array($payment_code, array('alipay_h5'))) {
  69. $payment = model('payment')->getPaymentInfo(array('payment_code' => 'alipay'));
  70. if (empty($payment) || empty(unserialize($payment['payment_config']))) {
  71. ds_json_encode('10001', lang('please_open_alipay_payment'));
  72. }
  73. }
  74. $payment = model('payment')->getPaymentInfo(array('payment_code' => $payment_code));
  75. if (empty($payment)) {
  76. $file_payment = include_once(PLUGINS_PATH . '/payments/' . $payment_code . '/payment.info.php');
  77. $data['payment_code'] = $file_payment['payment_code'];
  78. $data['payment_name'] = $file_payment['payment_name'];
  79. $data['payment_state'] = 1;
  80. $data['payment_platform'] = $file_payment['payment_platform'];
  81. $data['payment_config'] = serialize(array());
  82. $resutlt = $payment_mod->addPayment($data);
  83. if ($resutlt) {
  84. ds_json_encode('10000', lang('ds_common_op_succ'));
  85. } else {
  86. ds_json_encode('10001', lang('ds_common_op_fail'));
  87. }
  88. } else {
  89. ds_json_encode('10001', lang('ds_common_op_fail'));
  90. }
  91. }
  92. /**
  93. * 编辑
  94. */
  95. public function edit() {
  96. $payment_model = model('payment');
  97. $payment_code = trim(input('param.payment_code'));
  98. $install_payment = $payment_model->getPaymentInfo(array('payment_code' => $payment_code));
  99. $file_payment = include_once(PLUGINS_PATH . '/payments/' . $install_payment['payment_code'] . '/payment.info.php');
  100. if (is_array($file_payment['payment_config'])) {
  101. $install_payment_config = unserialize($install_payment['payment_config']);
  102. unset($install_payment['payment_config']);
  103. foreach ($file_payment['payment_config'] as $key => $value) {
  104. $install_payment['payment_config'][$key]['name'] = $value['name'];
  105. $install_payment['payment_config'][$key]['type'] = $value['type'];
  106. $install_payment['payment_config'][$key]['desc'] = lang($value['name'] . '_desc');
  107. $install_payment['payment_config'][$key]['lable'] = lang($value['name']);
  108. $install_payment['payment_config'][$key]['value'] = isset($install_payment_config[$value['name']]) ? $install_payment_config[$value['name']] : $value['value'];
  109. }
  110. }
  111. if (!(request()->isPost())) {
  112. View::assign('payment', $install_payment);
  113. return View::fetch();
  114. } else {
  115. $data = array();
  116. $data['payment_state'] = intval(input('post.payment_state'));
  117. $config_info = array();
  118. $cfg_value_array = input('post.cfg_value/a'); #获取数组
  119. $cfg_name_array = input('post.cfg_name/a'); #获取数组
  120. if (is_array($cfg_value_array) && !empty($cfg_value_array)) {
  121. foreach ($cfg_value_array as $i => $v) {
  122. $config_info[trim($cfg_name_array[$i])] = trim($cfg_value_array[$i]);
  123. }
  124. }
  125. $cfg_name2_array = input('post.cfg_name2/a'); #获取数组
  126. if (is_array($cfg_name2_array)) {
  127. foreach ($cfg_name2_array as $i => $v) {
  128. $cfg_value2 = isset($install_payment_config[trim($cfg_name2_array[$i])]) ? $install_payment_config[trim($cfg_name2_array[$i])] : '';
  129. $file = array();
  130. foreach ($_FILES['cfg_value2_' . $i] as $key => $value) {
  131. $file[$key] = $value;
  132. }
  133. if (!empty($file['name'])) {
  134. $upload_file = PLUGINS_PATH . '/payments/' . $install_payment['payment_code'] . '/asserts';
  135. $file = request()->file('cfg_value2_' . $i);
  136. $file_config = array(
  137. 'disks' => array(
  138. 'local' => array(
  139. 'root' => $upload_file
  140. )
  141. )
  142. );
  143. config($file_config, 'filesystem');
  144. try {
  145. validate(['image' => 'fileSize:' . ALLOW_IMG_SIZE . '|fileExt:pfx'])
  146. ->check(['image' => $file]);
  147. $file_name = \think\facade\Filesystem::putFile('', $file);
  148. $cfg_value2 = $file_name;
  149. } catch (\Exception $e) {
  150. $this->error($e->getMessage());
  151. }
  152. }
  153. $config_info[trim($cfg_name2_array[$i])] = $cfg_value2;
  154. }
  155. }
  156. $data['payment_config'] = serialize($config_info);
  157. $payment_model->editPayment($data, array('payment_code' => $payment_code));
  158. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  159. }
  160. }
  161. /**
  162. * 删除支付方式,卸载
  163. */
  164. public function del() {
  165. $payment_model = model('payment');
  166. $payment_code = trim(input('param.payment_code'));
  167. $condition = array();
  168. $condition[] = array('payment_code', '=', $payment_code);
  169. $result = $payment_model->delPayment($condition);
  170. if ($result) {
  171. ds_json_encode('10000', lang('ds_common_op_succ'));
  172. } else {
  173. ds_json_encode('10001', lang('ds_common_op_fail'));
  174. }
  175. }
  176. /**
  177. * 获取卖家栏目列表,针对控制器下的栏目
  178. */
  179. protected function getAdminItemList() {
  180. $menu_array = array(
  181. array(
  182. 'name' => 'index_pc',
  183. 'text' => lang('payment_index_pc'),
  184. 'url' => (string) url('Payment/index')
  185. ),
  186. array(
  187. 'name' => 'index_h5',
  188. 'text' => lang('payment_index_h5'),
  189. 'url' => (string) url('Payment/index', ['payment_platform' => 'h5'])
  190. ),
  191. array(
  192. 'name' => 'index_app',
  193. 'text' => lang('payment_index_app'),
  194. 'url' => (string) url('Payment/index', ['payment_platform' => 'app'])
  195. ),
  196. );
  197. return $menu_array;
  198. }
  199. }
  200. ?>