'--', 'nickname' => '--', 'avatar' => [ 'url' => base_url() . 'addons/food/img/avatar.png' ] ]; } return User::get($data['user_id']); } /** * 关联订单 */ public function order() { return $this->belongsTo('app\\common\\model\\food\\Order','order_id'); } /** * 关联门店 */ public function shop() { return $this->belongsTo('app\\common\\model\\food\\Shop','shop_id'); } /** * 显示状态 */ public function getIsShowAttr($value) { $status = [0 => '隐藏', 1 => '显示']; return ['text' => $status[$value], 'value' => $value]; } /** * 获取列表 */ public function getList($user_id = 0, $shop_id = 0, $is_show = -1) { // 筛选条件 $filter = []; $user_id > 0 && $filter['user_id'] = $user_id; $shop_id > 0 && $filter['shop_id'] = $shop_id; $is_show > -1 && $filter['is_show'] = $is_show; $list = $this->with(['order','shop']) ->where($filter) ->order(['comment_id' => 'desc']) ->paginate(['list_rows'=>15,'query' => request()->param()]); return $list; } /** * 根据条件统计数量 */ public static function getCount($shop_id = 0) { $self = new static; // 筛选条件 $filter = []; $shop_id > 0 && $filter['shop_id'] = $shop_id; $count = array(); //全部 $count['all'] = self::where($filter)->count(); //今天 $star = strtotime(date("Y-m-d"),time()); $count['today'] = self::where('create_time','>',$star)->where($filter)->count(); //昨天 $star = strtotime("-1 day"); $end = strtotime(date("Y-m-d"),time()); $count['today2'] = self::where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->count(); //前天 $star = strtotime("-2 day"); $end = strtotime("-1 day"); $coun['today3'] = self::where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->count(); //-4天 $star = strtotime("-3 day"); $end = strtotime("-2 day"); $count['today4'] = self::where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->count(); //-5天 $star = strtotime("-4 day"); $end = strtotime("-3 day"); $count['today5'] = self::where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->count(); //-6天 $star = strtotime("-5 day"); $end = strtotime("-4 day"); $count['today6'] = self::where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->count(); //-7天 $star = strtotime("-6 day"); $end = strtotime("-5 day"); $count['today7'] = self::where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->count(); //本月统计 $end = mktime(0,0,0,date('m'),1,date('y')); $count['month'] = self::where('create_time','>',$end)->where($filter)->count();//全部数量 //上月统计 $star = mktime(0,0,0,date('m')-1,1,date('y')); $count['month2'] = self::where('create_time','>',$star)->where('create_time','<',$end)->where($filter)->count();//全部数量 return $count; } /** * 详情 */ public static function detail($id) { return self::with(['order','shop'])->find($id); } /** * 编辑 */ public function edit(array $data) { return $this->save($data) !== false; } /** * 显示状态编辑 */ public function status() { $this->is_show['value']==0 ? $this->is_show = 1 : $this->is_show = 0; return $this->save() !== false; } /** * 评分计算 */ public function score($shop_id = 0) { $where = []; $shop_id > 0 && $where['shop_id'] = $shop_id; $serve = $this->where($where)->avg('serve'); $speed = $this->where($where)->avg('speed'); $flavor = $this->where($where)->avg('flavor'); $ambient = $this->where($where)->avg('ambient'); $serve <=0 && $serve = 5; $speed <=0 && $speed = 5; $flavor <=0 && $flavor = 5; $ambient <=0 && $ambient = 5; $all = ($serve+$speed+$flavor+$ambient)/4; return [ 'all' => round($all,2), 'serve' => round($serve,2), 'speed' => round($speed,2), 'flavor' => round($flavor,2), 'ambient' => round($ambient,2) ]; } }