Payment.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. namespace app\common\model;
  3. use think\facade\Db;
  4. /**
  5. * ============================================================================
  6. *
  7. * ============================================================================
  8. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  9. * 网站地址: https://www.valimart.net/
  10. * ----------------------------------------------------------------------------
  11. *
  12. * ============================================================================
  13. * 数据层模型
  14. */
  15. class Payment extends BaseModel {
  16. /**
  17. * 开启状态标识
  18. * @var unknown
  19. */
  20. const STATE_OPEN = 1;
  21. /**
  22. * 读取单行信息
  23. * @access public
  24. * @author csdeshang
  25. * @param array $condition 条件数组
  26. * @return array 数组格式的返回结果
  27. */
  28. public function getPaymentInfo($condition = array()) {
  29. return Db::name('payment')->where($condition)->find();
  30. }
  31. /**
  32. * 读开启中的取单行信息
  33. * @access public
  34. * @author csdeshang
  35. * @param array $condition 条件
  36. * @return type
  37. */
  38. public function getPaymentOpenInfo($condition = array()) {
  39. $condition[]=array('payment_state','=',self::STATE_OPEN);
  40. return Db::name('payment')->where($condition)->find();
  41. }
  42. /**
  43. * 读取多行
  44. * @access public
  45. * @author csdeshang
  46. * @param type $condition 条件
  47. * @return type
  48. */
  49. public function getPaymentList($condition = array()) {
  50. return Db::name('payment')->where($condition)->select()->toArray();
  51. }
  52. /**
  53. * 读取开启中的支付方式
  54. * @access public
  55. * @author csdeshang
  56. * @param array $condition 条件
  57. * @return array 数组格式的返回结果
  58. */
  59. public function getPaymentOpenList($condition = array()) {
  60. $condition[] = array('payment_state','=',self::STATE_OPEN);
  61. if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') == false) {
  62. //非微信内置浏览器,过滤微信支付
  63. $condition[] = array('payment_code','not in',array('wxpay_jsapi','wxpay_minipro','allinpay_h5'));
  64. }else{
  65. //微信内置浏览器,过滤微信H5支付,以及支付宝H5支付
  66. if( strpos($_SERVER['HTTP_USER_AGENT'], 'miniprogram') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'miniProgram') !== false ){
  67. $condition[] = array('payment_code','not in',array('wxpay_h5','alipay_h5','wxpay_jsapi'));
  68. }else{
  69. $condition[] = array('payment_code','not in',array('wxpay_h5','alipay_h5'));
  70. }
  71. }
  72. return Db::name('payment')->where($condition)->select()->toArray();
  73. }
  74. /**
  75. * 新增支付方式
  76. * @access public
  77. * @author csdeshang
  78. * @param type $data 参数内容
  79. * @return type
  80. */
  81. public function addPayment($data){
  82. return Db::name('payment')->insert($data);
  83. }
  84. /**
  85. * 删除支付方式
  86. * @access public
  87. * @author csdeshang
  88. * @param array $condition 条件
  89. * @return bool
  90. */
  91. public function delPayment($condition){
  92. return Db::name('payment')->where($condition)->delete();
  93. }
  94. /**
  95. * 更新信息
  96. * @access public
  97. * @author csdeshang
  98. * @param array $data 更新数据
  99. * @param array $condition 更新条件
  100. * @return bool 布尔类型的返回结果
  101. */
  102. public function editPayment($data, $condition) {
  103. return Db::name('payment')->where($condition)->update($data);
  104. }
  105. /**
  106. * 读取支付方式信息by Condition
  107. * @access public
  108. * @author csdeshang
  109. * @param type $conditionfield 条件字段
  110. * @param type $conditionvalue 条件值
  111. * @return type
  112. */
  113. public function getRowByCondition($conditionfield, $conditionvalue) {
  114. return Db::name('payment')->where($conditionfield,$conditionvalue)->find();
  115. }
  116. /**
  117. * 获取支付方式
  118. * @access public
  119. * @author csdeshang
  120. * @staticvar type $payments
  121. * @return type
  122. */
  123. function get_builtin() {
  124. static $payments = null;
  125. if ($payments === null) {
  126. $payment_dir = PLUGINS_PATH . '/payments';
  127. $dir = dir($payment_dir);
  128. $payments = array();
  129. while (false !== ($entry = $dir->read())) {
  130. /* 隐藏文件,当前目录,上一级,排除 */
  131. if ($entry{0} == '.') {
  132. continue;
  133. }
  134. /* 获取支付方式信息 */
  135. $payments[$entry] = $this->get_builtin_info($entry);
  136. }
  137. }
  138. return $payments;
  139. }
  140. /**
  141. * 获取内置支付方式的配置信息
  142. * @access public
  143. * @author csdeshang
  144. * @param type $code 编码
  145. * @return type
  146. */
  147. function get_builtin_info($code) {
  148. $payment_path = PLUGINS_PATH . '/payments/' . $code . '/payment.info.php';
  149. return include($payment_path);
  150. }
  151. }
  152. ?>