Browse Source

会员列表备注+搜索

Cherry 2 years ago
parent
commit
96a5976d0c

+ 21 - 5
application/admin/controller/user/User.php

@@ -51,13 +51,29 @@ class User extends Backend
             }
             list($where, $sort, $order, $offset, $limit) = $this->buildparams();
             $list = $this->model
-                ->with('group')
+//                ->with('group')
+                ->with(['joinremarks1','joinremarks2','joinremarks3'])
                 ->where($where)
                 ->order($sort, $order)
                 ->paginate($limit);
+
+//            // 备注数据-- 不需要查询时
+//            $remark_ids = [];
+//            $user_remarks_list = UserRemarks::select();
+//            foreach ($user_remarks_list as $vurl) {
+//                $remark_ids[$vurl['id']] = $vurl['value'];
+//            }
+
             foreach ($list as $k => $v) {
                 $v->avatar = $v->avatar ? cdnurl($v->avatar, true) : letter_avatar($v->nickname);
                 $v->hidden(['password', 'salt']);
+
+//                for ($i = 1; $i <= 3; $i++) {
+//                    $column_remarks = "remarks" . $i;
+//                    if ($v->$column_remarks != 0 && $v->$column_remarks != "") {
+//                        $list[$k]->$column_remarks = $remark_ids[$v->$column_remarks];
+//                    }
+//                }
             }
             $result = array("total" => $list->total(), "rows" => $list->items());
 
@@ -291,8 +307,8 @@ class User extends Backend
                                 $del_relations = true;
                                 // 绑定新关系
                                 $user_b_list = $this->model->where(['type_remarks' => $i, 'bind_remarks' => $params[$param_remarks]])->order('id', 'desc')->select();
-                                if(count($user_b_list)>0){
-                                    foreach ($user_b_list as $user_b){
+                                if (count($user_b_list) > 0) {
+                                    foreach ($user_b_list as $user_b) {
                                         $user_relation[] = [
                                             'c_user_id' => $row['id'],
                                             'b_user_id' => $user_b['id'],
@@ -316,10 +332,10 @@ class User extends Backend
                     //删除旧关系
                     if ($row[$param_remarks] != 0 && $del_relations) {
                         $user_b = $this->model->where(['type_remarks' => $i, 'bind_remarks' => $row[$param_remarks]])->order('id', 'desc')->select();
-                        foreach ($user_b as $vub){
+                        foreach ($user_b as $vub) {
                             $user_b_ids[] = $vub['id'];
                         }
-                        model('user_relations')->where('c_user_id',$row['id'])->whereIn('b_user_id',$user_b_ids)->delete();
+                        model('user_relations')->where('c_user_id', $row['id'])->whereIn('b_user_id', $user_b_ids)->delete();
                     }
                 }
             }

+ 14 - 0
application/admin/model/User.php

@@ -127,4 +127,18 @@ class User extends Model
         return $this->belongsTo('UserGroup', 'group_id', 'id', [], 'LEFT')->setEagerlyType(0);
     }
 
+    public function joinremarks1()
+    {
+        return $this->belongsTo('UserRemarks', 'remarks1', 'id', [], 'LEFT')->setEagerlyType(0);
+    }
+
+    public function joinremarks2()
+    {
+        return $this->belongsTo('UserRemarks', 'remarks2', 'id', [], 'LEFT')->setEagerlyType(0);
+    }
+
+    public function joinremarks3()
+    {
+        return $this->belongsTo('UserRemarks', 'remarks3', 'id', [], 'LEFT')->setEagerlyType(0);
+    }
 }

+ 4 - 1
public/assets/js/backend/user/user.js

@@ -43,7 +43,9 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                             searchList: {"1": __('Level 1'), "2": __('Level 2'), "3": __('Level 3')},
                             formatter: Table.api.formatter.normal
                         },
-                        {field: 'remarks', title: __('Remarks'), operate: 'LIKE'},
+                        {field: 'joinremarks1.value', title: __('Remarks1')},
+                        {field: 'joinremarks2.value', title: __('Remarks2')},
+                        {field: 'joinremarks3.value', title: __('Remarks3')},
                         {field: 'score', title: __('Score'), operate: 'LIKE'},
                         {
                             field: 'logintime',
@@ -76,6 +78,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                         },
                         {field: 'city', title: __('City'), operate: 'LIKE'},
                         {field: 'address', title: __('Address'), operate: 'LIKE'},
+                        {field: 'remarks', title: __('Remarks'), operate: 'LIKE'},
                         {
                             field: 'operate',
                             title: __('Operate'),