EndowController.class.php
2.99 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
<?php
/**
* Created by PhpStorm.
* 赋予勋章
* User: zhoutao
* Reader: zhoutao 2017-05-31 10:25:59
* Date: 2017-05-24 19:33:56
*/
/**
* 使用须知
*
* 调用方法:
* $rpcUrl = call_user_func_array('sprintf', [
* '%s://%s/%s/Integral/Rpc/Medal/Endow',
* $_SERVER['REQUEST_SCHEME'],
* $_SERVER['HTTP_HOST'],
* QY_DOMAIN
* ]);
*
* $postData = [
* 1, // im_id 勋章ID
* '9301F6AF7F0000010AF9CD33DD051EB3', // 人员ID
* '人员姓名' // 人员姓名
* ];
* \Com\Rpc::phprpc($rpcUrl)->invoke('Index', $postData)
*
* 返回值预览:
* true / false
*/
namespace Rpc\Controller\Medal;
use Common\Model\MedalLogModel;
use Common\Service\MedalLogService;
use Common\Service\MedalService;
use Common\Service\MemberMedalService;
class EndowController extends AbstractController
{
/**
* @param int $imId 勋章ID
* @param string $uid 人员ID
* @param string $userName 人员姓名
* @param int $getType 获得类型(1=自主获得;2=手动增加)
* @param array eaInfo 操作人信息
* @return bool
*/
public function index($imId, $uid, $userName, $getType = MedalLogModel::GET_TYPE_AUTO, $eaInfo = [])
{
$medalServ = new MedalService();
$medalLogServ = new MedalLogService();
$memMedalServ = new MemberMedalService();
// 判断是否有该勋章
$medalData = $medalServ->get($imId);
if (empty($medalData)) {
return false;
}
// 勋章申请
$mlId = $medalLogServ->insert([
'im_id' => $imId,
'mem_uid' => $uid
]);
try {
$memMedalServ->start_trans();
$medalLogServ->start_trans();
// 是否已经拥有过该勋章
$memMedalData = $memMedalServ->get_by_conds([
'im_id' => $imId,
'mem_uid' => $uid,
]);
if (empty($memMedalData)) {
$memMedalServ->insert([
'im_id' => $imId,
'mem_uid' => $uid,
'mem_username' => $userName,
'im_total' => 1,
]);
} else {
$memMedalServ->addMedalTotal($imId, $uid);
}
// 完成获得勋章
$medalLogServ->update($mlId, [
'get_status' => MedalLogModel::GET_STATUS_SUCCESS,
'get_type' => $getType,
'ea_id' => $eaInfo['eaId'] ?? '',
'ea_name' => $eaInfo['eaRealname'] ?? ''
]);
$memMedalServ->commit();
$medalLogServ->commit();
} catch (\Exception $e) {
$memMedalServ->rollback();
$medalLogServ->rollback();
// 更新获取勋章失败
$medalLogServ->update($mlId, [
'get_status' => MedalLogModel::GET_STATUS_FAILURE,
'get_type' => $getType
]);
return false;
}
return true;
}
}