/** * @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; }