farm.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. @Web.setting
  30. def get(self):
  31. # 获取农场信息
  32. self.data['farm'] = self.service('common').one('farm', id=Demeter.config['setting']['farm'])
  33. self.out('yes', self.data)
  34. """
  35. @api {post} /farm 更新农场信息
  36. @apiVersion 1.0.0
  37. @apiName updateFarm
  38. @apiGroup Farm
  39. @apiParam {String} id 农事ID,为空则插入新记录
  40. @apiParam {String} update_name 农场名称
  41. @apiParam {String} update_address 农场地址
  42. @apiParam {String} update_master_name 联系人
  43. @apiParam {String} update_tel 联系电话
  44. @apiParam {String} update_pic 农场照片
  45. @apiSuccess {Bool} status 状态
  46. @apiSuccess {String} msg 描述
  47. @apiSuccess {Number} code 状态码
  48. @apiErrorExample 操作成功
  49. {"status": 1, "msg": "操作成功", "code": 0, "data": {}}
  50. @apiErrorExample 操作失败
  51. {"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
  52. """
  53. @auth
  54. @Web.setting
  55. def post(self):
  56. id = self.input('id', None)
  57. update = {}
  58. update['pic'] = self.input('update_pic')
  59. update['name'] = self.input('update_name')
  60. update['master_name'] = self.input('update_master_name')
  61. update['address'] = self.input('update_address')
  62. update['tel'] = self.input('update_tel')
  63. if not update['name']:
  64. self.out(u'请输入农场名称')
  65. return
  66. """
  67. if not update['master_name']:
  68. self.out(u'请输入农场联系人')
  69. return
  70. if not update['address']:
  71. self.out(u'请输入农场地址')
  72. return
  73. if not update['tel']:
  74. self.out(u'请输入联系电话')
  75. return
  76. """
  77. state = self.service('common').update('farm', id, update, cdate=False)
  78. self.out('yes', {'id':state})
  79. class msg_path(Load):
  80. """
  81. @api {get} /farm/msg 获取消息通知
  82. @apiVersion 1.0.0
  83. @apiName getMsg
  84. @apiGroup Farm
  85. @apiParam {String} page 页数
  86. @apiSuccess {Object[]} setting 基本信息
  87. @apiSuccess {String} setting.name 站点名
  88. @apiSuccess {Number} setting.farm 当前的农场ID
  89. @apiSuccess {Object[]} list 消息列表
  90. @apiSuccess {Number} list.id 消息ID
  91. @apiSuccess {String} list.content 消息内容
  92. @apiSuccess {String} list.cdates 消息时间
  93. @apiSuccess {String} list.cdate 消息时间戳
  94. @apiSuccess {Object[]} page 分页信息
  95. @apiSuccess {String} page.current 当前页
  96. @apiSuccess {String} page.total 总页数
  97. @apiSuccess {String} page.num 每页数据条数
  98. @apiSuccess {String} page.totalNum 总数据条数
  99. @apiErrorExample 操作成功
  100. {"status": 1, "msg": "yes", "code": 0, "data": {"setting": {"farm": 1, "user": 0, "name": "\u519c\u5c0f\u76d2", "copyright": "2017 nongxiaohe.com v1.0.0", "site": "http://www.nongxiaohe.com/"}, "list": []}}
  101. @apiErrorExample 操作失败
  102. {"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
  103. """
  104. @auth
  105. @Web.setting
  106. def get(self):
  107. self.data['list'] = self.service('common').list('msg', search={'farm_id':self.data['setting']['farm']}, page=True, order='status asc, cdate desc')
  108. for key, value in enumerate(self.data['list']):
  109. self.data['list'][key]['cdates'] = Demeter.date(value['cdate'])
  110. type_info = self.service('common').one('msg_type', id=value['type_id'])
  111. self.data['list'][key]['type'] = type_info['name']
  112. id = value['id']
  113. update = {}
  114. update['status'] = True
  115. self.service('common').update('msg', id, update, cdate=False)
  116. self.out('yes', self.data)
  117. class qrcode_path(Load):
  118. @auth
  119. @Web.setting
  120. def get(self):
  121. url = self.input('url')
  122. url = Demeter.config['front']['qrcode_create'] + url
  123. data = Demeter.curl(url)
  124. self.write(data)
  125. self.set_header("Content-type", "image/jpg")