阶段更新
This commit is contained in:
@@ -6,11 +6,13 @@ use App\Api\Controllers\Controller;
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Jason\Api\Api;
|
||||
use Modules\User\Http\Resources\IdentityMiddleResource;
|
||||
use Modules\User\Http\Resources\UserIdentityResource;
|
||||
use Modules\User\Models\Identity;
|
||||
use Modules\User\Models\Order;
|
||||
use Validator;
|
||||
|
||||
class IndexController extends Controller
|
||||
{
|
||||
@@ -73,29 +75,12 @@ class IndexController extends Controller
|
||||
|
||||
}
|
||||
|
||||
// $price = $identity->getCondition('price', '0');
|
||||
// if ($identity->job == Identity::JOB_JK) {
|
||||
// $coupon =
|
||||
// }
|
||||
|
||||
$price = $identity->getCondition('price', '0');
|
||||
$cost = $identity->getCondition('cost', '0');
|
||||
if (! $cost) {
|
||||
$cost = $price;
|
||||
}
|
||||
|
||||
$coupon_price = 0;
|
||||
if ($identity->job == Identity::JOB_JK) {
|
||||
$coupons = $this->getCreateOrderCoupon($user, $identity, 0);
|
||||
if ($coupons->isNotEmpty()) {
|
||||
$user_coupon = $coupons->first();
|
||||
$coupon_price = $user_coupon->price;
|
||||
if ($user_coupon->coupon->type == Coupon::TYPE_REDUCTION) {
|
||||
$price = $price > $user_coupon->price ? bcsub($price, $coupon_price, 2) : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$data = [
|
||||
'identity' => [
|
||||
@@ -103,7 +88,6 @@ class IndexController extends Controller
|
||||
'name' => $identity->name,
|
||||
'cover' => $identity->cover_url,
|
||||
'description' => $ended_at ? '有效期至'.$ended_at : $identity->description,
|
||||
'coupon_price' => $coupon_price,
|
||||
'cost' => $cost,
|
||||
'price' => $price,
|
||||
'can_buy' => (bool) $identity->can_buy,
|
||||
@@ -130,48 +114,22 @@ class IndexController extends Controller
|
||||
{
|
||||
$user = Api::user();
|
||||
|
||||
$price = $request->price ?? 0;
|
||||
if ($identity->job != Identity::JOB_TY) {
|
||||
$validator = Validator::make($request->all(), [
|
||||
'name' => 'required',
|
||||
// 'card_no' => 'required|numeric',
|
||||
'cover' => 'required',
|
||||
'price' => 'required',
|
||||
], [
|
||||
'name.required' => '缺少姓名',
|
||||
'card_no.required' => '缺少银行卡号',
|
||||
'card_no.numeric' => '银行卡号只能是数字',
|
||||
'cover.required' => '缺少打款凭证',
|
||||
'price.required' => '缺少打款金额',
|
||||
]);
|
||||
$price = $request->price ?? 0;
|
||||
$validator = \Validator::make($request->all(), [
|
||||
'name' => 'required',
|
||||
// 'card_no' => 'required|numeric',
|
||||
'cover' => 'required',
|
||||
'price' => 'required',
|
||||
], [
|
||||
'name.required' => '缺少姓名',
|
||||
'card_no.required' => '缺少银行卡号',
|
||||
'card_no.numeric' => '银行卡号只能是数字',
|
||||
'cover.required' => '缺少打款凭证',
|
||||
'price.required' => '缺少打款金额',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return $this->failed($validator->errors()->first());
|
||||
}
|
||||
|
||||
|
||||
// if ($identity->job == Identity::JOB_NK && ! $user->parent) {
|
||||
// return $this->failed('没有推荐人不可开通年卡会员');
|
||||
// }
|
||||
} else {
|
||||
$total = $identity->users()->count();
|
||||
if ($total >= 100) {
|
||||
return $this->failed('体验官最多可开通100人');
|
||||
}
|
||||
$end_at = $identity->end_at;
|
||||
if ($end_at) {
|
||||
$end_at = Carbon::parse($end_at)->endOfDay();
|
||||
if (now()->gt($end_at)) {
|
||||
return $this->failed('体验官活动已过期');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$tencentMap = app('xuanchen.tencent.map');
|
||||
$res = $tencentMap->api()->ip(request()->ip())->toArray();
|
||||
if (! in_array($res['ad_info']['city'], ['深圳', '深圳市'])) {
|
||||
// return $this->failed('体验官活动只限于深圳用户参加');
|
||||
}
|
||||
if ($validator->fails()) {
|
||||
return $this->failed($validator->errors()->first());
|
||||
}
|
||||
|
||||
|
||||
@@ -197,17 +155,16 @@ class IndexController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$hasOne = Order::query()
|
||||
->byUser($user)
|
||||
->where('identity_id', $identity->id)
|
||||
->where('state', Order::STATE_INIT)
|
||||
->exists();
|
||||
|
||||
if ($hasOne) {
|
||||
return $this->failed('您已经提交过了,请等待审核');
|
||||
}
|
||||
|
||||
$hasOne = Order::query()
|
||||
->byUser($user)
|
||||
->where('identity_id', $identity->id)
|
||||
->where('state', Order::STATE_INIT)
|
||||
->exists();
|
||||
|
||||
if ($hasOne) {
|
||||
return $this->failed('您已经提交过了,请等待审核');
|
||||
}
|
||||
|
||||
|
||||
if (! $price) {
|
||||
@@ -231,21 +188,7 @@ class IndexController extends Controller
|
||||
$order = Order::create($data);
|
||||
|
||||
if ($order) {
|
||||
if ($coupon_price > 0) {
|
||||
$order->useCouponLog()->create([
|
||||
'sourceable_type' => get_class($order),
|
||||
'sourceable_id' => $order->id,
|
||||
'coupon_grant_id' => $user_coupon->id,
|
||||
]);
|
||||
}
|
||||
if ($identity->job == Identity::JOB_TY) {
|
||||
return $this->success([
|
||||
'order_id' => $order->id,
|
||||
'openids' => $user->wechat->getOpenids()
|
||||
]);
|
||||
} else {
|
||||
return $this->success('提交成功,请等待后台审核');
|
||||
}
|
||||
return $this->success('提交成功,请等待后台审核');
|
||||
} else {
|
||||
return $this->failed('创建订单失败,请稍后再试');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user