Browse Source

九方2.0版本

root 1 năm trước cách đây
mục cha
commit
fbc0530158

+ 38 - 0
app/Http/Controllers/Api/Device/BaseController.php

@@ -0,0 +1,38 @@
+<?php
+
+namespace App\Http\Controllers\Api\Device;
+
+use App\Http\Controllers\Controller;
+
+class BaseController extends Controller
+{
+    public $user_info;
+    public function __construct()
+    {
+    }
+
+    // 返回json数据
+    protected function json_return($code=200,$msg="Success",$data=[]){
+        if(!is_array($data)&&!is_object($data)) {
+            $msg = $data;
+            $data = '';
+        }
+        if(empty($msg)) $msg = '操作成功';
+        return ['code'=>$code,'msg'=>$msg,'data'=>$data];
+    }
+
+
+    //用户行为记录,暂时放这里具体用不用后期再加
+    public function user_log($data,$user,$id,$perm_id,$remark){
+
+    }
+
+
+
+
+
+
+
+
+
+}

+ 22 - 0
app/Http/Controllers/Api/Device/DeviceController.php

@@ -0,0 +1,22 @@
+<?php
+namespace App\Http\Controllers\Api\Device;
+
+use App\Service\Device\DeviceService;
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Log;
+
+
+class DeviceController extends BaseController
+{
+    public function deviceList(Request $request){
+        $service = new DeviceService();
+        list($status,$data) = $service->deviceList();
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+
+    }
+}

+ 0 - 17
app/Http/Controllers/Api/EmployeeController.php

@@ -342,23 +342,6 @@ class EmployeeController extends BaseController
     }
 
 
-    public function employeeRole(Request $request)
-    {
-
-
-        $service = new EmployeeService();
-        $user = $request->get('auth');
-        list($status,$data) = $service->upload_pic($request->all());
-
-        if($status){
-            return $this->json_return(200,'',$data);
-        }else{
-            return $this->json_return(201,$data);
-        }
-
-    }
-
-
 
 
 }

+ 53 - 0
app/Service/Device/DeviceService.php

@@ -0,0 +1,53 @@
+<?php
+
+namespace App\Service\Device;
+
+
+
+class DeviceService extends Service
+{
+
+
+    public function deviceList(){
+
+        $list = [
+            [
+                'id' => '1',
+                'title' => '木工',
+                'url' => '/cms/mg',
+                'device' => [
+                    'is_scan' => 1,
+                    'is_box' => 1,
+                ],
+            ],[
+                'id' => '2',
+                'title' => '油漆',
+                'url' => '/cms/yq',
+                'device' => [
+                    'is_scan' => 1,
+                    'is_box' => 0,
+                ],
+            ],[
+                'id' => '3',
+                'title' => '包装',
+                'url' => '/cms/bz',
+                'device' => [
+                    'is_scan' => 1,
+                    'is_box' => 1,
+                ],
+            ],[
+                'id' => '4',
+                'title' => '退出',
+                'url' => '/cms/login_out',
+                'device' => [
+                    'is_scan' => 1,
+                    'is_box' => 1,
+                ],
+            ],
+        ];
+
+        return [200,$list];
+    }
+
+
+}

+ 199 - 0
app/Service/Device/Service.php

