| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
- /**
- * 信息服务
- * @author wesmielr
- */
- namespace app\index\service;
- use think\Db;
- class MessageService
- {
- /**
- * 获取咨询留言列表
- * @param $params 参数
- * @param int $pageSize 记录大小
- * @param string $field 返回字段
- * @return $this
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public static function getList($params, $pageSize=10, $field=''){
- $field = $field? $field : 'id,jm_id,jm_title,name,address,ip,content,reply';
- return Db::name('message')
- ->where(function($query) use ($params){
- $type = isset($params['type'])? $params['type'] : 0;
- if($type){
- $query->where('type', $type);
- }
- })
- ->field($field)
- ->order('create_time desc')
- ->limit($pageSize)
- ->select()
- ->each(function($item, $k){
- if(isset($item['name'])){
- $item['name'] = $item['name']? formatName($item['name']) : '游客';
- }
- $item['address'] = isset($item['address'])? $item['address'] : '';
- $item['address'] = $item['address']? $item['address'] : (isset($item['ip'])? IpService::getAddress($item['ip']) : '未知地区');
- return $item;
- });
- }
- /**
- * 获取今天提交次数
- * @param $where
- */
- public static function getTodyCount($where){
- $todaytime = strtotime(date('Y-m-d'));
- return Db::name('message')
- ->where($where)
- ->where('create_time','gt',$todaytime)
- ->count();
- }
- /**
- * 获取本周提交次数
- * @param $where
- */
- public static function getWeekCount($where){
- // 当前日期
- $sdefaultDate = date("Y-m-d");
- // $first =1 表示每周星期一为开始日期 0表示每周日为开始日期
- $first=1;
- // 获取当前周的第几天 周日是0 周一到周六是 1 - 6
- $w = date('w', strtotime($sdefaultDate));
- // 获取本周开始日期,如果$w是0,则表示周日,减去 6 天
- $week_start=strtotime("$sdefaultDate -".($w ? $w - $first : 6).' days');
- return Db::name('message')
- ->where($where)
- ->where('create_time','gt',$week_start)
- ->count();
- }
- }
|