Payment.php 9.7 KB

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