|
|
@@ -27,6 +27,7 @@ use think\db\exception\DbException;
|
|
|
use think\db\exception\ModelNotFoundException;
|
|
|
use think\facade\Cache;
|
|
|
use crmeb\services\upload\Upload;
|
|
|
+use think\facade\Db;
|
|
|
|
|
|
/**
|
|
|
* 公共类
|
|
|
@@ -38,37 +39,12 @@ class PublicController
|
|
|
|
|
|
public function test()
|
|
|
{
|
|
|
- $uid = 168;
|
|
|
- $product_id = 34;
|
|
|
- $exchange_id = 6;
|
|
|
- $num = 3;
|
|
|
- $uni = '5cd4d2a8';
|
|
|
- $res = StoreCart::setCart($uid, $product_id, $num, $uni, 'product', 1, 0, 0, 0, 0, $exchange_id);
|
|
|
- if ($res) {
|
|
|
- $cartId = $res->id;
|
|
|
- $cartGroup = StoreCart::getUserProductCartList($uid, [$cartId], 1);
|
|
|
- if (count($cartGroup['invalid'])) return app('json')->fail($cartGroup['invalid'][0]['productInfo']['store_name'] . '已失效!');
|
|
|
- if (!$cartGroup['valid']) return app('json')->fail('请提交购买的商品');
|
|
|
- $cartInfo = $cartGroup['valid'];
|
|
|
- $priceGroup = StoreOrder::getOrderPriceGroup($cartInfo, 0);
|
|
|
- $other = [
|
|
|
- 'offlinePostage' => sys_config('offline_postage'),
|
|
|
- 'integralRatio' => sys_config('integral_ratio'),
|
|
|
- 'store_id' => 0,
|
|
|
- ];
|
|
|
- $orderKey = StoreOrder::cacheOrderInfo($uid, $cartInfo, $priceGroup, $other);
|
|
|
- if (!$orderKey) return app('json')->fail('生成订单错误!');
|
|
|
- if (StoreOrder::be(['order_id|unique' => $orderKey, 'uid' => $uid, 'is_del' => 0]))
|
|
|
- return app('json')->fail('订单已生成');
|
|
|
- $order = StoreOrder::cacheKeyCreateOrder($uid, $orderKey, 0, 'weixin', false, 0, '系统后台订单', 0, 0, 0, 0, 0, $exchange_id, false, 1, 2, '', '', 0, 0, 1, 1);
|
|
|
- if ($order === false) return app('json')->fail(StoreOrder::getErrorInfo('订单生成失败'));
|
|
|
- else $res = StoreOrder::jsPayPrice($order['order_id'], $uid);
|
|
|
- if ($res) {
|
|
|
- return app('json')->success('支付成功');
|
|
|
- }
|
|
|
- return app('json')->fail('支付失败');
|
|
|
- } else {
|
|
|
- return app('json')->fail('加入购物车失败');
|
|
|
+ try {
|
|
|
+ Db::startTrans();
|
|
|
+ StoreOrder::startTakeOrder();//7天自动收货
|
|
|
+ Db::commit();
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ Db::rollback();
|
|
|
}
|
|
|
}
|
|
|
|