def get_calculate_profitrate(pSKU, currentprice, COUNTRY_CODE, Country, Location, currency):
    profitrate = ''
    try:
        calculate_price_obj = calculate_price(str(pSKU))
        if Country and Country != u'CN' and Location not in ZSHWCL:
            t_cfg_platform_country = u'EBAYXNHWC'
        elif Country and Country != u'CN' and Location in ZSHWCL:
            t_cfg_platform_country = u'EBAYZSHWC'
        else:
            b_goods_objs = b_goods.objects.filter(SKU=str(pSKU)).values('AttributeName')
            if len(b_goods_objs) > 0:
                AttributeName = b_goods_objs[0]['AttributeName']
                if AttributeName:
                    if u'特货' in AttributeName:
                        t_cfg_platform_country = u'EBAYGNZFTH'
                    else:
                        t_cfg_platform_country = u'EBAYGNZF'
                else:
                    t_cfg_platform_country = u'EBAYGNZF'
            else:
                t_cfg_platform_country = u'EBAYGNZF'
        profitrate_info = calculate_price_obj.calculate_profitRate(sellingPrice=currentprice,
                                                                   platformCountryCode=t_cfg_platform_country,
                                                                   DestinationCountryCode=COUNTRY_CODE,
                                                                   price_des=currentprice,
                                                                   currencycode=currency)
        profitrate = profitrate_info['profitRate']
    except:
        profitrate = ''
    return profitrate
示例#2
0
def get_mymall_profitrate(price, sku):
    sellingPrice = price.split('~')
    calculate_price_obj = calculate_price(sku)

    try:
        profitrate_min = calculate_price_obj.calculate_profitRate(
            sellingPrice[0],
            platformCountryCode='ALIEXPRESS-RUS',
            DestinationCountryCode='RUS')
    except:
        profitrate_min = ''
    if profitrate_min:
        min_profitrate = '%.2f' % float(profitrate_min['profitRate'])
    else:
        min_profitrate = ''

    try:
        profitrate_max = calculate_price_obj.calculate_profitRate(
            sellingPrice[0],
            platformCountryCode='ALIEXPRESS-RUS',
            DestinationCountryCode='RUS')
    except:
        profitrate_max = ''
    if profitrate_max:
        max_profitrate = '%.2f' % float(profitrate_max['profitRate'])
    else:
        max_profitrate = ''

    profitrate = min_profitrate + '% ~' + max_profitrate + '%'
    return profitrate
示例#3
0
def show_variants(obj, plateform, page):
    rt = u'<table  class="table table-condensed" >' \
         u'<tr bgcolor="#C00"><th>子SKU</th><th>店铺SKU</th><th>库存量</th><th>价格</th><th>运费</th>' \
         u'<th>利润率</th><th>状态</th><th style="text-align:center">普源状态</th></tr>'
    try:
        variantsList = eval(obj.Variants)
    except:
        variantsList = []
    num = 0
    for variant in variantsList:
        try:
            productSKU = re.findall('([A-Z0-9-]+)',
                                    str(variant['Variant']['productSKU']))[0]
        except:
            productSKU = variant['Variant']['productSKU']
        shopSKU = variant['Variant']['sku']
        inventory = variant['Variant']['inventory']
        price = variant['Variant']['price']
        shipping = variant['Variant']['shipping']
        enabled = variant['Variant']['enabled']
        profit_id = str(productSKU) + str(num) + str(obj.id)
        num += 1
        if enabled == True:
            listing_state = 'Enabled'
        else:
            listing_state = 'Disabled'
        goodsStatus = classsku_obj.get_goodsstatus_by_sku(productSKU)
        cost_price = classsku_obj.get_price_by_sku(productSKU)
        weight = classsku_obj.get_weight_by_sku(productSKU)
        try:
            sellingPrice = float(price) + float(shipping)
            calculate_price_obj = calculate_price(productSKU,
                                                  float(cost_price),
                                                  float(weight))
            profitrate_info = calculate_price_obj.calculate_profitRate(
                sellingPrice,
                platformCountryCode='WISH-US',
                DestinationCountryCode='US')
            profitrate = profitrate_info['profitRate']
        except:
            sellingPrice = ''
            profitrate = ''
        rt = '%s<tr bgcolor="#FFFFFF"><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td>' \
             '<td><a><span id="%s">%s%%</span></a></td><td>%s</td><td>%s</td></tr> ' \
             % (rt,  variant['Variant']['productSKU'], shopSKU, inventory, price, shipping, profit_id, profitrate, listing_state, goodsStatus)
        rt = u"%s<script>$('#%s').on('click',function()" \
             u"{layer.open({type:2,skin:'layui-layer-lan',title:'算价表'," \
             u"fix:false,shadeClose: true,maxmin:true,area:['1300px','900px']," \
             u"content:'/price_list/?SKU=%s&sellingPrice=%s&platformCountryCode=%s&DestinationCountryCode=%s',});});</script>" \
             % (rt, profit_id, productSKU, sellingPrice, 'WISH-US', 'US')
    rt = u'%s<tr><td><a id="link_id_%s">点击修改</a></td></tr>' % (rt, obj.id)
    rt = u"%s</table><script>$('#link_id_%s').on('click',function(){" \
         u"layer.open({type:2,skin:'layui-layer-lan',title:'查看全部'," \
         u"fix:false,shadeClose: true,maxmin:true,area:['1650px','800px']," \
         u"content:'/show_wish_variant/?id=%s&plateform=%s&page=%s'," \
         u"end:function(){location.reload();}});});</script>" % (
             rt, obj.id, obj.id, plateform, page)
    return rt
示例#4
0
def aliexpress_price_parity(request):
    productid = request.POST.get('productid', '')
    ShopSKU = request.POST.get('ShopSKU', '')
    newprice = request.POST.get('newprice', '')
    oldprice = request.POST.get('oldprice', '')
    person = request.POST.get('person', '')
    SKU = request.POST.get('SKU', '')

    sRes = {'resultCode': '0', 'messages': ''}
    # source_price = t_aliexpress_online_info_detail.objects.get(ProductID=productid, ShopSKU=ShopSKU).Price
    # if newprice == source_price:
    #     sRes['resultCode'] = '-2'
    #     return JsonResponse(sRes)
    try:
        if newprice != '':
            float(newprice)
    except Exception:
        sRes['resultCode'] = '-1'
        sRes['messages'] = '%s is illegal price' % newprice
        return JsonResponse(sRes)
    pp_log_changeflags = t_aliexpress_price_parity_log.objects.filter(
        ProductID=productid, ShopSKU=ShopSKU).values('ChangeFlag')
    if pp_log_changeflags:
        changes = list(map(lambda x: x['ChangeFlag'], pp_log_changeflags))
        if 'False' in changes:
            res = udpate_aliexpress_price_parity_log(productid, ShopSKU,
                                                     newprice, oldprice,
                                                     person, 'update')
        else:
            res = udpate_aliexpress_price_parity_log(productid, ShopSKU,
                                                     newprice, oldprice,
                                                     person, 'insert')
    else:
        res = udpate_aliexpress_price_parity_log(productid, ShopSKU, newprice,
                                                 oldprice, person, 'insert')

    profitrate = ''
    if res['code'] == 0:
        update_aliexpress_online_price_parity(productid, person)
        try:
            calculate_price_obj = calculate_price(str(SKU))
            sellprice = float(newprice)
            profitrate_info = calculate_price_obj.calculate_profitRate(
                sellprice,
                platformCountryCode='ALIEXPRESS-RUS',
                DestinationCountryCode='RUS')
            if profitrate_info:
                profitrate = profitrate_info['profitRate']
        except Exception:
            profitrate = 'Get profitRate Error'
    else:
        sRes['resultCode'] = '-1'
        sRes['messages'] = res['message']

    sRes['profitrate'] = profitrate

    return JsonResponse(sRes)
示例#5
0
def get_profit_by_sku(sku, sellprice):
    profitrate = ''
    try:
        calculate_price_obj = calculate_price(str(sku))
        profitrate_info = calculate_price_obj.calculate_profitRate(
            sellprice,
            platformCountryCode='ALIEXPRESS-RUS',
            DestinationCountryCode='RUS')
        if profitrate_info:
            profitrate = profitrate_info['profitRate']
    except:
        pass
    return profitrate
