コード例 #1
0
ファイル: query_class.php プロジェクト: sammychan1981/quanpin
 /**
  * 构造方法
  * 
  * @access public
  * @param mixed $name
  * @return mixed
  */
 public function __construct($name)
 {
     $dbinfo = DBFactory::getDbInfo();
     $this->tablePre = $dbinfo['tablePre'];
     $this->table = $name;
     $this->dbo = DBFactory::getInstance();
 }
コード例 #2
0
ファイル: admin.php プロジェクト: sammychan1981/quanpin
 public function update()
 {
     $updateFile = Tiny::getPath('data') . 'update.php';
     $this->assign('status', '0');
     if (file_exists($updateFile)) {
         $updateInfo = (include $updateFile);
         if (isset($updateInfo['version'])) {
             $version = $updateInfo['version'];
             $versionFile = APP_CODE_ROOT . 'version.php';
             $currentVersion = (include $versionFile);
             if ($currentVersion == $version[0]) {
                 $do = Req::args('do');
                 if ($do == 'yes') {
                     $dbinfo = DBFactory::getDbInfo();
                     $this->assign('status', '1');
                     if (isset($updateInfo['sql'][$dbinfo['type']])) {
                         $sqls = $updateInfo['sql'][$dbinfo['type']];
                         $db = DBFactory::getInstance();
                         if (is_array($sqls)) {
                             foreach ($sqls as $sql) {
                                 $db->doSql($sql);
                             }
                         }
                         File::putContents($versionFile, "<?php return '{$version[1]}';?>");
                         unlink($updateFile);
                         $this->assign('info', '升级成功!');
                     } else {
                         $this->assign('info', '不支持' . $dbinfo['type'] . '数据库类型的升级!');
                     }
                 } else {
                     $this->assign('info', '系统可从当前版本:' . $currentVersion . '升级到' . $version[1]);
                 }
             } else {
                 $this->assign('status', '-1');
                 $this->assign('info', '没有可升级的信息!');
             }
         } else {
             $this->assign('status', '-1');
             $this->assign('info', '没有可升级的信息!');
         }
     } else {
         $this->assign('status', '-1');
         $this->assign('info', '没有可升级的信息!');
     }
     $this->redirect();
 }
