Parcourir la source

通知+审核

李浩杰 il y a 4 ans
Parent
commit
53932cceb2
37 fichiers modifiés avec 515 ajouts et 80 suppressions
  1. 10 0
      app/Console/Kernel.php
  2. 2 1
      app/Http/Controllers/Admin/TestController.php
  3. 2 0
      app/Http/Controllers/Api/mini/AuthController.php
  4. 8 0
      app/Http/Controllers/Api/mini/NotificationController.php
  5. 12 6
      app/Http/Controllers/Api/mini/OrderController.php
  6. 13 3
      app/Http/Controllers/Api/mini/ProjectController.php
  7. 21 4
      app/Http/Controllers/Api/mini/UserController.php
  8. 69 20
      app/Models/Notification.php
  9. 25 1
      app/Models/Order.php
  10. 19 0
      app/Models/Project.php
  11. 15 0
      app/Models/ProjectRole.php
  12. 12 0
      app/Models/User.php
  13. 2 1
      config/app.php
  14. 30 0
      database/migrations/2020_12_27_172149_add_active_to_projects.php
  15. 30 0
      database/migrations/2020_12_27_172404_add_user_id_to_projects.php
  16. 16 0
      database/seeds/PatchSeeder.php
  17. 10 3
      mini/app.js
  18. 1 1
      mini/app.json
  19. 1 0
      mini/app.wxss
  20. 7 4
      mini/components/inner-order-item/index.wxml
  21. 21 3
      mini/custom-tab-bar/index.js
  22. 2 4
      mini/custom-tab-bar/index.wxml
  23. 80 4
      mini/pages/create-order-inner/index.js
  24. 40 6
      mini/pages/create-order-inner/index.wxml
  25. 11 2
      mini/pages/create-project-role/index.js
  26. 5 5
      mini/pages/create-project-role/index.wxml
  27. 24 2
      mini/pages/index/index.js
  28. 2 1
      mini/pages/index/index.wxml
  29. 6 2
      mini/pages/notification/index.js
  30. 4 2
      mini/pages/order-detail-inner/index.js
  31. 4 0
      mini/pages/order-detail-inner/index.wxml
  32. 1 1
      mini/pages/order-detail/index.js
  33. 2 2
      mini/pages/order-detail/index.wxml
  34. 1 0
      mini/pages/project/index.js
  35. 1 1
      mini/utils/env.js
  36. 4 1
      readme.md
  37. 2 0
      routes/api.php

+ 10 - 0
app/Console/Kernel.php

xqd xqd
@@ -2,6 +2,9 @@
 
 namespace App\Console;
 
+use App\Models\Notification;
+use App\Models\OrderDevice;
+use Carbon\Carbon;
 use Illuminate\Console\Scheduling\Schedule;
 use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
 
@@ -24,6 +27,13 @@ class Kernel extends ConsoleKernel
      */
     protected function schedule(Schedule $schedule)
     {
+        $schedule->call(function () {
+            $yesterday = Carbon::yesterday()->toDateString();
+            $order_ids = OrderDevice::where('end_date', $yesterday)->pluck('order_id')->unique();
+            foreach($order_ids as $order_id) {
+                Notification::send($order_id, true);
+            }
+        })->dailyAt('01:00');
         // $schedule->command('inspire')
         //          ->hourly();
     }

+ 2 - 1
app/Http/Controllers/Admin/TestController.php

xqd xqd
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Admin;
 
 use App\Models\DeviceName;
 use App\Models\InnerDevice;
+use App\Models\Notification;
 use App\Models\Order;
 use App\Models\OrderDevice;
 use App\Models\ProjectRole;
@@ -18,7 +19,7 @@ class TestController extends Controller
 {
     public function index(Request $request)
     {
-        dd(User::find(8)->getProjectRoleName());
+        Notification::send(143);
     	return view('admin.test.index');
     }
 }

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

xqd xqd
@@ -17,6 +17,7 @@ class AuthController extends BaseController
             $user = Auth::guard('mini')->user();
             $user->updateToken();
             $user->avatar = $user->avatar ? $user->avatar : 'https://t18.9026.com/mini/default-user.png';
+            $user->topRole = $user->getTopRole();
             return $this->success(['data' => $user]);
         }
         return $this->error(['msg' => '账号或密码错误']);
@@ -43,6 +44,7 @@ class AuthController extends BaseController
                         'avatar' => $data['avatarUrl']
                     ]);
                     $user->updateToken();
+                    $user->topRole = $user->getTopRole();
                     return $this->success(['data' => $user]);
                 }
             }

+ 8 - 0
app/Http/Controllers/Api/mini/NotificationController.php

xqd xqd
@@ -41,6 +41,13 @@ class NotificationController extends BaseController
         return $this->success(['data' => $items->items()]);
     }
 
+    public function notReadCount(Request $request)
+    {
+        $user = Auth::guard('mini')->user();
+        $count = $this->model->where('user_id', $user->id)->where('is_read', 2)->count();
+        return $this->success(['data' => $count]);
+    }
+
     public function change(Request $request)
     {
         $user = Auth::guard('mini')->user();
@@ -58,6 +65,7 @@ class NotificationController extends BaseController
     {
         $item = $this->model->find($request->input('id'));
         if(!$item) return $this->error(['msg' => '通知不存在']);
+        $item->update(['is_read' => 1]);
         $order = Order::find($item->order_id);
         if($order) {
             $order->formatOrder($order);

+ 12 - 6
app/Http/Controllers/Api/mini/OrderController.php

xqd xqd xqd xqd
@@ -48,7 +48,7 @@ class OrderController extends BaseController
             'type' => 1
         ]);
         if(!$order) return $this->error(['msg' => '订单创建失败']);
-        Notification::send($order);
+        Notification::send($order->id);
         $devices = $request->input('devices');
         $total = 0;
         foreach($devices as $device) {
@@ -135,7 +135,7 @@ class OrderController extends BaseController
             'is_change' => 2
         ]);
         if(!$order) return $this->error(['msg' => '订单创建失败']);
