添加:在线买单功能及在线买单支付
This commit is contained in:
parent
3688b0f858
commit
62336133ff
|
|
@ -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);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1049,6 +1049,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository{
|
|||
$totalCost = bcadd($totalCost,$cost,2);
|
||||
$totalNum += $merchantCart['order']['total_num'];
|
||||
}
|
||||
|
||||
$groupOrder = [
|
||||
'uid' => $uid,
|
||||
'group_order_sn' => count($orderList) === 1 ? $orderList[0]['order_sn'] : ($this->getNewOrderId(StoreOrderRepository::TYPE_SN_ORDER).'0'),
|
||||
|
|
@ -2807,7 +2808,110 @@ class StoreOrderCreateRepository extends StoreOrderRepository{
|
|||
}*/
|
||||
|
||||
|
||||
/****** 在线买单 ************************************/
|
||||
public function onlinePayment($payType, $payInfo, $user){
|
||||
$payMoney = abs((float)$payInfo['money']);
|
||||
$merId = (int)$payInfo['mer_id'];
|
||||
$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' => 30,// 30=在线买单
|
||||
'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,
|
||||
'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' => 30,// 30=在线买单
|
||||
];
|
||||
$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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -136,14 +136,19 @@ 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']) . '元购买商品',
|
||||
'mark' => '余额支付' . floatval($groupOrder['pay_price']) . '元购买商品',
|
||||
'balance' => $user->now_money
|
||||
]);
|
||||
];
|
||||
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']]);
|
||||
|
|
@ -225,7 +230,8 @@ class StoreOrderRepository extends BaseRepository
|
|||
$_make->incCount($order->orderProduct[0]['activity_id'], $order->orderProduct[0]['product_sku'], 'two_pay');
|
||||
}
|
||||
$_make->incCount($order->orderProduct[0]['activity_id'], $order->orderProduct[0]['product_sku'], 'one_pay');
|
||||
} else if ($order->activity_type == 4) {
|
||||
}
|
||||
else if ($order->activity_type == 4) {
|
||||
$order->status = 9;
|
||||
$order->save();
|
||||
$group_buying_id = app()->make(ProductGroupBuyingRepository::class)->create(
|
||||
|
|
@ -236,19 +242,24 @@ class StoreOrderRepository extends BaseRepository
|
|||
);
|
||||
$order->orderProduct[0]->activity_id = $group_buying_id;
|
||||
$order->orderProduct[0]->save();
|
||||
} else if ($order->activity_type == 3) {
|
||||
}
|
||||
else if ($order->activity_type == 3) {
|
||||
//更新助力状态
|
||||
app()->make(ProductAssistSetRepository::class)->changStatus($order->orderProduct[0]['activity_id']);
|
||||
}
|
||||
if ($order->order_type == 1 && $order->status != 10)
|
||||
$order->verify_code = $this->verifyCode();
|
||||
if ($order->orderProduct[0]->product->type == 2) {
|
||||
if ($order->order_type == 1 && $order->status != 10) $order->verify_code = $this->verifyCode();
|
||||
if ($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($order->activity_type == 30){
|
||||
$order->status = 3;
|
||||
}
|
||||
|
||||
$order->save();
|
||||
if ($isPoints) $this->takeAfter($order, $groupOrder->user);
|
||||
$orderStatus[] = [
|
||||
|
|
@ -413,12 +424,14 @@ class StoreOrderRepository extends BaseRepository
|
|||
if (count($profitsharing)) {
|
||||
$storeOrderProfitsharingRepository->insertAll($profitsharing);
|
||||
}
|
||||
|
||||
$financialRecordRepository->insertAll($finance);
|
||||
$storeOrderStatusRepository->batchCreateLog($orderStatus);
|
||||
if (count($groupOrder['give_coupon_ids']) > 0)
|
||||
$groupOrder['give_coupon_ids'] = app()->make(StoreCouponRepository::class)->getGiveCoupon($groupOrder['give_coupon_ids'])->column('coupon_id');
|
||||
$groupOrder->save();
|
||||
});
|
||||
|
||||
if (count($groupOrder['give_coupon_ids']) > 0) {
|
||||
try {
|
||||
Queue::push(PayGiveCouponJob::class, ['ids' => $groupOrder['give_coupon_ids'], 'uid' => $groupOrder['uid']]);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
|
||||
namespace app\controller\api\store\order;
|
||||
|
||||
use app\common\repositories\store\order\StoreOrderCreateRepository;
|
||||
use app\common\repositories\store\order\StoreOrderRepository;
|
||||
use app\common\repositories\system\merchant\MerchantRepository;
|
||||
use crmeb\basic\BaseController;
|
||||
use crmeb\services\LockService;
|
||||
|
||||
class OnlinePay extends BaseController{
|
||||
/**
|
||||
* Common: 在线买单 - 搜索商户
|
||||
* Author: wu-hui
|
||||
* Time: 2024/01/12 11:53
|
||||
* @return mixed
|
||||
*/
|
||||
public function searchMer(){
|
||||
$search = $this->request->params(['search_text']);
|
||||
// if(empty($search['search_text'])) return app('json')->fail('请输入搜索内容!');
|
||||
// 内容查询
|
||||
$list = app()->make(MerchantRepository::class)
|
||||
->getSearch([])
|
||||
->field('mer_id,mer_name,mer_address,mer_avatar')
|
||||
->where('is_del',0)
|
||||
->where('mer_state', 1)
|
||||
->where('status', 1)
|
||||
->where(function($query) use ($search){
|
||||
$query->where('mer_name','like',"%{$search['search_text']}%")
|
||||
->whereOr('mer_address','like',"%{$search['search_text']}%");
|
||||
})
|
||||
->order('create_time desc,mer_id desc')
|
||||
->limit(100)
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
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('请选择商户!');
|
||||
// 发起支付
|
||||
$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]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -341,6 +341,9 @@ Route::group('api/', function () {
|
|||
Route::post('deleate/:id', 'PointsOrder/del');
|
||||
})->prefix('api.store.order.');
|
||||
// 在线买单
|
||||
Route::group('onlinePayment', function () {
|
||||
Route::get('searchMerList', 'OnlinePay/searchMer');
|
||||
Route::get('createOrder', 'OnlinePay/createOrder');
|
||||
|
||||
|
||||
|
||||
|
|
@ -349,6 +352,12 @@ Route::group('api/', function () {
|
|||
|
||||
|
||||
|
||||
})->prefix('api.store.order.');
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
})->middleware(UserTokenMiddleware::class, true);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue