2db47680
hexiaodong
chore: 初始提交 php 遗...
|
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
|
<?php
namespace addons\antis\controller;
use addons\antis\model\ExamineRecord;
use addons\antis\model\Consume as ConsumeModel;
use addons\antis\model\Message;
use addons\antis\model\File;
use addons\antis\model\Staff;
use think\Db;
use think\Exception;
/**
* 费用接口
*/
class Consume extends StaffApi
{
protected $noNeedLogin = [];
protected $noNeedRight = [];
//添加费用
public function addConsume()
{
$params = $this->request->post();
// 表单验证
if (($result = $this->qingdongValidate($params, get_class(), 'create')) !== true) {
$this->error($result);
}
Db::startTrans();
try {
$result = ConsumeModel::createConsume($params);
Db::commit();
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($result) {
$this->success('添加费用成功');
}
}
//编辑费用
public function editConsume()
{
$params = $this->request->post();
// 表单验证
if (($result = $this->qingdongValidate($params, get_class(), 'create')) !== true) {
$this->error($result);
}
Db::startTrans();
try {
$result = ConsumeModel::updateConsume($params);
Db::commit();
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($result) {
$this->success('添加费用成功');
}
}
//获取费用列表
public function getList()
{
$limit = input("limit/d", 10);
$customer_id = input('customer_id', '', 'intval');
$times = input('times', '');
$status = input('check_status',0);
$where = [];
$params = $this->request->post();
if ($times) {//
$times = explode(',', $times);
$where['createtime'] = ['between', [strtotime($times[0]), strtotime($times[1]) + 86400 - 1]];
}
if (isset($params['staff_id']) && $params['staff_id']) {//下级员工筛选
$where['staff_id'] = $params['staff_id'];
} else {
$where['staff_id'] = ['in', Staff::getMyStaffIds()];
if (isset($params['type']) && $params['type']) {//客户分类
if ($params['type'] == 1) {//我的客户
$where['staff_id'] = $this->auth->id;
} elseif ($params['type'] == 2) {//下属负责的客户
$where['staff_id'] = ['in', Staff::getLowerStaffId()];
}
}
}
if ($status) {
if($status == 1){//待审核
$where['check_status']=['in',[0,1]];
}elseif($status == 2){//通过
$where['check_status']=2;
}elseif($status == 3){//审核拒绝
$where['contract_status']=['in',[3,4]];
}
}
if($customer_id){
$where['customer_id'] = $customer_id;
}
$records = ConsumeModel::where($where)->with(['staff','customer'])->order('id desc')->paginate($limit)->toArray();
$remoney = ConsumeModel::where(['staff_id'=>$where['staff_id']])
->where(array('check_status'=>2))->sum('money');
$inmoney = ConsumeModel::where(['staff_id'=>$where['staff_id']])
->where(array('check_status'=>['in',[0,1]]))->sum('money');
$nomoney = ConsumeModel::where(['staff_id'=>$where['staff_id']])
->where(array('check_status'=>['in',[3,4]]))->sum('money');
$moneyinfo['remoney'] = $remoney;//已回款
$moneyinfo['inmoney'] = $inmoney;//回款中
$moneyinfo['nomoney'] = $nomoney;//未回款
$moneyinfo['allmoney'] = $remoney+$inmoney+$nomoney;//总金额
$records['moneyinfo']=$moneyinfo;
$this->success('请求成功', $records);
}
//获取费用详情
public function getDetail()
{
$id = input('id', '', 'intval');
$consume = ConsumeModel::where(['id' => $id])->with(['staff','customer'])->find();
if(empty($consume)){
$this->error('数据不存在');
}
$consume['files'] = File::where(['id' => ['in', explode(',', $consume['file_ids'])]])->field('id,types,name,file_path')->select();
if ($consume['check_status'] == 0 || $consume['check_status'] == 1) {
$consume['is_examine'] = ExamineRecord::isExaminse(ExamineRecord::CONSUME_TYPE, $id);
} else {
$consume['is_examine'] = 0;
}
//标记通知已读
Message::setRead(Message::CONSUME_TYPE, $id, $this->auth->id);
$this->success('请求成功', $consume);
}
}
|