Skip to content

Commit

Permalink
增加积分明细功能;修正User.Credit缓存和UserIncome不同步问题
Browse files Browse the repository at this point in the history
  • Loading branch information
shenyuyang committed Aug 1, 2012
1 parent f4b9c96 commit a1f4215
Show file tree
Hide file tree
Showing 18 changed files with 179 additions and 116 deletions.
2 changes: 1 addition & 1 deletion license.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
2) 可以对“我记录网站综合系统”以及源码进行二次分发,但必须保持项目和源码的完整,不得有任何修改。
3) 禁止未经同意对“我记录网站综合系统”进行销售,或以赢利为目的的任何行为。
4) 参与我记录团队开发并贡献代码到github托管库的(包括设计),或者帮忙推广的朋友,请到 www.wojilu.com 索取免费的商业授权。
5) 禁止去除页脚 Powered by“我记录”网站综合系统 信息和 www.wojilu.com 链接。
5) 除非购买商业授权,否则禁止去除页脚 Powered by“我记录”网站综合系统 信息和 www.wojilu.com 链接。
6)可以修改我记录的源码,但禁止修改命名空间。二次开发部分的源码可以使用自己的命名空间。
7) 更多未定事项,请联系 www.wojilu.com 确认。

Expand Down
5 changes: 3 additions & 2 deletions wojilu.Apps/Forum/Interface/IForumTopicService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@ public interface IForumTopicService {
void SetGloablStickyUndo( int appId, String ids );
void StickyMoveUp( int topicId );
void StickyMoveDown( int topicId );
void SubstractAuthorIncome( String condition, int actionId );

void AddAuthorIncome( String condition, int actionId, String actionName );
void SubstractAuthorIncome( String condition, int actionId, String actionName );
void SubstractTopicReward( ForumTopic topic, int postValue );

void AddAuthorIncome( String condition, int actionId );
void AddHits( ForumTopic topic );
void AdminUpdate( String action, String condition );
int CountReply( int topicId );
Expand Down
8 changes: 6 additions & 2 deletions wojilu.Apps/Forum/Service/ForumBuyLogService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using wojilu.Members.Users.Interface;
using wojilu.Common.Money.Interface;
using wojilu.Members.Users.Domain;
using wojilu.Web.Mvc;

namespace wojilu.Apps.Forum.Service {

Expand Down Expand Up @@ -53,8 +54,11 @@ public virtual Result Buy( int buyerId, int creatorId, ForumTopic topic ) {
log2.ActionId = actionId;
db.insert( log2 );

userIncomeService.AddKeyIncome( buyerId, -topic.Price );
userIncomeService.AddKeyIncome( creatorId, topic.Price );
String msg = string.Format( "购买有售价的帖子 <a href=\"{0}\">{1}</a>", alink.ToAppData( topic ), topic.Title );
userIncomeService.AddKeyIncome( buyerId, -topic.Price, msg );

String msg2 = string.Format( "销售帖子 <a href=\"{0}\">{1}</a>", alink.ToAppData( topic ), topic.Title );
userIncomeService.AddKeyIncome( creatorId, topic.Price, msg2 );

return result;
}
Expand Down
23 changes: 15 additions & 8 deletions wojilu.Apps/Forum/Service/ForumPostService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,9 @@ public virtual Result Insert( ForumPost post, User creator, IMember owner, IApp
if (result.IsValid) {

updateCount( post, creator, owner, app );
incomeService.AddIncome( creator, UserAction.Forum_ReplyTopic.Id );

String msg = string.Format( "回复帖子 <a href=\"{0}\">{1}</a>,得到奖励", alink.ToAppData( post ), post.Title );
incomeService.AddIncome( creator, UserAction.Forum_ReplyTopic.Id, msg );
addFeedInfo( post );
addNotification( post );

Expand Down Expand Up @@ -362,7 +364,9 @@ public virtual void DeleteTrue( ForumPost post, IMember owner, User user, String
boardService.DeletePostCount( forumBoardId, owner );
if (creatorId > 0) { //规避已注销用户
userService.DeletePostCount( creatorId );
incomeService.AddIncome( post.Creator, UserAction.Forum_PostDeleted.Id );

String msg = string.Format( "帖子被删除 <a href=\"{0}\">{1}</a>", alink.ToAppData( post ), post.Title );
incomeService.AddIncome( post.Creator, UserAction.Forum_PostDeleted.Id, msg );
}
forumLogService.AddPost( user, post.AppId, id, ForumLogAction.DeleteTrue, ip );
}
Expand All @@ -384,16 +388,16 @@ public virtual void AddReward( ForumPost post, int rewardValue ) {
post.Reward = rewardValue;
db.update( post, "Reward" );

incomeService.AddKeyIncome( post.Creator, rewardValue );
String msg = string.Format( "因为您回复了 \"<a href=\"{0}\">{1}</a>\",作者答谢您:{2}{3}", alink.ToAppData( topic ), topic.Title, rewardValue, KeyCurrency.Instance.Unit );

incomeService.AddKeyIncome( post.Creator, rewardValue, msg );

// 以下步骤不需要,因为发帖的时候已经被扣除了
//incomeService.AddKeyIncome( topic.Creator, -rewardValue );

topicService.SubstractTopicReward( topic, rewardValue );

notificationService.send( post.Creator.Id,
string.Format( "因为您回复了 \"<a href=\"{0}\">{1}</a>\",作者答谢您:{2}{3}", alink.ToAppData( topic ), topic.Title, rewardValue, KeyCurrency.Instance.Unit )
);
notificationService.send( post.Creator.Id, msg );
}

public virtual void SetPostCredit( ForumPost post, int currencyId, int currencyValue, String reason, User viewer ) {
Expand All @@ -416,15 +420,18 @@ public virtual void BanPost( ForumPost post, String reason, int isSendMsg, User
msgService.SendMsg( user, post.Creator.Name, msgTitle, msgBody );
}

incomeService.AddIncome( post.Creator, UserAction.Forum_PostBanned.Id );
String msg = string.Format( "帖子被屏蔽 <a href=\"{0}\">{1}</a>", alink.ToAppData( post ), post.Title );
incomeService.AddIncome( post.Creator, UserAction.Forum_PostBanned.Id, msg );

forumLogService.AddPost( user, appId, post.Id, ForumLogAction.Ban, ip );
}

public virtual void UnBanPost( ForumPost post, User user, int appId, String ip ) {
post.Status = 0;
db.update( post, "Status" );
incomeService.AddIncomeReverse( post.Creator, UserAction.Forum_PostBanned.Id );

String msg = string.Format( "帖子取消屏蔽 <a href=\"{0}\">{1}</a>", alink.ToAppData( post ), post.Title );
incomeService.AddIncomeReverse( post.Creator, UserAction.Forum_PostBanned.Id, msg );
forumLogService.AddPost( user, appId, post.Id, ForumLogAction.UnBan, ip );
}

Expand Down
38 changes: 25 additions & 13 deletions wojilu.Apps/Forum/Service/ForumTopicService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,6 @@ public virtual int CountReply( int topicId ) {

public virtual Result CreateTopic( ForumTopic topic, User user, IMember owner, IApp app ) {

if (topic.Reward > 0)
topic.TypeName = PostTypeString.Question;

populateData( topic, user, owner, app.Id );
return saveToDb( topic, user, app );
}
Expand Down Expand Up @@ -442,6 +439,14 @@ private static void populateData( ForumTopic topic, User user, IMember owner, in

private Result saveToDb( ForumTopic topic, User user, IApp app ) {

if (topic.Reward > 0) {
topic.TypeName = PostTypeString.Question;
}

if (topic.Reward > 0 && topic.Reward > user.Credit) {
return new Result( string.Format( "对不起,您现有积分{0},不够悬赏", user.Credit ) );
}

Result result = db.insert( topic );
if (result.HasErrors) throw new Exception( "insert forumtopic error" );

Expand All @@ -452,15 +457,16 @@ private Result saveToDb( ForumTopic topic, User user, IApp app ) {

// 发布悬赏问题,不会产生任何收益
if (topic.Reward > 0) {
incomeService.AddIncome( user, KeyCurrency.Instance.Id, -topic.Reward );
String msg = string.Format( "发布悬赏帖子 <a href=\"{0}\">{1}</a>,扣除积分", alink.ToAppData( topic ), topic.Title );
incomeService.AddIncome( user, KeyCurrency.Instance.Id, -topic.Reward, msg );
}
else {
incomeService.AddIncome( user, UserAction.Forum_CreateTopic.Id );
String msg = string.Format( "发布主题 <a href=\"{0}\">{1}</a>,得到奖励", alink.ToAppData( topic ), topic.Title );
incomeService.AddIncome( user, UserAction.Forum_CreateTopic.Id, msg );
}

addFeedInfo( topic );


return result;
}

Expand Down Expand Up @@ -613,7 +619,8 @@ public virtual void DeleteTrue( ForumTopic topic, User viewer, String ip ) {

// 更新作者的收入
if (creatorId > 0) { // 规避已注销用户
incomeService.AddIncome( topic.Creator, UserAction.Forum_TopicDeleted.Id );
String msg = string.Format( "主题被删除<a href=\"{0}\">{1}</a>", alink.ToAppData( topic ), topic.Title );
incomeService.AddIncome( topic.Creator, UserAction.Forum_TopicDeleted.Id, msg );
}

logService.AddTopic( viewer, topic.AppId, topic.Id, ForumLogAction.DeleteTrue, ip );
Expand Down Expand Up @@ -702,15 +709,19 @@ public virtual void Move( int targetForumId, String idList ) {
public virtual void Lock( ForumTopic topic, User user, String ip ) {
topic.IsLocked = 1;
db.update( topic, "IsLocked" );
incomeService.AddIncome( topic.Creator, UserAction.Forum_TopicLocked.Id );

String msg = string.Format( "帖子被锁定 <a href=\"{0}\">{1}</a>", alink.ToAppData( topic ), topic.Title );
incomeService.AddIncome( topic.Creator, UserAction.Forum_TopicLocked.Id, msg );

logService.AddTopic( user, topic.AppId, topic.Id, ForumLogAction.Lock, ip );
}

public virtual void UnLock( ForumTopic topic, User user, String ip ) {
topic.IsLocked = 0;
db.update( topic, "IsLocked" );
incomeService.AddIncomeReverse( topic.Creator, UserAction.Forum_TopicLocked.Id );

String msg = string.Format( "帖子取消锁定 <a href=\"{0}\">{1}</a>", alink.ToAppData( topic ), topic.Title );
incomeService.AddIncomeReverse( topic.Creator, UserAction.Forum_TopicLocked.Id, msg );
logService.AddTopic( user, topic.AppId, topic.Id, ForumLogAction.UnLock, ip );
}

Expand Down Expand Up @@ -740,17 +751,18 @@ public virtual void SetGloablStickyUndo( int appId, String ids ) {

//--------------------------------------- income -----------------------------------------

public virtual void AddAuthorIncome( String condition, int actionId ) {
public virtual void AddAuthorIncome( String condition, int actionId, String actionName ) {
List<ForumTopic> topics = db.find<ForumTopic>( condition ).list();
foreach (ForumTopic topic in topics) {
incomeService.AddIncome( topic.Creator, actionId );
String msg = string.Format( "帖子被{0} <a href=\"{1}\">{2}</a>", actionName, alink.ToAppData( topic ), topic.Title ); incomeService.AddIncome( topic.Creator, actionId, msg );
}
}

public virtual void SubstractAuthorIncome( String condition, int actionId ) {
public virtual void SubstractAuthorIncome( String condition, int actionId, String actionName ) {
List<ForumTopic> topics = db.find<ForumTopic>( condition ).list();
foreach (ForumTopic topic in topics) {
incomeService.AddIncomeReverse( topic.Creator, actionId );
String msg = string.Format( "帖子被{0} <a href=\"{1}\">{2}</a>", actionName, alink.ToAppData( topic ), topic.Title );
incomeService.AddIncomeReverse( topic.Creator, actionId, msg );
}
}

Expand Down
3 changes: 2 additions & 1 deletion wojilu.Controller/Forum/Moderators/PostSaveController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ public void SaveCredit( int id ) {
int currencyValue = ctx.PostInt( "CurrencyValue" );
if (((currencyValue != 0) && (currencyValue >= -rateMaxValue)) && (currencyValue <= rateMaxValue)) {
postService.SetPostCredit( post, ctx.PostInt( "CurrencyId" ), currencyValue, ctx.Post( "Reason" ), (User)ctx.viewer.obj );
userIncomeService.AddIncome( post.Creator, ctx.PostInt( "CurrencyId" ), currencyValue );
String msg = string.Format( "帖子被评分 <a href=\"{0}\">{1}</a>", alink.ToAppData( post ), post.Title );
userIncomeService.AddIncome( post.Creator, ctx.PostInt( "CurrencyId" ), currencyValue, msg );
echoRedirect( lang( "opok" ) );
}
else {
Expand Down
14 changes: 7 additions & 7 deletions wojilu.Controller/Forum/Moderators/TopicSaveController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public override void CheckPermission() {
public void Sticky() {
int id = ctx.GetInt( "boardId" );
topicService.AdminUpdate( "set Status=" + TopicStatus.Sticky, condition );
topicService.AddAuthorIncome( condition, UserAction.Forum_TopicSticky.Id );
topicService.AddAuthorIncome( condition, UserAction.Forum_TopicSticky.Id, "置顶" );
log( condition, ForumLogAction.Sticky );
echoToParent( lang( "opok" ) );
}
Expand All @@ -50,7 +50,7 @@ public void Sticky() {
public void StickyUndo() {
int id = ctx.GetInt( "boardId" );
topicService.AdminUpdate( "set Status=" + TopicStatus.Normal, condition );
topicService.SubstractAuthorIncome( condition, UserAction.Forum_TopicSticky.Id );
topicService.SubstractAuthorIncome( condition, UserAction.Forum_TopicSticky.Id, "取消置顶" );
log( condition, ForumLogAction.UnSticky );
echoAjaxOk();
}
Expand All @@ -75,7 +75,7 @@ public void GlobalStickyUndo() {
public void Pick() {
int id = ctx.GetInt( "boardId" );
topicService.AdminUpdate( "set IsPicked=1", condition );
topicService.AddAuthorIncome( condition, UserAction.Forum_TopicPicked.Id );
topicService.AddAuthorIncome( condition, UserAction.Forum_TopicPicked.Id, "加为精华" );
log( condition, ForumLogAction.Pick );
echoToParent( lang( "opok" ) );
}
Expand All @@ -84,7 +84,7 @@ public void Pick() {
public void PickedUndo() {
int id = ctx.GetInt( "boardId" );
topicService.AdminUpdate( "set IsPicked=0", condition );
topicService.SubstractAuthorIncome( condition, UserAction.Forum_TopicPicked.Id );
topicService.SubstractAuthorIncome( condition, UserAction.Forum_TopicPicked.Id, "取消精华" );
log( condition, ForumLogAction.UnPick );
echoAjaxOk();
}
Expand Down Expand Up @@ -112,7 +112,7 @@ public void HighlightUndo() {
public void Lock() {
int id = ctx.GetInt( "boardId" );
topicService.AdminUpdate( "set IsLocked=1", condition );
topicService.SubstractAuthorIncome( condition, UserAction.Forum_TopicLocked.Id );
topicService.SubstractAuthorIncome( condition, UserAction.Forum_TopicLocked.Id, "锁定" );
log( condition, ForumLogAction.Lock );
echoToParent( lang( "opok" ) );
}
Expand All @@ -121,7 +121,7 @@ public void Lock() {
public void LockUndo() {
int id = ctx.GetInt( "boardId" );
topicService.AdminUpdate( "set IsLocked=0", condition );
topicService.AddAuthorIncome( condition, UserAction.Forum_TopicLocked.Id );
topicService.AddAuthorIncome( condition, UserAction.Forum_TopicLocked.Id, "取消锁定" );
log( condition, ForumLogAction.UnLock );
echoAjaxOk();
}
Expand All @@ -130,7 +130,7 @@ public void LockUndo() {
public void Delete() {
int id = ctx.GetInt( "boardId" );
topicService.DeleteListToTrash( idList );
topicService.SubstractAuthorIncome( condition, UserAction.Forum_TopicDeleted.Id );
topicService.SubstractAuthorIncome( condition, UserAction.Forum_TopicDeleted.Id, "删除" );
log( idList, ForumLogAction.Delete );
echoToParent( lang( "opok" ) );
}
Expand Down
45 changes: 14 additions & 31 deletions wojilu.Controller/Users/Admin/CreditController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,15 @@ public CreditController() {

public override void Layout() {
set( "keyIncomeLink", to( My ) );
set( "incomeLogLink", to( IncomeLogLink ) );
set( "ruleLink", to( IncomeRule ) );
set( "rankLink", to( Rank ) );
//set( "postLink", to( Posts ) );
set( "incomeLink", to( IncomeLog, 0 ) );
}

public void My() {

User user = ctx.owner.obj as User;

set( "user.Credit", user.Credit );
set( "user.Name", user.Name );

set( "user.RoleName", user.Role.Name );
Expand All @@ -61,24 +59,31 @@ public void My() {
bindList( "list", "c", incomes );
}

private static readonly int tempKeyCurrencyId = 99999999;


public void IncomeLogLink() {
public void IncomeLog( int currencyId ) {

User user = ctx.owner.obj as User;

DataPage<UserIncomeLog> logs = incomeService.GetUserIncomeLog( user.Id );
bindList( "list", "c", logs.Results );
if (currencyId == 0) currencyId = -1;
if (currencyId == tempKeyCurrencyId) currencyId = 0;

DataPage<UserIncomeLog> logs = incomeService.GetUserIncomeLog( user.Id, currencyId );
bindList( "list", "x", logs.Results, bindCurrencyLink );
set( "pager", logs.PageBar );
}

public void IncomeRule() {
private void bindCurrencyLink( IBlock block, String lbl, Object data ) {
UserIncomeLog x = data as UserIncomeLog;
int currencyId = x.CurrencyId == 0 ? tempKeyCurrencyId : x.CurrencyId;
block.Set( "x.CurrencyLink", to( IncomeLog, currencyId ) );
}

public void IncomeRule() {

IList currencyList = currencyService.GetCurrencyAll();
IList actions = currencyService.GetUserActions();


StringBuilder builder = new StringBuilder();
builder.Append( "<table style='width:100%;' id='dataAdminList' cellspacing='0'>" );

Expand Down Expand Up @@ -141,28 +146,6 @@ public void Rank() {
}
}

//public void Posts() {


// User user = ctx.owner.obj as User;

// ForumBoard b = new ForumBoard();

// ForumPost p = new ForumPost();
// IPageList posts = p.findPage( "Creator.Id=" + user.Id );
// IBlock block = getBlock( "list" );
// foreach (ForumPost post in posts.Results) {
// block.Set( "post.Title", post.Title );
// block.Set( "post.Created", post.Created );
// block.Set( "post.LinkShow", alink.ToAppData( post ) );

// ForumBoard board = b.findById( post.ForumBoardId ) as ForumBoard;
// block.Set( "post.BoardName", board.Name );
// block.Set( "post.BoardLink", alink.ToAppData( board ) );
// block.Next();
// }
// set( "pager", posts.PageBar );
//}

}

Expand Down
1 change: 1 addition & 0 deletions wojilu.Core/Common/Money/Domain/UserIncomeLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class UserIncomeLog : ObjectBase<UserIncomeLog> {
[NotSave]
public String CurrencyName {
get {
if (this.CurrencyId == 0) return KeyCurrency.Instance.Name;
Currency c = cdb.findById<Currency>( this.CurrencyId );
return c == null ? "" : c.Name;
}
Expand Down
Loading

0 comments on commit a1f4215

Please sign in to comment.