ソースを参照

会员所属代理

zac3533 1 年間 前
コミット
8f5bfdda7a

+ 2 - 2
application/admin/controller/user/Team.php

@@ -72,8 +72,8 @@ class Team extends Backend
             ->order($sort, $order)
             ->paginate($limit);
         if($list->total() > 0){
-            $in  = model('Mongyin');
-            $out = model('Mongyout');
+            $in  = model('MoneyIn');
+            $out = model('MoneyOut');
             foreach ($list as &$item) {
                 $item->recharge = $in::where('status', 1)->where('user_id', $item->id)->sum('amount');
                 $item->withdraw = $out::where('status', 1)->where('user_id', $item->id)->sum('amount');

+ 56 - 8
application/admin/controller/user/User.php

@@ -50,18 +50,14 @@ class User extends Backend
             }
             list($where, $sort, $order, $offset, $limit) = $this->buildparams();
 
-            $list = $this->model->with('parent')
-                ->where($where)->where('users.is_delete', 0)
-                ->order($sort, $order)
-                ->paginate($limit);
+            $list = $this->model->with('parent,agent')
+                    ->where($where)->where('users.is_delete', 0)
+                    ->order($sort, $order)
+                    ->paginate($limit);
 
             $in  = model('MoneyIn');
             $out = model('MoneyOut');
-            $path= model('UsersPath');
             foreach ($list as &$item) {
-                $item->agent = $this->model
-                    ->where('id', '=', $path->where('user_id', $item->id)->where('is_agent', 1)->order('distance', 'desc')->value('parent_id'))
-                    ->value('mobile');
                 $item->recharge = $in::where('status', 200)->where('user_id', $item->id)->sum('amount');
                 $item->withdraw = $out::where('status', 200)->where('user_id', $item->id)->sum('amount');
             }
@@ -332,4 +328,56 @@ class User extends Backend
         $this->success();
     }
 
+
+    /**
+     * 批量更新
+     * @param $ids
+     * @return void
+     */
+    public function multi($ids = null)
+    {
+        if (false === $this->request->isPost()) {
+            $this->error(__('Invalid parameters'));
+        }
+        $ids = $ids ?: $this->request->post('ids');
+        if (empty($ids)) {
+            $this->error(__('Parameter %s can not be empty', 'ids'));
+        }
+
+        if (false === $this->request->has('params')) {
+            $this->error(__('No rows were updated'));
+        }
+        parse_str($this->request->post('params'), $values);
+        $values = $this->auth->isSuperAdmin() ? $values : array_intersect_key($values, array_flip(is_array($this->multiFields) ? $this->multiFields : explode(',', $this->multiFields)));
+        if (empty($values)) {
+            $this->error(__('You have no permission'));
+        }
+        $adminIds = $this->getDataLimitAdminIds();
+        if (is_array($adminIds)) {
+            $this->model->where($this->dataLimitField, 'in', $adminIds);
+        }
+        $count = 0;
+        Db::startTrans();
+        try {
+
+            $row = $this->model->where($this->model->getPk(), '=', $ids)->find();
+            $key = key($values); //修改key
+            if($key == 'is_agent'){
+                //默认开启:设置伞下当前会员所属代理id    
+                $map['agent_id'] = $values[$key] == 0? $row->agent_id: $ids;
+                $this->model->where('id','IN', UsersPath::where('parent_id', $ids)->column('user_id'))->update($map);
+            }
+            $count = $row->allowField(true)->isUpdate(true)->save($values);
+            Db::commit();
+        } catch (PDOException|Exception $e) {
+            Db::rollback();
+            $this->error($e->getMessage());
+        }
+        if ($count) {
+            $this->success();
+        }
+        $this->error(__('No rows were updated'));
+    }
+
+
 }

+ 6 - 1
application/admin/model/Users.php

@@ -72,9 +72,14 @@ class Users extends Model
 
     public function parent()
     {
-        return $this->hasOne('Users','id','parent_id',[],'LEFT')->setEagerlyType(0);
+        return $this->hasOne('Users','id','parent_id',[],'LEFT')->setEagerlyType(0)->field('id,parent_id,moblie');
     }
 
+    public function agent()
+    {
+        return $this->hasOne('Users','id','agent_id',[],'LEFT')->setEagerlyType(0)->field('id,agent_id,moblie');
+    }
+    
 
     public function getPrevtimeTextAttr($value, $data)
     {

+ 2 - 3
public/assets/js/backend/user/user.js

@@ -27,8 +27,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                     [
                         {checkbox: true},
                         {field: 'id', title: __('Id'), operate: false},
-
-                        {field: 'agent', title: __('Group_id'), operate: false},
+                        {field: 'agent.mobile', title: __('Group_id'), operate: false},
                         {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                         {field: 'parent.mobile', title: __('Parent_id'), operate: false},
                         {field: 'balance', title: __('Balance'), operate: false},
@@ -47,7 +46,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                             return row.recharge - row.withdraw;
                         }},
                         {field: 'invitation_code', title: __('Invitation_code'), operate: false},
-                        {field: 'is_agent', title: __('Is_agent'), searchList: {1: __('Yes'), 0: __('No')}, formatter: Table.api.formatter.status},
+                        {field: 'is_agent', title: __('Is_agent'), searchList: {1: __('Yes'), 0: __('No')}, formatter: Table.api.formatter.toggle},
                         {field: 'user_type', title: __('User_type'), formatter: Table.api.formatter.toggle,
                             searchList: {0: __('Dummy'), 1: __('Real person')}
                         },