浏览代码

【Add】产品导入

liuxiangxin 4 月之前
父节点
当前提交
9aaa94899a
共有 3 个文件被更改,包括 11 次插入12 次删除
  1. 4 2
      app/Http/Controllers/Admin/Product.php
  2. 4 5
      app/Http/Controllers/Api/Product.php
  3. 3 5
      app/Models/FilesManager.php

+ 4 - 2
app/Http/Controllers/Admin/Product.php

@@ -113,7 +113,7 @@ class Product extends Auth{
 	 * 表格导入
 	 * 
 	 * */
-	public function import_execl( Request $request,Model $Model,FilesManager $FilesManager){
+	public function import_execl( Request $request,Model $Model,ProductCity $ProductCity,FilesManager $FilesManager){
 		// 验证参数
 		// $request->scene('import_execl')->validate();
 		// 获取表格信息
@@ -131,8 +131,10 @@ class Product extends Auth{
 			$id								= $Model->add($value);
 			// 提示新增失败
 			if( !$id )						return json_send(['code'=>'error','msg'=>'新增失败']);
+			// 写入城市范围
+			$ProductCity->add(['city_id'=>1,'product_id'=>$id,'insert_time'=>time(),'update_time'=>time()]);
 			// 更新内容
-			$result							= $Model->updateDesc($id,$description);
+			$result							= $description ? $Model->updateDesc($id,$description) : true;
 			// 提示新增失败
 			if( !$result )					return json_send(['code'=>'error','msg'=>'更新内容失败']);
 		}

+ 4 - 5
app/Http/Controllers/Api/Product.php

@@ -47,18 +47,15 @@ class Product extends Api{
 		// 接收参数
 		$name					    = request('name','');
 		$limit						= request('limit',10);
+        $typeId						= request('type_id',0);
 		// 显示
 		$map						= [['status','=','0'],['stock','>',0]];
 		// 分类ID
 		if( $name )					$map[] = ['name','like','%'.$name.'%'];
-		// 是否有城市
-		$wherIn						= empty($custom['city_id']) ? [1] : [1,$custom['city_id']];
+		if( $typeId )			    $map[] = ['type_id','=',$typeId];
 		// 获取分页信息
 		$Paginator					= $Model->query()
-										->join('product_city','product_city.product_id','=','product.id')
 										->where($map)
-										->whereIn('product_city.city_id',$wherIn)
-										->groupBy('product_id')
 										->orderBy('product.sort')
 										->orderBy('product.id')
 										->paginate($limit,['product.id','product.sort','product.name','product.thumb','product.spec','product.price','product.market_price','product.stock']);
@@ -373,6 +370,8 @@ class Product extends Api{
         $uid						= $this->checkLogin();
         // 获取产品类型
         $list						= $ProductType->getList();
+        // 转数组
+        $list                       = array_values($list);
         // 返回结果
         return						json_send(['code'=>'success','msg'=>'获取成功','data'=>$list]);
     }

+ 3 - 5
app/Models/FilesManager.php

@@ -258,15 +258,13 @@ class FilesManager extends Model
                 // 适读
                 $order['grade']      = empty($order['grade']) ? '' : '【适读'. $order['grade'][0].'-'.$order['grade'][count($order['grade'])-1].'年级】';
             }
-            // 分类ID
-            $value['category_id']	 = 1;
             // 时间转换
-            $order['insert_time']    =  $order['insert_time'] ? strtotime($order['insert_time']) : 0;
-            $order['update_time']    =  $order['update_time'] ? strtotime($order['update_time']) : 0;
+            $order['insert_time']    = $order['insert_time'] ? strtotime($order['insert_time']) : 0;
+            $order['update_time']    = $order['update_time'] ? strtotime($order['update_time']) : 0;
             // 库存默认
             $order['stock']          = 99999;
             // 适读
-            $order['name']           = $order['grade'];
+            $order['name']           = $order['name'].$order['grade'];
             // 描述
             $order['description']    = str_ireplace('http://img.duibaoduikan.com/','https://edu.dfwy.tech/',$order['description']);
             // 删除数据