Payment.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. namespace app\common\model;
  3. use think\facade\Db;
  4. /**
  5. * ============================================================================
  6. * DSMall多用户商城
  7. * ============================================================================
  8. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  9. * 网站地址: http://www.csdeshang.com
  10. * ----------------------------------------------------------------------------
  11. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  12. * 不允许对程序代码以任何形式任何目的的再发布。
  13. * ============================================================================
  14. * 数据层模型
  15. */
  16. class Payment extends BaseModel {
  17. /**
  18. * 开启状态标识
  19. * @var unknown
  20. */
  21. const STATE_OPEN = 1;
  22. /**
  23. * 读取单行信息
  24. * @access public
  25. * @author csdeshang
  26. * @param array $condition 条件数组
  27. * @return array 数组格式的返回结果
  28. */
  29. public function getPaymentInfo($condition = array()) {
  30. return Db::name('payment')->where($condition)->find();
  31. }
  32. /**
  33. * 读开启中的取单行信息
  34. * @access public
  35. * @author csdeshang
  36. * @param array $condition 条件
  37. * @return type
  38. */
  39. public function getPaymentOpenInfo($condition = array()) {
  40. $condition[]=array('payment_state','=',self::STATE_OPEN);
  41. return Db::name('payment')->where($condition)->find();
  42. }
  43. /**
  44. * 读取多行
  45. * @access public
  46. * @author csdeshang
  47. * @param type $condition 条件
  48. * @return type
  49. */
  50. public function getPaymentList($condition = array()) {
  51. return Db::name('payment')->where($condition)->select()->toArray();
  52. }
  53. /**
  54. * 读取开启中的支付方式
  55. * @access public
  56. * @author csdeshang
  57. * @param array $condition 条件
  58. * @return array 数组格式的返回结果
  59. */
  60. public function getPaymentOpenList($condition = array()) {
  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. return Db::name('payment')->insert($data);
  84. }
  85. /**
  86. * 删除支付方式
  87. * @access public
  88. * @author csdeshang
  89. * @param array $condition 条件
  90. * @return bool
  91. */
  92. public function delPayment($condition){
  93. return Db::name('payment')->where($condition)->delete();
  94. }
  95. /**
  96. * 更新信息
  97. * @access public
  98. * @author csdeshang
  99. * @param array $data 更新数据
  100. * @param array $condition 更新条件
  101. * @return bool 布尔类型的返回结果
  102. */
  103. public function editPayment($data, $condition) {
  104. return Db::name('payment')->where($condition)->update($data);
  105. }
  106. /**
  107. * 读取支付方式信息by Condition
  108. * @access public
  109. * @author csdeshang
  110. * @param type $conditionfield 条件字段
  111. * @param type $conditionvalue 条件值
  112. * @return type
  113. */
  114. public function getRowByCondition($conditionfield, $conditionvalue) {
  115. return Db::name('payment')->where($conditionfield,$conditionvalue)->find();
  116. }
  117. /**
  118. * 获取支付方式
  119. * @access public
  120. * @author csdeshang
  121. * @staticvar type $payments
  122. * @return type
  123. */
  124. function get_builtin() {
  125. static $payments = null;
  126. if ($payments === null) {
  127. $payment_dir = PLUGINS_PATH . '/payments';
  128. $dir = dir($payment_dir);
  129. $payments = array();
  130. while (false !== ($entry = $dir->read())) {
  131. /* 隐藏文件,当前目录,上一级,排除 */
  132. if ($entry{0} == '.') {
  133. continue;
  134. }
  135. /* 获取支付方式信息 */
  136. $payments[$entry] = $this->get_builtin_info($entry);
  137. }
  138. }
  139. return $payments;
  140. }
  141. /**
  142. * 获取内置支付方式的配置信息
  143. * @access public
  144. * @author csdeshang
  145. * @param type $code 编码
  146. * @return type
  147. */
  148. function get_builtin_info($code) {
  149. $payment_path = PLUGINS_PATH . '/payments/' . $code . '/payment.info.php';
  150. return include($payment_path);
  151. }
  152. }
  153. ?>