whj преди 4 години
родител
ревизия
6e856b1537

+ 33 - 0
app/Admin/Actions/Phone/Import.php

@@ -0,0 +1,33 @@
+<?php
+
+namespace App\Admin\Actions\Phone;
+
+use App\Imports\PhoneImport;
+use Encore\Admin\Actions\Action;
+use Illuminate\Http\Request;
+
+class Import extends Action
+{
+    protected $selector = '.import-tenant';
+
+    public function handle(Request $request)
+    {
+        $request->file('file');
+        $import = new PhoneImport();
+        $import->import($request->file('file'));
+        return $this->response()->success('导入完成!')->refresh();
+
+    }
+
+    public function form()
+    {
+        $this->file('file', '请选择文件');
+    }
+
+    public function html()
+    {
+        return <<<HTML
+        <a class="btn btn-sm btn-default import-tenant"><i class="fa fa-upload"></i>导入数据</a>
+HTML;
+    }
+}

+ 71 - 0
app/Admin/Controllers/PhoneInfoController.php

@@ -0,0 +1,71 @@
+<?php
+
+namespace App\Admin\Controllers;
+
+use App\Admin\Actions\Phone\Import;
+use App\Model\PhoneInfo;
+use Encore\Admin\Controllers\AdminController;
+use Encore\Admin\Form;
+use Encore\Admin\Grid;
+use Encore\Admin\Show;
+
+class PhoneInfoController extends AdminController
+{
+    /**
+     * Title for current resource.
+     *
+     * @var string
+     */
+    protected $title = '物联网手机号';
+
+    /**
+     * Make a grid builder.
+     *
+     * @return Grid
+     */
+    protected function grid()
+    {
+        $grid = new Grid(new PhoneInfo());
+
+        $grid->disableCreateButton(false);
+        $grid->column('id', __('编号'));
+        $grid->column('device_name', __('设备名称'));
+        $grid->column('phone', __('物联网卡号'));
+        // 将导入操作加入到表格的工具条中
+        $grid->tools(function (Grid\Tools $tools) {
+            $tools->append(new Import());
+        });
+
+        return $grid;
+    }
+
+    /**
+     * Make a show builder.
+     *
+     * @param mixed $id
+     * @return Show
+     */
+    protected function detail($id)
+    {
+        $show = new Show(PhoneInfo::findOrFail($id));
+
+
+        return $show;
+    }
+
+    /**
+     * Make a form builder.
+     *
+     * @return Form
+     */
+    protected function form()
+    {
+        $form = new Form(new PhoneInfo());
+
+        $form->text('device_name', __('设备名称'))->width('150px');
+        $form->text('phone', __('物联网号码'))->width('150px');;
+
+
+        return $form;
+    }
+}

+ 1 - 1
app/Admin/routes.php

@@ -21,6 +21,6 @@ Route::group([
     $router->get('/setting_form', 'Config\FormController@form');
     $router->get('/setting_form', 'Config\FormController@form');
     $router->post('/setting_form_save', 'Config\FormController@setting_form_save');
     $router->post('/setting_form_save', 'Config\FormController@setting_form_save');
     $router->resource('/setting', 'Config\ConfigController');
     $router->resource('/setting', 'Config\ConfigController');
-
+    $router->resource('phone_infos', PhoneInfoController::class);
 
 
 });
 });

+ 42 - 0
app/Imports/PhoneImport.php

@@ -0,0 +1,42 @@
+<?php
+
+namespace App\Imports;
+
+use App\Model\PhoneInfo;
+use Maatwebsite\Excel\Concerns\ToModel;
+use Maatwebsite\Excel\Concerns\WithStartRow;
+use Maatwebsite\Excel\Concerns\Importable;
+use Maatwebsite\Excel\Concerns\WithValidation;
+
+class PhoneImport implements ToModel,WithStartRow,WithValidation
+{
+    use Importable;
+
+    /**
+    * @param array $row
+    *
+    * @return \Illuminate\Database\Eloquent\Model|null
+    */
+    public function model(array $row)
+    {
+        return new PhoneInfo([
+            'phone' => $row[0]
+        ]);
+    }
+
+
+    // 从2行开始读取数据
+    public function startRow(): int
+    {
+        return 2;
+    }
+
+    // 验证
+    public function rules(): array
+    {
+        return [
+            '0' => 'required',
+        ];
+    }
+
+}

+ 13 - 0
app/Model/PhoneInfo.php

@@ -0,0 +1,13 @@
+<?php
+
+namespace App\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+class PhoneInfo extends Model
+{
+
+    protected $fillable = ['phone'];
+    public $timestamps = false;
+    protected $table  = 'phone_info';
+}

+ 15 - 16
public/testweb/testdevice.html

@@ -68,7 +68,7 @@
                 {{item}}
                 {{item}}
             </div>
             </div>
         </div>
         </div>
