From e71d9f9f3ebc2fb1b68f231c3d57ddb74486ba28 Mon Sep 17 00:00:00 2001 From: wuhui_zzw <1760308791@qq.com> Date: Tue, 26 Mar 2024 14:59:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=EF=BC=9A=E5=9C=A8=E7=BA=BF?= =?UTF-8?q?=E4=B9=B0=E5=8D=95=20-=20=E7=A7=BB=E5=8A=A8=E7=AB=AF=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dao/store/order/StoreGroupOrderDao.php | 1 + app/common/dao/store/order/StoreOrderDao.php | 2 +- .../order/StoreOrderCreateRepository.php | 108 +++++++++++++++++ .../store/order/StoreOrderRepository.php | 22 +++- app/controller/api/store/order/OnlinePay.php | 113 ++++++++++++++++++ route/api.php | 13 +- 6 files changed, 246 insertions(+), 13 deletions(-) create mode 100644 app/controller/api/store/order/OnlinePay.php diff --git a/app/common/dao/store/order/StoreGroupOrderDao.php b/app/common/dao/store/order/StoreGroupOrderDao.php index d67ee87..2985035 100644 --- a/app/common/dao/store/order/StoreGroupOrderDao.php +++ b/app/common/dao/store/order/StoreGroupOrderDao.php @@ -50,6 +50,7 @@ class StoreGroupOrderDao extends BaseDao $query = StoreGroupOrder::getDB()->when(isset($where['paid']) && $where['paid'] !== '', function ($query) use ($where) { $query->where('paid', $where['paid']); }) + ->whereNotIn('activity_type', [30]) ->when(isset($where['paid']) && $where['paid'] !== '', function ($query) use ($where) { $query->where('paid', $where['paid']); }) diff --git a/app/common/dao/store/order/StoreOrderDao.php b/app/common/dao/store/order/StoreOrderDao.php index e5dc8d7..7cfb06f 100644 --- a/app/common/dao/store/order/StoreOrderDao.php +++ b/app/common/dao/store/order/StoreOrderDao.php @@ -65,7 +65,7 @@ class StoreOrderDao extends BaseDao } $query->where('is_del',0); }); - $query->where('StoreOrder.activity_type','<>',20); + $query->whereNotIn('StoreOrder.activity_type',[20,30]); $query->when(($sysDel !== null), function ($query) use ($sysDel) { $query->where('is_system_del', $sysDel); }); diff --git a/app/common/repositories/store/order/StoreOrderCreateRepository.php b/app/common/repositories/store/order/StoreOrderCreateRepository.php index 48f3cf8..ff597c6 100644 --- a/app/common/repositories/store/order/StoreOrderCreateRepository.php +++ b/app/common/repositories/store/order/StoreOrderCreateRepository.php @@ -1578,4 +1578,112 @@ class StoreOrderCreateRepository extends StoreOrderRepository Queue::push(SendSmsJob::class, ['tempId' => 'ORDER_CREATE', 'id' => $group->group_order_id]); return $group; } + + + // 在线买单 - 订单、代理入驻 - 订单 + public function onlinePayment($payType, $payInfo, $user, $activityType = 30){ + $payMoney = abs((float)$payInfo['money']); + $merId = array_key_exists('mer_id',$payInfo) ? (int)$payInfo['mer_id'] : 0; + $uid = $user->uid; + // 是否自购 + $isSelfBuy = $user->is_promoter && systemConfig('extension_self') ? 1 : 0; + if($isSelfBuy){ + $spreadUser = $user; + $topUser = $user->valid_spread; + }else{ + $spreadUser = $user->valid_spread; + $topUser = $user->valid_top; + } + // 整理订单数据 + $orderList[] = [ + 'cartInfo' => [], + 'activity_type' => $activityType,// 30=在线买单;32=代理入驻;33=参加活动支付 + 'commission_rate' => 0, + 'order_type' => 0, + 'is_virtual' => 1, + 'extension_one' => 0, + 'extension_two' => 0, + 'order_sn' => $this->getNewOrderId(StoreOrderRepository::TYPE_SN_ORDER).(0 + 1), + 'uid' => $uid, + 'spread_uid' => $spreadUser->uid ?? 0, + 'top_uid' => $topUser->uid ?? 0, + 'is_selfbuy' => $isSelfBuy, + 'real_name' => $user->real_name ?? '', + 'user_phone' => $user->phone ?? '', + 'user_address' => $user->addres ?? '', + 'cart_id' => '', + 'total_num' => 1, + 'total_price' => $payMoney, + 'total_postage' => 0, + 'pay_postage' => 0, + 'svip_discount' => 0, + 'pay_price' => $payMoney, + 'integral' => 0, + 'integral_price' => 0, + 'give_integral' => 0, + 'mer_id' => $merId ?? 0, + 'cost' => 0, + 'order_extend' => '', + 'coupon_id' => '', + 'mark' => '', + 'coupon_price' => '', + 'platform_coupon_price' => '', + 'pay_type' => $payType, + 'refund_switch' => 0, + ]; + $groupOrder = [ + 'uid' => $uid, + 'group_order_sn' => count($orderList) === 1 ? $orderList[0]['order_sn'] : ($this->getNewOrderId(StoreOrderRepository::TYPE_SN_ORDER).'0'), + 'total_postage' => 0, + 'total_price' => $payMoney, + 'total_num' => 1, + 'real_name' => $user->real_name ?? '', + 'user_phone' => $user->phone ?? '', + 'user_address' => $user->addres ?? '', + 'pay_price' => $payMoney, + 'coupon_price' => 0, + 'pay_postage' => 0, + 'cost' => 0, + 'coupon_id' => '', + 'pay_type' => $payType, + 'give_coupon_ids' => '', + 'integral' => 0, + 'integral_price' => 0, + 'give_integral' => 0, + 'activity_type' => $activityType,// 30=在线买单;32=代理入驻;33=参加活动支付 + ]; + $group = Db::transaction(function() use ($user,$groupOrder,$orderList){ + $storeGroupOrderRepository = app()->make(StoreGroupOrderRepository::class); + $storeOrderStatusRepository = app()->make(StoreOrderStatusRepository::class); + //创建订单 + $groupOrder = $storeGroupOrderRepository->create($groupOrder); + foreach($orderList as $k => $order){ + $orderList[$k]['group_order_id'] = $groupOrder->group_order_id; + } + $orderStatus = []; + foreach($orderList as $order){ + $cartInfo = $order['cartInfo']; + unset($order['cartInfo']); + //创建子订单 + $_order = $this->dao->create($order); + $orderStatus[] = [ + 'order_id' => $_order->order_id, + 'order_sn' => $_order->order_sn, + 'type' => $storeOrderStatusRepository::TYPE_ORDER, + 'change_message' => '订单生成', + 'change_type' => $storeOrderStatusRepository::ORDER_STATUS_CREATE, + 'uid' => $user->uid, + 'nickname' => $user->nickname, + 'user_type' => $storeOrderStatusRepository::U_TYPE_USER, + ]; + } + $storeOrderStatusRepository->batchCreateLog($orderStatus); + + return $groupOrder; + }); + + return $group; + } + + } diff --git a/app/common/repositories/store/order/StoreOrderRepository.php b/app/common/repositories/store/order/StoreOrderRepository.php index 583f30f..22ea839 100644 --- a/app/common/repositories/store/order/StoreOrderRepository.php +++ b/app/common/repositories/store/order/StoreOrderRepository.php @@ -136,14 +136,22 @@ class StoreOrderRepository extends BaseRepository $user->now_money = bcsub($user->now_money, $groupOrder['pay_price'], 2); $user->save(); $userBillRepository = app()->make(UserBillRepository::class); - $userBillRepository->decBill($user['uid'], 'now_money', 'pay_product', [ + $data = [ 'link_id' => $groupOrder['group_order_id'], 'status' => 1, 'title' => '购买商品', 'number' => $groupOrder['pay_price'], - 'mark' => '余额支付支付' . floatval($groupOrder['pay_price']) . '元购买商品', - 'balance' => $user->now_money - ]); + 'mark' => '余额支付' . floatval($groupOrder['pay_price']) . '元购买商品', + 'balance' => $user->now_money, + 'with_goods_mer_id' => $groupOrder->with_goods_mer_id + ]; + + if($groupOrder['activity_type'] == 30){ + $data['title'] = '在线买单'; + $data['mark'] = '余额支付' . floatval($groupOrder['pay_price']) . '元'; + } + + $userBillRepository->decBill($user['uid'], 'now_money', 'pay_product', $data); $this->paySuccess($groupOrder); }); return app('json')->status('success', '余额支付成功', ['order_id' => $groupOrder['group_order_id']]); @@ -242,13 +250,17 @@ class StoreOrderRepository extends BaseRepository } if ($order->order_type == 1 && $order->status != 10) $order->verify_code = $this->verifyCode(); - if ($order->orderProduct[0]->product->type == 2) { + if (!in_array($order->activity_type,[30]) && $order->orderProduct[0]->product->type == 2) { $order->status = 2; $order->delivery_type = 6; $order->delivery_name = '自动发货'; $order->delivery_id = $this->sendCdkey($order); $isPoints = true; } + // 判断:是否为在线买单 在线买单,订单支付则订单完成 + if(in_array($order->activity_type,[30])){ + $order->status = 3; + } $order->save(); if ($isPoints) $this->takeAfter($order, $groupOrder->user); $orderStatus[] = [ diff --git a/app/controller/api/store/order/OnlinePay.php b/app/controller/api/store/order/OnlinePay.php new file mode 100644 index 0000000..ea64398 --- /dev/null +++ b/app/controller/api/store/order/OnlinePay.php @@ -0,0 +1,113 @@ +request->params(['search_text','mer_id','lat','lng']); + // if(empty($search['search_text'])) return app('json')->fail('请输入搜索内容!'); + // 内容查询 + $list = app()->make(MerchantRepository::class) + ->getSearch([]) + ->where('is_del',0) + ->where('mer_state', 1) + ->where('status', 1) + ->where('is_online_payment', 1) + ->when((isset($search['lng']) && $search['lng'] > 0) && (isset($search['lat']) && $search['lat'] > 0),function($query) use ($search){ + $distance = "ROUND((ST_DISTANCE(point(`long`, lat), point({$search['lng']}, {$search['lat']})) * 111195),2)"; + $query->field("mer_id,mer_name,mer_address,mer_avatar,{$distance} as distance") + ->orderRaw("{$distance} ASC"); + },function($query){ + $query->field('mer_id,mer_name,mer_address,mer_avatar'); + }) + ->where(function($query) use ($search){ + $query->where('mer_name','like',"%{$search['search_text']}%") + ->whereOr('mer_address','like',"%{$search['search_text']}%"); + }) + ->when((int)$search['mer_id'] > 0,function($query) use ($search){ + $query->where('mer_id',$search['mer_id']); + }) + ->order('create_time desc,mer_id desc') + ->limit(20) + ->select()->each(function($item){ + $item->distance = $item->distance ?? 0; + $item->distance_text = ''; + if($item->distance > 0){ + if ($item->distance < 100) $item->distance_text = '100m以内'; + else $item->distance_text = sprintf("%.2f",$item->distance / 1000).'km'; + } + + return $item; + });; + + return app('json')->success($list); + } + /** + * Common: 在线买单 - 订单生成及发起支付 + * Author: wu-hui + * Time: 2024/01/12 16:07 + * @param StoreOrderCreateRepository $orderCreateRepository + * @return mixed + */ + public function createOrder(StoreOrderCreateRepository $orderCreateRepository){ + // 参数获取 + $payInfo = $this->request->params(['money','pay_type', 'mer_id', 'return_url']); + if (!in_array($payInfo['pay_type'], StoreOrderRepository::PAY_TYPE, true)) return app('json')->fail('请选择正确的支付方式'); + if ((float)$payInfo['money'] <= 0) return app('json')->fail('支付金额必须大于0!'); + if ((int)$payInfo['mer_id'] <= 0) return app('json')->fail('请选择商户!'); + // 判断:当前商户是否支持买单 商户类别:0=普通商户,1=酒道馆,2=供应商 + $isOnlinePayment = (int)app()->make(MerchantRepository::class)->getSearch([]) + ->where('mer_id', (int)$payInfo['mer_id']) + ->value('is_online_payment'); + if($isOnlinePayment != 1) return app('json')->fail('该商户不支持当前操作!'); + // 发起支付 + $groupOrder = app() + ->make(LockService::class) + ->exec('online_order.create',function() use ($payInfo,$orderCreateRepository){ + $payType = array_search($payInfo['pay_type'],StoreOrderRepository::PAY_TYPE); + + return $orderCreateRepository->onlinePayment($payType,$payInfo,$this->request->userInfo()); + }); + + if ($groupOrder['pay_price'] == 0) { + app()->make(StoreOrderRepository::class)->paySuccess($groupOrder); + return app('json')->status('success', '支付成功', ['order_id' => $groupOrder['group_order_id']]); + } + try { + + return app()->make(StoreOrderRepository::class)->pay($payInfo['pay_type'], $this->request->userInfo(), $groupOrder, $payInfo['return_url'], $this->request->isApp()); + } catch (\Exception $e) { + + return app('json')->status('error', $e->getMessage(), ['order_id' => $groupOrder->group_order_id]); + } + } + /** + * Common: 获取买单记录 + * Author: wu-hui + * Time: 2024/01/15 9:23 + * @return mixed + */ + public function getRecord(){ + $params = $this->request->params(['uid','mer_id']); + $params['uid'] = $this->request->uid(); + [$page, $limit] = $this->getPage(); + + $data = app()->make(StoreOrderRepository::class)->getOnlineOrderList((array)$params,(int)$page,(int)$limit); + + return app('json')->success($data); + } + + +} diff --git a/route/api.php b/route/api.php index d0c52c8..65ac53d 100644 --- a/route/api.php +++ b/route/api.php @@ -371,14 +371,13 @@ Route::group('api/', function () { Route::get('statistics', 'PlatformCommission/recordStatistics'); // 记录列表 Route::get('record_list', 'PlatformCommission/recordList'); - - - - - - - })->prefix('api.store.marketing.'); + // 在线买单 + Route::group('onlinePayment', function () { + Route::get('searchMerList', 'OnlinePay/searchMer'); + Route::get('createOrder', 'OnlinePay/createOrder'); + Route::get('record', 'OnlinePay/getRecord'); + })->prefix('api.store.order.');