feat : user
This commit is contained in:
@@ -24,16 +24,20 @@ use App\Model\CouponTemplate;
|
||||
use App\Model\User;
|
||||
use App\Model\UserAccount;
|
||||
use App\Model\UserCoupon;
|
||||
use App\Model\UserInvite;
|
||||
use App\Model\UserThird;
|
||||
use App\Service\Api\BaseService;
|
||||
use App\Service\ServiceTrait\Api\GetUserInfoTrait;
|
||||
use App\Service\ServiceTrait\Common\UserTrait;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use Random\RandomException;
|
||||
|
||||
abstract class LoginBaseService extends BaseService
|
||||
{
|
||||
use GetUserInfoTrait;
|
||||
use GetUserInfoTrait,
|
||||
UserTrait;
|
||||
|
||||
/**
|
||||
* 注入缓存类
|
||||
@@ -62,6 +66,12 @@ abstract class LoginBaseService extends BaseService
|
||||
#[Inject]
|
||||
protected ConfigCache $configCache;
|
||||
|
||||
/**
|
||||
* @var UserInvite $userInviteModel
|
||||
*/
|
||||
#[Inject]
|
||||
protected UserInvite $userInviteModel;
|
||||
|
||||
|
||||
/**
|
||||
* 锁定注册
|
||||
@@ -240,5 +250,41 @@ abstract class LoginBaseService extends BaseService
|
||||
$this->isNewcomerCouponPopUp = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws RandomException
|
||||
*/
|
||||
protected function addInviteCode(): void
|
||||
{
|
||||
$inviteCode = $this->generateStableCode($this->userId);
|
||||
|
||||
if ($this->userModel->checkInviteCodeIsUse($inviteCode) == 1) return;
|
||||
|
||||
if (!$this->userModel->where('id', $inviteCode)->update(['invite_code' => $inviteCode])) throw new ErrException('注册失败-00004');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
protected function checkInvite(): void
|
||||
{
|
||||
if (!$this->request->input('invite_code')) return;
|
||||
|
||||
$userId = $this->userModel->getUserIdByInviteCode($this->request->input('invite_code'));
|
||||
|
||||
if (empty($userId)) return;
|
||||
|
||||
if ($this->userInviteModel->checkIsInvite($this->userId) == 1) return;
|
||||
|
||||
$userInviteModel = new UserInvite();
|
||||
|
||||
$userInviteModel->user_id = $this->userId;
|
||||
$userInviteModel->invitee_user_id = $userId;
|
||||
$userInviteModel->channel = UserCode::INVITE_CHANNEL_USER; //todo 预先普通用户渠道
|
||||
$userInviteModel->status = UserCode::INVITE_STATUS_REGISTER;
|
||||
|
||||
if (!$userInviteModel->save()) throw new ErrException('注册失败-00005');
|
||||
}
|
||||
|
||||
abstract protected function register();
|
||||
}
|
||||
@@ -77,7 +77,10 @@ class WxFastLoginService extends LoginBaseService
|
||||
|
||||
$this->addAccount();
|
||||
|
||||
//todo 邀请过来的 邀请方有没有奖励 被邀请方有没有奖励
|
||||
$this->addInviteCode();
|
||||
|
||||
// 邀请过来的 邀请方有没有奖励 被邀请方有没有奖励
|
||||
$this->checkInvite();
|
||||
|
||||
// 有没有注册奖励
|
||||
$this->addCoupon();
|
||||
|
||||
49
app/Service/Api/Order/OrderListService.php
Normal file
49
app/Service/Api/Order/OrderListService.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/**
|
||||
* This service file is part of item.
|
||||
*
|
||||
* @author ctexthuang
|
||||
* @contact ctexthuang@qq.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Api\Order;
|
||||
|
||||
use App\Model\Order;
|
||||
use App\Service\Api\BaseService;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
|
||||
class OrderListService extends BaseService
|
||||
{
|
||||
/**
|
||||
* @var Order
|
||||
*/
|
||||
#[Inject]
|
||||
protected Order $orderModel;
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$limit = $this->request->input('limit', 20);
|
||||
|
||||
$orderList = $this->orderModel
|
||||
->where('user_id', $this->userId)
|
||||
->when($this->request->input('status'), function ($query) {
|
||||
$query->where('status', $this->request->input('status'));
|
||||
})
|
||||
->orderByDesc('id')
|
||||
->paginate($limit)
|
||||
->toArray();
|
||||
|
||||
if (!empty($orderList['data'])) {
|
||||
$this->buildData($orderList['data']);
|
||||
}
|
||||
}
|
||||
|
||||
private function buildData(array &$orderList)
|
||||
{
|
||||
// foreach ($orderList as &$order) {
|
||||
//
|
||||
// }
|
||||
}
|
||||
}
|
||||
@@ -10,10 +10,58 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Api\System;
|
||||
|
||||
class CityListService extends
|
||||
use App\Cache\Redis\Common\CityCache;
|
||||
use App\Constants\Common\CityCode;
|
||||
use App\Model\SystemCity;
|
||||
use App\Model\SystemCityConfig;
|
||||
use App\Service\Api\BaseService;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
class CityListService extends BaseService
|
||||
{
|
||||
public function handle()
|
||||
|
||||
/**
|
||||
* @var SystemCity
|
||||
*/
|
||||
#[Inject]
|
||||
protected SystemCity $systemCityModel;
|
||||
|
||||
/**
|
||||
* @var SystemCityConfig
|
||||
*/
|
||||
#[Inject]
|
||||
protected SystemCityConfig $systemCityConfigModel;
|
||||
|
||||
/**
|
||||
* @var CityCache
|
||||
*/
|
||||
#[Inject]
|
||||
protected CityCache $cityCache;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function handle(): array
|
||||
{
|
||||
//todo Write logic
|
||||
$allInfo = array_column($this->cityCache->getCityList(),'title','id');
|
||||
|
||||
$list = $this->systemCityModel
|
||||
->where('is_del', CityCode::IS_NOT_DELETE)
|
||||
->select(['id','title','status','city_id','province_id'])
|
||||
->get();
|
||||
|
||||
if (empty($list)) return $this->return->success('success', ['list' => []]);
|
||||
|
||||
$list = $list->toArray();
|
||||
foreach ($list as &$v) {
|
||||
$v['city_name'] = $allInfo[$v['city_id']];
|
||||
$v['province_name'] = $allInfo[$v['province_id']];
|
||||
}
|
||||
|
||||
return $this->return->success('success', ['list' => $list]);
|
||||
}
|
||||
}
|
||||
61
app/Service/Api/User/InviteListService.php
Normal file
61
app/Service/Api/User/InviteListService.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/**
|
||||
* This service file is part of item.
|
||||
*
|
||||
* @author ctexthuang
|
||||
* @contact ctexthuang@qq.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Api\User;
|
||||
|
||||
use App\Model\User;
|
||||
use App\Model\UserInvite;
|
||||
use App\Service\Api\BaseService;
|
||||
use App\Service\ServiceTrait\Api\GetUserInfoTrait;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
|
||||
class InviteListService extends BaseService
|
||||
{
|
||||
use GetUserInfoTrait;
|
||||
|
||||
/**
|
||||
* @var UserInvite $userInviteModel
|
||||
*/
|
||||
#[Inject]
|
||||
protected UserInvite $userInviteModel;
|
||||
|
||||
/**
|
||||
* @var User
|
||||
*/
|
||||
#[Inject]
|
||||
protected User $userModel;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function handle(): array
|
||||
{
|
||||
$limit = $this->request->input('limit', 20);
|
||||
|
||||
$list = $this->userInviteModel
|
||||
->where('invitee_user_id', $this->userId)
|
||||
->orderBy('id', 'desc')
|
||||
->paginate($limit)
|
||||
->toArray();
|
||||
|
||||
if (!empty($list['data'])) {
|
||||
$userIds = array_column($list['data'], 'user_id');
|
||||
$userInfoArr = $this->userModel->getInfoByIds($userIds);
|
||||
|
||||
foreach ($list['data'] as &$item) {
|
||||
$item['user_nick_name'] = $userInfoArr[$item['user_id']]['nick_name'];
|
||||
}
|
||||
}
|
||||
|
||||
$userInfo = $this->getUserInfo($this->userId);
|
||||
|
||||
return $this->return->success('success',['list' => $list,'invite_code'=> $userInfo['invite_code']]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user