Esempio n. 1
0
 public static function get($ka = null)
 {
     if (is_string($ka)) {
         $keys = array($ka);
     } elseif (is_array($ka)) {
         $keys = $ka;
     } elseif (empty($ka)) {
         // return all key-values
         $ret = array();
         $arr = Pdb::fetchAll('*', self::$table);
         foreach ($arr as $entry) {
             $ret[$entry['key']] = $entry['value'];
         }
         return $ret;
     }
     $ret = array();
     foreach ($keys as $key) {
         $value = Pdb::fetchRow('`value`', self::$table, array('`key`=?' => $key));
         if ($value === false) {
             throw new Exception("there is no key: {$key}");
         }
         $ret[$key] = $value;
     }
     return count($ret) === 1 ? reset($ret) : $ret;
 }
Esempio n. 2
0
function exec_sql($sql = '')
{
    if (ON_SAE && preg_match('/USE|CREATE\\sDATABASE/', $sql)) {
        return;
    }
    Pdb::exec($sql);
}
Esempio n. 3
0
function exec_sql($sql = '')
{
    if (ON_SAE && preg_match('/USE|CREATE\\sDATABASE/', $sql)) {
        return;
    }
    Pdb::exec($sql);
    $GLOBALS['histories'][] = $sql;
}
Esempio n. 4
0
 public static function add($info)
 {
     $order_id = $info['order'];
     $images = $info['images'];
     foreach ($images as $i) {
         Pdb::insert(array('image' => $i, '`order`' => $order_id), self::$table);
     }
 }
Esempio n. 5
0
 public function listAdmin($conds = array())
 {
     extract(self::defaultConds($conds));
     $conds = array('type=?' => 'Admin');
     $tail = "LIMIT {$limit} OFFSET {$offset}";
     return safe_array_map(function ($info) {
         return new Admin($info);
     }, Pdb::fetchAll('*', User::$table, $conds, array(), $tail));
 }
Esempio n. 6
0
 public function edit($key_or_array, $value = null)
 {
     if ($value !== null) {
         // give by key => value
         $arr = array($key_or_array, $value);
     } else {
         $arr = $key_or_array;
     }
     Pdb::update($arr, self::$table, $this->selfCond());
 }
Esempio n. 7
0
 public function createFromCart(Cart $cart)
 {
     // but big order need customer or something else??
     Pdb::insert(array('id=id' => null), self::$table);
     $id = Pdb::lastInsertId();
     foreach ($cart->orders() as $order) {
         Pdb::insert(array('big' => $id, 'small' => $order->id), 'big_to_small_order');
         $order->submit();
     }
 }
Esempio n. 8
0
 public function update($key_or_array, $value = null)
 {
     if ($value !== null) {
         // given by key => value
         $arr = array($key_or_array => $value);
     } else {
         $arr = $key_or_array;
     }
     $self = get_called_class();
     Pdb::update($arr, $self::$table, $this->selfCond());
     // why we need that? that doesn't make any sense
     $this->info = $this->info();
     // refresh data
 }
Esempio n. 9
0
 public function history($conds = array())
 {
     extract($conds);
     $tail = "LIMIT {$limit} OFFSET {$offset}";
     extract($this->buildHistoryArg($conds));
     if (!isset($sort) || empty($sort)) {
         $sort = 'DESC';
     }
     $order = array("time {$sort}");
     $ids = Pdb::fetchAll('id', AccountHistory::$table, $conds, $order);
     return safe_array_map(function ($id) {
         return new AccountHistory($id);
     }, $ids);
 }
Esempio n. 10
0
 public function doneOrder(Order $order)
 {
     $state = 'Done';
     Pdb::update(array('state' => $state, 'done_time=NOW()' => null), Order::$table, array('id=?', $order->id));
     UserLog::adminDealOrder($this, 'done', $order, '交易完成');
     return $state;
 }
Esempio n. 11
0
 public function setDefault()
 {
     Pdb::update(array('is_default' => 1), 'customer_address', array('address=?' => $this->id));
 }
Esempio n. 12
0
File: User.php Progetto: name3/cheng
 public function loginTimes()
 {
     return Pdb::count(UserLog::$table, $this->loginConds());
 }