示例#6
0
def aliexpress_realprice_update(request):
    productid = request.POST.get('productid', '')
    ShopSKU = request.POST.get('ShopSKU', '')
    realprice = request.POST.get('realprice', '')
    SKU = request.POST.get('SKU', '')

    sRes = {'resultCode': '0', 'messages': ''}
    try:
        if realprice != '':
            rp = float(realprice)
            print rp
    except Exception as e:
        sRes['resultCode'] = '-1'
        sRes['messages'] = '%s is illegal price' % realprice
        return JsonResponse(sRes)

    try:
        ali_detail_obj = t_aliexpress_online_info_detail.objects.get(
            ProductID=productid, ShopSKU=ShopSKU)
        ali_detail_obj.RealPrice = realprice
        ali_detail_obj.save()
    except Exception as e:
        sRes['resultCode'] = '-1'
        sRes['messages'] = str(e)
        return JsonResponse(sRes)

    profitrate = ''
    try:
        calculate_price_obj = calculate_price(str(SKU))
        sellprice = float(realprice)
        profitrate_info = calculate_price_obj.calculate_profitRate(
            sellprice,
            platformCountryCode='ALIEXPRESS-RUS',
            DestinationCountryCode='RUS')
        if profitrate_info:
            profitrate = profitrate_info['profitRate']
    except:
        profitrate = ''

    sRes['profitrate'] = profitrate
    return JsonResponse(sRes)
示例#7
0
def get_max_price(variations, profit):
    max_price = 0
    price_list = []
    for variation in variations:
        product_sku = variation['Variant']['productSKU']
        try:
            price = float(variation['Variant']['price'])
        except:
            price = 0
        price_list.append(price)

        calculate_price_obj = calculate_price(SKU=product_sku)
        param = calculate_price_obj.calculate_selling_price(profitRate=profit)
        this_price = param.get('sellingPrice_us', 0)
        if this_price > max_price:
            max_price = this_price

    if max_price == 0:
        return max(price_list)
    else:
        return max_price
示例#8
0
from brick.pricelist.calculate_price import calculate_price

defaultencoding = 'utf-8'
if sys.getdefaultencoding() != defaultencoding:
    reload(sys)
    sys.setdefaultencoding(defaultencoding)
# cursorclass=MySQLdb.cursors.SSCursor
from django.db import connection as conn
cur = conn.cursor()
sql = 'SELECT SKU,sellprice_us FROM a_test2'

print ('连接阿里云数据成功!')
cur.execute(sql)
rows = cur.fetchall()
for row in rows:
    calculate_price_obj = calculate_price(str(row[0]))
    try:
        Profit_info = calculate_price_obj.calculate_profitRate(str(row[1]), platformCountryCode='AMAZON-IN-FBA',
                                                                   DestinationCountryCode='IN')
        profitRate = str(Profit_info['profitRate'])
        price_extra_fba = str(Profit_info['price_extra_fba'])
        price_extra_js = str(Profit_info['price_extra_js'])
        price_extra_bcd = str(Profit_info['price_extra_bcd'])
        price_extra_gst = str(Profit_info['price_extra_gst'])
        price_extra_yj = str(Profit_info['price_extra_yj'])
        price_extra_qg = str(Profit_info['price_extra_qg'])
        price_extra_all = str(Profit_info['price_extra_all'])
        Money = str(Profit_info['Money'])
        price_yf = str(Profit_info['price_yf'])
        sum_money = str(Profit_info['sum_money'])
    except:
