阶段更新
This commit is contained in:
@@ -5,12 +5,14 @@ namespace Modules\User\Http\Controllers\Api\Auth;
|
||||
use App\Api\Controllers\Controller;
|
||||
use Exception;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Arr;
|
||||
use Jason\Api\Api;
|
||||
use Modules\User\Events\UserLoginSuccess;
|
||||
use Modules\User\Facades\Sms;
|
||||
use Modules\User\Http\Requests\LoginSmsRequest;
|
||||
use Modules\User\Http\Requests\SmsRequest;
|
||||
use Modules\User\Models\User;
|
||||
use Vinkla\Hashids\Facades\Hashids;
|
||||
|
||||
class SmsController extends Controller
|
||||
{
|
||||
@@ -30,9 +32,14 @@ class SmsController extends Controller
|
||||
try {
|
||||
Sms::sendVerificationCode($mobile);
|
||||
$isExists = User::where('username', $mobile)->exists();
|
||||
if (Arr::get(Sms::getConfig(), 'debug')) {
|
||||
$message = '短信发送成功,测试短信码'.Arr::get(Sms::getConfig(), 'debug_code');
|
||||
} else {
|
||||
$message = '短信发送成功';
|
||||
}
|
||||
return $this->success([
|
||||
'new' => ! $isExists,
|
||||
'message' => '短信发送成功',
|
||||
'message' => $message,
|
||||
]);
|
||||
} catch (Exception $exception) {
|
||||
return $this->failed($exception->getException('aliyun')->getMessage());
|
||||
@@ -49,18 +56,10 @@ class SmsController extends Controller
|
||||
*/
|
||||
public function login(LoginSmsRequest $request): JsonResponse
|
||||
{
|
||||
$mobileNo = $request->mobileNo;
|
||||
$code = $request->code;
|
||||
$invite_code = $request->invite ?? '';
|
||||
$channel_code = $request->channel ?? '';//渠道
|
||||
$channel = '';
|
||||
if ($channel_code) {
|
||||
$channel = UserChannel::query()
|
||||
->where('code', $channel_code)
|
||||
->first();
|
||||
}
|
||||
|
||||
$parent = 0;
|
||||
$mobileNo = $request->mobileNo;
|
||||
$code = $request->code;
|
||||
$invite_code = $request->invite ?? '';
|
||||
$parent = 0;
|
||||
|
||||
if ($invite_code) {
|
||||
$invite = Hashids::connection('code')->decode($invite_code);
|
||||
@@ -84,9 +83,9 @@ class SmsController extends Controller
|
||||
$user = User::firstOrCreate([
|
||||
'username' => $mobileNo,
|
||||
], [
|
||||
'parent_id' => $parent,
|
||||
'password' => 111111,
|
||||
]);
|
||||
'parent_id' => $parent,
|
||||
'password' => 111111,
|
||||
]);
|
||||
|
||||
$is_new = $user->wasRecentlyCreated;
|
||||
|
||||
@@ -95,10 +94,8 @@ class SmsController extends Controller
|
||||
if ($user->parent && $parent && $user->parent->id != $parent) {
|
||||
$message = "您已与用户{$user->parent->info->nickname}绑定隶属关系,此次邀请码无效";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
$token = Api::login($user);
|
||||
|
||||
event(new UserLoginSuccess($user, $request, '手机验证码'));
|
||||
|
||||
@@ -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('创建订单失败,请稍后再试');
|
||||
}
|
||||
|
||||
@@ -115,12 +115,6 @@ class IndexController extends Controller
|
||||
$address = Address::find($address_id);
|
||||
|
||||
$userIdentity = $user->identityFirst();
|
||||
if ($userIdentity->job == Identity::JOB_TY) {
|
||||
$shenzhen = Region::query()->where('name', '深圳市')->first();
|
||||
if ($address->city_id != $shenzhen->id) {
|
||||
return $this->failed('体验官收货地址只能选择深圳');
|
||||
}
|
||||
}
|
||||
|
||||
$goods_sku = GoodsSku::query()
|
||||
->whereHas('goods', function ($q) {
|
||||
|
||||
Reference in New Issue
Block a user