Esempio n. 13
0
 public static function adminDealOrder(Admin $admin, $action, Order $order, $remark = '')
 {
     Pdb::insert(array('subject' => $admin->id, 'action' => $action . 'Order', 'target' => $order->id, 'info' => $remark, 'time=NOW()' => null), self::$table);
 }
Esempio n. 14
0
function clear_relation_db($main_table, $ref_table, $relation_table = null, $key_main = null, $key_ref = null)
{
    if ($relation_table === null) {
        $relation_table = $main_table . '_' . $ref_table;
    }
    if ($key_main === null) {
        $key_main = $main_table;
    }
    if ($key_ref === null) {
        $key_ref = $ref_table;
    }
    $all = Pdb::fetchAll('*', $relation_table);
    if ($all === false) {
        Pdb::del($ref_table);
        return;
    }
    // del in relation table
    foreach ($all as $info) {
        if (!Pdb::exists($main_table, array('id=?' => $info[$key_main]))) {
            Pdb::del($relation_table, array($key_main . '=?' => $info[$key_main]));
        }
    }
    // del in ref table
    $all = Pdb::fetchAll('*', $ref_table);
    if (empty($all)) {
        return;
    }
    foreach ($all as $info) {
        $id = $info['id'];
        if (!Pdb::exists($relation_table, array($key_ref . '=?' => $id))) {
            Pdb::del($ref_table, array('id=?' => $id));
        }
    }
}
Esempio n. 15
0
File: Cart.php Progetto: name3/cheng
 public function del(Order $order)
 {
     Pdb::del(self::$table, array('customer=?' => $this->owner_id, 'order=?' => $order->id));
 }
Esempio n. 16
0
File: init.php Progetto: name3/cheng
<?php

!defined('IN_PTF') && exit('ILLEGAL EXECUTION');
/**
 * @file    init
 * @author  ryan <*****@*****.**>
 */
