123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- 'use strict';
- const shopController = require('./shop.js');
- // 合作餐厅控制器
- module.exports = class PartnerInfoController extends shopController {
- // 使用模型
- get useModel() {
- const that = this;
- return that.app.model.PartnerInfo;
- }
- /**
- * [selectValidate 查询合作餐店]
- * @return {[type]} [description]
- */
- get selectValidate() {
- const that = this;
- return {
- /* user_id: that.ctx.rules.default(that.service.shop.getWebUserId())
- .number(),*/
- county_name: that.ctx.rules.default('市辖区')
- .trim(),
- };
- }
- /**
- * [select 所有餐店列表]
- * @return {[type]} [description]
- */
- async selectAll() {
- const that = this;
- try {
- const options = {
- where: { online: true },
- order: [[ 'top', 'desc' ], [ 'order_amount', 'desc' ]],
- };
- const selectBean = await that.app.comoBean.instance({}, options);
- const result = await that.service.base.select(selectBean, that.useModel, '合作餐店查询失败,请稍候重试', true, true);
- return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', result, false));
- } catch (err) {
- return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', false, false));
- }
- }
- /**
- * [select 餐店列表]
- * @return {[type]} [description]
- */
- async select() {
- const that = this;
- try {
- const data = await that.ctx.validate(that.selectValidate, await that.ctx.getParse());
- const options = {
- where: { county_name: data.county_name, online: true },
- order: [[ 'top', 'desc' ], [ 'order_amount', 'desc' ]],
- };
- const selectBean = await that.app.comoBean.instance(data, options);
- const result = await that.service.base.select(selectBean, that.useModel, '合作餐店查询失败,请稍候重试', true, true);
- return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', result, false));
- } catch (err) {
- return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', false, false));
- }
- }
- /*
- async create() {
- const that = this;
- try {
- const data = await that.ctx.validate(that.createValidate, await that.ctx.postParse());
- const createBean = await that.app.comoBean.instance(data);
- const result = await that.service.base.create(createBean, that.useModel, '添加合作餐店失败,请重试');
- return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', result, false));
- } catch (err) {
- return that.ctx.appJson(that.app.szjcomo.appResult(err.message));
- }
- }
- async update() {
- const that = this;
- try {
- const data = await that.ctx.validate(that.updateValidate, await that.ctx.anyParse());
- if (data.fore) {
- const updateBean = await that.app.comoBean.instance({
- is_use: 0,
- update_time: that.app.szjcomo.date('Y-m-d H:i:s'),
- }, { where: { user_id: data.user_id } });
- await that.service.base.update(updateBean, that.useModel, '更新合作餐店失败,请重试');
- }
- const options = { where: { user_id: data.user_id, address_id: data.address_id } };
- const updateBean = await that.app.comoBean.instance(data, options);
- const result = await that.service.base.update(updateBean, that.useModel, '更新合作餐店失败,请稍候重试');
- return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', result, false));
- } catch (err) {
- return that.ctx.appJson(that.app.szjcomo.appResult(err.message));
- }
- }
- async delete() {
- const that = this;
- try {
- const data = await that.ctx.validate(that.deleteValidate, await that.ctx.anyParse());
- const options = { where: { user_id: data.user_id, address_id: data.address_id } };
- const deleteBean = await that.app.comoBean.instance(data, options);
- const result = await that.service.base.delete(deleteBean, that.useModel, '删除合作餐店失败,请稍候重试');
- return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', result, false));
- } catch (err) {
- return that.ctx.appJson(that.app.szjcomo.appResult(err.message));
- }
- }
- */
- };
|