|
@@ -3,8 +3,11 @@
|
|
|
|
|
|
namespace App\Modules\User\Services;
|
|
|
|
|
|
+use App\Cache\Lock\LockCache;
|
|
|
+use App\Consts\ErrorConst;
|
|
|
use App\Consts\QuickConst;
|
|
|
use App\Jobs\QappTikTokUser;
|
|
|
+use App\Libs\Utils;
|
|
|
use App\Modules\User\Models\QappPackage;
|
|
|
use App\Modules\User\Models\QappUser;
|
|
|
use App\Modules\User\Models\User;
|
|
@@ -24,24 +27,39 @@ class QappUserService
|
|
|
*/
|
|
|
public function login(array $data)
|
|
|
{
|
|
|
+ $lockToken = '';
|
|
|
$isNewRegister = false;
|
|
|
- $device_no = $data['device_no'];
|
|
|
- $channel_id = $this->findChannelId($data['package']);
|
|
|
- $qapp_user = $this->getQAppUserByDeviceNo($device_no, $channel_id);
|
|
|
+ $device_no = $data['device_no'];
|
|
|
+ $channel_id = $this->findChannelId($data['package']);
|
|
|
+ $qapp_user = $this->getQAppUserByDeviceNo($device_no, $channel_id);
|
|
|
if (!$qapp_user) {
|
|
|
+ // 加锁3秒,否则报错
|
|
|
+ $lockToken = md5($device_no . ':' . $channel_id);
|
|
|
+ $lock = LockCache::getLock($lockToken, 3);
|
|
|
+ if (!$lock) {
|
|
|
+ Utils::throwError(ErrorConst::QAPP_LOGIN_FREQUENTLY);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 初始化新用户
|
|
|
$isNewRegister = true;
|
|
|
$qapp_user = $this->createQuickAppUser($data);
|
|
|
}
|
|
|
- $user = $qapp_user->user;
|
|
|
- $uid = $user->id;
|
|
|
- $time = strtotime("+1 month");
|
|
|
+ $user = $qapp_user->user;
|
|
|
+ $uid = $user->id;
|
|
|
+ $time = strtotime("+1 month");
|
|
|
$token = JWTAuth::fromUser($user);
|
|
|
if ($data['send_order_id']) {
|
|
|
UserService::setUserSendOrder($uid, $data['send_order_id']);
|
|
|
}
|
|
|
// 新注册统计
|
|
|
if ($isNewRegister && $qapp_user) {
|
|
|
+ // 注册统计
|
|
|
QappAddDeskTopService::incrAddDeskTop($uid, QuickConst::FIELD_REGISTER);
|
|
|
+
|
|
|
+ // 释放锁
|
|
|
+ if ($lockToken) {
|
|
|
+ LockCache::releaseLock($lockToken);
|
|
|
+ }
|
|
|
}
|
|
|
return compact('token', 'time', 'uid');
|
|
|
}
|
|
@@ -69,7 +87,7 @@ class QappUserService
|
|
|
if ($version == "1.0") {
|
|
|
User::where('id', $uid)->update(
|
|
|
[
|
|
|
- 'balance' => DB::raw('balance+' . $reward),
|
|
|
+ 'balance' => DB::raw('balance+' . $reward),
|
|
|
'reward_balance' => DB::raw('reward_balance+' . $reward)
|
|
|
]
|
|
|
);
|
|
@@ -89,17 +107,17 @@ class QappUserService
|
|
|
|
|
|
public function setGolableUser(int $uid)
|
|
|
{
|
|
|
- $user_info = $this->getQAppUserByUid($uid);
|
|
|
- $qapp_user = app()->make('qapp_user');
|
|
|
- $qapp_user->id = $user_info->id;
|
|
|
- $qapp_user->uid = $user_info->uid;
|
|
|
- $qapp_user->send_order_id = $user_info->send_order_id;
|
|
|
- $qapp_user->device_no = $user_info->device_no;
|
|
|
- $qapp_user->device_info = $user_info->device_info;
|
|
|
- $qapp_user->phone = $user_info->phone;
|
|
|
- $qapp_user->user = $user_info->user;
|
|
|
+ $user_info = $this->getQAppUserByUid($uid);
|
|
|
+ $qapp_user = app()->make('qapp_user');
|
|
|
+ $qapp_user->id = $user_info->id;
|
|
|
+ $qapp_user->uid = $user_info->uid;
|
|
|
+ $qapp_user->send_order_id = $user_info->send_order_id;
|
|
|
+ $qapp_user->device_no = $user_info->device_no;
|
|
|
+ $qapp_user->device_info = $user_info->device_info;
|
|
|
+ $qapp_user->phone = $user_info->phone;
|
|
|
+ $qapp_user->user = $user_info->user;
|
|
|
$qapp_user->app_pay_merchat_id = $user_info->app_pay_merchat_id;
|
|
|
- $qapp_user->h5_pay_merchat_id = $user_info->h5_pay_merchat_id;
|
|
|
+ $qapp_user->h5_pay_merchat_id = $user_info->h5_pay_merchat_id;
|
|
|
$qapp_user->ali_pay_merchat_id = $user_info->ali_pay_merchat_id;
|
|
|
}
|
|
|
|
|
@@ -110,7 +128,7 @@ class QappUserService
|
|
|
{
|
|
|
$qapp_user = QappUser::where('device_no', $device_no)->where('channel_id', $channel_id)->first();
|
|
|
if ($qapp_user) {
|
|
|
- $user = User::find($qapp_user->uid);
|
|
|
+ $user = User::find($qapp_user->uid);
|
|
|
$qapp_user->user = $user;
|
|
|
}
|
|
|
return $qapp_user;
|
|
@@ -123,12 +141,12 @@ class QappUserService
|
|
|
{
|
|
|
$qapp_user = QappUser::where('uid', $uid)->first();
|
|
|
if ($qapp_user) {
|
|
|
- $user = User::find($uid);
|
|
|
- $qapp_user->user = $user;
|
|
|
- $qapp_user->send_order_id = UserService::getUserSendOrder($uid);
|
|
|
- $package_info = QappPackage::where('channel_id', $user->distribution_channel_id)->first();
|
|
|
+ $user = User::find($uid);
|
|
|
+ $qapp_user->user = $user;
|
|
|
+ $qapp_user->send_order_id = UserService::getUserSendOrder($uid);
|
|
|
+ $package_info = QappPackage::where('channel_id', $user->distribution_channel_id)->first();
|
|
|
$qapp_user->app_pay_merchat_id = $package_info->app_pay_merchat_id;
|
|
|
- $qapp_user->h5_pay_merchat_id = $package_info->h5_pay_merchat_id;
|
|
|
+ $qapp_user->h5_pay_merchat_id = $package_info->h5_pay_merchat_id;
|
|
|
$qapp_user->ali_pay_merchat_id = $package_info->ali_pay_merchat_id;
|
|
|
}
|
|
|
return $qapp_user;
|
|
@@ -142,16 +160,16 @@ class QappUserService
|
|
|
{
|
|
|
try {
|
|
|
DB::beginTransaction();
|
|
|
- $user = $this->createUser($data);
|
|
|
- $channel_id = $user->distribution_channel_id;
|
|
|
- $qapp_user = QappUser::firstOrCreate([
|
|
|
- 'device_no' => $data['device_no'],
|
|
|
+ $user = $this->createUser($data);
|
|
|
+ $channel_id = $user->distribution_channel_id;
|
|
|
+ $qapp_user = QappUser::firstOrCreate([
|
|
|
+ 'device_no' => $data['device_no'],
|
|
|
'channel_id' => $channel_id,
|
|
|
], [
|
|
|
- 'imei' => $data['imei'],
|
|
|
- 'androidid' => $data['androidid'],
|
|
|
- 'mac' => $data['mac'],
|
|
|
- 'uid' => $user->id,
|
|
|
+ 'imei' => $data['imei'],
|
|
|
+ 'androidid' => $data['androidid'],
|
|
|
+ 'mac' => $data['mac'],
|
|
|
+ 'uid' => $user->id,
|
|
|
'device_info' => $data['device_info'],
|
|
|
]);
|
|
|
$qapp_user->user = $user;
|
|
@@ -170,7 +188,7 @@ class QappUserService
|
|
|
$channel_id = env('QUICKAPP_SITE');
|
|
|
if ($package) {
|
|
|
$package_info = QappPackage::where('package', $package)->first();
|
|
|
- $channel_id = $package_info ? $package_info->channel_id : $channel_id;
|
|
|
+ $channel_id = $package_info ? $package_info->channel_id : $channel_id;
|
|
|
}
|
|
|
return $channel_id;
|
|
|
}
|
|
@@ -180,13 +198,13 @@ class QappUserService
|
|
|
*/
|
|
|
private function createUser(array $data)
|
|
|
{
|
|
|
- $openid = $data['device_no'];
|
|
|
- $unionid = $data['device_no'];
|
|
|
- $register_ip = _getIp();
|
|
|
+ $openid = $data['device_no'];
|
|
|
+ $unionid = $data['device_no'];
|
|
|
+ $register_ip = _getIp();
|
|
|
$distribution_channel_id = $this->findChannelId($data['package']);
|
|
|
- $send_order_id = $data['send_order_id'];
|
|
|
- $unique_key = compact('unionid', 'distribution_channel_id');
|
|
|
- $data = compact('openid', 'register_ip', 'send_order_id');
|
|
|
+ $send_order_id = $data['send_order_id'];
|
|
|
+ $unique_key = compact('unionid', 'distribution_channel_id');
|
|
|
+ $data = compact('openid', 'register_ip', 'send_order_id');
|
|
|
return User::firstOrCreate($unique_key, $data);
|
|
|
}
|
|
|
}
|