farm.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. demeter web
  5. name:farm.py 农场相关
  6. author:rabin
  7. """
  8. from __load__ import *
  9. class index_path(Load):
  10. """
  11. @api {get} /farm 获取农场基本信息
  12. @apiVersion 1.0.0
  13. @apiName getFarm
  14. @apiGroup Farm
  15. @apiSuccess {Object[]} setting 基本信息
  16. @apiSuccess {String} setting.name 站点名
  17. @apiSuccess {Number} setting.farm 当前的农场ID
  18. @apiSuccess {Object[]} farm 农场基本信息
  19. @apiSuccess {String} farm.name 农场名
  20. @apiSuccess {String} farm.master_name 联系人
  21. @apiSuccess {String} farm.tel 联系电话
  22. @apiSuccess {String} farm.address 农场地址
  23. @apiErrorExample 操作成功
  24. {"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/"}}}
  25. @apiErrorExample 操作失败
  26. {"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
  27. """
  28. @auth
  29. def get(self):
  30. # 获取农场信息
  31. self.data['farm'] = self.service('common').one('farm', id=Demeter.config['setting']['farm'])
  32. self.out('yes', self.data)
  33. """
  34. @api {post} /farm 更新农场信息
  35. @apiVersion 1.0.0
  36. @apiName updateFarm
  37. @apiGroup Farm
  38. @apiParam {String} id 农事ID,为空则插入新记录
  39. @apiParam {String} update_name 农场名称
  40. @apiParam {String} update_address 农场地址
  41. @apiParam {String} update_master_name 联系人
  42. @apiParam {String} update_tel 联系电话
  43. @apiParam {String} update_pic 农场照片
  44. @apiSuccess {Bool} status 状态
  45. @apiSuccess {String} msg 描述
  46. @apiSuccess {Number} code 状态码
  47. @apiErrorExample 操作成功
  48. {"status": 1, "msg": "操作成功", "code": 0, "data": {}}
  49. @apiErrorExample 操作失败
  50. {"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
  51. """
  52. @auth
  53. def post(self):
  54. id = self.input('id', None)
  55. update = {}
  56. update['pic'] = self.input('update_pic')
  57. update['name'] = self.input('update_name')
  58. update['master_name'] = self.input('update_master_name')
  59. update['address'] = self.input('update_address')
  60. update['tel'] = self.input('update_tel')
  61. if not update['name']:
  62. self.out(u'请输入农场名称')
  63. return
  64. if not update['master_name']:
  65. self.out(u'请输入农场联系人')
  66. return
  67. if not update['address']:
  68. self.out(u'请输入农场地址')
  69. return
  70. if not update['tel']:
  71. self.out(u'请输入联系电话')
  72. return
  73. state = self.service('common').update('farm', id, update)
  74. self.out('yes', {'id':state})