示例#9
0
    def show_SKU_list(self, obj):
        if obj.is_fba == 0:
            fba_heard_name = u'FBM'
        elif obj.is_fba == 1:
            fba_heard_name = 'FBA'
        else:
            fba_heard_name = ''
        # rt = u'<table class="table table-condensed" style="text-align:center;">' \
        #      u'<thead>' \
        #      u'<tr bgcolor="#C00">' \
        #      u'<th style="text-align:center;">子SKU</th>' \
        #      u'<th style="text-align:center;">商品状态</th>' \
        #      u'<th style="text-align:center;">可卖天数</th>' \
        #      u'<th style="text-align:center;">店铺SKU</th>' \
        #      u'<th style="text-align:center;">%s库存量</th>' \
        #      u'<th style="text-align:center;">价格</th>' \
        #      u'<th style="text-align:center;">利润率</th>' \
        #      u'</tr>' \
        #      u'</thead><tbody>' % (fba_heard_name)

        rt = '''
            <table class="table table-condensed" style="text-align:center;">
             <thead>
             <tr bgcolor="#C00">
             <th style="text-align:center;">子SKU</th>
             <th style="text-align:center;">商品状态</th>
             <th style="text-align:center;">可卖天数</th>
             <th style="text-align:center;">店铺SKU</th>
             <th style="text-align:center;">%s库存量</th>''' % fba_heard_name

        if obj.is_fba == 1:
            rt += '<th style="text-align:center;">到货时间</th>'

        rt += '''
             <th style="text-align:center;">价格</th>
             <th style="text-align:center;">运费</th>
             <th style="text-align:center;">利润率</th>
             </tr>
             </thead><tbody>'''

        infor = []
        shopsku = obj.seller_sku
        eachinfor = {}
        eachinfor['SKU'] = classshopskuobjs.getSKU(shopsku)
        eachinfor['SKUKEY'] = [
            'NotInStore', 'GoodsStatus', 'Number', 'ReservationNum',
            'CanSaleDay'
        ]
        eachinfor['ShopSKU'] = shopsku
        eachinfor['ShopSKUKEY'] = ['Quantity', 'Price', 'Shipping', 'Status']
        infor.append(eachinfor)
        sInfors = py_SynRedis_tables_obj.BatchReadRedis(infor)

        for sinfor in sInfors:
            if obj.is_fba == 0:
                shopskuQuantity = obj.quantity
            elif obj.is_fba == 1:
                shopskuQuantity = obj.afn_warehouse_quantity
            else:
                shopskuQuantity = ''
            shopskuPrice = obj.price
            shopskuShipping = obj.shipping_price
            shopskuStatus = obj.Status
            goodsstatus = sinfor['SKUKEY'][1]
            if sinfor['SKUKEY'][1] == '1':
                goodsstatus = u'正常'
            elif sinfor['SKUKEY'][1] == '2':
                goodsstatus = u'售完下架'
            elif sinfor['SKUKEY'][1] == '3':
                goodsstatus = u'临时下架'
            elif sinfor['SKUKEY'][1] == '4':
                goodsstatus = u'停售'
            else:
                goodsstatus = ''

            can_sold_days = sinfor['SKUKEY'][-1]
            if not can_sold_days:
                can_sold_days = ''

            style = ''
            if goodsstatus and goodsstatus != u'正常':
                style = 'class="danger"'  # 非正常为红色
            elif shopskuStatus == 'Inactive':
                style = 'class="active"'  # 正常  Disabled 为 灰色
            elif shopskuStatus == 'Active':
                style = 'class="success"'  # 正常  Enabled 为 绿色

            if not shopskuPrice:
                shopskuPrice = 0

            if not shopskuShipping:
                shopskuShipping = 0

            if '+' in shopsku:
                count_sku = len(shopsku.split('+'))
            else:
                count_sku = shopsku.split('*')[-1]
            try:
                count_sku = float(count_sku)
            except:
                count_sku = 0

            CountryCode = obj.ShopName.split('-')[-1].split('/')[0]
            if CountryCode == 'JP':
                CountryCode = 'JPN'
            elif CountryCode == 'AU':
                CountryCode = 'AUS'
            elif CountryCode == 'DE':
                CountryCode = 'GER'
            elif CountryCode == 'FR':
                CountryCode = 'FRA'
            elif not CountryCode:
                CountryCode = 'US'

            if obj.is_fba == 0:
                try:
                    if count_sku:
                        sellingPrice = (float(shopskuPrice) +
                                        float(shopskuShipping)) / count_sku
                    else:
                        sellingPrice = (float(shopskuPrice) +
                                        float(shopskuShipping))
                    calculate_price_obj = calculate_price(str(sinfor['SKU']))
                    profitrate_info = calculate_price_obj.calculate_profitRate(
                        sellingPrice,
                        platformCountryCode='AMAZONGNZF',
                        DestinationCountryCode=CountryCode)
                except:
                    profitrate_info = ''
                if profitrate_info:
                    profitrate = '%.2f' % float(profitrate_info['profitRate'])
                else:
                    profitrate = ''
            else:
                profitrate = ''

            profit_id = 'profit_id' + '_' + str(sinfor['SKU'])

            if obj.is_fba == 1:
                inventory_html = u'<td><a><span id="inventory_%s">%s</span></a></td>' % (
                    obj.id, shopskuQuantity)
                if obj.inventory_received_date:
                    receive_day = str(obj.inventory_received_date)[0:10]
                else:
                    receive_day = ''
                receive_date_html = u'<td>%s</td>' % receive_day
            else:
                inventory_html = u'<td>%s</td>' % shopskuQuantity
                receive_date_html = ''
            # u'<td>%s</td>' \
            # u'<td style="BORDER-RIGHT: #DDDDDD 1px solid;">%s</td></tr>' % \
            # rt = u'%s <tr %s>' \
            #      u'<td>%s</td>' \
            #      u'<td>%s</td>' \
            #      u'<td>%s</td>' \
            #      u'<td style="BORDER-LEFT: #DDDDDD 1px solid;">%s</td>' + inventory_html
            #      # u'<td><a><span id="inventory_%s">%s</span></a></td>' \
            #      u'<td>%s</td>' \
            #      u'<td><a><span id="%s">%s</span></a></td>' % \
            #      (rt, style, sinfor['SKU'],
            #       # sinfor['SKUKEY'][0],
            #       goodsstatus,
            #       # inventory, occupyNum, int(inventory) - int(occupyNum),
            #       can_sold_days,  sinfor['ShopSKU'].replace('<', '&lt;').replace('>', '&gt;'),
            #       obj.id,shopskuQuantity, shopskuPrice, profit_id, profitrate)

            rt = '''
                %s <tr %s>
                 <td>%s</td>
                 <td>%s</td>
                 <td>%s</td>
                 <td style="BORDER-LEFT: #DDDDDD 1px solid;">%s</td>
                 %s
                 %s
                 <td>%s</td>
                 <td>%s</td>
                 <td><a><span id="%s">%s</span></a></td></tr>
            ''' % (rt, style, sinfor['SKU'], goodsstatus, can_sold_days,
                   sinfor['ShopSKU'].replace('<', '&lt;').replace(
                       '>', '&gt;'), inventory_html, receive_date_html,
                   shopskuPrice, shopskuShipping, profit_id, profitrate)

            rt = u"%s<script>$('#%s').on('click',function()" \
                 u"{layer.open({type:2,skin:'layui-layer-lan',title:'算价表'," \
                 u"fix:false,shadeClose: true,maxmin:true,area:['1300px','900px']," \
                 u"content:'/price_list/?SKU=%s&sellingPrice=%s&platformCountryCode=%s&DestinationCountryCode=%s',});});" \
                 u"</script>" % (rt, profit_id, sinfor['SKU'], shopskuPrice, 'AMAZONGNZF', CountryCode)
            seller_sku = urllib.quote(
                obj.seller_sku.decode('gbk',
                                      'replace').encode('utf-8', 'replace'))

            if obj.is_fba == 1:
                rt += '''
                            <script>
                                a = screen.width*0.8
                                b = screen.height*0.3
                                 $("#inventory_%s").on("click", function(){
                                  layer.open({
                                   type: 2,
                                   skin: "layui-layer-lan",
                                   title: "库存详情",
                                   fix: false,
                                   shadeClose: true,
                                   maxmin: true,
                                   area: [a+'px', b+'px'],
                                   content: "/show_inventory_detail/?seller_sku=%s",
                                   btn: ["关闭页面"],
                                   });
                               })
                           </script>
                           ''' % (obj.id, seller_sku)

        rt += u"</tbody></table>"

        return mark_safe(rt)
    def show_child_sku(self, obj):
        rt = u'<table class="table table-condensed">' \
             u'<thead><tr><th></th>' \
             u'<th>商品SKU</th><th>商品状态</th>' \
             u'<th>店铺SKU</th><th>库存量</th><th>价格</th><th>折后价</th><th>利润率(%)</th>' \
             u'</tr>' \
             u'</thead><tbody>'
        sku_infos = json.loads(obj.product_skus)
        sku_info_list = sku_infos.get('aeop_ae_product_sku', '')
        infor = []
        shopsku_info_db = {}
        for sku_info in sku_info_list:
            if sku_info:
                shopsku = sku_info.get('sku_code', '')
                shopsku_info_db[shopsku] = {
                    'sku_price': sku_info.get('sku_price', ''),
                    'ipm_sku_stock': sku_info.get('ipm_sku_stock', ''),
                    'sku_discount_price': sku_info.get('sku_discount_price',
                                                       '')
                }
                eachinfor = {}
                eachinfor['SKU'] = classshopskuobjs.getSKU(shopsku)
                eachinfor['SKUKEY'] = [
                    'NotInStore', 'GoodsStatus', 'Number', 'ReservationNum',
                    'CanSaleDay'
                ]
                eachinfor['ShopSKU'] = shopsku
                eachinfor['ShopSKUKEY'] = [
                    'Quantity', 'Price', 'Shipping', 'Status'
                ]
                infor.append(eachinfor)
        # 这里调取redis数据
        sInfors = py_SynRedis_tables_obj.BatchReadRedis(infor)
        num = 0
        for a, sinfor in enumerate(sInfors):
            shop_sku = sinfor['ShopSKU'].replace('<',
                                                 '&lt;').replace('>', '&gt;')
            sku_discount_price = shopsku_info_db[shop_sku]['sku_price']
            if shopsku_info_db[shop_sku]['sku_discount_price']:
                sku_discount_price = shopsku_info_db[shop_sku][
                    'sku_discount_price']
            try:
                shopsku_info = py_redis_ali_sku_obj.hgetall_data(shop_sku)
                if len(shopsku_info) == 0:
                    shopsku_info = shopsku_info_db[shop_sku]
                sellingPrice = float(sku_discount_price)
                calculate_price_obj = calculate_price(str(sinfor['SKU']))
                profitrate_info = calculate_price_obj.calculate_profitRate(
                    sellingPrice,
                    platformCountryCode='ALIEXPRESS-RUS',
                    DestinationCountryCode='RUS')
                profitrate = profitrate_info['profitRate']
            except:
                traceback.print_exc()
                profitrate = u'故障'
            profit_id = str(sinfor['SKU']) + str(num)
            num += 1

            goodsstatus = sinfor['SKUKEY'][1]
            if sinfor['SKUKEY'][1] == '1':
                goodsstatus = u'正常'
            if sinfor['SKUKEY'][1] == '2':
                goodsstatus = u'售完下架'
            if sinfor['SKUKEY'][1] == '3':
                goodsstatus = u'临时下架'
            if sinfor['SKUKEY'][1] == '4':
                goodsstatus = u'停售'

            style = ''
            if goodsstatus != u'正常':
                style = 'class ="danger"'  # 非正常为红色
            elif shopsku_info['ipm_sku_stock'] == 0:
                style = 'class ="active"'  # 正常  Disabled 为 灰色
            elif shopsku_info['ipm_sku_stock'] > 0:
                style = 'class ="success"'  # 正常  Disabled 为 绿色

            rt = u'%s <tr %s><td><label><input type="checkbox" name="shopskucheck" id="%s_%s"></label></td>' \
                 u'<td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td><a><span id="%s">%s</span></a></td></tr>' % \
                 (rt, style, obj.id, sinfor['ShopSKU'].replace('<', '&lt;').replace('>', '&gt;'),
                  sinfor['SKU'], goodsstatus, sinfor['ShopSKU'].replace('<', '&lt;').replace('>', '&gt;'),
                  shopsku_info['ipm_sku_stock'],
                  shopsku_info_db[shop_sku]['sku_price'], sku_discount_price, profit_id, profitrate,)
            rt = u"%s<script>$('#%s').on('click',function()" \
                 u"{layer.open({type:2,skin:'layui-layer-lan',title:'算价表'," \
                 u"fix:false,shadeClose: true,maxmin:true,area:['1300px','900px']," \
                 u"content:'/price_list/?SKU=%s&sellingPrice=%s&platformCountryCode=%s" \
                 u"&DestinationCountryCode=%s&category=%s',});});</script>" % (
                     rt, profit_id, sinfor['SKU'], sellingPrice, 'ALIEXPRESS-RUS', 'RUS', 'non_ornament')
        rt += '</tbody></table>'
        edit_flag = 0
        if obj.online_status:
            operation_type = obj.online_status.split('_')[1]
            if operation_type == 'ing':
                edit_flag = 1
        if edit_flag == 0:
            rt = u'%s<a id="link_id_%s">编辑变体</a>' % (rt, obj.id)
            rt = u"%s<script>$('#link_id_%s').on('click',function()" \
                 u"{var index = layer.open({type:2,skin:'layui-layer-lan',title:'全部变体信息'," \
                 u"fix:false,shadeClose: true,maxmin:true,area:['1000px','800px'],btn: ['关闭页面']," \
                 u"content:'/t_erp_aliexpress_online_info/ShopSKU/?product_id=%s',end:function (){location.reload();}});" \
                 u"});</script>" % (rt, obj.id, obj.product_id)
        return mark_safe(rt)
