<?php
|
|
namespace app\admin\model;
|
|
use app\common\model\admin\Application as ApplicationModel;
|
use app\admin\model\Access as AccessModel;
|
use app\common\model\admin\RoleAccess as RoleAccess;
|
/**
|
* 应用表模型
|
*/
|
class Application extends ApplicationModel
|
{
|
/**
|
* 获取应用表数据
|
*/
|
public static function getAll()
|
{
|
$model = new static;
|
$list = $model->where('is_delete', '=', 0)->select();
|
// 查询分类下的应用
|
foreach ($list as $category){
|
$category['children'] = AccessModel::getListByPlusCategoryId($category['plus_category_id']);
|
}
|
return $list;
|
}
|
|
|
/**
|
* 软删除
|
*/
|
public function delete_category()
|
{
|
return $this->save(['category_id' => 0]);
|
}
|
public function add($data)
|
{
|
$this->startTrans();
|
try {
|
$arr = [
|
'category_id' => $data['category_id'],
|
'app_icon' => $data['app_icon'],
|
'app_name' => $data['app_name'],
|
'app_use' => $data['app_use'],
|
'admin_money' => $data['admin_money'],
|
'supplier_money' => $data['supplier_money'],
|
'shop' => $data['shop'],
|
];
|
$res = self::create($arr);
|
$arr1 = [];
|
foreach ($data['access_id'] as $val) {
|
$arr1[] = [
|
'role_id' => $res['id'],
|
'access_id' => $val,
|
'app_id' => self::$app_id
|
];
|
}
|
$model = new RoleAccess();
|
$model->saveAll($arr1);
|
// 事务提交
|
$this->commit();
|
return true;
|
} catch (\Exception $e) {
|
$this->error = $e->getMessage();
|
$this->rollback();
|
return false;
|
}
|
}
|
|
/**
|
* 软删除
|
*/
|
public function setDelete()
|
{
|
return $this->save(['is_delete' => 1]);
|
}
|
|
/**
|
* 编辑
|
* @param $data
|
* @return bool
|
*/
|
public function edit($data)
|
{
|
$this->startTrans();
|
try {
|
$this->save([
|
'category_id' => $data['category_id'],
|
'app_icon' => $data['app_icon'],
|
'app_name' => $data['app_name'],
|
'app_use' => $data['app_use'],
|
'admin_money' => $data['admin_money'],
|
'supplier_money' => $data['supplier_money'],
|
'shop' => $data['shop'],
|
]);
|
if (!isset($data['access_id'])) {
|
$this->commit();
|
return true;
|
}
|
|
$access_list = [];
|
$access_model = new RoleAccess();
|
$access_model->where(['role_id' => $data['id']])->delete();
|
|
foreach ($data['access_id'] as $val) {
|
$access_list[] = [
|
'role_id' => $data['id'],
|
'access_id' => $val,
|
'app_id' => self::$app_id
|
];
|
}
|
|
$access_model->saveAll($access_list);
|
// 事务提交
|
$this->commit();
|
return true;
|
} catch (\Exception $e) {
|
$this->error = $e->getMessage();
|
$this->rollback();
|
return false;
|
}
|
}
|
|
/**
|
* 获取所有插件
|
*/
|
public static function getAllPlus(){
|
$model = new static();
|
return $model->where('is_delete', '=', 0)
|
->where('category_id', '=', 0)
|
->select();
|
}
|
|
/**
|
* 新增应用
|
*/
|
public function addApplication($data)
|
{
|
$model = new self();
|
return $model->where('id', '=', $data['id'])->save(
|
[
|
'category_id' => $data['category_id'],
|
'is_delete' => 0
|
]
|
);
|
}
|
}
|