Payment.php 4.9 KB

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