/** * 签到功能核心入口函数 */ public function sign($member_id, $todaysay, $qdxq) { if (empty($member_id)) { return array('status' => 0, 'msg' => array('ErrorCode' => '0x0005', 'ErrorText' => '会员id不能为空')); //会员id不正确 } $member_sign_set = $this->get_setting(); if (empty($member_sign_set['is_on'])) { return array('status' => -1, 'msg' => array('ErrorCode' => '0x0089', 'ErrorText' => '签到功能未开启')); //签到功能未开启 } if (empty($member_sign_set['is_qdxq'])) { if (empty($qdxq)) { return array('status' => -5, 'msg' => array('ErrorCode' => '0x0093', 'ErrorText' => '你选择的心情不正确,请重新选择签到心情!')); } } else { $qdxq = 'no_mood'; //如果未开启心情功能则重置心情为默认无心情选项 } if ($member_sign_set['is_timeopen']) { $htime = hg_get_format_date(TIMENOW, 14); //本次时间 if ($htime < $member_sign_set['limit_time']['start']) { return array('status' => -7, 'msg' => array('ErrorCode' => '0x0095', 'ErrorText' => '签到时间还未开始!')); } elseif ($htime > $member_sign_set['limit_time']['end']) { return array('status' => -8, 'msg' => array('ErrorCode' => '0x0096', 'ErrorText' => '已经过了签到时间!')); } } if (!$member_sign_set['is_todaysay']) { if ($member_sign_set['is_todaysayxt']) { $todaysay = $todaysay ? $todaysay : '该会员没有填写最想说内容'; } elseif (empty($member_sign_set['is_todaysayxt']) && empty($todaysay)) { //今日最想说内容未填写 return array('status' => -6, 'msg' => array('ErrorCode' => '0x0092', 'ErrorText' => '今日最想说内容未填写!')); } } else { $todaysay = '该会员没有填写最想说内容'; } $checkdata = $this->Members->checkuser($member_id); if (!$checkdata) { return array('status' => -4, 'msg' => array('ErrorCode' => '0x0006', 'ErrorText' => '会员不存在')); } $today = strtotime(date('Y-m-d', TIMENOW)); //今天起始时间 $sign_info = $this->db->query_first('SELECT * FROM ' . DB_PREFIX . 'sign WHERE member_id=' . intval($member_id)); $num = $this->db->query_first("SELECT COUNT(*) as count FROM " . DB_PREFIX . "sign WHERE time >= {$today} "); $signnum = $num['count']; $stats = $this->db->query_first("SELECT * FROM " . DB_PREFIX . "sign_count WHERE id='1'"); $credit_type = array(); $credit_type_info = $this->Members->get_credit_type(); //获取已启用的积分类型 $credit_type = array_keys($credit_type_info); if (empty($credit_type)) { return array('status' => -2, 'msg' => array('ErrorCode' => '0x0090', 'ErrorText' => '未设置可用奖励积分.')); } $credits = array(); $credits = $member_sign_set['credits']; $new_credits = array(); $updatecredit = false; if (empty($sign_info)) { $logarr = array('member_id' => $member_id, 'time' => TIMENOW, 'days' => 1, 'lasted' => 1, 'mdays' => 1, 'qdxq' => $qdxq, 'todaysay' => $todaysay); $lastreward = 0; //最后增加积分值数量之和 if ($credits && is_array($credits)) { foreach ($credits as $k => $v) { if ($k == 'base' && is_array($v) && $v) { foreach ($v as $kk => $vv) { if (in_array($kk, $credit_type)) { $credit_num = intval($vv); $lastreward += $credit_num; $new_credits[$kk] = $credit_num; $logarr[$kk] = $credit_num; $logarr['reward_' . $kk] = $credit_num; } } } if ($k == 'lastedop' && is_array($v) && $v && $member_sign_set['is_lastedop']) { if ($member_sign_set['lastedop']) { $credit_d = $v[1]; foreach ($credit_d as $kk => $vv) { if (in_array($kk, $credit_type)) { $credit_num = intval($vv); $lastreward += $credit_num; $new_credits[$kk] += $credit_num; $logarr[$kk] += $credit_num; $logarr['reward_' . $kk] += $credit_num; } } } } } } $logarr['reward'] = $lastreward; $ret_log = $this->membersql->create('sign', $logarr); if ($ret_log) { $updatecredit = true; } } else { if ($sign_info['time'] > $today) { return array('status' => -3, 'msg' => array('ErrorCode' => '0x0091', 'ErrorText' => '今天已经签过到!')); } $lasted = 1; if ($today - $sign_info['time'] < 86400) { $lasted = $sign_info['lasted'] + 1; } $lastmonth = hg_get_format_date($sign_info['time'], 12); //上次签到月 $nowmonth = hg_get_format_date(TIMENOW, 11); //本次时间 $mdays = 1; if ($nowmonth == $lastmonth) { //是否在同一个月,在同一个月+1; $mdays = $sign_info['mdays'] + 1; } $logarr = array('member_id' => $member_id, 'time' => TIMENOW, 'days' => $sign_info['days'] + 1, 'lasted' => $lasted, 'mdays' => $mdays, 'qdxq' => $qdxq, 'todaysay' => $todaysay); $lastreward = 0; //最后增加积分值数量之和 if ($credits && is_array($credits)) { $credit_d = array(); foreach ($credits as $k => $v) { if ($k == 'base' && is_array($v) && $v) { foreach ($v as $kk => $vv) { if (in_array($kk, $credit_type)) { $credit_num = intval($vv); $lastreward += $credit_num; $new_credits[$kk] = $credit_num; $logarr[$kk] = $credit_num; $logarr['reward_' . $kk] = $sign_info['reward_' . $kk] + $credit_num; } } } if ($k == 'lastedop' && is_array($v) && $v && $member_sign_set['is_lastedop']) { if ($member_sign_set['lastedop'] >= $lasted) { $credit_d = $v[$lasted]; foreach ($credit_d as $kk => $vv) { if (in_array($kk, $credit_type)) { $credit_num = intval($vv); $lastreward += $credit_num; $new_credits[$kk] += $credit_num; $logarr[$kk] += $credit_num; $logarr['reward_' . $kk] += $credit_num; } } } } if ($k == 'final' && is_array($v) && $v && $member_sign_set['is_lastedop']) { if ($member_sign_set['lastedop'] < $lasted && $member_sign_set['lastedop']) { $credit_d = $v; foreach ($credit_d as $kk => $vv) { if (in_array($kk, $credit_type)) { $credit_num = mt_rand(intval($vv['min']), intval($vv['max'])); $lastreward += $credit_num; $new_credits[$kk] += $credit_num; $logarr[$kk] += $credit_num; $logarr['reward_' . $kk] += $credit_num; } } } } } } $logarr['reward'] = $sign_info['reward'] + $lastreward; $ret_log = $this->membersql->update('sign', $logarr, array('member_id' => $member_id)); if ($ret_log) { $updatecredit = true; } } if ($updatecredit) { if ($signnum == 0) { if ($stats['todayq'] > $stats['highestq']) { $this->db->query("UPDATE " . DB_PREFIX . "sign_count SET highestq='{$stats['todayq']}' WHERE id='1'"); } $this->db->query("UPDATE " . DB_PREFIX . "sign_count SET yesterdayq='{$stats['todayq']}',todayq=1 WHERE id='1'"); $this->db->query("UPDATE " . DB_PREFIX . "sign_emot SET count=0"); } else { $this->db->query("UPDATE " . DB_PREFIX . "sign_count SET todayq=todayq+1 WHERE id='1'"); } if ($qdxq) { $this->db->query("UPDATE " . DB_PREFIX . "sign_emot" . " SET count=count+1 WHERE qdxq='" . trim($qdxq) . "'"); } $this->db->query("UPDATE " . DB_PREFIX . "sign_count SET total=total+1 WHERE id='1'"); $credit_log = array('app_uniqueid' => APP_UNIQUEID, 'mod_uniqueid' => MOD_UNIQUEID, 'action' => 'sign', 'method' => 'sign', 'relatedid' => $member_id, 'title' => '签到', 'remark' => '签到成功'); $members_info = $this->Members->credits($new_credits, $member_id, $coef = 1, true, true, true, $credit_type, array(), $credit_log); $logarr['member_info'] = $members_info; } $logarr['updatecredit'] = $updatecredit; $logarr['status'] = 1; $logarr['credit_type'] = $credit_type_info; $logarr['copywriting_credit'] = copywriting_credit(array($logarr)); unset($logarr['credit_type']); $logarr['copywriting'] = '签到成功'; return $logarr; }
/** * 减少积分和经验 ... */ public function sub_credit() { $member_id = $this->get_condition(); //获取member_id $credit_type_info = $this->Members->get_credit_type(); $credit_type = array_keys($credit_type_info); if (empty($credit_type)) { $this->errorOutput(NO_CONSUME_CREDIT); } $credits = array(); foreach ($credit_type as $k => $v) { if ($credit = intval($this->input[$v])) { $credits[$v] = neg_num($credit); } } if ($credits) { $relatedid = $this->input['relatedid'] ? $this->input['relatedid'] : 0; //操作物品相关id $app_uniqueid = $this->input['app_uniqueid'] ? $this->input['app_uniqueid'] : APP_UNIQUEID; //应用id $mod_uniqueid = $this->input['mod_uniqueid'] ? $this->input['mod_uniqueid'] : MOD_UNIQUEID; //模块id $action = $this->input['action'] ? $this->input['action'] : $this->input['a']; $method = 'sub'; //操作方法 $remark = $this->input['remark'] ? trim($this->input['remark']) : ''; if (empty($remark)) { $this->errorOutput(CREDIT_OP_ERROR); } $credit_log = array('app_uniqueid' => $app_uniqueid, 'mod_uniqueid' => $mod_uniqueid, 'action' => $action, 'method' => $method, 'relatedid' => $relatedid, 'remark' => $remark); if ($title = $this->input['creditlogtitle']) { $credit_log['title'] = $title; } if ($icon = $this->input['creditlogicon']) { $credit_log['icon'] = maybe_serialize($icon); } $re_credit = $this->Members->credits($credits, $member_id, $coef = 1, true, true, false, $credit_type, array(), $credit_log); $this->error($re_credit); } $credits = array_merge($credits, $re_credit); $credits['credit_type'] = $credit_type_info; $credits['copywriting_credit'] = copywriting_credit(array($credits), true); unset($credits['credit_type']); $this->addItem($credits); $this->output(); }
/** * * 积分规则处理函数,积分规则入口. * @param String $operation 积分规则操作名,必传 * @param INT $uid 会员id * @param int $coef 可以说是积分倍数吧.比如说这里值传2的话.积分当然是增加2倍了,当然同时积分操作次数也加2.嘿嘿... * @param int $update 控制是否更新积分,积分日志等. * @param String $appid 应用标识,周期级别设置为应用级或者自定义应用积分规则使用,为了保持功能完整性和可选性,建议都传 * @param String $modid 模块标识 周期级别设置为模块级则必传,其它可选 * @param $sid intval 分类id 周期级别设置为分类级则必传,其它可选 * @param $cid intval 内容id 周期级别设置为内容级则必传,其它可选 */ public function credits_rule($operation, $uid, $coef = 1, $update = 1, $appid = '', $modid = '', $sid = 0, $cid = 0) { if (empty($operation)) { return -1; //未传操作key; } if (empty($uid)) { return 0; //未传会员id; } elseif (is_string($uid) && stripos($uid, ',') !== false || is_array($uid)) { return -2; //会员id格式不正确,仅支持单个会员id } $gid = $this->uid_to_gid($uid); if ($gid === false) { return -3; //无此会员或者会员已被删除 } $rule = $this->creditRuleProcess($operation, $appid, $gid); $cycleLevel = $this->checkRulesCycleLevel($rule, trim($appid), trim($modid), intval($sid), intval($cid)); if (is_numeric($cycleLevel) && $cycleLevel < 0) { return $cycleLevel; } $updatecredit = false; $enabled = false; if ($rule && $rule['opened']) { $credit_type = array(); $credit_type_info = $this->get_credit_type('db_field,title,img'); //获取已启用的积分类型 $credit_type = array_keys($credit_type_info); $member_credit = $this->membercredit($uid, false, false); if ($credit_type && is_array($credit_type)) { foreach ($credit_type as $v) { if (isset($rule[$v])) { if ($member_credit[$v] >= abs_num($rule[$v]) && $rule[$v] < 0 || $rule[$v] >= 0) { $enabled = true; } elseif ($member_credit[$v] < abs_num($rule[$v]) && $rule[$v] < 0) { $enabled = false; return -6; //可执行积分不足 } } } } else { return -5; //无可用积分类型 } } elseif ($rule && !$rule['opened']) { return -7; //此规则未启用 } else { return -4; //无此积分规则 } if ($enabled) { $rulelog = array(); $appid = $cycleLevel['appid'] ? $cycleLevel['appid'] : ''; //$appids = $rule['appids'] ? explode(',', $rule['appids']) : array(); //$appid = in_array($appid, $appids) ? trim($appid) : ''; $modid = $cycleLevel['modid'] ? $cycleLevel['modid'] : ''; $sid = $cycleLevel['sid'] ? $cycleLevel['sid'] : 0; $cid = $cycleLevel['cid'] ? $cycleLevel['cid'] : 0; $rulelog = $this->getcreditrulelog($rule['id'], $uid, $appid, $modid, $sid, $cid); if ($rule['rewardnum'] && $rule['rewardnum'] < $coef) { $coef = $rule['rewardnum']; } if (empty($rulelog)) { $logarr = array('uid' => $uid, 'rid' => $rule['id'], 'appid' => $appid, 'modid' => $modid, 'sid' => $sid, 'cid' => $cid, 'total' => $coef, 'cyclenum' => $coef, 'dateline' => TIMENOW); if (in_array($rule['cycletype'], array(2, 3))) { $logarr['starttime'] = TIMENOW; } $logarr = $this->addlogarr($logarr, $rule, $coef, $credit_type); if ($update) { $ret_log = $this->membersql->create('credit_rules_log', $logarr); } if ($ret_log) { $updatecredit = true; } } else { $newcycle = false; $logarr = array(); switch ($rule['cycletype']) { case 0: break; case 1: case 4: if ($rule['cycletype'] == 1) { $today = strtotime(date('Y-m-d', TIMENOW)); if ($rulelog['dateline'] < $today && $rule['rewardnum']) { $rulelog['cyclenum'] = 0; $newcycle = true; } } if (empty($rule['rewardnum']) || $rulelog['cyclenum'] < $rule['rewardnum']) { if ($rule['rewardnum']) { $remain = $rule['rewardnum'] - $rulelog['cyclenum']; if ($remain < $coef) { $coef = $remain; } } $cyclenunm = $newcycle ? $coef : $rulelog['cyclenum'] + $coef; $logarr = array('cyclenum' => $cyclenunm, 'total' => $rulelog['total'] + $coef, 'dateline' => TIMENOW); $updatecredit = true; } break; case 2: case 3: $nextcycle = 0; if ($rulelog['starttime']) { if ($rule['cycletype'] == 2) { $start = strtotime(date('Y-m-d H:00:00', $rulelog['starttime'])); $nextcycle = $start + $rule['cycletime'] * 3600; } else { $nextcycle = $rulelog['starttime'] + $rule['cycletime'] * 60; } } if (TIMENOW <= $nextcycle && $rulelog['cyclenum'] < $rule['rewardnum']) { if ($rule['rewardnum']) { $remain = $rule['rewardnum'] - $rulelog['cyclenum']; if ($remain < $coef) { $coef = $remain; } } $logarr = array('cyclenum' => $rulelog['cyclenum'] + $coef, 'total' => $rulelog['total'] + $coef, 'dateline' => TIMENOW); $updatecredit = true; } elseif (TIMENOW >= $nextcycle) { $newcycle = true; $logarr = array('cyclenum' => $coef, 'total' => $rulelog['total'] + $coef, 'dateline' => TIMENOW, 'starttime' => TIMENOW); $updatecredit = true; } break; } if ($update && $logarr) { $logarr = $this->addlogarr($logarr, $rule, $coef, $credit_type); $this->membersql->update('credit_rules_log', $logarr, array('uid' => intval($uid), 'rid' => $rulelog['rid'], 'appid' => $rulelog['appid'], 'gid' => $rulelog['gid'])); } } } $rule['member_info'] = array(); if ($enabled && $updatecredit && $update) { $credit_log = array('app_uniqueid' => APP_UNIQUEID, 'mod_uniqueid' => MOD_UNIQUEID, 'action' => 'credit_rules', 'method' => 'credit_rules', 'relatedid' => $rule['id'], 'title' => '积分策略', 'remark' => $rule['rname']); $members_info = $this->credits($rule, $uid, $coef, true, true, true, $credit_type, array(), $credit_log); $rule['member_info'] = $members_info; } $rule['updatecredit'] = $updatecredit; $rule['credit_type'] = $credit_type_info; $rule['copywriting_credit'] = copywriting_credit(array($rule), false, $credit_type_info); return $rule; }
private function editCreditRules($member_id, $_new_member_info = array(), $bind_info = array()) { $creditRule = array(); if ($member_id) { $condition = 'AND m.member_id = \'' . $member_id . '\''; $member_info = $this->Members->get_member_info($condition, 'm.member_name,m.avatar,mb.nick_name', 'LEFT join ' . DB_PREFIX . 'member_bind mb ON mb.member_id = m .member_id '); if ($_new_member_info['member_name'] && $_new_member_info['member_name'] != $member_info['member_name']) { $reCreditsRule = $this->Members->credits_rule('members_editMemberName', $member_id, $coef = 1, $update = 1, APP_UNIQUEID); $creditRule[] = $this->CreditRulesError($reCreditsRule); } if ($_new_member_info['avatar'] && empty($member_info['avatar'])) { $reCreditsRule = $this->Members->credits_rule('members_editAvatar', $member_id, $coef = 1, $update = 1, APP_UNIQUEID); $creditRule[] = $this->CreditRulesError($reCreditsRule); } if ($bind_info['nick_name'] && $bind_info['nick_name'] != $member_info['nick_name']) { $reCreditsRule = $this->Members->credits_rule('members_editNickName', $member_id, $coef = 1, $update = 1, APP_UNIQUEID); $creditRule[] = $this->CreditRulesError($reCreditsRule); } } return copywriting_credit($creditRule); }
/** * 验证会员 * $member_name 会员名 * $password 密码 * $type 登陆类型 * $appid * $appkey */ public function verify_member() { try { $encrypt = $this->input['encrypt'] ? intval($this->input['encrypt']) : 0; $platform_id = trim($this->input['platform_id']); $password = $encrypt ? passport_decrypt(trim($this->input['password']), CUSTOM_APPKEY) : trim($this->input['password']); $type = trim($this->input['type']); $_type = trim($this->input['_type']); //防止本地M2O同步至UC后,再次验证本地密码BUG。 $identifierUserSystem = new identifierUserSystem(); $identifier = $identifierUserSystem->setIdentifier((int) $this->input['identifier'])->checkIdentifier(); //多用户系统 $ip = hg_getip(); $need_password_type = array('shouji', 'm2o', 'email'); $appid = intval($this->input['appid']); $appkey = trim($this->input['appkey']); //会员名 if (!$platform_id) { $this->errorOutput(NO_MEMBER_NAME); } //密码 if (!$password && in_array($type, $need_password_type)) { $this->errorOutput(NO_PASSWORD); } $condition = " AND mb.platform_id = '" . $platform_id . "' AND mb.type = '" . $type . "' AND mb.identifier = '" . $identifier . '\''; $_bind = $this->mMember->get_bind_info($condition); $bind = array(); if (is_array($_bind) && count($_bind) > 1) { foreach ($_bind as $v) { if ($v['inuc'] > 0) { $bind = $v; break; } } } elseif (is_array($_bind)) { $bind = $_bind[0]; } $member_id = intval($bind['member_id']); $platform_id = $bind['platform_id']; $condition = " AND m.member_id = " . $member_id; $fileds_array = array('member_id', 'member_name', 'password', 'salt', 'avatar', 'type', 'type_name', 'gid', 'gradeid', 'guid', 'signature', 'mobile', 'email', 'isVerify', 'identifier', 'last_login_device'); $fields = implode(',', $fileds_array); $member_info = $this->mMember->get_member_info($condition, $fields); $member_info = $member_info[0]; if (empty($member_info)) { $this->errorOutput(LOGIN_NOMEMBER_ERROR); } $isComplete = isUserComplete($member_info['type']); if (in_array($type, $need_password_type) && $_type != 'uc') { $encrypt_num = intval($this->input['encrypt_num']); if ($encrypt_num == 1) { $md5_password = md5($password . $member_info['salt']); } else { $md5_password = md5(md5($password) . $member_info['salt']); } if ($md5_password != $member_info['password']) { $this->errorOutput(PASSWORD_ERROR); } } else { //验证新浪微博、腾讯微博、QQ、人人、豆瓣 等 用户信息 //暂时不作处理 } //积分规则调用 $credit_rules = $this->Members->credits_rule('members_login_login', $member_info['member_id'], $coef = 1, $update = 1, APP_UNIQUEID); $copywriting_credit = copywriting_credit(array($credit_rules)); $check_Bind = new check_Bind(); $inuc = $check_Bind->check_uc($member_id, $type); if (!$inuc && ($_type == 'm2o' || $type == 'm2o') && $member_info['email']) { if ($inuc = $this->mMember->syncUcRegister($member_id, $member_info['member_name'], $password, $member_info['email'])) { $platform_id = $inuc; } } $return = array('user_id' => $member_info['member_id'], 'platform_id' => (string) $platform_id, 'inuc' => $inuc, 'user_name' => $member_info['member_name'], 'nick_name' => $bind['nick_name'], 'type' => $member_info['type'], 'avatar' => $member_info['avatar'], 'copywriting' => '登录成功', 'copywriting_credit' => $copywriting_credit, 'isVerify' => $member_info['isVerify'], 'identifier' => $member_info['identifier'], 'isComplete' => $isComplete); $return = array_merge($return, $member_info); $this->addItem($return); $this->output(); } catch (Exception $e) { $this->errorOutput($e->getMessage(), $e->getCode()); } }