diff --git a/.env b/.env
index 3dc1653..f1b98bc 100644
--- a/.env
+++ b/.env
@@ -7,7 +7,7 @@ APP_URL=http://localhost
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
-DB_DATABASE=lara
+DB_DATABASE=fuwu_17cct_com
DB_USERNAME=root
DB_PASSWORD=root
diff --git a/app/Common/functions.php b/app/Common/functions.php
index 1af78a1..641c138 100644
--- a/app/Common/functions.php
+++ b/app/Common/functions.php
@@ -8,4 +8,24 @@ function objectToArray($object) {
}
}
+if (!function_exists('lastSql')) {
+ function lastSql(){
+ $sql = DB::getQueryLog();
+ $query = end($sql);
+ return $query;
+ }
+}
+
+if (!function_exists('price')) {
+ /**
+ * 精确价格,只保留俩位小数
+ * @param int|float $price 价格
+ * @return float
+ */
+ function price($price)
+ {
+ return sprintf("%.02f", $price);
+ }
+}
+
?>
\ No newline at end of file
diff --git a/app/Http/Controllers/PurchaseController.php b/app/Http/Controllers/PurchaseController.php
index ca7baaf..8bc4dd1 100644
--- a/app/Http/Controllers/PurchaseController.php
+++ b/app/Http/Controllers/PurchaseController.php
@@ -319,32 +319,38 @@ public function ajax_get_attr(Request $request){
}
//采购商品详情
- public function detail()
+ public function detail(Request $request)
{
- $id=intval($_GET['id']);
+ // $id=intval($_GET['id']);
+ // $id = $request->input('id');
+ // $request->route( 'id' ); or $request->id;
+ $id = $request->id;
if(!session('account_info')){
- session('redirect_url',U('Purchase/detail',array('id'=>$id)));
- header("Location:".U("Biz/login"));
-
+ session('redirect_url',url('purchase/detail',array('id'=>$id)));
+ header("Location:".url("biz/login"));
}
-
-
- $where=" and pg.id=".$id;
-
+ //开启日志查询
+ DB::enableQueryLog();
//详情信息
- $info=M('pms_goods as pg')->join('fw_pms_goods_attr as fpga on fpga.goods_id=pg.id')->join('fw_pms_supplier as fps on fps.id=pg.supplier_id')->field('pg.id,pg.goods_name,pg.unit,pg.sales,pg.thumbnail,pg.price,pg.stock,pg.promotion_price,pg.market_price,pg.detail,pg.imgs,pg.car_ids,fpga.attr_val,fpga.attr_name_val,fps.name as supplier_name,fps.qq')->where('pg.is_sale=1 and pg.is_del=0 '.$where)->find();
- if(!$info){
+ $info = DB::table('pms_goods as pg')
+ ->leftJoin('pms_goods_attr as fpga','fpga.goods_id','=','pg.id')
+ ->leftJoin('pms_supplier as fps','fps.id','=','pg.supplier_id')
+ ->select('pg.id','pg.goods_name','pg.unit','pg.sales','pg.thumbnail','pg.price','pg.stock','pg.promotion_price','pg.market_price','pg.detail','pg.imgs','pg.car_ids','fpga.attr_val','fpga.attr_name_val','fps.name as supplier_name','fps.qq','pg.class_id')
+ ->where([['pg.is_sale','=',1],['pg.is_del','=',0],['pg.id','=',$id]])
+ ->first();
+ // dd(lastSql());
+ $info = objectToArray($info);
+ // dd($info);
+ /*if(!$info){
$this->error('商品不存在或已下架',U('Purchase/index'),3);
- }
+ return redirect('home/dashboard');
- $info['imgs']=array_values(array_filter(explode(',',$info['imgs'])));
+ }*/
-
- // if($info['promotion_price']>0){
- // $info['price']=$info['promotion_price'];
- // }
- $info['detail']=str_replace('src="/ueditor/','src="http://www.17cct.com/ueditor/',$info['detail']);
+ $info['imgs'] = array_values(array_filter(explode(',',$info['imgs'])));
+
+ $info['detail'] = str_replace('src="/ueditor/','src="http://www.17cct.com/ueditor/',$info['detail']);
$attr_val=explode(',',$info['attr_name_val']);
foreach ($attr_val as $k => $v) {
@@ -386,7 +392,14 @@ public function detail()
//适用车型
if($info['car_ids']){
- $car_list = M('car')->field('id,name,parent_id,level')->where('level in(0,1,2) and id in('.$info['car_ids'].')')->select();
+ // $car_list = M('car')->field('id,name,parent_id,level')->where('level in(0,1,2) and id in('.$info['car_ids'].')')->select();
+ $car_list = DB::table('car')->select('id','name','parent_id','level')
+ ->whereIn('level',[0,1,2])
+ ->whereIn('id',$info['car_ids'])
+ ->get();
+ //将对象转换成数组
+ $car_list = get_object_vars($car_list);
+ dd($car_list);
if($car_list){
foreach ($car_list as $k => $v) {
if($v['level'] == 1){
@@ -401,14 +414,20 @@ public function detail()
}
}
}
- $cart_info=$this->get_location_cart_info();
- $this->assign('cart_num',intval($cart_info['number']));
- $this->assign("attr_vals",$attr_vals);
- $this->assign("attr_names",$attr_names);
- $this->assign("car",$car);
- $this->assign('info',$info);
- $this->assign('title',$info['goods_name']);
- $this->display();
+ $cart_info = $this->get_location_cart_info();
+ $cart_info = get_object_vars($cart_info);
+ // dd($cart_info);
+ $cart_num = intval($cart_info['number']);
+ $title = $info['goods_name'];
+ $no_include = 0;
+ // $this->assign('cart_num',intval($cart_info['number']));
+ // $this->assign("attr_vals",$attr_vals);
+ // $this->assign("attr_names",$attr_names);
+ // $this->assign("car",$car);
+ // $this->assign('info',$info);
+ // $this->assign('title',$info['goods_name']);
+ // $this->display();
+ return view('purchase/detail',compact('cart_num','attr_vals','attr_names','car','info','title','no_include'));
}
//加入购物车
@@ -1728,14 +1747,17 @@ public function goods_stock_info($goods_id,$goods_num){
//获取门店购物车中的商品数量
public function get_location_cart_info(){
- $location_id=$this->get_location_ids();
- $info=M()->query("select sum(number) as number,sum(price*number) as total_price from fw_pms_erp_cart where location_id=".$location_id." limit 1");
+ $location_id = $this->get_location_ids();
+ // $info=M()->query("select sum(number) as number,sum(price*number) as total_price from fw_pms_erp_cart where location_id=".$location_id." limit 1");
+ $info = DB::select("select sum(number) as number,sum(price*number) as total_price from fw_pms_erp_cart where location_id=? limit 1",[$location_id]);
+ // dd($info);
+ // $info = get_object_vars($info);
return $info[0];
}
//返回当前登录门店id
public function get_location_ids(){
- $account_info=session('account_info');
+ $account_info = session('account_info');
return $account_info['location_ids'][0];
}
diff --git a/resources/views/purchase/detail.html b/resources/views/purchase/detail.blade.php
similarity index 72%
rename from resources/views/purchase/detail.html
rename to resources/views/purchase/detail.blade.php
index ebc1de1..9cc8db3 100644
--- a/resources/views/purchase/detail.html
+++ b/resources/views/purchase/detail.blade.php
@@ -1,5 +1,5 @@
-
-
+@include('layouts.header')
+
@@ -71,38 +71,35 @@
.shoppingCart{left: 10px;}
.purchase_index{left: 54px; }
.shoppingCart a, .purchase_index a{ width: 36px; height: 36px;}
-.shoppingCart a{background: url(__PUBLIC__/images/shoppingCart.svg) no-repeat center;background-size: 20px;}
-.purchase_index a{background: url(__PUBLIC__/images/purchase_index.svg) no-repeat center;background-size: 30px;}
+.shoppingCart a{background: url({{asset('images/shoppingCart.svg')}} no-repeat center;background-size: 20px;}
+.purchase_index a{background: url({{asset('images/purchase_index.svg')}} no-repeat center;background-size: 30px;}
-
-
+
-
-
+ @if ($info['imgs'] != null)
+ @foreach ($info['imgs'] as $img)
-
+
-
-
+ @endforeach
+ @endif
-
-
+
+
- <{$info.supplier_name}>
-
-
-
+ {{$info['supplier_name']}}
@@ -176,68 +170,61 @@ <{$info.goods_name}>
- <{$info.detail}>
+ {{$info['detail']}}
-
-
+ @foreach ($attr_names as $key => $an)
- <{$an}> |
- <{$attr_vals[$key]}> |
+ {{$an}} |
+ {{$attr_vals[$key]}} |
-
+ @endforeach
-
-
+ @if (!empty($car))
+ @foreach ($car as $c)
- <{$c.cate2}> |
- <{$c.cate3}> |
+ {{$c['cate2']}} |
+ {{$c['cate3']}} |
-
-
-
+ @endforeach
+ @endif
-
+ @if ($info['qq'])
-
+ @endif
-
+
-
-
+@include('layouts.purchase_bottom')
diff --git a/routes/web.php b/routes/web.php
index b150ab0..ec8428f 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -17,6 +17,8 @@
Route::get('/biz/entrance', 'BizController@entrance');
Route::get('/biz/login', 'BizController@login');
Route::get('/purchase/home', 'PurchaseController@home');
+// Route::get('/purchase/detail/', 'PurchaseController@detail');
+Route::get('/purchase/detail/{id}','PurchaseController@detail');
Route::get('/purchase/ajax_get_qualitygoods', 'PurchaseController@ajax_get_qualitygoods');
Route::get('/purchase/index', 'PurchaseController@index');
/*Route::get('/biz/ajax_login', function() {