Exemple #1
0
 public function update_stock($filter, $col, $nums = 0, $operation, &$msg)
 {
     $where = base_db_tools::filter2sql($filter);
     $op_map = array('plus' => '+', 'minus' => '-', 'multiple' => '*');
     if ($op_map[$operation] == '-') {
         $exist_stock = app::get('b2c')->model('stock')->getRow($col, $filter);
         if ($exist_stock[$col] <= 0) {
             return true;
         }
     }
     if ($operation) {
         $set = $col . $op_map[$operation] . (string) intval($nums);
     } else {
         $set = $nums ? $nums : 0;
     }
     $SQL_update = "UPDATE `vmc_b2c_stock` SET {$col} = {$set},last_modify=UNIX_TIMESTAMP(CURRENT_TIMESTAMP)  WHERE {$where}";
     if (!vmc::database()->exec($SQL_update, true)) {
         $msg = '异常';
         return false;
     }
     $msg = '操作成功';
     return true;
 }
Exemple #2
0
 public function update($data, $filter, $mustUpdate = null)
 {
     if (count((array) $data) == 0) {
         return true;
     }
     $UpdateValues = array();
     foreach ($this->_columns() as $k => $v) {
         if (!empty($mustUpdate)) {
             if (!array_key_exists($k, $mustUpdate)) {
                 continue;
             } else {
                 unset($mustUpdate[$k]);
             }
         }
         if (array_key_exists($k, $data)) {
             $UpdateValues[] = '`' . $k . '`= ' . base_db_tools::quotevalue($this->db, $data[$k], $v['type']);
         }
         if ($data[$k] !== false) {
             if ($v['type'] == 'last_modify') {
                 $UpdateValues[] = '`' . $k . '` = ' . time() . ' ';
                 //     $data[$k] = time();
             } elseif ($v['depend_col']) {
                 $dependColVal = explode(':', $v['depend_col']);
                 if ($data[$dependColVal[0]] == $dependColVal[1]) {
                     switch ($dependColVal[2]) {
                         case 'now':
                             $UpdateValues[] = '`' . $k . '` = ' . time() . ' ';
                             //                                $data[$k] = time();
                             break;
                     }
                 }
             }
         }
     }
     if (!empty($mustUpdate)) {
         foreach ($mustUpdate as $mpk => $mpv) {
             $UpdateValues[] = '`' . $mpk . '`= NULL';
         }
     }
     if (count($UpdateValues) > 0) {
         $sql = 'update ' . $this->table_name(1) . ' set ' . implode(',', $UpdateValues) . ' where ' . base_db_tools::filter2sql($filter);
         if ($this->db->exec($sql)) {
             if ($rs = $this->db->affect_row()) {
                 return $rs;
             } else {
                 return true;
             }
         } else {
             return false;
         }
     }
 }
Exemple #3
0
 public function update($data, $filter = array(), $mustUpdate = null)
 {
     if (count((array) $data) == 0) {
         return true;
     }
     $UpdateValues = array();
     foreach ($this->_columns() as $k => $v) {
         if (!empty($mustUpdate)) {
             if (!array_key_exists($k, $mustUpdate)) {
                 continue;
             } else {
                 unset($mustUpdate[$k]);
             }
         }
         //如果是必填,那么参数如果是空则使用默认
         if ($v['required'] && array_key_exists($k, $data) && ($data[$k] === '' || is_null($data[$k]))) {
             unset($data[$k]);
         }
         if (array_key_exists($k, $data)) {
             $UpdateValues[] = '`' . $k . '`= ' . base_db_tools::quotevalue($this->db, $data[$k], $v['type']);
         }
         if ($data[$k] !== false) {
             if ($v['type'] == 'last_modify') {
                 $UpdateValues[] = '`' . $k . '` = ' . time() . ' ';
             } elseif (isset($v['depend_col']) && !empty($v['depend_col'])) {
                 $dependColVal = explode(':', $v['depend_col']);
                 if ($data[$dependColVal[0]] == $dependColVal[1]) {
                     switch ($dependColVal[2]) {
                         case 'now':
                             $UpdateValues[] = '`' . $k . '` = ' . time() . ' ';
                             break;
                     }
                 }
             }
         }
     }
     if (!empty($mustUpdate)) {
         foreach ($mustUpdate as $mpk => $mpv) {
             $UpdateValues[] = '`' . $mpk . '`= NULL';
         }
     }
     $where_sql = is_array($filter) ? base_db_tools::filter2sql($filter) : $filter;
     $sql = 'update `' . $this->table_name(1) . '` set ' . implode(',', $UpdateValues) . ' where ' . $where_sql;
     if (!stripos($where_sql, 'AND')) {
         logger::warning('全表更新操作被拦截!SQL:' . $sql);
         return false;
     }
     if (count($UpdateValues) > 0) {
         return $this->db->exec($sql, $this->skipModifiedMark);
     }
 }