Orders.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. <?php namespace App\Http\Controllers\Api;
  2. use App\Http\Controllers\Api\Api;
  3. use App\Models\Orders as Model;
  4. use App\Models\Product;
  5. use App\Models\Product\Skus as ProductSkus;
  6. use App\Http\Requests\Api\Orders as Request;
  7. use App\Models\Business;
  8. use App\Models\City;
  9. use App\Models\Custom;
  10. use App\Models\CustomAddr;
  11. use App\Models\CustomCoupon;
  12. use App\Models\CustomScore;
  13. use App\Models\OrdersAddr;
  14. use App\Models\OrdersProduct;
  15. use App\Models\ShopCart;
  16. use Illuminate\Support\Facades\DB;
  17. /**
  18. * 订单接口
  19. *
  20. * @author 刘相欣
  21. *
  22. * */
  23. class Orders extends Api{
  24. /**
  25. * 创建订单 /api/orders/create
  26. *
  27. * */
  28. public function create(Request $request,Custom $Custom,City $City,Model $Model,OrdersAddr $OrdersAddr,OrdersProduct $OrdersProduct,Product $Product,ProductSkus $ProductSkus,CustomCoupon $CustomCoupon,ShopCart $ShopCart,CustomAddr $CustomAddr,CustomScore $CustomScore){
  29. // 接口验签
  30. // $this->verify_sign();
  31. // 验证参数
  32. $request->scene('create')->validate();
  33. // 检查登录
  34. $uid = $this->checkLogin();
  35. // 接收参数
  36. $isCart = request('is_cart',0);
  37. $productList = request('product_list','[]');
  38. $customCouponId = request('custom_coupon_id',1);
  39. $addr = $CustomAddr->getOne(request('addr_id',0));
  40. // 如果不存在数据
  41. if( !$addr ) return json_send(['code'=>'error','msg'=>'地址有误,请核对','data'=>['error'=>'没有找到对应的地址']]);
  42. // 重组数据
  43. $addr = ['contact_name'=>$addr['contact_name'],'contact_shop'=>$addr['contact_shop'],'contact_phone'=>$addr['contact_phone'],'contact_province'=>$addr['contact_province'],'contact_city'=>$addr['contact_city'],'contact_area'=>$addr['contact_area'],'contact_addr'=>$addr['contact_addr']];
  44. // 获取客户城市ID
  45. $cityId = (int) $Custom->getValue($uid,'city_id');
  46. $cityName = $City->getOne($cityId,'name');
  47. $pid = $City->getOne($cityId,'pid');
  48. $province = $City->getOne($pid,'name');
  49. // 判断选择的城市名称是不是一致
  50. if( $cityName != $addr['contact_city'] ) return json_send(['code'=>'error','msg'=>'收货地址请选择'.$province.'/'.$cityName,'data'=>['error'=>'收货地址需与您所选城市一致']]);
  51. // 解码购买信息
  52. $buyList = json_decode($productList,true);
  53. // 如果不存在数据
  54. if( empty($buyList) ) return json_send(['code'=>'error','msg'=>'没有需下单的产品','data'=>['error'=>'产品列表为空']]);
  55. // 商品购买数量
  56. $buyNum = [];
  57. // 循环购买信息
  58. foreach ($buyList as $key => $value) {
  59. // 获取每个商品的总量
  60. $buyNum[$value['product_id']] = isset($buyNum[$value['product_id']]) ? ($buyNum[$value['product_id']] + $value['buy_num']) : $value['buy_num'];
  61. }
  62. // 查询产品信息
  63. $productList = $Product->getListByIds(array_column($buyList,'product_id'));
  64. $skusList = $ProductSkus->getListByIds(array_column($buyList,'product_skuid'));
  65. // 当前时间
  66. $time = time();
  67. // 产品以商业公司分组,方便写入订单
  68. $orderProduct = [];
  69. // 产品价格同级,用于优惠券计算
  70. $productPrice = [];
  71. // 循环处理购买信息
  72. foreach ($buyList as $buyInfo) {
  73. // 如果产品不存在
  74. if( empty($productList[$buyInfo['product_id']]) ) return json_send(['code'=>'error','msg'=>'产品不存在或已下架','data'=>['error'=>'产品不存在或已下架=>'.$buyInfo['product_id']]]);
  75. // 获取产信息
  76. $productInfo = $productList[$buyInfo['product_id']];
  77. // 如果产品限购
  78. if( $productInfo['quota'] ) {
  79. // 是否在限购时间,当前时间大于开始时间,并且小于结束时间
  80. if( $productInfo['quota_start'] <= $time && $time <= $productInfo['quota_end'] ){
  81. // 通过时间查询商品的购买总数
  82. $total = $OrdersProduct->query()->where([['custom_uid','=',$uid],['product_id','=',$productInfo['id']],['insert_time','>=',$productInfo['quota_start']],['insert_time','<=',$productInfo['quota_end']]])->sum('buy_num');
  83. // 判断限购数量
  84. $total = $buyNum[$buyInfo['product_id']] + $total;
  85. // 如果超过数量
  86. if( $total > $productInfo['quota'] ) return json_send(['code'=>'error','msg'=>'限购'.$productInfo['quota'].'套-'.$productInfo['product_name'],'data'=>['error'=>'已超限=>'.($total - $productInfo['quota'])]]);
  87. }
  88. }
  89. // 如果存在SKU
  90. if( $buyInfo['product_skuid'] ) {
  91. // 判断SKU信息存不存在
  92. if( empty($skusList[$buyInfo['product_skuid']]) ) return json_send(['code'=>'error','msg'=>'该产品规格不存在或已下架','data'=>['error'=>'SKU不存在或已下架=>'.$buyInfo['product_skuid']]]);
  93. // 产品ID不匹配的话
  94. if( $skusList[$buyInfo['product_skuid']]['product_id'] != $buyInfo['product_id'] ) return json_send(['code'=>'error','msg'=>'该产品规格不存在或已下架','data'=>['error'=>'SKU不匹配=>'.$buyInfo['product_skuid']]]);
  95. // 如果SKU存在,合并产品信息
  96. $productInfo = array_merge($productInfo,$skusList[$buyInfo['product_skuid']]);
  97. // 需要扣除的库存
  98. $skusList[$buyInfo['product_skuid']]['decr'] = empty($skusList[$buyInfo['product_skuid']]['decr']) ? $buyInfo['buy_num'] : $skusList[$buyInfo['product_skuid']]['decr'] + $buyInfo['buy_num'];
  99. }
  100. // 需要扣除的库存
  101. $productList[$buyInfo['product_id']]['decr'] = empty($productList[$buyInfo['product_id']]['decr']) ? $buyInfo['buy_num'] : $productList[$buyInfo['product_id']]['decr'] + $buyInfo['buy_num'];
  102. // 判断库存
  103. if( $productInfo['stock'] < $productList[$buyInfo['product_id']]['decr'] ) return json_send(['code'=>'error','msg'=>$productInfo['product_name'].'-库存不足','data'=>['error'=>'产品库存不足=>'.$buyInfo['product_id']]]);
  104. // 计算价值
  105. $priceTotal = $buyInfo['buy_num'] * $productInfo['price'];
  106. // 购买信息
  107. $buyInfo = ['is_rebate'=>0,'custom_uid'=>$uid,'business_id'=>$productInfo['business_id'],'product_id'=>$buyInfo['product_id'],'buy_num'=>$buyInfo['buy_num'],'price_total'=>$priceTotal,'pay_total'=>$priceTotal,'coupon_total'=>0,'product_name'=>$productInfo['product_name'],'sku_attr_names'=>$productInfo['sku_attr_names'],'product_thumb'=>$productInfo['product_thumb']];
  108. // 获取信息
  109. if( !isset($orderProduct[$buyInfo['business_id']]) ) $orderProduct[$buyInfo['business_id']] = ['business_id'=>$buyInfo['business_id'],'custom_uid'=>$buyInfo['custom_uid'],'price_total'=>0,'pay_total'=>0,'coupon_total'=>0,'product_list'=>[]];
  110. // 订单产品
  111. $orderProduct[$buyInfo['business_id']]['price_total'] += $buyInfo['price_total'];
  112. $orderProduct[$buyInfo['business_id']]['pay_total'] += $buyInfo['price_total'];
  113. $orderProduct[$buyInfo['business_id']]['product_list'][] = $buyInfo;
  114. // 商品优惠信息不存在,创建
  115. if( !isset($productPrice[$buyInfo['product_id']]) ) $productPrice[$buyInfo['product_id']] = ['price_total'=>0,'rebate_price'=>0];
  116. // 计算总价
  117. $productPrice[$buyInfo['product_id']]['price_total'] = $productPrice[$buyInfo['product_id']]['price_total'] + $priceTotal;
  118. }
  119. // 优惠券数据
  120. $couponRebate = $CustomCoupon->getRebatePrice($customCouponId,$uid,$productPrice);
  121. // 判断是否使用了优惠券
  122. $usedCoupon = $couponRebate['is_used'];
  123. // 获取优惠券扣减金额
  124. $productPrice = $couponRebate['product_price'];
  125. // 获取优惠券赠品信息
  126. $rebateProduct = $couponRebate['rebate_product'];
  127. // 组合订单数据
  128. foreach ($orderProduct as $key => $order) {
  129. // 判断哪一家的赠品
  130. if( isset($rebateProduct[$order['business_id']]) ){
  131. // 循环赠品
  132. foreach ( $rebateProduct[$order['business_id']] as $value) {
  133. // 没有对应的产品
  134. if( !isset($productList[$value['product_id']]) ) $productList[$value['product_id']] = ['id'=>$value['id'],'stock'=>$value['stock']];
  135. // 判断库存,如果库存不足,只赠送最后的库存
  136. if( $productList[$value['product_id']]['stock'] <= $value['buy_num'] ) $value['buy_num'] = $productList[$value['product_id']]['stock'];
  137. // 库存扣减
  138. $productList[$value['product_id']]['decr'] = empty($productList[$value['product_id']]['decr']) ? $value['buy_num'] : $productList[$value['product_id']]['decr'] + $value['buy_num'];
  139. // 追加到订单表
  140. $order['product_list'][] = ['is_rebate'=>1,'custom_uid'=>$uid,'business_id'=>$value['business_id'],'product_id'=>$value['product_id'],'buy_num'=>$value['buy_num'],'price_total'=>$value['price_total'],'pay_total'=>$value['pay_total'],'coupon_total'=>$value['coupon_total'],'product_name'=>$value['product_name'],'sku_attr_names'=>$value['sku_attr_names'],'product_thumb'=>$value['product_thumb']];
  141. }
  142. }
  143. // 计算总价格
  144. foreach ($order['product_list'] as $k=>$product) {
  145. // 商品不存在,不进行扣减
  146. if( empty($productPrice[$product['product_id']]['rebate_price']) ) {
  147. // 重组
  148. $order['product_list'][$k] = $product;
  149. continue;
  150. }
  151. // 总优惠增加
  152. $order['coupon_total'] = $order['coupon_total'] + $productPrice[$product['product_id']]['rebate_price'];
  153. // 当前商品的优惠折扣计算
  154. $product['coupon_total'] = number_format( $productPrice[$product['product_id']]['rebate_price'] * ($product['price_total'] / $productPrice[$product['product_id']]['price_total']) , 2 , '.' ,'');
  155. // 成交小计
  156. $product['pay_total'] = $product['pay_total'] - $product['coupon_total'];
  157. // 重组
  158. $order['product_list'][$k] = $product;
  159. }
  160. // 成交总价
  161. $order['pay_total'] = $order['pay_total'] - $order['coupon_total'];
  162. // 赠送积分
  163. $order['order_score'] = (config('order_score_send',0) && floor( $order['pay_total'] * 1 ) > 0 ) ? floor( $order['pay_total'] * 1 ) : 0;
  164. // 成交总价
  165. $order['custom_uid'] = $uid;
  166. // 重组
  167. $orderProduct[$key] = $order;
  168. }
  169. // 组合数据,写入订单表,子表
  170. DB::beginTransaction();
  171. // 写入数据
  172. try {
  173. // 扣减商品库存
  174. foreach ($productList as $key => $value) {
  175. // 扣减库存
  176. $result = $Product->edit($value['id'],['stock'=>DB::raw('stock+-'.$value['decr'])]);
  177. // 判断结果
  178. if( !$result ) {
  179. // 回退数据
  180. DB::rollBack();
  181. // 错误提示
  182. return json_send(['code'=>'error','msg'=>'库存扣减失败','data'=>['error'=>'库存扣减失败']]);
  183. }
  184. }
  185. // 扣减商品库存
  186. foreach ($skusList as $key => $value) {
  187. // 扣减库存
  188. $result = $ProductSkus->edit($value['sku_id'],['stock'=>DB::raw('stock+-'.$value['decr'])]);
  189. // 判断结果
  190. if( !$result ) {
  191. // 回退数据
  192. DB::rollBack();
  193. // 错误提示
  194. return json_send(['code'=>'error','msg'=>'库存扣减失败','data'=>['error'=>'库存扣减失败']]);
  195. }
  196. }
  197. // 循环订单数据
  198. foreach ($orderProduct as $order) {
  199. // 先获取产品列表,并去除key
  200. $productItem = array_values($order['product_list']);
  201. // 删除非必要数据
  202. unset($order['product_list']);
  203. // 创建总订单
  204. $orderId = $Model->add($order);
  205. // 如果订单写入失败
  206. if( !$orderId ) {
  207. // 回退数据
  208. DB::rollBack();
  209. // 错误提示
  210. return json_send(['code'=>'error','msg'=>'下单失败','data'=>['error'=>'订单创建失败']]);
  211. }
  212. // 创建子订单
  213. foreach ($productItem as $key=>$value) {
  214. // 增加订单ID
  215. $value['order_id'] = $orderId;
  216. // 增加订单ID
  217. $value['insert_time']= $time;
  218. $value['update_time']= $time;
  219. // 结果
  220. $productItem[$key] = $value;
  221. }
  222. // 写入子表
  223. $result = $OrdersProduct->query()->insert($productItem);
  224. // 如果扣减失败
  225. if( !$result ) {
  226. // 回退数据
  227. DB::rollBack();
  228. // 提示信息
  229. return json_send(['code'=>'error','msg'=>'子订单创建失败','data'=>['error'=>'子订单创建失败']]);
  230. }
  231. // 写入订单地址表
  232. $addr['order_id'] = $orderId;
  233. // 写入订单地址表
  234. $result = $OrdersAddr->add($addr);
  235. // 地址写入失败
  236. if( !$result ) {
  237. // 回退数据
  238. DB::rollBack();
  239. // 提示信息
  240. return json_send(['code'=>'error','msg'=>'地址写入失败','data'=>['error'=>'地址写入失败']]);
  241. }
  242. // 赠送积分
  243. if( $order['order_score'] > 0 ) $CustomScore->trade($order['custom_uid'],$orderId,$order['order_score'],5,1);
  244. // 如果使用了优惠券
  245. if( $usedCoupon ) $CustomCoupon->edit($usedCoupon,['status'=>1,'order_id'=>$orderId]);
  246. // 购物车
  247. if( $isCart ) $ShopCart->query()->where([['custom_uid','=',$uid]])->whereIn('skuid',array_column($buyList,'product_skuid'))->delete();
  248. }
  249. // 自动发放优惠券
  250. $this->autoCoupon($uid);
  251. // 提交数据
  252. DB::commit();
  253. // 返回结果
  254. return json_send(['code'=>'success','msg'=>'下单成功','data'=>['id'=>null]]);
  255. // 返回结果
  256. } catch (\Throwable $th) {
  257. // 回退数据
  258. DB::rollBack();
  259. // 判断结果,如果库存扣减失败的话
  260. if( stripos($th->getMessage(),'UNSIGNED') ) return json_send(['code'=>'error','msg'=>'库存不足','data'=>['error'=>'产品库存扣减失败']]);
  261. // 下单失败提示
  262. return json_send(['code'=>'error','msg'=>'系统异常,请稍后再试','data'=>['error'=>$th->getMessage().$th->getLine()]]);
  263. }
  264. }
  265. /**
  266. * 获取产品列表 /api/orders/get_list
  267. *
  268. * @param string $name 产品名称
  269. * @param int $page 页码,默认1
  270. * @param int $limit 每页条数,默认10条
  271. *
  272. * */
  273. public function get_list(Request $request,Model $Model,OrdersProduct $OrdersProduct,Business $Business){
  274. // 接口验签
  275. // $this->verify_sign();
  276. // 验证参数
  277. $request->scene('get_list')->validate();
  278. // 检查登录
  279. $uid = $this->checkLogin();
  280. // 接收参数
  281. $status = request('status',0);
  282. $limit = request('limit',10);
  283. // 显示
  284. $map = [['custom_uid','=',$uid]];
  285. // 查询状态
  286. if( $status ) $map[] = ['status','=',$status];
  287. // 查询
  288. $Paginator = $Model->query()->where($map)->orderByDesc('id')->paginate($limit,['id','pay_total','status','price_total','coupon_total','business_id','pay_total','weizan_orderid','insert_time']);
  289. // 订单产品
  290. $productList = $OrdersProduct->query()->whereIn('order_id', array_column($Paginator->items(),'id'))->select(['id as item_id','order_id','product_id','buy_num','is_rebate','sku_attr_names as product_spec','product_name','product_thumb'])->get()->toArray();
  291. // 循环处理
  292. foreach ($Paginator as $key => $order) {
  293. // 商品列表
  294. $itemList = [];
  295. // 返回结果
  296. foreach ($productList as $item) {
  297. // 产品图路径
  298. $item['product_thumb'] = path_compat($item['product_thumb']);
  299. // 如果是订单的
  300. if( $item['order_id'] == $order['id'] ) $itemList[] = $item;
  301. }
  302. // 获取子列表
  303. $order['state'] = (string) $Model->getState($order['status'],'state');
  304. // 获取子列表
  305. $order['business_name'] = (string) ($order['business_id'] ? $Business->getOne($order['business_id'],'name') : ($order['weizan_orderid'] ? '微赞订单' : ''));
  306. // 获取子列表
  307. $order['contents_class']= 0;
  308. // 获取子列表
  309. $order['product_list'] = $itemList;
  310. // 重组
  311. $Paginator[$key] = $order;
  312. }
  313. // 获取数据
  314. $data['total'] = $Paginator->total();
  315. $data['current_page'] = $Paginator->currentPage();
  316. $data['per_page'] = $Paginator->perPage();
  317. $data['last_page'] = $Paginator->lastPage();
  318. $data['data'] = $Paginator->items();
  319. // 返回结果
  320. return json_send(['code'=>'success','msg'=>'获取成功','data'=>$data]);
  321. }
  322. /**
  323. * 自动发放优惠券
  324. *
  325. */
  326. private function autoCoupon($uid){
  327. // 模型实例
  328. $Rule = new \App\Models\CouponRewardRule();
  329. // 获取配置列表
  330. $ruleList = $Rule->getList();
  331. // 如果没有信息的话
  332. if( !$ruleList ) return ['success'=>'暂无活动'];
  333. // 其他实例
  334. $RuleProduct = new \App\Models\CouponRewardProduct();
  335. $OrdersProduct = new \App\Models\OrdersProduct();
  336. $Custom = new \App\Models\Custom();
  337. $Coupon = new \App\Models\Coupon();
  338. $CustomCoupon = new \App\Models\CustomCoupon();
  339. // 获取客户城市ID
  340. $customCityId = (int) $Custom->getValue($uid,'city_id');
  341. // 循环配置列表
  342. foreach ( $ruleList as $value ) {
  343. // 如果存在城市范围,并且不在城市范围,不参与这个活动
  344. if( $value['city_ids'] && !in_array($customCityId,explode(',',$value['city_ids'])) ) continue;
  345. // 未到开始时间
  346. if( $value['start_time'] > time() ) continue;
  347. // 通过配置ID获取对应的商品范围
  348. $productList = $RuleProduct->getListByRule($value['id']);
  349. // 如果不存在产品范围,跳过
  350. if( !$productList ) continue;
  351. // 获取客户 规定时段内订单的商品ID以及购买数量
  352. $orderList = $OrdersProduct->query()->where([['custom_uid','=',$uid],['status','=',1],['insert_time','>=',$value['start_time']],['insert_time','<=',$value['end_time']]])->get(['product_id','buy_num'])->toArray();
  353. // 如果没有订单总数
  354. if( !$orderList ) continue;
  355. // 计算商品总量
  356. $total = 0;
  357. // 循环商品范围
  358. foreach ($productList as $scope) {
  359. // 循环订单产品
  360. foreach ($orderList as $order) {
  361. // 如果产品不相等
  362. if( $scope['product_id'] != $order['product_id'] ) continue;
  363. // 相等的计算总量
  364. $total += $scope['product_units'] * $order['buy_num'];
  365. }
  366. }
  367. // 判断总数是不是达标
  368. if( $total < $value['std_num'] ) continue;
  369. // 达标的是否已经发送过优惠券
  370. $havaCoupon = $CustomCoupon->query()->where([['custom_uid','=',$uid],['coupon_id','=',$value['coupon_id']]])->first(['status']);
  371. // 已经发过优惠券的,不发
  372. if( $havaCoupon ) continue;
  373. // 获取优惠券的可用时间
  374. $expTime = $Coupon->query()->where([['id','=',$value['coupon_id']]])->value('exp_time');
  375. // 时间转时间
  376. $expTime = $Coupon->getExpTime($expTime);
  377. // 发送优惠券
  378. $CustomCoupon->add(['coupon_id'=>$value['coupon_id'],'custom_uid'=>$uid,'exp_time'=>$expTime]);
  379. }
  380. // 返回成功
  381. return ['success'=>'操作成功'];
  382. }
  383. /**
  384. * 取消 /api/orders/cancel
  385. *
  386. * */
  387. public function cancel( Request $request, Model $Model,OrdersProduct $OrdersProduct,CustomScore $CustomScore){
  388. // 验证参数
  389. $request->scene('cancel')->validate();
  390. // 检查登录
  391. $uid = $this->checkLogin();
  392. // 接收参数
  393. $id = request('id',0);
  394. $status = 4;
  395. // 获取产品和数量
  396. $oldData = $Model->query()->where([['id','=',$id],['custom_uid','=',$uid]])->first(['id','order_score','status','custom_uid','insert_time']);
  397. // 如果用户不存在
  398. if( !$oldData ) return json_send(['code'=>'error','msg'=>'订单不存在']);
  399. // 如果已经取消
  400. if( $oldData['status'] == 4 ) return json_send(['code'=>'error','msg'=>'订单已取消']);
  401. // 组合数据,写入订单表,子表
  402. DB::beginTransaction();
  403. try{
  404. // 查询数据
  405. $result = $Model->setOrderStatus($id,$status,$OrdersProduct);
  406. // 提示新增失败
  407. if( isset($result['error']) ) {
  408. // 回退数据
  409. DB::rollBack();
  410. // 提示信息
  411. return json_send(['code'=>'error','msg'=>$result['error'],'data'=>['error'=>$result['error']]]);
  412. }
  413. if( $status == 4 ){
  414. // 取消积分
  415. if( $oldData['order_score'] > 0 ) {
  416. // 如果扣减失败
  417. $result = $CustomScore->trade($oldData['custom_uid'],$oldData['id'],($oldData['order_score']*-1),6,1);
  418. // 提示新增失败
  419. if( isset($result['error']) ) {
  420. // 回退数据
  421. DB::rollBack();
  422. // 提示信息
  423. return json_send(['code'=>'error','msg'=>'取消赠送积分失败','data'=>['error'=>$result['error']]]);
  424. }
  425. }
  426. // 取消关联订单
  427. $result = $Model->cancelRelate($oldData['insert_time'],$oldData['custom_uid'],$OrdersProduct,$CustomScore);
  428. // 提示新增失败
  429. if( isset($result['error']) ) {
  430. // 回退数据
  431. DB::rollBack();
  432. // 提示信息
  433. return json_send(['code'=>'error','msg'=>'取消关联订单失败','data'=>['error'=>$result['error']]]);
  434. }
  435. }
  436. // 提交数据
  437. DB::commit();
  438. // 告知结果
  439. return json_send(['code'=>'success','msg'=>'取消成功']);
  440. // 返回结果
  441. } catch (\Throwable $th) {
  442. // 回退数据
  443. DB::rollBack();
  444. // 下单失败提示
  445. return json_send(['code'=>'error','msg'=>'取消失败','data'=>['error'=>$th->getMessage().$th->getLine()]]);
  446. }
  447. }
  448. }