// db config
Pdb::setConfig($config['db']);
// login
$user = User::loggingUser();
// but the var here should be long such as $logging_user
if ($user === false) {
    $has_login = false;
} else {
    $has_login = true;
    $user_type = $user->type;
    $type = strtolower($user_type);
    // $type is a temp var
    ${$type} = $user->instance();
    switch ($user_type) {
        case 'Customer':
            $cart = $customer->cart();
            break;
        case 'Admin':
        case 'SuperAdmin':
            $page['styles'][] = 'admin';
            break;
        default:
            throw new Exception('unrecognize type: ' . $user_type);
            break;
Esempio n. 17
0
 public function log()
 {
     $ret = Pdb::fetchAll(array('info as remark', 'time'), UserLog::$table, array('action LIKE ?' => '%Order', 'target=?' => $this->id));
     return empty($ret) ? array() : $ret;
 }
Esempio n. 18
0
 private static function typeId($name = '')
 {
     $id = Pdb::fetchRow('id', 'product_type', array('name = ?' => $name));
     if (empty($id)) {
         throw new Exception("no type: {$name}");
     }
     return $id;
 }
Esempio n. 19
0
 public function orderTimes()
 {
     return Pdb::count(UserLog::$table, array('subject=?' => $this->id, 'action=?' => 'StartBill'));
 }
Esempio n. 20
0
$phone = '13711231212';
$email = '*****@*****.**';
$info = compact('username', 'password', 'realname', 'phone', 'email');
$customer = Customer::create($info);
test(1, 1, array('name' => 'register Customer, db'));
begin_test();
test(User::check($username, $password), true, array('name' => 'User::check($username, $password)'));
begin_test();
$username = '******';
$password = '******';
$user = User::getByName('root');
$superadmin = $user->instance();
$admin = $superadmin->createAdmin(compact('username', 'password'));
$ideal_arr = array('name' => $username, 'password' => md5($password), 'type' => 'Admin');
$id = Pdb::lastInsertId();
$real_arr = Pdb::fetchRow('name, password, type', User::$table, array('id=?' => $id));
test($real_arr, $ideal_arr, array('name' => 'Super Admin create Admin, db'));
begin_test();
$prd_types = Product::types();
$info = array('name' => '唯爱心形群镶女戒_test', 'type' => reset(array_keys($prd_types)), 'material' => json_encode(array('PT950', '白18K金', '黄18K金', '红18K金')), 'rabbet_start' => '0.30', 'rabbet_end' => '0.60', 'weight' => 9, 'small_stone' => 3, 'st_weight' => 2.1, 'images' => array('400' => array('/test/static/img/i400-1.jpg', '/test/static/img/i400-2.jpg', '/test/static/img/i400-3.jpg'), 'thumb' => array('/test/static/img/i80-1.jpg', '/test/static/img/i80-2.jpg', '/test/static/img/i80-3.jpg')));
$product = Product::create($info);
test(1, 1, array('name' => 'Admin post Product, db'));
begin_test();
$address = $customer->defaultAddress();
$address->edit(array('name' => '小池', 'phone' => '14722320989', 'detail' => '深圳罗湖区田贝'));
test(1, 1, array('name' => 'edit Address'));
begin_test();
$cart = $customer->cart();
test(+$cart->count(), 2, array('name' => 'Cart count()'));
begin_test();
$cart->submit();
Esempio n. 21
0
 public function close()
 {
     if (self::$dbm) {
         self::$dbm->close();
         self::$dbm = null;
     }
     if (self::$dbs) {
         self::$dbs->close();
         self::$dbs = null;
     }
 }
Esempio n. 22
0
 public function info()
 {
     return Pdb::fetchRow('*', self::$table, $this->selfCond());
 }
Esempio n. 23
0
 private static function saleInfo($date_str, $format)
 {
     $arr = Pdb::fetchAll('paid', Order::$table, array($format => $date_str));
     return array('date' => $date_str, 'count' => count($arr), 'sum' => $arr ? array_sum($arr) : 0);
 }
Esempio n. 24
0
 public static function update($type, $price)
 {
     Pdb::insert(array('type' => $type, 'price' => $price, 'time=NOW()' => null), self::$table);
 }
Esempio n. 25
0
 public function accountRecords($conds)
 {
     $order_id = $conds['order'];
     return Pdb::fetchAll('*', AccountHistory::$table, array('account = ?' => $this->account()->id, '`order` = ?' => $order_id));
 }
Esempio n. 26
0
 public function changePassword($new_password)
 {
     Pdb::update(array('password' => md5($new_password)), self::$table, $this->selfCond());
 }
Esempio n. 27
0
File: test.php Progetto: name3/cheng
$opts = array('material' => 'PT950', 'size' => 12, 'carve_text' => 'I love U');
$opts2 = $opts;
$opts2['carve_text'] = $opts['carve_text'] . '2';
$order_dajiangyou = $customer->addProductToCart($product, $opts2);
$opts2['carve_text'] = $opts['carve_text'] . '3';
$order_to_del = $customer->addProductToCart($product, $opts2);
// add for twice
$old_num = $customer->cart()->count();
$customer->delProductFromCart($order_to_del);
$new_num = $customer->cart()->count();
test($old_num - 1, $new_num, array('name' => 'Customer del a Product from Cart'));
// case 14 Customer submit a Cart
begin_test();
$old_entry_num = Pdb::count(BigOrder::$table);
$big_order = $customer->submitCart();
$entry_num = Pdb::count(BigOrder::$table);
test($old_entry_num + 1, +$entry_num, array('name' => 'Customer submit a Cart'));
// case 15 Admin(?) edit Stone
begin_test();
$info = array('weight' => '3', 'cut' => 'EX', 'color' => '', 'polish' => '', 'clarity' => '', 'symmetry' => '', 'certificate' => '', 'no' => '', 'remark' => '');
$stone = $order->stone();
$stone->edit($info);
test(1, 1, array('name' => 'Admin(?) edit Stone'));
// case 16 Customer customize Order
begin_test();
$info = array('material' => 'PT950', 'stone' => '9', 'size' => '13', 'carve_text' => 'for test', 'remark' => 'for test');
$customer->customizeOrder($info);
test(1, 1, array('name' => 'Customer customize Order'));
// case 16 Admin recharge customer's Account then use it to pay order
begin_test();
$account = $customer->account();