LaveRepository.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. namespace liuniu\repositories;
  3. use app\common\model\Lave as LaveModel;
  4. use app\common\model\UserRelation;
  5. use liuniu\MiniProgramService;
  6. use liuniu\WechatService;
  7. class LaveRepository
  8. {
  9. /**
  10. * 微信公众号JS支付
  11. * @param $orderId
  12. * @param string $field
  13. * @return array|string
  14. * @throws Exception
  15. */
  16. public static function wxpay($cid, $orderId, $field = "order_id")
  17. {
  18. if (is_string($orderId))
  19. $orderInfo = LaveModel::where($field, $orderId)->find();
  20. else
  21. $orderInfo = $orderId;
  22. if (!$orderInfo || !isset($orderInfo['paid'])) exception('支付订单不存在!');
  23. if ($orderInfo['paid']) exception('支付已支付!');
  24. if ($orderInfo['amount'] <= 0) exception('该支付无需支付!');
  25. $openid = UserRelation::userIdToOpenId($orderInfo['user_id']);
  26. $rs = WechatService::paymentOrder($openid, $orderInfo['order_id'], $orderInfo['amount'], "lave", $orderInfo['order_name'], '', 'JSAPI', [], $cid);
  27. return WechatService::jspay($cid, $rs['prepay_id']);
  28. }
  29. /**
  30. * 小程序JS支付
  31. * @param $orderId
  32. * @param string $field
  33. * @return array|string
  34. * @throws DataNotFoundException
  35. * @throws ModelNotFoundException
  36. * @throws DbException
  37. * @throws Exception
  38. */
  39. public static function jsPay($cid, $orderId, $field = 'order_id')
  40. {
  41. if (is_string($orderId))
  42. $orderInfo = LaveModel::where($field, $orderId)->find();
  43. else
  44. $orderInfo = $orderId;
  45. if (!$orderInfo || !isset($orderInfo['paid'])) exception('支付订单不存在!');
  46. if ($orderInfo['paid']) exception('支付已支付!');
  47. if ($orderInfo['amount'] <= 0) exception('该支付无需支付!');
  48. $openid = UserRelation::userIdToOpenId($orderInfo['user_id'], 'routine_openid');
  49. $bodyContent = $orderInfo['intention'];
  50. $site_name = sys_config('site_name');
  51. if (!$bodyContent && !$site_name) exception('支付参数缺少:请前往后台设置->系统设置-> 填写 网站名称');
  52. return MiniProgramService::paymentOrder($openid, $orderInfo['order_id'], $orderInfo['money'], 'lave', $orderInfo['order_name'], '', '', [], $cid);
  53. }
  54. /**
  55. * 微信h5支付
  56. * @param $orderId
  57. * @param string $field
  58. * @return array|string
  59. * @throws Exception
  60. */
  61. public static function h5Pay($cid, $orderId, $field = 'order_id')
  62. {
  63. if (is_string($orderId))
  64. $orderInfo = Donate::where($field, $orderId)->find();
  65. else
  66. $orderInfo = $orderId;
  67. if (!$orderInfo || !isset($orderInfo['paid'])) exception('支付订单不存在!');
  68. if ($orderInfo['paid']) exception('支付已支付!');
  69. if ($orderInfo['amount'] <= 0) exception('该支付无需支付!');
  70. $bodyContent = $orderInfo['intention'];
  71. $site_name = sys_config('site_name');
  72. if (!$bodyContent && !$site_name) exception('支付参数缺少:请前往后台设置->系统设置-> 填写 网站名称');
  73. return WechatService::payment(false, $cid)->paymentOrder(null, $orderInfo['order_id'], $orderInfo['amount'], "lave", $orderInfo['order_name'], '', 'MWEB', [], $cid);
  74. }
  75. /**
  76. * 微信公众号JS支付签约
  77. * @param $orderId
  78. * @param string $field
  79. * @return array|string
  80. * @throws Exception
  81. */
  82. public static function wxpaySign($cid, $orderId,$plan_record, $field = "order_id")
  83. {
  84. if (is_string($orderId))
  85. $orderInfo = LaveModel::where($field, $orderId)->find();
  86. else
  87. $orderInfo = $orderId;
  88. if (!$orderInfo || !isset($orderInfo['paid'])) exception('支付订单不存在!');
  89. if ($orderInfo['paid']) exception('支付已支付!');
  90. if ($orderInfo['amount'] <= 0) exception('该支付无需支付!');
  91. $openid = UserRelation::userIdToOpenId($orderInfo['user_id']);
  92. // ($openid, $out_trade_no, $total_fee, $attach, $body, $contract_code, $plan_id, $spbill_create_ip ,$detail = '', $trade_type = 'JSAPI', $options = [], $cid = 0,$contract_display_account='')
  93. $rs = WechatService::paysignedOrder($openid, $orderInfo['order_id'], $orderInfo['amount'], "lave", $orderInfo['order_name'], $plan_record['contract_code'],$plan_record['plan_id'],$plan_record['spbill_create_ip'],'', 'JSAPI', [], $cid,$plan_record['contract_display_account']);
  94. return WechatService::jspay($cid, $rs['prepay_id']);
  95. }
  96. /**
  97. * 小程序JS支付签约
  98. * @param $orderId
  99. * @param string $field
  100. * @return array|string
  101. * @throws DataNotFoundException
  102. * @throws ModelNotFoundException
  103. * @throws DbException
  104. * @throws Exception
  105. */
  106. public static function jsPaySign($cid, $orderId,$plan_record, $field = 'order_id')
  107. {
  108. if (is_string($orderId))
  109. $orderInfo = LaveModel::where($field, $orderId)->find();
  110. else
  111. $orderInfo = $orderId;
  112. if (!$orderInfo || !isset($orderInfo['paid'])) exception('支付订单不存在!');
  113. if ($orderInfo['paid']) exception('支付已支付!');
  114. if ($orderInfo['amount'] <= 0) exception('该支付无需支付!');
  115. $openid = UserRelation::userIdToOpenId($orderInfo['user_id'], 'routine_openid');
  116. $bodyContent = $orderInfo['intention'];
  117. $site_name = sys_config('site_name');
  118. if (!$bodyContent && !$site_name) exception('支付参数缺少:请前往后台设置->系统设置-> 填写 网站名称');
  119. // ($openid, $out_trade_no, $total_fee, $attach, $body, $contract_code, $plan_id,$spbill_create_ip, $detail = '', $trade_type = 'JSAPI', $options = [], $cid=0,$contract_display_account='', $contract_notify_url='')
  120. return MiniProgramService::paysignedOrder($openid, $orderInfo['order_id'], $orderInfo['amount'], 'lave', $orderInfo['order_name'], $plan_record['contract_code'],$plan_record['plan_id'],$plan_record['spbill_create_ip'],'', '', [], $cid,$plan_record['contract_display_account'],$plan_record['contract_notify_url']);
  121. }
  122. /**
  123. * 微信h5支付签约
  124. * @param $orderId
  125. * @param string $field
  126. * @return array|string
  127. * @throws Exception
  128. */
  129. public static function h5PaySign($cid, $orderId,$plan_record, $field = 'order_id')
  130. {
  131. if (is_string($orderId))
  132. $orderInfo = Donate::where($field, $orderId)->find();
  133. else
  134. $orderInfo = $orderId;
  135. if (!$orderInfo || !isset($orderInfo['paid'])) exception('支付订单不存在!');
  136. if ($orderInfo['paid']) exception('支付已支付!');
  137. if ($orderInfo['amount'] <= 0) exception('该支付无需支付!');
  138. $bodyContent = $orderInfo['intention'];
  139. $site_name = sys_config('site_name');
  140. if (!$bodyContent && !$site_name) exception('支付参数缺少:请前往后台设置->系统设置-> 填写 网站名称');
  141. // ($openid, $out_trade_no, $total_fee, $attach, $body, $contract_code, $plan_id, $spbill_create_ip ,$detail = '', $trade_type = 'JSAPI', $options = [], $cid = 0,$contract_display_account='')
  142. return WechatService::payment(false, $cid)->paysignedOrder(null, $orderInfo['order_id'], $orderInfo['amount'], "lave", $orderInfo['order_name'],$plan_record['contract_code'],$plan_record['plan_id'],$plan_record['spbill_create_ip'], '', 'MWEB', [], $cid.$plan_record['contract_display_account']);
  143. }
  144. }