用户注册赠送抽奖次数
parent
47ec06259c
commit
34a585f081
|
|
@ -10,6 +10,7 @@ use App\Admin\Actions\Show\UserEditAgent;
|
|||
use App\Admin\Actions\Show\UserEditPhone;
|
||||
use App\Admin\Renderable\UserSalesValueLogSimpleTable;
|
||||
use App\Admin\Repositories\User;
|
||||
use App\Events\UserCreated;
|
||||
use App\Exceptions\BizException;
|
||||
use App\Models\Agent;
|
||||
use App\Models\Order;
|
||||
|
|
@ -240,6 +241,15 @@ class UserController extends AdminController
|
|||
$form->display('created_at');
|
||||
$form->display('updated_at');
|
||||
$form->hidden('register_ip')->value(RequestFacades::getClientIp());
|
||||
|
||||
// $form->saved(function (Form $form) {
|
||||
// if ($form->isCreating()) {
|
||||
// $newId = $form->getKey();
|
||||
// if ($newId) {
|
||||
// event(new UserCreated(UserModel::findOrFail($newId)));
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ use App\Exceptions\BizException;
|
|||
use Illuminate\Support\Facades\DB;
|
||||
use App\Models\{User, SocialiteUser};
|
||||
use App\Endpoint\Api\Http\Controllers\Controller;
|
||||
use App\Events\UserCreated;
|
||||
use EasyWeChat\Factory;
|
||||
|
||||
class MiniprogramController extends Controller
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ class DrawActivityController extends Controller
|
|||
{
|
||||
$drawActivity = DrawActivity::with(['prizes' => function ($builder) {
|
||||
$builder->latest('sort');
|
||||
}])->onlyPublished()->orderByDesc('id')->findOrFail($id);
|
||||
}])->onlyPublished()->findOrFail($id);
|
||||
|
||||
$drawTicket = null;
|
||||
$drawLog = null;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Broadcasting\Channel;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* 用户注册成功
|
||||
*/
|
||||
class UserCreated
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
public User $user;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(User $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
namespace App\Listeners;
|
||||
|
||||
use App\Events\UserCreated;
|
||||
use App\Models\DrawActivity;
|
||||
use App\Services\DrawTicketService;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
|
||||
/**
|
||||
* 赠送抽奖次数
|
||||
*/
|
||||
class SendDrawTicket
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param object $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(UserCreated $event)
|
||||
{
|
||||
$user = $event->user;
|
||||
// 有效的抽奖活动
|
||||
$drawActivity = DrawActivity::onlyRunning()->where("send_ticket_type", 1)->first();
|
||||
if ($drawActivity) {
|
||||
(new DrawTicketService())->change($user, $drawActivity, 1, "新用户注册赠送1次抽奖");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -41,6 +41,7 @@ class DrawActivity extends Model
|
|||
'bg_image',
|
||||
'bg_color',
|
||||
'status',
|
||||
'send_ticket_type'
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Events\UserCreated;
|
||||
use Dcat\Admin\Traits\HasDateTimeFormatter;
|
||||
use Illuminate\Auth\Authenticatable;
|
||||
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
|
||||
|
|
@ -10,6 +11,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Foundation\Auth\Access\Authorizable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Str;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
|
|
@ -64,6 +66,10 @@ class User extends Model implements AuthorizableContract, AuthenticatableContrac
|
|||
'status' => 'int',
|
||||
];
|
||||
|
||||
protected $dispatchesEvents = [
|
||||
'created' => UserCreated::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
@ -380,7 +386,10 @@ class User extends Model implements AuthorizableContract, AuthenticatableContrac
|
|||
// 邀请人的深度
|
||||
$depth = (int) $inviter?->userInfo?->depth;
|
||||
|
||||
$phone = $user->phone;
|
||||
$hidePhone = substr($phone, 0, 3) . '****' . substr($phone, 7);
|
||||
$user->userInfo()->create([
|
||||
'nickname' => $hidePhone,
|
||||
'inviter_id' => $inviter?->id,
|
||||
'depth' => $depth + 1,
|
||||
'path' => Str::finish($inviter?->userInfo?->full_path, '-'),
|
||||
|
|
|
|||
|
|
@ -24,6 +24,9 @@ class EventServiceProvider extends ServiceProvider
|
|||
\App\Listeners\OrderPrint::class,
|
||||
\App\Listeners\OrderAutoComplete::class,
|
||||
],
|
||||
\App\Events\UserCreated::class => [
|
||||
\App\Listeners\SendDrawTicket::class,
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue