123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338 |
- <?php
- namespace crmeb\repositories;
- use app\admin\model\vote\VoteOrder;
- use app\models\member\MemberCheck;
- use app\models\store\StoreOrder;
- use app\models\user\User;
- use app\models\user\WechatUser;
- use app\admin\model\order\StoreOrder as AdminStoreOrder;
- use crmeb\services\MiniProgramService;
- use crmeb\services\WechatService;
- /**
- * Class OrderRepository
- * @package crmeb\repositories
- */
- class OrderRepository
- {
- /**
- * TODO 小程序JS支付
- * @param $orderId
- * @param string $field
- * @return array|string
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public static function jsPay($orderId, $field = 'order_id')
- {
- if (is_string($orderId))
- $orderInfo = StoreOrder::where($field, $orderId)->find();
- else
- $orderInfo = $orderId;
- if (!$orderInfo || !isset($orderInfo['paid'])) exception('支付订单不存在!');
- if ($orderInfo['paid']) exception('支付已支付!');
- if ($orderInfo['pay_price'] <= 0) exception('该支付无需支付!');
- $openid = WechatUser::getOpenId($orderInfo['uid']);
- $bodyContent = StoreOrder::getProductTitle($orderInfo['cart_id']);
- $site_name = sys_config('site_name');
- if (!$bodyContent && !$site_name) exception('支付参数缺少:请前往后台设置->系统设置-> 填写 网站名称');
- return MiniProgramService::jsPay($openid, $orderInfo['order_id'], $orderInfo['pay_price'], 'product', StoreOrder::getSubstrUTf8($site_name . ' - ' . $bodyContent, 30));
- }
- /**
- * 微信公众号JS支付
- * @param $orderId
- * @param string $field
- * @return array|string
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public static function wxPay($orderId, $field = 'order_id')
- {
- if (is_string($orderId))
- $orderInfo = StoreOrder::where($field, $orderId)->find();
- else
- $orderInfo = $orderId;
- if (!$orderInfo || !isset($orderInfo['paid'])) exception('支付订单不存在!');
- if ($orderInfo['paid']) exception('支付已支付!');
- if ($orderInfo['pay_price'] <= 0) exception('该支付无需支付!');
- $openid = WechatUser::uidToOpenid($orderInfo['uid'], 'openid');
- $bodyContent = StoreOrder::getProductTitle($orderInfo['cart_id']);
- $site_name = sys_config('site_name');
- if (!$bodyContent && !$site_name) exception('支付参数缺少:请前往后台设置->系统设置-> 填写 网站名称');
- return WechatService::jsPay($openid, $orderInfo['order_id'], $orderInfo['pay_price'], 'product', StoreOrder::getSubstrUTf8($site_name . ' - ' . $bodyContent, 30));
- }
- /**
- * 微信h5支付
- * @param $orderId
- * @param string $field
- * @return array|string
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public static function h5Pay($orderId, $field = 'order_id')
- {
- if (is_string($orderId))
- $orderInfo = StoreOrder::where($field, $orderId)->find();
- else
- $orderInfo = $orderId;
- if (!$orderInfo || !isset($orderInfo['paid'])) exception('支付订单不存在!');
- if ($orderInfo['paid']) exception('支付已支付!');
- if ($orderInfo['pay_price'] <= 0) exception('该支付无需支付!');
- $bodyContent = StoreOrder::getProductTitle($orderInfo['cart_id']);
- $site_name = sys_config('site_name');
- if (!$bodyContent && !$site_name) exception('支付参数缺少:请前往后台设置->系统设置-> 填写 网站名称');
- return WechatService::paymentPrepare(null, $orderInfo['order_id'], $orderInfo['pay_price'], 'product', StoreOrder::getSubstrUTf8($site_name . ' - ' . $bodyContent, 30), '', 'MWEB');
- }
- /**
- * TODO 小程序JS支付
- * @param $orderId
- * @param string $field
- * @return array|string
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public static function jsVotePay($orderId, $field = 'order_id')
- {
- if (is_string($orderId))
- $orderInfo = VoteOrder::where($field, $orderId)->find();
- else
- $orderInfo = $orderId;
- if (!$orderInfo || !isset($orderInfo['paid'])) exception('支付订单不存在!');
- if ($orderInfo['paid']) exception('支付已支付!');
- if ($orderInfo['pay_price'] <= 0) exception('该支付无需支付!');
- $openid = WechatUser::getOpenId($orderInfo['uid']);
- $bodyContent = '参与投票';
- $site_name = sys_config('site_name');
- if (!$bodyContent && !$site_name) exception('支付参数缺少:请前往后台设置->系统设置-> 填写 网站名称');
- return MiniProgramService::jsPay($openid, $orderInfo['order_id'], $orderInfo['pay_price'], 'vote', StoreOrder::getSubstrUTf8($site_name . ' - ' . $bodyContent, 30));
- }
- /**
- * 微信公众号JS支付
- * @param $orderId
- * @param string $field
- * @return array|string
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public static function wxVotePay($orderId, $field = 'order_id')
- {
- if (is_string($orderId))
- $orderInfo = VoteOrder::where($field, $orderId)->find();
- else
- $orderInfo = $orderId;
- if (!$orderInfo || !isset($orderInfo['paid'])) exception('支付订单不存在!');
- if ($orderInfo['paid']) exception('支付已支付!');
- if ($orderInfo['pay_price'] <= 0) exception('该支付无需支付!');
- $openid = WechatUser::uidToOpenid($orderInfo['uid'], 'openid');
- $bodyContent = '参与投票';
- $site_name = sys_config('site_name');
- if (!$bodyContent && !$site_name) exception('支付参数缺少:请前往后台设置->系统设置-> 填写 网站名称');
- return WechatService::jsPay($openid, $orderInfo['order_id'], $orderInfo['pay_price'], 'vote', StoreOrder::getSubstrUTf8($site_name . ' - ' . $bodyContent, 30));
- }
- /**
- * 微信h5支付
- * @param $orderId
- * @param string $field
- * @return array|string
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public static function h5VotePay($orderId, $field = 'order_id')
- {
- if (is_string($orderId))
- $orderInfo = VoteOrder::where($field, $orderId)->find();
- else
- $orderInfo = $orderId;
- if (!$orderInfo || !isset($orderInfo['paid'])) exception('支付订单不存在!');
- if ($orderInfo['paid']) exception('支付已支付!');
- if ($orderInfo['pay_price'] <= 0) exception('该支付无需支付!');
- $bodyContent = '参与投票';
- $site_name = sys_config('site_name');
- if (!$bodyContent && !$site_name) exception('支付参数缺少:请前往后台设置->系统设置-> 填写 网站名称');
- return WechatService::paymentPrepare(null, $orderInfo['order_id'], $orderInfo['pay_price'], 'vote', StoreOrder::getSubstrUTf8($site_name . ' - ' . $bodyContent, 30), '', 'MWEB');
- }
- /**
- * TODO 小程序JS支付
- * @param $orderId
- * @param string $field
- * @return array|string
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public static function jsMemberPay($orderId, $field = 'order_id')
- {
- if (is_string($orderId))
- $orderInfo = MemberCheck::where($field, $orderId)->find();
- else
- $orderInfo = $orderId;
- if (!$orderInfo || !isset($orderInfo['paid'])) exception('支付订单不存在!');
- if ($orderInfo['paid']) exception('支付已支付!');
- if ($orderInfo['pay_money'] <= 0) exception('该支付无需支付!');
- $openid = WechatUser::getOpenId($orderInfo['uid']);
- $bodyContent = '申请会员';
- $site_name = sys_config('site_name');
- if (!$bodyContent && !$site_name) exception('支付参数缺少:请前往后台设置->系统设置-> 填写 网站名称');
- return MiniProgramService::jsPay($openid, $orderInfo['order_id'], $orderInfo['pay_money'], 'member', StoreOrder::getSubstrUTf8($site_name . ' - ' . $bodyContent, 30));
- }
- /**
- * 微信公众号JS支付
- * @param $orderId
- * @param string $field
- * @return array|string
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public static function wxMemberPay($orderId, $field = 'order_id')
- {
- if (is_string($orderId))
- $orderInfo = MemberCheck::where($field, $orderId)->find();
- else
- $orderInfo = $orderId;
- if (!$orderInfo || !isset($orderInfo['paid'])) exception('支付订单不存在!');
- if ($orderInfo['paid']) exception('支付已支付!');
- if ($orderInfo['pay_money'] <= 0) exception('该支付无需支付!');
- $openid = WechatUser::uidToOpenid($orderInfo['uid'], 'openid');
- $bodyContent = '申请会员';
- $site_name = sys_config('site_name');
- if (!$bodyContent && !$site_name) exception('支付参数缺少:请前往后台设置->系统设置-> 填写 网站名称');
- return WechatService::jsPay($openid, $orderInfo['order_id'], $orderInfo['pay_money'], 'member', StoreOrder::getSubstrUTf8($site_name . ' - ' . $bodyContent, 30));
- }
- /**
- * 微信h5支付
- * @param $orderId
- * @param string $field
- * @return array|string
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public static function h5MemberPay($orderId, $field = 'order_id')
- {
- if (is_string($orderId))
- $orderInfo = MemberCheck::where($field, $orderId)->find();
- else
- $orderInfo = $orderId;
- if (!$orderInfo || !isset($orderInfo['paid'])) exception('支付订单不存在!');
- if ($orderInfo['paid']) exception('支付已支付!');
- if ($orderInfo['pay_money'] <= 0) exception('该支付无需支付!');
- $bodyContent = '参与投票';
- $site_name = sys_config('site_name');
- if (!$bodyContent && !$site_name) exception('支付参数缺少:请前往后台设置->系统设置-> 填写 网站名称');
- return WechatService::paymentPrepare(null, $orderInfo['order_id'], $orderInfo['pay_money'], 'member', StoreOrder::getSubstrUTf8($site_name . ' - ' . $bodyContent, 30), '', 'MWEB');
- }
- /**
- * 用户确认收货
- * @param $order
- * @param $uid
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- * @throws \think\db\exception\DbException
- * @throws \Exception
- */
- public static function storeProductOrderUserTakeDelivery($order, $uid)
- {
- $res1 = StoreOrder::gainUserIntegral($order);
- // $res2 = User::backOrderBrokerage($order);
- $res2 = User::sendBackOrderBrokerage($order);
- StoreOrder::orderTakeAfter($order);
- //满赠优惠券
- WechatUser::userTakeOrderGiveCoupon($uid, $order['total_price']);
- if (!($res1 && $res2)) exception('收货失败!');
- }
- /**
- * 修改状态 为已收货 admin模块
- * @param $order
- * @throws \Exception
- */
- public static function storeProductOrderTakeDeliveryAdmin($order)
- {
- $res1 = AdminStoreOrder::gainUserIntegral($order);
- // $res2 = User::backOrderBrokerage($order);
- $res2 = User::sendBackOrderBrokerage($order);
- AdminStoreOrder::orderTakeAfter($order);
- if (!($res1 && $res2)) exception('收货失败!');
- }
- /**
- * 修改状态 为已收货 定时任务使用
- * @param $order
- * @throws \Exception
- */
- public static function storeProductOrderTakeDeliveryTimer($order)
- {
- $res1 = AdminStoreOrder::gainUserIntegral($order, false);
- $res2 = User::sendBackOrderBrokerage($order);
- AdminStoreOrder::orderTakeAfter($order);
- if (!($res1 && $res2)) exception('收货失败!');
- }
- /**
- * 修改状态为 已退款 admin模块
- * @param $data
- * @param $oid
- * @return bool|mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public static function storeProductOrderRefundY($data, $oid)
- {
- $order = AdminStoreOrder::where('id', $oid)->find();
- if ($order['is_channel'] == 1)
- return AdminStoreOrder::refundRoutineTemplate($oid); //TODO 小程序余额退款模板消息
- else
- return AdminStoreOrder::refundTemplate($data, $oid);//TODO 公众号余额退款模板消息
- }
- /**
- * TODO 后台余额退款
- * @param $product
- * @param $refund_data
- * @throws \Exception
- */
- public static function storeOrderYueRefund($product, $refund_data)
- {
- $res = AdminStoreOrder::integralBack($product['id']);
- if (!$res) exception('退积分失败!');
- }
- /**
- * 订单退积分
- * @param $product $product 商品信息
- * @param $back_integral $back_integral 退多少积分
- */
- public static function storeOrderIntegralBack($product, $back_integral)
- {
- }
- }
|