|
|
@@ -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'));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|