<?php

if(!defined('IN_DISCUZ')) {
    exit('Access Denied');
}

if(!$_G['uid']){
    echo json_encode(array('code' => 0, 'msg' => 'no login'));
    exit;
}

//获取配置文件
$setting = get_mocuz_setting(array('integral_article_share','integral_share_switch'));

$share = unserialize($setting['integral_article_share']);

$share_switch = $setting['integral_share_switch'];
$score = $share['score'];
$extcredits = 'extcredits'.$share['type'];

$extcredit = $_G ['setting'] ['extcredits'];
$score_name = $extcredit[$share['type']]['title'];

if(!empty($share_switch))
{
    //判断用户今天是否分享过操作
    $sql = "SELECT * FROM ".DB::table('common_credit_log')." WHERE uid = {$_G['uid']} AND operation = 'SHT' AND dateline BETWEEN ".(time() - 86400)." AND ".time();
    $result = DB::query($sql);
    $count = DB::num_rows($result);
    if(empty($count))
    {
        //对积分进行操作
        
        updatemembercount($_G['uid'], array($extcredits => '+'.$score ), true, '', 0, '');
        credit_log($_G['uid'],'SHT',0,array($extcredits => '+'.$score ), 'share_get_score');
        $message = odz_lang('get_share_score').$score_name.$score;

        echo json_encode(odz_encode(array('code' => 1, 'msg' => $message)));//已经使用积分
    }
    else{
        echo json_encode(array('code' => 0, 'msg' => 'used'));//已经使用积分
    }
}
else
{
    echo json_encode(array('code' => 0, 'msg' => 'unopen'));//设置没开启
}



