xxxrrrdddd 2 years ago
parent
commit
0ff5fc055c

+ 18 - 3
application/admin/controller/Mobile.php

@@ -6,6 +6,7 @@ use app\admin\library\Auth;
 use app\admin\model\Admin;
 use app\common\controller\Backend;
 use app\common\library\MobileConstant;
+use app\common\model\MobileSub;
 use app\common\service\MobileImport;
 use app\common\service\MobilePriceLogService;
 use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
@@ -822,16 +823,30 @@ class Mobile extends Backend
         if(!$mobile){
             return '';
         }
+        $row=[
+            'sort'=>0,
+        ];
         if($this->request->isGet()){
-            $this->assign('row',$mobile);
+            if($this->admin('sub')){
+                $row['sort']=MobileSub::getBy($mobile,$this->admin())['sub_sort'];
+            }else{
+                $row['sort']=$mobile['sort'];
+            }
+            $this->assign('row',$row);
             return view();
         }else{
             $data=input('row/a');
             $this->validate($data,[
                 'sort|排序'=>['require','integer','gt:0'],
             ]);
-            $mobile['sort']=$data['sort'];
-            $mobile->save();
+            if($this->admin('sub')){
+                $mobileSub=MobileSub::getBy($mobile,$this->admin());
+                $mobileSub['sub_sort']=$data['sort'];
+                $mobileSub->save();
+            }else{
+                $mobile['sort']=$data['sort'];
+                $mobile->save();
+            }
             $this->success();
         }
     }

+ 12 - 0
application/common/controller/Backend.php

@@ -3,6 +3,7 @@
 namespace app\common\controller;
 
 use app\admin\library\Auth;
+use app\admin\model\Admin;
 use think\Config;
 use think\Controller;
 use think\Hook;
@@ -604,4 +605,15 @@ class Backend extends Controller
         //刷新Token
         $this->request->token();
     }
+
+    protected function admin($field=null){
+        static $admin;
+        if(is_null($admin)){
+            $admin=Admin::get($this->auth->id);
+        }
+        if($field){
+            return $admin[$field];
+        }
+        return $admin;
+    }
 }

+ 3 - 0
application/common/model/Mobile.php

@@ -46,6 +46,9 @@ class Mobile extends Model
     public function holdLog(){
         return $this->hasMany(MobileHoldLog::class);
     }
+    public function sub(){
+        return $this->hasMany(MobileSub::class);
+    }
     const BEAUTI=1;
     const FLOW=2;
 

+ 36 - 0
application/common/model/MobileSub.php

@@ -0,0 +1,36 @@
+<?php
+
+namespace app\common\model;
+
+use app\admin\model\Admin;
+use think\db\Query;
+use think\Model;
+
+/**
+ * 配置模型
+ */
+class MobileSub extends Model
+{
+    protected function scopeAdmin(Query $query,$adminId){
+        $query->where('admin_id',$adminId);
+    }
+
+    public static function getBy(Mobile $mobile,Admin $admin){
+        $one=self::where('mobile_id',$mobile['id'])->where('sub_admin_id',$admin['id'])->find();
+        if(!$one){
+            $one=self::create([
+                'mobile_id'=>$mobile['id'],
+                'sub_admin_id'=>$admin['id']
+            ]);
+        }
+        return $one;
+    }
+
+    protected static function init()
+    {
+        self::beforeUpdate(function (self $mobileSub){
+            $sort=$mobileSub['sub_sort'];
+            $mobileSub->where('sub_sort','>=',$sort)->where('sub_admin_id',$mobileSub['sub_admin_id'])->setInc('sub_sort');
+        });
+    }
+}