AppManageModel.php
5.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<?php
// +----------------------------------------------------------------------
// | 狂团[kt8.cn]旗下KtAdmin是为独立版SAAS系统而生的快速开发框架.
// +----------------------------------------------------------------------
// | [KtAdmin] Copyright (c) 2022 http://ktadmin.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
namespace app\base\model\admin\market;
use think\facade\Db;
use think\facade\Session;
use app\base\model\BaseModel;
use think\facade\Cache;
/*
* 应用管理
*/
class AppManageModel extends BaseModel
{
/**
* 获取 应用列表
* @return
*/
public static function list($req)
{
// $page = $req->post('page',1);
// $size = $req->post('size',10);
$name = $req->post('name');
$appType = $req->post('app_type');
$installType = $req->post('install_type');
$where = [];
if($name) $where[] = ['name','like',"%{$name}%"];
if($appType) $where[] = ['app_type','=',$appType];
if($installType) $where[] = ['install_type','=',$installType];
// $data['page'] = $page;
// $data['size'] = $size;
$res = Db::table('kt_base_market_app')->field('logo,code,name,app_type,describe,install_type,author,version,c_time')->where('app_type','<',3);
if($where) $res->where($where);
// $data['count'] = $res->count();
// $data['item'] = $res->page($page,$size)->select();
return $res->select();
}
/**
* 删除 应用
* @return
*/
public static function delete($req)
{
$id = $req->post('id');
$app = Db::table('kt_base_market_app')->find($id);
if(!$app) return error('应用不存在');
$res = Db::table('kt_base_market_app')->delete($id);
if($res) return success('删除成功');
return error('删除失败');
}
/**
* 应用信息
*/
public static function appInfo($code)
{
$uid = Session::get("uid");
$info = Db::table("kt_base_market_app")->where(["code"=>$code,'uid'=>$uid])->json(['specs',"label"])->find();
//初始化数据
if(!$info){
$app = self::getMainfestByName($code);
if(!$app) return null;
$data = [
'uid' => $uid,
'code' => $code,
'name' => $app['name'],
'logo' => $app['logo'],
'sort' => 0,
'recom' => 0,
'try_days' => 7,
'scene' => $app['description'] ?? '',
'version' => $app['version'] ?? '',
'user_link' => $app['userindex'] ?? '',
'admin_link' => $app['adminindex'] ?? '',
'describe' => $app['description'] ?? '',
'c_time' => date('Y-m-d H:i:s'),
];
$nameArr = explode('_', $code);
if($app['type'] == 2 && in_array('plugin', $nameArr)){
$key = array_keys($nameArr,'plugin');
$panmeArr = array_slice($nameArr, 0,$key);
$pname = implode('_', $panmeArr);
$data['pid'] = Db::table("kt_base_market_app")->where(["code"=>$pname,'uid'=>$uid])->value('id') ?: 0;
}
$id = Db::table("kt_base_market_app")->insertGetId($data);
$info = Db::table("kt_base_market_app")->find($id);
}
if(isset($info['specs'])){
foreach ($info["specs"] as $key=>$value){
if(is_int($info["specs"][$key]["duration_type"]))$info["specs"][$key]["duration_type"] = (string)$info["specs"][$key]["duration_type"];
}
}
return $info;
}
/**
* 设置应用信息
*/
public static function setApp($args)
{
$uid = Session::get("uid");
$args['uid'] = $uid;
$info = Db::table("kt_base_market_app")->where(["code"=>$args['code'],'uid'=>$uid])->find();
if($info){
$args['u_time'] = date('Y-m-d H:i:s');
$res = Db::table("kt_base_market_app")->where(["code"=>$args['code'],'uid'=>$uid])->json(['specs',"label"])->update($args);
}else{
$args['c_time'] = date('Y-m-d H:i:s');
$res = Db::table("kt_base_market_app")->json(['specs',"label"])->insert($args);
}
return $res;
}
/**
* 分类列表
*/
public static function types($page=1,$size=10)
{
$uid = Session::get("uid");
$res = Db::table('kt_base_market_type')->where(['uid'=>$uid]);
$data['count'] = $res->count();
$data['item'] = $res->page($page,$size)->select();
$data['page'] = $page;
$data['size'] = $size;
return $data;
}
/**
* 分类信息
*/
public static function typeInfo($id)
{
$uid = Session::get("uid");
$info = Db::table("kt_base_market_type")->where(['id'=>$id])->find();
return $info;
}
/**
* 添加分类
*/
public static function addType($args)
{
$uid = Session::get("uid");
$args['uid'] = $uid;
$args['c_time'] = date('Y-m-d H:i:s');
$info = Db::table("kt_base_market_type")->where(['name'=>$args['name'],'level'=>1])->find();
if($info) return '分类名称已存在';
$res = Db::table("kt_base_market_type")->insert($args);
return 'ok';
}
/**
* 修改分类
*/
public static function editType($id,$args)
{
$uid = Session::get("uid");
$args['uid'] = $uid;
$args['u_time'] = date('Y-m-d H:i:s');
$info = Db::table("kt_base_market_type")->find($id);
if($info['name'] != $args['name']){
$checkname = Db::table("kt_base_market_type")->where(['name'=>$args['name'],'level'=>1])->find();
if($checkname) return ['status'=>'error','msg'=>'分类名称已存在'];
}
$res = Db::table("kt_base_market_type")->where(['id'=>$id])->update($args);
return $res;
}
/**
* 删除分类
*/
public static function delType($id)
{
$app = Db::table("kt_base_market_app")->where(["type"=>$id])->find();
if($app) return ['status'=>'error','msg'=>'删除失败'];
$res = Db::table("kt_base_market_type")->where(['id'=>$id])->delete();
return $res;
}
}