zoukankan      html  css  js  c++  java
  • ASP.Net SKU

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Net.Http;
    using System.Web.Http;
    using WebApplication22.Models;
    
    namespace WebApplication22.Controllers
    {
        public class DefaultController : ApiController
        {
            MyShopDB db = new MyShopDB();
            public object GetAll()
            {
                var list = db.Goods_SPU.ToList();
                var data = list.Select(p => new { Goods = p, Img = db.Image.Where(k => k.SPUID == p.Id ).FirstOrDefault().ImageUrl });
                return data;
            }
    
            public object GetOne(int Id)
            { 
                // 获取商品
                Goods_SPU goods = db.Goods_SPU.Find(Id);
                // 获取商品的SPU属性
                var goods_Attribute = (from S in db.SPUAttribute
                                       join A in db.Attribute
                                       on S.AID equals A.Id
                                       where A.AttributeType == 0
                                       select new
                                       {
                                          Id = S.SPID, // 商品ID
                                          AId = S.AID, // 属性ID
                                          AType = A.InputType ,// 属性的输入类型
                                          AName = A.AttributeName, //属性名
                                          AValue = db.AttributeValue.Where(p => p.AttributeId == S.AID).ToList(),// 属性值列表
                                          Value = S.Value // 实际值
                                       }).ToList();
                // 获取商品的SKU属性
                var goods_SKU_Attribute = (from S in db.SPUAttribute
                                           join A in db.Attribute
                                           on S.AID equals A.Id
                                           where A.AttributeType == 1
                                           select new
                                           {
                                               Id = S.SPID, // 商品ID
                                               AId = S.AID, // 属性ID
                                               AType = A.InputType,// 属性的输入类型
                                               AName = A.AttributeName, //属性名
                                               AValue = db.AttributeValue.Where(p => p.AttributeId == S.AID).ToList(),// 属性值列表
                                               Value = S.Value // 实际值
                                           }).ToList();
    
                var imgs = db.Image.Where(p => p.SPUID == Id).ToList();
                var sku = db.Goods_SKU.Where(p => p.SPUID == Id).ToList();
    
                return new {
                    Goods=goods, // 商品本身
                    Attr=goods_Attribute,  // 商品属性
                    SKUAttr = goods_SKU_Attribute, // 商品库存属性
                    Imgs =imgs,     // 商品图片
                    Sku=sku // 商品规格列表
                };
            }
        }
    }
    View Code

    后台

    @{
        ViewBag.Title = "Index";
    }
    
    <h2>Index</h2>
    
    <div id="dv">
        <table style="float:left">
            <tr>
                <td>
                    <img src="" width="80" height="120" />
                </td>
            <tr />
            
            <tr>
    
            <td>
                <span></span>
                <span></span>
            </td>
            </tr>
        </table>
    </div>
    <div style="clear:both"></div>
    
    <script>
        function load()
        {
            $.ajax({
                url: 'http://localhost:56334/api/Default/GetAll',
                type: 'get',
                dataType: 'json',
                success: function (data) {
                    $("#dv").empty();
                    $(data).each(function () {
                        $("#dv").append(
                              '<table style="float:left">'+
                              '  <tr>'+
                              '      <td>'+
                              '      <a href="/Default/Detail/'+this.Goods.Id+'">    <img src="'+this.Img+'" width="80" height="120" /></a>'+
                              '      </td></tr><tr>'+
                              '      <td>'+
                              '          <span>'+this.Goods.Name+'</span>'+
                              '          <span>'+this.Goods.Price+'</span>'+
                              '      </td>'+
                              '  </tr>'+
                            '</table>'
                        );
                    });
                }
            });
        }
        load();
    </script>
    View Code

    页面

  • 相关阅读:
    dede日期时间标签调用大全
    安全配置织梦系统初探参考[转载]
    最好最实用的PHP二次开发教程
    DEDE网站地图优化技巧
    模板引擎类dedetemplate.class.php使用说明【转自织梦官方】
    如何完成DEDE CMS外部数据库调用|不同数据库调用数据
    《DSP using MATLAB》示例Example5.10
    《DSP using MATLAB》示例Example5.9
    《DSP using MATLAB》示例Example5.8
    《DSP using MATLAB》示例Example5.7
  • 原文地址:https://www.cnblogs.com/XJNB/p/13383506.html
Copyright © 2011-2022 走看看