db ->where('id', $data['member_id']) ->limit(1) ->get('members'); if ($q->num_rows() > 0) { $out = $q->result_array(); $out['current_balance'] = $out[0]['balance']; //pay attention to row 1 $out['new_message'] = 0; $out['active_task'] = 0; $out['active_pass_due'] = 0; $out['total_jobs'] = 0; } else { return false; } $y = $this->getNewMessageCount($data['member_id']); $out['new_message'] = $y['new_message']; $y = $this->getEscrowBalance($data['member_id']); $out['escrow_balance'] = $y['escrow_balance'] + $y['escrow_c_offer']; $y = $this->getPeningOfferCount($data['member_id']); $out['active_offers_count'] = $y['active_offers_count']; $z = $this->getOfferInterestCount($data['member_id']); $out["offers_interest_count"] = $z['offers_interest_count']; $k = $this->getAccountDetail($data['member_id']); $out["description"] = $k['description']; return $out; } public function getNewMessageCount($member_id) { $out = array(); $out['new_message'] =0; $mysql = " SELECT count(id) AS new_message FROM members_messages WHERE member_id =$member_id AND reply IS NULL AND added > now() +'-2 day(s)' "; $q = $this->db->query($mysql); if ($q->num_rows() > 0) { $out['new_message'] = $q->row()->new_message; } return $out; } public function getEscrowBalance($member_id) { $out = array(); $out['escrow_balance'] = $out['escrow_c_offer'] = 0; $mysql = "SELECT sum(jb.price) AS escrow_offer FROM members_jobs_offer j LEFT JOIN members_jobs jb ON jb.id=j.job_id WHERE j.status = 1 AND client_id> 0 AND j.member_id = " . $member_id; $q = $this->db->query($mysql); if ($q->num_rows() > 0) { $out['escrow_balance'] = $q->row()->escrow_offer; } $mysql = "SELECT sum(j.price) AS escrow_c_offer FROM members_jobs_contract j WHERE j.status IN(1,2) AND j.member_id = " . $member_id; $q2 = $this->db->query($mysql); if ($q2->num_rows() > 0) { $out['escrow_c_offer'] = $q2->row()->escrow_c_offer; } return $out; //['escrow_c_offer'] + $out['escrow_balance']; } public function getAccountDetail($member_id) { $out['description'] = ""; $mysql = "SELECT * FROM members_detail WHERE member_id = " . $member_id; $q = $this->db->query($mysql); if ($q->num_rows() > 0) { $out['description'] = $q->row()->description; } return $out; } public function getOfferInterestCount($member_id) { $out['active_offers_count'] = 0; $mysql = " SELECT count(mi.id) AS offers_interest_count" . " FROM members_offer_interest mi " . " LEFT JOIN members_jobs_offer jo ON jo.id=mi.offer_id " . " WHERE mi.status=1 AND jo.expire> now() " . " AND mi.member_id = " . $member_id; $q = $this->db->query($mysql); if ($q->num_rows() > 0) { $out['offers_interest_count'] = $q->row()->offers_interest_count; } return $out; } /* select * from members_offer_interest order by id desc; id | member_id | offer_id | status | added ----+-----------+----------+--------+---------------------------- 56 | 18 | 71 | 1 | 2017-06-22 09:36:25.576627 55 | 23 | 71 | 1 | 2017-06-22 09:36:08.856582 */ public function getPeningOfferCount($member_id) { $out['active_offers_count'] = 0; $mysql = " SELECT count(id) AS active_offers_count FROM members_jobs_offer WHERE status=1 AND expire> now() AND member_id = " . $member_id; $q = $this->db->query($mysql); if ($q->num_rows() > 0) { $out['active_offers_count'] = $q->row()->active_offers_count; } return $out; } }