12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?php
- namespace liuniu\repositories;
- use app\common\model\Lave as LaveModel;
- use app\common\model\UserRelation;
- use liuniu\MiniProgramService;
- use liuniu\WechatService;
- class LaveRepository
- {
- /**
- * 微信公众号JS支付
- * @param $orderId
- * @param string $field
- * @return array|string
- * @throws Exception
- */
- public static function wxpay($cid,$orderId,$field="order_id")
- {
- if (is_string($orderId))
- $orderInfo = LaveModel::where($field, $orderId)->find();
- else
- $orderInfo = $orderId;
- if (!$orderInfo || !isset($orderInfo['paid'])) exception('支付订单不存在!');
- if ($orderInfo['paid']) exception('支付已支付!');
- if ($orderInfo['amount'] <= 0) exception('该支付无需支付!');
- $openid = UserRelation::userIdToOpenId($orderInfo['user_id']);
- $rs = WechatService::paymentOrder($openid, $orderInfo['order_id'], $orderInfo['amount'],"lave", $orderInfo['order_name'],'', 'JSAPI', [],$cid);
- return WechatService::jspay($cid,$rs['prepay_id']);
- }
- /**
- * 小程序JS支付
- * @param $orderId
- * @param string $field
- * @return array|string
- * @throws DataNotFoundException
- * @throws ModelNotFoundException
- * @throws DbException
- * @throws Exception
- */
- public static function jsPay($cid,$orderId, $field = 'order_id')
- {
- if (is_string($orderId))
- $orderInfo = LaveModel::where($field, $orderId)->find();
- else
- $orderInfo = $orderId;
- if (!$orderInfo || !isset($orderInfo['paid'])) exception('支付订单不存在!');
- if ($orderInfo['paid']) exception('支付已支付!');
- if ($orderInfo['amount'] <= 0) exception('该支付无需支付!');
- $openid = UserRelation::userIdToOpenId($orderInfo['user_id'],'routine_openid');
- $bodyContent = $orderInfo['intention'];
- $site_name = sys_config('site_name');
- if (!$bodyContent && !$site_name) exception('支付参数缺少:请前往后台设置->系统设置-> 填写 网站名称');
- return MiniProgramService::paymentOrder($openid, $orderInfo['order_id'], $orderInfo['money'], 'lave', $orderInfo['order_name'],'','',[],$cid);
- }
- /**
- * 微信h5支付
- * @param $orderId
- * @param string $field
- * @return array|string
- * @throws Exception
- */
- public static function h5Pay($cid,$orderId, $field = 'order_id')
- {
- if (is_string($orderId))
- $orderInfo = Donate::where($field, $orderId)->find();
- else
- $orderInfo = $orderId;
- if (!$orderInfo || !isset($orderInfo['paid'])) exception('支付订单不存在!');
- if ($orderInfo['paid']) exception('支付已支付!');
- if ($orderInfo['amount'] <= 0) exception('该支付无需支付!');
- $bodyContent = $orderInfo['intention'];
- $site_name = sys_config('site_name');
- if (!$bodyContent && !$site_name) exception('支付参数缺少:请前往后台设置->系统设置-> 填写 网站名称');
- return WechatService::payment(false,$cid)->paymentOrder(null, $orderInfo['order_id'], $orderInfo['amount'],"lave", $orderInfo['order_name'],'', 'MWEB', [],$cid);
- }
- }
|