Browse Source

修改用户登录和信息更新

master
weigang 5 years ago
parent
commit
16e7c5b1f5
  1. 17
      app/Constants/v3/OssThumbnail.php
  2. 5
      app/Constants/v3/SsdbKeys.php
  3. 187
      app/Controller/v3/GoodsRecommendController.php
  4. 17
      app/Controller/v3/HomeController.php
  5. 9
      app/Controller/v3/UserController.php
  6. 6
      app/Model/v3/Banner.php
  7. 4
      app/Model/v3/Goods.php
  8. 7
      app/Model/v3/GoodsActivity.php
  9. 11
      app/Request/v3/UserUpdateRequest.php
  10. 7
      app/Service/v3/Implementations/ActivityService.php
  11. 3
      app/Service/v3/Implementations/CategoryService.php
  12. 35
      app/Service/v3/Implementations/TabsService.php
  13. 35
      app/Service/v3/Implementations/UserInfoService.php
  14. 18
      app/Service/v3/Implementations/WxLoginService.php
  15. 11
      app/Service/v3/Interfaces/TabsServiceInterface.php
  16. 2
      app/Service/v3/Interfaces/UserInfoServiceInterface.php
  17. 1
      config/autoload/dependencies.php

17
app/Constants/v3/OssThumbnail.php

@ -0,0 +1,17 @@
<?php
namespace App\Constants\v3;
use Hyperf\Constants\AbstractConstants;
use Hyperf\Constants\Annotation\Constants;
/**
* @Constants
*/
class OssThumbnail extends AbstractConstants
{
/**
* @Message("thumbnail_100_q50")
*/
const THUMBNAIL_100_Q50 = '!thumbnail_100_q50';
}

5
app/Constants/v3/SsdbKeys.php

@ -50,4 +50,9 @@ class SsdbKeys extends AbstractConstants
*/
const APPLET_INDEX_CATEGORY = 'applet_index_category';
/**
* @Message("用户信息")
*/
const USER_INFO = 'user_info_';
}

187
app/Controller/v3/GoodsRecommendController.php

