cqpCow 1 ano atrás
pai
commit
91e017cc38

+ 36 - 0
app/Http/Controllers/Api/BoxController.php

@@ -158,4 +158,40 @@ class BoxController extends BaseController
         }
 
     }
+
+    public function boxAdd(Request $request)
+    {
+        $service = new BoxService();
+        list($status,$data) = $service->boxIn($request->all());
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
+    public function boxFhDetail(Request $request)
+    {
+        $service = new BoxService();
+        list($status,$data) = $service->boxIn($request->all());
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
+    public function boxFhDel(Request $request)
+    {
+        $service = new BoxService();
+        list($status,$data) = $service->boxFhDel($request->all());
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
 }

+ 12 - 0
app/Http/Controllers/Api/FyyOrderController.php

@@ -152,4 +152,16 @@ class FyyOrderController extends BaseController
             return $this->json_return(201,$data);
         }
     }
+
+    public function getYyShipmentOrder(Request $request){
+        $service = new FyyOrderService();
+        $userData = $request->userData->toArray();
+        list($status,$data) = $service->getYyShipmentOrder($request->all(),$userData);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
 }

+ 86 - 1
app/Service/Box/BoxService.php

@@ -591,7 +591,92 @@ class BoxService extends Service
 
         return [true,'删除成功'];
     }
-//    public function
 
+    public function boxAdd($data)
+    {
+        list($status,$msg) = $this->boxAddRule($data);
+        if(! $status) return [false,$msg];
+
+        try{
+            DB::beginTransaction();
+            $box = new Box();
+            $box->order_no = $msg['order_no'];
+            $box->save();
 
+            DB::table('box_detail')->insert($msg['detail']);
+
+            DB::commit();
+            return [true,''];
+        }catch (\Exception $e){
+
+            DB::rollBack();
+            return [false,$e->getLine().':'.$e->getMessage()];
+        }
+    }
+
+    public function boxAddRule($data)
+    {
+        if(empty($data['param'])) return [false,'请选择包装数据'];
+        $order_no = (new BoxHookService())->setOrderNo();
+        $detail = [];
+        foreach ($data['param'] as $value) {
+            $key = $this->lock_key.'_'.$value['idlsid'];
+            list($status,$msg) = $this->limitingSendRequestBackg($key);
+            if(! $status) return [false,$msg];
+
+            if(empty($value['submit_quantity']) || ! is_numeric($value['submit_quantity']) || $value['submit_quantity'] > $value['quantity']) return [false,'包装数量错误'];
+            if(empty($value['team_id'])) return [false,'班组必须选择'];
+
+            $detail[] = [
+                'order_no' => $order_no,
+                'out_order_no' => $value['csocode'],
+                'crt_time' => time(),
+                'upd_time' => time(),
+                'type' => 1,
+                'ext_1' => $value['cinvcode'],
+                'ext_2' => $value['technology_material'],
+                'ext_3' => $value['cfree1'] ?? "",
+                'ext_4' => $value['cfree2'] ?? "",
+                'ext_5' => $value['process_mark'],
+                'ext_6' => $value['customer_name'] ?? "",
+                'ext_7' => $value['cuscode'] ?? "",
+                'ext_8' => $value['product_title'],
+                'ext_9' => $value['product_size'],
+                'top_id' => $value['idlsid'],
+                'state' => 0,
+                'num' => $value['submit_quantity'],
+                'box_type' => 2,
+                'team_id' => $value['team_id'],
+                'shipment_order_no' => $value['cdlcode'],
+            ];
+        }
+
+        return [true,['order_no' => $order_no, 'detail' => $detail]];
+    }
+
+    public function boxFhDetail($data){
+        if(empty($data['idlsid'])) return [false,'请选择数据'];
+
+        $result = DB::table('box_detail')->where('del_time',0)
+            ->select('order_no','ext_6','ext_7','ext_1','ext_8','ext_9','num','ext_2','ext_3','ext_4','ext_5')
+            ->get()->toArray();
+        if(! empty($result)){
+            foreach ($result as $key => $value){
+                $result[$key] = (array)$value;
+            }
+        }
+
+        return [true,$result];
+    }
+
+    public function boxFhDel($data){
+        if(empty($data['order_nos'])) return [false,'包装单号不能为空'];
+
+        $box = Box::whereIn('order_no',$data['order_nos'])->update(['del_time' => time()]);
+
+        DB::table('box_detail')->whereIn('order_no',$data['order_nos'])->where('del_time',0)->update([
+            'del_time' => time()
+        ]);
+        return [true,''];
+    }
 }

+ 11 - 0
app/Service/FyyOrderService.php

@@ -436,4 +436,15 @@ class FyyOrderService extends Service
 
         return [true, array_column($order,'out_order_no')];
     }
