SaveController.class.php
2.36 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
<?php
/**
* 【后台】导入人员激励信息
* SaveController.class.php
* @author:daijun
* @date:2017-08-31
*/
namespace Apicp\Controller\Incentives;
use Common\Service\IncentivesService;
class SaveController extends \Apicp\Controller\AbstractController
{
/**
* 导入人员激励信息
* @author daijun
*/
protected $_require_login = false;
public function Index_post()
{
$param = I('post.');
$incentives_serv = new IncentivesService();
$ed_id = $param['ed_id'];
if (empty($ed_id)) {
E('_EMPTY_EDUCATION_ID');
}
// 获取错误提示信息
$incentives_serv->get_code($ed_id, $param['data'], $codes);
$params = $param['data'];
// 如果没有错误
if (empty($codes)) {
$conds = ['sr_uid' => $params['sr_uid'], 'ed_id' => $ed_id];
$in_data = $incentives_serv->get_by_conds($conds);
if (empty($in_data)) {
// 组织插入数据
$insert_data = [
'sr_uid' => $params['sr_uid'],
'sr_medal' => $params['sr_medal'],
'sr_score' => intval($params['sr_score']),
'sr_credit' => (int)$params['sr_credit'],
'sr_give_status' => IncentivesService::GIVE_STATUS_NO,
'ed_id' => $ed_id
];
// 写入数据
$incentives_serv->insert($insert_data);
} elseif ($in_data['sr_give_status'] != IncentivesService::GIVE_STATUS_OK) {
// 组织更新数据
$update_data = [
'sr_medal' => $params['sr_medal'],
'sr_score' => intval($params['sr_score']),
'sr_credit' => (int)$params['sr_credit'],
'sr_give_status' => IncentivesService::GIVE_STATUS_NO,
];
// 更新数据
$incentives_serv->update_by_conds($conds, $update_data);
}
}
// 初始化
$data = [];
// 如果存在错误
if (!empty($codes)) {
// 组织返回参数
$data = $incentives_serv->data_format($param, $codes);
}
// 返回数据
$this->_result = ['data' => $data, 'error' => $codes];
return true;
}
}