module.exports = app => {
  class AccountService extends app.Service {
    constructor(ctx) {
      super(ctx);
    }
    * index() {
      const { pageNumber = 1, pageSize = 5 } = this.ctx.query;
      // const result = yield this.ctx.pagination(app.mysql, 'id, type, username, source_id', 'from vip_account order by modify_date desc', pageNumber, pageSize);
      const accounts = yield app.mysql.select('vip_account', {
        columns: ['id', 'type', 'username', 'source_id'],
        order: [['modify_date', 'desc'], ['id', 'desc']],
      });
      // return {
      //   list: result.list.map(account => {
      //     return {
      //       id: account.id,
      //       type: account.type,
      //       username: account.username,
      //       source_id: account.source_id,
      //     }
      //   }),
      //   pageInfo: {
      //     pageNumber: result.pageNumber,
      //     pageSize: result.pageSize,
      //   },
      // };
      return accounts.map(account => {
        return {
          id: account.id,
          type: account.type,
          username: this.ctx.hideStr(account.username, account.username.length >= 5 ? 2 : 0, account.username.length >= 5 ? account.username.length - 4 : account.username.length),
          source_id: account.source_id,
          editable: this.ctx.auth.user_id == account.source_id,
        }
      });
    }
    * show(id) {
      const account = yield app.mysql.get('vip_account', {
        id,
      });

      // view + 1
      yield app.mysql.query(`update vip_user_statistics set helpful_count = helpful_count + 1 where id = ${account.user_id}`)
      // todo alarm while updating vip_user_statistics failed.

      return account;
    }
    * viewable(id, password) {
      const account = yield app.mysql.get('vip_account', {
        id,
      });
      if (account == null) {
        return false;
      }
      return account.password === password;
    }
    * create(account) {
      const date = new Date();
      const conn = yield app.mysql.beginTransaction();
      try {
        const result = yield conn.insert('vip_account', {
          create_date: date,
          modify_date: date,
          source_id: this.ctx.auth.user_id,
          type: account.type,
          username: account.username,
          password: account.password,
          sharePass: account.sharePass,
        });
        if (result.affectedRows !== 1) {
          return false;
        }

        const result2 = yield conn.query(`update vip_user_statistics set shares_count = shares_count + 1 where id = ${result.insertId}`);
        if (result.affectedRows !== 1) {
          throw new Error('update statistics failed');
        }

        yield conn.commit();
      } catch (error) {
        yield conn.rollback();
        return false;
      }

      return true;
    }
  }
  return AccountService;
};

@@ -1484,16 +1484,74 @@
 iew + 1%0A
+      if (account.source_id != this.ctx.auth.user_id) %7B%0A  
       yi
@@ -1661,19 +1661,23 @@
 unt.
-user
+source
 _id%7D%60)%0A
+  
     
@@ -1735,16 +1735,23 @@
 failed.%0A
+      %7D
 %0A      r
@@ -1865,32 +1865,61 @@
 , %7B%0A        id,%0A
+        sharePass: password,%0A
       %7D);%0A      
@@ -1988,37 +1988,12 @@
 urn 
-account.password === password
+true
 ;%0A  

Fix viewable and statistics bug