@ -14,97 +14,6 @@ use App\Model\v3\Goods;
class GoodsRecommendController extends BaseController
{
protected $data;
public function __construct()
{
$this->data = [
[
'goods' => [
'id' => 1,
'cover_img' => config('alioss.img_host').'/attachment/types/c9b656181bbbc463624ca3803c5be7539f2fd62253f9a-cwVLri.png',
'name' => '【优质】大白菜11',
'spec' => [
['key' => '净含量', 'value' => '500g']
],
'tags' => ['限时', '折扣'],
'original_price' => 50.5,
'price' => 25.25,
'inventory' => 10,
'month_sales' => 20,
'total_sales' => 20,
'cart_num' => 0,
'is_effective' => 2,
'noneffective_note' => '已卖完',
'store' => ['id' => 1, 'logo' => '', 'name' => '我是一个商家']
],
],
[
'goods' => [
'id' => 2,
'cover_img' => config('alioss.img_host').'/attachment/types/c9b656181bbbc463624ca3803c5be7539f2fd62253f9a-cwVLri.png',
'name' => '【优质】大白菜11',
'spec' => [
['key' => '净含量', 'value' => '500g']
],
'tags' => ['限时', '折扣'],
'original_price' => 50.5,
'price' => 25.25,
'inventory' => 10,
'month_sales' => 20,
'total_sales' => 20,
'cart_num' => 0,
'is_effective' => 2,
'noneffective_note' => '已卖完',
'store' => ['id' => 222, 'logo' => '', 'name' => '我是一个商家222']
],
],
[
'goods' => [
'id' => 3,
'cover_img' => config('alioss.img_host').'/attachment/types/c9b656181bbbc463624ca3803c5be7539f2fd62253f9a-cwVLri.png',
'name' => '【优质】大白菜11',
'spec' => [
['key' => '净含量', 'value' => '500g']
],
'tags' => ['限时', '折扣'],
'original_price' => 50.5,
'price' => 25.25,
'inventory' => 10,
'month_sales' => 20,
'total_sales' => 20,
'cart_num' => 0,
'is_effective' => 2,
'noneffective_note' => '已卖完',
'store' => ['id' => 2, 'logo' => '', 'name' => '我是一个商家333']
],
],
[
'goods' => [
'id' => 4,
'cover_img' => config('alioss.img_host').'/attachment/types/c9b656181bbbc463624ca3803c5be7539f2fd62253f9a-cwVLri.png',
'name' => '【优质】大白菜11',
'spec' => [
['key' => '净含量', 'value' => '500g']
],
'tags' => ['限时', '折扣'],
'original_price' => 50.5,
'price' => 25.25,
'inventory' => 10,
'month_sales' => 20,
'total_sales' => 20,
'cart_num' => 0,
'is_effective' => 2,
'noneffective_note' => '已卖完',
],
'store' => ['id' => 3, 'logo' => '', 'name' => '我是一个商家444']
]
];
parent::__construct();
}
/**
* 获取首页tabs推荐商品列表
* 1、前端上传tab标识
@ -114,108 +23,12 @@ class GoodsRecommendController extends BaseController
*/
public function getByTabsForAppletIndex()
{
$tabsData = [
Tabs::APPLET_INDEX_RECOMMEND => [
[
'goods' => [
'id' => 1,
'cover_img' => config('alioss.img_host').'/attachment/types/c9b656181bbbc463624ca3803c5be7539f2fd62253f9a-cwVLri.png',
'name' => '【优质】大白菜11',
'spec' => [
['key' => '净含量', 'value' => '500g']
],
'tags' => ['限时', '折扣'],
'original_price' => 50.5,
'price' => 25.25,
'inventory' => 10,
'month_sales' => 20,
'total_sales' => 20,
'cart_num' => 0,
'is_effective' => 2,
'noneffective_note' => '已卖完',
],
'store' => ['id' => 1, 'logo' => '', 'name' => '我是一个商家']
],
],
Tabs::APPLET_INDEX_NEW => [
[
'goods' => [
'id' => 2,
'cover_img' => config('alioss.img_host').'/attachment/types/c9b656181bbbc463624ca3803c5be7539f2fd62253f9a-cwVLri.png',
'name' => '【优质】大白菜11',
'spec' => [
['key' => '净含量', 'value' => '500g']
],
'tags' => ['限时', '折扣'],
'original_price' => 50.5,
'price' => 25.25,
'inventory' => 10,
'month_sales' => 20,
'total_sales' => 20,
'cart_num' => 0,
'is_effective' => 2,
'noneffective_note' => '已卖完',
],
'store' => ['id' => 2, 'logo' => '', 'name' => '我是一个商家222']
],
],
Tabs::APPLET_INDEX_FRESH => [
[
'goods' => [
'id' => 3,
'cover_img' => config('alioss.img_host').'/attachment/types/c9b656181bbbc463624ca3803c5be7539f2fd62253f9a-cwVLri.png',
'name' => '【优质】大白菜11',
'spec' => [
['key' => '净含量', 'value' => '500g']
],
'tags' => ['限时', '折扣'],
'original_price' => 50.5,
'price' => 25.25,
'inventory' => 10,
'month_sales' => 20,
'total_sales' => 20,
'cart_num' => 0,
'is_effective' => 2,
'noneffective_note' => '已卖完',
],
'store' => ['id' => 3, 'logo' => '', 'name' => '我是一个商家333']
],
],
Tabs::APPLET_INDEX_OFFICE => [
[
'goods' => [
'id' => 4,
'cover_img' => config('alioss.img_host').'/attachment/types/c9b656181bbbc463624ca3803c5be7539f2fd62253f9a-cwVLri.png',
'name' => '【优质】大白菜11',
'spec' => [
['key' => '净含量', 'value' => '500g']
],
'tags' => ['限时', '折扣'],
'original_price' => 50.5,
'price' => 25.25,
'inventory' => 10,
'month_sales' => 20,
'total_sales' => 20,
'cart_num' => 0,
'is_effective' => 2,
'noneffective_note' => '已卖完',
],
'store' => ['id' => 4, 'logo' => '', 'name' => '我是一个商家444']
],
]
];
$goods = Goods::query()
->with(['store'])
->forPage($this->request->input('page', 1), $this->request->input('pagesize', 15))
->get()->toArray();
return $this->success(['tab_data' => $goods]);
return $this->success([
'tab_data' => $tabsData[$this->request->post('tab', 'applet_index_recommend')]
]);
}
/**

17
app/Controller/v3/HomeController.php

@ -14,6 +14,7 @@ use App\Service\v3\Interfaces\CategoryServiceInterface;
use App\Service\v3\Interfaces\CollectStoreServiceInterface;
use App\Service\v3\Interfaces\CouponServiceInterface;
use App\Service\v3\Interfaces\StoreInfoServiceInterface;
use App\Service\v3\Interfaces\TabsServiceInterface;
use App\Service\v3\Interfaces\UserCenterBlockServiceInterface;
use App\Service\v3\Interfaces\UserInfoServiceInterface;
use App\TaskWorker\SSDBTask;
@ -77,6 +78,12 @@ class HomeController extends BaseController
*/
protected $activityService;
/**
* @Inject
* @var TabsServiceInterface
*/
protected $tabsService;
/**
* 小程序首页,根据market_id
* 1.banner数据
@ -90,18 +97,14 @@ class HomeController extends BaseController
$marketId = $this->request->input('market_id', 0);
$banners = $this->bannerService->all(Banner::TYPE_APPLET_INDEX, $marketId);
$categories = $this->categoryService->allForAppletIndex();
$activity = $this->activityService->allForAppletIndex(ActivityType::FLASH_SALE, $marketId);
$activity = $this->activityService->allForAppletIndex(env('APPLET_INDEX_ACTIVITY_TYPE'), $marketId);
$tabs = $this->tabsService->allForAppletIndex();
return $this->success([
'banners' => $banners,
'categories' => $categories,
'activity' => ['type' => ActivityType::FLASH_SALE, 'goods' => $activity],
'tabs' => [
['tab' => Tabs::APPLET_INDEX_RECOMMEND, 'title' => '推荐', 'subtitle' => '猜你喜欢', 'badge' => '', 'bg_color' => '#FF0000', 'font_color' => '#FFFFFF'],
['tab' => Tabs::APPLET_INDEX_NEW, 'title' => '懒族上新', 'subtitle' => '买点不一样', 'badge' => '限时', 'bg_color' => '#FF0000', 'font_color' => '#FFFFFF'],
['tab' => Tabs::APPLET_INDEX_FRESH, 'title' => '实时鲜货', 'subtitle' => '今天辛苦了', 'badge' => '好新鲜', 'bg_color' => '#FF0000', 'font_color' => '#FFFFFF'],
['tab' => Tabs::APPLET_INDEX_OFFICE, 'title' => '上班带餐', 'subtitle' => '轻奢快手菜', 'badge' => '不慌', 'bg_color' => '#FF0000', 'font_color' => '#FFFFFF'],
]
'tabs' => $tabs,
]);
}

9
app/Controller/v3/UserController.php

@ -9,6 +9,7 @@ use App\Service\v3\Interfaces\UserBindTelServiceInterface;
use App\Service\v3\Interfaces\UserInfoServiceInterface;
use App\Service\v3\Interfaces\VerifyCodeServiceInterface;
use Hyperf\Di\Annotation\Inject;
use Psr\Http\Message\ResponseInterface;
/**
* 用户相关
@ -42,7 +43,7 @@ class UserController extends BaseController
* 2、校验用户和验证码
* 3、执行绑定
* @param UserBindTelRequest $request
* @return \Psr\Http\Message\ResponseInterface
* @return ResponseInterface
*/
public function bindTel(UserBindTelRequest $request)
{
@ -60,13 +61,13 @@ class UserController extends BaseController
* 更新用户信息,上传保存unionid等
* 1、wxlogin成功后,会有user_id,传上来,同时传一些其他的参数
* 2、更新用户数据,头像、昵称、unionid、国家、省份、城市、性别、语言等
* @param UserUpdateRequest $request
* @return ResponseInterface
*/
public function updateInfo(UserUpdateRequest $request)
{
$data = $request->validated();
$userId = $data['user_id'];
unset($data['user_id']);
$this->userInfoService->do($userId, $data);
$this->userInfoService->do($data['user_id'], $data['iv'], $data['encrypted_data']);
return $this->success([]);
}
}

6
app/Model/v3/Banner.php

@ -11,11 +11,15 @@ class Banner extends Model
use SoftDeletes;
protected $table = 'lanzu_banners';
protected $visible = [
'id', 'cover', 'cover_type', 'title', 'subtitle', 'path', 'path_type', 'bg_color'
];
protected function boot(): void
{
parent::boot();
self::addGlobalScope('normal', function (Builder $builder) {
return $builder->where(['status' => 1]);
return $builder->where(['status' => 1])->orderBy('sort', 'desc');
});
}
}

