afa 5 сар өмнө
parent
commit
1588b71d25

+ 32 - 3
app/api/controller/Inventory.php

@@ -12,18 +12,47 @@ class Inventory extends Base
 {
 
 
-
     //品种包装箱/出入库列表
-    public function stockList( StockConfig $stockConfig)
+    public function stockList(StockConfig $stockConfig)
     {
         $type_id = $this->request->post('type_id', 'variety_name');
         if(!in_array($type_id, [$stockConfig::VarietyName, $stockConfig::PackingBox, $stockConfig::Material])) $this->error(__('参数错误'));
-        $list = $stockConfig::where('type_id', $type_id)->field('id,title')->select();
+        $list = $stockConfig::where('type_id', $type_id)->field('id,title,field_name')->select();
 
         $this->success('ok', $list);
     }
 
 
+    //添加出入库
+    public function stock(ApiAuthService $authService)
+    {
+        
+        $data = $this->request->post();
+        $result = false;
+        Db::startTrans();
+        try {
+            
+            $where['user_id'] = $this->userinfo['id'];
+          
+        
+            //join
+            $data['variety'] = json_encode($data['variety'], JSON_UNESCAPED_UNICODE);
+            $result = $userEnterLog::create($data);
+
+            Db::commit();
+        }catch (ValidateException $e) {
+      
+            return $this->error($e->getError());
+        } catch (\Exception $e) {
+            Db::rollback();
+            $this->error($e->getMessage());
+        }
+        if ($result === false) {
+            $this->error(__('没有新增任何数据'));
+        }
+        $this->success();
+    }
+
     //出入库记录
     public function stocklog(ApiAuthService $authService)
     {

+ 18 - 3
app/api/controller/Shops.php

@@ -34,6 +34,7 @@ class Shops extends Base
         return $this->success('ok', $shopList->where('platform', $platform_id)->column('name', 'id'));   
     }
 
+    
 
     //获取规格
     public function getSpec(ShopList $shopList){
@@ -47,12 +48,26 @@ class Shops extends Base
         return $this->success('ok', $shopList);  
     }
 
+
     //发货记录
     public function delivery(ShopDelivery $shopDelivery){
 
-        $data = $this->request->post();
-        $result = $shopDelivery::where($data)->select();
-        $this->success();
+        $plat_id = $this->request->post('plat_id/d', 0); //平台
+        $shop_id = $this->request->post('shop_id/d', 0); //店铺
+        $variety_id = $this->request->post('variety_id/d', 0); //品种
+
+        $where['a.user_id'] = $this->userinfo['id'];
+        if($plat_id  > 0) $where['a.plat_id']   = $plat_id;
+        if($shop_id  > 0) $where['a.shop_id']   = $shop_id;
+        if($variety_id  > 0) $where['a.variety_id']= $variety_id;
+        $result = $shopDelivery::alias('a')
+                ->leftjoin('shop_list b', 'a.shop_id = b.id') //店铺
+                ->leftjoin('stock_config c', 'a.variety_id = c.id') //品种
+                ->leftjoin('product_config d', 'a.spec_id = d.id') //规格
+                ->field('a.id,a.num, b.name shop_name,c.title variety_name,d.title spec_name')
+                ->where($where)
+                ->paginate(15);
+        $this->success('ok', $result);
     }
 
 

+ 5 - 1
app/api/route/route.php

@@ -21,15 +21,19 @@ Route::group('user', function () {
     //规格
     Route::rule('specs','shops/getSpec','POST');
 
+
     //添加记录
     Route::rule('create','shops/create','POST');
 
     //发货记录
     Route::rule('delivery','shops/delivery','POST');
 
-    //出入库
+    //出入库数据
     Route::rule('stockList','inventory/stockList','POST');
 
+    //出入库
+    Route::rule('stock','inventory/stock','POST');
+
     //库存记录
     Route::rule('stocklog','inventory/stocklog','POST');
 

+ 7 - 0
app/common/model/ShopDelivery.php

@@ -17,6 +17,13 @@ class ShopDelivery Extends Model
         'updatetime'     =>  'timestamp:Y-m-d H:i',
     ];
 
+
+
+    
+
+
+
+
     public static function onAfterInsert($data)
     {
         $data->weigh=1000-$data->id;