签到打卡api

/*
     * 签到*
    */
    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;
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值