shop.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. 'use strict';
  2. import ShopModel from '../../models/shopping/shop';
  3. import AddressComponent from '../../prototype/addressComponent'
  4. import formidable from 'formidable'
  5. class Shop extends AddressComponent{
  6. constructor(){
  7. super()
  8. this.addShop = this.addShop.bind(this);
  9. }
  10. async addShop(req, res, next){
  11. let shopId;
  12. try{
  13. shopId = await this.getId('shopId');
  14. }catch(err){
  15. res.send({
  16. type: 'ERROR_DATA',
  17. message: '获取数据失败'
  18. })
  19. return
  20. }
  21. const form = new formidable.IncomingForm();
  22. form.uploadDir = './img/shop';
  23. form.parse(req, async (err, fields, files) => {
  24. try{
  25. if (!fields.name) {
  26. throw new Error('必须填写商店名称');
  27. }else if(!fields.address){
  28. throw new Error('必须填写商店地址');
  29. }else if(!fields.phone){
  30. throw new Error('必须填写联系电话');
  31. }else if(!fields.latitude || !fields.longitude){
  32. throw new Error('商店位置信息错误');
  33. }
  34. }catch(err){
  35. res.send({
  36. type: 'ERROR_PARAMS',
  37. message: err.message
  38. })
  39. return
  40. }
  41. const opening_hours = fields.startTime&&fields.endTime? fields.startTime + '/' + fields.endTime : "8:30/20:30";
  42. const newShop = {
  43. name: fields.name,
  44. address: fields.address,
  45. description: fields.description || '',
  46. float_delivery_fee: fields.float_delivery_fee || 0,
  47. float_minimum_order_amount: fields.float_minimum_order_amount || 0,
  48. id: shopId,
  49. is_premium: fields.is_premium || false,
  50. is_new: fields.new || false,
  51. latitude: 31.056997,
  52. longitude: 121.396113,
  53. opening_hours: [opening_hours],
  54. phone: fields.phone,
  55. promotion_info: fields.promotion_info || "欢迎光临,用餐高峰请提前下单,谢谢",
  56. rating: (Math.random()*5).toFixed(1),
  57. rating_count: Math.ceil(Math.random()*1000),
  58. recent_order_num: Math.ceil(Math.random()*1000),
  59. status: Math.round(Math.random()),
  60. image_path: fields.image_path,
  61. piecewise_agent_fee: {
  62. tips: "配送费约¥" + (fields.float_delivery_fee || 0),
  63. },
  64. activities: [],
  65. supports: [],
  66. license: {
  67. business_license_image: fields.business_license_image || '',
  68. catering_service_license_image: fields.catering_service_license_image || '',
  69. },
  70. identification: {
  71. company_name: "",
  72. identificate_agency: "",
  73. identificate_date: "",
  74. legal_person: "",
  75. licenses_date: "",
  76. licenses_number: "",
  77. licenses_scope: "",
  78. operation_period: "",
  79. registered_address: "",
  80. registered_number: "",
  81. },
  82. }
  83. if (fields.delivery_mode) {
  84. Object.assign(newShop, {delivery_mode: {
  85. color: "57A9FF",
  86. id: 1,
  87. is_solid: true,
  88. text: "蜂鸟专送"
  89. }})
  90. }
  91. fields.activities.forEach((item, index) => {
  92. switch(item.icon_name){
  93. case '减':
  94. item.icon_color = 'f07373';
  95. item.id = index + 1;
  96. break;
  97. case '特':
  98. item.icon_color = 'EDC123';
  99. item.id = index + 1;
  100. break;
  101. case '新':
  102. item.icon_color = '70bc46';
  103. item.id = index + 1;
  104. break;
  105. case '领':
  106. item.icon_color = 'E3EE0D';
  107. item.id = index + 1;
  108. break;
  109. }
  110. newShop.activities.push(item);
  111. })
  112. if (fields.bao) {
  113. newShop.supports.push({
  114. description: "已加入“外卖保”计划,食品安全有保障",
  115. icon_color: "999999",
  116. icon_name: "保",
  117. id: 7,
  118. name: "外卖保"
  119. })
  120. }
  121. if (fields.zhun) {
  122. newShop.supports.push({
  123. description: "准时必达,超时秒赔",
  124. icon_color: "57A9FF",
  125. icon_name: "准",
  126. id: 9,
  127. name: "准时达"
  128. })
  129. }
  130. if (fields.piao) {
  131. newShop.supports.push({
  132. description: "该商家支持开发票,请在下单时填写好发票抬头",
  133. icon_color: "999999",
  134. icon_name: "票",
  135. id: 4,
  136. name: "开发票"
  137. })
  138. }
  139. console.log(newShop)
  140. res.send(newShop)
  141. return
  142. })
  143. }
  144. }
  145. export default new Shop()