4
app/Model/v3/Goods.php

@ -55,6 +55,10 @@ class Goods extends Model
'noneffective_note',
];
protected $visible = [
'id', 'cover_img', 'name', 'original_price', 'price', 'inventory', 'store_id', 'sales as total_sales'
];
protected function boot(): void
{
parent::boot();

7
app/Model/v3/GoodsActivity.php

@ -39,6 +39,11 @@ class GoodsActivity extends Model
'total_seconds',
];
protected $visible = [
'id', 'cover_img', 'name', 'original_price', 'price', 'inventory', 'store_id', 'spec', 'tags', 'sales',
'month_sales', 'cart_num', 'is_effective', 'noneffective_note', 'total_seconds',
];
protected function boot(): void
{
parent::boot();
@ -75,6 +80,6 @@ class GoodsActivity extends Model
public function store()
{
return $this->belongsTo(Store::class, 'store_id', 'goods_id');
return $this->belongsTo(Store::class, 'store_id', 'id');
}
}

11
app/Request/v3/UserUpdateRequest.php

@ -16,15 +16,8 @@ class UserUpdateRequest extends BaseFormRequest
{
return [
'user_id' => 'required|nonempty',
'nick_name' => 'required|nonempty',
'avatar' => 'required|nonempty',
'openid' => 'required|nonempty',
'unionid' => 'required|nonempty',
'country' => 'string',
'province' => 'string',
'city' => 'string',
'gender' => 'string',
'language' => 'string',
'iv' => 'required|nonempty',
'encrypted_data' => 'required|nonempty'
];
}

