parent
4392d68c2d
commit
04751a6c8f
|
|
@ -6,6 +6,7 @@ use app\common\dao\BaseDao;
|
|||
use app\common\model\store\product\ProductCate;
|
||||
use app\common\model\store\product\Spu;
|
||||
use app\common\model\store\StoreCategory;
|
||||
use app\common\model\system\merchant\Merchant;
|
||||
use app\common\repositories\store\StoreCategoryRepository;
|
||||
use app\common\repositories\system\merchant\MerchantRepository;
|
||||
use crmeb\services\VicWordService;
|
||||
|
|
@ -51,6 +52,10 @@ class SpuDao extends BaseDao
|
|||
$order = '';
|
||||
}
|
||||
$query = Spu::getDB()->alias('S')->join('StoreProduct P','S.product_id = P.product_id', 'left');
|
||||
// 这里不显示供应商商品
|
||||
$supplierMerId = (array)Merchant::where('merchant_type', 2)->column('mer_id');
|
||||
$query->whereNotIn('S.mer_id', $supplierMerId);
|
||||
|
||||
$query->when(isset($where['is_del']) && $where['is_del'] !== '',function($query)use($where){
|
||||
$query->where('P.is_del',$where['is_del']);
|
||||
})
|
||||
|
|
|
|||
|
|
@ -0,0 +1,94 @@
|
|||
<?php
|
||||
|
||||
namespace app\common\middleware;
|
||||
|
||||
use app\common\repositories\user\UserRepository;
|
||||
use app\Request;
|
||||
use crmeb\exceptions\AuthException;
|
||||
use crmeb\services\JwtTokenService;
|
||||
use Firebase\JWT\ExpiredException;
|
||||
use think\exception\ValidateException;
|
||||
use think\Response;
|
||||
use Throwable;
|
||||
|
||||
class ShopTokenMiddleware extends BaseMiddleware{
|
||||
|
||||
|
||||
public function before(Request $request){
|
||||
$force = $this->getArg(0, true);
|
||||
try {
|
||||
$token = trim($request->header('X-Token'));
|
||||
|
||||
|
||||
|
||||
throw new ValidateException('请登录');
|
||||
|
||||
|
||||
if (strpos($token, 'Bearer') === 0) $token = trim(substr($token, 6));
|
||||
if (!$token) throw new ValidateException('请登录');
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @var UserRepository $repository
|
||||
*/
|
||||
$repository = app()->make(UserRepository::class);
|
||||
$service = new JwtTokenService();
|
||||
try {
|
||||
$payload = $service->parseToken($token);
|
||||
} catch (ExpiredException $e) {
|
||||
$repository->checkToken($token);
|
||||
$payload = $service->decode($token);
|
||||
} catch (Throwable $e) {//Token 过期
|
||||
throw new AuthException('token 已过期');
|
||||
}
|
||||
if ('user' != $payload->jti[1])
|
||||
throw new AuthException('无效的 token');
|
||||
|
||||
$user = $repository->get($payload->jti[0]);
|
||||
if (!$user)
|
||||
throw new AuthException('用户不存在');
|
||||
if (!$user['status'])
|
||||
throw new AuthException('用户已被禁用');
|
||||
if ($user['cancel_time'])
|
||||
throw new AuthException('用户不存在');
|
||||
|
||||
} catch (Throwable $e) {
|
||||
if ($force)
|
||||
throw $e;
|
||||
$request->macro('isLogin', function () {
|
||||
return false;
|
||||
});
|
||||
$request->macros(['tokenInfo', 'uid', 'userInfo', 'token'], function () {
|
||||
throw new AuthException('请登录');
|
||||
});
|
||||
return;
|
||||
}
|
||||
$repository->updateToken($token);
|
||||
|
||||
$request->macro('isLogin', function () {
|
||||
return true;
|
||||
});
|
||||
$request->macro('userType', function () {
|
||||
return 1;
|
||||
});
|
||||
$request->macro('tokenInfo', function () use (&$payload) {
|
||||
return $payload;
|
||||
});
|
||||
$request->macro('token', function () use (&$token) {
|
||||
return $token;
|
||||
});
|
||||
$request->macro('uid', function () use (&$user) {
|
||||
return $user->uid;
|
||||
});
|
||||
$request->macro('userInfo', function () use (&$user) {
|
||||
return $user;
|
||||
});
|
||||
}
|
||||
|
||||
public function after(Response $response){
|
||||
// TODO: Implement after() method.
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
namespace app\common\repositories\store\product;
|
||||
|
||||
use app\common\dao\store\product\ProductDao;
|
||||
use app\common\model\system\merchant\Merchant;
|
||||
use app\common\repositories\BaseRepository;
|
||||
|
||||
|
||||
class SupplierProductRepository extends BaseRepository{
|
||||
protected $dao;
|
||||
|
||||
public function __construct(ProductDao $dao){
|
||||
$this->dao = $dao;
|
||||
}
|
||||
/**
|
||||
* Common: 获取列表
|
||||
* Author: wu-hui
|
||||
* Time: 2024/02/28 15:48
|
||||
* @param $search
|
||||
* @param $page
|
||||
* @param $limit
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getList($search, $page, $limit){
|
||||
// 仅显示供应商商品
|
||||
$supplierMerId = (array)Merchant::where('merchant_type', 2)->column('mer_id');
|
||||
$query = $this->dao->getSearch([])
|
||||
->whereIn('mer_id', $supplierMerId)
|
||||
->where('delete', 0)
|
||||
->where('product_type', 0)
|
||||
->where('status', 1)
|
||||
->when(isset($search['store_name']) && $search['store_name'] !== '', function ($query) use ($search) {
|
||||
$query->whereLike('store_name', "%{$search['store_name']}%");
|
||||
});
|
||||
|
||||
$list = $query
|
||||
->field([
|
||||
'product_id',
|
||||
'mer_id',
|
||||
'store_name',
|
||||
'price',
|
||||
'unit_name',
|
||||
'is_batch',
|
||||
'batch_num',
|
||||
'batch_unit',
|
||||
'image'
|
||||
])
|
||||
->with([
|
||||
'attr' => function($query){
|
||||
$query->field(['product_id','attr_name','attr_values']);
|
||||
},
|
||||
'attrValue' => function($query){
|
||||
$query->field(['product_id','detail','image','price','sku','unique','value_id']);
|
||||
}
|
||||
])
|
||||
->order('sort desc,mer_id desc')
|
||||
->page($page, $limit)
|
||||
->select()
|
||||
->toArray();
|
||||
$count = $query->count();
|
||||
|
||||
return compact('count', 'list');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -188,13 +188,23 @@ class StoreServiceRepository extends BaseRepository
|
|||
}
|
||||
// 获取当前用户的员工信息
|
||||
public function getServices($uid, array $where = [],$is_sys = 1){
|
||||
$where['uid'] = $uid;
|
||||
// $where['uid'] = $uid;
|
||||
|
||||
$list = $this->dao->getSearch([])
|
||||
->hasWhere('merchant',function($query) use ($is_sys){
|
||||
$query->where('is_del', 0)->where('merchant_type', $is_sys == 2 ? 1 : 0);
|
||||
->when(isset($where['appoint_mer_id']) && $where['appoint_mer_id'] !== '',function($query) use ($where){
|
||||
// 存在指定商户ID
|
||||
$query->hasWhere('merchant',function($query){
|
||||
$query->where('is_del', 0);
|
||||
})->where('StoreService.mer_id', $where['appoint_mer_id'])
|
||||
->where('StoreService.is_manage', 1);
|
||||
},function($query) use ($is_sys, $uid){
|
||||
// 不存在指定商户id
|
||||
$query->hasWhere('merchant',function($query) use ($is_sys){
|
||||
$query->where('is_del', 0)->where('merchant_type', $is_sys == 2 ? 1 : 0);
|
||||
})->where('StoreService.mer_id',$is_sys == 1 ? '=' : '>',0)
|
||||
->where('StoreService.uid',$uid);
|
||||
})
|
||||
->where('StoreService.is_del',0)
|
||||
->where('StoreService.mer_id',$is_sys == 1 ? '=' : '>',0)
|
||||
->when(isset($where['is_verify']) && $where['is_verify'] !== '',function($query) use ($where){
|
||||
$query->where('StoreService.is_verify',$where['is_verify']);
|
||||
})
|
||||
|
|
|
|||
|
|
@ -209,6 +209,7 @@ class MerchantAdminRepository extends BaseRepository
|
|||
if (!$merchant['status'])
|
||||
throw new ValidateException('商户已被锁定');
|
||||
|
||||
$adminInfo->merchant_type = $merchant->merchant_type ?? 0;
|
||||
$adminInfo->last_time = date('Y-m-d H:i:s');
|
||||
$adminInfo->last_ip = app('request')->ip();
|
||||
$adminInfo->login_count++;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace app\controller\api;
|
||||
|
||||
|
||||
use app\common\repositories\store\product\SupplierProductRepository;
|
||||
use app\services\supplier\SystemSupplierApplyServices;
|
||||
use app\services\supplier\SystemSupplierServices;
|
||||
use crmeb\basic\BaseController;
|
||||
|
|
@ -131,6 +131,28 @@ class Supplier extends BaseController{
|
|||
|
||||
return app('json')->success($data);
|
||||
}
|
||||
/**
|
||||
* Common: 获取全部供应商商品
|
||||
* Author: wu-hui
|
||||
* Time: 2024/02/28 15:50
|
||||
* @return mixed
|
||||
*/
|
||||
public function goodsList(){
|
||||
// 参数获取
|
||||
$search = $this->request->params(['store_name']);
|
||||
[$page, $limit] = $this->getPage();
|
||||
$data = app()->make(SupplierProductRepository::class)->getList($search, $page, $limit);
|
||||
// 循环处理列表数据
|
||||
$data['list'] = array_map(function($item){
|
||||
if(count($item['attrValue']) > 1) $item['attrValue'] = array_column($item['attrValue'],null,'sku');
|
||||
|
||||
return $item;
|
||||
},$data['list']);
|
||||
|
||||
return app('json')->success($data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -5,11 +5,14 @@
|
|||
namespace app\controller\api\store\merchant;
|
||||
|
||||
use app\common\repositories\store\service\StoreServiceRepository;
|
||||
use app\common\repositories\system\merchant\MerchantAdminRepository;
|
||||
use app\common\repositories\user\UserMerchantRepository;
|
||||
use crmeb\services\QrcodeService;
|
||||
use think\App;
|
||||
use crmeb\basic\BaseController;
|
||||
use app\common\repositories\system\merchant\MerchantRepository as repository;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Cache;
|
||||
|
||||
class Merchant extends BaseController
|
||||
{
|
||||
|
|
@ -147,7 +150,36 @@ class Merchant extends BaseController
|
|||
|
||||
return app('json')->fail('小程序码生成失败!');
|
||||
}
|
||||
|
||||
/**
|
||||
* Common: 商户登录移动端
|
||||
* Author: wu-hui
|
||||
* Time: 2024/02/28 17:30
|
||||
* @return mixed
|
||||
*/
|
||||
public function storeLogin(){
|
||||
// 参数获取
|
||||
$params = $this->request->params(['account','password']);
|
||||
if(empty($params['account'])) throw new ValidateException('请输入账号');
|
||||
if(empty($params['password'])) throw new ValidateException('请输入密码');
|
||||
// 判断登录是否成功
|
||||
$repository = app()->make(MerchantAdminRepository::class);
|
||||
$adminInfo = $repository->login($params['account'], $params['password']);
|
||||
$tokenInfo = $repository->createToken($adminInfo);
|
||||
$admin = $adminInfo->toArray();
|
||||
// 判断:这里仅允许酒道馆和普通商户登录
|
||||
if($admin['merchant_type'] == 2) throw new ValidateException('当前账号禁止登录!');
|
||||
// unset($admin['pwd']);
|
||||
// $data = [
|
||||
// 'token' => $tokenInfo['token'],
|
||||
// 'exp' => $tokenInfo['out'],
|
||||
// 'admin' => $admin
|
||||
// ];
|
||||
return app('json')->success([
|
||||
'token' => $tokenInfo['token'],
|
||||
'exp' => $tokenInfo['out'],
|
||||
'mer_id' => $admin['mer_id']
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -526,7 +526,7 @@ class User extends BaseController
|
|||
public function services()
|
||||
{
|
||||
$uid = $this->user->uid;
|
||||
$where = $this->request->params(['is_verify', 'customer', 'is_goods', ['is_open',1]]);
|
||||
$where = $this->request->params(['is_verify', 'customer', 'is_goods', ['is_open',1],'appoint_mer_id']);
|
||||
$is_sys = $this->request->param('is_sys');
|
||||
$list = app()->make(StoreServiceRepository::class)->getServices($uid, $where,$is_sys);
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
use app\common\middleware\AllowOriginMiddleware;
|
||||
use app\common\middleware\CheckSiteOpenMiddleware;
|
||||
use app\common\middleware\InstallMiddleware;
|
||||
use app\common\middleware\ShopTokenMiddleware;
|
||||
use app\common\middleware\UserTokenMiddleware;
|
||||
use app\common\middleware\VisitProductMiddleware;
|
||||
use app\common\middleware\RequestLockMiddleware;
|
||||
|
|
@ -406,8 +407,13 @@ Route::group('api/', function () {
|
|||
Route::post('apply_record', 'applyRecord');// 申请记录
|
||||
Route::get('apply_info', 'applyInfo');// 申请信息详情
|
||||
})->prefix('api.Supplier/');
|
||||
// 需要酒道馆登录的接口
|
||||
Route::group('supplier',function(){
|
||||
// 进货相关
|
||||
Route::get('goods_list','goodsList');// 供应商全部商品
|
||||
|
||||
|
||||
})->prefix('api.Supplier/')->middleware(ShopTokenMiddleware::class,TRUE);
|
||||
})->middleware(UserTokenMiddleware::class, true);
|
||||
//非强制登录
|
||||
Route::group(function () {
|
||||
|
|
@ -546,6 +552,9 @@ Route::group('api/', function () {
|
|||
Route::get('/detail/:id', 'Merchant/detail');
|
||||
Route::get('/qrcode/:id', 'Merchant/qrcode');
|
||||
Route::get('/local', 'Merchant/localLst');
|
||||
// 酒道馆登录相关
|
||||
Route::get('/login', 'Merchant/storeLogin');
|
||||
|
||||
})->prefix('api.store.merchant.');
|
||||
Route::post('store/certificate/:merId', 'api.Auth/getMerCertificate');
|
||||
|
||||
|
|
@ -611,6 +620,16 @@ Route::group('api/', function () {
|
|||
})->prefix('api.Diy');
|
||||
|
||||
})->middleware(UserTokenMiddleware::class, false);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//微信支付回调
|
||||
Route::any('notice/wechat_pay', 'api.Common/wechatNotify')->name('wechatNotify');
|
||||
//微信支付回调
|
||||
|
|
|
|||
Loading…
Reference in New Issue