diff --git a/application/admin/controller/Dashboard.php b/application/admin/controller/Dashboard.php index 2dd2e06..01f2baa 100644 --- a/application/admin/controller/Dashboard.php +++ b/application/admin/controller/Dashboard.php @@ -3,7 +3,10 @@ namespace app\admin\controller; use app\admin\model\Admin; -use app\admin\model\User; +use app\common\model\user4s\User; +use app\common\model\user4s\Log; +use app\common\model\user4s\Levellog; +use app\common\model\user4s\Visit; use app\common\controller\Backend; use app\common\model\Attachment; use fast\Date; @@ -29,10 +32,10 @@ class Dashboard extends Backend } $column = []; - $starttime = Date::unixtime('day', -6); + $starttime = Date::unixtime('day', -10); $endtime = Date::unixtime('day', 0, 'end'); - $joinlist = Db("user")->where('jointime', 'between time', [$starttime, $endtime]) - ->field('jointime, status, COUNT(*) AS nums, DATE_FORMAT(FROM_UNIXTIME(jointime), "%Y-%m-%d") AS join_date') + $joinlist = User::where('createtime', 'between time', [$starttime, $endtime]) + ->field('createtime, status, COUNT(*) AS nums, DATE_FORMAT(FROM_UNIXTIME(createtime), "%Y-%m-%d") AS join_date') ->group('join_date') ->select(); for ($time = $starttime; $time <= $endtime;) { @@ -43,40 +46,65 @@ class Dashboard extends Backend foreach ($joinlist as $k => $v) { $userlist[$v['join_date']] = $v['nums']; } - - $dbTableList = Db::query("SHOW TABLE STATUS"); - $addonList = get_addon_list(); - $totalworkingaddon = 0; - $totaladdon = count($addonList); - foreach ($addonList as $index => $item) { - if ($item['state']) { - $totalworkingaddon += 1; - } + $this->assignconfig('column', array_keys($userlist)); + $this->assignconfig('userdata', array_values($userlist)); + //var_dump(Log::getlastsql()); + $joinlist = Log::where('state','=','0') + ->where('createtime', 'between time', [$starttime, $endtime]) + ->where('end','exp',' > start') + ->field('createtime, SUM(end-start) AS price, DATE_FORMAT(FROM_UNIXTIME(createtime), "%Y-%m-%d") AS join_date') + ->group('join_date') + ->select(); + + // for ($time = $starttime; $time <= $endtime;) { + // $column[] = date("Y-m-d", $time); + // $time += 86400; + // } + $pricelist = array_fill_keys($column, 0); + foreach ($joinlist as $k => $v) { + $pricelist[$v['join_date']] = $v['price']; } + $this->assignconfig('pricedata', array_values($pricelist)); + + //保险临期 + $start_date = strtotime("-1 year"); + $end_date = strtotime("+2 month",$start_date); + $ins_where = array( + 'insdate'=>['between',[date('Y-m-d',$start_date),date('Y-m-d',$end_date)]] + ); + $ins_end = User::where($ins_where)->count(); + $visit_where = array( + 'visittime'=>['between time',[Date::unixtime('day', 0,'begin'),Date::unixtime('day', 0,'end')]] + ); + $visit = Visit::where($visit_where)->where('status',0)->count(); + //var_dump(Visit::getlastsql()); $this->view->assign([ 'totaluser' => User::count(), - 'totaladdon' => $totaladdon, + 'totalvipuser' => User::where('level_id','>','1')->count(), + 'todayprice' => Log::where('state','=','0')->whereTime('createtime', 'today')->where('end','exp',' > start')->sum('end-start'), + 'sumprice' =>Log::where('state','=','0')->where('end','exp',' > start')->sum('end-start'), 'totaladmin' => Admin::count(), 'totalcategory' => \app\common\model\Category::count(), - 'todayusersignup' => User::whereTime('jointime', 'today')->count(), - 'todayuserlogin' => User::whereTime('logintime', 'today')->count(), - 'sevendau' => User::whereTime('jointime|logintime|prevtime', '-7 days')->count(), - 'thirtydau' => User::whereTime('jointime|logintime|prevtime', '-30 days')->count(), - 'threednu' => User::whereTime('jointime', '-3 days')->count(), - 'sevendnu' => User::whereTime('jointime', '-7 days')->count(), - 'dbtablenums' => count($dbTableList), - 'dbsize' => array_sum(array_map(function ($item) { - return $item['Data_length'] + $item['Index_length']; - }, $dbTableList)), - 'totalworkingaddon' => $totalworkingaddon, - 'attachmentnums' => Attachment::count(), + 'todayusersignup' => User::whereTime('createtime', 'today')->count(), + 'todayusertovip' => Levellog::whereTime('createtime', 'today')->where('end','exp',' > start')->count(), + 'day7user' => User::whereTime('createtime', '-7 days')->count(), + 'day7price' => Log::where('state','=','0')->whereTime('createtime', '-7 days')->where('end','exp',' > start')->sum('end-start'), + 'day3user' => User::whereTime('createtime', '-3 days')->count(), + 'day3price' => Log::where('state','=','0')->whereTime('createtime', '-3 days')->where('end','exp',' > start')->sum('end-start'), + // 'dbtablenums' => count($dbTableList), + // 'dbsize' => array_sum(array_map(function ($item) { + // return $item['Data_length'] + $item['Index_length']; + // }, $dbTableList)), + // 'totalworkingaddon' => $totalworkingaddon, + 'ins_end' => $ins_end, + 'visit' => $visit, + 'all_visit' => Visit::count(), 'attachmentsize' => Attachment::sum('filesize'), 'picturenums' => Attachment::where('mimetype', 'like', 'image/%')->count(), 'picturesize' => Attachment::where('mimetype', 'like', 'image/%')->sum('filesize'), ]); - $this->assignconfig('column', array_keys($userlist)); - $this->assignconfig('userdata', array_values($userlist)); + return $this->view->fetch(); } diff --git a/application/admin/controller/user4s/Category.php b/application/admin/controller/user4s/Category.php index bb21d8b..32b95fc 100644 --- a/application/admin/controller/user4s/Category.php +++ b/application/admin/controller/user4s/Category.php @@ -55,4 +55,12 @@ class Category extends Backend $data = ['searchlist' => $searchlist]; $this->success('', null, $data); } + public function del($ids = null) + { + $ids = $ids ? $ids : $this->request->post("ids"); + if ($ids == 1 || in_array(1, $ids)) { + $this->error('系统默认等级不能删除!'); + } + return parent::del($ids); + } } diff --git a/application/admin/controller/user4s/Inslog.php b/application/admin/controller/user4s/Inslog.php index fde9988..b4d2fed 100644 --- a/application/admin/controller/user4s/Inslog.php +++ b/application/admin/controller/user4s/Inslog.php @@ -39,6 +39,13 @@ class Inslog extends Backend */ public function index() { + $all_star = array( + 1=>'★', + 2=>'★★', + 3=>'★★★', + 4=>'★★★★', + 5=>'★★★★★', + ); //当前是否为关联查询 $this->relationSearch = true; //设置过滤方法 @@ -56,9 +63,9 @@ class Inslog extends Backend ->order($sort, $order) ->paginate($limit); - foreach ($list as $row) { - - + foreach ($list as &$item) { + $item->star_f = $all_star[$item->star]; + $item->createtime_f = date('Y-m-d',$item->createtime); } $result = array("total" => $list->total(), "rows" => $list->items()); diff --git a/application/admin/controller/user4s/Level.php b/application/admin/controller/user4s/Level.php index 1fb7596..ecc5c6f 100644 --- a/application/admin/controller/user4s/Level.php +++ b/application/admin/controller/user4s/Level.php @@ -87,4 +87,12 @@ class Level extends Backend } return json(['code' => 0, 'msg' => '非法请求']); } + public function del($ids = null) + { + $ids = $ids ? $ids : $this->request->post("ids"); + if ($ids == 1 || in_array(1, $ids)) { + $this->error('系统默认等级不能删除!'); + } + return parent::del($ids); + } } diff --git a/application/admin/controller/user4s/Levellog.php b/application/admin/controller/user4s/Levellog.php index 5699cc0..4d918ff 100644 --- a/application/admin/controller/user4s/Levellog.php +++ b/application/admin/controller/user4s/Levellog.php @@ -22,7 +22,7 @@ class Levellog extends Backend { parent::_initialize(); $this->model = new \app\common\model\user4s\Levellog; - + $this->level_model = new \app\common\model\user4s\Level; } @@ -39,6 +39,8 @@ class Levellog extends Backend */ public function index() { + $all_level = $this->level_model->where('status', 1)->column('id,name'); + //var_dump($all_level); //当前是否为关联查询 $this->relationSearch = true; //设置过滤方法 @@ -63,6 +65,12 @@ class Levellog extends Backend $row->getRelation('endlevel')->visible(['name']); $row->getRelation('admin')->visible(['nickname']); // var_dump($row); + if($row->start == 0){ + $row->start_name = $all_level[1]; + }else{ + $row->start_name = $all_level[$row->start]; + } + $row->end_name = $all_level[$row->end]; } $result = array("total" => $list->total(), "rows" => $list->items()); diff --git a/application/admin/controller/user4s/User.php b/application/admin/controller/user4s/User.php index b46928b..19e8dbb 100644 --- a/application/admin/controller/user4s/User.php +++ b/application/admin/controller/user4s/User.php @@ -43,9 +43,9 @@ class User extends Backend { parent::_initialize(); $this->model = new \app\common\model\user4s\User; - $this->level_model = new \app\common\model\user4s\Level(); - $this->levellog_model = new \app\common\model\user4s\Levellog(); - $this->log_model = new \app\common\model\user4s\Log(); + $this->level_model = new \app\common\model\user4s\Level; + $this->levellog_model = new \app\common\model\user4s\Levellog; + $this->log_model = new \app\common\model\user4s\Log; $this->view->assign("genderdataList", $this->model->getGenderdataList()); $this->view->assign("statusList", $this->model->getStatusList()); } @@ -124,7 +124,7 @@ class User extends Backend $this->model->validateFailException(true)->validate($validate); } $result = $this->model->allowField(true)->save($params); - var_dump($params['need_visit']); + //var_dump($params['need_visit']); //新加用户期初等级 if($result && $this->model->id){ if($params['need_visit'] == 1){ @@ -165,7 +165,7 @@ class User extends Backend public function edit($ids = null) { if ($this->request->isPost()) { - $this->token(); + //$this->token(); } $row = $this->model->get($ids); if (!$row) { diff --git a/application/admin/controller/user4s/Visit.php b/application/admin/controller/user4s/Visit.php index 8c4eb22..d8db6d0 100644 --- a/application/admin/controller/user4s/Visit.php +++ b/application/admin/controller/user4s/Visit.php @@ -142,7 +142,7 @@ class Visit extends Backend return $this->view->fetch(); } /** - * 回访记录和结单 + * 回访记录 没有使用提交记录 提交在visitlog->add中 */ public function visitlog($vid = null) { @@ -154,6 +154,91 @@ class Visit extends Backend $this->error(__('No Results were found')); } + $adminIds = $this->getDataLimitAdminIds(); + if (is_array($adminIds)) { + if (!in_array($row[$this->dataLimitField], $adminIds)) { + $this->error(__('You have no permission')); + } + } + $all_type = $this->type_model->where('deletetime', null)->column('id,name'); + $all_star = array( + 1=>'★', + 2=>'★★', + 3=>'★★★', + 4=>'★★★★', + 5=>'★★★★★', + ); + if ($this->request->isAjax()) { + //当前是否为关联查询 + $this->relationSearch = true; + //设置过滤方法 + $this->request->filter(['strip_tags', 'trim']); + //如果发送的来源是Selectpage,则转发到Selectpage + if ($this->request->request('keyField')) { + return $this->selectpage(); + } + $where_v = ['visit_id'=>$row->id]; + list($where, $sort, $order, $offset, $limit) = $this->buildparams(); + + $list = $this->log_model + ->with(['visittype', 'user', 'visit','admin']) + ->where($where) + ->where($where_v) + ->order($sort, $order) + ->paginate($limit); + foreach ($list as &$item) { + //$item->visit_time_f=date('Y-m-d',$item->visit_time); + //var_dump($item->visit_time_f); + $item->star_f = $all_star[$item->star]; + } + //var_dump($list->items()); + $result = array("total" => $list->total(), "rows" => $list->items(),'all_star'=>$all_star); + return json($result); + } + + if ($this->request->isPost()) { + $params = $this->request->post("row/a"); + //回访记录 + if (!empty($params['inscom']) && !empty($params['insdate'])) { + $log_data = array( + 'user4s_id' => $row->id, + 'admin_id'=>$this->auth->id, + 'inscom'=>$params['inscom'], + 'insdate'=>$params['insdate'], + 'star'=>$params['star'], + 'description'=>$params['description'] + ); + $this->Inslog_model = new \app\common\model\user4s\Inslog(); + $this->Inslog_model->isUpdate(false)->save($log_data); + $user_data = array( + 'inscom'=>$params['inscom'], + 'insdate'=>$params['insdate'], + ); + $this->model->save($user_data, ['id' => $row->id]); + }else{ + $this->error('请填写续保信息',url('user4s/user/expireins',['user4s_id'=>$row->id])); + } + $this->success('续保成功!',url('user4s/user/expireins',['user4s_id'=>$row->id])); + } + + $this->view->assign("now", date('Y-m-d')); + $this->view->assign("all_star", $all_star); + $this->view->assign('row', $row); + return $this->view->fetch(); + } + /** + * 记录回访情况 废弃 未使用 + */ + public function pushlog($vid = null) + { + if ($this->request->isPost()) { + $this->token(); + } + $row = $this->model->get($vid); + if (!$row) { + $this->error(__('No Results were found')); + } + $adminIds = $this->getDataLimitAdminIds(); if (is_array($adminIds)) { if (!in_array($row[$this->dataLimitField], $adminIds)) { @@ -198,7 +283,7 @@ class Visit extends Backend if ($this->request->isPost()) { $params = $this->request->post("row/a"); - //记录用户续保记录 + //回访记录 if (!empty($params['inscom']) && !empty($params['insdate'])) { $log_data = array( 'user4s_id' => $row->id, diff --git a/application/admin/controller/user4s/Visitlog.php b/application/admin/controller/user4s/Visitlog.php index 1531593..8811de6 100644 --- a/application/admin/controller/user4s/Visitlog.php +++ b/application/admin/controller/user4s/Visitlog.php @@ -3,6 +3,10 @@ namespace app\admin\controller\user4s; use app\common\controller\Backend; +use Exception; +use think\Db; +use think\exception\PDOException; +use think\exception\ValidateException; /** * 回访记录 @@ -22,7 +26,8 @@ class Visitlog extends Backend { parent::_initialize(); $this->model = new \app\common\model\user4s\Visitlog; - + $this->visit_model = new \app\common\model\user4s\Visit; + $this->type_model = new \app\common\model\user4s\Visittype; } @@ -68,4 +73,179 @@ class Visitlog extends Backend return $this->view->fetch(); } + /** + * 添加 + */ + public function add() + { + if ($this->request->isPost()) { + $this->token(); + } + $all_type = $this->type_model->where('deletetime', null)->column('id,name'); + $this->view->assign("all_type", $all_type); + $all_star = array( + 1=>'★', + 2=>'★★', + 3=>'★★★', + 4=>'★★★★', + 5=>'★★★★★', + ); + $this->view->assign("all_star", $all_star); + if (!$this->request->isPost()) { + $visit_id = $this->request->get("vid/d"); + if ($visit_id > 0) { + $visit=$this->visit_model->get($visit_id,['user','visittype']); + if(isset($visit->id)){ + $this->view->assign("row", $visit); + }else{ + $this->error("回访单不存在!"); + } + }else{ + $this->error("请选择要记录的回访单"); + } + } + if ($this->request->isPost()) { + $params = $this->request->post("row/a"); + if ($params) { + $visi_time = strtotime($params['visit_time'].' 00:00:00'); + $params['visit_time'] = $visi_time; + //处理结单等信息 + if($params['visit_id'] > 0){ + $visit_data = array( + 'id'=>$params['visit_id'], + //'star'=>$params['star'], + //'visittime'=>strtotime($params['visit_time']), + 'admin_id'=>$this->auth->id, + 'status'=>$params['is_end']==1?1:0, + 'endtime'=>$params['is_end']==1?time():null, + ); + //var_dump($visit_data);exit(); + $this->visit_model->where('id', $params['visit_id'])->update($visit_data); + // if($visit_id == false){ + // $this->error("更新回访单失败!"); + // } + } + $params = $this->preExcludeFields($params); + $params['admin_id'] = $this->auth->id; + // if ($this->dataLimit && $this->dataLimitFieldAutoFill) { + // $params[$this->dataLimitField] = $this->auth->id; + // } + + $result = false; + $this->model->startTrans(); + try { + //是否采用模型验证 + if ($this->modelValidate) { + $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); + $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate; + $this->model->validateFailException(true)->validate($validate); + } + $result = $this->model->allowField(true)->save($params); + $this->model->commit(); + } catch (ValidateException $e) { + $this->model->rollback(); + $this->error($e->getMessage()); + } catch (PDOException $e) { + $this->model->rollback(); + $this->error($e->getMessage()); + } catch (Exception $e) { + $this->model->rollback(); + $this->error($e->getMessage()); + } + if ($result !== false) { + $this->success(); + } else { + $this->error(__('No rows were inserted')); + } + } + $this->error(__('Parameter %s can not be empty', '')); + } + return parent::add(); + } + /** + * 编辑 + */ + public function edit($ids = null) + { + $all_type = $this->type_model->where('deletetime', null)->column('id,name'); + $this->view->assign("all_type", $all_type); + $all_star = array( + 1=>'★', + 2=>'★★', + 3=>'★★★', + 4=>'★★★★', + 5=>'★★★★★', + ); + $this->view->assign("all_star", $all_star); + $row = $this->model->get($ids,['visittype', 'user', 'visit','admin']); + if (!$row) { + $this->error(__('No Results were found')); + } + if (empty($row->visit->id)) { + $this->error(__('没找到对应的回访单!')); + } + if (empty($row->user->id)) { + $this->error(__('没找到对应的客户!')); + } + $adminIds = $this->getDataLimitAdminIds(); + if (is_array($adminIds)) { + if (!in_array($row[$this->dataLimitField], $adminIds)) { + $this->error(__('You have no permission')); + } + } + if ($this->request->isPost()) { + $params = $this->request->post("row/a"); + if ($params) { + $visi_time = strtotime($params['visit_time'].' 00:00:00'); + $params['visit_time'] = $visi_time; + //处理结单等信息 + if($params['visit_id'] > 0){ + $visit_data = array( + 'id'=>$params['visit_id'], + //'star'=>$params['star'], + //'visittime'=>strtotime($params['visit_time']), + 'admin_id'=>$this->auth->id, + 'status'=>$params['is_end']==1?1:0, + 'endtime'=>$params['is_end']==1?time():null, + ); + //var_dump($visit_data);exit(); + $this->visit_model->where('id', $params['visit_id'])->update($visit_data); + } + unset($params['is_end']); + //var_dump($params);exit(); + $params = $this->preExcludeFields($params); + $result = false; + $this->model->startTrans(); + try { + //是否采用模型验证 + if ($this->modelValidate) { + $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); + $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate; + $row->validateFailException(true)->validate($validate); + } + //var_dump($params);exit(); + $result = $row->allowField(true)->save($params); + $this->model->commit(); + } catch (ValidateException $e) { + $this->model->rollback(); + $this->error($e->getMessage()); + } catch (PDOException $e) { + $this->model->rollback(); + $this->error($e->getMessage()); + } catch (Exception $e) { + $this->model->rollback(); + $this->error($e->getMessage()); + } + if ($result !== false) { + $this->success(); + } else { + $this->error(__('No rows were updated')); + } + } + $this->error(__('Parameter %s can not be empty', '')); + } + $this->view->assign("row", $row); + return $this->view->fetch(); + } + } diff --git a/application/admin/view/dashboard/index.html b/application/admin/view/dashboard/index.html index 0c04396..58655ad 100644 --- a/application/admin/view/dashboard/index.html +++ b/application/admin/view/dashboard/index.html @@ -163,14 +163,61 @@
{:build_heading(null, false)}
+ +
@@ -185,8 +232,8 @@
- {$totaladdon} - {:__('Total addon')} + {$totalvipuser} + {:__('高级会员数')}
@@ -194,8 +241,8 @@
- {$attachmentnums} - {:__('Total attachment')} + {$todayprice|round=###,2} + {:__('今日充值金额')}
@@ -204,16 +251,13 @@
{$totaladmin} - {:__('Total admin')} + {:__('管理员数量')}
-
-
-
@@ -222,7 +266,7 @@
{$todayusersignup}
-
{:__('Today user signup')}
+
{:__('今日新增客户')}
@@ -231,48 +275,48 @@
-
{$todayuserlogin}
-
{:__('Today user login')}
+
{$todayusertovip}
+
{:__('今日新升级客户')}
-
+
-
{$threednu}
-
{:__('Three dnu')}
+
{$day3user}
+
{:__('三日新增客户')}
-
+
-
{$sevendnu}
-
{:__('Seven dnu')}
+
{$day3price|round=###,2}
+
{:__('三日充值金额')}
-
+
-
{$sevendau}
-
{:__('Seven dau')}
+
{$day7user}
+
{:__('近一周新增客户')}
-
+
-
{$thirtydau}
-
{:__('Thirty dau')}
+
{$day7price|round=###,2}
+
{:__('近一周充值金额')}
@@ -282,114 +326,13 @@
+
+
+
+
-
-
-
-
-
-
-
- {:__('Real time')} -
{:__('Working addon count')}
-
-
-
-
-

{$totalworkingaddon}

-
- {:__('Working addon count tips')} -
-
-
-
-
-
-
-
-
-
-
- {:__('Real time')} -
{:__('Database count')}
-
-
-
-
-

{$dbtablenums}

-
- {:__('Database table nums')} -
-
-
-

{$dbsize|format_bytes=###,'',0}

-
- {:__('Database size')} -
-
-
-
-
-
-
- -
-
-
-
- {:__('Real time')} -
{:__('Attachment count')}
-
-
- -
-
-

{$attachmentnums}

-
- {:__('Attachment nums')} -
-
-
-

{$attachmentsize|format_bytes=###,'',0}

-
- {:__('Attachment size')} -
-
-
-
-
-
-
-
-
-
-
- {:__('Real time')} -
{:__('Picture count')}
-
-
- -
-
-

{$picturenums}

-
- {:__('Picture nums')} -
-
-
-

{$picturesize|format_bytes=###,'',0}

-
- {:__('Picture size')} -
-
-
-
-
-
-
-
diff --git a/application/admin/view/user4s/user/recharge.html b/application/admin/view/user4s/user/recharge.html index c7f24e5..3183bf2 100644 --- a/application/admin/view/user4s/user/recharge.html +++ b/application/admin/view/user4s/user/recharge.html @@ -29,6 +29,7 @@
+
diff --git a/application/admin/view/user4s/visit/edit.html b/application/admin/view/user4s/visit/edit.html index f5df0b0..f6c1a72 100644 --- a/application/admin/view/user4s/visit/edit.html +++ b/application/admin/view/user4s/visit/edit.html @@ -24,6 +24,16 @@
+
+ +
+ + + + + 结单后不能再填报记录,后续还有回访请重新开单。绿色为结单,灰色为不结单! +
+