|
@@ -13,6 +13,9 @@ use App\Models\CustomCoupon;
|
|
use App\Models\CustomScore;
|
|
use App\Models\CustomScore;
|
|
use App\Models\OrdersAddr;
|
|
use App\Models\OrdersAddr;
|
|
use App\Models\OrdersProduct;
|
|
use App\Models\OrdersProduct;
|
|
|
|
+use App\Models\Regiment;
|
|
|
|
+use App\Models\RegimentActive;
|
|
|
|
+use App\Models\RegimentRecord;
|
|
use App\Models\ShopCart;
|
|
use App\Models\ShopCart;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\DB;
|
|
use App\Models\WeiBan\Tags as WeiBanTags;
|
|
use App\Models\WeiBan\Tags as WeiBanTags;
|
|
@@ -531,4 +534,359 @@ class Orders extends Api{
|
|
return json_send(['code'=>'success','msg'=>'获取成功','data'=>$orderInfo]);
|
|
return json_send(['code'=>'success','msg'=>'获取成功','data'=>$orderInfo]);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 创建拼团订单 /api/orders/create_regiment
|
|
|
|
+ *
|
|
|
|
+ * */
|
|
|
|
+ public function create_regiment(Request $request,Custom $Custom,City $City,Model $Model,WeiBanTags $WeiBanTags,OrdersAddr $OrdersAddr,OrdersProduct $OrdersProduct,Product $Product,ProductSkus $ProductSkus,CustomCoupon $CustomCoupon,ShopCart $ShopCart,CustomAddr $CustomAddr,CustomScore $CustomScore){
|
|
|
|
+ // 接口验签
|
|
|
|
+ // $this->verify_sign();
|
|
|
|
+ // 验证参数
|
|
|
|
+ $request->scene('create')->validate();
|
|
|
|
+ // 检查登录
|
|
|
|
+ $uid = $this->checkLogin();
|
|
|
|
+ // 接收参数
|
|
|
|
+ $isCart = request('is_cart',0);
|
|
|
|
+ $productList = request('product_list','[]');
|
|
|
|
+ $customCouponId = request('custom_coupon_id',0);
|
|
|
|
+ $addrId = request('addr_id',0);
|
|
|
|
+ $regimentId = request('regiment_id',0);
|
|
|
|
+ $regimentActiveId = request('regiment_active_id',0);
|
|
|
|
+ $btnType = request('btn_type',0);
|
|
|
|
+ // 如果不存在数据
|
|
|
|
+ if( !$addrId ) return json_send(['code'=>'error','msg'=>'请选择收货地址','data'=>['error'=>'请选择收货地址']]);
|
|
|
|
+ // 解码购买信息
|
|
|
|
+ $buyList = json_decode($productList,true);
|
|
|
|
+ // 如果不存在数据
|
|
|
|
+ if( empty($buyList) ) return json_send(['code'=>'error','msg'=>'没有需下单的产品','data'=>['error'=>'产品列表为空']]);
|
|
|
|
+ $time = time();
|
|
|
|
+ // 选择地址
|
|
|
|
+ $addr = $CustomAddr->getOne($addrId);
|
|
|
|
+ // 如果不存在数据
|
|
|
|
+ if( !$addr ) return json_send(['code'=>'error','msg'=>'地址有误,请核对','data'=>['error'=>'没有找到对应的地址']]);
|
|
|
|
+ // 重组数据
|
|
|
|
+ $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']];
|
|
|
|
+ // 获取客户城市ID
|
|
|
|
+ $custom = $Custom->getOne($uid);
|
|
|
|
+ // 如果不存在的话
|
|
|
|
+ if( !$custom ) return json_send(['code'=>'no_login','msg'=>'用户不存在,请重新登录','data'=>['error'=>'用户不存在,请重新登录']]);
|
|
|
|
+ // 如果不存在的话
|
|
|
|
+ if( !$custom['city_id'] ) return json_send(['code'=>'error','msg'=>'请选择所在城市后下单','data'=>['error'=>'请选择所在城市后下单']]);
|
|
|
|
+ // 获取城市ID
|
|
|
|
+ $cityId = $custom['city_id'];
|
|
|
|
+ $cityName = $City->getOne($cityId,'name');
|
|
|
|
+ $pid = $City->getOne($cityId,'pid');
|
|
|
|
+ $province = $City->getOne($pid,'name');
|
|
|
|
+ // 判断选择的城市名称是不是一致
|
|
|
|
+ if( $cityName != $addr['contact_city'] ) return json_send(['code'=>'error','msg'=>'收货地址请选择'.$province.'/'.$cityName,'data'=>['error'=>'收货地址需与您所选城市一致']]);
|
|
|
|
+ //获取团活动信息
|
|
|
|
+ $regimentActiveInfo = RegimentActive::query()
|
|
|
|
+ ->where([['id','=',$regimentActiveId],['status','=',1],['start_time','<=',$time],['end_time','>=',$time]])
|
|
|
|
+ ->first();
|
|
|
|
+ if (!$regimentActiveInfo) return json_send(['code'=>'error','msg'=>'拼团活动不存在','data'=>['error'=>'拼团活动不存在']]);
|
|
|
|
+ //是否符合开团条件
|
|
|
|
+ if($btnType == 3){
|
|
|
|
+ if ($regimentActiveInfo['open_people'] == 1){
|
|
|
|
+ if ($custom['insert_time'] > $regimentActiveInfo['start_time']) return json_send(['code'=>'error','msg'=>'此活动只允许老用户开团','data'=>['error'=>'此活动只允许老用户开团']]);
|
|
|
|
+ }
|
|
|
|
+ if ($regimentActiveInfo['open_people'] == 2){
|
|
|
|
+ if ($custom['insert_time'] < $regimentActiveInfo['start_time']) return json_send(['code'=>'error','msg'=>'此活动只允许新用户开团','data'=>['error'=>'此活动只允许新用户开团']]);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //是否符合参团条件
|
|
|
|
+ if($btnType == 4){
|
|
|
|
+ if ($regimentActiveInfo['partake_people'] == 1){
|
|
|
|
+ if ($custom['insert_time'] > $regimentActiveInfo['start_time']) return json_send(['code'=>'error','msg'=>'此活动只允许老用户参与','data'=>['error'=>'此活动只允许老用户开团']]);
|
|
|
|
+ }
|
|
|
|
+ if ($regimentActiveInfo['open_people'] == 2){
|
|
|
|
+ if ($custom['insert_time'] < $regimentActiveInfo['start_time']) return json_send(['code'=>'error','msg'=>'此活动只允许新用户参与','data'=>['error'=>'此活动只允许新用户开团']]);
|
|
|
|
+ }
|
|
|
|
+ //查询团信息
|
|
|
|
+ $regimentInfo = Regiment::query()
|
|
|
|
+ ->where([['id','=',$regimentId],['status','=',1],['start_time','<=',$time],['end_time','>=',$time]])
|
|
|
|
+ ->first();
|
|
|
|
+ if (!$regimentInfo) return json_send(['code'=>'error','msg'=>'拼团活动不存在','data'=>['error'=>'拼团活动不存在']]);
|
|
|
|
+ }
|
|
|
|
+ //查询用户参团记录
|
|
|
|
+ $regimentRecordCount = RegimentRecord::query()
|
|
|
|
+ ->where([['custom_uid','=',$uid],['active_id','=',$regimentActiveInfo['id']]])
|
|
|
|
+ ->count('id');
|
|
|
|
+ if ($regimentRecordCount >= $regimentActiveInfo['participation_number']) return json_send(['code'=>'error','msg'=>'该活动每人仅限参与'.$regimentActiveInfo['participation_number'].'次','data'=>['error'=>'该活动每人仅限参与'.$regimentActiveInfo['participation_number'].'次']]);
|
|
|
|
+
|
|
|
|
+ $tags = $WeiBanTags->getListByWeibanExtid($custom['weiban_extid']);
|
|
|
|
+ // 查询产品信息
|
|
|
|
+ $productList = $Product->getListByIds(array_column($buyList,'product_id'));
|
|
|
|
+ // 当前时间
|
|
|
|
+ $time = time();
|
|
|
|
+ // 产品以商业公司分组,方便写入订单
|
|
|
|
+ $orderProduct = [];
|
|
|
|
+ // 产品价格同级,用于优惠券计算
|
|
|
|
+ $productPrice = [];
|
|
|
|
+ $priceTotal = 0;
|
|
|
|
+ $payTotal = 0;
|
|
|
|
+ $buyInfo = $buyList[0];
|
|
|
|
+ if ($buyInfo){
|
|
|
|
+ if( empty($productList[$buyInfo['product_id']]) ) return json_send(['code'=>'error','msg'=>'产品不存在或已下架','data'=>['error'=>'产品不存在或已下架=>'.$buyInfo['product_id']]]);
|
|
|
|
+ // 获取产信息
|
|
|
|
+ $productInfo = $productList[$buyInfo['product_id']];
|
|
|
|
+ // 判断是不是可以参与
|
|
|
|
+ if( $productInfo['tag_scope'] ) {
|
|
|
|
+ // 解析数组
|
|
|
|
+ $productInfo['tag_scope'] = explode(',',$productInfo['tag_scope']);
|
|
|
|
+ // 标签范围限定时,默认不能参与
|
|
|
|
+ $allowJoin = 0;
|
|
|
|
+ // 判断标签是不是存在
|
|
|
|
+ foreach ($tags as $value) {
|
|
|
|
+ // 标签范围内,允许参加
|
|
|
|
+ if( in_array($value['name'],$productInfo['tag_scope']) ) $allowJoin = 1;
|
|
|
|
+ }
|
|
|
|
+ // 如果不能参与
|
|
|
|
+ if( !$allowJoin ) return json_send(['code'=>'error','msg'=>'不在 '.$productInfo['product_name'].' 参与范围','data'=>['error'=>'不在标签范围内']]);
|
|
|
|
+ }
|
|
|
|
+ // 判断是不是可以参与
|
|
|
|
+ if( $productInfo['tag_exclude'] ) {
|
|
|
|
+ // 解析数组
|
|
|
|
+ $productInfo['tag_exclude'] = explode(',',$productInfo['tag_exclude']);
|
|
|
|
+ // 判断标签是不是存在
|
|
|
|
+ foreach ($tags as $value) {
|
|
|
|
+ // 标签排除范围内,不允许参加
|
|
|
|
+ if( in_array($value['name'],$productInfo['tag_exclude']) ) return json_send(['code'=>'error','msg'=>'不在 '.$productInfo['product_name'].' 可参与范围','data'=>['error'=>'用户在标签排除范围']]);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //拼团活动限购
|
|
|
|
+ if ($regimentActiveInfo['quota']){
|
|
|
|
+ if ($buyInfo['buy_num'] > $regimentActiveInfo['quota']) return json_send(['code'=>'error','msg'=>'超过拼团限购','data'=>['error'=>'拼团限购=>'.$buyInfo['product_id']]]);
|
|
|
|
+ }
|
|
|
|
+ // 如果产品限购
|
|
|
|
+ if( $productInfo['quota'] ) {
|
|
|
|
+ // 是否在限购时间,当前时间大于开始时间,并且小于结束时间
|
|
|
|
+ if( $productInfo['quota_start'] <= $time && $time <= $productInfo['quota_end'] ){
|
|
|
|
+ // 通过时间查询商品的购买总数
|
|
|
|
+ $total = $OrdersProduct->query()->where([['custom_uid','=',$uid],['product_id','=',$productInfo['id']],['insert_time','>=',$productInfo['quota_start']],['insert_time','<=',$productInfo['quota_end']]])->sum('buy_num');
|
|
|
|
+ // 判断限购数量
|
|
|
|
+ $total = $buyInfo['buy_num'] + $total;
|
|
|
|
+ // 如果超过数量
|
|
|
|
+ if( $total > $productInfo['quota'] ) return json_send(['code'=>'error','msg'=>'限购'.$productInfo['quota'].'套-'.$productInfo['product_name'],'data'=>['error'=>'已超限=>'.($total - $productInfo['quota'])]]);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // 需要扣除的库存
|
|
|
|
+ $productList[$buyInfo['product_id']]['decr'] = $buyInfo['buy_num'];
|
|
|
|
+ // 判断库存
|
|
|
|
+ if( $productInfo['stock'] < $productList[$buyInfo['product_id']]['decr'] ) return json_send(['code'=>'error','msg'=>$productInfo['product_name'].'-库存不足','data'=>['error'=>'产品库存不足=>'.$buyInfo['product_id']]]);
|
|
|
|
+ // 计算价值
|
|
|
|
+ $priceTotal = $buyInfo['buy_num'] * $regimentActiveInfo['regiment_price'];
|
|
|
|
+ $payTotal = $buyInfo['buy_num'] * $productInfo['price'];
|
|
|
|
+ }
|
|
|
|
+ $orderInfo = [
|
|
|
|
+ 'custom_uid' => $uid,
|
|
|
|
+ 'status' => 10,
|
|
|
|
+ 'pay_total' => $payTotal,
|
|
|
|
+ 'price_total' => $priceTotal,
|
|
|
|
+ 'business_id' => $productList[$buyInfo['product_id']]['business_id'],
|
|
|
|
+ ];
|
|
|
|
+ // 赠送积分
|
|
|
|
+ $orderInfo['order_score'] = (config('order_score_send',0) && floor( $orderInfo['pay_total'] * 1 ) > 0 ) ? floor( $orderInfo['pay_total'] * 1 ) : 0;
|
|
|
|
+ $orderProductInfo = [
|
|
|
|
+ 'product_name' => $productList[$buyInfo['product_id']]['product_name'],
|
|
|
|
+ 'sku_attr_names' => $productList[$buyInfo['product_id']]['sku_attr_names'],
|
|
|
|
+ 'product_thumb' => $productList[$buyInfo['product_id']]['product_thumb'],
|
|
|
|
+ 'buy_num' => $buyInfo['buy_num'],
|
|
|
|
+ 'price_total' => $priceTotal,
|
|
|
|
+ 'pay_total' => $buyInfo['buy_num'] * $productList[$buyInfo['product_id']]['price'],
|
|
|
|
+ 'product_id' => $buyInfo['product_id'],
|
|
|
|
+ 'custom_uid' => $uid,
|
|
|
|
+ 'business_id' => $productList[$buyInfo['product_id']]['business_id'],
|
|
|
|
+ ];
|
|
|
|
+ // 组合数据,写入订单表,子表
|
|
|
|
+ DB::beginTransaction();
|
|
|
|
+ // 写入数据
|
|
|
|
+ try {
|
|
|
|
+ // 扣减商品库存
|
|
|
|
+ foreach ($productList as $key => $value) {
|
|
|
|
+ // 扣减库存
|
|
|
|
+ $result = $Product->edit($value['id'],['stock'=>DB::raw('stock+-'.$value['decr'])]);
|
|
|
|
+ // 判断结果
|
|
|
|
+ if( !$result ) {
|
|
|
|
+ // 回退数据
|
|
|
|
+ DB::rollBack();
|
|
|
|
+ // 错误提示
|
|
|
|
+ return json_send(['code'=>'error','msg'=>'库存扣减失败','data'=>['error'=>'库存扣减失败']]);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //创建拼团
|
|
|
|
+ if($btnType == 3){
|
|
|
|
+ $regimentInfo = [
|
|
|
|
+ 'custom_uid' => $uid,
|
|
|
|
+ 'active_id' => $regimentActiveInfo['id'],
|
|
|
|
+ 'product_id' => $buyInfo['product_id'],
|
|
|
|
+ 'people_number' => 1,
|
|
|
|
+ 'status' => 1,
|
|
|
|
+ 'start_time' => $time,
|
|
|
|
+ 'end_time' => $time + $regimentActiveInfo['expiration']*3600,
|
|
|
|
+ 'update_time' => $time,
|
|
|
|
+ 'insert_time' => $time,
|
|
|
|
+ ];
|
|
|
|
+ $regimentId = Regiment::query()->insert($regimentInfo);
|
|
|
|
+ if( !$regimentId ) {
|
|
|
|
+ // 回退数据
|
|
|
|
+ DB::rollBack();
|
|
|
|
+ // 提示信息
|
|
|
|
+ return json_send(['code'=>'error','msg'=>'创建拼团失败','data'=>['error'=>'创建拼团失败']]);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ $orderInfo['regiment_id'] = $regimentId;
|
|
|
|
+ // 创建总订单
|
|
|
|
+ $orderId = $Model->add($orderInfo);
|
|
|
|
+ // 如果订单写入失败
|
|
|
|
+ if( !$orderId ) {
|
|
|
|
+ // 回退数据
|
|
|
|
+ DB::rollBack();
|
|
|
|
+ // 错误提示
|
|
|
|
+ return json_send(['code'=>'error','msg'=>'下单失败','data'=>['error'=>'订单创建失败']]);
|
|
|
|
+ }
|
|
|
|
+ $orderProductInfo['order_id'] = $orderId;
|
|
|
|
+ // 写入子表
|
|
|
|
+ $result = $OrdersProduct->query()->insert($orderProductInfo);
|
|
|
|
+ // 如果扣减失败
|
|
|
|
+ if( !$result ) {
|
|
|
|
+ // 回退数据
|
|
|
|
+ DB::rollBack();
|
|
|
|
+ // 提示信息
|
|
|
|
+ return json_send(['code'=>'error','msg'=>'子订单创建失败','data'=>['error'=>'子订单创建失败']]);
|
|
|
|
+ }
|
|
|
|
+ // 写入订单地址表
|
|
|
|
+ $addr['order_id'] = $orderId;
|
|
|
|
+ // 写入订单地址表
|
|
|
|
+ $result = $OrdersAddr->add($addr);
|
|
|
|
+ // 地址写入失败
|
|
|
|
+ if( !$result ) {
|
|
|
|
+ // 回退数据
|
|
|
|
+ DB::rollBack();
|
|
|
|
+ // 提示信息
|
|
|
|
+ return json_send(['code'=>'error','msg'=>'地址写入失败','data'=>['error'=>'地址写入失败']]);
|
|
|
|
+ }
|
|
|
|
+ if($btnType == 4){
|
|
|
|
+ // 拼团人数加1
|
|
|
|
+ $inc = Regiment::query()->where('id','=',$regimentId)->increment('people_number',1);
|
|
|
|
+ if( !$inc ) {
|
|
|
|
+ // 回退数据
|
|
|
|
+ DB::rollBack();
|
|
|
|
+ // 提示信息
|
|
|
|
+ return json_send(['code'=>'error','msg'=>'创建拼团失败','data'=>['error'=>'创建拼团失败']]);
|
|
|
|
+ }
|
|
|
|
+ //团满
|
|
|
|
+ if ((($regimentInfo['people_number'] + 1) == $regimentActiveInfo['number']) && $regimentActiveInfo == 1) {
|
|
|
|
+ $res = regiment::query()->where('id','=',$regimentId)->update(['status'=>3]);
|
|
|
|
+ if( !$res ) {
|
|
|
|
+ // 回退数据
|
|
|
|
+ DB::rollBack();
|
|
|
|
+ // 提示信息
|
|
|
|
+ return json_send(['code'=>'error','msg'=>'创建拼团失败','data'=>['error'=>'创建拼团失败']]);
|
|
|
|
+ }
|
|
|
|
+ //修改订单
|
|
|
|
+ $orderRes = $Model::query()->where('regiment_id','=',$regimentId)->update(['status'=>'1']);
|
|
|
|
+ if( !$orderRes ) {
|
|
|
|
+ // 回退数据
|
|
|
|
+ DB::rollBack();
|
|
|
|
+ // 提示信息
|
|
|
|
+ return json_send(['code'=>'error','msg'=>'创建拼团失败','data'=>['error'=>'创建拼团失败']]);
|
|
|
|
+ }
|
|
|
|
+ //赠送积分
|
|
|
|
+ $orderList = $Model::query()->where('regiment_id','=',$regimentId)->get();
|
|
|
|
+ foreach ($orderList as $key => $value) {
|
|
|
|
+ if( $value['order_score'] > 0 ) $CustomScore->trade($orderInfo['custom_uid'],$value['id'],$value['order_score'],5,1);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //拼团记录
|
|
|
|
+ $regimentRecordInfo = [
|
|
|
|
+ 'custom_uid' => $uid,
|
|
|
|
+ 'regiment_id' => $regimentId,
|
|
|
|
+ 'active_id' => $regimentActiveInfo['id'],
|
|
|
|
+ 'product_id' => $buyInfo['product_id'],
|
|
|
|
+ 'order_id' => $orderId,
|
|
|
|
+ 'update_time' => $time,
|
|
|
|
+ 'insert_time' => $time,
|
|
|
|
+ ];
|
|
|
|
+ $result = RegimentRecord::query()->insert($regimentRecordInfo);
|
|
|
|
+ if( !$result ) {
|
|
|
|
+ // 回退数据
|
|
|
|
+ DB::rollBack();
|
|
|
|
+ // 提示信息
|
|
|
|
+ return json_send(['code'=>'error','msg'=>'创建拼团记录失败','data'=>['error'=>'创建拼团记录失败']]);
|
|
|
|
+ }
|
|
|
|
+ // 提交数据
|
|
|
|
+ DB::commit();
|
|
|
|
+ // 返回结果
|
|
|
|
+ return json_send(['code'=>'success','msg'=>'下单成功','data'=>['id'=>null]]);
|
|
|
|
+ // 返回结果
|
|
|
|
+ } catch (\Throwable $th) {
|
|
|
|
+ // 回退数据
|
|
|
|
+ DB::rollBack();
|
|
|
|
+ // 判断结果,如果库存扣减失败的话
|
|
|
|
+ if( stripos($th->getMessage(),'UNSIGNED') ) return json_send(['code'=>'error','msg'=>'库存不足','data'=>['error'=>'产品库存扣减失败']]);
|
|
|
|
+ // 下单失败提示
|
|
|
|
+ return json_send(['code'=>'error','msg'=>'系统异常,请稍后再试','data'=>['error'=>$th->getMessage().$th->getLine()]]);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ /**
|
|
|
|
+ * 取消拼团 /api/orders/cancel_regiment
|
|
|
|
+ *
|
|
|
|
+ * */
|
|
|
|
+ public function cancel_regiment( Request $request, Model $Model,OrdersProduct $OrdersProduct,CustomScore $CustomScore){
|
|
|
|
+ // 验证参数
|
|
|
|
+ $request->scene('cancel')->validate();
|
|
|
|
+ // 检查登录
|
|
|
|
+ $uid = $this->checkLogin();
|
|
|
|
+ // 接收参数
|
|
|
|
+ $id = request('id',0);
|
|
|
|
+ $status = 4;
|
|
|
|
+ // 获取产品和数量
|
|
|
|
+ $oldData = $Model->query()->where([['id','=',$id],['custom_uid','=',$uid]])->first(['id','order_score','status','custom_uid','insert_time']);
|
|
|
|
+ // 如果用户不存在
|
|
|
|
+ if( !$oldData ) return json_send(['code'=>'error','msg'=>'订单不存在']);
|
|
|
|
+ // 如果已经取消
|
|
|
|
+ if( $oldData['status'] == 4 ) return json_send(['code'=>'error','msg'=>'订单已取消']);
|
|
|
|
+ // 如果团不存在
|
|
|
|
+ if( !$oldData['regiment_id'] ) return json_send(['code'=>'error','msg'=>'拼团不存在']);
|
|
|
|
+ // 组合数据,写入订单表,子表
|
|
|
|
+ DB::beginTransaction();
|
|
|
|
+ try{
|
|
|
|
+ // 查询数据
|
|
|
|
+ $result = $Model->setOrderStatus($id,$status,$OrdersProduct);
|
|
|
|
+ // 提示新增失败
|
|
|
|
+ if( isset($result['error']) ) {
|
|
|
|
+ // 回退数据
|
|
|
|
+ DB::rollBack();
|
|
|
|
+ // 提示信息
|
|
|
|
+ return json_send(['code'=>'error','msg'=>$result['error'],'data'=>['error'=>$result['error']]]);
|
|
|
|
+ }
|
|
|
|
+ //取消加入团
|
|
|
|
+ $regimentRes = Regiment::query()->where('id','=',$oldData['regiment_id'])->decrement('people_number',1);
|
|
|
|
+ if( !$regimentRes ) {
|
|
|
|
+ // 回退数据
|
|
|
|
+ DB::rollBack();
|
|
|
|
+ // 提示信息
|
|
|
|
+ return json_send(['code'=>'error','msg'=>'取消拼团失败']);
|
|
|
|
+ }
|
|
|
|
+ //修改拼团记录
|
|
|
|
+ $regimentRes = RegimentRecord::query()->where([['order_id','=',$oldData['id'],]])->update(['status'=>'2']);
|
|
|
|
+ if( !$regimentRes ) {
|
|
|
|
+ // 回退数据
|
|
|
|
+ DB::rollBack();
|
|
|
|
+ // 提示信息
|
|
|
|
+ return json_send(['code'=>'error','msg'=>'取消拼团失败']);
|
|
|
|
+ }
|
|
|
|
+ // 提交数据
|
|
|
|
+ DB::commit();
|
|
|
|
+ // 告知结果
|
|
|
|
+ return json_send(['code'=>'success','msg'=>'取消成功']);
|
|
|
|
+ // 返回结果
|
|
|
|
+ } catch (\Throwable $th) {
|
|
|
|
+ // 回退数据
|
|
|
|
+ DB::rollBack();
|
|
|
|
+ // 下单失败提示
|
|
|
|
+ return json_send(['code'=>'error','msg'=>'取消失败','data'=>['error'=>$th->getMessage().$th->getLine()]]);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|