예제 #1
0
파일: search.php 프로젝트: OICTH1/mtpizza
 public function post_search()
 {
     $where = array();
     $result = DB::query('SELECT * FROM `tbl_item`');
     if (!empty($_POST['s_period']) && !empty($_POST['e_period'])) {
         $start = new DateTime($_POST['s_period']);
         $end = new DateTime($_POST['e_period']);
         $start = date('Y-m-d H:i:s', $start->getTimestamp());
         $end = date('Y-m-d H:i:s', $end->getTimestamp());
         $where[] = array(array('date', '>=', $start));
         $where[] = array(array('date', '<=', $end));
     }
     if (!empty($_POST['category'])) {
         $in = array();
         foreach ($_POST['category'] as $value) {
             $in[] = $value;
         }
         $where[] = array(array('category', 'in', $in));
     }
     if (!empty($_POST['item_name'])) {
         $where[] = array(array('item_name', 'like', "%" . $_POST['item_name'] . "%"));
     }
     //return $_POST;
     //return array(,new DateTime($_POST['e_period']));
     return Model_Earning::find('all', array('where' => $where));
 }
예제 #2
0
파일: order.php 프로젝트: OICTH1/website
 public function action_commit()
 {
     $user_id = \Session::get(self::SESSION_KEY_USER_ID);
     $user = Model_Member::find($user_id);
     $address = \Session::get(self::SESSION_KEY_ADDRESS);
     /*------make order----------------------------------------------------------*/
     $order = new Model_Order();
     $order->member_id = $user->id;
     $order->postalcode = $address['postalcode'];
     $order->destination = $address['address'] . $address['billname'] . $address['companyname'];
     $date = time();
     $order->order_date = date('Y-m-d H:i:s', $date);
     $order->print_flag = 0;
     $order->status = 0;
     $order->save();
     /*-----make orderline------------------------*/
     $cart = \Session::get(self::SESSION_KEY_CART);
     foreach ($cart['orders'] as $orderline) {
         $item_id = $orderline['item_id'];
         $item = Model_Item::find($item_id);
         $num = $orderline['quantity'];
         $size = $orderline['size'];
         $neworderline = new Model_Orderline();
         $neworderline->order_id = $order->id;
         $neworderline->item_id = $item_id;
         $neworderline->num = $num;
         $neworderline->size = $size;
         $neworderline->save();
         $earning = new Model_Earning();
         $earning->member_id = $user->id;
         $earning->item_id = $item_id;
         $earning->size = $size;
         switch ($size) {
             case 'S':
                 $unit_price = $neworderline->item->unit_price_s;
                 break;
             case 'M':
                 $unit_price = $neworderline->item->unit_price_m;
                 break;
             case 'L':
                 $unit_price = $neworderline->item->unit_price_m;
                 break;
             default:
                 $unit_price = $neworderline->item->unit_price;
                 break;
         }
         $earning->unit_price = $unit_price;
         $earning->num = $num;
         $earning->date = date('Y-m-d H:i:s', $date);
         $earning->category = $item->category;
         $earning->item_name = $item->name;
         $now = date('Ymd');
         $birthday = date('Ymd', strtotime($user->birthday));
         $earning->age = (int) floor(($now - $birthday) / 10000);
         $earning->save();
     }
     \Session::delete(self::SESSION_KEY_CART);
     return Response::redirect('index.php/message/commit');
 }
예제 #3
0
파일: cfm.php 프로젝트: OICTH1/mtpizza
 public function action_commit()
 {
     $orders = \Session::get(self::ORDER);
     if (count($orders['cart']) == 0) {
         Response::redirect('index.php/controlsystem/order/order');
     }
     $post = $_POST;
     $order = new Model_Order();
     $order->postalcode = $post['postalcode1'] . '-' . $post['postalcode2'];
     $order->destination = $post['address'];
     $order->print_flag = false;
     $order->status = false;
     $date = date("Y-m-d", time());
     $order->order_date = $date;
     $customer = Model_Member::query()->where('name', $post['customer_name'])->get_one();
     if (!empty($customer)) {
         $order->member_id = $customer->id;
     } else {
         $order->member_id = null;
     }
     $order->save();
     $order_id = $order->id;
     //make orderlines
     $orders = \Session::get(self::ORDER);
     foreach ($orders['cart'] as $orderline) {
         $item_id = $orderline['item_id'];
         $item = Model_Item::find($item_id);
         $num = $orderline['num'];
         $size = strtoupper($orderline['size']);
         $neworderline = new Model_Orderline();
         $neworderline->order_id = $order->id;
         $neworderline->item_id = $item_id;
         $neworderline->num = $num;
         $neworderline->size = $size;
         $neworderline->save();
         $earning = new Model_Earning();
         if (!empty($customer)) {
             $earning->member_id = $customer->id;
         } else {
             $earning->member_id = null;
         }
         $earning->item_id = $item_id;
         $earning->size = $size;
         switch ($size) {
             case 'S':
                 $unit_price = $neworderline->item->unit_price_s;
                 break;
             case 'M':
                 $unit_price = $neworderline->item->unit_price_m;
                 break;
             case 'L':
                 $unit_price = $neworderline->item->unit_price_m;
                 break;
             default:
                 $unit_price = $neworderline->item->unit_price;
                 break;
         }
         $earning->unit_price = $unit_price;
         $earning->num = $num;
         $earning->date = $date;
         $earning->category = $item->category;
         $earning->item_name = $item->name;
         $now = date('Ymd');
         if (!empty($customer)) {
             $birthday = date('Ymd', strtotime($customer->birthday));
             $earning->age = (int) floor(($now - $birthday) / 10000);
         } else {
             $birthday = null;
             $earning->age = 0;
         }
         $earning->save();
     }
     return View::forge('controlsystem/order/commit');
 }