-        <div v-if="isshezhi" style="margin-top: 1rem; text-align: center">
+        <!-- <div v-if="isshezhi" style="margin-top: 1rem; text-align: center">
             <h1 style="font-size: 0.7rem;text-align: center">绿色地球定时定点设备调试</h1>
             <h1 style="font-size: 0.7rem;text-align: center">绿色地球定时定点设备调试</h1>
             <input type="text" disabled v-model="value" placeholder="">
             <input type="text" disabled v-model="value" placeholder="">
             <input type="text" v-model="phone" placeholder="请输入DTU绑定手机卡号">
             <input type="text" v-model="phone" placeholder="请输入DTU绑定手机卡号">
@@ -80,7 +80,7 @@
                 <option value="4">五箱可回收</option>
                 <option value="4">五箱可回收</option>
             </select>
             </select>
             <button @click="shezhi">立即设置</button>
             <button @click="shezhi">立即设置</button>
-        </div>
+        </div> -->
         <div v-if="isbox">
         <div v-if="isbox">
             <nav class="bianhao">
             <nav class="bianhao">
                 设备编号:{{arrdata.device_name}}
                 设备编号:{{arrdata.device_name}}
@@ -220,26 +220,26 @@
                                 this.phone = res.data.data.phone
                                 this.phone = res.data.data.phone
                                 this.typevalue = res.data.data.device_type
                                 this.typevalue = res.data.data.device_type
                                 this.findBox = false;
                                 this.findBox = false;
-                                this.isshezhi = true
-                            }
-                        })
-                    }
-
-                },
-                shezhi() {
-                    if (this.phone != "") {
-                        axios.get("/updateDevice?id=" + this.value + "&type=" + this.type + "&phone=" + this.phone).then(res => {
-                            console.log(res)
-                            if (res.data.status == 200) {
                                 this.isbox = true
                                 this.isbox = true
                                 this.getData()
                                 this.getData()
                             }
                             }
                         })
                         })
-                    } else {
-                        alert("请输入手机号")
                     }
                     }
 
 
                 },
                 },
+                // shezhi() {
+                //     if (this.phone != "") {
+                //         axios.get("/updateDevice?id=" + this.value + "&type=" + this.type + "&phone=" + this.phone).then(res => {
+                //             console.log(res)
+                //             if (res.data.status == 200) {
+                //                 this.isbox = true
+
+                //             }
+                //         })
+                //     } else {
+                //         alert("请输入手机号")
+                //     }
+                // },
                 startbtn(e) {
                 startbtn(e) {
                     //开始测试
                     //开始测试
                     axios.get("/send_protocol?id=" + this.value + "&type=" + this.type + "&status" + this.isstatus).then(res => {
                     axios.get("/send_protocol?id=" + this.value + "&type=" + this.type + "&status" + this.isstatus).then(res => {
@@ -369,7 +369,6 @@
                     axios.get("/getDevcielist").then(res => {
                     axios.get("/getDevcielist").then(res => {
                         this.Numarr = res.data.data
                         this.Numarr = res.data.data
                     })
                     })
-
                 }
                 }
             },
             },
         })
         })

+ 94 - 8
public/testweb/upgrade.html

@@ -50,9 +50,25 @@
                 {{item}}
                 {{item}}
             </div>
             </div>
             <input class="inputstyle" type="text" v-model="value" placeholder="请输入你需要升级的设备IMEI号码">
             <input class="inputstyle" type="text" v-model="value" placeholder="请输入你需要升级的设备IMEI号码">
-            <button class="btnstyle" @click="installbtn">点击设置</button>
+            <button class="btnstyle" @click="installbtn">点击搜索</button>
         </div>
         </div>
-        <div class="container" style="align-items: flex-start;" v-else>
+        <div v-if="isshezhi" style="margin-top: 1rem; text-align: center">
+            <h1 style="font-size: 0.7rem;text-align: center">绿色地球</h1>
+            <input type="text" class="inputstyle" disabled v-model="value" placeholder="">
+            <div v-for="(item,index) in phonedata" style="font-size: .5rem;margin-top: .3rem;" @click="tapphone(item)">
+                {{item}}
+            </div>
+            <input type="text" class="inputstyle" v-model="phone" placeholder="请输入DTU绑定手机卡号">
+            <br />
+            <select class="inputstyle" v-model="typevalue" @change="changeProduct($event)">
+                <option value="1">四箱</option>
+                <option value="2">五箱</option>
+                <option value="3">四箱可回收</option>
+                <option value="4">五箱可回收</option>
+            </select>
+            <button @click="shezhi" class="btnstyle">立即设置</button>
+        </div>
+        <div class="container" style="align-items: flex-start;" v-if="isbox">
             <div style="font-size: .5rem;">
             <div style="font-size: .5rem;">
                 设备IMEI号:{{equipment}}
                 设备IMEI号:{{equipment}}
             </div>
             </div>
@@ -94,10 +110,18 @@
                 versionNum: "",
                 versionNum: "",
                 isnew: "",
                 isnew: "",
                 Numarr: [],
                 Numarr: [],
