當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Book::get_books_info方法代碼示例

本文整理匯總了PHP中app\Book::get_books_info方法的典型用法代碼示例。如果您正苦於以下問題:PHP Book::get_books_info方法的具體用法?PHP Book::get_books_info怎麽用?PHP Book::get_books_info使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在app\Book的用法示例。


在下文中一共展示了Book::get_books_info方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: get_operations

 /**
  * @param $personid
  * @return mixed
  */
 public static function get_operations($personid)
 {
     $books = array();
     $books_info = Book::get_books_info(Auth::user()->id);
     $books_left = array();
     $books_distr = array();
     $used = 0;
     $laxmi = 0;
     $os = DB::table('operations AS o')->leftJoin('books AS b', 'o.book_id', '=', 'b.id')->where('o.person_id', $personid)->orderBy('o.custom_date', 'asc')->orderBy('o.operation_type', 'asc')->orderBy('o.datetime', 'asc')->select('o.datetime', 'o.custom_date', 'o.person_id', 'o.book_id', 'o.price', 'o.quantity', 'o.operation_type', 'o.created_at', 'o.updated_at', 'o.laxmi', 'o.description', 'b.name')->get();
     $prevcase = 0;
     $prevop = 0;
     $lxm = 0;
     $gain = 0;
     $debt = 0;
     $oss = [];
     $os[] = 1;
     foreach ($os as $o) {
         if ($prevcase == 10 && (gettype($o) != 'object' || ($o->operation_type != 10 || $o->operation_type == 10 && $prevop != $o->datetime))) {
             foreach ($books as $k => $v) {
                 if (!isset($books_distr[$k])) {
                     $books_distr[$k] = 0;
                 }
                 foreach (array_slice($v, 1) as $b) {
                     $lxm += $b[0] * $b[1];
                     $gain += $b[0] * ($b[1] > $books_info[$k]->price_buy ? $b[1] - $books_info[$k]->price_buy : 0);
                     $books_distr[$k] += $b[0];
                 }
                 unset($books[$k]);
             }
             $books = $books_left;
             $books_left = [];
             $oss[] = array('type' => 'info', 'text' => 'Распространенные книги:', 'o' => '');
             $total_books = 0;
             $points = 0;
             $book_types = ['Махабиги' => 0, 'Биги' => 0, 'Средние' => 0, 'Маленькие' => 0];
             foreach ($books_distr as $k => $v) {
                 $oss[] = array('type' => 'info', 'text' => $books_info[$k]->name, 'o' => $v);
                 switch ($books_info[$k]->book_type) {
                     case 1:
                         $points += 2 * $v;
                         $book_types['Махабиги'] += $v;
                         $total_books += $v;
                         break;
                     case 2:
                         $points += 1 * $v;
                         $book_types['Биги'] += $v;
                         $total_books += $v;
                         break;
                     case 3:
                         $points += 0.5 * $v;
                         $book_types['Средние'] += $v;
                         $total_books += $v;
                         break;
                     case 4:
                         $points += 0.25 * $v;
                         $book_types['Маленькие'] += $v;
                         $total_books += $v;
                         break;
                 }
             }
             $books_distr = [];
             $oss[] = array('type' => 'info', 'text' => 'Всего распространено книг', 'o' => $total_books);
             foreach ($book_types as $k => $v) {
                 $oss[] = array('type' => 'info', 'text' => $k, 'o' => $v);
             }
             $oss[] = array('type' => 'info', 'text' => 'Всего очков', 'o' => $points);
             $oss[] = array('type' => 'info', 'text' => 'Распространено на', 'o' => $lxm);
             $oss[] = array('type' => 'info', 'text' => 'Прибыль', 'o' => $gain);
             $oss[] = array('type' => 'info', 'text' => 'Получено', 'o' => $laxmi);
             if ($laxmi - $debt > $lxm) {
                 $oss[] = array('type' => 'info', 'text' => 'Сверхпожертвование', 'o' => $laxmi - $debt - $lxm);
                 $debt = 0;
             } elseif ($laxmi - $debt < $lxm) {
                 $debt -= $laxmi - $lxm;
                 $oss[] = array('type' => 'info', 'text' => 'Долг', 'o' => $debt);
             } else {
                 $debt = 0;
             }
             $lxm = 0;
             $laxmi = 0;
             $gain = 0;
         }
         if (gettype($o) != 'object') {
             break;
         }
         if ($prevop != $o->datetime || !$prevop) {
             $oss[] = array('type' => 'operation', 'o' => $o);
         }
         $prevcase = $o->operation_type;
         $prevop = $o->datetime;
         switch ($o->operation_type) {
             case 10:
                 if (!$o->book_id) {
                 } elseif (isset($books[$o->book_id])) {
                     $used = $books[$o->book_id][0] - $o->quantity;
                     if ($used < 0) {
//.........這裏部分代碼省略.........
開發者ID:vladimirgolovanov,項目名稱:brihad-mridanga,代碼行數:101,代碼來源:Operation.php


注:本文中的app\Book::get_books_info方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。