示例#11
0
    def show_SKU_list(
        self, obj
    ):  # <label><input type="checkbox" name="shopskucheck_%s_%s"></label>
        classshopskuobjs = classshopsku(connection, redis_conn, obj.ShopName)
        activeflag = self.request.GET.get('EXPRESS', 'STANDARD')
        rt = u'<table class="table table-condensed">' \
             u'<thead><tr><th></th>' \
             u'<th>商品SKU</th><th>商品状态</th><th>可卖天数</th>' \
             u'<th>店铺SKU</th><th>价格</th>'

        if activeflag == 'DE':
            rt = rt + u'<th>德国仓运费</th><th>德国仓库存</th>'
        elif activeflag == 'GB':
            rt = rt + u'<th>英国仓运费</th><th>英国仓库存</th>'
        elif activeflag == 'US':
            rt = rt + u'<th>美国仓运费</th><th>美国仓库存</th>'
        else:
            rt = rt + u'<th>标准仓运费</th><th>标准仓库存</th>'

        rt = rt + u'<th>利润率(%)</th><th>变体状态</th></tr></thead>' \
                  u'<tbody>'
        shopskulist = listingobjs.getShopSKUList(obj.ProductID)
        infor = []
        for i, shopsku in enumerate(shopskulist):
            eachinfor = {}
            eachinfor['SKU'] = classshopskuobjs.getSKU(shopsku)
            eachinfor['SKUKEY'] = [
                'GoodsStatus', 'CanSaleDay', 'CostPrice', 'Weight'
            ]
            eachinfor['ShopSKU'] = shopsku

            if activeflag == 'DE':
                eachinfor['ShopSKUKEY'] = [
                    '{}.Price'.format(obj.ShopName),
                    '{}.DEShipping'.format(obj.ShopName),
                    '{}.DEQuantity'.format(obj.ShopName),
                    '{}.Shipping'.format(obj.ShopName),
                    '{}.Status'.format(obj.ShopName)
                ]
            elif activeflag == 'GB':
                eachinfor['ShopSKUKEY'] = [
                    '{}.Price'.format(obj.ShopName),
                    '{}.GBShipping'.format(obj.ShopName),
                    '{}.GBQuantity'.format(obj.ShopName),
                    '{}.Shipping'.format(obj.ShopName),
                    '{}.Status'.format(obj.ShopName)
                ]
            elif activeflag == 'US':
                eachinfor['ShopSKUKEY'] = [
                    '{}.Price'.format(obj.ShopName),
                    '{}.USShipping'.format(obj.ShopName),
                    '{}.USQuantity'.format(obj.ShopName),
                    '{}.Shipping'.format(obj.ShopName),
                    '{}.Status'.format(obj.ShopName)
                ]
            else:
                eachinfor['ShopSKUKEY'] = [
                    '{}.Price'.format(obj.ShopName),
                    '{}.Shipping'.format(obj.ShopName),
                    '{}.Quantity'.format(obj.ShopName),
                    '{}.Status'.format(obj.ShopName)
                ]

            infor.append(eachinfor)
        # 这里调取redis数据
        sInfors = py_SynRedis_tables_obj.readData_Redis_table(infor)
        num = 0
        for a, sinfor in enumerate(sInfors):
            try:
                if activeflag == 'STANDARD':
                    yf = sinfor['ShopSKUKEY'][1]
                else:
                    if activeflag in obj.WishExpress:
                        yf = sinfor['ShopSKUKEY'][1]
                    elif activeflag not in obj.WishExpress:
                        yf = sinfor['ShopSKUKEY'][3]
                cb = sinfor['ShopSKUKEY'][0]

                if cb is None or cb.strip() == '':
                    cb = 0
                if yf is None or yf.strip() == '':
                    yf = 0
                sellingPrice = float(cb) + float(yf)
                calculate_price_obj = calculate_price(
                    str(sinfor['SKU']), float(sinfor['SKUKEY'][2]),
                    float(sinfor['SKUKEY'][3]))
                profitrate_info = calculate_price_obj.calculate_profitRate(
                    sellingPrice,
                    platformCountryCode='WISH-US',
                    DestinationCountryCode='US')
                profitrate = profitrate_info['profitRate']
            except:
                sellingPrice = ''
                profitrate = ' '
            profit_id = str(sinfor['SKU']) + str(num)
            num += 1

            goodsstatus = sinfor['SKUKEY'][0]
            if goodsstatus == '1':
                goodsstatus = u'正常'
            if goodsstatus == '2':
                goodsstatus = u'售完下架'
            if goodsstatus == '3':
                goodsstatus = u'临时下架'
            if goodsstatus == '4':
                goodsstatus = u'停售'

            style = ''
            if goodsstatus != u'正常':
                style = 'class ="danger"'  # 非正常为红色
            elif sinfor['ShopSKUKEY'][-1] == 'Disabled':
                style = 'class ="active"'  # 正常  Disabled 为 灰色
            elif sinfor['ShopSKUKEY'][-1] == 'Enabled':
                style = 'class ="success"'  # 正常  Enabled 为 绿色

            if not sinfor['ShopSKUKEY'][1]:
                sinfor['ShopSKUKEY'][1] = ''

            if not sinfor['ShopSKUKEY'][2]:
                sinfor['ShopSKUKEY'][2] = ''

            rt = u'%s <tr %s><td><label><input type="checkbox" name="shopskucheck" id="%s_%s_%s" ></label></td>' \
                 u'<td>%s</td><td>%s</td><td>%s</td><td>%s</td>' \
                 u'<td>%s</td><td>%s</td><td>%s</td><td><a><span id="%s">%s</span></a></td><td>%s</td>' % \
                 (rt, style, obj.id, a, obj.ShopName, sinfor['SKU'], goodsstatus,
                  sinfor['SKUKEY'][1], sinfor['ShopSKU'].replace('<', '&lt;').replace('>', '&gt;'),
                  sinfor['ShopSKUKEY'][0],
                  sinfor['ShopSKUKEY'][1], sinfor['ShopSKUKEY'][2], profit_id, profitrate, sinfor['ShopSKUKEY'][-1],)
            rt = u"%s<script>$('#%s').on('click',function()" \
                 u"{layer.open({type:2,skin:'layui-layer-lan',title:'算价表'," \
                 u"fix:false,shadeClose: true,maxmin:true,area:['1300px','900px']," \
                 u"content:'/price_list/?SKU=%s&sellingPrice=%s&platformCountryCode=%s&DestinationCountryCode=%s',});});</script>" % (
                 rt, profit_id, sinfor['SKU'], sellingPrice, 'WISH-US', 'US')

        rt = u'%s<tr><td></td><td><a id="link_id_%s">查看变体</a></td></tr>' % (
            rt, obj.id)
        rt = u"%s</tbody></table><script>$('#link_id_%s').on('click',function()" \
             u"{var index = layer.open({type:2,skin:'layui-layer-lan',title:'%s'," \
             u"fix:false,shadeClose: true,maxmin:true,area:['90%%','80%%'],btn: ['关闭页面']," \
             u"content:'/t_online_info_wish_store/ShopSKU/?abc=%s&express=%s&readonly=readonly',});" \
             u"});</script>" % (rt, obj.id, activeflag, obj.ProductID, activeflag)

        # rt = rt + u"<script>function en_id_%s(shopsku) {layer.confirm(shopsku + '  请问确定要进行上架吗?'," \
        #           u"{btn: ['确定','算了'],btn1:function(){static_refresh('/up_dis_by_wish_api_shopsku/?enshopsku='+shopsku+" \
        #           u"'&shopname=%s&flag=0');},});}</script>" % (obj.id, obj.ShopName)
        # rt = rt + u"<script>function dis_id_%s(shopsku) {layer.confirm(shopsku + '  请问确定要进行下架吗?'," \
        #           u"{btn: ['确定','算了'],btn1:function(){static_refresh('/up_dis_by_wish_api_shopsku/?disshopsku='+shopsku+" \
        #           u"'&shopname=%s&flag=0')},});}</script>" % (obj.id, obj.ShopName)
        return mark_safe(rt)
