LaveRepository.php 7.7 KB

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