-        Notification::send($order);
+        Notification::send($order->id);
         foreach($devices as $device) {
             OrderDevice::create([
                 'name' => $device['name'],
@@ -340,8 +340,8 @@ class OrderController extends BaseController
         $status = Option::get('orders', 'status', $request->input('type'));
 
         $is_inner = $order->type == 2;
-        // 工区负责人或机电负责人确认通过
-        if($request->input('type') == 'confirm') {
+        // 工区负责人确认通过
+        if($request->input('type') == 'pass') {
             $status = Option::get('orders', 'status', 'pass');
             $next_project_role_id = $project_role->id;
         } else if($request->input('type') == 're-submit') {
@@ -353,16 +353,22 @@ class OrderController extends BaseController
             } else {
                 $next_project_role_id = ProjectRole::getByKey('work', 'id');
             }
+        } else if($request->input('type') == 'back') {
+            $next_project_role_id = $project_role->id;
+            $order->backInnerDevices();
         } else {
+            // 审核
             $next_project_role_id = $project_role->getNext('id', $is_inner);
         }
+        $is_change = $request->input('is_change');
 
         $res = $order->update([
             'status' => $status,
             'last_project_role_id' => $project_role->id,
-            'project_role_id' => $next_project_role_id
+            'project_role_id' => $next_project_role_id,
+            'is_change' => $is_change
         ]);
-        Notification::send($order);
+        Notification::send($order->id);
         if($res) return $this->success();
         return $this->error(['msg' => '操作失败']);
     }

+ 13 - 3
app/Http/Controllers/Api/mini/ProjectController.php

xqd xqd xqd
@@ -6,6 +6,7 @@ use App\Models\Project;
 use App\Models\ProjectUser;
 use Illuminate\Http\Request;
 use Illuminate\Database\Eloquent\Builder;
+use Illuminate\Support\Facades\Auth;
 
 class ProjectController extends BaseController
 {
@@ -48,16 +49,20 @@ class ProjectController extends BaseController
     {
         if(empty($request->input('name'))) return $this->error(['msg' => '项目名称不能为空']);
         if($item = $this->model->where('name', $request->input('name'))->first()) return $this->error(['msg' => '项目名称已存在']);
+        $user = Auth::guard('mini')->user();
         $res = $this->model->create([
-            'name' => $request->input('name')
+            'name' => $request->input('name'),
+            'active' => 2,
+            'user_id' => $user->id
         ]);
         if(!$res) return $this->error(['msg' => '创建失败']);
+        $res->createDefaultUser();
         return $this->success(['msg' => '创建成功']);
     }
 
     public function get(Request $request)
     {
-        $items = $this->model;
+        $items = $this->model->where('active', 1);
         $tmp_items = collect(['name']);
         foreach($tmp_items as $tmp_item) {
             if($request->has($tmp_item) && !empty($request->input($tmp_item))) {
@@ -82,7 +87,12 @@ class ProjectController extends BaseController
             $items = $items->prepend(collect(['text' => '请选择项目', 'value' => '']));
             return $this->success(['data' => $items]);
         }
-        $items = $this->model->get();
+        $items = $this->model;
+        if($request->input('user_id')) {
+            $project_ids = ProjectUser::where('user_id', $request->input('user_id'))->pluck('project_id');
+            if(count($project_ids) > 0) $items = $items->whereNotIn('id', $project_ids);
+        }
+        $items = $items->get();
         return $this->success(['msg' => '创建成功', 'data' => $items]);
     }
 

+ 21 - 4
app/Http/Controllers/Api/mini/UserController.php

xqd xqd xqd xqd
@@ -2,10 +2,14 @@
 
 namespace App\Http\Controllers\Api\mini;
 
+use App\Models\Project;
+use App\Models\ProjectRole;
+use App\Models\ProjectUser;
 use App\Models\User;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\Auth;
 use Illuminate\Support\Facades\Hash;
+use Illuminate\Support\Facades\Log;
 
 class UserController extends BaseController
 {
@@ -18,11 +22,12 @@ class UserController extends BaseController
 
     public function search(Request $request)
     {
-        $items = $this->model;
+        $items = $this->model->with('project_users');
         $tmp_items = collect(['keyword']);
         foreach($tmp_items as $tmp_item) {
             if($request->has($tmp_item) && !empty($request->input($tmp_item))) {
-                $items = $items->where('name', 'like', '%' . $request->input($tmp_item) . '%')->orWhere('phone', 'like', '%' . $request->input($tmp_item) . '%');
+//                $items = $items->where('name', 'like', '%' . $request->input($tmp_item) . '%')->orWhere('phone', 'like', '%' . $request->input($tmp_item) . '%');
+                $items = $items->where('name', '=', $request->input($tmp_item))->orWhere('phone', '=', $request->input($tmp_item));
             }
         }
 
@@ -38,8 +43,12 @@ class UserController extends BaseController
         foreach($items as $item) {
             $item->project = $item->projects->implode('name', ',');
             $item->project = $item->project ? $item->project : '暂未添加项目';
-            $item->role = $item->project_roles->implode('name', ',');
-            $item->role = $item->role ? $item->role : '暂未添加角色';
+            foreach ($item->project_users as $project_user) {
+                $project = Project::find($project_user->project_id);
+                $project_user->project_name = $project ? $project->name : '';
+                $role = ProjectRole::find($project_user->project_role_id);
+                $project_user->role_name = $role ? $role->name : '';
+            }
         }
 
         return $this->success(['msg' => '操作成功', 'data' => $items]);
@@ -62,4 +71,12 @@ class UserController extends BaseController
         }
         return $this->error(['msg' => '原密码错误']);
     }
+
+    public function getTopRole()
+    {
+        $user = Auth::guard('mini')->user();
+
+        $project_role = $user->getTopRole();
+        return $this->success(['data' => $project_role]);
+    }
 }

+ 69 - 20
app/Models/Notification.php

xqd xqd xqd xqd xqd
@@ -4,8 +4,10 @@ namespace App\Models;
 
 class Notification extends BaseModel
 {
-    public static function send(Order $order)
+    public static function send($order_id, $overdue = false)
     {
+        $order = Order::find($order_id);
+        if(!$order) return false;
         if($order['is_draft'] == 1) return false;
         $checked_id = Option::get('orders', 'status', 'checked');
         $reject_id = Option::get('orders', 'status', 'reject');
@@ -15,16 +17,32 @@ class Notification extends BaseModel
         $role = ProjectRole::find($order['project_role_id']);
         $status = 1;
         $user_ids = [];
-        if($role) {
+        $project_role_ids = [$role['id']];
+        if($overdue) {
+            // 调用时间到期
+            $role = ProjectRole::getFirstRole($order);
+            $project_role_ids = [$role['id']];
+        } else if($order['status'] == $pass_id) {
+            // 租赁完成,调用完成
+            if($order['type'] == 1) {
+                $project_role_ids = ProjectRole::whereIn('key', ['manager'])->pluck('id');
+            } else if($order['is_change' == 2]) {
+                $project_role_ids = ProjectRole::whereIn('key', ['machine', 'admin'])->pluck('id');
+            } else {
+                $project_role_ids = ProjectRole::whereIn('key', ['machine'])->pluck('id');
+            }
+        } else if($order['status'] == $back_id) {
+            $project_role_ids = ProjectRole::whereIn('key', ['admin'])->pluck('id');
+        }
+        if(count($project_role_ids) > 0) {
             $user_ids = ProjectUser::where([
-                ['project_id', $order['project_id']],
-                ['project_role_id', $role['id']]
-            ])->pluck('user_id');
+                ['project_id', $order['project_id']]
+            ])->whereIn('project_role_id', $project_role_ids)->pluck('user_id');
         }
         // 外部租赁
         if($order['type'] == 1) {
             // 审批成功
-            if($order['status'] == $checked_id && $role && $last_role && $last_role['key'] == 'manager') {
+            if($order['status'] == $checked_id && $last_role && $last_role['key'] == 'manager') {
                 $status = 1;
             } else if($role && in_array($role['key'], ['machine', 'assist', 'manager'])) {
                 // 审批待处理
@@ -33,7 +51,6 @@ class Notification extends BaseModel
                 // 审批被驳回
                 $status = 3;
             } else if($order['status'] == $pass_id) {
-                // 租赁时间到期 status = 4
                 // 租赁已完成
                 $status = 5;
             }
@@ -49,14 +66,20 @@ class Notification extends BaseModel
                 // 调用被驳回
                 $status = 3;
             } else if($order['status'] == $pass_id) {
-                // 调用时间到期 status = 4
                 // 调用已完成
                 $status = 5;
             } else if($order['status'] == $back_id) {
                 // 调用已归还
                 $status = 6;
+            } else if($order['is_change'] == 1) {
+                // 调用修改通知
+                $status = 7;
             }
         }
+        // 调用时间到期 status = 4
+        if($overdue) {
+            $status = 4;
+        }
         foreach($user_ids as $user_id) {
             Notification::create([
                 'user_id' => $user_id,
@@ -69,69 +92,95 @@ class Notification extends BaseModel
         return true;
     }
 
+    /**
+     * 租赁时间到期 status = 4
+     * @param $id
+     * @return bool
+     */
+    public static function sendOverdue($id)
+    {
+        $order = self::find($id);
+        if(!$order) return false;
+        $role = $order->type == 1 ? $role = ProjectRole::getByKey('work') : ProjectRole::getByKey('machine');
+        $user_ids = ProjectUser::where([
+            ['project_id', $order['project_id']],
+            ['project_role_id', $role['id']]
+        ])->pluck('user_id');
+        foreach($user_ids as $user_id) {
+            Notification::create([
+                'user_id' => $user_id,
+                'order_id' => $order['id'],
+                'status' => 4,
+                'type' => $order['type'],
+                'is_read' => 2
+            ]);
+        }
+        return false;
+    }
+
     public function getNameContent()
     {
         if($this['type'] == 1) {
             if($this['status'] == 1) {
                 return [
-                    'name' => '设备租赁申请通过',
+                    'name' => '租赁审批成功通知',
                     'content' => '你的设备租赁申请已通过,请确认相关信息:'
                 ];
             } else if($this['status'] == 2) {
                 return [
-                    'name' => '设备租赁审批待处理',
+                    'name' => '租赁审批待处理通知',
                     'content' => '你有一条设备租赁申请待审批,请确认相关信息:'
                 ];
             } else if($this['status'] == 3) {
                 return [
-                    'name' => '设备租赁审批被驳回',
+                    'name' => '租赁审批驳回通知',
                     'content' => '你有一条设备租赁申请被驳回,请确认相关信息:'
                 ];
             } else if($this['status'] == 4) {
                 return [
-                    'name' => '设备租赁已到期',
+                    'name' => '租赁时间到期通知',
                     'content' => '你有一条设备租赁已到期消息,请确认相关信息:'
                 ];
             } else if($this['status'] == 5) {
                 return [
-                    'name' => '设备租赁已完成',
+                    'name' => '租赁完成通知',
                     'content' => '你有一条设备租赁已完成消息,请确认相关信息:'
                 ];
             }
         } else {
             if($this['status'] == 1) {
                 return [
-                    'name' => '设备调用申请通过',
+                    'name' => '调用审批成功通知',
                     'content' => '你的设备调用申请已通过,请确认相关信息:'
                 ];
             } else if($this['status'] == 2) {
                 return [
-                    'name' => '设备调用审批待处理',
+                    'name' => '调用审批待处理通知',
                     'content' => '你有一条设备调用申请待审批,请确认相关信息:'
                 ];
             } else if($this['status'] == 3) {
                 return [
-                    'name' => '设备租赁调用被驳回',
+                    'name' => '调用审批驳回通知',
                     'content' => '你有一条设备调用申请被驳回,请确认相关信息:'
                 ];
             } else if($this['status'] == 4) {
                 return [
-                    'name' => '设备调用已到期',
+                    'name' => '调用时间到期通知',
                     'content' => '你有一条设备调用已到期消息,请确认相关信息:'
                 ];
             } else if($this['status'] == 5) {
                 return [
-                    'name' => '设备调用完成',
+                    'name' => '调用完成通知',
                     'content' => '你有一条设备调用已完成消息,请确认相关信息:'
                 ];
             } else if($this['status'] == 6) {
                 return [
-                    'name' => '设备调用已归还',
+                    'name' => '调用退回通知',
                     'content' => '你有一条设备调用已归还消息,请确认相关信息:'
                 ];
             } else if($this['status'] == 7) {
                 return [
-                    'name' => '设备调用修改',
+                    'name' => '调用修改通知',
                     'content' => '你有一条设备调用被修改消息,请确认相关信息:'
                 ];
             }

+ 25 - 1
app/Models/Order.php

xqd xqd xqd
@@ -3,6 +3,7 @@
 namespace App\Models;
 
 use Carbon\Carbon;
+use Illuminate\Support\Facades\Request;
 
 class Order extends BaseModel
 {
@@ -65,7 +66,8 @@ class Order extends BaseModel
             $project_role = ProjectRole::find($this['last_project_role_id']);
             return $project_role ? $project_role->name . ' - ' . $option['name'] : $option['name'];
         } else if($option['key'] == 'pass') {
-            return '提交人 - 已确定';
+            if($this['is_change'] == 1) return '管理员 - 已修订';
+            return $this['type'] == 1 ? '提交人 - 已确定' : '已完成';
         }
         return $option ? $option['name'] : '';
     }
@@ -102,4 +104,26 @@ class Order extends BaseModel
         $item->color = $option ? $option['color'] : '';
         $item->date_time = substr($item->created_at, 0, 16);
     }
+
+    public function backInnerDevices()
+    {
+        $free_id = Option::get('inner_devices', 'status', 'free');
+        $device_ids = $this['innerDevices']->pluck('id');
+        InnerDevice::whereIn('id', $device_ids)->update([
+            'status' => $free_id,
+            'start_date' => '',
+            'end_date' => '',
+            'work_point_id' => ''
+        ]);
+    }
+
+    /**
+     * @param Request $request
+     * @return int(1改变2不改变)
+     */
+    public function checkIsChange(Request $request)
+    {
+        if($this['type'] == 1) return 2;
+        $devices = $request->input('devices');
+    }
 }

+ 19 - 0
app/Models/Project.php

xqd
@@ -75,4 +75,23 @@ class Project extends BaseModel
     {
         return self::where('id', '>', 0)->get()->toArray();
     }
+
+    public function createDefaultUser()
+    {
+        $user_id = $this['user_id'];
+        ProjectUser::where('project_id', $this['id'])->delete();
+        ProjectUser::create([
+            'project_id' => $this['id'],
+            'user_id' => $user_id,
+            'project_role_id' => ProjectRole::getByKey('manager', 'id')
+        ]);
+        $project_user = ProjectUser::where('project_role_id', ProjectRole::getByKey('admin', 'id'))->first();
+        if($project_user) {
+            ProjectUser::create([
+                'project_id' => $this['id'],
+                'user_id' => $project_user->user_id,
+                'project_role_id' => $project_user->project_role_id
+            ]);
+        }
+    }
 }

+ 15 - 0
app/Models/ProjectRole.php

xqd xqd
@@ -30,6 +30,11 @@ class ProjectRole extends BaseModel
             [$need_check, '=', 1],
             ['id', '>', $this['id']]
         ])->first();
+        if(!$inner && $this['key'] == 'manager') {
+            $item = self::getByKey('work');
+        } else if($inner && $this['key'] == 'admin') {
+            $item = self::getByKey('machine');
+        }
         return $column ? ($item ? $item[$column] : '') : $item;
     }
 
@@ -37,4 +42,14 @@ class ProjectRole extends BaseModel
     {
         return self::where('id', '>', 0)->get()->toArray();
     }
+
+    public static function getFirstRole(Order $order)
+    {
+        return $order['type'] == 1 ? $role = self::getByKey('work') : self::getByKey('machine');
+    }
+
+    public static function getLastRole(Order $order)
+    {
+        return $order['type'] == 1 ? $role = self::getByKey('manager') : self::getByKey('admin');
+    }
 }

+ 12 - 0
app/Models/User.php

xqd xqd
@@ -69,6 +69,11 @@ class User extends Authenticatable
         return $this->belongsToMany('App\Models\Project', 'project_users', 'user_id', 'project_id');
     }
 
+    public function project_users()
+    {
+        return $this->hasMany('App\Models\ProjectUser', 'user_id');
+    }
+
     public function project_roles()
     {
         return $this->belongsToMany('App\Models\ProjectRole', 'project_users', 'project_role_id', 'user_id');
@@ -89,4 +94,11 @@ class User extends Authenticatable
     {
         return self::where('id', '>', 0)->get()->toArray();
     }
+
+    public function getTopRole()
+    {
+        $project_user = ProjectUser::where('user_id', $this['id'])->orderBy('project_role_id', 'desc')->first();
+        if(!$project_user) return null;
+        return ProjectRole::find($project_user->project_role_id);
+    }
 }

+ 2 - 1
config/app.php

xqd
@@ -64,7 +64,8 @@ return [
     |
     */
 
-    'timezone' => 'UTC',
+//    'timezone' => 'UTC',
+    'timezone' => 'Asia/Shanghai',
 
     /*
     |--------------------------------------------------------------------------

+ 30 - 0
database/migrations/2020_12_27_172149_add_active_to_projects.php

xqd
@@ -0,0 +1,30 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class AddActiveToProjects extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('projects', function (Blueprint $table) {
+            $table->tinyInteger('active')->after('name')->default(2)->comment('1是2否')->nullable();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        //
+    }
+}

+ 30 - 0
database/migrations/2020_12_27_172404_add_user_id_to_projects.php

xqd
@@ -0,0 +1,30 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class AddUserIdToProjects extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('projects', function (Blueprint $table) {
+            $table->unsignedInteger('user_id')->after('name')->nullable();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        //
+    }
+}

+ 16 - 0
database/seeds/PatchSeeder.php

xqd
@@ -0,0 +1,16 @@
+<?php
+
+use Illuminate\Database\Seeder;
+
+class PatchSeeder extends Seeder
+{
+    /**
+     * Run the database seeds.
+     *
+     * @return void
+     */
+    public function run()
+    {
+        \App\Models\Project::where('id', '>', 0)->update(['active' => 1]);
+    }
+}