示例#12
0
def get_sku_info_list(sku_info_list):
    py_redis_ali_sku_obj = py_redis_ali_sku()
    infor = []
    shopsku_info_db = {}
    for sku_info in sku_info_list:
        if sku_info:
            shopsku = sku_info.get('sku_code', '')
            shopsku_info_db[shopsku] = {
                'sku_price': sku_info.get('sku_price', ''),
                'id': sku_info.get('id', ''),
                'ipm_sku_stock': sku_info.get('ipm_sku_stock', '')
            }
            eachinfor = {}
            eachinfor['SKU'] = classshopskuobjs.getSKU(shopsku)
            eachinfor['SKUKEY'] = [
                'NotInStore', 'GoodsStatus', 'Number', 'ReservationNum',
                'CanSaleDay'
            ]
            eachinfor['ShopSKU'] = shopsku
            eachinfor['ShopSKUKEY'] = [
                'Quantity', 'Price', 'Shipping', 'Status'
            ]
            infor.append(eachinfor)
    # 这里调取redis数据
    sInfors = py_SynRedis_tables_obj.BatchReadRedis(infor)
    num = 0
    all_sku_info = []
    all_shopSKU_list = '['
    all_shopSKU_id_list = '['
    for a, sinfor in enumerate(sInfors):
        shopSKU_info = {}
        try:
            shop_sku = sinfor['ShopSKU'].replace('<',
                                                 '&lt;').replace('>', '&gt;')
            shopsku_info = py_redis_ali_sku_obj.hgetall_data(shop_sku)
            if len(shopsku_info) == 0:
                shopsku_info = shopsku_info_db[shop_sku]
            sellingPrice = float(shopsku_info['sku_price'])
            calculate_price_obj = calculate_price(str(sinfor['SKU']))
            profitrate_info = calculate_price_obj.calculate_profitRate(
                sellingPrice,
                platformCountryCode='ALIEXPRESS-RUS',
                DestinationCountryCode='US',
                category='non_ornament')
            profitrate = profitrate_info['profitRate']
        except:
            profitrate = ' '
        num += 1
        inventory = sinfor['SKUKEY'][2]
        if inventory is None or inventory == -1:
            inventory = 0
        else:
            inventory = str(inventory).split('.')[0]
            if inventory == '':
                inventory = '0'
        occupyNum = sinfor['SKUKEY'][3]
        if occupyNum is None or occupyNum == -1:
            occupyNum = 0
        else:
            occupyNum = str(occupyNum).split('.')[0]
            if occupyNum == '':
                occupyNum = '0'

        goodsstatus = sinfor['SKUKEY'][1]
        if sinfor['SKUKEY'][1] == '1':
            goodsstatus = u'正常'
        if sinfor['SKUKEY'][1] == '2':
            goodsstatus = u'售完下架'
        if sinfor['SKUKEY'][1] == '3':
            goodsstatus = u'临时下架'
        if sinfor['SKUKEY'][1] == '4':
            goodsstatus = u'停售'

        sku_status = 'Out of stock'
        if shopsku_info['ipm_sku_stock'] > 0:
            sku_status = 'On Sale'
        shopSKU_info['SKU'] = sinfor['SKU']
        shopSKU_info['CGWRK'] = sinfor['SKUKEY'][0]
        shopSKU_info['goods_status'] = goodsstatus
        shopSKU_info['KC'] = inventory
        shopSKU_info['ZY'] = occupyNum
        shopSKU_info['can_use_num'] = int(inventory) - int(occupyNum)
        shopSKU_info['can_selling_day'] = sinfor['SKUKEY'][-1]
        shopSKU_info['shopSKU'] = sinfor['ShopSKU'].replace('<',
                                                            '&lt;').replace(
                                                                '>', '&gt;')
        shopSKU_info['sku_stocks'] = shopsku_info['ipm_sku_stock']
        shopSKU_info['sku_price'] = shopsku_info['sku_price']
        shopSKU_info['profitrate'] = profitrate
        shopSKU_info['sku_status'] = sku_status
        shopSKU_info['skuid'] = shopsku_info['id']
        all_sku_info.append(shopSKU_info)
        all_shopSKU_list += '"' + shopSKU_info['shopSKU'] + '",'
        all_shopSKU_id_list += '"' + shopSKU_info['skuid'] + '",'
    all_shopSKU_list = all_shopSKU_list[:-1] + ']'
    all_shopSKU_id_list = all_shopSKU_id_list[:-1] + ']'
    return all_sku_info, all_shopSKU_list, all_shopSKU_id_list
