From ebc7f2be880fc3c7059450939069e37fa0c46d5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=9F=E5=87=A1=E6=87=82?= Date: Sat, 9 Jul 2022 04:16:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=8A=9F=E8=83=BD=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=20fix=20#1=20fix=20#2=20fix=20#3=20fix=20#4=20fix=20#5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controller/Dashboard.php | 74 +- .../admin/controller/user4s/Inslog.php | 114 +- application/admin/controller/user4s/User.php | 432 +- .../admin/view/user4s/inslog/index.html | 32 + .../admin/view/user4s/user/birthday.html | 98 +- .../admin/view/user4s/user/expireins.html | 40 +- application/admin/view/user4s/user/index.html | 2 + .../admin/view/user4s/visit/index.html | 2 +- application/extra/site.php | 7 +- car4s.sql | 5243 +---------------- public/assets/js/backend/user4s/inslog.js | 53 +- public/assets/js/backend/user4s/user.js | 289 +- public/assets/js/backend/user4s/visit.js | 51 + 13 files changed, 1358 insertions(+), 5079 deletions(-) diff --git a/application/admin/controller/Dashboard.php b/application/admin/controller/Dashboard.php index c04702d..e006883 100644 --- a/application/admin/controller/Dashboard.php +++ b/application/admin/controller/Dashboard.php @@ -11,6 +11,9 @@ use app\common\controller\Backend; use app\common\model\Attachment; use fast\Date; use think\Db; +use think\Config; + +use car\Sms; /** * 控制台 @@ -29,8 +32,35 @@ class Dashboard extends Backend try { \think\Db::execute("SET @@sql_mode='';"); } catch (\Exception $e) { - } + + $user_ids=[1,2]; + // $list = User::where('id', 'in', $user_ids)->select(); + // $list = collection($list)->toarray(); + // $list = array_column($list, null, 'id'); + // var_dump($list); + // $sms = new Sms(['userid' => 5838, 'account' => '盛世鑫鼎比亚迪', 'password' => '123456']); + + // $prefix = Config::get('database.prefix'); + // $fieldArr = []; + // $table = $prefix . 'user4s_user'; + // $database = Config::get('database.database'); + // $pk = Db::getTableInfo($table, 'pk'); + // $list = db()->query( + // "SELECT COLUMN_NAME,COLUMN_COMMENT,COLUMN_TYPE,IS_NULLABLE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = ? AND TABLE_SCHEMA = ?", + // [$table, $database] + // ); + // foreach ($list as $k => $v) { + // if ($v['COLUMN_NAME'] !== $pk) { + // $fieldArr[$v['COLUMN_COMMENT']] = $v; //['COLUMN_NAME'] + // } + // } + // var_dump($fieldArr); + + //$sms->sendsms('15264925507','测试短信啊'); + //$sms->getStatus(); + // print_r($sms->send($user_ids,'【比亚迪汽车】如果搜[姓名]-将返回[联系方式]-要对数[余额]-进行[积分]-找且[性别]-要[车牌号码],退订回T')); + // $sms->getStatus(); $column = []; $starttime = Date::unixtime('day', -10); $endtime = Date::unixtime('day', 0, 'end'); @@ -49,13 +79,13 @@ class Dashboard extends Backend $this->assignconfig('column', array_keys($userlist)); $this->assignconfig('userdata', array_values($userlist)); //var_dump(Log::getlastsql()); - $joinlist = Log::where('state','=','0') + $joinlist = Log::where('state', '=', '0') ->where('createtime', 'between time', [$starttime, $endtime]) - ->where('end','exp',' > start') + ->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; @@ -68,31 +98,40 @@ class Dashboard extends Backend //保险临期 $start_date = strtotime("-1 year"); - $end_date = strtotime("+2 month",$start_date); + $end_date = strtotime("+2 month", $start_date); $ins_where = array( - 'insdate'=>['between',[date('Y-m-d',$start_date),date('Y-m-d',$end_date)]] + 'insdate' => ['between', [date('Y-m-d', $start_date), date('Y-m-d', $end_date)]] ); - $ins_end = User::where($ins_where)->count(); + $ins_end = User::where(function ($query) { + for ($y = 1; $y <= 20; $y++) { + $start_date = strtotime("-" . $y . " 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)]] + ); + $query->whereOr($ins_where); + } + })->count(); $visit_where = array( - 'visittime'=>['<=',Date::unixtime('day', 0,'end')] + 'visittime' => ['<=', Date::unixtime('day', 0, 'end')] ); - $visit = Visit::where($visit_where)->where('status',0)->count(); + $visit = Visit::where($visit_where)->where('status', 0)->count(); //今日生日 $birthday_users = Db::query("select count(*) as num from car_user4s_user where MONTH(birthday) = MONTH(NOW()) and DAY(birthday) = DAY(NOW())"); //var_dump(Db::getlastsql(), $birthday_users); $index_data = [ 'totaluser' => User::count(), - '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'), + '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('createtime', 'today')->count(), - 'todayusertovip' => Levellog::whereTime('createtime', 'today')->where('end','exp',' > start')->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'), + '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'), + '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']; @@ -105,12 +144,11 @@ class Dashboard extends Backend 'attachmentsize' => Attachment::sum('filesize'), 'picturenums' => Attachment::where('mimetype', 'like', 'image/%')->count(), 'picturesize' => Attachment::where('mimetype', 'like', 'image/%')->sum('filesize'), - ]; - + ]; + $this->assignconfig('index_data', $index_data); $this->view->assign($index_data); return $this->view->fetch(); } - } diff --git a/application/admin/controller/user4s/Inslog.php b/application/admin/controller/user4s/Inslog.php index 5366141..ce98e48 100644 --- a/application/admin/controller/user4s/Inslog.php +++ b/application/admin/controller/user4s/Inslog.php @@ -4,6 +4,15 @@ namespace app\admin\controller\user4s; use app\common\controller\Backend; +use PhpOffice\PhpSpreadsheet\Cell\Coordinate; +use PhpOffice\PhpSpreadsheet\Reader\Xlsx; +use PhpOffice\PhpSpreadsheet\Reader\Xls; +use PhpOffice\PhpSpreadsheet\Reader\Csv; +use PhpOffice\PhpSpreadsheet\Shared\Date; + +use PhpOffice\PhpSpreadsheet\IOFactory; +use PhpOffice\PhpSpreadsheet\Spreadsheet; +use PhpOffice\PhpSpreadsheet\Style; /** * 续保记录 * @@ -69,11 +78,114 @@ class Inslog extends Backend $item->createtime_f = date('Y-m-d',$item->createtime); } - $result = array("total" => $list->total(), "rows" => $list->items()); + $result = array("total" => $list->total(), "rows" => $list->items(), "extend" => ['start_data'=>date('Y-m-d',strtotime('-1 month')),'end_data'=>date('Y-m-d')]); return json($result); } return $this->view->fetch(); } + /** + * 对Spreadsheet方法封装(锐庆) + * @param array $arr 该数组必须为键值对,键是表格单元,值是单元格的值 + * @param array $data 该数组如果为一维数组,则填写一行,如果为二维数组,则多行数据 + * @param string $name 下载Excel的文件名,可忽略 + * @param string $type 选择文件类型,如果不填写,默认下载为xlsx格式,如果任意填写数值为xls格式 + * @param int $with 设置sheet默认列宽 + */ + public function downloadExcel(array $arr, array $data, $name = "", $type = "Xlsx") + { + //文件名处置 + if (empty($name)) { + $name = date("Y-m-d H:i:s") . "_" . rand(1000, 9999); + } else { + $name = $name . "_" . date("Y-m-d H:i:s"); + } + //内容设置 + $preadsheet = new Spreadsheet(); + $sheet = $preadsheet->getActiveSheet(); + foreach ($arr as $k => $v) { + $sheet->setCellValue($k, $v); + } + $sheet->fromArray($data, null, "A2"); + + //样式设置 + $sheet->getDefaultColumnDimension()->setWidth(20); + + //设置下载与后缀 + if ($type == "Xlsx") { + header("Content-Type:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + $suffix = "xlsx"; + } else { + header("Content-Type:application/vnd.ms-excel"); + $type = "Xls"; + $suffix = "xls"; + } + header("Content-Disposition:attachment;filename=$name.$suffix"); + header("Cache-Control:max-age=0"); //缓存控制 + $writer = IOFactory::createWriter($preadsheet, $type); + $writer->save("php://output"); //数据流 + } + public function excel() + { + + set_time_limit(0); + $all_star = array( + 1 => '★', + 2 => '★★', + 3 => '★★★', + 4 => '★★★★', + 5 => '★★★★★', + ); + //设置过滤方法 + $this->request->filter(['strip_tags', 'trim']); + $start_date = $this->request->get("start_date", ''); + $end_date = $this->request->get("end_date", ''); + if(empty($start_date) || empty($end_date)){ + $this->error('请选择要导出的日期范围'); + } + $ins_where = array('inslog.insdate' => ['between', [date('Y-m-d', strtotime($start_date)), date('Y-m-d', strtotime($end_date))]]); + $data = array(); + $head = array( + 'A1' => '编号', + 'B1' => '姓名', + 'C1' => '联系方式', + 'D1' => '身份证', + 'E1' => '生日', + 'F1' => '购车日期', + 'G1' => '车牌号码', + 'H1' => '车架号', + 'I1' => '车型', + 'J1' => '颜色', + 'K1' => '续保保险类型', + 'L1' => '续保保险公司', + 'M1' => '续保日期', + 'N1' => '满意度', + 'O1' => '备注', + ); + $list = $this->model->with(['user'])->where($ins_where)->select(); + //var_dump($this->model->getLastSql());exit(); + $logs = collection($list)->toArray(); + foreach ($logs as $index => $item) { + //var_dump($item); + $data[] = array( + $item['id'], + $item['user']['name'], + ' '.$item['user']['tel'], + ' '.$item['user']['cardid'], + date('Y年m月d日',strtotime($item['user']['birthday'])), + date('Y年m月d日',strtotime($item['user']['buydate'])), + $item['user']['carno'], + $item['user']['frameno'], + $item['user']['model'], + $item['user']['color'], + $item['instype'], + $item['inscom'], + date('Y年m月d日',strtotime($item['insdate'])), + $all_star[$item['star']], + $item['description'], + ); + } + return $this->downloadExcel($head,$data); + } } diff --git a/application/admin/controller/user4s/User.php b/application/admin/controller/user4s/User.php index 5fcfa95..4af1f93 100644 --- a/application/admin/controller/user4s/User.php +++ b/application/admin/controller/user4s/User.php @@ -18,6 +18,10 @@ use PhpOffice\PhpSpreadsheet\Reader\Xlsx; use PhpOffice\PhpSpreadsheet\Reader\Xls; use PhpOffice\PhpSpreadsheet\Reader\Csv; use fast\Pinyin; +use think\Loader; +use think\Model; +use car\Sms; +use fast\Date; /** * 用户档案 @@ -299,50 +303,7 @@ class User extends Backend } $this->error('车架号重复'); } - /** - * 删除 - */ - // public function del($ids = "") - // { - // if (!$this->request->isPost()) { - // $this->error(__("Invalid parameters")); - // } - // $ids = $ids ? $ids : $this->request->post("ids"); - // if ($ids) { - // if($ids == 1 || in_array('1',$ids)){ - // $this->error(__('默认等级(ID:1)禁止删除,请重新操作!')); - // } - // $pk = $this->model->getPk(); - // $adminIds = $this->getDataLimitAdminIds(); - // if (is_array($adminIds)) { - // $this->model->where($this->dataLimitField, 'in', $adminIds); - // } - // $list = $this->model->where($pk, 'in', $ids)->select(); - - // $count = 0; - // $this->model->startTrans(); - // try { - // foreach ($list as $k => $v) { - // $count += $v->delete(); - // //删除用户记录 - // //$log_res = $this->model->afterlog($this->auth->id,$this->model,$v->id,'',false); - // } - // $this->model->commit(); - // } catch (PDOException $e) { - // $this->model->rollback(); - // $this->error($e->getMessage()); - // } catch (Exception $e) { - // $this->model->rollback(); - // $this->error($e->getMessage()); - // } - // if ($count) { - // $this->success(); - // } else { - // $this->error(__('No rows were deleted')); - // } - // } - // $this->error(__('Parameter %s can not be empty', 'ids')); - // } + /** * 充值 */ @@ -438,36 +399,65 @@ class User extends Backend //设置过滤方法 $this->request->filter(['strip_tags', 'trim']); - $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_where = array(); + $start = strtotime("-1 year"); + $end = strtotime("+2 month", $start); + $start_date = $this->request->get("start_date", ''); + $end_date = $this->request->get("end_date", ''); + + if(!empty($start_date) && !empty($end_date)){ + $start = strtotime(date('Y-').$start_date); + $end = strtotime(date('Y-').$end_date); + + for ($y=1; $y<=30; $y++) { + $start_dates = strtotime("-".$y." year",$start); + $end_dates = strtotime("-".$y." year", $end); + $ins_where[] = array('insdate' => ['between', [date('Y-m-d', $start_dates), date('Y-m-d', $end_dates)]]); + } + } if ($this->request->isAjax()) { + // $start_date = $this->request->post("start_date", ''); + // $end_date = $this->request->post("end_date", ''); list($where, $sort, $order, $offset, $limit) = $this->buildparams(); $list = $this->model ->with(['category', 'level']) ->where($where) - ->where(function ($query) { - for ($y=1; $y<=20; $y++) { - $start_date = strtotime("-".$y." 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)]] - ); - $query->whereOr($ins_where); + ->where(function ($query) use($ins_where) { + //todo:测试闭包传递参数 + if(!empty($ins_where)){ + foreach($ins_where as $item){ + $query->whereOr($item); + } + }else{ + for ($y=1; $y<=30; $y++) { + $start = strtotime("-".$y." year"); + $end = strtotime("+2 month", $start); + $ins_where = array( + 'insdate' => ['between', [date('Y-m-d', $start), date('Y-m-d', $end)]] + ); + $query->whereOr($ins_where); + } } + }) ->order($sort, $order) ->paginate($limit); - //var_dump($this->model->getLastSql()); - foreach ($list as $row) { + + foreach ($list as &$row) { $row->getRelation('category')->visible(['name']); $row->getRelation('level')->visible(['name']); + $tip_start = Date::unixtime('year', 0,'start'); + $tip_end = Date::unixtime('year', 0,'end'); + //var_dump($tip_start,$tip_end); + if($row->instiptime >=$tip_start && $row->instiptime <=$tip_end){ + $row->instip = 1; + }else{ + $row->instip = 0; + } } - $result = array("total" => $list->total(), "rows" => $list->items(), "extend" => ['start_date' => date('m-d', $start_date), 'end_date' => date('m-d', $end_date)]); + $result = array("total" => $list->total(), "rows" => $list->items(), "extend" => ['start_date' => date('m-d', $start), 'end_date' => date('m-d', $end)],'sql'=>$this->model->getLastSql()); return json($result); } @@ -533,7 +523,60 @@ class User extends Backend $this->view->assign('row', $row); return $this->view->fetch(); } + /** + * 续保提醒 + */ + public function instip($ids = null) + { + $row = $this->model->get($ids); + if (!$row) { + $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_level = $this->level_model->where('status', 1)->column('id,name'); + + if ($this->request->isPost()) { + //记录用户续保提醒 + $row->instiptime = time(); + $row->save(); + $this->success('记录提醒状态成功!', url('user4s/user/expireins'),array('tiptime'=>date('Y-m-d H:i:s'))); + } + $this->view->assign('row', $row); + return $this->view->fetch(); + } + /** + * 取消续保提醒 + */ + public function instipno($ids = null) + { + $row = $this->model->get($ids); + if (!$row) { + $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_level = $this->level_model->where('status', 1)->column('id,name'); + + if ($this->request->isPost()) { + //记录用户续保提醒 + $row->instiptime = 0; + $row->save(); + $this->success('取消提醒状态成功', url('user4s/user/expireins'),array('tiptime'=>date('Y-m-d H:i:s'))); + } + $this->view->assign('row', $row); + return $this->view->fetch(); + } /** * 过生日用户列表 */ @@ -545,9 +588,29 @@ class User extends Backend $this->request->filter(['strip_tags', 'trim']); if ($this->request->isAjax()) { - $birthday_users = Db::query("select id from car_user4s_user where MONTH(birthday) = MONTH(NOW()) and DAY(birthday) = DAY(NOW())"); + + $birthday = $this->request->get("birthday", ''); + if(!empty($birthday)){ + //halt($birthday); + $search_date = '2022-'.$birthday; + }else{ + $filter = $this->request->get("filter", ''); + $op = $this->request->get("op", '', 'trim'); + $filter = (array)json_decode($filter, true); + $op = (array)json_decode($op, true); + if(!empty($filter['birthday'])){ + $search_date = '2022-'.$filter['birthday']; + $_GET['filter']= '{}'; + $_GET['op']= '{}'; + }else{ + $search_date = date('Y-m-d'); + } + } + + $birthday_users = Db::query("select id from car_user4s_user where MONTH(birthday) = MONTH('".$search_date."') and DAY(birthday) = DAY('".$search_date."')"); + if(empty($birthday_users)){ - $result = array("total" => 0, "rows" => [], "extend" => ['start_date' => date('m-d')]); + $result = array("total" => 0, "rows" => [], "extend" => ['start_date' => date('m-d',strtotime($search_date))]); return json($result); }else{ foreach ($birthday_users as $key => $value) { @@ -555,27 +618,262 @@ class User extends Backend } } if(empty($birthday_user_ids)){ - $result = array("total" => 0, "rows" => [], "extend" => ['start_date' => date('m-d')]); + $result = array("total" => 0, "rows" => [], "extend" => ['start_date' => date('m-d',strtotime($search_date))]); return json($result); } - //var_dump($birthday_user_ids); - list($where, $sort, $order, $offset, $limit) = $this->buildparams(); + + //var_dump($filter,$op); + //var_dump($birthday_user_ids); + list($where, $sort, $order, $offset, $limit) = $this->buildparamsu('{}','{}'); $list = $this->model ->with(['category', 'level']) ->where($where) ->where('user.id', 'in', $birthday_user_ids) + ->where('user.birthday', '<>', '0000-00-00') ->order($sort, $order) ->paginate($limit); - //var_dump($this->model->getLastSql()); + //echo($this->model->getLastSql()); foreach ($list as $row) { $row->getRelation('category')->visible(['name']); $row->getRelation('level')->visible(['name']); } - $result = array("total" => $list->total(), "rows" => $list->items(), "extend" => ['start_date' => date('m-d')]); + $result = array("total" => $list->total(), "rows" => $list->items(), "extend" => ['start_date' => date('m-d',strtotime($search_date))]); return json($result); } return $this->view->fetch(); } + protected function buildparamsu($filter,$op,$searchfields = null, $relationSearch = null) + { + $searchfields = is_null($searchfields) ? $this->searchFields : $searchfields; + $relationSearch = is_null($relationSearch) ? $this->relationSearch : $relationSearch; + $search = $this->request->get("search", ''); + // $filter = $this->request->get("filter", ''); + // $op = $this->request->get("op", '', 'trim'); + $sort = $this->request->get("sort", !empty($this->model) && $this->model->getPk() ? $this->model->getPk() : 'id'); + $order = $this->request->get("order", "DESC"); + $offset = $this->request->get("offset/d", 0); + $limit = $this->request->get("limit/d", 999999); + //新增自动计算页码 + $page = $limit ? intval($offset / $limit) + 1 : 1; + if ($this->request->has("page")) { + $page = $this->request->get("page/d", 1); + } + $this->request->get([config('paginate.var_page') => $page]); + $filter = (array)json_decode($filter, true); + $op = (array)json_decode($op, true); + $filter = $filter ? $filter : []; + $where = []; + $alias = []; + $bind = []; + $name = ''; + $aliasName = ''; + if (!empty($this->model) && $this->relationSearch) { + $name = $this->model->getTable(); + $alias[$name] = Loader::parseName(basename(str_replace('\\', '/', get_class($this->model)))); + $aliasName = $alias[$name] . '.'; + } + $sortArr = explode(',', $sort); + foreach ($sortArr as $index => & $item) { + $item = stripos($item, ".") === false ? $aliasName . trim($item) : $item; + } + unset($item); + $sort = implode(',', $sortArr); + $adminIds = $this->getDataLimitAdminIds(); + if (is_array($adminIds)) { + $where[] = [$aliasName . $this->dataLimitField, 'in', $adminIds]; + } + if ($search) { + $searcharr = is_array($searchfields) ? $searchfields : explode(',', $searchfields); + foreach ($searcharr as $k => &$v) { + $v = stripos($v, ".") === false ? $aliasName . $v : $v; + } + unset($v); + $where[] = [implode("|", $searcharr), "LIKE", "%{$search}%"]; + } + $index = 0; + foreach ($filter as $k => $v) { + if (!preg_match('/^[a-zA-Z0-9_\-\.]+$/', $k)) { + continue; + } + $sym = isset($op[$k]) ? $op[$k] : '='; + if (stripos($k, ".") === false) { + $k = $aliasName . $k; + } + $v = !is_array($v) ? trim($v) : $v; + $sym = strtoupper(isset($op[$k]) ? $op[$k] : $sym); + //null和空字符串特殊处理 + if (!is_array($v)) { + if (in_array(strtoupper($v), ['NULL', 'NOT NULL'])) { + $sym = strtoupper($v); + } + if (in_array($v, ['""', "''"])) { + $v = ''; + $sym = '='; + } + } + switch ($sym) { + case '=': + case '<>': + $where[] = [$k, $sym, (string)$v]; + break; + case 'LIKE': + case 'NOT LIKE': + case 'LIKE %...%': + case 'NOT LIKE %...%': + $where[] = [$k, trim(str_replace('%...%', '', $sym)), "%{$v}%"]; + break; + case '>': + case '>=': + case '<': + case '<=': + $where[] = [$k, $sym, intval($v)]; + break; + case 'FINDIN': + case 'FINDINSET': + case 'FIND_IN_SET': + $v = is_array($v) ? $v : explode(',', str_replace(' ', ',', $v)); + $findArr = array_values($v); + foreach ($findArr as $idx => $item) { + $bindName = "item_" . $index . "_" . $idx; + $bind[$bindName] = $item; + $where[] = "FIND_IN_SET(:{$bindName}, `" . str_replace('.', '`.`', $k) . "`)"; + } + break; + case 'IN': + case 'IN(...)': + case 'NOT IN': + case 'NOT IN(...)': + $where[] = [$k, str_replace('(...)', '', $sym), is_array($v) ? $v : explode(',', $v)]; + break; + case 'BETWEEN': + case 'NOT BETWEEN': + $arr = array_slice(explode(',', $v), 0, 2); + if (stripos($v, ',') === false || !array_filter($arr, function($v){ + return $v != '' && $v !== false && $v !== null; + })) { + continue 2; + } + //当出现一边为空时改变操作符 + if ($arr[0] === '') { + $sym = $sym == 'BETWEEN' ? '<=' : '>'; + $arr = $arr[1]; + } elseif ($arr[1] === '') { + $sym = $sym == 'BETWEEN' ? '>=' : '<'; + $arr = $arr[0]; + } + $where[] = [$k, $sym, $arr]; + break; + case 'RANGE': + case 'NOT RANGE': + $v = str_replace(' - ', ',', $v); + $arr = array_slice(explode(',', $v), 0, 2); + if (stripos($v, ',') === false || !array_filter($arr)) { + continue 2; + } + //当出现一边为空时改变操作符 + if ($arr[0] === '') { + $sym = $sym == 'RANGE' ? '<=' : '>'; + $arr = $arr[1]; + } elseif ($arr[1] === '') { + $sym = $sym == 'RANGE' ? '>=' : '<'; + $arr = $arr[0]; + } + $tableArr = explode('.', $k); + if (count($tableArr) > 1 && $tableArr[0] != $name && !in_array($tableArr[0], $alias) && !empty($this->model)) { + //修复关联模型下时间无法搜索的BUG + $relation = Loader::parseName($tableArr[0], 1, false); + $alias[$this->model->$relation()->getTable()] = $tableArr[0]; + } + $where[] = [$k, str_replace('RANGE', 'BETWEEN', $sym) . ' TIME', $arr]; + break; + case 'NULL': + case 'IS NULL': + case 'NOT NULL': + case 'IS NOT NULL': + $where[] = [$k, strtolower(str_replace('IS ', '', $sym))]; + break; + default: + break; + } + $index++; + } + if (!empty($this->model)) { + $this->model->alias($alias); + } + $model = $this->model; + $where = function ($query) use ($where, $alias, $bind, &$model) { + if (!empty($model)) { + $model->alias($alias); + $model->bind($bind); + } + foreach ($where as $k => $v) { + if (is_array($v)) { + call_user_func_array([$query, 'where'], $v); + } else { + $query->where($v); + } + } + }; + return [$where, $sort, $order, $offset, $limit, $page, $alias, $bind]; + } + + /** + * sms + */ + public function sms($ids = null) + { + if ($this->request->isPost()) { + $this->token(); + } + if(stripos($ids, ',') >= 1){ + $ids = explode(',',$ids); + }else{ + $ids = array($ids); + } + $row = $this->model->where('id','in',$ids)->select(); + + if (!$row) { + $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')); + } + } + + //短信info + $sms_config = array( + 'userid' => Config::get('site.sms_userid'), + 'account' => Config::get('site.sms_user'), + 'password' => Config::get('site.sms_passwd'), + ); + $sms = new Sms($sms_config); + $sms_info = $sms->getOverage(); + if(!$sms_info['status']){ + $this->error('短信平台配置错误,请检查配置!'.$sms_info['message']); + } + $this->view->assign("sms_info", $sms_info); + if ($this->request->isPost()) { + $content = $this->request->post("sms_content"); + if ($content && is_array($ids)) { + //var_dump($ids); + //halt($content); + $send_status = $sms->send($ids,$content); + if($send_status['code'] == 0){ + $this->error(__('发送失败!错误提示:'.$send_status['msg'], ''),'',$send_status); + }else{ + $this->success('发送成功!共计:'.$send_status['total'].'个,发送成功:'.$send_status['success'].'个','',$send_status); + } + //var_dump($send_status); + } + $this->error(__('短信内容为空', '')); + } + $this->view->assign("row", collection($row)->toarray()); + $this->view->assign("user_num", count($row)); + return $this->view->fetch(); + } } diff --git a/application/admin/view/user4s/inslog/index.html b/application/admin/view/user4s/inslog/index.html index 44099b5..9717e3a 100644 --- a/application/admin/view/user4s/inslog/index.html +++ b/application/admin/view/user4s/inslog/index.html @@ -11,6 +11,38 @@ {:__('Edit')} {:__('Delete')} + +
+ + + + +
+ +
+
+ +
+ +
+ +
+
+
+
+ + {:__('导出')} @@ -12,12 +12,75 @@
+ + + + \ No newline at end of file diff --git a/application/admin/view/user4s/user/expireins.html b/application/admin/view/user4s/user/expireins.html index fb66b93..a786540 100644 --- a/application/admin/view/user4s/user/expireins.html +++ b/application/admin/view/user4s/user/expireins.html @@ -12,13 +12,51 @@
+ + + + 统计时间: + + +
+ + + + +
+ +
+
+ +
+ +
+ +
+
+
+
+ + + + + + + + {:__('发送短信')}
{:__('Excel导入')} + {:__('发送短信')} + {:__('Delete')} - + {:__('发送短信')}