|
@@ -8,8 +8,7 @@ use app\admin\model\system\{
|
|
|
use app\admin\model\user\User;
|
|
|
use app\models\routine\RoutineFormId;
|
|
|
use crmeb\repositories\OrderRepository;
|
|
|
-use app\models\store\{
|
|
|
- StoreBargainUser,
|
|
|
+use app\models\store\{StoreBargainUser,
|
|
|
StoreCart,
|
|
|
StoreCoupon,
|
|
|
StoreCouponIssue,
|
|
@@ -18,11 +17,12 @@ use app\models\store\{
|
|
|
StoreOrderCartInfo,
|
|
|
StoreOrderStatus,
|
|
|
StorePink,
|
|
|
- StoreProductReply
|
|
|
-};
|
|
|
+ StoreProduct,
|
|
|
+ StoreProductReply};
|
|
|
use app\models\system\SystemStore;
|
|
|
use app\models\user\UserAddress;
|
|
|
use app\models\user\UserLevel;
|
|
|
+use app\models\user\User as User2;
|
|
|
use app\Request;
|
|
|
use crmeb\services\{
|
|
|
CacheService,
|
|
@@ -283,87 +283,139 @@ class StoreOrderController
|
|
|
*/
|
|
|
public function pay(Request $request)
|
|
|
{
|
|
|
+ // 获取请求参数
|
|
|
list($uni, $paytype, $from) = UtilService::postMore([
|
|
|
['uni', ''],
|
|
|
['paytype', 'weixin'],
|
|
|
['from', 'weixin']
|
|
|
], $request, true);
|
|
|
- if (!$uni) return app('json')->fail('参数错误!');
|
|
|
+
|
|
|
+ // 根据订单号和用户ID获取订单信息
|
|
|
$order = StoreOrder::getUserOrderDetail($request->uid(), $uni);
|
|
|
- if (!$order)
|
|
|
- return app('json')->fail('订单不存在!');
|
|
|
- if ($order['paid'])
|
|
|
- return app('json')->fail('该订单已支付!');
|
|
|
- if ($order['pink_id']) if (StorePink::isPinkStatus($order['pink_id']))
|
|
|
- return app('json')->fail('该订单已失效!');
|
|
|
-
|
|
|
- if ($from == 'weixin') {//0
|
|
|
- if (in_array($order->is_channel, [1, 2]))
|
|
|
- $order['order_id'] = mt_rand(100, 999) . '_' . $order['order_id'];
|
|
|
- }
|
|
|
- if ($from == 'weixinh5') {//2
|
|
|
- if (in_array($order->is_channel, [0, 1]))
|
|
|
- $order['order_id'] = mt_rand(100, 999) . '_' . $order['order_id'];
|
|
|
- }
|
|
|
- if ($from == 'routine') {//1
|
|
|
- if (in_array($order->is_channel, [0, 2]))
|
|
|
- $order['order_id'] = mt_rand(100, 999) . '_' . $order['order_id'];
|
|
|
+
|
|
|
+ // 检查订单是否存在
|
|
|
+ if (!$order) return app('json')->fail('订单不存在!');
|
|
|
+
|
|
|
+ // 检查订单是否已支付
|
|
|
+ if ($order['paid']) return app('json')->fail('该订单已支付!');
|
|
|
+
|
|
|
+ // 检查订单是否失效
|
|
|
+ if ($order['pink_id'] && StorePink::isPinkStatus($order['pink_id'])) return app('json')->fail('该订单已失效!');
|
|
|
+
|
|
|
+ // 根据支付来源调整订单ID
|
|
|
+ if ($from == 'weixin' && in_array($order->is_channel, [1, 2])) {
|
|
|
+ $order['order_id'] = mt_rand(100, 999) . '_' . $order['order_id'];
|
|
|
+ } elseif ($from == 'weixinh5' && in_array($order->is_channel, [0, 1])) {
|
|
|
+ $order['order_id'] = mt_rand(100, 999) . '_' . $order['order_id'];
|
|
|
+ } elseif ($from == 'routine' && in_array($order->is_channel, [0, 2])) {
|
|
|
+ $order['order_id'] = mt_rand(100, 999) . '_' . $order['order_id'];
|
|
|
}
|
|
|
|
|
|
- $order['pay_type'] = $paytype; //重新支付选择支付方式
|
|
|
+ // 重新设置支付方式
|
|
|
+ $order['pay_type'] = $paytype;
|
|
|
+
|
|
|
+ // 根据支付方式进行处理
|
|
|
switch ($order['pay_type']) {
|
|
|
case 'weixin':
|
|
|
try {
|
|
|
- if ($from == 'routine') {
|
|
|
- $jsConfig = OrderRepository::jsPay($order); //订单列表发起支付
|
|
|
- } else if ($from == 'weixinh5') {
|
|
|
- $jsConfig = OrderRepository::h5Pay($order);
|
|
|
- } else {
|
|
|
- $jsConfig = OrderRepository::wxPay($order);
|
|
|
- }
|
|
|
-
|
|
|
- $uid = $request->uid();
|
|
|
- $parent = ''; // 获取推荐人的逻辑,根据您的绑定规则来获取
|
|
|
- $parentArea = ''; // 获取推荐人的区域的逻辑,根据您的绑定规则来获取
|
|
|
-
|
|
|
- if ($parent) {
|
|
|
- // 根据推荐人的逻辑来判断是否需要绑定
|
|
|
- $user = User::where('uid', $uid)->first();
|
|
|
- if (!$user->parent) {
|
|
|
- // 更新用户表中的parent和parent_area字段
|
|
|
- User::where('uid', $uid)->update(['parent' => $parent, 'parent_area' => $parentArea]);
|
|
|
- // 调用User模型中的setParentUser()方法
|
|
|
- $user->setParentUser();
|
|
|
- }
|
|
|
- }
|
|
|
+ $jsConfig = OrderRepository::jsPay($order);
|
|
|
} catch (\Exception $e) {
|
|
|
return app('json')->fail($e->getMessage());
|
|
|
}
|
|
|
+
|
|
|
if ($from == 'weixinh5') {
|
|
|
return app('json')->status('wechat_h5_pay', ['jsConfig' => $jsConfig, 'order_id' => $order['order_id']]);
|
|
|
} else {
|
|
|
+ $this->set_parent($request);
|
|
|
+
|
|
|
return app('json')->status('wechat_pay', ['jsConfig' => $jsConfig, 'order_id' => $order['order_id']]);
|
|
|
}
|
|
|
break;
|
|
|
case 'yue':
|
|
|
- if (StoreOrder::yuePay($order['order_id'], $request->uid()))
|
|
|
+ if (StoreOrder::yuePay($order['order_id'], $request->uid())) {
|
|
|
+ $this->set_parent($request);
|
|
|
+
|
|
|
return app('json')->status('success', '余额支付成功');
|
|
|
- else {
|
|
|
+ } else {
|
|
|
$error = StoreOrder::getErrorInfo();
|
|
|
return app('json')->fail(is_array($error) && isset($error['msg']) ? $error['msg'] : $error);
|
|
|
}
|
|
|
break;
|
|
|
case 'offline':
|
|
|
StoreOrder::createOrderTemplate($order);
|
|
|
- if (StoreOrder::setOrderTypePayOffline($order['order_id']))
|
|
|
+ if (StoreOrder::setOrderTypePayOffline($order['order_id'])) {
|
|
|
return app('json')->status('success', '订单创建成功');
|
|
|
- else
|
|
|
+ } else {
|
|
|
return app('json')->status('success', '支付失败');
|
|
|
+ }
|
|
|
break;
|
|
|
}
|
|
|
+
|
|
|
return app('json')->fail('支付方式错误');
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public function set_parent(Request $request)
|
|
|
+ {
|
|
|
+ $uid = $request->uid(); // 获取当前用户ID
|
|
|
+ $user = User::getUserInfo($uid);
|
|
|
+
|
|
|
+ // 检查该用户是否是当前用户的下级
|
|
|
+ if ($user['spread_uid'] != $uid) return app('json')->fail('该用户并非你的下级');
|
|
|
+
|
|
|
+ // 检查该用户是否已经设置了接点
|
|
|
+ if ($user['parent']) return app('json')->fail('该用户已设置接点');
|
|
|
+
|
|
|
+ // 检查该用户是否已完成报单
|
|
|
+ $storeOrder = StoreOrder::where('uid', $uid)->where('store_order', 1)->where('paid', 1)->find();
|
|
|
+ if (!$storeOrder) return app('json')->fail('该用户尚未完成报单');
|
|
|
+
|
|
|
+ // 检查该用户是否购买了会员商品
|
|
|
+ $isMemberProduct = StoreProduct::where('is_best', 1)->where('id', $user['product_id'])->find();
|
|
|
+ if (!$isMemberProduct) return app('json')->fail('该用户尚未购买会员商品');
|
|
|
+
|
|
|
+ // 根据当前用户的AB区情况选择合适的接点和接点区域
|
|
|
+ $parent = 0;
|
|
|
+ $parent_area = '';
|
|
|
+
|
|
|
+ if ($request->user()['A_count'] == 0) {
|
|
|
+ $parent = $uid; // 接点为当前用户自己
|
|
|
+ $parent_area = 'A';
|
|
|
+ } elseif ($request->user()['B_count'] == 0) {
|
|
|
+ $parent = $uid; // 接点为当前用户自己
|
|
|
+ $parent_area = 'B';
|
|
|
+ } elseif ($request->user()['C_count'] == 0) {
|
|
|
+ // 查找当前用户A区和B区下级最少的区域
|
|
|
+ $aCount = User2::where('parent', $uid)->where('parent_area', 'A')->count();
|
|
|
+ $bCount = User2::where('parent', $uid)->where('parent_area', 'B')->count();
|
|
|
+
|
|
|
+ if ($aCount <= $bCount) {
|
|
|
+ $parent = $uid; // 接点为当前用户自己
|
|
|
+ $parent_area = 'A';
|
|
|
+ } else {
|
|
|
+ $parent = $uid; // 接点为当前用户自己
|
|
|
+ $parent_area = 'B';
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return app('json')->fail('当前用户的ABC区已满');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新用户的接点和接点区域信息
|
|
|
+ User2::where('uid', $uid)->update(['parent' => $parent, 'parent_area' => $parent_area]);
|
|
|
+
|
|
|
+ // 设置用户的上级关系
|
|
|
+ $res = User2::setParentUser($uid, $parent, $parent_area);
|
|
|
+
|
|
|
+ if ($res) {
|
|
|
+ return app('json')->success('设置成功');
|
|
|
+ } else {
|
|
|
+ return app('json')->fail(User2::getErrorInfo('设置失败'));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 订单列表
|
|
|
* @param Request $request
|