示例#1
0
 /**
  * @author: lmkhang - skype
  * @date: 2016-02-03
  * Remove
  */
 public function remove($channel_id)
 {
     $channel_get = new \App\Channels();
     $channel = $channel_get->getChannelById($channel_id);
     if (!$channel) {
         //set Flash Message
         $this->setFlash('message', 'This channel is deactivated!');
         return redirect()->back()->with('message', 'This channel is deactivated!');
     }
     $channel_get = \App\Channels::find($channel_id);
     $channel_get->delete();
     //set Flash Message
     $this->setFlash('message', $channel->daily_channel_name . ' channel is removed');
     return redirect()->back()->with('message', $channel->daily_channel_name . ' channel is removed');
 }
示例#2
0
 /**
  * @author: lmkhang - skype
  * @date: 2016-02-01
  * Detail about income and expenditure of channel
  */
 public function detail($daily_channel_id)
 {
     //Check Status
     if ($this->_stop) {
         return Redirect::intended(url($this->_redirectTo));
     }
     //set Title for PAGE
     $this->_page_title = 'Detail of A Channel';
     //check owning channel
     $channel_get = new \App\Channels();
     $_channel = $channel_get->getUserIdByChannelId($daily_channel_id);
     if (!$_channel || $_channel['user_id'] != $this->_user_id) {
         //set Flash Message
         $this->setFlash('message', 'You do not own that channel!');
         return Redirect::intended($this->_page_url)->with('message', 'You do not own that channel!');
     }
     //get income and expenditure list
     //Get income-expenditure list
     $channel_in_ex_get = new \App\ChannelIncome();
     $number_pagination = \App\Config::where(['prefix' => 'site', 'name' => 'pagination', 'del_flg' => 1])->get()[0]['value'];
     $channel_in_ex = $channel_in_ex_get->getAllPaging(['channel_income.user_id' => $this->_user_id, 'channel_income.daily_channel_id' => $daily_channel_id], $number_pagination);
     return view('dashboard.channels.detail', ['user' => $this->_user, 'name' => $this->getName(), 'page_title' => $this->_page_title, 'active' => $this->_active, 'number_pagination' => $number_pagination, 'daily_channel_name' => $_channel['daily_channel_name'], 'channel_in_ex' => $channel_in_ex, 'in_expen_type' => config('constant.in_expen_type'), 'in_exp_action' => config('constant.in_exp_action')]);
 }
