/*
* 签到*
*/
public function sign(){
!$this->uid && x_json(1,'请登录');
$clock = $this->record(1);
if($clock) {
x_json(1, $clock,'今日已打卡');
}
$this->db->insert('member_clock', array(
'uid' => $this->uid,
'status' => 1,
'inputtime' => SYS_TIME
));
$id = $this->db->insert_id();
$value = dr_var("qdjyz");
//打卡加积分
$this->db->set('experience','experience+'.$value,false)->where('uid',$this->uid)->update('member');
$id > 0 ? x_json(0,'success') : x_json(1,'error');
}
/*
*签到记录
*/
public function lists($params='') {
!$this->uid && x_json(1,'请登录');
$starttime = strtotime('today');
$endtime = strtotime('next day today');
$params = (int)$_GET['params'];
$clock = $this->record($params);
if($params == 1) {
$data = $this->show();
if($data) {
$index = 0;
for($i = 0; $i < count($data); $i++) {
if($data[$i]['inputtime'] < $endtime - 86400 * $i && $starttime - 86400 * $i < $data[$i]['inputtime']) {
$index++;
} else {
break;
}
}
}
if($index > 0) {
$clock['0']['count'] = $index;
} else {
$clock['count'] = 0;
}
}
x_json(0, $clock, 'success');
}
public function record($params) {
if($params == 1) {
$starttime = strtotime('today');
$endtime = strtotime('next day today');
} else {
// 结束时间
$endtime = SYS_TIME;
// 3个月前月初的时间戳
$starttime = strtotime(date('Y-m', SYS_TIME - 24*60*60*90));
}
$this->db->where('(inputtime between '.(int)$starttime.' and '.(int)$endtime . ')');
$clock = $this->db->select("FROM_UNIXTIME(inputtime, '%Y-%m-%d') as time, uid, status, inputtime")
->where('uid', $this->uid)
->where('status', 1)
->order_by('inputtime desc')
->get('member_clock')
->result_array();
return $clock;
}
签到打卡api
最新推荐文章于 2024-07-04 04:31:54 发布