示例#13
0
def get_aliexpress_competitor_profit_range(product_id, price_range):
    pro_info = t_aliexpress_online_info_detail.objects.filter(
        ProductID=product_id).values('SKU', 'Price')
    pro_dict = dict()
    pro_dict = {
        'max': {
            'SKU': '',
            'price': ''
        },
        'min': {
            'SKU': '',
            'price': ''
        }
    }
    max_price = None
    min_price = None

    for i in pro_info:
        if not i['SKU']:
            continue

        price_now = float(i['Price'])

        if not max_price:
            max_price = price_now
            pro_dict['max'] = {'SKU': i['SKU'], 'price': max_price}
        elif max_price < price_now:
            max_price = price_now
            pro_dict['max'] = {'SKU': i['SKU'], 'price': max_price}

        if not min_price:
            min_price = min_price
            pro_dict['min'] = {'SKU': i['SKU'], 'price': min_price}
        elif min_price > price_now:
            max_price = price_now
            pro_dict['min'] = {'SKU': i['SKU'], 'price': max_price}

    if price_range[0]:
        try:
            min_profit_obj = calculate_price(pro_dict['min']['SKU'])
            min_profit_rate = min_profit_obj.calculate_profitRate(
                price_range[0],
                platformCountryCode='ALIEXPRESS-RUS',
                DestinationCountryCode='RUS')
            min_profit_rate = '%.2f' % float(min_profit_rate['profitRate'])
        except:
            min_profit_rate = ''
    else:
        min_profit_rate = ''
    if price_range[-1]:
        try:
            max_profit_obj = calculate_price(pro_dict['max']['SKU'])
            max_profit_rate = max_profit_obj.calculate_profitRate(
                price_range[-1],
                platformCountryCode='ALIEXPRESS-RUS',
                DestinationCountryCode='RUS')
            max_profit_rate = '%.2f' % float(max_profit_rate['profitRate'])
        except:
            max_profit_rate = ''
    else:
        max_profit_rate = ''

    profitrate_range = [min_profit_rate, max_profit_rate]

    return profitrate_range
    def show_SKU_list(self, obj):
        rt = u'<table class="table table-condensed" style="text-align:center;">' \
             u'<thead>' \
             u'<tr bgcolor="#C00">' \
             u'<th style="text-align:center;">子SKU</th>' \
             u'<th style="text-align:center;">店铺SKU</th>' \
             u'<th style="text-align:center;">库存量</th>' \
             u'<th style="text-align:center;">实际销售价($)</th>' \
             u'<th style="text-align:center;">调后价($)</th>' \
             u'<th style="text-align:center;">我方利润率(%)</th>' \
             u'<th style="text-align:center;">启用状态</th>' \
             u'</tr>' \
             u'</thead><tbody>'
        # u'<th style="text-align:center;">原价($)</th>' \
        # u'<th style="text-align:center;">运费($)</th>' \
        shopskulist = obj.ShopSKU.split(',')
        infor = []
        for i, shopsku in enumerate(shopskulist):
            eachinfor = {}
            eachinfor['SKU'] = classshopskuobjs.getSKU(shopsku)
            # eachinfor['SKUKEY'] = ['19', 'goodsstatus', 'Number', 'ReservationNum', 'CanSaleDay']
            eachinfor['SKUKEY'] = [
                'NotInStore', 'GoodsStatus', 'Number', 'ReservationNum',
                'CanSaleDay'
            ]
            eachinfor['ShopSKU'] = shopsku
            eachinfor['ShopSKUKEY'] = [
                'Quantity', 'Price', 'Shipping', 'Status'
            ]
            infor.append(eachinfor)
        # 这里调取redis数据
        num = 0
        sInfors = py_SynRedis_tables_obj.BatchReadRedis(infor)
        aliexpress_product_shop_sku_info = t_aliexpress_online_info_detail.objects.filter(
            ProductID=obj.ProductID).values('ShopSKU', 'Quantity', 'Price',
                                            'Status', 'RealPrice')
        aliexpress_pro_dict = dict()
        if aliexpress_product_shop_sku_info:
            for i in aliexpress_product_shop_sku_info:
                aliexpress_pro_dict[i['ShopSKU']] = i

        # 判断MainSKU个数确定是否为组合商品
        count_mainsku = 0
        if obj.MainSKU:
            count_mainsku = len(obj.MainSKU.split(','))
        ms_num = 0

        for sinfor in sInfors:
            if count_mainsku > 1:
                ms_num += 1
            else:
                pass

            if ms_num > 5:
                break

            if aliexpress_pro_dict.get(sinfor['ShopSKU']):
                shopskuQuantity = aliexpress_pro_dict[
                    sinfor['ShopSKU']]['Quantity']
                if aliexpress_pro_dict[sinfor['ShopSKU']]['Price']:
                    shopskuPrice = '%.2f' % float(
                        aliexpress_pro_dict[sinfor['ShopSKU']]['Price'])
                else:
                    shopskuPrice = ''
                shopskuStatus = aliexpress_pro_dict[
                    sinfor['ShopSKU']]['Status']
                realprice = aliexpress_pro_dict[sinfor['ShopSKU']]['RealPrice']
            else:
                shopskuQuantity = ''
                shopskuPrice = ''
                shopskuStatus = ''
                realprice = ''

            if not realprice:
                realprice = ''

            newPrice = ''
            try:
                newPrice = t_aliexpress_price_parity_log.objects.get(
                    ProductID=obj.ProductID,
                    ShopSKU=sinfor['ShopSKU'],
                    ChangeFlag='False').NewPrice
            except t_aliexpress_price_parity_log.DoesNotExist:
                pass

            input_id = obj.ProductID + '_' + str(num)
            show_input_res = input_id + '_' + str(num)
            profit_id = show_input_res + '_' + str(num)

            real_price_id = obj.ProductID + '_realprice_' + str(num)
            real_price_input_res = real_price_id + '_' + str(num)

            # shipping_id = obj.ProductID + '_shipping_' + str(num)
            # shipping_input_res = shipping_id + '_' + str(num)
            num += 1

            # shipping_rt = u'<td><input type="text" style="width:40px" id="%s" value=""/><span id="%s"  style="color:#F00"></span></td>' % (shipping_id, shipping_input_res)

            if self.request.get_full_path().find(
                    'priceParity_Status=WAIT') != -1:
                realprice_rt = u'<td><input type="text" style="width:40px" id="%s" value="%s" onkeyup="this.value=this.value.replace(/[^\d\.]/g,\'\')"/><span id="%s" style="color:#F00"></span></td>' % (
                    real_price_id, realprice, real_price_input_res)
                input_rt = u'<td><input type="text" style="width:40px" id="%s" value="%s" onkeyup="this.value=this.value.replace(/[^\d\.]/g,\'\')"/><span id="%s" style="color:#F00"></span></td>'
                if not newPrice:
                    if realprice:
                        newPrice = realprice
                    else:
                        newPrice = shopskuPrice
            else:
                input_rt = u'<td id="%s">%s<span id="%s"></span></td>'
                realprice_rt = u'<td id="%s">%s<span id="%s"></span></td>' % (
                    real_price_id, realprice, real_price_input_res)

            if newPrice:
                sellingPrice = float(newPrice.split('-')[0])
            else:
                if shopskuPrice:
                    sellingPrice = float(shopskuPrice)
                else:
                    sellingPrice = ''
            if sellingPrice:
                try:
                    calculate_price_obj = calculate_price(str(sinfor['SKU']))
                    profitrate_info = calculate_price_obj.calculate_profitRate(
                        sellingPrice,
                        platformCountryCode='ALIEXPRESS-RUS',
                        DestinationCountryCode='RUS')
                except:
                    profitrate_info = ''
            else:
                profitrate_info = ''
            if profitrate_info:
                profitrate = '%.2f' % float(profitrate_info['profitRate'])
            else:
                profitrate = ''

            if self.request.get_full_path().find(
                    'priceParity_Status=SUCCESS') != -1:
                newPrice = shopskuPrice

            rt_tmp = u'%s <tr bgcolor="#FFFFFF">' \
                     u'<td>%s</td>' \
                     u'<td style="BORDER-LEFT: #DDDDDD 1px solid;">%s</td>' \
                     u'<td>%s</td>' + \
                     realprice_rt + \
                     input_rt + \
                     u'<td><a><span id="%s">%s</span></a></td>' \
                     u'<td style="BORDER-RIGHT: #DDDDDD 1px solid;">%s</td></tr>'
            # u'<td>%s</td>' \
            # shipping_rt + \
            rt = rt_tmp % (
                rt,
                sinfor['SKU'],
                sinfor['ShopSKU'].replace('<', '&lt;').replace('>', '&gt;'),
                shopskuQuantity,
                # shopskuPrice,
                input_id,
                newPrice,
                show_input_res,
                profit_id,
                profitrate,
                shopskuStatus)

            rt = u"%s<script>$('#%s').on('click',function()" \
                 u"{layer.open({type:2,skin:'layui-layer-lan',title:'算价表'," \
                 u"fix:false,shadeClose: true,maxmin:true,area:['1300px','900px']," \
                 u"content:'/price_list/?SKU=%s&sellingPrice=%s&platformCountryCode=%s&DestinationCountryCode=%s',});" \
                 "});</script>" % (rt, profit_id, sinfor['SKU'], sellingPrice, 'ALIEXPRESS-RUS', 'RUS')

            if self.request.get_full_path().find(
                    'priceParity_Status=WAIT') != -1:
                rt = '%s<script>$(document).ready(function(){$("#%s").blur(function(){' \
                     'var newprice = $("#%s").val();if(newprice!=""){' \
                     '$.ajax({url:"/aliexpress/aliexpress_price_parity/",type:"POST",contentType:"application/x-www-form-urlencoded:charset=UTF-8",' \
                     'dataType: "json",data: {"newprice":newprice,"productid":"%s","ShopSKU":"%s",' \
                     '"oldprice":"%s","person":"%s","SKU":"%s"},' \
                     'success:function(result){var res_mess="";var profitrate="";' \
                     'if(result.resultCode==0){res_mess="SUCCESS";profitrate=result.profitrate;}' \
                     'else if(result.resultCode==-2){res_mess="SAMEPRICE NOCHANGE";}' \
                     'else{res_mess=result.messages;}$("#%s").html(res_mess);$("#%s").html(profitrate);},' \
                     'error:function(XMLHttpRequest,textStatus,errorThrown){' \
                     'alert("错误信息:"+XMLHttpRequest.responseText);}' \
                     '});}else{}' \
                     '});});</script>' % (rt, input_id, input_id, obj.ProductID, sinfor['ShopSKU'].replace('<', '&lt;').replace('>', '&gt;').replace('\\', '\\\\'),
                                          shopskuPrice, self.request.user.first_name, sinfor['SKU'], show_input_res, profit_id)

            if self.request.get_full_path().find(
                    'priceParity_Status=WAIT') != -1:
                realprice_script = '<script>$(document).ready(function(){$("#%s").blur(' \
                                   'function(){var realprice = $("#%s").val();if(realprice!=""){' \
                                   '$.ajax({url:"/aliexpress/aliexpress_realprice_update/",' \
                                   'type:"POST",contentType:"application/x-www-form-urlencoded:charset=UTF-8",' \
                                   'dataType:"json",data:{"realprice":realprice,"productid":"%s","ShopSKU":"%s","SKU":"%s"' \
                                   '},success:function(result){var res_mess="";var profitrate="";' \
                                   'if(result.resultCode==0){res_mess="SUCCESS";profitrate=result.profitrate;' \
                                   '}else if(result.resultCode==-2){res_mess="SAMEPRICE NOCHANGE";}else{' \
                                   'res_mess=result.messages;}$("#%s").html(res_mess);$("#%s").html(profitrate);},' \
                                   'error:function(XMLHttpRequest,textStatus,errorThrown)' \
                                   '{console.log("错误信息:"+XMLHttpRequest.responseText);}});}else{}});});</script>' % \
                                   (real_price_id, real_price_id, obj.ProductID, sinfor['ShopSKU'].replace('<', '&lt;').replace('>', '&gt;').replace('\\', '\\\\'),
                                    sinfor['SKU'], real_price_input_res, profit_id)

                rt = rt + realprice_script

        rt = u'%s</tbody></table>' % (rt)

        if count_mainsku > 1:
            rt += u'<span style="color:#F00">组合商品不进行比价, 最多只显示五条信息</span>'

        return mark_safe(rt)
