<?php
namespace application\member\models;
use ticky\traits\call;
class point {
use call;
public $pay_type = array(
0 => '每日登陆',
1 => '评论奖励',
2 => '投稿奖励',
3 => '会员充值',
4 => '后台充值',
5 => '积分兑换',
6 => '积分购买',
7 => '阅读收费',
8 => '下载收费',
9 => '发表帖子',
10 => '每日签到',
11 => '其他'
);
public function point_add($type, $value, $pay_type, $userid, $username, $experience = 0, $remarks = '', $adminnote = '', $mod_experience = true) {
$data = array();
$data['trade_sn'] = create_tradenum();
$data['money'] = $value;
$data['userid'] = $userid;
$data['username'] = $username;
$data['type'] = $type;
$data['msg'] = $this->pay_type[$pay_type];
$data['remarks'] = $remarks;
$data['creat_time'] = NOW_TIME;
$data['ip'] = getip();
$data['adminnote'] = $adminnote;
if ($type == 1)
$data['status'] = 1;
$update = $type == '1' ? '`point`=`point`+' . $value : '`amount`=`amount`+' . $value;
if ($mod_experience) {
$update .= ',`experience`=`experience`+' . $value;
if (!$experience)
$experience = db('member')->field('experience')->where(array('uid' => $userid))->one();
$this->_check_update_group($value, $experience, $userid);
}
db('member')->where(array('uid' => $userid))->update($update);
db('pay')->add($data);
}
public function point_spend($type, $value, $pay_type, $userid = '', $username = '', $remarks = '') {
$data = array();
$data['trade_sn'] = create_tradenum();
$data['money'] = $value;
$data['userid'] = $userid;
$data['username'] = $username;
$data['type'] = $type;
$data['msg'] = $this->pay_type[$pay_type];
$data['remarks'] = $remarks;
$data['creat_time'] = NOW_TIME;
$data['ip'] = getip();
$update = $type == '1' ? '`point`=`point`-' . $value : '`amount`=`amount`-' . $value;
db('member')->where(array('uid' => $userid))->update($update); db('pay_spend')->add($data);
}
protected function _check_update_group($add = 0, $experience, $userid) {
$new_groupid = 1;
$groupid = intval(cookie('_groupid'));
$data = get_groupinfo();
if (!$data)
return false;
$exp = $experience + $add;
foreach ($data as $k => $v) {
$experience_list[$k] = $v['experience'];
}
arsort($experience_list);
if ($exp > max($experience_list)) {
$new_groupid = key($experience_list);
} else {
foreach ($experience_list as $k => $v) {
if ($exp >= $v) {
$new_groupid = $tmp_k;
break;
}
$tmp_k = $k;
}
}
if ($new_groupid != $groupid) {
cookie('_groupid', $new_groupid);
db('member')->where(array('uid' => $userid))->update(array('groupid' => $new_groupid));
}
}
}