+
+    public function getYyShipmentOrder($data,$user){
+        if(empty($data['time'][0]) || empty($data['time'][1])) return ['false', '时间范围不能为空!'];
+
+        $sqlServerModel = new FyySqlServerService($user);
+        if($sqlServerModel->error) return [false,$sqlServerModel->error];
+
+        $result = $sqlServerModel->getDataFromDispatchListPage($data);
+
+        return [true,$result];
+    }
 }

+ 36 - 0
app/Service/FyySqlServerService.php

@@ -590,4 +590,40 @@ class FyySqlServerService extends Service
         curl_close($ch);
         return json_decode($r, true);
     }
+
+    //获取发货单数据 还没发的 分页
+    public function getDataFromDispatchListPage($data){
+        //检索条件
+        if(empty($data['time'][0]) || empty($data['time'][1])) return [false,'时间不能为空'];
+
+        $model = $this->db->table('DispatchList as a')
+            ->leftJoin('DispatchLists as b','b.DLID','a.DLID')
+            ->leftJoin('Inventory as c','c.cInvCode','b.cInvCode')
+            ->select('a.cDLCode as cdlcode','a.DLID as id','a.cDefine10 as customer_name','b.cSOCode as csocode','a.cDepCode as cdepcode','a.cCusCode as cuscode','a.dDate as date','b.iDLsID as idlsid','b.cWhCode as cwhcode','b.cInvCode as cinvcode','b.cInvName as product_title','b.cFree1 as cfree1','b.cFree2 as cfree2','b.cPosition as cposition','b.cBatch as cbatch','b.iQuantity as iquantity','b.iNum as inum','b.iInvExchRate as iinvexchrate','b.fOutQuantity as out_quantity','b.iUnitPrice as iunitcost','b.iMoney as imoney','b.cDefine28 as technology_material','b.cDefine30 as process_mark','c.cInvStd as product_size',DB::raw('(b.iQuantity - b.fOutQuantity) as quantity'))
+            ->whereNotNull('a.cVerifier')
+            ->whereColumn('b.iQuantity', '>', 'b.fOutQuantity')
+            ->where('a.dDate','>=',$data['time'][0])
+            ->where('a.dDate','<=',$data['time'][1]);
+
+        $list = $this->limit($model,'',$data);
+
+        if(! empty($list['data'])){
+            $product_no = array_unique(array_column($list['data'],'cinvcode'));
+            $messageMap = $this->db->table('Inventory as a')
+                ->join('ComputationUnit as b', function ($join) {
+                    $join->on('a.cGroupCode', '=', 'b.cGroupCode')
+                        ->on('a.cComUnitCode', '=', 'b.cComUnitCode');
+                }, null, null, 'left')
+                ->whereIn('a.cInvCode', $product_no)
+                ->pluck( 'b.cComUnitName as product_unit','a.cInvCode')
+                ->toArray();
+
+            foreach ($list['data'] as $key => $value){
+                $list['data'][$key] = (array)$value;
+                $list['data'][$key]['unit'] = $messageMap[$value->cinvcode] ?? '';
+            }
+        }
+
+        return $list;
+    }
 }

+ 15 - 0
app/Service/Service.php

@@ -4,6 +4,7 @@ namespace App\Service;
 
 
 use Illuminate\Support\Facades\Cache;
+use Illuminate\Support\Facades\Redis;
 
 /**
  * 公用的公共服务
@@ -257,4 +258,18 @@ class Service
     function delLock($key){
         Cache::forget($key);
     }
+
+    //后台端 某些需要限制请求频率的接口
+    public function limitingSendRequestBackg($key,$ttl = 5){
+        if($ttl < 5) $ttl = 5;
+
+        // 使用Redis Facade设置,当键名不存在时才设置成功
+        if (Redis::setnx($key, 1)) {
+            Redis::expire($key, $ttl); //多少秒后过期
+
+            return [true, ''];
+        }
+
+        return [false,'操作频繁, 请在 ' . $ttl . '秒后重试'];
+    }
 }

+ 6 - 0
routes/api.php

@@ -236,4 +236,10 @@ Route::group(['middleware'=> ['checkLogin']],function ($route){
     $route->any('delBoxDetail', 'Api\BoxController@delBoxDetail');
     //包装扫码出库
     $route->any('fyySaveOutOrder','Api\FyyOrderController@fyySaveOutOrder');
+
+    //发货包装单
+    $route->any('getYyShipmentOrder', 'Api\FyyOrderController@getYyShipmentOrder');
+    $route->any('boxAdd','Api\BoxController@boxAdd');
+    $route->any('boxFhDetail','Api\BoxController@boxFhDetail');
+    $route->any('boxFhDel','Api\BoxController@boxFhDel');
 });