Department.php
3.3 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
<?php
namespace app\products\controller;
use app\web\controller\BaseController;
use think\Db;
use think\Request;
use util\MCurl;
use think\Cookie;
use think\Session;
use app\common\model\products\department as departmentModel;
header("Content-type: text/html; charset=utf-8");
header('Access-Control-Allow-Origin:*');
header('Content-Type: application/json; charset=utf-8');
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
/**
* 功能描述 妇记通获客
* Class Product
* @package app\FuJiTong\controller
* Date: 2021/5/6
* Time: 10:00
* @author nyq
*/
class Department extends BaseController
{
/**
* Notes:函数功能描述 获取部门列表
* User: 张佳
* DateTime: 2021/6/9 18:00
*/
public function department_list(Request $request)
{
$data = $request->param();
$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
$offset=($page-1)*$rows;
$data['offset']=$offset;
$data['rows']=$rows;
$where=[];
if(!empty($data['result'])){
$where['departmentName']=['like', '%' . $data['result'] . '%'];
}
//$org_id = session('organization.org_id');
$list= Db::table('sos_user_department')->alias('d')->join("sos_user_mechanism m", "m.id=d.mechanismId")->field('d.id,d.departmentName,d.createTime,mechanismName')->where($where)->limit($offset,$rows)->select()->toArray();
$total= Db::table('sos_user_department')->where($where)->count();
foreach($list as $key=>$val ){
$list[$key]['createTime']=$val['createTime'] == ''? '' : date('Y-m-d H:i:s',$val['createTime']);
}
$result["total"] =$total;
$result['rows']=$list;
echo json_encode($result);
}
/**
* Notes:函数功能描述 新增部门
* User: 张佳
* DateTime: 2021/6/10 10:55
*/
public function department_add(Request $request)
{
$data = $request->param();
if(isset($data['id'])){
$info = [
'mechanismId'=>$data['mechanism'],
'departmentName'=>$data['name'],
];
$res = Db::table('sos_user_department')->where(['id'=>$data['id']])->update($info);
if($res){
return json(['code'=>200,'msg'=>'修改部门成功']);
}else{
return json(['code'=>100,'msg'=>'修改部门失败']);
}
}
$info = [
'mechanismId'=>$data['mechanism'],
'departmentName'=>$data['name'],
'createTime'=>time()
];
$res = Db::table('sos_user_department')->insert($info);
if($res){
return json(['code'=>200,'msg'=>'新增部门成功']);
}else{
return json(['code'=>100,'msg'=>'新增部门失败']);
}
}
/**
* Notes:函数功能描述 获取部门详情
* User: 张佳
* DateTime: 2021/6/10 11:07
*/
public function getDepartment(Request $request)
{
$data = $request->param();
$res = Db::table('sos_user_department')->where(['id'=>$data['id']])->find();
return $res;
}
}