李浩杰 4 سال پیش
والد
کامیت
fc7d49a7a2

+ 6 - 0
app/Http/Controllers/Admin/ProjectController.php

xqd
@@ -130,4 +130,10 @@ class ProjectController extends BaseController
         $this->model->where('id', $request->input('id'))->update(['active' => $request->input('active')]);
         return response()->json(['status' => 'success', 'info' => '操作成功']);
     }
+
+    public function active(Request $request)
+    {
+        $this->model->where('id', $request->input('id'))->update(['active' => 1]);
+        return response()->json(['status' => 'success', 'info' => '操作成功']);
+    }
 }

+ 11 - 0
app/Http/Controllers/Admin/RepairDeviceController.php

xqd xqd xqd xqd
@@ -3,6 +3,7 @@
 namespace App\Http\Controllers\Admin;
 
 use App\Models\InnerDevice;
+use App\Models\Part;
 use App\Models\RepairDevice;
 use Illuminate\Http\Request;
 
@@ -34,6 +35,12 @@ class RepairDeviceController extends BaseController
         return view($this->view_path . 'index', compact('model', 'model_name','pre_uri', 'inner_device'));
     }
 
+    public function all(Request $request)
+    {
+        list($model, $model_name, $pre_uri) = array($this->model, $this->model_name, $this->pre_uri);
+        return view($this->view_path . 'all', compact('model', 'model_name','pre_uri'));
+    }
+
     public function get(Request $request)
     {
         $items = $this->model->orderBy('created_at', 'desc');
@@ -57,6 +64,9 @@ class RepairDeviceController extends BaseController
         foreach ($items as $item) {
             $item->user_name = $item->user ? $item->user->name : '';
             $item->project_name = $item->project ? $item->project->name : '';
+            $item->number = $item->inner_device ? $item->inner_device->number : '';
+            $item->device_name = $item->inner_device ? ($item->inner_device->device_name ? $item->inner_device->device_name->name : '') : '';
+            $item->work_point_name = $item->work_point ? $item->work_point->name : '';
         }
 
         return response()->json(['code' => 0, 'message' => '', 'count' => $items->total(), 'data' => $items->items()]);
@@ -105,6 +115,7 @@ class RepairDeviceController extends BaseController
     public function delete(Request $request)
     {
         if(empty($request->input('id')) || empty($item = $this->model->find($request->input('id')))) return response()->json(['status' => 'fail', 'info' => '找不到要删除的数据']);
+        Part::where('repair_device_id', $item->id)->delete();
         $res = $item->delete();
         if (!$res) return response()->json(['status' => 'fail', 'info' => '删除失败']);
         return response()->json(['status' => 'success', 'info' => '操作成功']);

+ 1 - 0
app/Http/Controllers/Api/mini/AuthController.php

xqd
@@ -33,6 +33,7 @@ class AuthController extends BaseController
         }
         if($session_key) {
             $data = $app->encryptor->decryptData($session_key, $request->input('iv'), $request->input('encryptedData'));
+            Log::info($data);
             if(isset($data['openId'])) {
                 if($request->input('bind')) {
                     $token = $request->header('X-Token');

+ 7 - 0
app/Http/Controllers/Api/mini/ProjectController.php

xqd xqd
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Api\mini;
 
 use App\Models\Project;
 use App\Models\ProjectUser;
+use App\Models\User;
 use Illuminate\Http\Request;
 use Illuminate\Database\Eloquent\Builder;
 use Illuminate\Support\Facades\Auth;
@@ -101,6 +102,12 @@ class ProjectController extends BaseController
             $project_ids = ProjectUser::where('user_id', $request->input('user_id'))->pluck('project_id');
             if(count($project_ids) > 0) $items = $items->whereNotIn('id', $project_ids);
         }
+        if($request->input('self')) {
+            $user = Auth::guard('mini')->user();
+
+            $project_ids = ProjectUser::where('user_id', $user->id)->pluck('project_id');
+            $items = $items->whereIn('id', $project_ids);
+        }
         $items = $items->get();
         return $this->success(['msg' => '创建成功', 'data' => $items]);
     }

+ 14 - 3
app/Http/Controllers/WechatController.php

xqd
@@ -2,13 +2,24 @@
 
 namespace App\Http\Controllers;
 
-use Illuminate\Http\Request;
+use App\Models\User;
+use App\Models\WechatInfo;
 
 class WechatController extends Controller
 {
     public function index()
     {
-        $user = session('wechat.oauth_user.default');
-        dd($user);
+        $wechat_user = session('wechat.oauth_user.default');
+        if($wechat_user && isset($wechat_user['original'])) {
+            $official_open_id = $wechat_user['original']['openid'];
+            $union_id = $wechat_user['original']['unionid'];
+            WechatInfo::firstOrCreate([
+                'official_open_id' => $official_open_id,
+                'union_id' => $union_id
+            ]);
+            User::where('union_id', $union_id)->update(['official_open_id' => $official_open_id]);
+            return '授权成功';
+        }
+        return '授权失败';
     }
 }

+ 10 - 0
app/Models/RepairDevice.php

xqd
@@ -18,4 +18,14 @@ class RepairDevice extends BaseModel
     {
         return $this->belongsTo('App\Models\Project', 'project_id');
     }
+
+    public function inner_device()
+    {
+        return $this->belongsTo('App\Models\InnerDevice', 'inner_device_id');
+    }
+
+    public function work_point()
+    {
+        return $this->belongsTo('App\Models\WorkPoint', 'work_point_id');
+    }
 }

+ 8 - 0
app/Models/WechatInfo.php

xqd
@@ -0,0 +1,8 @@
+<?php
+
+namespace App\Models;
+
+class WechatInfo extends BaseModel
+{
+    //
+}

+ 31 - 0
database/migrations/2021_01_17_102922_add_official_open_id_to_users.php

xqd
@@ -0,0 +1,31 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class AddOfficialOpenIdToUsers extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('users', function (Blueprint $table) {
+            $table->string('official_open_id', 200)->after('open_id')->nullable();
+            $table->string('union_id', 200)->after('open_id')->nullable();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        //
+    }
+}

+ 34 - 0
database/migrations/2021_01_17_103048_create_wechat_infos_table.php

xqd
@@ -0,0 +1,34 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CreateWechatInfosTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('wechat_infos', function (Blueprint $table) {
+            $table->increments('id');
+            $table->string('open_id', 200)->nullable();
+            $table->string('official_open_id', 200)->nullable();
+            $table->string('union_id', 200)->nullable();
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('wechat_infos');
+    }
+}

+ 38 - 20
mini/custom-tab-bar/index.js

xqd xqd xqd xqd
@@ -1,9 +1,9 @@
 Component({
 	data: {
+		activeUrl: '',
 		active: 0,
 		list: [],
-		initList: [
-			{
+		initList: [{
 				icon: 'home-o',
 				text: '首页',
 				url: '/pages/index/index',
@@ -26,21 +26,32 @@ Component({
 	},
 
 	lifetimes: {
-		attached: function() {
-			
-    },
+		attached: function () {
+
+		},
 	},
 
 	methods: {
+		switchTab(e) {
+			var url = e.currentTarget.dataset.url
+			if (url && this.data.activeUrl != url) {
+				wx.switchTab({
+					url: url
+				})
+			}
+
+		},
 		onChange(e) {
-			this.setData({ active: e.detail });
+			this.setData({
+				active: e.detail
+			});
 			var active = e.detail
 			var cnt = -1;
 			var list = this.data.list
 			var url = '';
-			for(var i = 0; i < list.length; ++i) {
-				if(!list[i].hidden) cnt = cnt + 1;
-				if(cnt == active) {
+			for (var i = 0; i < list.length; ++i) {
+				if (!list[i].hidden) cnt = cnt + 1;
+				if (cnt == active) {
 					url = list[i].url
 					break;
 				}
@@ -48,7 +59,6 @@ Component({
 			wx.switchTab({
 				url: url
 			});
-			console.log(url)
 		},
 
 		init() {
@@ -56,27 +66,35 @@ Component({
 			var userInfo = getApp().globalData.userInfo
 			var role = userInfo ? userInfo.topRole : ''
 			var list = this.data.initList
-			if(role && role.key == 'leader') {
+			if (role && role.key == 'leader') {
 				// list = this.data.initList.slice(1)
 				list[0].hidden = true;
+			} else {
+				list[0].hidden = false;
 			}
-			if(role && role.rights && role.rights.dataView) {
+			if (role && role.rights && role.rights.dataView) {
 				list[1].hidden = false;
+			} else {
+				list[1].hidden = true;
 			}
 			this.setData({
 				list: list
 			})
-			var active = -1;
-			for(var i = 0; i < list.length; ++i) {
-				if(!list[i].hidden) active = active + 1;
-				if(list[i].url == '/' + page.route) break;
+			var activeUrl = '';
+			for (var i = 0; i < list.length; ++i) {
+				if (list[i].url == '/' + page.route) {
+					activeUrl = list[i].url
+					break;
+				};
 			}
 			this.setData({
-				active: active
+				activeUrl
 			});
-			if(role) {
-				this.setData({role})
+			if (role) {
+				this.setData({
+					role
+				})
 			}
 		}
 	}
-});
+});

+ 6 - 3
mini/custom-tab-bar/index.wxml

xqd
@@ -1,3 +1,6 @@
-<van-tabbar active="{{ active }}" bind:change="onChange">
-  <van-tabbar-item icon="{{ item.icon }}" wx:for="{{ list }}" wx:key="index" wx:if="{{!item.hidden}}">{{ item.text }}</van-tabbar-item>
-</van-tabbar>
+<view class="sg-tabbar">
+  <view class="sg-tab-item {{item.url == activeUrl ? 'sg-active' : ''}}" wx:for="{{list}}" wx:key="index" wx:if="{{!item.hidden}}" bindtap="switchTab" data-url="{{item.url}}">
+    <van-icon class="sg-icon" name="{{item.icon}}" />
+    <view class="sg-name">{{item.text}}</view>
+  </view>
+</view>

+ 27 - 0
mini/custom-tab-bar/index.wxss

xqd
@@ -0,0 +1,27 @@
+.sg-tabbar {
+  position: fixed;
+  bottom: 0;
+  left: 0;
+  width: 100%;
+  justify-content: space-around;
+  display: flex;
+  align-items: center;
+  border-top: 1px solid #ebedf0;
+  padding: 8px 0;
+  background: white;
+}
+.sg-tab-item.sg-active {
+  color: #5693FC;
+}
+.sg-tab-item {
+  display: flex;
+  align-items: center;
+  flex-direction: column;
+}
+.sg-icon {
+  font-size: 1.2rem;
+}
+.sg-name {
+  font-size: 0.8rem;
+  margin-top: 5px;
+}

+ 2 - 2
mini/pages/account/index.wxml

xqd
@@ -10,11 +10,11 @@
             <image src="./out.png" alt="" mode="widthFix" style="width:40rpx"></image>
           </view>
         </view>
-        <view class="sg-font-small sg-flex sg-align-center" style="justify-content: space-between;" wx:if="{{project_num<=0}}">
+        <view class="sg-font-small sg-flex sg-align-center" style="justify-content: space-between;" wx:if="{{project_num>0}}">
           <view wx:if="userInfo">所属项目个数 | {{project_num}}个</view>
           <view bindtap="navigate" data-url="{{userInfo ? '/pages/user/index' : '/pages/login/index'}}">{{ userInfo ? '修改用户信息' : '点击按钮进行登录操作' }}</view>
         </view>
-        <view class="sg-margin-tb-sm sg-pad-sm sg-primary sg-font-xs sg-white sg-flex sg-align-center sg-space-between" style="background: #4281F0; border-radius: 5px" bindtap="navigate" data-url="/pages/bind/index">
+        <view class="sg-margin-tb-sm sg-pad-sm sg-primary sg-font-xs sg-white sg-flex sg-align-center sg-space-between" style="background: #4281F0; border-radius: 5px" bindtap="navigate" data-url="/pages/bind/index" wx:else>
           <view>联系管理员进行授权,进行项目查看</view>
           <van-icon name="arrow"></van-icon>
         </view>

+ 2 - 1
mini/pages/create-project-role/index.js

xqd
@@ -197,7 +197,8 @@ Page({
     http({
       url: 'projects/getAll',
       data: {
-        user_id: user_id
+        user_id: user_id,
+        self: true
       },
       success: function(res) {
         if(res.code == 0) {

+ 1 - 0
mini/pages/index/index.js

xqd
@@ -43,6 +43,7 @@ Page({
     });
     api.getByName(this, 'getUserInfo', 'userInfo', {}, function(res) {
       app.updateUserInfo(res);
+      that.getTabBar().init();
     });
   },
   onLoad: function () {

+ 1 - 1
mini/pages/password/index.wxml

xqd
@@ -14,6 +14,6 @@
       <input class="sg-input sg-text-right" value="{{new_confirm}}" bindinput="updateInput" data-name="new_confirm" placeholder="请重复新密码" password="{{true}}"></input>
     </view>
   </view>
-  <view class="sg-pad sg-gray-color sg-font-small">密码长度6~32位,须包含数字、字母</view>
+  <view class="sg-pad sg-gray-color sg-font-small">密码长度6~32位,须包含数字、字母,默认密码为123456</view>
   <view class="sg-fix-bottom sg-pad sg-text-center sg-white-bg" bindtap="save">保存</view>
 </view>

+ 10 - 5
mini/pages/user/index.js

xqd xqd
@@ -106,6 +106,11 @@ Page({
         if (res.code == 0) {
           util.success('操作成功')
           app.updateUserInfo(res.data)
+          setTimeout(function() {
+            wx.navigateBack({
+              delta: 0,
+            })
+          }, 1000)
         } else {
           util.error('操作失败')
         }
@@ -114,16 +119,16 @@ Page({
   },
 
   save: function() {
-    if(!util.checkMobile(this.data.phone)) {
-      util.error('手机号错误')
-      return false
-    }
+    // if(!util.checkMobile(this.data.phone)) {
+    //   util.error('手机号错误')
+    //   return false
+    // }
     if(!this.data.name) {
       util.error('姓名必填')
       return false
     }
+    var that = this;
     if(this.data.userInfo.avatar != this.data.avatar) {
-      var that = this;
       util.uploadFile(this.data.avatar, function(res) {
         that.setData({
           avatar: res.path

+ 1 - 1
mini/utils/env.js

xqd
@@ -1,3 +1,3 @@
-const isTest = false;
+const isTest = true;
 export const baseUrl = isTest ? 'http://app.rt/api/mini/' : 'http://t18.9026.com/api/mini/';
 export const imgHost = isTest ? 'http://app.rt/images/' : 'http://t18.9026.com/images/'

+ 235 - 0
resources/views/admin/repair-devices/all.blade.php

xqd
@@ -0,0 +1,235 @@
+@extends('admin.layout-content')
+
+@section('header')
+    <style>
+
+    </style>
+@endsection
+
+@section('content')
+    <div class="layui-card">
+        <div class="layui-card-header sg-card-header">
+            {{ $model_name }}管理
+        </div>
+        <div class="layui-card-body">
+            <form class="layui-form" id="sg-search-form">
+                <div class="layui-form-item layui-row">
+                    <div class="layui-inline">
+                        <div class="layui-input-inline">
+                            <input type="text" name="name" placeholder="请输入名称" autocomplete="off" class="layui-input" value="{{ request('name') }}">
+                        </div>
+                    </div>
+                    <div class="layui-inline">
+                        <div class="layui-btn" id="sg-search-btn">搜索</div>
+                    </div>
+                </div>
+            </form>
+            <table id="sg-main-table" class="layui-hide" lay-filter="tableEvent"></table>
+            <script type="text/html" id="sg-table-bar">
+                <div class="layui-btn-group">
+                    <div class="layui-btn-group">
+                        <a class="layui-btn layui-btn-xs" lay-event="part">维修配件清单</a>
+                        <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="delete">删除</a>
+                    </div>
+                </div>
+            </script>
+        </div>
+    </div>
+@endsection
+
+@section('footer')
+    <script>
+        $(function () {
+            layui.use(['table', 'layer'], function(){
+                var table = layui.table,
+                    layer = layui.layer,
+                    form = layui.form,
+                    laydate = layui.laydate,
+                    top_window = window;
+
+                $('#sg-back-btn').on('click', function () {
+                    window.history.go(-1);
+                });
+                table.render({
+                    elem: '#sg-main-table',
+                    url: '{{ $pre_uri }}' + 'get',
+                    cellMinWidth: 80,
+                    cols: [[
+                        { field: 'id', title: 'ID', align: 'center' },
+                        { field: 'number', title: '固定资产编号', align: 'center' },
+                        { field: 'device_name', title: '设备名称', align: 'center' },
+                        { field: 'project_name', title: '所在项目', align: 'center' },
+                        { field: 'work_point_name', title: '上报工点', align: 'center' },
+                        { field: 'money', title: '维修总金额', align: 'center' },
+                        { field: 'user_name', title: '提交人', align: 'center' },
+                        { field: 'reason', title: '维修原因', align: 'center' },
+                        { field: 'day', title: '维修日期', align: 'center' },
+                        { field: 'remark', title: '备注', align: 'center' },
+                        { title: '操作', align:'center', toolbar: '#sg-table-bar' }
+                    ]],
+                    page: {
+                        layout: ['count', 'prev', 'page', 'next', 'skip', 'refresh'],
+                        limit: 15
+                    },
+                    even: true,
+                    where: transformToJson($('#sg-search-form').serializeArray()),
+                    done: function(res, curr, count) {
+
+                    }
+                });
+                table.on('tool(tableEvent)', function(obj){
+                    var data = obj.data;
+                    if(obj.event === 'delete'){
+                        layer.confirm('确定要删除吗?', function(index) {
+                            $.ajax({
+                                method: 'POST',
+                                url: '{{ $pre_uri }}' + 'delete',
+                                headers: {
+                                    'X-CSRF-TOKEN': '{{ csrf_token() }}'
+                                },
+                                data: {
+                                    id: data.id
+                                },
+                                success: function (data) {
+                                    if(data.status === 'success') {
+                                        obj.del();
+                                    } else {
+                                        layer.msg(data.info, {
+                                            icon: 2
+                                        });
+                                    }
+                                    layer.close(index);
+                                },
+                                error: function () {
+                                    layer.close(index);
+                                    layer.msg('删除失败', {
+                                        icon: 2
+                                    });
+                                }
+                            });
+                        });
+                    } else if(obj.event === 'edit') {
+                        layer.open({
+                            title: '编辑成员',
+                            type: 2,
+                            area: ['90%', '90%'],
+                            content: '{{ $pre_uri }}' + 'edit?id=' + data.id,
+                            end: function () {
+                                top_window.location.reload();
+                            }
+                        });
+                    } else if(obj.event === 'part') {
+                        layer.open({
+                            title: '维修部件',
+                            type: 2,
+                            area: ['90%', '90%'],
+                            content: '/admin/Part/index?repair_device_id=' + data.id,
+                            end: function () {
+                                top_window.location.reload();
+                            }
+                        });
+                    }
+                });
+
+                if($('#search-begin-date').length > 0) {
+                    laydate.render({
+                        elem: '#search-begin-date',
+                        done: function () {
+                            updateTableBySearch();
+                        }
+                    });
+                }
+
+                if($('#search-end-date').length > 0) {
+                    laydate.render({
+                        elem: '#search-end-date',
+                        done: function () {
+                            updateTableBySearch();
+                        }
+                    });
+                }
+
+                function transformToJson(formData){
+                    var obj={};
+                    for (var i in formData) {
+                        obj[formData[i].name]=formData[i]['value'];
+                    }
+                    return obj;
+                }
+
+                function updateTableBySearch() {
+                    table.reload('sg-main-table', {
+                        where: transformToJson($('#sg-search-form').serializeArray()),
+                        page: {
+                            curr: 1
+                        }
+                    });
+                }
+
+                $('#sg-search-btn').click(function() {
+                    updateTableBySearch();
+                });
+                // $('#sg-search-form').change(function () {
+                //     updateTableBySearch();
+                // });
+                //
+                // form.on('select()', function(){
+                //     updateTableBySearch();
+                // });
+
+                $('#sg-create-btn').on('click', function () {
+                    layer.open({
+                        title: '创建' + '{{ $model_name }}',
+                        type: 2,
+                        area: ['90%', '90%'],
+                        content: '{{ $pre_uri }}' + 'create',
+                        end: function () {
+                            top_window.location.reload();
+                        }
+                    });
+                });
+
+                $('#sg-table-top-container').on('click', '.btn-delete-many', function () {
+                    layer.confirm('确定要删除所有选中行吗?', function () {
+                        var data = table.checkStatus('sg-main-table').data;
+                        if(data.length <= 0) {
+                            layer.msg('选择不能为空', {
+                                icon: 2
+                            });
+                            return false;
+                        }
+                        var ids = [];
+                        for(var i = 0; i < data.length; ++i) {
+                            ids.push(data[i]['id']);
+                        }
+                        $.ajax({
+                            method: 'POST',
+                            url: '{{ $pre_uri }}' + 'deleteMany',
+                            headers: {
+                                'X-CSRF-TOKEN': '{{ csrf_token() }}'
+                            },
+                            data: {
+                                ids: JSON.stringify(ids)
+                            },
+                            success: function (data) {
+                                if(data.status === 'success') {
+                                    top_window.location.reload();
+                                } else {
+                                    layer.msg(data.info, {
+                                        icon: 2
+                                    });
+                                }
+
+                            },
+                            error: function () {
+                                layer.msg('删除失败', {
+                                    icon: 2
+                                });
+                            }
+                        });
+                    })
+                });
+            });
+        })
+    </script>
+@endsection