wangtengyu
2018-12-07 f459412e0dac4ed94106da043b4c6f8576bfe496
commit | author | age
e2b48d 1 <?php
B 2
3 /**
4  * 商品内容
5 */
6     ob_start();
7     
8     require('includes/safety_mysql.php');
9     define('IN_ECS', true);
10     require('../includes/init.php');
11     //require('../includes/lib_goods.php');
12     $act = isset($_REQUEST['act'])  ? trim($_REQUEST['act']) : '';
13     $atxt = isset($_REQUEST['atxt'])  ? trim($_REQUEST['atxt']) : '';
14     $goods_id = isset($_REQUEST['goods_id'])  ? intval($_REQUEST['goods_id']) : 0;
15     $user_id = isset($_REQUEST['user_id'])  ? intval($_REQUEST['user_id']) : 0;
16     $result=array();
17     /*查找后台配置的库存管理*/
18     $sql="SELECT value FROM ".$ecs->table('shop_config')." WHERE id='207'";
19     $use_storage=$db ->getRow($sql);
20     $result['use_storage']=$use_storage;
21     
22     /*每100积分可抵多少元现金*/
23     $sql="SELECT value FROM ".$ecs->table('shop_config')." WHERE id='211'";
24     $shop_config=$db ->getRow($sql);
25     $shop_config_integral=$shop_config['value'];
26     
27     /*获取商品的图片*/
28     if(empty($act))
29     {  
30     $sql="SELECT img_url FROM ".$ecs->table('goods_gallery')." WHERE goods_id='$goods_id'  LIMIT 0 ,5 ";
31     $goods_gallery = $db -> getAll($sql);
32     /*获取商品的评论*/
33     //$sql="SELECT user_name,content,add_time FROM ".$ecs->table('comment')." WHERE id_value='$goods_id'  LIMIT 0 ,5 ";
34     //$comment = $db -> getAll($sql);
35     
36     /*获取商品的类型*/
37     
38     $sql="SELECT attr.goods_attr_id,attr.attr_value,attribute.attr_name 
39     FROM ".$ecs->table('goods_attr')." AS attr,".$ecs->table('attribute')." AS attribute  
40     WHERE attr.goods_id='$goods_id' AND attr.attr_id=attribute.attr_id ;";
41     
42     $sql="SELECT a.attr_id, a.attr_name, a.attr_group, a.is_linked, a.attr_type, g.goods_attr_id, g.attr_value, g.attr_price FROM ".$ecs->table('goods_attr')." AS g LEFT JOIN  ".$ecs->table('attribute')."  AS a ON a.attr_id = g.attr_id WHERE a.attr_group='0' AND  g.goods_id = '$goods_id' ORDER BY a.sort_order, g.attr_price, g.goods_attr_id";
43     $res = $db -> getAll($sql);
44     $goods_attr=array();
45     $attr=array();
46     $list=array();
47     
48     if(count($res)!=0){
49         foreach ($res AS $row)
50         {
51             
52             
53                 $arr[$row['attr_id']]['attr_id'] = $row['attr_id'];
54                 $arr[$row['attr_id']]['attr_type'] = $row['attr_type'];
55                 $arr[$row['attr_id']]['name']     = $row['attr_name'];
56                 $arr[$row['attr_id']]['values'][] = array(
57                                                             'label'        => $row['attr_value'],
58                                                             'price'        => $row['attr_price'],
59                                                             
60                                                             'id'           => $row['goods_attr_id']
61                                                             );
62         
63         }
64         foreach($arr AS $key =>$row){
65             $goods_attr[]=$row;
66         }
67     }
68     
69     $atr_price=0;
70     foreach ($goods_attr AS $key=>$val)
71     {
72
73
74         if($val['attr_type']==1)
75         {        //echo $val['attr_id'];
76             $atr_price+=$val['values'][0]['price'];
77         }
78         
79     }
80     //exit;
81
82     $sql="SELECT click_count FROM ".$ecs->table('goods')." WHERE goods_id='$goods_id'";
83     $goods=$db ->getRow($sql);
84     $click_count=$goods['click_count']+1;
85     $db -> query("update ".$ecs->table('goods')." set click_count = '$click_count' where goods_id = '$goods_id'");
86     
87     /*获取商品详细信息*/
88     $sql="SELECT 
89         g.goods_sn,
90         g.goods_name,
91         g.click_count,
92         g.brand_id,
93         g.goods_number,
94         g.goods_weight,
95         g.shop_price,
96         g.market_price,
97         g.promote_price,
98         g.promote_start_date,
99         g.promote_end_date,
100         g.goods_desc,
101         g.is_real,
102         g.is_promote,
103         g.integral,
104         g.give_integral,
105         g.rank_integral,
106         g.supplier_id,
107         ifnull(ssc.value,'网站自营') as shopname
108     FROM ".$ecs->table('goods')." AS g LEFT JOIN ".$ecs->table('supplier_shop_config')." AS ssc ON g.supplier_id=ssc.supplier_id AND ssc.code='shop_name' WHERE g.goods_id='$goods_id'";
109     $goods=$db ->getRow($sql);
110     $goods['shop_logo'] = $db ->getOne("select value from ".$ecs->table('supplier_shop_config')." where code='shop_logo' and supplier_id=".$goods['supplier_id']);
111     $goods['service_phone'] = $db ->getOne("select value from ".$ecs->table('supplier_shop_config')." where code='service_phone' and supplier_id=".$goods['supplier_id']);
112         $goods_price = $goods['shop_price'];
113     $goods['shop_price']+=$atr_price;
114     
115     $goods['integral']=$goods['integral']/$shop_config_integral*100;
116     if($goods['give_integral']==-1){
117         if($goods['is_promote']==1&&$goods['promote_start_date']<gmtime()&&$goods['promote_end_date']>gmtime()){
118             $goods['give_integral'] = intval($goods['promote_price']);
119         }else{
120             $goods['give_integral'] = intval($goods['shop_price']);
121         }
122     }
123     if($goods['rank_integral']==-1){
124         if($goods['is_promote']==1&&$goods['promote_start_date']<gmtime()&&$goods['promote_end_date']>gmtime()){
125             $goods['rank_integral']=$goods['promote_price'];
126         }else{
127             $goods['rank_integral']=$goods['shop_price'];
128         }
129     }
130     $goods['volume'] = get_volume($goods_id);//查询商品的优惠价格
131     $goods['shop_atr'] = $goods['shop_price']+$atr_price;//不是促销商品的总价格(加上属性价格)
132     $goods['promote_atr'] = $goods['promote_price']+$atr_price;//促销商品的总价格(加上属性价格)
133 //    $result['linked_goods']=get_linked_goods($goods_id);//获取指定商品的关联商品
134     $result['goods']=$goods;
135     $result['goods_gallery']=$goods_gallery;
136     $result['goods_attr']=$goods_attr;
137     $result['user_rank_info']=get_rank_info($user_id);
138     //$result['user_rank_prices']=get_user_rank_prices($goods_id, $goods['shop_price'],$user_id);
139     $result['user_rank_prices']=get_user_rank_prices($goods_id, $goods_price,$user_id,$atr_price,$goods['promote_price']);
140     foreach($user_rank_prices as $key => $value)
141     {
142         
143     }
144     $result['is_collect_goods']=is_collect_goods($goods_id,$user_id);
145     
146     print_r(json_encode($result));
147   }
148   elseif(!empty($atxt))
149   {
150       /*    $sql="SELECT 
151         shop_price    FROM ".$ecs->table('goods')." WHERE goods_id='$goods_id'";
152        $goods_price=$db ->getOne($sql);*/
153    // $goods['shop_price']+=$atr_price;
154        $sql="SELECT 
155         shop_price,
156         promote_price,
157         promote_start_date,
158         promote_end_date,
159         is_promote
160         FROM ".$ecs->table('goods')." WHERE goods_id='$goods_id'";
161        $goods=$db ->getRow($sql);
162        $shop_pricr = $goods['shop_price'];
163         if($goods['is_promote'] == 1 && $goods['promote_start_date'] < gmtime() && $goods['promote_end_date'] > gmtime() && $goods['shop_price'] > $goods['promote_price'])
164     {
165         $result['shop_price_shao'] = $goods['promote_price'];
166     }else
167     {
168         $result['shop_price_shao']= $goods['shop_price'];
169     }
170     if($goods['is_promote'] == 1 && $goods['promote_start_date'] < gmtime() && $goods['promote_end_date'] > gmtime())
171     {
172         $result['shop_price'] = $goods['promote_price'];
173     }else
174     {
175         $result['shop_price']= $goods['shop_price'];
176     }
177     $atr_price=0;
178     $goods_att=explode('@',$atxt);
179     $fuck = array_pop($goods_att);//弹出数组最后一个空值
180     sort($goods_att);
181     $good_attr = implode('|',$goods_att);
182     //判断所选属性是不是有库存
183     $sql = "SELECT product_number FROM ".$ecs->table('products')."WHERE goods_id = '$goods_id' and goods_attr = '$good_attr'";
184     $product_number = $db ->getOne($sql);
185     if(empty($product_number))
186     {
187         $result['error'] = '1';
188         $result['result'] = "所选属性库存不足";
189     }
190     foreach ($goods_att as $val)
191     {
192         
193         if(!empty($val))
194         {
195             $sql="SELECT `attr_price` FROM " .$ecs->table('goods_attr')." WHERE goods_id='$goods_id' AND `goods_attr_id`='$val'";
196             $atr_price+=$db->getOne($sql);
197         }
198         
199     }
200     $result['cart_price'] = $result['shop_price_shao']+$atr_price;        //本店售价加上属性价格
201 $result['is_promote'] = $goods['is_promote'];//$result['shop_price']=$goods_price+$atr_price;
202     $result['promote_start_date'] = $goods['promote_start_date'];
203     $result['promote_end_date'] = $goods['promote_end_date'];
204     $result['user_rank_info']=get_rank_info($user_id);
205     //$result['user_rank_prices']=get_user_rank_prices($goods_id, $result['shop_price'],$user_id);
206         $result['user_rank_prices']=get_user_rank_prices($goods_id, $shop_pricr,$user_id,$atr_price,$goods['promote_price']);
207     print_r(json_encode($result));
208   }
209     
210 /*=====================================的一些函数方法======================================*/
211     
212     
213     
214 /**
215  * 获得指定商品的各会员等级对应的价格
216  *
217  * @access  public
218  * @param   integer     $goods_id
219  * @return  array
220  */
221 function get_user_rank_prices($goods_id, $shop_price,$user_id,$atr_price,$promote_price)
222 {
223     $user_rank = $GLOBALS['db']->getOne("SELECT user_rank FROM " . $GLOBALS['ecs']->table('users') . " WHERE user_id = '$user_id'");
224     $sql = "SELECT rank_id, IFNULL(mp.user_price, r.discount * $shop_price / 100) AS price, r.rank_name, r.discount, r.show_price " .
225             'FROM ' . $GLOBALS['ecs']->table('user_rank') . ' AS r ' .
226             'LEFT JOIN ' . $GLOBALS['ecs']->table('member_price') . " AS mp ".
227                 "ON mp.goods_id = '$goods_id' AND mp.user_rank = r.rank_id ";
228     $res = $GLOBALS['db']->query($sql);
229
230     $arr = array();
231     while ($row = $GLOBALS['db']->fetchRow($res))
232     {
233
234         $arr[] = array(
235                         'rank_name' => htmlspecialchars($row['rank_name']),
236                         'rank_id'   => $row['rank_id'],
237                         'price'     => price_format($row['price']),
238                         'show_price'     => $row['show_price'],
239                         'price_promote'=>price_format($promote_price+$atr_price),
240                         'price_shop'=> price_format($row['price']+$atr_price));
241     }
242
243     return $arr;
244 }
245     
246 /**
247  * 获得会员等级
248  *
249  * @access  public
250  * @param   integer     $goods_id
251  * @return  array
252  */
253 function get_rank_info($user_id)
254 {
255     $user_rank = $GLOBALS['db']->getOne("SELECT user_rank FROM " . $GLOBALS['ecs']->table('users') . " WHERE user_id = '$user_id'");
256     
257     $sql = "SELECT rank_name FROM " . $GLOBALS['ecs']->table('user_rank') . " WHERE rank_id = '$user_rank'";
258     $row = $GLOBALS['db']->getRow($sql);
259     $rank_name=$row['rank_name'];
260     
261     return array('rank_name'=>$rank_name);
262 }
263     
264     
265
266 /**
267  * 判断用户是否收藏
268  *
269  * @param   string  $goods_id    商品编号
270  * @param   string  $user_id    用户编号
271  *
272  * @return  布尔值
273  */
274  function is_collect_goods($goods_id,$user_id)
275 {
276 $sql="SELECT * 
277     FROM  ".$GLOBALS['ecs']->table('collect_goods')." WHERE user_id='$user_id' and goods_id='$goods_id'";
278     
279     $isCollect=$GLOBALS['db'] ->getRow($sql);
280     
281     if(!empty($isCollect)){return true;}else{return false;}
282 }    
283 /**
284  *
285  *
286  *查询商品的优惠价格
287  *@param   string  $goods_id    商品编号
288  *
289  *
290  */
291 function get_volume($goods_id)
292 {
293     $sql = "SELECT * FROM ".$GLOBALS['ecs']->table('volume_price')."WHERE goods_id = '$goods_id' order by volume_number ASC";
294     $volume = $GLOBALS['db']->getAll($sql);
295     return $volume;
296     
297 }
298 ob_end_flush();
299 ?>
300