添加:在线买单 - 移动端相关接口
This commit is contained in:
parent
d4de8c70e2
commit
e71d9f9f3e
|
|
@ -50,6 +50,7 @@ class StoreGroupOrderDao extends BaseDao
|
||||||
$query = StoreGroupOrder::getDB()->when(isset($where['paid']) && $where['paid'] !== '', function ($query) use ($where) {
|
$query = StoreGroupOrder::getDB()->when(isset($where['paid']) && $where['paid'] !== '', function ($query) use ($where) {
|
||||||
$query->where('paid', $where['paid']);
|
$query->where('paid', $where['paid']);
|
||||||
})
|
})
|
||||||
|
->whereNotIn('activity_type', [30])
|
||||||
->when(isset($where['paid']) && $where['paid'] !== '', function ($query) use ($where) {
|
->when(isset($where['paid']) && $where['paid'] !== '', function ($query) use ($where) {
|
||||||
$query->where('paid', $where['paid']);
|
$query->where('paid', $where['paid']);
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ class StoreOrderDao extends BaseDao
|
||||||
}
|
}
|
||||||
$query->where('is_del',0);
|
$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->when(($sysDel !== null), function ($query) use ($sysDel) {
|
||||||
$query->where('is_system_del', $sysDel);
|
$query->where('is_system_del', $sysDel);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1578,4 +1578,112 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
||||||
Queue::push(SendSmsJob::class, ['tempId' => 'ORDER_CREATE', 'id' => $group->group_order_id]);
|
Queue::push(SendSmsJob::class, ['tempId' => 'ORDER_CREATE', 'id' => $group->group_order_id]);
|
||||||
return $group;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -136,14 +136,22 @@ class StoreOrderRepository extends BaseRepository
|
||||||
$user->now_money = bcsub($user->now_money, $groupOrder['pay_price'], 2);
|
$user->now_money = bcsub($user->now_money, $groupOrder['pay_price'], 2);
|
||||||
$user->save();
|
$user->save();
|
||||||
$userBillRepository = app()->make(UserBillRepository::class);
|
$userBillRepository = app()->make(UserBillRepository::class);
|
||||||
$userBillRepository->decBill($user['uid'], 'now_money', 'pay_product', [
|
$data = [
|
||||||
'link_id' => $groupOrder['group_order_id'],
|
'link_id' => $groupOrder['group_order_id'],
|
||||||
'status' => 1,
|
'status' => 1,
|
||||||
'title' => '购买商品',
|
'title' => '购买商品',
|
||||||
'number' => $groupOrder['pay_price'],
|
'number' => $groupOrder['pay_price'],
|
||||||
'mark' => '余额支付支付' . floatval($groupOrder['pay_price']) . '元购买商品',
|
'mark' => '余额支付' . floatval($groupOrder['pay_price']) . '元购买商品',
|
||||||
'balance' => $user->now_money
|
'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);
|
$this->paySuccess($groupOrder);
|
||||||
});
|
});
|
||||||
return app('json')->status('success', '余额支付成功', ['order_id' => $groupOrder['group_order_id']]);
|
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)
|
if ($order->order_type == 1 && $order->status != 10)
|
||||||
$order->verify_code = $this->verifyCode();
|
$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->status = 2;
|
||||||
$order->delivery_type = 6;
|
$order->delivery_type = 6;
|
||||||
$order->delivery_name = '自动发货';
|
$order->delivery_name = '自动发货';
|
||||||
$order->delivery_id = $this->sendCdkey($order);
|
$order->delivery_id = $this->sendCdkey($order);
|
||||||
$isPoints = true;
|
$isPoints = true;
|
||||||
}
|
}
|
||||||
|
// 判断:是否为在线买单 在线买单,订单支付则订单完成
|
||||||
|
if(in_array($order->activity_type,[30])){
|
||||||
|
$order->status = 3;
|
||||||
|
}
|
||||||
$order->save();
|
$order->save();
|
||||||
if ($isPoints) $this->takeAfter($order, $groupOrder->user);
|
if ($isPoints) $this->takeAfter($order, $groupOrder->user);
|
||||||
$orderStatus[] = [
|
$orderStatus[] = [
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,113 @@
|
||||||
|
<?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','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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -371,14 +371,13 @@ Route::group('api/', function () {
|
||||||
Route::get('statistics', 'PlatformCommission/recordStatistics');
|
Route::get('statistics', 'PlatformCommission/recordStatistics');
|
||||||
// 记录列表
|
// 记录列表
|
||||||
Route::get('record_list', 'PlatformCommission/recordList');
|
Route::get('record_list', 'PlatformCommission/recordList');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
})->prefix('api.store.marketing.');
|
})->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.');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue