Browse Source

默认头像

李浩杰 4 years ago
parent
commit
785e9ffe4a

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

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

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

xqd xqd xqd
@@ -25,14 +25,16 @@ class OrderController extends BaseController
         $project = Project::find($request->input('project_id'));
         if(!$project) return $this->error(['msg' => '找不到项目']);
         $user = Auth::guard('mini')->user();
+        $project_role_id = $project->getCreateProjectRoleId($user, $request->input('is_draft'));
         $order = Order::create([
             'work_point_id' => $request->input('work_point_id'),
             'remark' => $request->input('remark'),
             'is_draft' => $request->input('is_draft'),
-            'status' => Option::get('orders', 'status', 'checking'),
+            'status' => $this->model->getOrderStatus($project, $user, $request->input('is_draft')),
             'order_number' => $this->model->createOrderNumber(),
             'project_id' => $project->id,
-            'user_id' => $user->id
+            'user_id' => $user->id,
+            'project_role_id' => $project_role_id
         ]);
         if(!$order) return $this->error(['msg' => '订单创建失败']);
         $devices = $request->input('devices');
@@ -59,6 +61,13 @@ class OrderController extends BaseController
             $status = Option::get('orders', 'status', $request->input('status'));
             if($status) $items = $items->where('status', $status);
         }
+        $equal_items = ['work_point_id'];
+        foreach ($equal_items as $item) {
+            if($request->input($item)) {
+                $items = $items->where($item, '=', $request->input($item));
+            }
+        }
+        $items = $items->orderBy('created_at', 'desc');
         $items = $items->paginate();
         foreach($items as $item) {
             $item->devices = OrderDevice::where('order_id', $item->id)->get();
@@ -68,6 +77,7 @@ class OrderController extends BaseController
             $item->user_name = $item->user ? $item->user->name : '';
             $item->status = Option::getById($item->status, 'name');
             $item->date_time = substr($item->created_at, 0, 16);
+            $item->work_point_name = $item->workPoint ? $item->workPoint->name : '';
         }
         return $this->success(['data' => $items->items()]);
     }

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

xqd
@@ -22,6 +22,7 @@ class WorkPointController extends BaseController
     public function get()
     {
         $items = $this->model->get();
+        $items = $items->prepend(collect(['id' => '0', 'name' => '所有需求工点']));
         return $this->success(['data' => $items]);
     }
 }

+ 1 - 1
app/Http/Middleware/AuthMini.php

xqd
@@ -27,6 +27,6 @@ class AuthMini
                 return $next($request);
             }
         }
-        return response()->json(['code' => -1, 'msg' => '请先登录']);
+        return response()->json(['code' => -100, 'msg' => '请先登录']);
     }
 }

+ 16 - 0
app/Models/Order.php

xqd
@@ -24,4 +24,20 @@ class Order extends BaseModel
     {
         return $this->belongsTo('App\Models\User', 'user_id');
     }
+
+    public function workPoint()
+    {
+        return $this->belongsTo('App\Models\WorkPoint', 'work_point_id');
+    }
+
+    public function getOrderStatus(Project $project, $user, $is_draft)
+    {
+        if($is_draft) {
+            return Option::get('orders', 'status', 'checking');
+        }
+        if($project->isTopLevel($user)) {
+            return Option::get('orders', 'status', 'pass');
+        }
+        return Option::get('orders', 'status', 'checking');
+    }
 }

+ 39 - 0
app/Models/Project.php

xqd
@@ -31,4 +31,43 @@ class Project extends BaseModel
         }
         return null;
     }
+
+    public function isTopLevel($user)
+    {
+        $current_role = ProjectUser::where([
+            ['project_id', '=', $this['id']],
+            ['user_id', '=', $user->id]
+        ])->first();
+        if(empty($current_role)) return false;
+        $res = ProjectUser::where([
+            ['project_id', '=', $this['id']],
+            ['project_role_id', '>', $current_role['project_role_id']]
+        ])->first();
+        return $res ? false : true;
+    }
+
+    /**
+     * @param User $user
+     * @param $type: current/next
+     * @return ProjectUser
+     */
+    public function getProjectUser(User $user, $type = 'current')
+    {
+        $current = ProjectUser::where([
+            ['project_id', '=', $this['id']],
+            ['user_id', '=', $user['id']]
+        ])->first();
+        if($type == 'current' || !$current) return $current;
+        $next = ProjectUser::where([
+            ['project_id', '=', $this['id']],
+            ['project_role_id', '>', $current['project_role_id']]
+        ])->first();
+        return $next ? $next : $current;
+    }
+
+    public function getCreateProjectRoleId(User $user, $is_draft)
+    {
+        $project_user = $this->getProjectUser($user, $is_draft == 1 ? 'current' : 'next');
+        return $project_user ? $project_user['project_role_id'] : '';
+    }
 }

+ 4 - 4
database/seeds/MiniSeeder.php

xqd xqd xqd
@@ -87,7 +87,7 @@ class MiniSeeder extends Seeder
         $work_points = \App\Models\WorkPoint::all();
         $user = \App\Models\User::first();
         $devices = \App\Models\Device::all();
-        for($i = 1; $i < 2 * $total; ++$i) {
+        for($i = 1; $i < $total * 2; ++$i) {
             $project_role = $project_roles->random();
             $is_draft = collect([1, 2])->random();
             $status = $statuses->random()->id;
@@ -101,12 +101,12 @@ class MiniSeeder extends Seeder
                 'project_role_id' => $project_role->id
             ]);
 
-            $total = 0;
+            $money = 0;
 
             for($j = 1; $j < 3; ++$j) {
                 $quantity = mt_rand(1, 5);
                 $price = mt_rand(1, 10) * 1000;
-                $total = $total + $quantity * $price;
+                $money = $money + $quantity * $price;
                 \App\Models\OrderDevice::create([
                     'name' => '设备' . $j,
                     'order_id' => $order->id,
@@ -115,7 +115,7 @@ class MiniSeeder extends Seeder
                     'price' => $price
                 ]);
             }
-            $order->update(['money' => $total]);
+            $order->update(['money' => $money]);
         }
     }
 }

+ 6 - 4
database/seeds/OptionSeeder.php

xqd xqd
@@ -15,9 +15,10 @@ class OptionSeeder extends Seeder
         $table = 'orders';
         $column = 'status';
         $items = [
-            ['name' => '待审核', 'key' => 'checking', 'color' => ''],
-            ['name' => '已完成', 'key' => 'pass'],
-            ['name' => '已驳回', 'key' => 'reject'],
+            ['name' => '待审核', 'key' => 'checking', 'color' => 'rgba(234, 151, 14, 1)'],
+            ['name' => '已审核', 'key' => 'checked', 'color' => 'rgba(76, 173, 132, 1)'],
+            ['name' => '已完成', 'key' => 'pass', 'color' => 'rgba(25, 133, 251, 1)'],
+            ['name' => '已驳回', 'key' => 'reject', 'color' => 'rgba(225, 132, 132, 1)'],
         ];
         \App\Models\Option::where([
             ['table', '=', $table],
@@ -29,7 +30,8 @@ class OptionSeeder extends Seeder
                 'column' => $column,
                 'name' => $val['name'],
                 'key' => $val['key'],
-                'sort' => $key + 1
+                'sort' => $key + 1,
+                'color' => $val['color']
             ]);
         }
     }

+ 1 - 1
mini/app.json

xqd
@@ -1,7 +1,7 @@
 {
   "pages": [
-    "pages/index/index",
     "pages/order/index",
+    "pages/index/index",
     "pages/project/index",
     "pages/create-order/index",
     "pages/create-project-role/index",

+ 3 - 3
mini/pages/index/index.js

xqd
@@ -26,9 +26,9 @@ Page({
       list: []
     })
     this.getList();
-    api.getByName(this, 'getUserInfo', 'userInfo', {}, function(res) {
-      app.updateUserInfo(res);
-    });
+    // api.getByName(this, 'getUserInfo', 'userInfo', {}, function(res) {
+    //   app.updateUserInfo(res);
+    // });
   },
   onLoad: function () {
     if (app.globalData.userInfo) {

+ 42 - 18
mini/pages/order/index.js

xqd xqd
@@ -12,7 +12,13 @@ Page({
     project: null,
     tabs: ['全部订单', '待审核', '已审核', '已完成', '已驳回'],
     statuses: ['', 'checking', 'checked', 'pass', 'reject'],
-    list: [[], [], [], [], []],
+    list: [
+      [],
+      [],
+      [],
+      [],
+      []
+    ],
     pages: [1, 1, 1, 1, 1],
     tabIndex: 0,
     touchBottom: [false, false, false, false, false],
@@ -33,45 +39,63 @@ Page({
     this.getList();
   },
 
-  getList: function() {
+  search() {
+    this.setData({
+      list: [
+        [],
+        [],
+        [],
+        [],
+        []
+      ],
+      pages: [1, 1, 1, 1, 1],
+      touchBottom: [false, false, false, false, false],
+    })
+    this.getList()
+  },
+
+  getList: function () {
     var index = this.data.tabIndex
     var touchBottom = this.data.touchBottom[index]
-    if(touchBottom) return false;
+    if (touchBottom) return false;
     var status = this.data.statuses[index]
     var page = this.data.pages[index]
     var that = this
+    var pointIndex = this.data.pointIndex
+    var work_point_id = pointIndex >= 0 ? this.data.work_points[pointIndex].id : 0
     http({
       url: 'orders/get',
       data: {
         project_id: this.data.id,
         status: status,
-        page: page
+        page: page,
+        work_point_id: work_point_id
       },
-      success: function(res) {
-        if(res.code == 0) {
-         var list = that.data.list
-         var touchBottom = that.data.touchBottom
-         list[index] = list[index].concat(res.data);
-         if(res.data.length <= 0) {
-           touchBottom[index] = true;
-         }
-         that.setData({
-           touchBottom,
-           list
-         })
+      success: function (res) {
+        if (res.code == 0) {
+          var list = that.data.list
+          var touchBottom = that.data.touchBottom
+          list[index] = list[index].concat(res.data);
+          if (res.data.length <= 0) {
+            touchBottom[index] = true;
+          }
+          that.setData({
+            touchBottom,
+            list
+          })
         }
       }
     })
   },
 
-  switchTab: function(e) {
+  switchTab: function (e) {
     var index = e.currentTarget.dataset.index
     this.setData({
       tabIndex: index
     })
   },
 
-  onChange: function(e) {
+  onChange: function (e) {
     var name = e.currentTarget.dataset.name
     this.setData({
       [name]: e.detail.value

+ 1 - 0
mini/pages/order/index.json

xqd
@@ -1,3 +1,4 @@
 {
+  "navigationBarTitleText": "所有订单",
   "usingComponents": {}
 }

+ 4 - 4
mini/pages/order/index.wxml

xqd xqd
@@ -5,12 +5,12 @@
       <view class="sg-left sg-flex-grow sg-border">
         <picker bindchange="onChange" value="{{pointIndex}}" range="{{work_points}}" range-key="name"
           data-name="pointIndex" class="sg-input">
-          <view class="picker sg-gray-color">
+          <view class="picker sg-gray-color sg-center">
             {{pointIndex >= 0 ? work_points[pointIndex].name : '选择所需的工点'}}
           </view>
         </picker>
       </view>
-      <van-icon name="search" class="sg-icon sg-index-color" />
+      <van-icon name="search" class="sg-icon sg-index-color" bind:click="search"/>
     </view>
     <view class="sg-tabs sg-flex sg-align-center sg-white-bg sg-pad sg-bottom-border sg-top-border sg-font-small">
       <view wx:for="{{tabs}}" wx:key="index" class="sg-tab {{tabIndex == index ? 'sg-selected' : ''}}"
@@ -31,10 +31,10 @@
             <view class="sg-device-item sg-flex sg-align-center sg-space-between sg-margin-tb-sm"
               wx:for="{{i_item.devices}}" wx:for-item="j_item" wx:for-index="j_index" wx:key="j_index">
               <view class="sg-name">{{j_index+1}}.{{j_item.type}}-{{j_item.name}}</view>
-              <view class="sg-price">¥{{j_item.price}}×{{j_item.quantity}}</view>
+              <view class="sg-price">¥{{j_item.price/100}}×{{j_item.quantity}}</view>
             </view>
           </view>
-          <view class="sg-total sg-text-right sg-margin-tb-sm">合计:¥{{i_item.money}}</view>
+          <view class="sg-total sg-text-right sg-margin-tb-sm">合计:¥{{i_item.money/100}}</view>
         </view>
         <view class="sg-bottom sg-flex sg-align-center sg-space-between">
           <view class="sg-left">

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

xqd
@@ -67,8 +67,8 @@ Page({
       id: id,
       userInfo: app.globalData.userInfo
     })
-    api.getByName(this, 'getUserInfo', 'userInfo', function(res) {
-      app.updateUserInfo(res.data);
+    api.getByName(this, 'getUserInfo', 'userInfo', {}, function(res) {
+      app.updateUserInfo(res);
     });
   },
 

+ 5 - 0
mini/utils/http.js

xqd
@@ -40,6 +40,11 @@ const http = (data) => {
           title: res.data.msg,
           icon: 'none'
         })
+        if(res.data.code == -100) {
+          wx.navigateTo({
+            url: '/pages/login/index',
+          })
+        }
       }
       typeof data.success === "function" && data.success(res.data)
     },

BIN
public/mini/default-user.png