Example #1
0
File: Bin.php Project: sete-pw/test
 function remove($params)
 {
     if (!isset($params['id_order_set'])) {
         return [ApiConstants::$STATUS => ApiConstants::$ERROR, ApiConstants::$ERROR_MESSAGE => ApiConstants::$ERROR_PARAMS_STRING, ApiConstants::$ERROR_CODE => ApiConstants::$ERROR_PARAMS_CODE];
     }
     if (\CO::AUTH()->user()) {
         // Корзина
         $bin = new \Application\Test\Model\Bin();
         // Заказ
         $orderSet = new \Application\Test\Model\OrderSet();
         //Место
         $set = new \Application\Test\Model\Set();
         // Проверяем, есть ли корзина у пользователя
         $binId = $bin->QUERY("SELECT id_order\nfrom orders\nwhere\n    user_id = ?\n    and\n    state = 'bin'\nlimit 1;\n            ", [['i', \CO::AUTH()->who()->ID()]]);
         if (count($binId)) {
             //Если есть, то забираем ее
             $bin->findBy_id_order($binId[0]['id_order']);
         } else {
             return [ApiConstants::$STATUS => ApiConstants::$SUCCESS, ApiConstants::$ERROR_MESSAGE => ApiConstants::$ERROR_NOT_FOUND_BIN_STRING, ApiConstants::$ERROR_CODE => ApiConstants::$ERROR_NOT_FOUND_BIN_CODE];
         }
         $orderSet->findBy_id_order_set($params['id_order_set']);
         if (count($orderSet->id_order_set) == 0) {
             return null;
         }
         if ($orderSet->order_id == $bin->id_order) {
             $set->findBy_id_set($orderSet->set_id);
             $orderSet->DELETE();
         } else {
             return [ApiConstants::$STATUS => ApiConstants::$ERROR, ApiConstants::$ERROR_MESSAGE => ApiConstants::$ERROR_AUTH__STRING, ApiConstants::$ERROR_CODE => ApiConstants::$ERROR_AUTH_CODE];
         }
         /*$this->QUERY("DELETE FROM order_sets
                             WHERE order_sets.state = ? and id_order_set in (
                                 SELECT id_order_set
                                 FROM (SELECT id_order_set FROM order_sets inner join orders on order_sets.order_id = orders.id_order
                                 WHERE user_id = ? and id_order_set = ?) as tmp
                             )
                            ",[
               ['s','add'],
               ['i',\CO::AUTH()->who()->ID()],
               ['i',$params['id_order_set']]
           ]);*/
         $countSets = $this->QUERY("SELECT price, COUNT(set_id) as count\n                                              FROM orders inner join order_sets\n                                              WHERE user_id = ? and orders.state = ? GROUP BY price\n                                              ", [['i', \CO::AUTH()->who()->ID()], ['s', 'bin']]);
         if (!isset($countSets[0]['count'])) {
             $this->QUERY("DELETE FROM orders WHERE user_id =? and state = ?", [['i', \CO::AUTH()->who()->ID()], ['s', 'bin']]);
         } else {
             $bin->price -= $this->QUERY("\nSELECT price\nFROM tables\nWHERE id_table = ?\n                ", [['i', $set->table_id]])[0]['price'];
         }
         $bin->UPDATE();
         /**
                                TODO:   Должен возвращать ошибку, если такой позиции нет!!!
         */
         return [ApiConstants::$STATUS => ApiConstants::$SUCCESS];
     }
     if (\CO::AUTH()->unknown()) {
         return [ApiConstants::$STATUS => ApiConstants::$ERROR, ApiConstants::$ERROR_MESSAGE => ApiConstants::$ERROR_AUTH__STRING, ApiConstants::$ERROR_CODE => ApiConstants::$ERROR_AUTH_CODE];
     }
 }
Example #2
0
 function edit($params)
 {
     if (!isset($params['id_order_set']) || !isset($params['id_set'])) {
         return [ApiConstants::$STATUS => ApiConstants::$ERROR, ApiConstants::$ERROR_MESSAGE => ApiConstants::$ERROR_PARAMS_STRING, ApiConstants::$ERROR_CODE => ApiConstants::$ERROR_PARAMS_CODE];
     }
     if (\CO::AUTH()->admin()) {
         $order = new \Application\Test\Model\OrderSet();
         $set = new \Application\Test\Model\Set();
         $orderId = $order->QUERY("\nSELECT *\nFROM order_sets\nINNER JOIN sets ON order_sets.set_id = sets.id_set\nWHERE state = 'pay'\nAND sort_id >0\nAND id_order_set = ?\n\t\t\t\t", [['i', $params['id_order_set']]]);
         $orderId2 = $order->QUERY("\nSELECT *\nFROM `sets`\nWHERE id_set = ? and id_set not in (SELECT set_id FROM order_sets WHERE state in ('pay','bin'))\n\t\t\t\t", [['i', $params['id_set']]]);
         if (count($orderId) == 0) {
             if (count($orderId2) == 0) {
                 return [ApiConstants::$STATUS => ApiConstants::$ERROR, ApiConstants::$ERROR_MESSAGE => ApiConstants::$ERROR_NOT_FOUND_RECORD_STRING, ApiConstants::$ERROR_CODE => ApiConstants::$ERROR_NOT_FOUND_RECORD_CODE];
             }
         } else {
             if (count($orderId2) == 0) {
                 return [ApiConstants::$STATUS => ApiConstants::$ERROR, ApiConstants::$ERROR_MESSAGE => ApiConstants::$ERROR_NOT_FOUND_SET_STRING, ApiConstants::$ERROR_CODE => ApiConstants::$ERROR_NOT_FOUND_SET_CODE];
             }
         }
         $orderId = $order->findBy_id_order_set($params['id_order_set']);
         $orderId->set_id = $params['id_set'];
         $orderId->UPDATE();
         return [ApiConstants::$STATUS => ApiConstants::$SUCCESS];
     }
     if (\CO::AUTH()->unknown() || \CO::AUTH()->user()) {
         return [ApiConstants::$STATUS => ApiConstants::$ERROR, ApiConstants::$ERROR_MESSAGE => ApiConstants::$ERROR_AUTH__STRING, ApiConstants::$ERROR_CODE => ApiConstants::$ERROR_AUTH_CODE];
     }
 }