def update_ebayapp_price():
    try:
        db_conn = MySQLdb.connect(DATABASES['HOST'],
                                  DATABASES['USER'],
                                  DATABASES['PASSWORD'],
                                  DATABASES['NAME'],
                                  charset="utf8")
        print db_conn
    except Exception as e:
        error = 'Connect mysql db error %s' % e
        print error

    site_result = getsiteshop(db_conn=db_conn)
    if site_result['code'] <> 0:
        print 'select t_online_info_ebay error'
        return 'error'
    site_datas = site_result['data']
    for site_data in site_datas:
        try:
            itemid = site_data[0]
            # title = site_data[1]
            # currentprice = site_data[2]
            # realavailable = site_data[3]
            Productsku = site_data[4]
            isVariations = site_data[5]
            # site = site_data[6]
            # shopName = site_data[7]
            if isVariations == 'NO':
                priceparams = {}
                ncalculate_price_obj = calculate_price(str(Productsku))
                MY_calculate_result = ncalculate_price_obj.calculate_selling_price(
                    profitRate=40,
                    platformCountryCode='SHOPEE',
                    DestinationCountryCode='MY')
                priceparams['MY_calculate_price'] = MY_calculate_result[
                    'sellingPrice_destination']

                PH_calculate_result = ncalculate_price_obj.calculate_selling_price(
                    profitRate=40,
                    platformCountryCode='SHOPEE',
                    DestinationCountryCode='PH')
                priceparams['PH_calculate_price'] = PH_calculate_result[
                    'sellingPrice_destination']

                VNM_calculate_result = ncalculate_price_obj.calculate_selling_price(
                    profitRate=40,
                    platformCountryCode='SHOPEE',
                    DestinationCountryCode='VNM')
                priceparams['VNM_calculate_price'] = VNM_calculate_result[
                    'sellingPrice_destination']

                THA_calculate_result = ncalculate_price_obj.calculate_selling_price(
                    profitRate=40,
                    platformCountryCode='SHOPEE',
                    DestinationCountryCode='THA')
                priceparams['THA_calculate_price'] = THA_calculate_result[
                    'sellingPrice_destination']

                SG_calculate_result = ncalculate_price_obj.calculate_selling_price(
                    profitRate=40,
                    platformCountryCode='SHOPEE',
                    DestinationCountryCode='SG')
                priceparams['SG_calculate_price'] = SG_calculate_result[
                    'sellingPrice_destination']

                INA_calculate_result = ncalculate_price_obj.calculate_selling_price(
                    profitRate=40,
                    platformCountryCode='SHOPEE',
                    DestinationCountryCode='INA')
                priceparams['INA_calculate_price'] = INA_calculate_result[
                    'sellingPrice_destination']

                update_online_ebay(db_conn=db_conn,
                                   itemid=itemid,
                                   priceparams=priceparams)
            elif isVariations == 'YES':
                sub_reuslt = get_info_ebay_subSKU(db_conn=db_conn,
                                                  itemid=itemid)
                if sub_reuslt['code'] == 0:
                    sub_items = sub_reuslt['data']
                    for sub_item in sub_items:
                        # sstartprice = sub_item[1]
                        # srealavailable = sub_item[2]
                        try:
                            sproductsku = sub_item[3]
                            subSKU = sub_item[4]
                            ycalculate_price_obj = calculate_price(
                                str(sproductsku))
                            MY_calculate_result = ycalculate_price_obj.calculate_selling_price(
                                profitRate=40,
                                platformCountryCode='SHOPEE',
                                DestinationCountryCode='MY')
                            priceparams[
                                'MY_calculate_price'] = MY_calculate_result[
                                    'sellingPrice_destination']

                            PH_calculate_result = ycalculate_price_obj.calculate_selling_price(
                                profitRate=40,
                                platformCountryCode='SHOPEE',
                                DestinationCountryCode='PH')
                            priceparams[
                                'PH_calculate_price'] = PH_calculate_result[
                                    'sellingPrice_destination']

                            VNM_calculate_result = ycalculate_price_obj.calculate_selling_price(
                                profitRate=40,
                                platformCountryCode='SHOPEE',
                                DestinationCountryCode='VNM')
                            priceparams[
                                'VNM_calculate_price'] = VNM_calculate_result[
                                    'sellingPrice_destination']

                            THA_calculate_result = ycalculate_price_obj.calculate_selling_price(
                                profitRate=40,
                                platformCountryCode='SHOPEE',
                                DestinationCountryCode='THA')
                            priceparams[
                                'THA_calculate_price'] = THA_calculate_result[
                                    'sellingPrice_destination']

                            SG_calculate_result = ycalculate_price_obj.calculate_selling_price(
                                profitRate=40,
                                platformCountryCode='SHOPEE',
                                DestinationCountryCode='SG')
                            priceparams[
                                'SG_calculate_price'] = SG_calculate_result[
                                    'sellingPrice_destination']

                            INA_calculate_result = ycalculate_price_obj.calculate_selling_price(
                                profitRate=40,
                                platformCountryCode='SHOPEE',
                                DestinationCountryCode='INA')
                            priceparams[
                                'INA_calculate_price'] = INA_calculate_result[
                                    'sellingPrice_destination']
                            update_online_ebay_subsku(db_conn=db_conn,
                                                      itemid=itemid,
                                                      subSKU=subSKU,
                                                      priceparams=priceparams)
                        except:
                            continue
        except Exception, ex:
            continue
