|
@@ -15,6 +15,7 @@ use app\models\store\{
|
|
|
StoreCouponIssue,
|
|
StoreCouponIssue,
|
|
|
StoreCouponUser,
|
|
StoreCouponUser,
|
|
|
StoreOrder,
|
|
StoreOrder,
|
|
|
|
|
+ StoreOrderBatch,
|
|
|
StoreOrderCartInfo,
|
|
StoreOrderCartInfo,
|
|
|
StoreOrderStatus,
|
|
StoreOrderStatus,
|
|
|
StorePink,
|
|
StorePink,
|
|
@@ -50,8 +51,11 @@ class StoreOrderController
|
|
|
// TODO: 运费模板只能选择 ID 为 1 的模板?
|
|
// TODO: 运费模板只能选择 ID 为 1 的模板?
|
|
|
$temp = ShippingTemplates::get(1);
|
|
$temp = ShippingTemplates::get(1);
|
|
|
if (!$temp) return app('json')->fail('默认模板未配置,无法下单');
|
|
if (!$temp) return app('json')->fail('默认模板未配置,无法下单');
|
|
|
|
|
+
|
|
|
list($cartId) = UtilService::postMore(['cartId'], $request, true);
|
|
list($cartId) = UtilService::postMore(['cartId'], $request, true);
|
|
|
if (!is_string($cartId) || !$cartId) return app('json')->fail('请提交购买的商品');
|
|
if (!is_string($cartId) || !$cartId) return app('json')->fail('请提交购买的商品');
|
|
|
|
|
+
|
|
|
|
|
+ // 查询当前购物车有效的商品
|
|
|
$uid = $request->uid();
|
|
$uid = $request->uid();
|
|
|
$cartGroup = StoreCart::getUserProductCartList($uid, $cartId, 1);
|
|
$cartGroup = StoreCart::getUserProductCartList($uid, $cartId, 1);
|
|
|
if (count($cartGroup['invalid'])) {
|
|
if (count($cartGroup['invalid'])) {
|
|
@@ -60,15 +64,17 @@ class StoreOrderController
|
|
|
if (!$cartGroup['valid']) {
|
|
if (!$cartGroup['valid']) {
|
|
|
return app('json')->fail('请提交购买的商品');
|
|
return app('json')->fail('请提交购买的商品');
|
|
|
}
|
|
}
|
|
|
|
|
+ //
|
|
|
$cartInfo = $cartGroup['valid'];
|
|
$cartInfo = $cartGroup['valid'];
|
|
|
$addr = UserAddress::getUserDefaultAddress($uid); //UserAddress::where('uid', $uid)->where('is_default', 1)->find();
|
|
$addr = UserAddress::getUserDefaultAddress($uid); //UserAddress::where('uid', $uid)->where('is_default', 1)->find();
|
|
|
|
|
+ // 获取当前购物车中各项价格
|
|
|
$priceGroup = StoreOrder::getOrderPriceGroup($cartInfo, $addr);
|
|
$priceGroup = StoreOrder::getOrderPriceGroup($cartInfo, $addr);
|
|
|
if ($priceGroup === false) {
|
|
if ($priceGroup === false) {
|
|
|
return app('json')->fail(StoreOrder::getErrorInfo('运费模板不存在'));
|
|
return app('json')->fail(StoreOrder::getErrorInfo('运费模板不存在'));
|
|
|
}
|
|
}
|
|
|
$other = [
|
|
$other = [
|
|
|
- 'offlinePostage' => sys_config('offline_postage'),
|
|
|
|
|
- 'integralRatio' => sys_config('integral_ratio')
|
|
|
|
|
|
|
+ 'offlinePostage' => sys_config('offline_postage'), // 线下支付是否包邮
|
|
|
|
|
+ 'integralRatio' => sys_config('integral_ratio') // 积分抵用比例
|
|
|
];
|
|
];
|
|
|
$usableCoupons = []; // TIP 屏蔽优惠券 StoreCouponUser::getUsableCouponList($uid, $cartGroup, $priceGroup['totalPrice']);
|
|
$usableCoupons = []; // TIP 屏蔽优惠券 StoreCouponUser::getUsableCouponList($uid, $cartGroup, $priceGroup['totalPrice']);
|
|
|
$usableCoupon = isset($usableCoupons[0]) ? $usableCoupons[0] : null;
|
|
$usableCoupon = isset($usableCoupons[0]) ? $usableCoupons[0] : null;
|
|
@@ -103,7 +109,7 @@ class StoreOrderController
|
|
|
}
|
|
}
|
|
|
$data['userInfo'] = $user;
|
|
$data['userInfo'] = $user;
|
|
|
$data['integralRatio'] = $other['integralRatio'];
|
|
$data['integralRatio'] = $other['integralRatio'];
|
|
|
- $data['offline_pay_status'] = (int)sys_config('offline_pay_status') ?? (int)2;
|
|
|
|
|
|
|
+ $data['offline_pay_status'] = (int)sys_config('offline_pay_status') ?? (int)2; // 线下支付
|
|
|
$data['store_self_mention'] = (int)sys_config('store_self_mention') ?? 0;//门店自提是否开启
|
|
$data['store_self_mention'] = (int)sys_config('store_self_mention') ?? 0;//门店自提是否开启
|
|
|
$data['system_store'] = []; // TIP: 屏蔽门店信息 ($res = SystemStore::getStoreDispose()) ? $res : [];//门店信息
|
|
$data['system_store'] = []; // TIP: 屏蔽门店信息 ($res = SystemStore::getStoreDispose()) ? $res : [];//门店信息
|
|
|
return app('json')->successful($data);
|
|
return app('json')->successful($data);
|
|
@@ -121,9 +127,9 @@ class StoreOrderController
|
|
|
*/
|
|
*/
|
|
|
public function computedOrder(Request $request, $key)
|
|
public function computedOrder(Request $request, $key)
|
|
|
{
|
|
{
|
|
|
-
|
|
|
|
|
-// $priceGroup = StoreOrder::getOrderPriceGroup($cartInfo);
|
|
|
|
|
|
|
+ // $key 就是 confirm 返回的 orderKey
|
|
|
if (!$key) return app('json')->fail('参数错误!');
|
|
if (!$key) return app('json')->fail('参数错误!');
|
|
|
|
|
+ // 是否已存在
|
|
|
$uid = $request->uid();
|
|
$uid = $request->uid();
|
|
|
if (StoreOrder::be(['order_id|unique' => $key, 'uid' => $uid, 'is_del' => 0]))
|
|
if (StoreOrder::be(['order_id|unique' => $key, 'uid' => $uid, 'is_del' => 0]))
|
|
|
return app('json')->status('extend_order', '订单已生成', ['orderId' => $key, 'key' => $key]);
|
|
return app('json')->status('extend_order', '订单已生成', ['orderId' => $key, 'key' => $key]);
|
|
@@ -141,6 +147,7 @@ class StoreOrderController
|
|
|
['bargainId', ''],
|
|
['bargainId', ''],
|
|
|
['shipping_type', 1],
|
|
['shipping_type', 1],
|
|
|
], $request, true);
|
|
], $request, true);
|
|
|
|
|
+ // weixin / yue
|
|
|
$payType = strtolower($payType);
|
|
$payType = strtolower($payType);
|
|
|
if ($bargainId) {
|
|
if ($bargainId) {
|
|
|
$bargainUserTableId = StoreBargainUser::getBargainUserTableId($bargainId, $uid);//TODO 获取用户参与砍价表编号
|
|
$bargainUserTableId = StoreBargainUser::getBargainUserTableId($bargainId, $uid);//TODO 获取用户参与砍价表编号
|
|
@@ -161,7 +168,8 @@ class StoreOrderController
|
|
|
if (StoreOrder::getIsOrderPink($pinkId, $request->uid()))
|
|
if (StoreOrder::getIsOrderPink($pinkId, $request->uid()))
|
|
|
return app('json')->status('ORDER_EXIST', '订单生成失败,你已经参加该团了,请先支付订单', ['orderId' => StoreOrder::getStoreIdPink($pinkId, $request->uid())]);
|
|
return app('json')->status('ORDER_EXIST', '订单生成失败,你已经参加该团了,请先支付订单', ['orderId' => StoreOrder::getStoreIdPink($pinkId, $request->uid())]);
|
|
|
}
|
|
}
|
|
|
- $priceGroup = StoreOrder::cacheKeyCreateOrder($request->uid(), $key, $addressId, $payType, (int)$useIntegral, $couponId, $mark, $combinationId, $pinkId, $seckill_id, $bargainId, true, 0, $shipping_type);
|
|
|
|
|
|
|
+ $priceGroup = StoreOrder::cacheKeyCreateOrder($request->uid(), $key, $addressId, $payType, (int)$useIntegral,
|
|
|
|
|
+ $couponId, $mark, $combinationId, $pinkId, $seckill_id, $bargainId, true, 0, $shipping_type);
|
|
|
// return app('json')->fail(StoreOrder::getErrorInfo('计算失败'));
|
|
// return app('json')->fail(StoreOrder::getErrorInfo('计算失败'));
|
|
|
if ($priceGroup)
|
|
if ($priceGroup)
|
|
|
return app('json')->status('NONE', 'ok', $priceGroup);
|
|
return app('json')->status('NONE', 'ok', $priceGroup);
|
|
@@ -181,14 +189,24 @@ class StoreOrderController
|
|
|
*/
|
|
*/
|
|
|
public function create(Request $request, $key)
|
|
public function create(Request $request, $key)
|
|
|
{
|
|
{
|
|
|
|
|
+ // 还是那个 $orderKey
|
|
|
if (!$key) return app('json')->fail('参数错误!');
|
|
if (!$key) return app('json')->fail('参数错误!');
|
|
|
|
|
+ // 订单是否已存在
|
|
|
$uid = $request->uid();
|
|
$uid = $request->uid();
|
|
|
if (StoreOrder::be(['order_id|unique' => $key, 'uid' => $uid, 'is_del' => 0]))
|
|
if (StoreOrder::be(['order_id|unique' => $key, 'uid' => $uid, 'is_del' => 0]))
|
|
|
return app('json')->status('extend_order', '订单已生成', ['orderId' => $key, 'key' => $key]);
|
|
return app('json')->status('extend_order', '订单已生成', ['orderId' => $key, 'key' => $key]);
|
|
|
|
|
+ // 获得参数
|
|
|
list($addressId, $couponId, $payType, $useIntegral, $mark, $combinationId, $pinkId, $seckill_id, $formId, $bargainId, $from, $shipping_type, $real_name, $phone, $storeId) = UtilService::postMore([
|
|
list($addressId, $couponId, $payType, $useIntegral, $mark, $combinationId, $pinkId, $seckill_id, $formId, $bargainId, $from, $shipping_type, $real_name, $phone, $storeId) = UtilService::postMore([
|
|
|
- 'addressId', 'couponId', 'payType', ['useIntegral', 0], 'mark', ['combinationId', 0], ['pinkId', 0], ['seckill_id', 0], ['formId', ''], ['bargainId', ''], ['from', 'weixin'],
|
|
|
|
|
|
|
+ 'addressId',
|
|
|
|
|
+ 'couponId',
|
|
|
|
|
+ 'payType',
|
|
|
|
|
+ ['useIntegral', 0],
|
|
|
|
|
+ 'mark',
|
|
|
|
|
+ ['combinationId', 0], ['pinkId', 0], ['seckill_id', 0], ['formId', ''], ['bargainId', ''],
|
|
|
|
|
+ ['from', 'weixin'],
|
|
|
['shipping_type', 1], ['real_name', ''], ['phone', ''], ['store_id', 0]
|
|
['shipping_type', 1], ['real_name', ''], ['phone', ''], ['store_id', 0]
|
|
|
], $request, true);
|
|
], $request, true);
|
|
|
|
|
+ // weixin / yue
|
|
|
$payType = strtolower($payType);
|
|
$payType = strtolower($payType);
|
|
|
if ($bargainId) {
|
|
if ($bargainId) {
|
|
|
$bargainUserTableId = StoreBargainUser::getBargainUserTableId($bargainId, $uid);//TODO 获取用户参与砍价表编号
|
|
$bargainUserTableId = StoreBargainUser::getBargainUserTableId($bargainId, $uid);//TODO 获取用户参与砍价表编号
|
|
@@ -209,18 +227,22 @@ class StoreOrderController
|
|
|
if (StoreOrder::getIsOrderPink($pinkId, $request->uid()))
|
|
if (StoreOrder::getIsOrderPink($pinkId, $request->uid()))
|
|
|
return app('json')->status('ORDER_EXIST', '订单生成失败,你已经参加该团了,请先支付订单', ['orderId' => StoreOrder::getStoreIdPink($pinkId, $request->uid())]);
|
|
return app('json')->status('ORDER_EXIST', '订单生成失败,你已经参加该团了,请先支付订单', ['orderId' => StoreOrder::getStoreIdPink($pinkId, $request->uid())]);
|
|
|
}
|
|
}
|
|
|
- $isChannel = 1;
|
|
|
|
|
|
|
+ $isChannel = 1; // 'routine'
|
|
|
if ($from == 'weixin')
|
|
if ($from == 'weixin')
|
|
|
$isChannel = 0;
|
|
$isChannel = 0;
|
|
|
elseif ($from == 'weixinh5')
|
|
elseif ($from == 'weixinh5')
|
|
|
$isChannel = 2;
|
|
$isChannel = 2;
|
|
|
- $order = StoreOrder::cacheKeyCreateOrder($request->uid(), $key, $addressId, $payType, (int)$useIntegral, $couponId, $mark, $combinationId, $pinkId, $seckill_id, $bargainId, false, $isChannel, $shipping_type, $real_name, $phone, $storeId);
|
|
|
|
|
- if ($order === false) return app('json')->fail(StoreOrder::getErrorInfo('订单生成失败'));
|
|
|
|
|
|
|
+ $order = StoreOrder::cacheKeyCreateOrder($request->uid(), $key, $addressId, $payType, (int)$useIntegral,
|
|
|
|
|
+ $couponId, $mark, $combinationId, $pinkId, $seckill_id, $bargainId, false, $isChannel,
|
|
|
|
|
+ $shipping_type, $real_name, $phone, $storeId);
|
|
|
|
|
+ if ($order === false) {
|
|
|
|
|
+ return app('json')->fail(StoreOrder::getErrorInfo('订单生成失败'));
|
|
|
|
|
+ }
|
|
|
$orderId = $order['order_id'];
|
|
$orderId = $order['order_id'];
|
|
|
$info = compact('orderId', 'key');
|
|
$info = compact('orderId', 'key');
|
|
|
if ($orderId) {
|
|
if ($orderId) {
|
|
|
event('OrderCreated', [$order]); //订单创建成功事件
|
|
event('OrderCreated', [$order]); //订单创建成功事件
|
|
|
-// event('ShortMssageSend', [$orderId, 'AdminPlaceAnOrder']);//发送管理员通知
|
|
|
|
|
|
|
+ // event('ShortMssageSend', [$orderId, 'AdminPlaceAnOrder']);//发送管理员通知
|
|
|
switch ($payType) {
|
|
switch ($payType) {
|
|
|
case "weixin":
|
|
case "weixin":
|
|
|
$orderInfo = StoreOrder::where('order_id', $orderId)->find();
|
|
$orderInfo = StoreOrder::where('order_id', $orderId)->find();
|
|
@@ -270,7 +292,195 @@ class StoreOrderController
|
|
|
return app('json')->status('success', '订单创建成功', $info);
|
|
return app('json')->status('success', '订单创建成功', $info);
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
- } else return app('json')->fail(StoreOrder::getErrorInfo('订单生成失败!'));
|
|
|
|
|
|
|
+ } else { // !$orderId
|
|
|
|
|
+ return app('json')->fail(StoreOrder::getErrorInfo('订单生成失败!'));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 计算订单金额
|
|
|
|
|
+ * @param Request $request
|
|
|
|
|
+ * @param $key
|
|
|
|
|
+ * @return mixed
|
|
|
|
|
+ * @throws \think\Exception
|
|
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
|
|
+ * @throws \think\exception\DbException
|
|
|
|
|
+ */
|
|
|
|
|
+ public function computedOrder_v2(Request $request, $key)
|
|
|
|
|
+ {
|
|
|
|
|
+ // $key 就是 confirm 返回的 orderKey
|
|
|
|
|
+ if (!$key) return app('json')->fail('参数错误!');
|
|
|
|
|
+ // 是否已存在
|
|
|
|
|
+ $uid = $request->uid();
|
|
|
|
|
+ if (StoreOrderBatch::be(['unique' => $key, 'uid' => $uid]))
|
|
|
|
|
+ return app('json')->status('extend_order', '订单已生成', ['orderId' => $key, 'key' => $key]);
|
|
|
|
|
+ list($addressId, $couponId, $payType, $useIntegral, $mark,
|
|
|
|
|
+ $combinationId, $pinkId, $seckill_id, $formId, $bargainId, $shipping_type) = UtilService::postMore([
|
|
|
|
|
+ 'addressId',
|
|
|
|
|
+ 'couponId',
|
|
|
|
|
+ ['payType', 'yue'],
|
|
|
|
|
+ ['useIntegral', 0],
|
|
|
|
|
+ 'mark',
|
|
|
|
|
+ ['combinationId', 0],
|
|
|
|
|
+ ['pinkId', 0],
|
|
|
|
|
+ ['seckill_id', 0],
|
|
|
|
|
+ ['formId', ''],
|
|
|
|
|
+ ['bargainId', ''],
|
|
|
|
|
+ ['shipping_type', 1],
|
|
|
|
|
+ ], $request, true);
|
|
|
|
|
+ // weixin / yue
|
|
|
|
|
+ $payType = strtolower($payType);
|
|
|
|
|
+ if ($bargainId) {
|
|
|
|
|
+ $bargainUserTableId = StoreBargainUser::getBargainUserTableId($bargainId, $uid);//TODO 获取用户参与砍价表编号
|
|
|
|
|
+ if (!$bargainUserTableId)
|
|
|
|
|
+ return app('json')->fail('砍价失败');
|
|
|
|
|
+ $status = StoreBargainUser::getBargainUserStatusEnd($bargainUserTableId);
|
|
|
|
|
+ if ($status == 3)
|
|
|
|
|
+ return app('json')->fail('砍价已支付');
|
|
|
|
|
+ StoreBargainUser::setBargainUserStatus($bargainId, $uid); //修改砍价状态
|
|
|
|
|
+ }
|
|
|
|
|
+ if ($pinkId) {
|
|
|
|
|
+ $cache_pink = Cache::get(md5('store_pink_' . $pinkId));
|
|
|
|
|
+ if ($cache_pink && bcsub($cache_pink['people'], $cache_pink['now_people'], 0) <= 0) {
|
|
|
|
|
+ return app('json')->status('ORDER_EXIST', '订单生成失败,该团人员已满', ['orderId' => StoreOrder::getStoreIdPink($pinkId, $request->uid())]);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StorePink::getIsPinkUid($pinkId, $request->uid()))
|
|
|
|
|
+ return app('json')->status('ORDER_EXIST', '订单生成失败,你已经在该团内不能再参加了', ['orderId' => StoreOrder::getStoreIdPink($pinkId, $request->uid())]);
|
|
|
|
|
+ if (StoreOrder::getIsOrderPink($pinkId, $request->uid()))
|
|
|
|
|
+ return app('json')->status('ORDER_EXIST', '订单生成失败,你已经参加该团了,请先支付订单', ['orderId' => StoreOrder::getStoreIdPink($pinkId, $request->uid())]);
|
|
|
|
|
+ }
|
|
|
|
|
+ $priceGroup = StoreOrderBatch::cacheKeyCreateOrderBatch($request->uid(), $key, $addressId, $payType, (int)$useIntegral,
|
|
|
|
|
+ $couponId, $mark, $combinationId, $pinkId, $seckill_id, $bargainId, true, 0, $shipping_type);
|
|
|
|
|
+ // return app('json')->fail(StoreOrder::getErrorInfo('计算失败'));
|
|
|
|
|
+ if ($priceGroup)
|
|
|
|
|
+ return app('json')->status('NONE', 'ok', $priceGroup);
|
|
|
|
|
+ else
|
|
|
|
|
+ return app('json')->fail(StoreOrder::getErrorInfo('计算失败'));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 订单创建, 支持子订单版本
|
|
|
|
|
+ * @param Request $request
|
|
|
|
|
+ * @param $key
|
|
|
|
|
+ * @return mixed
|
|
|
|
|
+ * @throws \think\Exception
|
|
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
|
|
+ * @throws \think\exception\DbException
|
|
|
|
|
+ */
|
|
|
|
|
+ public function create_v2(Request $request, $key)
|
|
|
|
|
+ {
|
|
|
|
|
+ // 还是那个 $orderKey
|
|
|
|
|
+ if (!$key) {
|
|
|
|
|
+ return app('json')->fail('参数错误!');
|
|
|
|
|
+ }
|
|
|
|
|
+ // 订单是否已存在
|
|
|
|
|
+ $uid = $request->uid();
|
|
|
|
|
+ if (StoreOrderBatch::be(['unique' => $key, 'uid' => $uid]))
|
|
|
|
|
+ return app('json')->status('extend_order', '订单已生成', ['orderId' => $key, 'key' => $key]);
|
|
|
|
|
+ // 获得参数
|
|
|
|
|
+ list($addressId, $couponId, $payType, $useIntegral, $mark, $combinationId, $pinkId, $seckill_id, $formId, $bargainId, $from, $shipping_type, $real_name, $phone, $storeId) = UtilService::postMore([
|
|
|
|
|
+ 'addressId',
|
|
|
|
|
+ 'couponId',
|
|
|
|
|
+ 'payType',
|
|
|
|
|
+ ['useIntegral', 0],
|
|
|
|
|
+ 'mark',
|
|
|
|
|
+ ['combinationId', 0], ['pinkId', 0], ['seckill_id', 0], ['formId', ''], ['bargainId', ''],
|
|
|
|
|
+ ['from', 'weixin'],
|
|
|
|
|
+ ['shipping_type', 1], ['real_name', ''], ['phone', ''], ['store_id', 0]
|
|
|
|
|
+ ], $request, true);
|
|
|
|
|
+ // weixin / yue
|
|
|
|
|
+ $payType = strtolower($payType);
|
|
|
|
|
+ if ($bargainId) {
|
|
|
|
|
+ $bargainUserTableId = StoreBargainUser::getBargainUserTableId($bargainId, $uid);//TODO 获取用户参与砍价表编号
|
|
|
|
|
+ if (!$bargainUserTableId)
|
|
|
|
|
+ return app('json')->fail('砍价失败');
|
|
|
|
|
+ $status = StoreBargainUser::getBargainUserStatusEnd($bargainUserTableId);
|
|
|
|
|
+ if ($status == 3)
|
|
|
|
|
+ return app('json')->fail('砍价已支付');
|
|
|
|
|
+ StoreBargainUser::setBargainUserStatus($bargainId, $uid); //修改砍价状态
|
|
|
|
|
+ }
|
|
|
|
|
+ if ($pinkId) {
|
|
|
|
|
+ $cache_pink = Cache::get(md5('store_pink_' . $pinkId));
|
|
|
|
|
+ if ($cache_pink && bcsub($cache_pink['people'], $cache_pink['now_people'], 0) <= 0) {
|
|
|
|
|
+ return app('json')->status('ORDER_EXIST', '订单生成失败,该团人员已满', ['orderId' => StoreOrder::getStoreIdPink($pinkId, $request->uid())]);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StorePink::getIsPinkUid($pinkId, $request->uid()))
|
|
|
|
|
+ return app('json')->status('ORDER_EXIST', '订单生成失败,你已经在该团内不能再参加了', ['orderId' => StoreOrder::getStoreIdPink($pinkId, $request->uid())]);
|
|
|
|
|
+ if (StoreOrder::getIsOrderPink($pinkId, $request->uid()))
|
|
|
|
|
+ return app('json')->status('ORDER_EXIST', '订单生成失败,你已经参加该团了,请先支付订单', ['orderId' => StoreOrder::getStoreIdPink($pinkId, $request->uid())]);
|
|
|
|
|
+ }
|
|
|
|
|
+ $isChannel = 1; // 'routine'
|
|
|
|
|
+ if ($from == 'weixin')
|
|
|
|
|
+ $isChannel = 0;
|
|
|
|
|
+ elseif ($from == 'weixinh5')
|
|
|
|
|
+ $isChannel = 2;
|
|
|
|
|
+ $porderId = StoreOrderBatch::cacheKeyCreateOrderBatch($request->uid(), $key, $addressId, $payType, (int)$useIntegral,
|
|
|
|
|
+ $couponId, $mark, $combinationId, $pinkId, $seckill_id, $bargainId, false, $isChannel,
|
|
|
|
|
+ $shipping_type, $real_name, $phone, $storeId);
|
|
|
|
|
+ if ($porderId === false) {
|
|
|
|
|
+ return app('json')->fail(StoreOrderBatch::getErrorInfo('订单生成失败'));
|
|
|
|
|
+ }
|
|
|
|
|
+ $orderId = $porderId; // for compact
|
|
|
|
|
+ $info = compact('orderId', 'key');
|
|
|
|
|
+ if ($porderId) {
|
|
|
|
|
+ event('BatchOrderCreated', [$porderId]); //订单创建成功事件
|
|
|
|
|
+ // event('ShortMssageSend', [$orderId, 'AdminPlaceAnOrder']);//发送管理员通知
|
|
|
|
|
+ switch ($payType) {
|
|
|
|
|
+ case "weixin":
|
|
|
|
|
+ $subOrders = StoreOrderBatch::getAllSubOrders($porderId);
|
|
|
|
|
+ if (!$subOrders) return app('json')->fail('支付订单不存在!');
|
|
|
|
|
+ $fieldValues = StoreOrderBatch::sumFields($subOrders, ['paid','pay_price']);
|
|
|
|
|
+ if ($fieldValues['paid']) {
|
|
|
|
|
+ return app('json')->fail('支付已支付!');
|
|
|
|
|
+ }
|
|
|
|
|
+ //支付金额为0
|
|
|
|
|
+ if (bcsub($fieldValues['pay_price'], 0, 2) <= 0) {
|
|
|
|
|
+ //创建订单jspay支付
|
|
|
|
|
+ $payPriceStatus = StoreOrderBatch::jsPayPriceBatch($porderId, $uid, $formId);
|
|
|
|
|
+ if ($payPriceStatus)//0元支付成功
|
|
|
|
|
+ return app('json')->status('success', '微信支付成功', $info);
|
|
|
|
|
+ else
|
|
|
|
|
+ return app('json')->status('pay_error', StoreOrderBatch::getErrorInfo());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ try {
|
|
|
|
|
+ if ($from == 'routine') {
|
|
|
|
|
+ $jsConfig = OrderRepository::jsPayBatch($porderId); //创建订单jspay
|
|
|
|
|
+ } else if ($from == 'weixinh5') {
|
|
|
|
|
+ $jsConfig = OrderRepository::h5PayBatch($porderId);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $jsConfig = OrderRepository::wxPayBatch($porderId);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (\Exception $e) {
|
|
|
|
|
+ return app('json')->status('pay_error', $e->getMessage(), $info);
|
|
|
|
|
+ }
|
|
|
|
|
+ $info['jsConfig'] = $jsConfig;
|
|
|
|
|
+ if ($from == 'weixinh5') {
|
|
|
|
|
+ return app('json')->status('wechat_h5_pay', '订单创建成功', $info);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return app('json')->status('wechat_pay', '订单创建成功', $info);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 'yue':
|
|
|
|
|
+ if (StoreOrderBatch::yuePayBatch($porderId, $request->uid(), $formId))
|
|
|
|
|
+ return app('json')->status('success', '余额支付成功', $info);
|
|
|
|
|
+ else {
|
|
|
|
|
+ $errorinfo = StoreOrderBatch::getErrorInfo();
|
|
|
|
|
+ if (is_array($errorinfo))
|
|
|
|
|
+ return app('json')->status($errorinfo['status'], $errorinfo['msg'], $info);
|
|
|
|
|
+ else
|
|
|
|
|
+ return app('json')->status('pay_error', $errorinfo);
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 'offline':
|
|
|
|
|
+ return app('json')->status('success', '订单创建成功', $info);
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else { // !$orderId
|
|
|
|
|
+ return app('json')->fail(StoreOrderBatch::getErrorInfo('订单生成失败!'));
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -396,6 +606,37 @@ class StoreOrderController
|
|
|
return app('json')->successful(StoreOrder::getUserOrderSearchList($request->uid(), $type, $page, $limit, $search));
|
|
return app('json')->successful(StoreOrder::getUserOrderSearchList($request->uid(), $type, $page, $limit, $search));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 订单详情 v2
|
|
|
|
|
+ * 订单支持子订单之后,订单详情协议传过来的 $uni 有可能是子订单的,也有可能是主订单的
|
|
|
|
|
+ */
|
|
|
|
|
+ public function detail_v2(Request $request, $uni)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (!strlen(trim($uni))) return app('json')->fail('参数错误');
|
|
|
|
|
+ $uid = $request->uid();
|
|
|
|
|
+ $first4 = mb_substr($uni, 0, 4);
|
|
|
|
|
+ if ($first4 == 'wxcn') {
|
|
|
|
|
+ $porder = StoreOrderBatch::where('porder_id', $uni)->where('uid', $uid)->find();
|
|
|
|
|
+ if (!$porder) {
|
|
|
|
|
+ return app('json')->fail('订单不存在');
|
|
|
|
|
+ }
|
|
|
|
|
+ $porder = $porder->toArray();
|
|
|
|
|
+ $subOrders = StoreOrderBatch::getAllSubOrders($porder['porder_id']);
|
|
|
|
|
+ if (!$subOrders) {
|
|
|
|
|
+ return app('json')->fail('订单不存在');
|
|
|
|
|
+ }
|
|
|
|
|
+ $order = $this->__get_order_details($uid, $subOrders[0]['order_id']);
|
|
|
|
|
+ if (!$order) {
|
|
|
|
|
+ return app('json')->fail('订单不存在');
|
|
|
|
|
+ }
|
|
|
|
|
+ $order['order_id'] = $porder['porder_id'];
|
|
|
|
|
+ $order['pay_price'] = $porder['total_price'];
|
|
|
|
|
+ return app('json')->successful('ok', $order);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return $this->detail($request, $uni);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 订单详情
|
|
* 订单详情
|
|
|
* @param Request $request
|
|
* @param Request $request
|
|
@@ -404,9 +645,19 @@ class StoreOrderController
|
|
|
*/
|
|
*/
|
|
|
public function detail(Request $request, $uni)
|
|
public function detail(Request $request, $uni)
|
|
|
{
|
|
{
|
|
|
- if (!strlen(trim($uni))) return app('json')->fail('参数错误');
|
|
|
|
|
- $order = StoreOrder::getUserOrderDetail($request->uid(), $uni);
|
|
|
|
|
- if (!$order) return app('json')->fail('订单不存在');
|
|
|
|
|
|
|
+ $order = $this->__get_order_details($request->uid(), $uni);
|
|
|
|
|
+ if (!$order) {
|
|
|
|
|
+ return app('json')->fail('订单不存在');
|
|
|
|
|
+ }
|
|
|
|
|
+ return app('json')->successful('ok', $order);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function __get_order_details($uid, $uni)
|
|
|
|
|
+ {
|
|
|
|
|
+ $order = StoreOrder::getUserOrderDetail($uid, $uni);
|
|
|
|
|
+ if (!$order) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
$order = $order->toArray();
|
|
$order = $order->toArray();
|
|
|
//是否开启门店自提
|
|
//是否开启门店自提
|
|
|
$store_self_mention = sys_config('store_self_mention');
|
|
$store_self_mention = sys_config('store_self_mention');
|
|
@@ -438,7 +689,7 @@ class StoreOrderController
|
|
|
$order['code'] = $url;
|
|
$order['code'] = $url;
|
|
|
}
|
|
}
|
|
|
$order['mapKey'] = sys_config('tengxun_map_key');
|
|
$order['mapKey'] = sys_config('tengxun_map_key');
|
|
|
- return app('json')->successful('ok', StoreOrder::tidyOrder($order, true, true));
|
|
|
|
|
|
|
+ return StoreOrder::tidyOrder($order, true, true);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|