Payment.php 5.0 KB

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