示例#16
0
    def show_SKU_list(self, obj):
        rt = u'<table class="table table-condensed">' \
             u'<thead>' \
             u'<tr bgcolor="#C00">' \
             u'<th style="text-align:center;">子SKU</th>' \
             u'<th style="text-align:center;">商品状态</th>' \
             u'<th style="text-align:center;">可卖天数</th>' \
             u'<th style="text-align:center;">店铺SKU</th>' \
             u'<th style="text-align:center;">库存量</th>' \
             u'<th style="text-align:center;">价格</th>' \
             u'<th style="text-align:center;">运费</th>' \
             u'<th style="text-align:center;">利润率</th>' \
             u'<th style="text-align:center;">启用状态</th>' \
             u'</tr>' \
             u'</thead><tbody>'
        # u'<th style="text-align:center;">采购未入库</th>' \
        # u'<th style="text-align:center;">库存</th>' \
        # u'<th style="text-align:center;">占用</th>' \
        # u'<th style="text-align:center;">可用数量</th>' \
        # u'<th style="text-align:center;">操作</th>' \
        shopskulist = obj.ShopSKU.split(',')
        infor = []
        for i, shopsku in enumerate(shopskulist):
            if i >= 5:
                break
            eachinfor = {}
            eachinfor['SKU'] = classshopskuobjs.getSKU(shopsku)
            # eachinfor['SKUKEY'] = ['19', 'goodsstatus', 'Number', 'ReservationNum', 'CanSaleDay']
            eachinfor['SKUKEY'] = [
                'NotInStore', 'GoodsStatus', 'Number', 'ReservationNum',
                'CanSaleDay'
            ]
            eachinfor['ShopSKU'] = shopsku
            eachinfor['ShopSKUKEY'] = [
                'Quantity', 'Price', 'Shipping', 'Status'
            ]
            infor.append(eachinfor)
        # 这里调取redis数据
        num = 0
        sInfors = py_SynRedis_tables_obj.BatchReadRedis(infor)
        for sinfor in sInfors:
            mymall_product_shop_sku_info = t_mymall_online_info_detail.objects.filter(
                ProductID=obj.ProductID,
                ShopSKU=sinfor['ShopSKU']).values('Quantity', 'Price',
                                                  'Shipping', 'Status')

            if mymall_product_shop_sku_info:
                shopskuQuantity = mymall_product_shop_sku_info[0]['Quantity']
                shopskuPrice = '%.2f' % float(
                    mymall_product_shop_sku_info[0]['Price'])
                shopskuShipping = mymall_product_shop_sku_info[0]['Shipping']
                shopskuStatus = mymall_product_shop_sku_info[0]['Status']
                if shopskuStatus == '1':
                    shopskuStatus = 'True'
                else:
                    shopskuStatus = 'False'
            else:
                shopskuQuantity = ''
                shopskuPrice = ''
                shopskuShipping = ''
                shopskuStatus = ''

            inventory = sinfor['SKUKEY'][2]
            if inventory is None or inventory == -1:
                inventory = 0
            else:
                inventory = str(inventory).split('.')[0]
                if inventory == '':
                    inventory = '0'
            occupyNum = sinfor['SKUKEY'][3]
            if occupyNum is None or occupyNum == -1:
                occupyNum = 0
            else:
                occupyNum = str(occupyNum).split('.')[0]
                if occupyNum == '':
                    occupyNum = '0'

            goodsstatus = sinfor['SKUKEY'][1]
            if sinfor['SKUKEY'][1] == '1':
                goodsstatus = u'正常'
            elif sinfor['SKUKEY'][1] == '2':
                goodsstatus = u'售完下架'
            elif sinfor['SKUKEY'][1] == '3':
                goodsstatus = u'临时下架'
            elif sinfor['SKUKEY'][1] == '4':
                goodsstatus = u'停售'
            else:
                goodsstatus = ''

            can_sold_days = sinfor['SKUKEY'][-1]
            if not can_sold_days:
                can_sold_days = ''

            style = ''
            if goodsstatus and goodsstatus != u'正常':
                style = 'class="danger"'  # 非正常为红色
            elif shopskuStatus == 'False':
                style = 'class="active"'  # 正常  Disabled 为 灰色
            elif shopskuStatus == 'True':
                style = 'class="success"'  # 正常  Enabled 为 绿色

            if not shopskuPrice:
                shopskuPrice = 0

            if not shopskuShipping:
                shopskuShipping = 0

            try:
                sellingPrice = float(shopskuPrice) + float(shopskuShipping)
                calculate_price_obj = calculate_price(str(sinfor['SKU']))
                profitrate_info = calculate_price_obj.calculate_profitRate(
                    sellingPrice,
                    platformCountryCode='MALL',
                    DestinationCountryCode='RUS')
            except:
                profitrate_info = ''
            if profitrate_info:
                profitrate = '%.2f' % float(profitrate_info['profitRate'])
            else:
                profitrate = ''

            profit_id = 'profit_id' + '_' + str(num) + '_' + str(sinfor['SKU'])
            num += 1

            # u'<td>%s</td>' \
            # u'<td>%s</td>' \
            # u'<td>%s</td>' \
            # u'<td>%s</td>' \
            rt = u'%s <tr %s>' \
                 u'<td>%s</td>' \
                 u'<td>%s</td>' \
                 u'<td>%s</td>' \
                 u'<td style="BORDER-LEFT: #DDDDDD 1px solid;">%s</td>' \
                 u'<td>%s</td>' \
                 u'<td>%s</td>' \
                 u'<td>%s</td>' \
                 u'<td><a><span id="%s">%s</span></a></td>' \
                 u'<td style="BORDER-RIGHT: #DDDDDD 1px solid;">%s</td></tr>' % \
                 (rt, style, sinfor['SKU'],
                  # sinfor['SKUKEY'][0],
                  goodsstatus,
                  # inventory, occupyNum, int(inventory) - int(occupyNum),
                  can_sold_days, sinfor['ShopSKU'].replace('<', '&lt;').replace('>', '&gt;'),
                  shopskuQuantity, shopskuPrice, shopskuShipping, profit_id, profitrate, shopskuStatus)

            rt = u"%s<script>$('#%s').on('click',function()" \
                 u"{layer.open({type:2,skin:'layui-layer-lan',title:'算价表'," \
                 u"fix:false,shadeClose: true,maxmin:true,area:['1300px','900px']," \
                 u"content:'/price_list/?SKU=%s&sellingPrice=%s&platformCountryCode=%s&DestinationCountryCode=%s',});});" \
                 u"</script>" % (rt, profit_id, sinfor['SKU'], shopskuPrice, 'MALL', 'RUS')

            # shopsku = sinfor['ShopSKU'].replace('#', '%23')

            # rt = u'%s<td style="text-align:center;"><a onclick="en_id_%s(\'%s\')">上架</a>' % (rt, obj.id, shopsku) + \
            #      u'//<a onclick="dis_id_%s(\'%s\')">下架</a></td></tr> ' % (obj.id, shopsku)
        rt = u'%s<tr><td><a id="link_id_%s">编辑变体</a></td></tr>' % (rt, obj.id)
        rt = u"%s</tbody></table><script>$('#link_id_%s').on('click',function()" \
             u"{layer.open({type:2,skin:'layui-layer-lan',title:'全部变体信息'," \
             u"fix:false,shadeClose: true,maxmin:true,area:['1600px','800px']," \
             u"content:'/mymallapp/t_mymall_online_info/ShopSKU/?abc=%s',});});</script>" % (rt, obj.id, obj.ProductID)

        # rt = rt + u"<script>function en_id_%s(shopsku) {layer.confirm(shopsku + '  请问确定要进行上架吗?'," \
        #           u"{btn: ['确定','算了'],btn1:function(){shopsku=shopsku.replace('#', '%%23');static_refresh('/mymallapp/up_dis_by_mymall_api_shopsku/?enshopsku='+shopsku+" \
        #           u"'&shopname=%s&flag=0');},});}</script>" % (obj.id, obj.ShopName)
        # rt = rt + u"<script>function dis_id_%s(shopsku) {layer.confirm(shopsku + '  请问确定要进行下架吗?'," \
        #           u"{btn: ['确定','算了'],btn1:function(){shopsku=shopsku.replace('#', '%%23');static_refresh('/mymallapp/up_dis_by_mymall_api_shopsku/?disshopsku='+shopsku+" \
        #           u"'&shopname=%s&flag=0')},});}</script>" % (obj.id, obj.ShopName)
        return mark_safe(rt)