作者 王智

xiugai

... ... @@ -226,36 +226,79 @@ class Config extends Api
{
$UserId = $this->IsToken($this->request->header());
$Params = $this->request->param();
$IsGive = Db::name('message')->where('user_id', $UserId)->where('ob_id', $Params['ob_id'])->where('type', 2)->where('message', '')->find();
// $IsGive = Db::name('message')->where('user_id', $UserId)->where('ob_id', $Params['ob_id'])->where('type', 2)->where('message', '')->find();
$ObInfo = Db::name('ob')->where('id', $Params['ob_id'])->find();
// if ($Params['gift_id'] != 0) {
// if (!empty($IsGive)) {
// $this->error('只能送出一份礼物');
// }
// $data = [
// 'user_id' => $UserId,
// 'ob_id' => $Params['ob_id'],
// 'type' => 2,
// 'touser_id' => $ObInfo['user_id'],
// 'gift_id' => $Params['gift_id'],
// 'createtime' => time()
// ];
// $Res = Db::name('message')->insert($data);
// }
// $IsMessage = Db::name('message')->where('user_id', $UserId)->where('ob_id', $Params['ob_id'])->where('type', 2)->where('gift_id', 0)->find();
// if ($Params['message'] != null && !empty($Params['message']) && $Params['message'] != '') {
// if (!empty($IsMessage)) {
// $this->error('只能留言一次');
// }
// $data = [
// 'message' => $Params['message'],
// ];
// $Res = Db::name('message')->where(['user_id' => $UserId,
// 'ob_id' => $Params['ob_id'], 'type' => 2,
// ])->update($data);
// }
// if ($ObInfo['user_id'] == '' || $ObInfo['user_id'] == null) {
// $this->error('未获取发布讣告人信息');
// }
// $this->Res($Res);
//Gift
$IsHave = Db::name('message')->where(['user_id' => $UserId, 'ob_id' => $Params['ob_id'], 'type' => 2])->find();
if ($Params['gift_id'] != 0) {
if (!empty($IsGive)) {
$this->error('只能送出一份礼物');
if (!empty($IsHave)) {
//update
$data = [
'gift_id' => $Params['gift_id']
];
$Res = Db::name('message')->where(['user_id' => $UserId, 'ob_id' => $Params['ob_id'], 'type' => 2])->update($data);
} else {
//add
$data = [
'user_id' => $UserId,
'ob_id' => $Params['ob_id'],
'type' => 2,
'touser_id' => $ObInfo['user_id'],
'gift_id' => $Params['gift_id'],
'createtime' => time()
];
$Res = Db::name('message')->insert($data);
}
$data = [
'user_id' => $UserId,
'ob_id' => $Params['ob_id'],
'type' => 2,
'touser_id' => $ObInfo['user_id'],
'gift_id' => $Params['gift_id'],
'createtime' => time()
];
$Res = Db::name('message')->insert($data);
}
$IsMessage = Db::name('message')->where('user_id', $UserId)->where('ob_id', $Params['ob_id'])->where('type', 2)->where('gift_id', 0)->find();
if ($Params['message'] != null && !empty($Params['message']) && $Params['message'] != '') {
if (!empty($IsMessage)) {
$this->error('只能留言一次');
} else {
//Message
if (!empty($IsHave)) {
//update
$data = [
'message' => $Params['message'],
];
$Res = Db::name('message')->where(['user_id' => $UserId, 'ob_id' => $Params['ob_id'], 'type' => 2])->update($data);
} else {
//add
$data = [
'user_id' => $UserId,
'ob_id' => $Params['ob_id'],
'type' => 2,
'touser_id' => $ObInfo['user_id'],
'message' => $Params['message'],
'createtime' => time()
];
$Res = Db::name('message')->insert($data);
}
$data = [
'message' => $Params['message'],
];
$Res = Db::name('message')->where(['user_id' => $UserId,
'ob_id' => $Params['ob_id'], 'type' => 2,
])->update($data);
}
if ($ObInfo['user_id'] == '' || $ObInfo['user_id'] == null) {
$this->error('未获取发布讣告人信息');
}
$this->Res($Res);
}
... ...