作者 Cool

领取红包,浏览量记录调试

... ... @@ -146,11 +146,13 @@ class Hot extends Api
];
$view_model->where($where_v)->setInc('count');
} else {
$this->store_inform_model->where('id',$v['id'])->setInc('views');
$insert = [
'user_id' => $this->auth->id,
'object_id' => $v['id']
'object_id' => $v['id'],
'createtime' => time()
];
$view_model->add($insert);
$view_model->insertGetId($insert);
}
}
$return = [
... ... @@ -300,6 +302,9 @@ class Hot extends Api
'where' => ['id'=>$param['store_inform_id'],'status'=>2]
];
$inform = $this->store_inform_model->findOrFail($where);
if($inform['type'] == 2) {
$this->error('一般信息无法领取红包');
}
if($inform['surplus'] == 0) {
$this->error('红包已抢完');
}
... ... @@ -324,6 +329,13 @@ class Hot extends Api
'money' => $inform['single']
];
$res_log = $log_model->add($log_data);
// 修改已领取、剩余红包数量
$inform_edit = [
'id' => $inform['id'],
'get' => $inform['get'] + 1,
'surplus' => $inform['number'] - $inform['get'] - 1,
];
$res_inform = $this->store_inform_model->edit($inform_edit);
// 新增用户余额
$res_user = $user_model->where('id',$this->auth->id)->setInc('money',$inform['single']);
// 新增余额记录
... ... @@ -335,7 +347,7 @@ class Hot extends Api
'memo' => '领取红包'
];
$res_moeny_log = $money_log_model->add($money_log_data);
if(!$res_log || !$res_user || !$res_moeny_log) {
if(!$res_log || !$res_inform || !$res_user || !$res_moeny_log) {
Db::rollback();
$this->error('红包领取失败');
}
... ...
... ... @@ -7,4 +7,5 @@ namespace app\api\model;
class StoreInformLog extends Base
{
protected $updateTime = false;
}
\ No newline at end of file
... ...
... ... @@ -4,4 +4,5 @@ namespace app\api\model;
class UserMoneyLog extends Base{
protected $updateTime = false;
}
... ...