+ 10 - 3
mini/app.js

xqd
@@ -97,8 +97,15 @@ App({
   },
   loginCallback: function(data) {
     this.updateUserInfo(data)
-    wx.switchTab({
-      url: '/pages/index/index',
-    })
+    var topRole = data.topRole
+    if(topRole && topRole.key == 'leader') {
+      wx.switchTab({
+        url: '/pages/account/index',
+      })
+    } else {
+      wx.switchTab({
+        url: '/pages/index/index',
+      })
+    }
   }
 })

+ 1 - 1
mini/app.json

xqd xqd
@@ -1,6 +1,7 @@
 {
   "pages": [
     "pages/index/index",
+    "pages/create-project-role/index",
     "pages/data/index",
     "pages/order-inner/index",
     "pages/order/index",
@@ -24,7 +25,6 @@
     "pages/create-order-inner/index",
     "pages/order-detail-inner/index",
     "pages/order-detail/index",
-    "pages/create-project-role/index",
     "pages/project-user/index",
     "pages/create-project/index",
     "pages/login/index",

+ 1 - 0
mini/app.wxss

xqd
@@ -170,6 +170,7 @@
 }
 .sg-big-avatar {
   width: 130rpx;
+  height: 130rpx;
   margin-right: 30rpx;
   border-radius: 50%;
 }

+ 7 - 4
mini/components/inner-order-item/index.wxml

xqd xqd
@@ -1,6 +1,5 @@
 <!--components/out-order-item/index.wxml-->
-<view class="sg-item sg-white-bg sg-pad sg-margin-bottom sg-font-small" data-url="/pages/order-detail-inner/index?id={{item.id}}"
-        bindtap="navigate">
+<view class="sg-item sg-white-bg sg-pad sg-margin-bottom sg-font-small">
         <view class="sg-top sg-bottom-border">
           <view class="sg-order-status sg-flex sg-align-center sg-space-between sg-margin-bottom sg-font-xs">
             <view class="sg-order sg-gray-color">订单号:{{item.order_number}}</view>
@@ -40,9 +39,13 @@
             <view class="sg-right sg-green-bg sg-pad-sm sg-white" catchtap="doAction" data-type="edit"
               data-url="/pages/create-order-inner/index?id={{item.project_id}}&order_id={{item.id}}&type=edit">归还/续租</view>
           </block>
+          <block wx:elif="{{item.status_key=='checked' && role && role.project_role && role.project_role.key=='admin'}}">
+            <view class="sg-right sg-index-bg sg-pad-sm sg-white" catchtap="doAction" data-type="edit"
+              data-url="/pages/create-order-inner/index?id={{item.project_id}}&order_id={{item.id}}&type=edit">查看详情</view>
+          </block>
           <block wx:else>
-            <view class="sg-right sg-index-bg sg-pad-sm sg-white" catchtap="doAction" data-type="detail"
-              data-url="/pages/order-detail-inner/index?id={{item.id}}">查看详情</view>
+            <view class="sg-right sg-index-bg sg-pad-sm sg-white" catchtap="doAction" data-type="edit"
+              data-url="/pages/create-order-inner/index?id={{item.project_id}}&order_id={{item.id}}&type=edit">查看详情</view>
           </block>
         </view>
       </view>

+ 21 - 3
mini/custom-tab-bar/index.js

xqd xqd xqd
@@ -1,7 +1,8 @@
 Component({
 	data: {
 		active: 0,
-		list: [
+		list: [],
+		initList: [
 			{
 				icon: 'home-o',
 				text: '首页',
@@ -17,7 +18,14 @@ Component({
 				text: '个人中心',
 				url: '/pages/account/index'
 			}
-		]
+		],
+		role: ''
+	},
+
+	lifetimes: {
+		attached: function() {
+			
+    },
 	},
 
 	methods: {
@@ -30,8 +38,18 @@ Component({
 
 		init() {
 			const page = getCurrentPages().pop();
+			var userInfo = getApp().globalData.userInfo
+			var role = userInfo ? userInfo.topRole : ''
+			var list = this.data.initList
+			if(role && role.key == 'leader') {
+				list = this.data.initList.slice(1)
+			}
+			this.setData({
+				list: list
+			})
 			this.setData({
-				active: this.data.list.findIndex(item => item.url === `/${page.route}`)
+				active: this.data.list.findIndex(item => item.url === `/${page.route}`),
+				role: role
 			});
 		}
 	}

+ 2 - 4
mini/custom-tab-bar/index.wxml

xqd
@@ -1,5 +1,3 @@
 <van-tabbar active="{{ active }}" bind:change="onChange">
-  <van-tabbar-item wx:for="{{ list }}" wx:key="index" icon="{{ item.icon }}">{{
-    item.text
-  }}</van-tabbar-item>
-</van-tabbar>
+  <van-tabbar-item icon="{{ item.icon }}" wx:for="{{ list }}" wx:key="index">{{ item.text }}</van-tabbar-item>
+</van-tabbar>

+ 80 - 4
mini/pages/create-order-inner/index.js

xqd xqd xqd
@@ -2,6 +2,8 @@
 import http from '../../utils/http'
 import util from '../../utils/util'
 import api from '../../utils/api'
+import Dialog from '../../miniprogram_npm/@vant/weapp/dialog/dialog';
+
 Page({
 
   /**
@@ -19,7 +21,12 @@ Page({
     // create/edit
     type: 'create',
     order_id: '',
-    loadedOrder: false
+    loadedOrder: false,
+    role: null,
+    // 审核(check)|确认(pass)|重新提交(re-submit)|退回(back)
+    actionType: null,
+    order: null,
+    canEdit: true
   },
 
   /**
@@ -33,30 +40,99 @@ Page({
     // }
     var id = options.id ? options.id : 1
     var type = options.type ? options.type : 'create'
-    var order_id = options.order_id ? options.order_id : 195
+    var order_id = options.order_id ? options.order_id : ''
     this.setData({
       id,
       type,
       order_id
     })
+    this.init()
+  },
+
+  init() {
+    var order_id = this.data.order_id
     api.getProject(this)
     api.getByName(this, 'work-points/get', 'work_points');
     if(order_id) {
       var that = this
+      
       api.getByName(this, 'orders/detail', 'order', {id: order_id}, function(res) {
-        that.initData()
+        api.getByName(that, 'orders/getRole', 'role', {id: order_id}, function (res) {
+          that.updateActionType()
+          that.initData()
+        });
       });
       wx.setNavigationBarTitle({
-        title: '修订订单',
+        title: '订单详情',
       })
     }
   },
 
+  updateActionType: function () {
+    var actionType = ''
+    var role = this.data.role
+    var order = this.data.order
+    if (order.project_role_id == role.id) {
+      if(order.status_key == 'checking' && role.project_role.key == 'assist') actionType = 'check'
+      else if(order.status_key == 'checked' && ['manager', 'admin'].indexOf(role.project_role.key) != -1) actionType = 'check'
+      else if(order.status_key == 'reject' && role.project_role.key == 'machine') actionType = 're-submit'
+      else if(order.status_key == 'pass' && role.project_role.key == 'machine') actionType = 'back'
+    }
+    var canEdit = actionType == 'check' && role.project_role.key == 'admin' || (actionType == 're-submit');
+    this.setData({
+      actionType,
+      canEdit
+    })
+  },
+
   navigate: function(e) {
     wx.navigateTo({
       url: e.currentTarget.dataset.url,
     })
   },
+
+  check: function(e) {
+    var type = e.currentTarget.dataset.type
+    var that = this
+    var msg = '确认通过审核吗?'
+    if(type == 'reject') msg = '确认驳回申请吗?'
+    else if(type == 'pass' || type == 're-submit') msg = '确认提交吗?'
+    else if(type == 'back') msg = '确认归还吗?'
+    Dialog.confirm({
+      title: '提示',
+      message: msg,
+    })
+      .then(() => {
+        that.submitCheck(e)
+      })
+  },
+  submitCheck: function (e) {
+    var type = e.currentTarget.dataset.type
+    var is_change = e.currentTarget.dataset.change
+    var that = this
+    if(this.data.devices.length <= 0) {
+      util.error('请选择调用设备');
+      return false;
+    }
+    http({
+      url: 'orders/check',
+      data: {
+        id: this.data.order_id,
+        type: type,
+        remark: this.data.remark,
+        devices: this.data.devices,
+        is_change: is_change
+      },
+      success: function (res) {
+        if (res.code == 0) {
+          util.success('操作成功')
+          setTimeout(function() {
+            that.init()
+          }, 1000)
+        }
+      }
+    })
+  },
   
   initData: function() {
     var order = this.data.order,

+ 40 - 6
mini/pages/create-order-inner/index.wxml

xqd xqd xqd xqd
@@ -15,7 +15,7 @@
       <view class="sg-form-item sg-pad sg-top-border">
         <view class="sg-label">需求工点</view>
         <picker bindchange="onChange" value="{{pointIndex}}" range="{{work_points}}" range-key="name"
-          data-name="pointIndex" class="sg-input">
+          data-name="pointIndex" class="sg-input" disabled="{{!canEdit}}">
           <view class="picker sg-gray-color">
             {{pointIndex >= 0 ? work_points[pointIndex].name : '选择所需的工点'}}
           </view>
@@ -25,12 +25,28 @@
         <view class="sg-label">调用设备</view>
         <input value="{{devices.length}}" class="sg-input" disabled="true"></input>
       </view>
+      <block wx:if="{{type == 'edit'}}">
+        <view class="sg-form-item sg-pad sg-top-border">
+          <view class="sg-label">填单人</view>
+          <view class="sg-input sg-gray-color">{{order.user ? order.user.name : ''}}</view>
+        </view>
+        <view class="sg-form-item sg-pad sg-top-border">
+          <view class="sg-label">创建时间</view>
+          <view class="sg-input sg-gray-color">{{order.created_at}}</view>
+        </view>
+        <view class="sg-form-item sg-pad sg-top-border">
+          <view class="sg-label">订单状态</view>
+          <view class="sg-input sg-gray-color sg-bold" style="color:{{order.color}}">{{order.status}}</view>
+        </view>
+      </block>
       <view class="sg-form-item sg-pad sg-top-border">
         <view class="sg-label">备注</view>
-        <input value="{{remark}}" class="sg-input" bindinput="onChange" data-name="remark" placeholder="订单备注填写"></input>
+        <input value="{{remark}}" class="sg-input" bindinput="onChange" data-name="remark" placeholder="订单备注填写"
+          disabled="{{!canEdit}}"></input>
       </view>
     </view>
   </view>
+  <van-dialog id="van-dialog" />
   <view class="sg-device-box" wx:if="{{tabIndex == 1}}">
     <view class="sg-device-list sg-top-border">
       <block wx:if="{{devices.length <= 0}}">
@@ -54,7 +70,7 @@
       </block>
     </view>
   </view>
-  <block wx:if="{{tabIndex == 1}}">
+  <block wx:if="{{tabIndex == 1 &&  canEdit}}">
     <view class="sg-submit-box sg-pad sg-fix-bottom sg-flex sg-align-center sg-center" bindtap="goAdd"
       data-url="/pages/add-inner-device/index">
       <van-icon name="plus" /><text>立即添加</text>
@@ -65,9 +81,27 @@
       <view class="sg-action sg-draft sg-pad sg-border-right" bindtap="submit" data-type='draft'>暂存</view>
       <view class="sg-action sg-pad sg-index-bg sg-white" bindtap="submit" data-type='save'>提交</view>
     </block>
-    <block wx:else>
-      <view class="sg-action sg-draft sg-pad sg-border-right sg-red-bg" bindtap="submit" data-type='back'>归还</view>
-      <view class="sg-action sg-pad sg-index-bg sg-white sg-green-bg" bindtap="submit" data-type='re-rent'>续租</view>
+    <block wx:if="{{actionType == 'check'}}">
+      <view class="sg-action sg-draft sg-pad sg-border-right sg-red-bg" bindtap="check" data-change="2" data-type='reject'>驳回申请</view>
+      <block wx:if="{{ role && role.project_role && role.project_role.key == 'admin' }}">
+        <view class="sg-action sg-pad sg-green-bg" bindtap="check" data-change="2" data-type='pass'>通过审核</view>
+        <view class="sg-action sg-pad sg-index-bg sg-white" bindtap="check" data-change="1" data-type='pass'>修订通过</view>
+      </block>
+      <block wx:else>
+        <view class="sg-action sg-pad sg-green-bg" bindtap="check" data-change="2" data-type='checked'>通过审核</view>
+      </block>
+    </block>
+    <!-- <block wx:if="{{actionType == 'pass'}}">
+      <view class="sg-action sg-draft sg-pad sg-border-right sg-index-bg sg-white sg-block" bindtap="check" data-change="2"
+        data-type='confirm' style="width: 100%">提交确认</view>
+    </block> -->
+    <block wx:if="{{actionType == 're-submit'}}">
+      <view class="sg-action sg-draft sg-pad sg-border-right sg-index-bg sg-white sg-block" bindtap="check" data-change="2"
+        data-type='re-submit' style="width: 100%">重新提交</view>
+    </block>
+    <block wx:if="{{actionType == 'back'}}">
+      <view class="sg-action sg-draft sg-pad sg-border-right sg-red-bg" bindtap="check" data-change="2" data-type='back'>归还</view>
+      <view class="sg-action sg-pad sg-index-bg sg-green-bg" bindtap="check" data-change="2" data-type='checked'>续租</view>
     </block>
   </view>
 </view>

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

xqd xqd
@@ -155,6 +155,7 @@ Page({
           that.setData({
             users: res.data
           })
+          that.getProjects()
         }
       }
     })
@@ -185,13 +186,21 @@ Page({
 
   getProjects: function() {
     var that = this
+    var users = this.data.users
+    var user_id = ''
+    if(users.length > 0) {
+      user_id = users[0].id
+    }
     http({
       url: 'projects/getAll',
-      data: {},
+      data: {
+        user_id: user_id
+      },
       success: function(res) {
         if(res.code == 0) {
           that.setData({
-            projects: res.data
+            projects: res.data,
+            projectIndex: -1
           })
           if(that.data.type == 'edit') that.updateIndex()
         }

+ 5 - 5
mini/pages/create-project-role/index.wxml

xqd
@@ -9,12 +9,12 @@
   <view class="sg-user-box">
     <view class="sg-user-list sg-margin-tb">
       <view class="sg-user-item sg-pad sg-margin-top-sm" wx:for="{{users}}" wx:key="index">
-        <image class="sg-big-avatar" src="{{item.avatar}}" mode="widthFix"></image>
-        <view class="sg-right sg-flex-grow">
+        <image class="sg-big-avatar" src="{{item.avatar}}"></image>
+        <view class="sg-right sg-flex-grow" style="width: 560rpx">
           <view class="sg-name">{{item.name}}</view>
-          <view class="sg-project-role sg-gray-color sg-font-small sg-flex sg-align-center sg-space-between sg-margin-tb-sm">
-            <view class="sg-project">{{ item.project }}</view>
-            <view class="sg-role">{{ item.role }}</view>
+          <view class="sg-project-role sg-gray-color sg-font-small sg-flex sg-align-center sg-space-between sg-margin-tb-sm" wx:for="{{item.project_users}}" wx:for-item="i_item" wx:for-key="i_index" wx:key="i_index">
+            <view class="sg-project">{{ i_item.project_name }}</view>
+            <view class="sg-role">{{ i_item.role_name }}</view>
           </view>
           <view class="sg-phone sg-gray-color sg-font-small">{{ item.phone }}</view>
         </view>

+ 24 - 2
mini/pages/index/index.js

xqd xqd xqd xqd
@@ -2,6 +2,8 @@
 //获取应用实例
 import http from '../../utils/http'
 import api from '../../utils/api'
+import util from '../../utils/util'
+
 const app = getApp()
 
 Page({
@@ -13,7 +15,9 @@ Page({
     keyword: '',
     page: 1,
     list: [],
-    touchBottom: false
+    touchBottom: false,
+    notReadCount: 0,
+    topRole: null
   },
   //事件处理函数
   bindViewTap: function() {
@@ -27,6 +31,16 @@ Page({
       list: []
     })
     this.getList();
+    api.getByName(this, 'notifications/notReadCount', 'notReadCount');
+    var that = this;
+    api.getByName(this, 'users/getTopRole', 'topRole', {}, function(res) {
+      var role = that.data.topRole
+      if(role && role.key == 'leader') {
+        wx.switchTab({
+          url: '/pages/account/index',
+        })
+      }
+    });
     // api.getByName(this, 'getUserInfo', 'userInfo', {}, function(res) {
     //   app.updateUserInfo(res);
     // });
@@ -60,8 +74,16 @@ Page({
     }
   },
   navigate: function(e) {
+    var url = e.currentTarget.dataset.url
+    if(['/pages/create-project/index', '/pages/create-project-role/index'].indexOf(url) != -1) {
+      var role = this.data.topRole
+      if(!role || ['manager', 'admin'].indexOf(role.key)) {
+        util.error('没有权限');
+        return false;
+      }
+    }
     wx.navigateTo({
-      url: e.currentTarget.dataset.url,
+      url: url,
     })
   },
   updateInput: function(e) {

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

xqd
@@ -14,7 +14,8 @@
       <view class="sg-top-name">草稿箱</view>
     </view>
     <view class="sg-top-item sg-font-xs sg-right-border" bindtap="navigate" data-url="/pages/notification/index">
-      <van-icon name="comment-o" class="sg-icon"/>
+      <van-icon name="bell" class="sg-icon" wx:if="{{notReadCount > 0}}" info="{{notReadCount}}"/>
+        <van-icon name="bell" class="sg-icon" wx:else/>
       <view class="sg-top-name">消息提示</view>
     </view>
     <view class="sg-top-item sg-font-xs">

+ 6 - 2
mini/pages/notification/index.js

xqd xqd
@@ -21,8 +21,7 @@ Page({
    * 生命周期函数--监听页面加载
    */
   onLoad: function (options) {
-    api.getByName(this, 'notifications/getStat', 'stat');
-    this.getList();
+    
   },
 
   navigate(e) {
@@ -109,7 +108,12 @@ Page({
    * 生命周期函数--监听页面显示
    */
   onShow: function () {
+    this.getStat()
+    this.search();
+  },
 
+  getStat() {
+    api.getByName(this, 'notifications/getStat', 'stat');
   },
 
   /**

+ 4 - 2
mini/pages/order-detail-inner/index.js

xqd xqd xqd xqd
@@ -16,7 +16,7 @@ Page({
     order: null,
     device_total: 0,
     role: null,
-    // 审核(check)|确认(pass)|重新提交(re-submit)
+    // 审核(check)|确认(pass)|重新提交(re-submit)|退回(back)
     actionType: null,
     changePrice: false,
     remark: '',
@@ -29,7 +29,7 @@ Page({
    * 生命周期函数--监听页面加载
    */
   onLoad: function (options) {
-    var id = options.id ? options.id : 193
+    var id = options.id ? options.id : ''
     this.setData({
       id
     })
@@ -69,6 +69,7 @@ Page({
       if (['assist', 'manager', 'admin'].indexOf(role.project_role.key) != -1) actionType = 'check'
       if(order.status_key == 'checked' && role.project_role.key == 'machine') actionType = 'pass'
       if(order.status_key == 'reject' && role.project_role.key == 'machine') actionType = 're-submit'
+      if(order.status_key == 'pass') actionType = 'back'
     }
     var changePrice = false
     this.setData({
@@ -132,6 +133,7 @@ Page({
     var msg = '确认通过审核吗?'
     if(type == 'reject') msg = '确认驳回申请吗?'
     else if(type == 'confirm' || type == 're-submit') msg = '确认提交吗?'
+    else if(type == 'back') msg = '确认归还吗?'
     Dialog.confirm({
       title: '提示',
       message: msg,

+ 4 - 0
mini/pages/order-detail-inner/index.wxml

xqd
@@ -94,6 +94,10 @@
       <view class="sg-action sg-draft sg-pad sg-border-right sg-index-bg sg-white sg-block" bindtap="check"
         data-type='re-submit' style="width: 100%">重新提交</view>
     </block>
+    <block wx:if="{{actionType == 'back'}}">
+      <view class="sg-action sg-draft sg-pad sg-border-right sg-red-bg" bindtap="check" data-type='back'>归还</view>
+      <view class="sg-action sg-pad sg-index-bg sg-green-bg" bindtap="check" data-type='checked'>续租</view>
+    </block>
   </view>
   <van-dialog id="van-dialog" />
   <van-dialog show="{{ showPrice }}" use-slot title="修改价格" show-cancel-button bind:confirm="changePrice" z-index="1">

+ 1 - 1
mini/pages/order-detail/index.js

xqd
@@ -134,7 +134,7 @@ Page({
     var that = this
     var msg = '确认通过审核吗?'
     if(type == 'reject') msg = '确认驳回申请吗?'
-    else if(type == 'confirm' || type == 're-submit') msg = '确认提交吗?'
+    else if(type == 'pass' || type == 're-submit') msg = '确认提交吗?'
     Dialog.confirm({
       title: '提示',
       message: msg,

+ 2 - 2
mini/pages/order-detail/index.wxml

xqd
@@ -76,11 +76,11 @@
   <view class="sg-submit-box sg-fix-bottom sg-flex sg-align-center sg-center">
     <block wx:if="{{actionType == 'check'}}">
       <view class="sg-action sg-draft sg-pad sg-border-right sg-red-bg" bindtap="check" data-type='reject'>驳回申请</view>
-      <view class="sg-action sg-pad sg-index-bg sg-green-bg" bindtap="check" data-type='pass'>通过审核</view>
+      <view class="sg-action sg-pad sg-index-bg sg-green-bg" bindtap="check" data-type='checked'>通过审核</view>
     </block>
     <block wx:if="{{actionType == 'pass'}}">
       <view class="sg-action sg-draft sg-pad sg-border-right sg-index-bg sg-white sg-block" bindtap="check"
-        data-type='confirm' style="width: 100%">提交确认</view>
+        data-type='pass' style="width: 100%">提交确认</view>
     </block>
     <block wx:if="{{actionType == 're-submit'}}">
       <view class="sg-action sg-draft sg-pad sg-border-right sg-index-bg sg-white sg-block" bindtap="check"

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

xqd
@@ -78,6 +78,7 @@ Page({
     api.getByName(this, 'getUserInfo', 'userInfo', {}, function(res) {
       app.updateUserInfo(res);
     });
+    wx.setStorageSync('sg-added-devices', [])
   },
 
   navigate: function(e) {

+ 1 - 1
mini/utils/env.js

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

+ 4 - 1
readme.md

xqd
@@ -31,4 +31,7 @@ https://org.modao.cc/app/edfb182d437e2a9f298a275b9bc935d65a3cdd6c
 https://share.mubu.com/doc/1bwUiSTcCQC
 
 后台
-https://share.mubu.com/doc/4Bid7O5TWS
+https://share.mubu.com/doc/4Bid7O5TWS
+
+小程序问题
+https://docs.qq.com/doc/DVHd2SnFlcWJHQWZ2

+ 2 - 0
routes/api.php

xqd xqd
@@ -73,6 +73,7 @@ $api->version('v1', ['namespace' => 'App\Http\Controllers\Api\mini', 'prefix' =>
     $api->any('notifications/get', 'NotificationController@get');
     $api->any('notifications/detail', 'NotificationController@detail');
     $api->any('notifications/change', 'NotificationController@change');
+    $api->any('notifications/notReadCount', 'NotificationController@notReadCount');
 
     $api->any('data/getYearsAndMonths', 'DataController@getYearsAndMonths');
     $api->any('data/getDateInfo', 'DataController@getDateInfo');
@@ -86,6 +87,7 @@ $api->version('v1', ['namespace' => 'App\Http\Controllers\Api\mini', 'prefix' =>
 
     $api->any('users/update', 'UserController@update');
     $api->any('users/changePassword', 'UserController@changePassword');
+    $api->any('users/getTopRole', 'UserController@getTopRole');
 
     $api->any('feedback/create', 'FeedbackController@create');
 });