add admin/live/goods/update

FFIB 5 年 前
コミット
cd181bdd80
共有2 個のファイルを変更した59 個の追加0 個の削除を含む
  1. 58 0
      api/admin_views.py
  2. 1 0
      api/urls.py

+ 58 - 0
api/admin_views.py

@@ -228,6 +228,63 @@ def live_goods_create(request):
228 228
     })
229 229
 
230 230
 @logit(res=True)
231
+def live_goods_update(request):
232
+    admin_id = request.POST.get('admin_id', '')
233
+    goods_id = request.POST.get('goods_id', '')
234
+    price_type = int(request.POST.get('price_type', 1))
235
+    price = int(request.POST.get('price', 0))
236
+    price2 = int(request.POST.get('price2', 0))
237
+
238
+    try:
239
+        administrator = AdministratorInfo.objects.get(admin_id=admin_id, user_status=AdministratorInfo.ACTIVATED, status=True)
240
+    except AdministratorInfo.DoesNotExist:
241
+        return response(AdministratorStatusCode.ADMINISTRATOR_NOT_FOUND)
242
+    
243
+
244
+    goods_info = liveGoodsInfo.objects.get(goods_id=goods_id, status=True)
245
+
246
+    wxcfg = WECHAT.get('MINIAPP', {})
247
+
248
+    appid = wxcfg.get('appID')
249
+    secret = wxcfg.get('appsecret')
250
+    token = access_token(appid, secret)
251
+
252
+    media = requests.post(url=('https://api.weixin.qq.com/cgi-bin/media/upload?access_token=' + token + '&type=image'), files={'media': open(settings.MEDIA_ROOT + '/' + goods_info.goods_img_path, 'rb')}).text
253
+    media_id = json.loads(media).get('media_id', '')
254
+
255
+    if media_id == '':
256
+        return response()
257
+
258
+    data ={
259
+        "goodsInfo": {
260
+            'goodsId': goods_info.wx_goods_id,
261
+            'name': goods_info.name,
262
+            'coverImgUrl': media_id,
263
+            'priceType': price_type,
264
+            'price': price,
265
+            'price2': price2,
266
+            'url': 'pages/live/order/order?goods_id=' + goods_id,
267
+        }
268
+    } 
269
+
270
+    wx_goods = requests.post(url=('https://api.weixin.qq.com/wxaapi/broadcast/goods/update?access_token=' + token), json=data).text
271
+    errcode = json.loads(wx_goods).get('errcode', -1)
272
+
273
+    if errcode != 0:
274
+        return response(errcode, 'Live Goods Update Fail', u'直播商品库更新失败')
275
+
276
+    goods_info.price_type = price_type
277
+    goods_info.price = price * 100
278
+    goods_info.price2 = price2 * 100
279
+    goods_info.coverImgUrl = media_id
280
+    goods_info.save()
281
+    
282
+
283
+    return response(200, 'Live Goods Update Success', u'直播商品库更新成功', data={
284
+        'goods': goods_info.admindata,
285
+    })
286
+
287
+@logit(res=True)
231 288
 def live_goods_audit(request):
232 289
     admin_id = request.POST.get('admin_id', '')
233 290
     try:
@@ -259,6 +316,7 @@ def live_goods_audit(request):
259 316
     return response(200, 'Live Goods Audit Success', '获取直播商品库审核状态成功') 
260 317
 
261 318
 
319
+
262 320
 @logit(res=True)
263 321
 def live_goods_delete(request):
264 322
     admin_id = request.POST.get('admin_id', '')

+ 1 - 0
api/urls.py

@@ -48,6 +48,7 @@ urlpatterns += [
48 48
     # 直播
49 49
     url(r'^admin/live/goods/list$', admin_views.live_goods_list, name='live_goods_list'),   # 直播商品库列表
50 50
     url(r'^admin/live/goods/create$', admin_views.live_goods_create, name='live_goods_create'),
51
+    url(r'^admin/live/goods/update$', admin_views.live_goods_update, name='live_goods_update'),
51 52
     url(r'^admin/live/goods/delete$', admin_views.live_goods_delete, name='live_goods_delete'),
52 53
     url(r'^admin/live/goods/audit$', admin_views.live_goods_audit, name='live_goods_audit'),
53 54