private function _tradeDataInsertDb($v) { $user_trade_list = new UserTradeList(); $user_trade_info = $user_trade_list->where('uid', $v['uid'])->where('gid', $v['gid'])->where('stock_code', $v['stock_code'])->first(); if ($user_trade_info) { $user_trade_info = $user_trade_info->toArray(); } if (isset($user_trade_info['id'])) { $user_trade_list->where('id', $user_trade_info['id'])->update(['stock_amount' => $this->_reCalculateStockAmount($user_trade_info, $v['order_amount']), 'enable_amount' => $this->_reCalculateStockEnableAmount($user_trade_info, $v['enable_amount']), 'cost_price' => $this->_reCalculateAveragePrice($user_trade_info, $v['order_amount'], $v['order_price'])]); $user_trade_list->id = $user_trade_info['id']; } else { $user_trade_list->uid = $v['uid']; $user_trade_list->gid = $v['gid']; $user_trade_list->stock_code = $v['stock_code']; $user_trade_list->stock_amount = $this->_reCalculateStockAmount($user_trade_info, $v['order_amount']); $user_trade_list->enable_amount = $this->_reCalculateStockEnableAmount($user_trade_info, $v['enable_amount']); $user_trade_list->cost_price = $this->_reCalculateAveragePrice($user_trade_info, $v['order_amount'], $v['order_price']); $user_trade_list->save(); } }
/** * Execute the console command. * * @return mixed */ public function fire() { if (!$this->_checkTime()) { $this->info('update time is limited'); return false; } $user_trade_list = new UserTradeList(); $i = 0; $step = 20; while ($data = $user_trade_list->orderBy('id', 'DESC')->offset($i)->limit(20)->get()->toArray()) { if (!$data) { break; } foreach ($data as $k => $v) { $user_trade_list->where('id', $v['id'])->update(['last_amount' => $v['stock_amount'], 'last_price' => $v['cost_price']]); } $i += $step; } $this->info('update close amount price task finish...'); }