@@ -0,0 +1,199 @@
+<?php
+
+namespace App\Service\Device;
+
+
+
+/**
+ * 公用的公共服务
+ * @package App\Models
+ */
+class Service
+{
+
+    public $log;
+    public $total = 0;
+
+    public function __construct()
+    {
+
+    }
+
+    //分页共用
+    public function limit($db, $columns, $request)
+    {
+        $per_page = $request['page_size'] ?? 9999;
+        $page = $request['page_index'] ?? 1;
+        $return = $db->paginate($per_page, $columns, 'page', $page)->toArray();
+
+        $data['total'] = $return['total'];
+        $data['data'] = $return['data'];
+        return $data;
+    }
+
+
+    //抽象一个查询条件,省的每天写很多行
+    protected function is_exist_db($data, $word, $words, $db, $formula = '=', $type = '')
+    {
+        if (isset($data[$word]) && ($data[$word] !== null && $data[$word] !== '' && $data[$word] !== [])) {
+            switch ($type) {
+                case 'time':
+                    $data[$word] = ctype_digit($data[$word]) ? $data[$word] : strtotime($data[$word]);
+                    if ($formula == '<'||$formula == '<=') $data[$word] += 86400;
+                    $db = $db->where($words, $formula, $data[$word]);
+                    break;
+                case 'like':
+                    $db = $db->where($words, $type, '%' . $data[$word] . '%');
+                    break;
+                case 'in':
+                    if (is_array($data[$word])) {
+                        $db = $db->wherein($words, $data[$word]);
+                    } else {
+                        $db = $db->wherein($words, explode(',', $data[$word]));
+                    }
+
+                    break;
+                default:
+                    $db = $db->where($words, $formula, $data[$word]);
+                    break;
+            }
+
+            return $db;
+        }
+        return $db;
+    }
+
+
+    //判断是否为空
+    protected function isEmpty($data, $word)
+    {
+        if (isset($data[$word]) && (!empty($data[$word]) || $data[$word] === '0'|| $data[$word] === 0)) return false;
+        return true;
+    }
+
+
+    //递归处理数据成子父级关系
+    public function makeTree($parentId, &$node)
+    {
+        $tree = [];
+        foreach ($node as $key => $value) {
+            if ($value['parent_id'] == $parentId) {
+                $tree[$value['id']] = $value;
+                unset($node[$key]);
+                if (isset($tree[$value['id']]['children'])) {
+                    $tree[$value['id']]['children'] = array_merge($tree[$value['id']]['children'], $this->makeTree($value['id'], $node));
+                } else {
+                    $tree[$value['id']]['children'] = $this->makeTree($value['id'], $node);
+                }
+            }
+        }
+        return $tree;
+    }
+
+    //进行递归处理数组的排序问题
+    public function set_sort_circle($data){
+        foreach ($data as $k=>$v){
+//            var_dump($v);die;
+            if(isset($v['children'])&&!empty($v['children'])){
+                $data[$k]['children'] =  $this->set_sort_circle($v['children']);
+            }
+        }
+        $data = array_merge($data);
+
+        return $data;
+    }
+
+
+    //根据编码规则获取每一级的code
+    public function get_rule_code($code, $rule)
+    {
+        $rules = [];
+        $num = 0;
+        foreach ($rule as $v) {
+            $num += $v['num'];
+            $code = substr($code, 0, $num);
+            if (strlen($code) != $num) continue;
+            $rules[] = $code;
+
+        }
+
+        return $rules;
+    }
+
+
+
+    function curlOpen($url, $config = array())
+    {
+        $arr = array('post' => false,'referer' => $url,'cookie' => '', 'useragent' => 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.0.04506; customie8)', 'timeout' => 100, 'return' => true, 'proxy' => '', 'userpwd' => '', 'nobody' => false,'header'=>array(),'gzip'=>true,'ssl'=>true,'isupfile'=>false,'returnheader'=>false,'request'=>'post');
+        $arr = array_merge($arr, $config);
+        $ch = curl_init();
+
+        curl_setopt($ch, CURLOPT_URL, $url);
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, $arr['return']);
+        curl_setopt($ch, CURLOPT_NOBODY, $arr['nobody']);
+        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
+        curl_setopt($ch, CURLOPT_USERAGENT, $arr['useragent']);
+        curl_setopt($ch, CURLOPT_REFERER, $arr['referer']);
+        curl_setopt($ch, CURLOPT_TIMEOUT, $arr['timeout']);
+
+
+        curl_setopt($ch, CURLOPT_HEADER, $arr['returnheader']);//��ȡheader
+        if($arr['gzip']) curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
+        if($arr['ssl'])
+        {
+            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
+            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
+        }
+        if(!empty($arr['cookie']))
+        {
+            curl_setopt($ch, CURLOPT_COOKIEJAR, $arr['cookie']);
+            curl_setopt($ch, CURLOPT_COOKIEFILE, $arr['cookie']);
+        }
+
+        if(!empty($arr['proxy']))
+        {
+            //curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
+            curl_setopt ($ch, CURLOPT_PROXY, $arr['proxy']);
+            if(!empty($arr['userpwd']))
+            {
+                curl_setopt($ch,CURLOPT_PROXYUSERPWD,$arr['userpwd']);
+            }
+        }
+
+        //ip�Ƚ����⣬�ü�ֵ��ʾ
+        if(!empty($arr['header']['ip']))
+        {
+            array_push($arr['header'],'X-FORWARDED-FOR:'.$arr['header']['ip'],'CLIENT-IP:'.$arr['header']['ip']);
+            unset($arr['header']['ip']);
+        }
+        $arr['header'] = array_filter($arr['header']);
+
+        if(!empty($arr['header']))
+        {
+            curl_setopt($ch, CURLOPT_HTTPHEADER, $arr['header']);
+        }
+
+        if($arr['request'] === 'put'){
+            curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, "PUT");
+            curl_setopt($ch, CURLOPT_POSTFIELDS,$arr['post']);
+        }elseif($arr['post'] != false)
+        {
+            curl_setopt($ch, CURLOPT_POST, true);
+            if(is_array($arr['post']) && $arr['isupfile'] === false)
+            {
+                $post = http_build_query($arr['post']);
+            }
+            else
+            {
+                $post = $arr['post'];
+            }
+            curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
+        }
+
+        $result = curl_exec($ch);
+        curl_close($ch);
+
+        return $result;
+    }
+
+}

+ 2 - 1
routes/api.php

@@ -96,4 +96,5 @@ Route::any('transportDetail', 'Api\OrderTransportController@transportDetail');
 Route::any('boxIn', 'Api\OrderBoxController@boxIn');
 Route::any('boxOut', 'Api\OrderBoxController@boxOut');
 Route::any('boxTransport', 'Api\OrderTransportController@boxTransport');
-Route::any('transportConfirm', 'Api\OrderTransportController@transportConfirm');
+Route::any('transportConfirm', 'Api\OrderTransportController@transportConfirm');
+Route::any('deviceList', 'Api\Device\DeviceController@deviceList');