コード例 #3
0
ファイル: goods.php プロジェクト: sammychan1981/quanpin
 function goods_save()
 {
     $spec_items = Req::args('spec_items');
     $spec_item = Req::args('spec_item');
     $items = explode(",", $spec_items);
     $values_array = array();
     //货品中的一些变量
     $pro_no = Req::args("pro_no");
     $store_nums = Req::args("store_nums");
     $warning_line = Req::args("warning_line");
     $weight = Req::args("weight");
     $sell_price = Req::args("sell_price");
     $market_price = Req::args("market_price");
     $cost_price = Req::args("cost_price");
     //values的笛卡尔积
     $values_dcr = array();
     $specs_new = array();
     if (is_array($spec_item)) {
         foreach ($spec_item as $item) {
             $values = explode(",", $item);
             foreach ($values as $value) {
                 $value_items = explode(":", $value);
                 $values_array[$value_items[0]] = $value_items;
             }
         }
         $value_ids = implode(",", array_keys($values_array));
         $values_model = new Model('spec_value');
         $spec_model = new Model('goods_spec');
         $specs = $spec_model->where("id in ({$spec_items})")->findAll();
         $values = $values_model->where("id in ({$value_ids})")->order('sort')->findAll();
         $values_new = array();
         foreach ($values as $k => $row) {
             $current = $values_array[$row['id']];
             if ($current[1] != $current[2]) {
                 $row['name'] = $current[2];
             }
             if ($current[3] != '') {
                 $row['img'] = $current[3];
             }
             $values_new[$row['spec_id']][$row['id']] = $row;
         }
         foreach ($specs as $key => $value) {
             $value['value'] = isset($values_new[$value['id']]) ? $values_new[$value['id']] : null;
             $specs_new[$value['id']] = $value;
         }
         foreach ($spec_item as $item) {
             $values = explode(",", $item);
             $key_code = ';';
             foreach ($values as $k => $value) {
                 $value_items = explode(":", $value);
                 $key = $items[$k];
                 $tem[$key] = $specs_new[$key];
                 $tem[$key]['value'] = $values_array[$value_items[0]];
                 $key_code .= $key . ':' . $values_array[$value_items[0]][0] . ';';
             }
             $values_dcr[$key_code] = $tem;
         }
     }
     //商品处理
     $goods = new Model('goods');
     Req::args('specs', serialize($specs_new));
     $attrs = is_array(Req::args("attr")) ? Req::args("attr") : array();
     $imgs = is_array(Req::args("imgs")) ? Req::args("imgs") : array();
     Req::args('attrs', serialize($attrs));
     Req::args('imgs', serialize($imgs));
     Req::args('up_time', date("Y-m-d H:i:s"));
     $id = intval(Req::args("id"));
     $gdata = Req::args();
     $gdata['name'] = Filter::sql($gdata['name']);
     //$gdata['sub_title'] = Filter::sql($gdata['sub_title']);
     $gdata['content'] = Filter::htmlstr($gdata['content']);
     $gdata['sale_protection'] = Filter::htmlstr($gdata['sale_protection']);
     if (isset($gdata['pro_no']) && is_array($gdata['pro_no'])) {
         $gdata['pro_no'] = $gdata['pro_no'][0];
     }
     //Tiny::log(__FILE__.__LINE__."-".var_export($gdata, true));
     if ($id == 0) {
         $gdata['create_time'] = date("Y-m-d H:i:s");
         $goods_id = $goods->data($gdata)->save();
         Log::op($this->manager['id'], "添加商品", "管理员[" . $this->manager['name'] . "]:添加了商品 " . Req::args('name'));
     } else {
         $goods_id = $id;
         $goods->data($gdata)->where("id =" . $id)->update();
         //$sql = Tiny::getSqlLog(); Tiny::log(__FILE__.__LINE__."-".var_export($sql, true));
         Log::op($this->manager['id'], "修改商品", "管理员[" . $this->manager['name'] . "]:修改了商品 " . Req::args('name'));
     }
     //货品添加处理
     $g_store_nums = $g_warning_line = $g_weight = $g_sell_price = $g_market_price = $g_cost_price = 0;
     $products = new Model("products");
     $k = 0;
     foreach ($values_dcr as $key => $value) {
         $result = $products->where("goods_id = " . $goods_id . " and specs_key = '{$key}'")->find();
         $data = array('goods_id' => $goods_id, 'pro_no' => $pro_no[$k], 'store_nums' => $store_nums[$k], 'warning_line' => $warning_line[$k], 'weight' => $weight[$k], 'sell_price' => $sell_price[$k], 'market_price' => $market_price[$k], 'cost_price' => $cost_price[$k], 'specs_key' => $key, 'spec' => serialize($value));
         $g_store_nums += $data['store_nums'];
         if ($g_warning_line == 0) {
             $g_warning_line = $data['warning_line'];
         } else {
             if ($g_warning_line > $data['warning_line']) {
                 $g_warning_line = $data['warning_line'];
             }
         }
         if ($g_weight == 0) {
             $g_weight = $data['weight'];
         } else {
             if ($g_weight < $data['weight']) {
                 $g_weight = $data['weight'];
             }
         }
         if ($g_sell_price == 0) {
             $g_sell_price = $data['sell_price'];
         } else {
             if ($g_sell_price > $data['sell_price']) {
                 $g_sell_price = $data['sell_price'];
             }
         }
         if ($g_market_price == 0) {
             $g_market_price = $data['market_price'];
         } else {
             if ($g_market_price < $data['market_price']) {
                 $g_market_price = $data['market_price'];
             }
         }
         if ($g_cost_price == 0) {
             $g_cost_price = $data['cost_price'];
         } else {
             if ($g_cost_price < $data['cost_price']) {
                 $g_cost_price = $data['cost_price'];
             }
         }
         if (!$result) {
             $products->data($data)->insert();
         } else {
             $products->data($data)->where("goods_id=" . $goods_id . " and specs_key='{$key}'")->update();
         }
         $k++;
     }
     //如果没有规格
     if ($k == 0) {
         $g_store_nums = $store_nums;
         $g_warning_line = $warning_line;
         $g_weight = $weight;
         $g_sell_price = $sell_price;
         $g_market_price = $market_price;
         $g_cost_price = $cost_price;
         $data = array('goods_id' => $goods_id, 'pro_no' => $pro_no, 'store_nums' => $store_nums, 'warning_line' => $warning_line, 'weight' => $weight, 'sell_price' => $sell_price, 'market_price' => $market_price, 'cost_price' => $cost_price, 'specs_key' => '', 'spec' => serialize(array()));
         $result = $products->where("goods_id = " . $goods_id)->find();
         if (!$result) {
             $products->data($data)->insert();
         } else {
             $products->data($data)->where("goods_id=" . $goods_id)->update();
         }
     }
     //更新商品相关货品的部分信息
     $goods->data(array('store_nums' => $g_store_nums, 'warning_line' => $g_warning_line, 'weight' => $g_weight, 'sell_price' => $g_sell_price, 'market_price' => $g_market_price, 'cost_price' => $g_cost_price))->where("id=" . $goods_id)->update();
     $keys = array_keys($values_dcr);
     $keys = implode("','", $keys);
     //清理多余的货品
     $products->where("goods_id=" . $goods_id . " and specs_key not in('{$keys}')")->delete();
     //规格与属性表添加部分
     $spec_attr = new Model("spec_attr");
     //处理属性部分
     $value_str = '';
     if ($attrs) {
         foreach ($attrs as $key => $attr) {
             if (is_numeric($attr)) {
                 $value_str .= "({$goods_id},{$key},{$attr}),";
             }
         }
     }
     foreach ($specs_new as $key => $spec) {
         if (isset($spec['value'])) {
             foreach ($spec['value'] as $k => $v) {
                 $value_str .= "({$goods_id},{$key},{$k}),";
             }
         }
     }
     $value_str = rtrim($value_str, ',');
     //更新商品键值对表
     $spec_attr->where("goods_id = " . $goods_id)->delete();
     $dbinfo = DBFactory::getDbInfo();
     $spec_attr->query("insert into {$dbinfo['tablePre']}spec_attr values {$value_str}");
     $this->redirect("goods_list");
 }
コード例 #4
0
ファイル: model_class.php プロジェクト: sammychan1981/quanpin
 /**
  * get完整表名
  * @author COU
  * 2015/07/03
  * @access public
  * @param  $tableNameStr   表名后缀
  * @return tableName
  */
 public function getTableName($tableNameStr)
 {
     $db = DBFactory::getDbInfo();
     $tableName = $db['tablePre'] . "{$tableNameStr}";
     return $tableName;
 }