lqmac 8 months ago
parent 45ff01a8b5
commit 694b59eec6
  1. 44
      app/admin/controller/Controller.php
  2. 10
      app/admin/controller/Goods.php
  3. 26
      app/admin/controller/Store.php
  4. 2
      app/admin/controller/goods/Import.php
  5. 1
      app/admin/service/admin/User.php
  6. 9
      app/common/model/Goods.php
  7. 2
      app/job/service/goods/Collector.php
  8. 6
      app/store/model/goods/Import.php

@ -15,6 +15,7 @@ namespace app\admin\controller;
use cores\BaseController;
use app\admin\service\admin\User as AdminUserService;
use cores\exception\BaseException;
use app\common\model\Channel;
/**
* 超管后台控制器基类
@ -67,7 +68,48 @@ class Controller extends BaseController
// 强制验证当前访问的控制器方法method
$this->checkMethodRules();
}
/**
* 获取当前用户的数据平台权限
* [getUserPlatform description]
* @return [type] [description]
*/
public function getUserPlatform(){
if ($this->admin['user']['role'] == 1) {
//京东账号可以看到京东和自营的
if ($this->admin['user']['channel'] == 'jd') {
$list = Channel::where('status', 1)->whereIn('code',['jd','zy'])->select();
//苏宁账号可以看到苏宁和自营的
} elseif($this->admin['user']['channel'] == 'sn'){
$list = Channel::where('status', 1)->whereIn('code',['sn','zy'])->select();
//新阙通信账号可以看到新阙通信和自营的
} elseif($this->admin['user']['channel'] == 'xqtx'){
$list = Channel::where('status', 1)->whereIn('code',['xqtx','zy'])->select();
//其他账号供应商只能看到自己的
} else {
$list = Channel::where('status', 1)->whereIn('code',[$this->admin['user']['channel']])->select();
}
} else {
//超级管理员看到所有的
$list = Channel::where('status', 1)->select();
}
return $list;
}
/**
* 获取用户添加和导入数据时的platform
* [getUserAddPlatform description]
* @return [type] [description]
*/
public function getUserAddPlatform(){
if ($this->admin['user']['role'] == 1) {
if (in_array($this->admin['user']['channel'], ['jd','sn','xqtx'])) {
return 'zy';
} else {
return $this->admin['user']['channel'];
}
} else {
return 'zy';
}
}
/**
* 设置管理员登录信息
*/

@ -45,7 +45,9 @@ class Goods extends Controller
$model = new GoodsModel;
$params = $this->request->param();
$params['store_id'] = 0;
$params['role'] = $this->admin['user']['role'];
//$params['role'] = $this->admin['user']['role'];
$platform = $this->getUserPlatform();
$params['channels'] = $platform ? array_column($platform->toArray(), "code") : [];
$list= $model->getAdminList($params, $pageSize);
return $this->renderSuccess(compact('list'));
}
@ -108,7 +110,9 @@ class Goods extends Controller
public function add(): Json
{
$model = new GoodsModel;
if ($model->add($this->postForm())) {
$params = $this->postForm();
$params['channel'] = $this->getUserAddPlatform();
if ($model->add($params)) {
return $this->renderSuccess('添加成功');
}
return $this->renderError($model->getError() ?: '添加失败');
@ -179,7 +183,7 @@ class Goods extends Controller
foreach ($goodsIds as $key => $goodsId) {
\app\store\model\GoodsCategoryRel::updates($goodsId, $categoryIds);
}
$model->whereIn('goods_id', $goodsIds)->update(['cate_status'=>1]);
return $this->renderSuccess('操作成功');
}
/**

@ -162,13 +162,25 @@ class Store extends Controller
*/
public function platformList(): Json
{
if ($this->admin['user']['role'] == 1) {
$list = Channel::where('status', 1)->whereIn('code',['jd','sn','zy'])->select();
} else {
$list = Channel::where('status', 1)->select();
}
// if ($this->admin['user']['role'] == 1) {
// //京东账号可以看到京东和自营的
// if ($this->admin['user']['channel'] == 'jd') {
// $list = Channel::where('status', 1)->whereIn('code',['jd','zy'])->select();
// //苏宁账号可以看到苏宁和自营的
// } elseif($this->admin['user']['channel'] == 'sn'){
// $list = Channel::where('status', 1)->whereIn('code',['sn','zy'])->select();
// //新阙通信账号可以看到新阙通信和自营的
// } elseif($this->admin['user']['channel'] == 'xqtx'){
// $list = Channel::where('status', 1)->whereIn('code',['xqtx','zy'])->select();
// //其他账号供应商只能看到自己的
// } else {
// $list = Channel::where('status', 1)->whereIn('code',[$this->admin['user']['channel']])->select();
// }
// } else {
// //超级管理员看到所有的
// $list = Channel::where('status', 1)->select();
// }
$list = $this->getUserPlatform();
$platformList = [];
foreach ($list as $key => $value) {
$platformList[$value['code']] = $value['name'];

@ -34,6 +34,8 @@ class Import extends Controller
$params = $this->request->param();
$params['store_id'] = 0;
$model = new ImportModel;
$platform = $this->getUserPlatform();
$params['channels'] = $platform ? array_column($platform->toArray(), "code") : [];
$list = $model->getList($params);
return $this->renderSuccess(compact('list'));
}

@ -51,6 +51,7 @@ class User extends BaseService
'admin_user_id' => (int)$userInfo['admin_user_id'],
'user_name' => $userInfo['user_name'],
'role' => $userInfo['role'],
'channel' => $userInfo['channel'],
],
'is_login' => true,
], 86400 * 7);

@ -445,14 +445,17 @@ class Goods extends BaseModel
if (isset($param['is_in_store']) && $param['is_in_store'] !== '') {
$filter[] = ['is_in_store', '=', $params['is_in_store']];
}
if (isset($param['role']) && $param['role'] == 1) {
$filter[] = ['channel', 'in', ['jd', 'sn', 'zy']];
}
if (isset($param['store_id']) && $param['store_id'] !== '') {
$filter[] = ['goods.store_id', '=', $params['store_id']];
}
//不同的渠道查看不同的数据
if (isset($param['channel']) && $param['channel'] !== '') {
$filter[] = ['goods.channel', '=', $params['channel']];
} else {
if (isset($param['channels']) && $param['channels']) {
$filter[] = ['goods.channel', 'in', $param['channels']];
}
}
if (isset($param['is_grab']) && $param['is_grab'] !== '') {
$filter[] = ['goods.is_grab', '=', intval($params['is_grab'])];

@ -292,7 +292,7 @@ class Collector extends BaseService
//sku
$goodsSku['stock_num'] = $form['stock_total'];
unset($goodsSku['goods_price']);
//unset($goodsSku['goods_price']);
}
// var_dump($data);
// var_dump($goodsSku);

@ -39,7 +39,11 @@ class Import extends ImportModel
*/
public function getList(array $param = []): \think\Paginator
{
return $this->where($this->getFilter($param))
$where = $this->getFilter($param);
if (isset($param['channels']) && $param['channels']) {
$where[] = ['channel', 'in', $param['channels']];
}
return $this->where($where)
->where('is_delete', '=', 0)
->order(['create_time' => 'desc', $this->getPk()])
->paginate();

Loading…
Cancel
Save