public function index(Request $request) { $members = Member::where('status', 1)->orWhere('status', 2)->get(); $login = Login::where('remember_token', '=', $request->header('token'))->where('login_from', '=', $request->ip())->join('members', 'members.id', '=', 'logins.member_id')->where('logins.status', '=', '1')->first(); $server_status = MetaData::select('meta_value')->where('meta_key', 'server_status')->first(); if ($login->mtype == 3 || $login->mtype == 1) { foreach ($members as $member) { $accounts = Account::where('memberId', '=', $member->id)->get(); $amount = 0; foreach ($accounts as $account) { if ($account->type == 1) { $amount += $account->amount; } else { $amount -= $account->amount; } } $clientStocks = ClientStock::where('memberId', $member->id)->where('status', '<', 6)->get(); $pending = 0; if (count($clientStocks) > 0) { foreach ($clientStocks as $clientStock) { if ($clientStock->status == 1) { $pending += $clientStock->margin + $clientStock->commission; } elseif ($clientStock->status == 2 || $clientStock->status == 5) { $pending += $clientStock->margin + $clientStock->commission + $clientStock->holding_cost; } elseif ($clientStock->status == 4 || $clientStock->status == 6) { $pending += $clientStock->margin + $clientStock->commission + $clientStock->holding_cost + $clientStock->delivery_charge; } else { } } } $member->pending = $pending; $member->amount = $amount; $user[] = $member; } } else { //$user = $members; foreach ($members as $member) { if ($member->id == $login->member_id) { $accounts = Account::where('memberId', '=', $member->id)->get(); $amount = 0; foreach ($accounts as $account) { if ($account->type == 1) { $amount += $account->amount; } else { $amount -= $account->amount; } } $clientStocks = ClientStock::where('memberId', $member->id)->where('status', '<', 5)->get(); $pending = 0; if (count($clientStocks) > 0) { foreach ($clientStocks as $clientStock) { if ($clientStock->status == 1) { $pending += $clientStock->margin + $clientStock->commission; } elseif ($clientStock->status == 2 || $clientStock->status == 5) { $pending += $clientStock->margin + $clientStock->commission + $clientStock->holding_cost; } elseif ($clientStock->status == 4 || $clientStock->status == 6) { $pending += $clientStock->margin + $clientStock->commission + $clientStock->holding_cost + $clientStock->delivery_charge; } else { } } } $member->pending = $pending; $member->amount = $amount; } $user[] = $member; } } $returnData = array('status' => 'ok', 'members' => $user, 'user' => $login->member_id, 'server_status' => $server_status['meta_value'], 'code' => 200); return $returnData; }
public function ticket_generate() { $today_date = date("dm"); $today_time = date("Hs"); $rand = mt_rand(0, 9); $rand2 = mt_rand(0, 9); $ticket = $rand . $today_time . $rand2 . $today_date; $ticket_count = ClientStock::where('ticket', $ticket)->count(); if ($ticket_count > 0) { $this->ticket_generate(); } else { return $ticket; } }