7
app/Service/v3/Implementations/ActivityService.php

@ -27,13 +27,10 @@ class ActivityService implements ActivityServiceInterface
public function allForAppletIndex($type, $marketId)
{
$builder = GoodsActivity::query()
->select(['*'])
->with(['store'])
->where(['type' => $type])
->addSelect('sales as total_sales');
->whereIn('market_id', [0,$marketId]);
if ($marketId) {
$builder->where(['market_id' => $marketId]);
}
return $builder->get()->toArray();
}
}

3
app/Service/v3/Implementations/CategoryService.php

@ -2,6 +2,7 @@
namespace App\Service\v3\Implementations;
use App\Constants\v3\OssThumbnail;
use App\Constants\v3\SsdbKeys;
use App\Model\v3\Category;
use App\Model\v3\Goods;
@ -57,7 +58,7 @@ class CategoryService implements CategoryServiceInterface
$returnData = [];
foreach ($categories as $key => &$category) {
$value = json_decode($category, true);
$returnData[] = ['id' => $key, 'icon' => config('alioss.img_host').$value['icon'], 'name' => $value['name']];
$returnData[] = ['id' => $key, 'icon' => config('alioss.img_host').$value['icon'].OssThumbnail::THUMBNAIL_100_Q50, 'name' => $value['name']];
}
return $returnData;

35
app/Service/v3/Implementations/TabsService.php

@ -0,0 +1,35 @@
<?php
namespace App\Service\v3\Implementations;
use App\Constants\v3\Tabs;
use App\Service\v3\Interfaces\TabsServiceInterface;
class TabsService implements TabsServiceInterface
{
public function do()
{
// TODO: Implement do() method.
}
public function check()
{
// TODO: Implement check() method.
}
public function undo()
{
// TODO: Implement undo() method.
}
public function allForAppletIndex()
{
return [
['tab' => Tabs::APPLET_INDEX_RECOMMEND, 'title' => '推荐', 'subtitle' => '猜你喜欢', 'badge' => '', 'bg_color' => '#FF0000', 'font_color' => '#FFFFFF'],
['tab' => Tabs::APPLET_INDEX_NEW, 'title' => '懒族上新', 'subtitle' => '买点不一样', 'badge' => '限时', 'bg_color' => '#FF0000', 'font_color' => '#FFFFFF'],
['tab' => Tabs::APPLET_INDEX_FRESH, 'title' => '实时鲜货', 'subtitle' => '今天辛苦了', 'badge' => '好新鲜', 'bg_color' => '#FF0000', 'font_color' => '#FFFFFF'],
['tab' => Tabs::APPLET_INDEX_OFFICE, 'title' => '上班带餐', 'subtitle' => '轻奢快手菜', 'badge' => '不慌', 'bg_color' => '#FF0000', 'font_color' => '#FFFFFF'],
];
}
}

