阶段更新
This commit is contained in:
@@ -5,9 +5,10 @@ namespace Modules\User\Http\Controllers\Admin\Actions;
|
||||
use Encore\Admin\Actions\Response;
|
||||
use Encore\Admin\Actions\RowAction;
|
||||
use Exception;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\User\Models\Identity;
|
||||
use Modules\User\Models\Order;
|
||||
use Modules\User\Models\User;
|
||||
|
||||
class JoinIdentity extends RowAction
|
||||
{
|
||||
@@ -38,11 +39,6 @@ class JoinIdentity extends RowAction
|
||||
$order = Order::create($data);
|
||||
$order->pay();
|
||||
|
||||
//
|
||||
// $user->joinIdentity($identity_id, 'System', [
|
||||
// 'remark' => $remark,
|
||||
// ]);
|
||||
|
||||
return $this->response()->success('加入身份成功')->refresh();
|
||||
} catch (Exception $e) {
|
||||
return $this->response()->error($e->getMessage())->refresh();
|
||||
@@ -52,13 +48,9 @@ class JoinIdentity extends RowAction
|
||||
public function form(User $user)
|
||||
{
|
||||
$userIdentity = $user->identityFirst();
|
||||
if (empty($userIdentity)) {
|
||||
$identities = Identity::whereIn('order', [2, 3, 4, 5])->pluck('name', 'id');
|
||||
} elseif ($userIdentity->job == Identity::JOB_YK) {
|
||||
$identities = Identity::whereIn('order', [2, 3, 4, 5])->pluck('name', 'id');
|
||||
} else {
|
||||
$identities = Identity::where('order', '>', $userIdentity->order)->pluck('name', 'id');
|
||||
}
|
||||
|
||||
$identities = Identity::where('order', '>', $userIdentity->order)->pluck('name', 'id');
|
||||
|
||||
$this->select('join_identity_id', '加入身份')
|
||||
->options($identities)
|
||||
->required();
|
||||
|
||||
@@ -136,11 +136,7 @@ class IdentitiesController extends AdminController
|
||||
->default(1);
|
||||
$form->radioButton('job', '身份')
|
||||
->options(Identity::JOBS)
|
||||
->default(0)
|
||||
->when(Identity::JOB_TY, function (Form $form) {
|
||||
$form->number('total', '可开通总数')->default(100);
|
||||
$form->date('end_at', '结束日期');
|
||||
});
|
||||
->default(0);
|
||||
$form->divider();
|
||||
|
||||
$form->table('conditions', '升级条件', function (NestedForm $form) {
|
||||
|
||||
@@ -11,7 +11,9 @@ use Illuminate\Support\Facades\DB;
|
||||
use Modules\User\Http\Controllers\Admin\Actions\JoinIdentity;
|
||||
use Modules\User\Http\Controllers\Admin\Actions\RemoveIdentity;
|
||||
use Modules\User\Http\Controllers\Admin\Actions\UpdateRelation;
|
||||
use Modules\User\Models\Identity;
|
||||
use Modules\User\Models\User;
|
||||
use Vinkla\Hashids\Facades\Hashids;
|
||||
|
||||
class IndexController extends AdminController
|
||||
{
|
||||
|
||||
@@ -3,9 +3,12 @@
|
||||
namespace Modules\User\Http\Controllers\Admin;
|
||||
|
||||
use Encore\Admin\Controllers\AdminController;
|
||||
use Encore\Admin\Form;
|
||||
use Encore\Admin\Grid;
|
||||
use Exception;
|
||||
use Modules\User\Http\Controllers\Admin\Actions\Pay;
|
||||
use Modules\User\Http\Controllers\Admin\Actions\Refund;
|
||||
use Modules\User\Models\Identity;
|
||||
use Modules\User\Models\Order;
|
||||
|
||||
class OrderController extends AdminController
|
||||
@@ -67,7 +70,7 @@ class OrderController extends AdminController
|
||||
$grid->column('price', '应打款额')->editable();
|
||||
$grid->column('state', '状态')->using(Order::STATES)->label();
|
||||
$grid->column('type', '类型')->using(Order::TYPES)->label();
|
||||
|
||||
|
||||
$grid->column('created_at', '升级时间');
|
||||
|
||||
return $grid;
|
||||
|
||||
@@ -5,7 +5,6 @@ namespace Modules\User\Http\Controllers\Admin;
|
||||
use Encore\Admin\Controllers\AdminController;
|
||||
use Encore\Admin\Grid;
|
||||
use Modules\User\Models\UserStock;
|
||||
use Modules\User\Models\UserStockLog;
|
||||
|
||||
class StockController extends AdminController
|
||||
{
|
||||
@@ -43,7 +42,7 @@ class StockController extends AdminController
|
||||
});
|
||||
|
||||
$grid->column('stock', '总数');
|
||||
$grid->column('hold', '提货数')
|
||||
$grid->column('logs_count', '变动记录')
|
||||
->link(function () {
|
||||
return admin_url('/users/stocks/'.$this->id.'/logs');
|
||||
}, '_blank');
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -4,15 +4,10 @@ namespace Modules\User\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Jason\Api\Api;
|
||||
use Modules\Coupon\Models\Coupon;
|
||||
use Modules\Coupon\Traits\WithCoupon;
|
||||
use Modules\User\Models\Identity;
|
||||
use Modules\User\Models\Order;
|
||||
|
||||
class UserIdentityResource extends JsonResource
|
||||
{
|
||||
use WithCoupon;
|
||||
|
||||
public function toArray($request): array
|
||||
{
|
||||
$user = Api::user();
|
||||
@@ -44,36 +39,17 @@ class UserIdentityResource extends JsonResource
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ($this->job == Identity::JOB_JK) {
|
||||
$openIdentity = Identity::find($this->id);
|
||||
$coupons = $this->getCreateOrderCoupon($user, $openIdentity, 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->job == Identity::JOB_HH && $identity->job == Identity::JOB_HH) {
|
||||
$star = $identity->getOriginal('pivot_star', 0);
|
||||
if ($star > 0) {
|
||||
$identityName = config('identity.stars.'.$star, '').$identityName;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$open = true;
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'identity_id' => $this->id,
|
||||
'name' => $identityName,
|
||||
'stock' => $this->stock,
|
||||
'years' => $this->years,
|
||||
'times' => $this->when($user && $this->id == $user->identityFirst()->id, function () use ($user) {
|
||||
'identity_id' => $this->id,
|
||||
'name' => $identityName,
|
||||
'stock' => $this->stock,
|
||||
'years' => $this->years,
|
||||
'times' => $this->when($user && $this->id == $user->identityFirst()->id, function () use ($user) {
|
||||
return new IdentityMiddleResource($user->identityMiddle()->first());
|
||||
}, [
|
||||
'name' => '---',
|
||||
@@ -81,22 +57,22 @@ class UserIdentityResource extends JsonResource
|
||||
'started_at' => '---',
|
||||
'ended_at' => '---',
|
||||
]),
|
||||
'cover' => $this->cover_url,
|
||||
'order' => $this->order,
|
||||
'description' => $this->description ?? "",
|
||||
'coupon_price' => floatval($coupon_price),//开通金额
|
||||
'cost' => floatval($cost),//开通金额
|
||||
'price' => floatval($price),//开通金额
|
||||
'can' => [
|
||||
'cover' => $this->cover_url,
|
||||
'order' => $this->order,
|
||||
'description' => $this->description ?? "",
|
||||
'coupon_price' => floatval($coupon_price),//开通金额
|
||||
'cost' => floatval($cost),//开通金额
|
||||
'price' => floatval($price),//开通金额
|
||||
'can' => [
|
||||
'buy' => (bool) $this->can_buy,
|
||||
'open' => $this->can_buy ? $open : false,//开通
|
||||
'renew' => $this->can_buy ? $renew : false,//续费
|
||||
],
|
||||
'buttonText' => $text,
|
||||
'rights' => $this->rights,
|
||||
'rules' => $this->getRules(),
|
||||
'not_rules' => $this->getNotRules(),
|
||||
'is_open' => $user && $this->id == $user->identityFirst()->id
|
||||
'buttonText' => $text,
|
||||
'rights' => $this->rights,
|
||||
'rules' => $this->getRules(),
|
||||
'not_rules' => $this->getNotRules(),
|
||||
'is_open' => $user && $this->id == $user->identityFirst()->id
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ class UserInfoBaseResource extends JsonResource
|
||||
'identity' => new UserIdentityBaseResource($this->identities->first()),
|
||||
'status' => $this->getStateData(),
|
||||
'canPick' => $this->canPick(),
|
||||
'nowStatus' => $this->getNowStatus(),
|
||||
'tag' => $this->tag
|
||||
];
|
||||
}
|
||||
|
||||
@@ -37,12 +37,9 @@ class UserInfoResource extends JsonResource
|
||||
'created_at' => (string) $this->created_at,
|
||||
'sign' => $this->getSignData(),
|
||||
'status' => $this->getStateData(),
|
||||
'nowStatus' => $this->getNowStatus(),
|
||||
'canPick' => $this->canPick(),
|
||||
'count' => [
|
||||
'coupon' => $this->couponGrants()->count(),//<2F>Ż<EFBFBD>ȯ<EFBFBD><C8AF><EFBFBD><EFBFBD>
|
||||
'relation' => $this->getRelationCount(),//<2F>¼<EFBFBD>
|
||||
'invites' => $this->invites()->count(),//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
'notifications' => $this->unreadNotifications()->count(),//<2F><>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>
|
||||
'orders' => Order::byUser(Api::user())->common()->count(),//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
'refunds' => RefundModel::byUser(Api::user())->count(),//<2F>˿<CBBF><EEB5A5><EFBFBD><EFBFBD>
|
||||
|
||||
Reference in New Issue
Block a user