示例#3
0
文件: Stats.php 项目: lmkhang/mcntw
 /**
  * @author: lmkhang - skype
  * @date: 2016-01-18
  * Import data from CSV
  */
 public function import(Request $request)
 {
     $post = $request->all();
     $filter = $post['filter'];
     $channel_ids = isset($filter['channel_id']) ? $filter['channel_id'] : [];
     $path = config('constant.path.csv');
     $csv = Input::file('csv_file');
     //Setup validation
     $validator = Validator::make($post, ['csv_file' => 'required']);
     if ($validator->fails()) {
         //set Flash Message
         $this->setFlash('message', 'Please choose at least a csv file!');
         return redirect()->back()->with('message', 'Please choose at least a csv file!');
     }
     //Path
     $destinationPath = storage_path($path);
     if (!file_exists($destinationPath)) {
         mkdir($destinationPath, 777);
     }
     $original_name = $csv->getClientOriginalName();
     //Upload
     $csv->move($destinationPath, $csv->getClientOriginalName());
     $file = $destinationPath . '/' . $original_name;
     if (!file_exists($file)) {
         //set Flash Message
         $this->setFlash('message', 'Error saving the file');
         return redirect()->back()->with('message', 'Error saving the file');
     }
     //Read CSV
     $csvArray = ImportCSV2Array($file);
     //check input date
     $checkDate = false;
     $year = '';
     $month = '';
     if ($filter['month']) {
         try {
             list($month, $year) = explode('/', $filter['month']);
             $checkDate = checkdate($month, 1, $year);
         } catch (\Exception $ex) {
         }
     }
     $income = [];
     $channel_objects = [];
     foreach ($csvArray as $k => $row) {
         if ($checkDate && isset($row['date']) && $year . '-' . $month != date('Y-m', strtotime($row['date']))) {
             continue;
         }
         if ($channel_ids && isset($row['channel_id']) && count($channel_ids) > 0 && !in_array($row['channel_id'], $channel_ids)) {
             continue;
         }
         //get user id by channel id
         if (!isset($channel_objects[$row['channel_id']])) {
             $channel_get = new \App\Channels();
             $channel_objects[$row['channel_id']] = $channel_get->getChannelForImport($row['channel_id'], $row['date']);
         }
         $_channel = $channel_objects[$row['channel_id']];
         if ($_channel) {
             $_date = date('Y-m', strtotime($row['date']));
             try {
                 //New Payment
                 $earningDate = new \App\EarningDate();
                 $earningDate->daily_channel_id = isset($row['channel_id']) ? $row['channel_id'] : '';
                 $earningDate->daily_channel_username = isset($row['channel_username']) ? $row['channel_username'] : '';
                 $earningDate->parent_username = isset($row['parent_username']) ? $row['parent_username'] : '';
                 $earningDate->earning_date = isset($row['date']) ? $row['date'] : '';
                 $earningDate->estimated_earnings = isset($row['estimated_earnings']) ? $row['estimated_earnings'] : '';
                 $earningDate->impressions = isset($row['impressions']) ? $row['impressions'] : '';
                 $earningDate->save();
                 $money = $earningDate->estimated_earnings;
                 if (!isset($income[$earningDate->daily_channel_id][$_date]['info'])) {
                     $income[$earningDate->daily_channel_id][$_date]['info'] = ['user_id' => $_channel->user_id, 'type' => 1, 'date' => date('Y-m-d', strtotime($earningDate->earning_date))];
                     $income[$earningDate->daily_channel_id][$_date]['income'] = $money;
                     $income[$earningDate->daily_channel_id][$_date]['status'] = $_channel->status;
                 } else {
                     $income[$earningDate->daily_channel_id][$_date]['income'] = $income[$earningDate->daily_channel_id][$_date]['income'] + $money;
                 }
             } catch (\Exception $ex) {
             }
         }
     }
     $user_income = [];
     $income_valid = 1;
     //Insert Income
     if ($income && count($income) > 0) {
         foreach ($income as $channel_id => $dates) {
             foreach ($dates as $_date_ => $in) {
                 try {
                     $income_valid = 1;
                     //valid
                     if ($in['status'] == 4) {
                         //blocked
                         $income_valid = 2;
                         //invalid
                     }
                     $channel_income = new \App\ChannelIncome();
                     $channel_income->user_id = $in['info']['user_id'];
                     $channel_income->daily_channel_id = $channel_id;
                     $_amount = $this->net_amount($in['income']);
                     //                    $channel_income->amount = $in['income'];
                     $channel_income->amount = $_amount['amount'];
                     $channel_income->original_amount = $_amount['original_amount'];
                     $channel_income->commission = $_amount['commission'];
                     $channel_income->tax_from_daily = $_amount['tax_from_daily'];
                     $channel_income->status = $in['status'];
                     $channel_income->type = $in['info']['type'];
                     $channel_income->date = $_date_ . '-01';
                     $channel_income->save();
                     //update income
                     if (!isset($user_income[$channel_income->user_id][$_date_][$income_valid])) {
                         $user_income[$channel_income->user_id][$_date_][$income_valid]['income'] = 0;
                         $user_income[$channel_income->user_id][$_date_][$income_valid]['date'] = $_date_;
                         $user_income[$channel_income->user_id][$_date_][$income_valid]['type'] = $income_valid;
                     }
                     $user_income[$channel_income->user_id][$_date_][$income_valid]['income'] += $in['income'];
                 } catch (\Exception $ex) {
                 }
             }
         }
     }
     //Update $ for user
     //1: valid, 2: invalid
     foreach ($user_income as $user_id => $date) {
         foreach ($date as $_date_ => $income_valid) {
             foreach ($income_valid as $_type => $r) {
                 if ($r['income'] > 0) {
                     try {
                         $this->historyInExp($user_id, $r['income'], 'Processed by System', 1, 1, ['is_import' => 1, 'date' => $r['date']], $r['type']);
                     } catch (\Exception $ex) {
                     }
                 }
             }
         }
     }
     //delete file
     unlink($file);
     //set Flash Message
     $this->setFlash('message', 'Imported data');
     return redirect()->back()->with('message', 'Imported data');
 }