店铺类型页所有bug修复

This commit is contained in:
liuxiaoquan 2023-03-15 10:39:38 +08:00
parent 5ca21a7e11
commit 67d225cb9e
4 changed files with 57 additions and 19 deletions

View File

@ -59,6 +59,7 @@ class MerchantType extends BaseController
// 进入编辑页,显示店铺数据
$detail = $this->merchant->Find($id);
View::assign('id', $id);
}
if (empty($detail)) {
$detail = [
@ -77,21 +78,26 @@ class MerchantType extends BaseController
// 查出商户所有菜单数据权限 tree
$data = $menu->getList([],1);
// 获取已有权限
$checked_list = $this->merchant->getList(['mer_type_id'=>$id]);
$checked_list = [];
if (!empty($id) && $id>0) {
// 获取已有菜单权限
$checked_list = $this->merchant->getList(['mer_type_id'=>$id]);
// 给菜单权限附加选中状态
foreach($data['list'] as $k=>$item) {
foreach ($checked_list['list'] as $auth) {
if (in_array($item['id'], $auth['auth_ids'])) {
if ($item['pid']>0 && $item['title']!='权限')
// 给菜单权限附加选中状态
foreach($data['list'] as $k=>$item) {
foreach ($checked_list['list'] as $auth) {
if (in_array($item['id'], $auth['auth_ids'])) {
$data['list'][$k]['checked'] = true;
$data['list'][$k]['spread'] = true;
}
}
}
}
View::assign('dataTree', $format->FormatCategory($data['list']));
// 递归分类, 顺便去掉所有父节点的 checked
$treelist = $format->FormatCategory($data['list']);
View::assign('dataTree', $treelist);
View::assign('detail', $detail);
$path = empty($id)?'add':'edit';
@ -111,7 +117,7 @@ class MerchantType extends BaseController
$limit = empty($param['limit']) ? 10 : (int)$param['limit'];
$data = $this->merchant->getList([], $page, $limit);
return to_assign(0, '', $data);
}
@ -173,6 +179,7 @@ class MerchantType extends BaseController
}
}
}
$format = app()->make(FormatList::class);
View::assign('dataTree', $format->FormatCategory($list));
View::assign('detail', $detail);
@ -239,9 +246,9 @@ class MerchantType extends BaseController
return to_assign(1, '数据不存在');
}
$rows = $this->merchant->Del($id);
$res = $this->merchant->Del($id);
return $rows>0?to_assign(0, '操作成功'):to_assign(1, '操作失败');
return $res['code']==0?to_assign(0, '操作成功'):to_assign(1, $res['msg']);
}

View File

@ -38,6 +38,14 @@ class FormatList
foreach ($items as $item) {
if (isset($items[$item[$parentId]])) {
$items[$item[$parentId]][$childrenKey][] = &$items[$item[$idName]];
//--begin-
//因前端js Tree组件待性父节点checked其所属子孙节点会全部为checked状态, 所以此处去除所有父节点的checked
if (isset($items[$item[$parentId]]['checked'])&& $items[$item[$parentId]]['checked']) {
$items[$item[$parentId]]['checked'] = false;
}
//--end--
} else if ($item[$parentId] == 0) {
$result[] = &$items[$item[$idName]];
}

View File

@ -94,6 +94,14 @@ class Merchant extends Model
});
}
/**
* 清除店铺类型
*/
public function clearTypeId(int $typeId)
{
return Merchant::where('type_id', $typeId)->update(['type_id' => 0]);
}
/**
* 扣除保证金
*@param array $data [mer_id] => 75

View File

@ -215,15 +215,30 @@ class MerchantType extends Model
return 0;
}
// return Db::transaction(function () use ($id) {
// $this->dao->delete($id);
// app()->make(Merchant::class)->clearTypeId($id);
// app()->make(Relevance::class)->batchDelete($id, Relevance::TYPE_MERCHANT_AUTH);
// });
Db::startTrans();
try{
$b1 = MerchantType::where($this->getPk(), $id)->delete();
$b2 = app()->make(Merchant::class)->clearTypeId($id);
$b3 = app()->make(Relevance::class)->batchDelete($id, Relevance::TYPE_MERCHANT_AUTH);
if (empty($b1)) {
Db::rollback();
throw new DbException('删除店铺类型失败');
}else if($b2){
Db::rollback();
throw new DbException('清除商户店铺类型失败');
}else if($b3){
Db::rollback();
throw new DbException('删除店铺权限失败');
}else{
Db::commit();
}
$msg = ['code'=>0, 'msg'=>'success'];
}catch(DbException $e){
Db::rollback();
$msg = ['code'=>1, 'msg'=>$e->getMessage()];
}
$rows = self::where('mer_type_id', $id)->delete();
return $rows;
return $msg;
}
/**