feature/main20240421
lqmac 9 months ago
parent 4a5e8401b3
commit 60865a5da7
  1. 30
      app/admin/model/Store.php
  2. 21
      app/store/controller/Goods.php
  3. 1
      app/store/controller/store/Role.php
  4. 3
      app/store/model/store/Role.php

@ -20,6 +20,8 @@ use app\common\model\User as UserModel;
use think\facade\Db; use think\facade\Db;
use app\store\model\Category as CategoryModel; use app\store\model\Category as CategoryModel;
use app\common\model\UploadFile; use app\common\model\UploadFile;
use app\store\model\store\Role as RoleModel;
/** /**
* 商家记录表模型 * 商家记录表模型
* Class Store * Class Store
@ -69,11 +71,39 @@ class Store extends StoreModel
if ($user_id) { if ($user_id) {
(new StoreUserModel)->where(['store_id' => $this['store_id']])->save(['user_id' => $user_id]); (new StoreUserModel)->where(['store_id' => $this['store_id']])->save(['user_id' => $user_id]);
} }
//复制商品分类
$this->copyCategory((int)$this['store_id']); $this->copyCategory((int)$this['store_id']);
//多商户版本新增一个商户角色
if (isset($data['store_version']) && $data['store_version'] == 1) {
$this->addMerchantRoleAndMenu((int)$this['store_id']);
}
} }
return $status; return $status;
}); });
} }
/**
* 新增一个多商户角色,不能删除
* [addMerchantRoleAndMenu description]
* @param int $storeId [description]
*/
public function addMerchantRoleAndMenu(int $storeId){
$data = [
'role_name' => '商户',
'parent_id' => 0,
'sort' => 100,
'menus' => [
10034,10035,10204,10038,10036,10037,10141,10043,10044,10045,
10046,10047,10048,10049,10243,10244,10246,10245,10050,10051,
10052,10205,10054,10189,10055,10223,10139,10252,10056,10058,
10059,10057,10201,10238,10241,10239,10240,10242,10202,10203,
10206,10207,10208,10209,10213,10210,10211,10115
],
'store_id' => $storeId
];
$model = new RoleModel;
$model->add($data);
}
public function copyCategory(int $new_store_id){ public function copyCategory(int $new_store_id){
$store_id = 0; $store_id = 0;
$model = new CategoryModel; $model = new CategoryModel;

@ -171,7 +171,26 @@ class Goods extends Controller
} }
return $this->renderError($model->getError() ?: '更新失败'); return $this->renderError($model->getError() ?: '更新失败');
} }
/**
* 商品入池、出池
* @param array $goodsIds 商品id集
* @param bool $state 为true表示上架
* @return Json
*/
public function pool(array $goodsIds, bool $state): Json
{
$model = new GoodsModel;
//过滤其他渠道的商品,只能把自营商品加入商品池
$list = GoodsModel::whereIn('goods_id', $goodsIds)->where('channel','zy')->select();
if (!$list) {
return $this->renderError("没有需要加入商品池的自营商品");
}
$goodsIds = array_column($list, "goods_id");
if (!$model->setIsPool($goodsIds, $state)) {
return $this->renderError($model->getError() ?: '操作失败');
}
return $this->renderSuccess('操作成功');
}
/** /**
* 修改商品状态(上下架) * 修改商品状态(上下架)
* @param array $goodsIds 商品id集 * @param array $goodsIds 商品id集

@ -63,6 +63,7 @@ class Role extends Controller
{ {
// 角色详情 // 角色详情
$model = RoleModel::detail($roleId); $model = RoleModel::detail($roleId);
// 更新记录 // 更新记录
if ($model->edit($this->postForm())) { if ($model->edit($this->postForm())) {
return $this->renderSuccess('更新成功'); return $this->renderSuccess('更新成功');

@ -102,7 +102,10 @@ class Role extends RoleModel
} }
$this->transaction(function () use ($data) { $this->transaction(function () use ($data) {
// 新增角色记录 // 新增角色记录
if (!isset($data['store_id']) || !$data['store_id']) {
$data['store_id'] = self::$storeId; $data['store_id'] = self::$storeId;
}
$this->save($data); $this->save($data);
// 新增角色菜单关系记录 // 新增角色菜单关系记录
RoleMenuModel::increased((int)$this['role_id'], $data['menus']); RoleMenuModel::increased((int)$this['role_id'], $data['menus']);

Loading…
Cancel
Save