91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

nodejs之egg框架mysql應用

發布時間:2020-07-25 08:35:28 來源:網絡 閱讀:886 作者:小涴熊 欄目:web開發

config/plugin.js

mysql: {
    enable: true,
    package: 'egg-mysql',
}

config/config.default.js

config.mysql = {
        client: {
            host: '127.0.0.1',
            port: '3306',
            user: 'devuser',
            password: 'devuser123',
            database: 'db_co_lottery',
        },
        // 是否加載到 app 上,默認開啟
        app: true,
        // 是否加載到 agent 上,默認關閉
        agent: false
 };

service類

'use strict';
const Service = require('egg').Service;
class NumberService extends Service {
    /**
     * 獲取所有Number
     * @returns {Promise<Array>}
     */
    async getAllNumbers() {
        let sql = 'SELECT zodiac,zodiac_img,punching FROM t_luckdraw_numbers GROUP BY zodiac,zodiac_img,punching ORDER BY sort';
        let res = await this.app.mysql.query(sql);
        let result = [];
        let sqlt = 'SELECT * FROM t_luckdraw_numbers WHERE zodiac = ? ORDER BY sort ASC';
        for (let i = 0; i < res.length; i++) {
            let object = {zodiac: res[i].zodiac, zodiac_img: res[i].zodiac_img, punching: res[i].punching};
            let numbers = await this.app.mysql.query(sqlt, res[i].zodiac);
            let numberArr = [];
            for (let j = 0; j < numbers.length; j++) {
                let numObj = {
                    number: numbers[j].number,
                    wave_color: numbers[j].wave_color,
                    five_elements: numbers[j].five_elements,
                    single_double: numbers[j].single_double,
                    big_small: numbers[j].big_small
                };
                numberArr.push(numObj);
            }
            object['numbers'] = numberArr;
            result.push(object);
        }
        return result;
    }

    /**
     * 獲取開獎結果
     * @returns {Promise<void>}
     */
    async getLastResult() {
        let sql = 'SELECT lr.*,ln.wave_color FROM t_luckdraw_result lr LEFT JOIN t_luckdraw_numbers ln ON ln.number = lr.number WHERE lr.number IS NOT NULL ORDER BY lr.stage DESC LIMIT 0,1';
        let res = await this.app.mysql.query(sql);
        var result = {};
        result['this_stage'] = res[0].stage;
        result['this_number'] = res[0].number;
        result['this_wave_color'] = res[0].wave_color;
        sql = 'SELECT * FROM t_luckdraw_result WHERE number IS NULL ORDER BY create_time DESC LIMIT 0,1';
        res = await this.app.mysql.query(sql);
        result['next_stage'] = res[0].stage;
        result['next_time'] = this.ctx.helper.formatTime(res[0].end_time);
        result['next_time_format'] = this.ctx.helper.formatTime(res[0].end_time, 'MM月DD日HH時mm分');
        result['next_week'] = this.ctx.helper.getWeekOfDate(res[0].end_time);
        return result;
    }

    async getNumberInfo(numbers) {
        const sql = 'SELECT * FROM t_luckdraw_numbers WHERE number IN(' + numbers + ')';
        const result = await this.app.mysql.query(sql);
        return result;
    }
}

module.exports = NumberService;

controller類

'use strict';

const Controller = require('egg').Controller;

class NumberController extends Controller {

    async getNumbers() {
        const {ctx, service} = this;
        let result = await service.number.getAllNumbers();
        ctx.body = result;
        ctx.status = 200;
    }

    async getLuckdrawResult() {
        const {ctx, service} = this;
        let result = await service.number.getLastResult();
        ctx.body = result;
        ctx.status = 200;
    }

    async getNumberInfo() {
        const {ctx, service} = this;
        const numbers = this.ctx.request.query.numbers;
        if (numbers == null || numbers.split(',').length <= 0) {
            ctx.body = {
                msg: '參數有誤'
            }
            return ctx.body;
        }
        let result = await service.number.getNumberInfo(numbers);
        ctx.body = result;
    }
}

module.exports = NumberController;
向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

新疆| 屯昌县| 五峰| 海丰县| 稻城县| 高陵县| 英德市| 邹城市| 云和县| 大荔县| 铜鼓县| 栾城县| 崇州市| 车险| 汉川市| 青铜峡市| 荆门市| 九寨沟县| 巴马| 南召县| 平顶山市| 广汉市| 姚安县| 特克斯县| 河北区| 河津市| 桦甸市| 巴彦淖尔市| 宝丰县| 东阳市| 瓦房店市| 沧州市| 鹿泉市| 长武县| 巫溪县| 政和县| 镶黄旗| 白水县| 上思县| 云林县| 恩施市|