12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- """
- demeter web
- name:farm.py 农场相关
- author:rabin
- """
- from __load__ import *
- class index_path(Load):
- """
- @api {get} /farm 获取农场基本信息
- @apiVersion 1.0.0
- @apiName getFarm
- @apiGroup Farm
- @apiSuccess {Object[]} setting 基本信息
- @apiSuccess {String} setting.name 站点名
- @apiSuccess {Number} setting.farm 当前的农场ID
- @apiSuccess {Object[]} farm 农场基本信息
- @apiSuccess {String} farm.name 农场名
- @apiSuccess {String} farm.master_name 联系人
- @apiSuccess {String} farm.tel 联系电话
- @apiSuccess {String} farm.address 农场地址
- @apiErrorExample 操作成功
- {"status": 1, "msg": "yes", "code": 0, "data": {"farm": {"info": "", "master_name": "", "tel": "", "name": "\u9ed8\u8ba4\u56ed\u533a", "pic": "", "cdate": 1503915445, "state": true, "address": "", "id": 1}, "setting": {"farm": 1, "user": 0, "name": "\u519c\u5c0f\u76d2", "copyright": "2017 nongxiaohe.com v1.0.0", "site": "http://www.nongxiaohe.com/"}}}
- @apiErrorExample 操作失败
- {"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
- """
- @auth
- def get(self):
- # 获取农场信息
- self.data['farm'] = self.service('common').one('farm', id=Demeter.config['setting']['farm'])
- self.out('yes', self.data)
- """
- @api {post} /farm 更新农场信息
- @apiVersion 1.0.0
- @apiName updateFarm
- @apiGroup Farm
- @apiParam {String} id 农事ID,为空则插入新记录
- @apiParam {String} update_name 农场名称
- @apiParam {String} update_address 农场地址
- @apiParam {String} update_master_name 联系人
- @apiParam {String} update_tel 联系电话
- @apiParam {String} update_pic 农场照片
- @apiSuccess {Bool} status 状态
- @apiSuccess {String} msg 描述
- @apiSuccess {Number} code 状态码
- @apiErrorExample 操作成功
- {"status": 1, "msg": "操作成功", "code": 0, "data": {}}
- @apiErrorExample 操作失败
- {"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
- """
- @auth
- def post(self):
- id = self.input('id', None)
- update = {}
- update['pic'] = self.input('update_pic')
- update['name'] = self.input('update_name')
- update['master_name'] = self.input('update_master_name')
- update['address'] = self.input('update_address')
- update['tel'] = self.input('update_tel')
- if not update['name']:
- self.out(u'请输入农场名称')
- return
- if not update['master_name']:
- self.out(u'请输入农场联系人')
- return
- if not update['address']:
- self.out(u'请输入农场地址')
- return
- if not update['tel']:
- self.out(u'请输入联系电话')
- return
- state = self.service('common').update('farm', id, update)
- self.out('yes', {'id':state})
|