LaveRepository.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. // if ($orderInfo['user_id']==6779||$orderInfo['user_id']==12125){
  94. // ($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='')
  95. // $rs = WechatService::signedOrder($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']);
  96. // }else{
  97. // ($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='')
  98. $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']);
  99. // }
  100. @file_put_contents("quanju3.txt", json_encode($rs) . "-签约返回结果测试2\r\n", 8);
  101. return WechatService::jspay($cid, $rs['prepay_id']);
  102. }
  103. /**
  104. * 小程序JS支付签约
  105. * @param $orderId
  106. * @param string $field
  107. * @return array|string
  108. * @throws DataNotFoundException
  109. * @throws ModelNotFoundException
  110. * @throws DbException
  111. * @throws Exception
  112. */
  113. public static function jsPaySign($cid, $orderId,$plan_record, $field = 'order_id')
  114. {
  115. if (is_string($orderId))
  116. $orderInfo = LaveMonthModel::where($field, $orderId)->find();
  117. else
  118. $orderInfo = $orderId;
  119. if (!$orderInfo || !isset($orderInfo['paid'])) exception('支付订单不存在!');
  120. if ($orderInfo['paid']) exception('支付已支付!');
  121. if ($orderInfo['amount'] <= 0) exception('该支付无需支付!');
  122. $openid = UserRelation::userIdToOpenId($orderInfo['user_id'], 'routine_openid');
  123. $bodyContent = $orderInfo['intention'];
  124. $site_name = sys_config('site_name');
  125. if (!$bodyContent && !$site_name) exception('支付参数缺少:请前往后台设置->系统设置-> 填写 网站名称');
  126. // ($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='')
  127. 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']);
  128. }
  129. /**
  130. * 微信h5支付签约
  131. * @param $orderId
  132. * @param string $field
  133. * @return array|string
  134. * @throws Exception
  135. */
  136. public static function h5PaySign($cid, $orderId,$plan_record, $field = 'order_id')
  137. {
  138. if (is_string($orderId))
  139. $orderInfo = Donate::where($field, $orderId)->find();
  140. else
  141. $orderInfo = $orderId;
  142. if (!$orderInfo || !isset($orderInfo['paid'])) exception('支付订单不存在!');
  143. if ($orderInfo['paid']) exception('支付已支付!');
  144. if ($orderInfo['amount'] <= 0) exception('该支付无需支付!');
  145. $bodyContent = $orderInfo['intention'];
  146. $site_name = sys_config('site_name');
  147. if (!$bodyContent && !$site_name) exception('支付参数缺少:请前往后台设置->系统设置-> 填写 网站名称');
  148. // ($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='')
  149. 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']);
  150. }
  151. }