调整首页接口和返回数据
This commit is contained in:
@@ -65,14 +65,6 @@ class OrderBuyController extends Controller
|
||||
}
|
||||
|
||||
|
||||
$areaCode = $user->info->areaCode;
|
||||
if (! $areaCode) {
|
||||
return $this->failed('您没有提货码不可参与此活动');
|
||||
}
|
||||
if ($areaCode->status != AreaCode::STATUS_INIT) {
|
||||
return $this->failed('提货码已被使用,不可重复使用');
|
||||
}
|
||||
|
||||
$address_id = $request->address_id;
|
||||
if ($address_id) {
|
||||
$address = Address::find($address_id);
|
||||
@@ -93,6 +85,14 @@ class OrderBuyController extends Controller
|
||||
$type = OrderModel::TYPE_SCORE;
|
||||
}
|
||||
|
||||
$areaCode = $user->info->areaCode;
|
||||
if (! $areaCode && $type == OrderModel::TYPE_SAMPLE) {
|
||||
return $this->failed('您没有提货码不可参与此活动');
|
||||
}
|
||||
if ($areaCode->status != AreaCode::STATUS_INIT && $type == OrderModel::TYPE_SAMPLE) {
|
||||
return $this->failed('提货码已被使用,不可重复使用');
|
||||
}
|
||||
|
||||
$freight = $item->freight();
|
||||
$amount = $item->total();
|
||||
$weight = $item->weight();
|
||||
@@ -154,14 +154,6 @@ class OrderBuyController extends Controller
|
||||
$qty = $request->qty;
|
||||
$share_user_id = $request->share_user_id ?? 0;
|
||||
|
||||
$areaCode = $user->info->areaCode;
|
||||
if (! $areaCode) {
|
||||
return $this->failed('您没有提货码不可参与此活动');
|
||||
}
|
||||
if ($areaCode->status != AreaCode::STATUS_INIT) {
|
||||
return $this->failed('提货码已被使用,不可重复使用');
|
||||
}
|
||||
|
||||
|
||||
$detail = collect();
|
||||
|
||||
@@ -187,6 +179,14 @@ class OrderBuyController extends Controller
|
||||
$type = OrderModel::TYPE_SCORE;
|
||||
}
|
||||
|
||||
$areaCode = $user->info->areaCode;
|
||||
if (! $areaCode && $type == OrderModel::TYPE_SAMPLE) {
|
||||
return $this->failed('您没有提货码不可参与此活动');
|
||||
}
|
||||
if ($areaCode->status != AreaCode::STATUS_INIT && $type == OrderModel::TYPE_SAMPLE) {
|
||||
return $this->failed('提货码已被使用,不可重复使用');
|
||||
}
|
||||
|
||||
$address = Address::where('user_id', $user->id)->where('id', $address_id)->first();
|
||||
|
||||
if (in_array($type, [OrderModel::TYPE_SCORE, OrderModel::TYPE_NORMAL]) && ! $address) {
|
||||
|
||||
@@ -64,15 +64,15 @@ class OrderController extends Controller
|
||||
}, function ($query) {
|
||||
$query->common();
|
||||
})
|
||||
// ->when($type, function ($q) use ($type) {
|
||||
// if ($type == 'score') {
|
||||
// $q->TypeScore();
|
||||
// }
|
||||
//
|
||||
// if ($type == 'sample') {
|
||||
// $q->TypeSample();
|
||||
// }
|
||||
// })
|
||||
->when($type, function ($q) use ($type) {
|
||||
if ($type == 'score') {
|
||||
$q->TypeScore();
|
||||
}
|
||||
|
||||
if ($type == 'sample') {
|
||||
$q->TypeSample();
|
||||
}
|
||||
})
|
||||
->paginate();
|
||||
|
||||
return $this->success(new OrderCollection($list));
|
||||
|
||||
@@ -135,4 +135,17 @@ trait OrderScopes
|
||||
return $query->where('type', Order::TYPE_SAMPLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 正常购买
|
||||
*
|
||||
* @Author: 玄尘
|
||||
* @Date: 2023/1/18 16:11
|
||||
* @param Builder $query
|
||||
* @return Builder
|
||||
*/
|
||||
public function scopeTypeNormal(Builder $query): Builder
|
||||
{
|
||||
return $query->where('type', Order::TYPE_NORMAL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -63,10 +63,27 @@ trait HasOrders
|
||||
public function getOrderCount(): array
|
||||
{
|
||||
return [
|
||||
'all' => $this->orders()->common()->count(),
|
||||
'paid' => $this->orders()->paid()->count(),
|
||||
'unpay' => $this->orders()->unpay()->count(),
|
||||
'delivered' => $this->orders()->delivered()->count(),
|
||||
//免费领取
|
||||
'sample' => [
|
||||
'all' => $this->orders()->typesample()->common()->count(),
|
||||
'paid' => $this->orders()->typesample()->paid()->count(),
|
||||
'unpay' => $this->orders()->typesample()->unpay()->count(),
|
||||
'delivered' => $this->orders()->typesample()->delivered()->count(),
|
||||
],
|
||||
//正常
|
||||
'normal' => [
|
||||
'all' => $this->orders()->typenormal()->common()->count(),
|
||||
'paid' => $this->orders()->typenormal()->paid()->count(),
|
||||
'unpay' => $this->orders()->typenormal()->unpay()->count(),
|
||||
'delivered' => $this->orders()->typenormal()->delivered()->count(),
|
||||
],
|
||||
//积分兑换
|
||||
'score' => [
|
||||
'all' => $this->orders()->scopeTypeScore()->common()->count(),
|
||||
'paid' => $this->orders()->scopeTypeScore()->paid()->count(),
|
||||
'unpay' => $this->orders()->scopeTypeScore()->unpay()->count(),
|
||||
'delivered' => $this->orders()->scopeTypeScore()->delivered()->count(),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user