/** * 增加积分和经验 ... */ public function add_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_CREDITS); } $credits = array(); $re_credit = array(); foreach ($credit_type as $v) { $credit = intval($this->input[$v]); if ($credit) { $credits[$v] = abs_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 = 'add'; //操作类型 $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); } is_array($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 filter_data() { $name = isset($this->input['name']) ? trim(urldecode($this->input['name'])) : ''; $brief = isset($this->input['brief']) ? trim(urldecode($this->input['brief'])) : ''; $is_award_time = isset($this->input['is_award_time']) ? intval($this->input['is_award_time']) : 0; $start_date = $is_award_time ? !empty($this->input['start_date']) ? strtotime(trim($this->input['start_date'])) : 0 : 0; $end_date = $is_award_time ? !empty($this->input['end_date']) ? strtotime(trim($this->input['end_date'])) : 0 : 0; $limit_num = isset($this->input['limit_num']) ? abs_num($this->input['limit_num']) : 0; $expiration = isset($this->input['expiration']) ? abs_num($this->input['expiration']) : 0; $medal_type = isset($this->input['medal_type']) ? intval($this->input['medal_type']) : 0; $data = array('name' => $name, 'brief' => $brief, 'start_date' => $start_date, 'end_date' => $end_date, 'limit_num' => $limit_num, 'expiration' => $expiration, 'type' => $medal_type); if ($_FILES['image']) { $data['image'] = $this->img_upload($_FILES['image']); } return $data; }
/** * * 设置定义字段数量 ... * @param unknown_type $id * @param unknown_type $count * @param unknown_type $type */ public function setMFcount($id, $count, $type) { $mfcountArr = array(); $count = (int) $count; if ($mfcountArr = $this->getMFcountAssoc($id)) { $mfcount = (int) $mfcountArr['mfcount']; if ($type == 'del') { if ($count > 0 && $mfcount >= $count) { $mfcount -= $count; } elseif ($count < 0 && $mfcount >= abs_num($count)) { $mfcount += $count; } else { if ($count && $mfcount) { $mfcount = 0; } } } else { if ($type == 'add') { if ($count < 0) { throw new Exception(NOT_NEGATIVE_NUMBER, 200); } $count > 0 && ($mfcount += $count); } else { throw new Exception(SETMFCOUNT_NOT_OPERATE, 200); } } if ($count) { return $this->update(array('mfcount' => $mfcount), array('id' => $id)); } } else { throw new Exception(MYSET_ERROR, 200); } return false; }