-                list: []
+                list: [],
+                typevalue: "1",
+                phone: "",
+                type: 1,
+                isbox: false,
+                isshezhi: false,
+                phoneList: [],
+                phonedata: []
             },
             },
             mounted() {
             mounted() {
                 this.getNum()
                 this.getNum()
+                this.getphone()
             },
             },
             watch: {
             watch: {
                 value(newdata, jiu) {
                 value(newdata, jiu) {
@@ -109,9 +133,40 @@
                     if (newdata == "") {
                     if (newdata == "") {
                         this.list = []
                         this.list = []
                     }
                     }
+                },
+                phone(newdata, jiu) {
+                    console.log(newdata)
+                    if (typeof newdata === 'string') {
+                        if (newdata.trim().length !== 0) {
+                            this.debounce(this.phonechange, 1500);
+                        } else { }
+                    }
+                    if (newdata == "") {
+                        this.phonedata = []
+                    }
                 }
                 }
             },
             },
             methods: {
             methods: {
+                shezhi() {
+                    if (this.phone != "") {
+                        if (confirm("请再次确定选择的手机号和箱体类型选择正确,提交后不可变更")) {
+                            axios.get("/updateDevice?id=" + this.value + "&type=" + this.type + "&phone=" + this.phone).then(res => {
+                                console.log(res)
+                                if (res.data.status == 200) {
+                                    this.isshezhi = false
+                                    this.isbox = true
+                                    alert('设备更新中')
+                                }
+                            })
+                        }
+                    } else {
+                        alert("请输入手机号")
+                    }
+                },
+                changeProduct(e) {
+                    console.log(e)
+                    this.type = e.target.value
+                },
                 getNum() {
                 getNum() {
                     axios.get("/getDevcielist").then(res => {
                     axios.get("/getDevcielist").then(res => {
                         this.Numarr = res.data.data
                         this.Numarr = res.data.data
@@ -121,6 +176,10 @@
                     this.value = item
                     this.value = item
                     this.list = []
                     this.list = []
                 },
                 },
+                tapphone(item) {
+                    this.phone = item
+                    this.phonedata = []
+                },
                 changeStr() {
                 changeStr() {
                     this.list = []
                     this.list = []
                     this.Numarr.forEach(item => {
                     this.Numarr.forEach(item => {
@@ -130,6 +189,15 @@
                     })
                     })
                     console.log(this.list)
                     console.log(this.list)
                 },
                 },
+                phonechange() {
+                    this.phonedata = []
+                    this.phoneList.forEach(item => {
+                        if (item.substr(item.length - 4) == this.phone) {
+                            this.phonedata.push(item)
+                        }
+                    })
+                    console.log(this.phonedata)
+                },
                 debounce(fn, wait) {
                 debounce(fn, wait) {
                     if (this.fun !== null) {
                     if (this.fun !== null) {
                         clearTimeout(this.fun)
                         clearTimeout(this.fun)
@@ -152,11 +220,24 @@
                         axios.get("/getDevice?id=" + this.value).then(res => {
                         axios.get("/getDevice?id=" + this.value).then(res => {
                             console.log(res)
                             console.log(res)
                             if (res.data.status == 200) {
                             if (res.data.status == 200) {
-                                this.isInstall = false
-                                this.equipment = res.data.data.id
-                                this.isxian = res.data.data.status
-                                this.versionNum = res.data.data.version
-                                this.isnew = res.data.data.is_last
+                                if (res.data.data.phone != null && res.data.data.device_type != null && res.data.data.is_last == 0) {
+                                    this.isInstall = false
+                                    this.isbox = true
+                                    this.equipment = res.data.data.id
+                                    this.isxian = res.data.data.status
+                                    this.versionNum = res.data.data.version
+                                    this.isnew = res.data.data.is_last
+                                } else if (res.data.data.phone == null && res.data.data.device_type == null && res.data.data.is_last == 0) {
+                                    this.isInstall = false
+                                    this.isshezhi = true
+                                    this.equipment = res.data.data.id
+                                    this.isxian = res.data.data.status
+                                    this.versionNum = res.data.data.version
+                                    this.isnew = res.data.data.is_last
+                                } else {
+                                    alert('当前设备已是最新版本,已有箱体和已绑定手机号无需设置升级')
+                                }
+
                             } else {
                             } else {
                                 alert("无效设备")
                                 alert("无效设备")
                             }
                             }
@@ -178,6 +259,11 @@
                     } else {
                     } else {
                         alert('设备已是最新版本,无需更新')
                         alert('设备已是最新版本,无需更新')
                     }
                     }
+                },
+                getphone() {
+                    axios.get("/getPhonelist").then(res => {
+                        this.phoneList = res.data.data
+                    })
                 }
                 }
             }
             }
         })
         })

+ 1 - 0
routes/web.php

@@ -23,4 +23,5 @@ Route::get('/updateDevice', 'IndexController@updateDevice');
 Route::get('/getDevice', 'IndexController@getDevice');
 Route::get('/getDevice', 'IndexController@getDevice');
 Route::get('/upVersion', 'IndexController@upVersion');
 Route::get('/upVersion', 'IndexController@upVersion');
 Route::get('/getDevcielist', 'IndexController@getDevcielist');
 Route::get('/getDevcielist', 'IndexController@getDevcielist');
+Route::get('/getPhonelist', 'IndexController@getPhonelist');