Commit b53cae26f99229f9a5c7cb7b8b12fa876d930c3f
1 parent
55cbd78d
Exists in
master
增加一些方法
Showing
3 changed files
with
32 additions
and
11 deletions
Show diff stats
app/service/contract.js
| ... | ... | @@ -3,7 +3,6 @@ |
| 3 | 3 | const Service = require('egg').Service; |
| 4 | 4 | const objExclude = require('../util/common').objExclude; |
| 5 | 5 | const objToQuery = require('../util/common').objToQuery; |
| 6 | -const moment = require('moment'); | |
| 7 | 6 | |
| 8 | 7 | class ContractService extends Service { |
| 9 | 8 | async count() { |
| ... | ... | @@ -11,22 +10,18 @@ class ContractService extends Service { |
| 11 | 10 | return result; |
| 12 | 11 | } |
| 13 | 12 | async add(data) { |
| 14 | - const value = data; | |
| 15 | - value.create_time = moment().format('YYYY-MM-DD HH:mm:ss'); | |
| 16 | - const result = await this.app.mysql.insert('contract', value); | |
| 13 | + const result = await this.app.mysql.insert('contract', data); | |
| 17 | 14 | return result; |
| 18 | 15 | } |
| 19 | 16 | async update(data) { |
| 20 | - const value = data; | |
| 21 | - value.update_time = moment().format('YYYY-MM-DD HH:mm:ss'); | |
| 22 | - const result = await this.app.mysql.update('contract', value); | |
| 17 | + const result = await this.app.mysql.update('contract', data); | |
| 23 | 18 | return result; |
| 24 | 19 | } |
| 25 | 20 | async find(id) { |
| 26 | 21 | // const user = await this.app.mysql.get('contract', { id }); |
| 27 | 22 | const user = await this.app.mysql.query(` |
| 28 | - select id, customer_id, number, value, product, invoice, date_format(invoice_time, '%Y-%m-%d') as invoice_time, | |
| 29 | - method, date_format(method_time, '%Y-%m-%d') as method_time, other_expenses, remark, type, create_time, update_time | |
| 23 | + select id, customer_id, number, name, value, product, invoice, date_format(invoice_time, '%Y-%m-%d') as invoice_time, | |
| 24 | + method, date_format(method_time, '%Y-%m-%d') as method_time, other_expenses, remark, type | |
| 30 | 25 | from contract where id = ? |
| 31 | 26 | `, [ id ]); |
| 32 | 27 | const result = user && user.length > 0 ? user[0] : {}; | ... | ... |
app/service/project.js
| ... | ... | @@ -2,6 +2,7 @@ |
| 2 | 2 | |
| 3 | 3 | const Service = require('egg').Service; |
| 4 | 4 | const objExclude = require('../util/common').objExclude; |
| 5 | +const moment = require('moment'); | |
| 5 | 6 | |
| 6 | 7 | class ProjectService extends Service { |
| 7 | 8 | async count() { |
| ... | ... | @@ -9,11 +10,20 @@ class ProjectService extends Service { |
| 9 | 10 | return result; |
| 10 | 11 | } |
| 11 | 12 | async add(data) { |
| 12 | - const result = await this.app.mysql.insert('project', data); | |
| 13 | + const value = data; | |
| 14 | + value.create_time = moment().format('YYYY-MM-DD HH:mm:ss'); | |
| 15 | + const todayCountResult = await this.app.mysql.query('select count(*) as count from project where create_time like ?', [ `%${moment().format('YYYY-MM-DD')}%` ]); | |
| 16 | + const todayCount = todayCountResult && todayCountResult.length > 0 ? todayCountResult[0].count : 0; | |
| 17 | + const count = Number(todayCount) + 1; | |
| 18 | + const number = `SF${moment().format('YYYYMMDD')}${count > 9 ? count : `0${count}`}`; | |
| 19 | + value.number = number; | |
| 20 | + const result = await this.app.mysql.insert('project', value); | |
| 13 | 21 | return result; |
| 14 | 22 | } |
| 15 | 23 | async update(data) { |
| 16 | - const result = await this.app.mysql.update('project', data); | |
| 24 | + const value = data; | |
| 25 | + value.update_time = moment().format('YYYY-MM-DD HH:mm:ss'); | |
| 26 | + const result = await this.app.mysql.update('project', value); | |
| 17 | 27 | return result; |
| 18 | 28 | } |
| 19 | 29 | async find(id) { | ... | ... |
app/service/statistic.js
| ... | ... | @@ -17,6 +17,22 @@ class StatisticService extends Service { |
| 17 | 17 | `); |
| 18 | 18 | return result && result.length > 0 ? result[0] : {}; |
| 19 | 19 | } |
| 20 | + async projectAnalysis() { | |
| 21 | + const result = await this.app.mysql.query(` | |
| 22 | + select | |
| 23 | + project.number, | |
| 24 | + project.name, | |
| 25 | + s_contract.value as s_value, | |
| 26 | + s_contract.other_expenses as s_other_expenses, | |
| 27 | + s_contract.invoice as s_invoice, | |
| 28 | + p_contract.value as p_value, | |
| 29 | + p_contract.other_expenses as p_other_expenses, | |
| 30 | + p_contract.invoice as p_invoice | |
| 31 | + from project, contract as s_contract, contract as p_contract | |
| 32 | + where project.sale_contract_id = s_contract.id and project.purchase_contract_id = p_contract.id | |
| 33 | + `); | |
| 34 | + return result; | |
| 35 | + } | |
| 20 | 36 | } |
| 21 | 37 | |
| 22 | 38 | module.exports = StatisticService; | ... | ... |