/** * @author: lmkhang - skype * @date: 2016-01-09 * DASHBOARD HOME */ public function index() { //Check Status if ($this->_stop) { return Redirect::intended(url($this->_redirectTo)); } //set Title for PAGE $this->_page_title = 'Home'; //Get income-expenditure list $user_in_ex_get = new \App\UserIncomeExpenditure(); $number_pagination = \App\Config::where(['prefix' => 'site', 'name' => 'pagination', 'del_flg' => 1])->get()[0]['value']; $user_in_ex = $user_in_ex_get->getAllPaging(['user_id' => $this->_user_id, 'status' => 1], $number_pagination); //get money $user_stats_get = new \App\UserStats(); $user_stats = $user_stats_get->getAccount($this->_user_id); //min PAY $minpay = \App\Config::where(['prefix' => 'payment', 'name' => 'minpay', 'del_flg' => 1])->get()[0]['value']; return view('dashboard.home.index', ['user' => $this->_user, 'name' => $this->getName(), 'page_title' => $this->_page_title, 'active' => $this->_active, 'user_stats' => $user_stats, 'number_pagination' => $number_pagination, 'user_in_ex' => $user_in_ex, 'in_expen_type' => config('constant.in_expen_type'), 'in_exp_action' => config('constant.in_exp_action'), 'minpay' => $minpay]); }
/** * @author: lmkhang - skype * @date: 2016-01-15 * Adjust income of members */ public function member_adjust(Request $request) { if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { $post = $request->all(); $post = $this->trim_all($post); $rs = ['error' => true]; if ($post['user_id'] && $post['amount'] && $post['amount'] > 0 && $post['type']) { //process data $rs['error'] = $this->historyInExp($post['user_id'], $post['amount'], $post['reason'], $post['type'], 2, $post) ? false : true; $user_stats_get = new \App\UserStats(); $user_stats = $user_stats_get->getAccount($post['user_id']); $rs['user_id'] = $user_stats['user_id']; $rs['total'] = $user_stats['total']; $rs['last_income'] = date('Y-m-d H:i:s'); } header('Content-Type: application/json'); echo json_encode($rs); exit; } }
/** * @author: lmkhang - skype * @date: 2016-02-01 * $type: 1=> Plus; 2=> Minus * $action: 1=> System; 2=>People; $valid_type: 1=> valid, 2=> invalid */ protected function historyInExp($user_id, $amount, $reason = '', $type = 1, $action = 1, $post = [], $valid_type = 1) { $rs = true; $process_amount = ['currency_string' => '$', 'original_amount' => $amount, 'amount' => $amount]; //get some info //min PAY $minpay = \App\Config::where(['prefix' => 'payment', 'name' => 'minpay', 'del_flg' => 1])->get()[0]['value']; //initial USERSTATS $user_stats_get = new \App\UserStats(); $user_stats = $user_stats_get->getAccount($user_id); //if choose payment if (count($post) > 0 && isset($post['is_payment']) && $post['is_payment'] == 1 && $type == 2) { if ($user_stats->total < $minpay || $post['amount'] < $minpay) { $rs = false; return $rs; } //no payment information $payment_user_get = new \App\Payment(); $user_payment = $payment_user_get->getPaymentInfomation($user_id); if (!$user_payment) { $rs = false; return $rs; } $process_amount = $this->payment_amount($amount, $user_payment['payment_method']); } //without payment, only withdraw if ($type == 2 && $user_stats->total < $post['amount']) { $rs = false; return $rs; } //if choose import from csv if (count($post) > 0 && isset($post['is_import']) && $post['is_import'] == 1 && $type == 1) { $process_amount = $this->net_amount($amount); } $date = isset($post['date']) ? date('Y-m-d H:i:s', strtotime($post['date'])) : date('Y-m-d H:i:s'); //insert history $user_history = new \App\UserIncomeExpenditure(); $user_history->user_id = $user_id; $user_history->tax_from_daily = isset($process_amount['tax_from_daily']) ? $process_amount['tax_from_daily'] : ''; $user_history->commission = isset($process_amount['commission']) ? $process_amount['commission'] : ''; $user_history->currency = isset($process_amount['currency']) ? $process_amount['currency'] : ''; $user_history->tax_pay_bank = isset($process_amount['tax_pay_bank']) ? $process_amount['tax_pay_bank'] : ''; $user_history->payment_method = isset($process_amount['payment_method']) ? $process_amount['payment_method'] : ''; $user_history->original_amount = isset($process_amount['original_amount']) ? $process_amount['original_amount'] : ''; $user_history->currency_string = isset($process_amount['currency_string']) ? $process_amount['currency_string'] : ''; $user_history->status = $valid_type; $user_history->type = $type; $user_history->date = $date; $user_history->action = $action; $user_history->reason = str_replace(array('{mm-YYYY}'), array(date('F Y', strtotime($date))), $reason); if ($type == 1) { //increase $user_history->amount = $process_amount['amount']; if ($valid_type == 1) { $user_stats->total = floatval($user_stats->total + $process_amount['amount']); } else { if ($valid_type == 2) { $user_stats->loss_total = floatval($user_stats->loss_total + $process_amount['amount']); } } } else { if ($type == 2) { //withdraw, payment $_amount = $process_amount['original_amount']; $user_history->amount = $_amount; if ($valid_type == 1) { $user_stats->total = floatval($user_stats->total - $_amount); } //if choose payment if (count($post) > 0 && isset($post['is_payment']) && $post['is_payment'] == 1 && $type == 2) { $user_history->is_payment = 1; $this->sendmailPayment($user_id, $process_amount['string_amount'], $process_amount['string_original_amount'], $process_amount['net_amount_word_info'], $date, $reason); } } } $user_history->save(); $user_stats->save(); return $rs; }
/** * @author: lmkhang - skype * @date: 2015-12-30 * Register USER */ public function create_registration(Request $request) { //Check isLogged if ($this->isLogged()) { die; } //Post $post = $request->all(); $register = $post['register']; //Trim $register = $this->trim_all($register); //Setup validation $validator = Validator::make($register, ['username' => array('required', 'regex: /^\\w{5,50}$/'), 'pin_code' => 'required|min:6|max:6|digits:6', 'email' => 'required|email|min:5|max:100', 'password' => 'required|min:5|max:50', 'repeat_password' => 'required|same:password', 'first_name' => 'required|min:2|max:50', 'last_name' => 'required|min:2|max:50']); // Optionally customize this version using new ->after() /*$validator->after(function() use ($validator) { // Do more validation $validator->errors()->add('field', 'new error'); });*/ //Checking if ($validator->fails()) { // The given data did not pass validation // $session = new \Symfony\Component\HttpFoundation\Session\Session(); // $session->set('messages', $validator->errors()); //set Flash Message $this->setFlash('message', 'Errors!'); return redirect()->back(); } //Check some existed attributes $registration_system = config('constant.registration'); $msg_attributes = $this->checkUserAttributes($register, $registration_system['site']); if ($msg_attributes) { //set Flash Message $this->setFlash('message', 'Errors!'); return redirect()->back(); } //Success unset($register['repeat_password']); $match = new Libraries\Math(); $register['refer'] = $match->to_base(rand(10, 30) . substr(time(), 5, 10) . rand(10, 30), 62) . $match->to_base(rand(100, 300) . substr(time(), 5, 10) . rand(100, 300), 62) . $match->to_base(rand(100, 300) . substr(time(), 5, 10) . rand(100, 300), 62); $salt = \App\Config::where(['prefix' => 'site', 'name' => 'salt', 'del_flg' => 1])->get()[0]['value']; $user = new \App\User(); $user->refer = $register['refer']; $user->from_refer = $register['from_refer']; $user->password = $this->encryptString($register['password'], $salt); $user->username = $register['username']; $user->pin_code = $this->encryptString($register['pin_code'], $salt); $user->active_code = $match->to_base(rand(10, 30) . substr(time(), 5, 10) . rand(10, 30), 62) . $this->encryptString(rand(111, 999) . rand(1111, 9999), $salt) . $this->encryptString(time(), $salt) . $match->to_base(rand(10, 30) . substr(time(), 5, 10) . rand(10, 30), 62); $user->first_name = $register['first_name']; $user->last_name = $register['last_name']; $user->email = $register['email']; $user->save(); //Insert User Stats $user_stats = new \App\UserStats(); $user_stats->user_id = $user->user_id; $user_stats->total = 0; $user_stats->save(); //Send mail $this->_sendmail_registration($user); //set Flash Message $this->setFlash('message', 'Please confirm from email ' . $register['email'] . '!'); return Redirect::intended('/')->with('message', 'Please confirm from email ' . $register['email'] . '!'); }
/** * @author: lmkhang - skype * @date: 2016-05-02 * Update all Amount: Gross, Net, Blocked, Hold */ public function update() { //Get Amount $user_stats_get = new \App\UserStats(); #Gross Amount #Net Amount $net_amount = $user_stats_get->getAmountAllAccount([], 'total'); #Pay Amount $pay_amount = $user_stats_get->getPayAmount(); #Blocked Amount $blocked_amount = $user_stats_get->getAmountAllAccount([], 'loss_total'); #Hold Amount $hold_amount = $user_stats_get->getHoldAmount(); #Paid Amount $paid_amount = $user_stats_get->getPaidAmount(); //Update Amount $home_get = new \App\Home(); #Gross Amount #Net Amount $net_amount_get = $home_get->getKey(['prefix' => 'stats', 'name' => 'net_mount', 'del_flg' => 1]); $net_amount_get->value = $net_amount; $net_amount_get->save(); #Pay Amount $pay_amount_get = $home_get->getKey(['prefix' => 'stats', 'name' => 'pay_amount', 'del_flg' => 1]); $pay_amount_get->value = $pay_amount; $pay_amount_get->save(); #Blocked Amount $blocked_amount_get = $home_get->getKey(['prefix' => 'stats', 'name' => 'blocked_mount', 'del_flg' => 1]); $blocked_amount_get->value = $blocked_amount; $blocked_amount_get->save(); #Hold Amount $hold_amount_get = $home_get->getKey(['prefix' => 'stats', 'name' => 'hold_amount', 'del_flg' => 1]); $hold_amount_get->value = $hold_amount; $hold_amount_get->save(); #Paid Amount $paid_amount_get = $home_get->getKey(['prefix' => 'stats', 'name' => 'paid_amount', 'del_flg' => 1]); $paid_amount_get->value = $paid_amount; $paid_amount_get->save(); //set Flash Message $this->setFlash('message', 'Updated successfully!'); return redirect()->back()->with('message', 'Updated successfully!'); }