|
@@ -651,9 +651,7 @@ class Orders extends Api{
|
|
|
// 检查登录
|
|
|
$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);
|
|
@@ -685,6 +683,7 @@ class Orders extends Api{
|
|
|
$pid = $City->getOne($cityId,'pid');
|
|
|
// 如果上级不是省份
|
|
|
if( strlen($cityId) > 4 ) $pid = (int) $City->getOne($pid,'pid');
|
|
|
+ // 获取省份
|
|
|
$province = $City->getOne($pid,'name');
|
|
|
// 如果不是海南,
|
|
|
if( $province != '海南省' ) {
|
|
@@ -694,9 +693,8 @@ class Orders extends Api{
|
|
|
if( trim($addr['contact_province']) != trim($province) ) return json_send(['code'=>'error','msg'=>'收货地址请选择海南范围','data'=>['error'=>'收货地址需与您所选城市一致']]);
|
|
|
}
|
|
|
//获取团活动信息
|
|
|
- $regimentActiveInfo = RegimentActive::query()
|
|
|
- ->where([['id','=',$regimentActiveId],['status','=',1],['start_time','<=',$time],['end_time','>=',$time]])
|
|
|
- ->first();
|
|
|
+ $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){
|
|
@@ -727,19 +725,15 @@ class Orders extends Api{
|
|
|
}
|
|
|
//查询用户参团记录
|
|
|
$regimentRecordCount = RegimentRecord::query()
|
|
|
- ->where([['custom_uid','=',$uid],['active_id','=',$regimentActiveInfo['id']]])
|
|
|
- ->count('id');
|
|
|
+ ->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];
|
|
@@ -844,7 +838,7 @@ class Orders extends Api{
|
|
|
'active_id' => $regimentActiveInfo['id'],
|
|
|
'product_id' => $buyInfo['product_id'],
|
|
|
'people_number' => 1,
|
|
|
- 'status' => 0,
|
|
|
+ 'status' => 1,
|
|
|
'start_time' => $time,
|
|
|
'end_time' => $time + $regimentActiveInfo['expiration']*3600,
|
|
|
'update_time' => $time,
|
|
@@ -889,6 +883,16 @@ class Orders extends Api{
|
|
|
// 提示信息
|
|
|
return json_send(['code'=>'error','msg'=>'地址写入失败','data'=>['error'=>'地址写入失败']]);
|
|
|
}
|
|
|
+ //拼团记录
|
|
|
+ $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,
|
|
|
+ ];
|
|
|
if($btnType == 4){
|
|
|
// 拼团人数加1
|
|
|
$inc = Regiment::query()->where('id','=',$regimentId)->increment('people_number',1);
|
|
@@ -896,16 +900,16 @@ class Orders extends Api{
|
|
|
// 回退数据
|
|
|
DB::rollBack();
|
|
|
// 提示信息
|
|
|
- return json_send(['code'=>'error','msg'=>'创建拼团失败','data'=>['error'=>'创建拼团失败']]);
|
|
|
+ return json_send(['code'=>'error','msg'=>'参与拼团失败','data'=>['error'=>'参与拼团失败']]);
|
|
|
}
|
|
|
//团满
|
|
|
if ((($regimentInfo['people_number'] + 1) == $regimentActiveInfo['number']) && $regimentActiveInfo['exceed_people'] == 1) {
|
|
|
- $res = regiment::query()->where('id','=',$regimentId)->update(['status'=>3]);
|
|
|
+ $res = Regiment::query()->where('id','=',$regimentId)->update(['status'=>2]);
|
|
|
if( !$res ) {
|
|
|
// 回退数据
|
|
|
DB::rollBack();
|
|
|
// 提示信息
|
|
|
- return json_send(['code'=>'error','msg'=>'创建拼团失败','data'=>['error'=>'创建拼团失败']]);
|
|
|
+ return json_send(['code'=>'error','msg'=>'修改成团状态失败','data'=>['error'=>'参与拼团失败']]);
|
|
|
}
|
|
|
//修改订单
|
|
|
$orderRes = $Model::query()->where('regiment_id','=',$regimentId)->update(['status'=>'1']);
|
|
@@ -913,25 +917,36 @@ class Orders extends Api{
|
|
|
// 回退数据
|
|
|
DB::rollBack();
|
|
|
// 提示信息
|
|
|
- return json_send(['code'=>'error','msg'=>'创建拼团失败','data'=>['error'=>'创建拼团失败']]);
|
|
|
+ return json_send(['code'=>'error','msg'=>'修改订单状态失败','data'=>['error'=>'参与拼团失败']]);
|
|
|
+ }
|
|
|
+ // 查询拼团对应的订单
|
|
|
+ $orderIds = $Model::query()->where('regiment_id','=',$regimentId)->pluck('id')->toArray();
|
|
|
+ // 修改这些订单的子订单状态
|
|
|
+ $orderProductRes = $OrdersProduct::query()->whereIn('order_id',$orderIds)->update(['status'=>'1']);
|
|
|
+ // 修改
|
|
|
+ if( !$orderProductRes ) {
|
|
|
+ // 回退数据
|
|
|
+ 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);
|
|
|
}
|
|
|
+ // 修改所有参团中的为已成功
|
|
|
+ $result = RegimentRecord::query()->where([['regiment_id','=',$regimentId],['status','=',0]])->update(['status'=>2]);
|
|
|
+ if( !$result ) {
|
|
|
+ // 回退数据
|
|
|
+ DB::rollBack();
|
|
|
+ // 提示信息
|
|
|
+ return json_send(['code'=>'error','msg'=>'创建拼团记录失败','data'=>['error'=>'创建拼团记录失败']]);
|
|
|
+ }
|
|
|
+ // 拼团成功
|
|
|
+ $regimentRecordInfo['status'] = 2;
|
|
|
}
|
|
|
}
|
|
|
- //拼团记录
|
|
|
- $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 ) {
|
|
|
// 回退数据
|
|
@@ -947,7 +962,7 @@ class Orders extends Api{
|
|
|
'snowflake_id' =>$orderInfo['snowflake_id'],
|
|
|
];
|
|
|
// 返回结果
|
|
|
- return json_send(['code'=>'success','msg'=>'下单成功','data'=>$data]);
|
|
|
+ return json_send(['code'=>'success','msg'=>'拼团成功','data'=>$data]);
|
|
|
// 返回结果
|
|
|
} catch (\Throwable $th) {
|
|
|
// 回退数据
|
|
@@ -996,10 +1011,10 @@ class Orders extends Api{
|
|
|
//开团用户取消团订单
|
|
|
if ($regimentInfo['people_number'] > 1 && $regimentInfo['custom_uid'] == $uid){
|
|
|
//查询团记录
|
|
|
- $regimentRecordInfo = RegimentRecord::query()->where([['order_id','<>',$oldData['id']],['regiment_id','=',$regimentInfo['id']],['status','=',0]])->first();
|
|
|
+ $regimentRecordInfo = RegimentRecord::query()->where([['order_id','<>',$oldData['id']],['regiment_id','=',$regimentInfo['id']],['status','=',0]])->first();
|
|
|
if ($regimentRecordInfo){
|
|
|
//将参团成员中的第一个用户变成开团人
|
|
|
- $result = Regiment::query()->where('id','=',$regimentRecordInfo['regiment_id'])->update(['custom_uid'=>$regimentRecordInfo['custom_uid']]);
|
|
|
+ $result = Regiment::query()->where('id','=',$regimentRecordInfo['regiment_id'])->update(['custom_uid'=>$regimentRecordInfo['custom_uid'],'update_time'=>time()]);
|
|
|
if (!$result) {
|
|
|
DB::rollBack();
|
|
|
return json_send(['code'=>'error','msg'=>'取消拼团,改变开团人失败']);
|
|
@@ -1011,22 +1026,22 @@ class Orders extends Api{
|
|
|
// 回退数据
|
|
|
DB::rollBack();
|
|
|
// 提示信息
|
|
|
- return json_send(['code'=>'error','msg'=>'取消拼团失败']);
|
|
|
+ return json_send(['code'=>'error','msg'=>'扣减开团成员失败']);
|
|
|
}
|
|
|
}else{
|
|
|
- $regimentRes = Regiment::query()->where('id','=',$oldData['regiment_id'])->update(['status'=>1]);
|
|
|
+ $regimentRes = Regiment::query()->where('id','=',$oldData['regiment_id'])->update(['status'=>1,'update_time'=>time()]);
|
|
|
if (!$regimentRes){
|
|
|
DB::rollBack();
|
|
|
return json_send(['code'=>'error','msg'=>'取消拼团失败']);
|
|
|
}
|
|
|
}
|
|
|
//修改拼团记录
|
|
|
- $regimentRes = RegimentRecord::query()->where([['order_id','=',$oldData['id'],]])->update(['status'=>'1']);
|
|
|
+ $regimentRes = RegimentRecord::query()->where([['order_id','=',$oldData['id']]])->update(['status'=>'1','update_time'=>time()]);
|
|
|
if( !$regimentRes ) {
|
|
|
// 回退数据
|
|
|
DB::rollBack();
|
|
|
// 提示信息
|
|
|
- return json_send(['code'=>'error','msg'=>'取消拼团失败']);
|
|
|
+ return json_send(['code'=>'error','msg'=>'修改拼团记录失败']);
|
|
|
}
|
|
|
// 提交数据
|
|
|
DB::commit();
|