35
app/Service/v3/Implementations/UserInfoService.php

@ -3,9 +3,15 @@
namespace App\Service\v3\Implementations;
use App\Constants\v3\ErrorCode;
use App\Constants\v3\SsdbKeys;
use App\Exception\ErrorCodeException;
use App\Model\v3\User;
use App\Service\v3\Interfaces\UserInfoServiceInterface;
use App\TaskWorker\SSDBTask;
use EasyWeChat\Factory;
use EasyWeChat\Kernel\Exceptions\DecryptException;
use Hyperf\Guzzle\CoroutineHandler;
use Hyperf\Utils\ApplicationContext;
class UserInfoService implements UserInfoServiceInterface
{
@ -13,11 +19,34 @@ class UserInfoService implements UserInfoServiceInterface
/**
* 更新
* @param $userId
* @param $data
* @return int
* @param $iv
* @param $encryptedData
* @return array
* @throws DecryptException
*/
public function do($userId, $data)
public function do($userId, $iv, $encryptedData)
{
$ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
$user = $ssdb->exec('hgetall', SsdbKeys::USER_INFO.$userId);
// 微信登录
$config = config('applet');
$app = Factory::miniProgram($config);
$app['guzzle_handler'] = CoroutineHandler::class;
$decryptedData = $app->encryptor->decryptData($user['session_key'], $iv, $encryptedData);
$data = [
'nick_name' => $decryptedData['nickName'],
'avatar' => $decryptedData['avatarUrl'],
'openid' => $decryptedData['openId'],
'unionid' => $decryptedData['unionId'],
'country' => $decryptedData['country'],
'province' => $decryptedData['province'],
'city' => $decryptedData['city'],
'gender' => $decryptedData['gender'],
'language' => $decryptedData['nickName'],
];
$user = User::query()->find($userId);
$res = $user->fill($data)->save();

18
app/Service/v3/Implementations/WxLoginService.php

@ -3,10 +3,13 @@
namespace App\Service\v3\Implementations;
use App\Constants\v3\ErrorCode;
use App\Constants\v3\SsdbKeys;
use App\Exception\ErrorCodeException;
use App\Model\v3\User;
use App\TaskWorker\SSDBTask;
use EasyWeChat\Factory;
use Hyperf\Guzzle\CoroutineHandler;
use Hyperf\Utils\ApplicationContext;
class WxLoginService implements \App\Service\v3\Interfaces\WxLoginServiceInterface
{
@ -25,10 +28,21 @@ class WxLoginService implements \App\Service\v3\Interfaces\WxLoginServiceInterfa
}
// 更新或者插入用户数据
return User::query()->firstOrCreate(
$user = User::query()->firstOrCreate(
['openid' => $result['openid']],
['unionid' => $result['unionid']]
);
)->toArray();
$return = array_merge($user, $result);
$kvs = [];
foreach ($return as $k => $v) {
$kvs[] = $k;
$kvs[] = $v;
}
$ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
$ssdb->exec('multi_hset', SsdbKeys::USER_INFO.$user['id'], $kvs);
return $user;
}
public function check($userId)

11
app/Service/v3/Interfaces/TabsServiceInterface.php

@ -0,0 +1,11 @@
<?php
namespace App\Service\v3\Interfaces;
interface TabsServiceInterface
{
public function do();
public function check();
public function undo();
public function allForAppletIndex();
}

2
app/Service/v3/Interfaces/UserInfoServiceInterface.php

@ -4,7 +4,7 @@ namespace App\Service\v3\Interfaces;
interface UserInfoServiceInterface
{
public function do($userId, $data);
public function do($userId, $iv, $encryptedData);
public function check($userId);
public function undo($userId);
public function detail($userId);

1
config/autoload/dependencies.php

@ -58,4 +58,5 @@ return [
\App\Service\v3\Interfaces\StoreInfoServiceInterface::class => \App\Service\v3\Implementations\StoreInfoService::class,
\App\Service\v3\Interfaces\BannerServiceInterface::class => \App\Service\v3\Implementations\BannerService::class,
\App\Service\v3\Interfaces\ActivityServiceInterface::class => \App\Service\v3\Implementations\ActivityService::class,
\App\Service\v3\Interfaces\TabsServiceInterface::class => \App\Service\v3\Implementations\TabsService::class,
];
Loading…
Cancel
Save