[], ]; } public function queryWhere() { // 指定用户 $propertyHeadId = (int)PropertyHead::where('user_id',$this->userId)->value('id'); $where[] = ['b.property_head_id', '=', $propertyHeadId]; if (isset($this->params['start_time']) && !empty($this->params['start_time'])) { $monthStart = strtotime(date("Y-m-01",strtotime($this->params['start_time']))); $monthEnd = strtotime(date("Y-m-t 23:59:59",strtotime($this->params['start_time']))); $where[] = ['a.appointment_time', 'between', [$monthStart, $monthEnd]]; } $where[] = ['a.service_status', '=', 3]; return $where; } /** * @notes 获取列表 * @return array */ public function lists(): array { $lists = GroupServiceWork::alias('a') ->leftJoin('group_order b','a.group_order_id=b.id') ->leftJoin('user c','a.user_id=c.id') ->field('a.id,a.work_sn,a.title,a.appointment_time,a.work_total,a.work_amount,c.avatar as image') ->where($this->queryWhere()) ->limit($this->limitOffset, $this->limitLength) ->order('a.appointment_time', 'desc') ->select() ->toArray(); foreach($lists as &$item) { $item['work_total'] = bcsub($item['work_total'], $item['work_amount'], 2); $item['appointment_time'] = date('n月j日', strtotime($item['appointment_time'])); } return $lists; } /** * @notes 获取数量 * @return int */ public function count(): int { return GroupServiceWork::alias('a') ->leftJoin('group_order b','a.group_order_id=b.id') ->where($this->queryWhere()) ->count(); } /** * @notes 统计工单总收益 * @return float */ public function extend(): array { $totalWorkTotal = GroupServiceWork::alias('a') ->leftJoin('group_order b','a.group_order_id=b.id') ->where($this->searchWhere) ->where($this->queryWhere()) ->sum('a.work_total'); $totalWorkAmount = GroupServiceWork::alias('a') ->leftJoin('group_order b','a.group_order_id=b.id') ->where($this->searchWhere) ->where($this->queryWhere()) ->sum('a.work_amount'); return ["total_amount" => bcsub($totalWorkTotal, $totalWorkAmount, 2)]; } }