<?php
/**
 * umeng 推送服务
 *
 ***/


defined('InShopNC') or exit('Access Invalid!');

class umengControl extends mbMemberControl
{
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * 更新device_token数据
     */
    public function updateOp()
    {
        $member_id = $_SESSION['member_id'];
        $data = array();
        $data['upush_device_token'] = trim($_GET['device_token']);
        $data['updatetime'] = time();

        // 判断用户是否存在
        $ret = Model()->table('device_binding')->where(array('member_id' => $member_id))->select();

        if (!empty($ret)) {
            $ret = Model()->table('device_binding')->where(array('member_id' => $member_id))->update($data);
        } else {
            $data['member_id'] = $member_id;
            $ret = Model()->table('device_binding')->insert($data);
        }

        if ($ret) {
            self::outsuccess(array('result' => 'true'));
        } else {
            self::outerr(errcode::ErrDB);
        }
    }
}
