Example #1
0
//$data['keywords'] = trim($_POST['keywords']);
$data['goods_brief'] = trim($_POST['goods_brief']);

$data['add_time'] = time();
*/
$goods = new GoodsModel();
$data = array();
$goods->setField($goods->showField());
//自动格式化数据
$data = $goods->_facade($_POST);
$data['goods_weight'] = $_POST['goods_weight'] * $_POST['weight_unit'];
//自动填充
$data = $goods->_autofill($data);
//自动校验
if (!$goods->_validate($data)) {
    echo $goods->getErr()[0];
    exit;
}
//若没有goods_sn,自动生成
if (!$data['goods_sn']) {
    $data['goods_sn'] = $goods->snGenerator();
}
//上传图片
$updriver = new UploadHelper();
$ori_img = $updriver->doUpload('goods_img');
if ($ori_img) {
    $data['ori_img'] = $ori_img;
    //处理缩略图文件名
    $abs_ori = __ROOT__ . $ori_img;
    $abs_goods = dirname($abs_ori) . "/goods_" . basename($abs_ori);
    $goods_img = str_replace(__ROOT__, '', $abs_goods);
Example #2
0
<?php

/****
燕十八 公益PHP讲堂

论  坛: http://www.zixue.it
微  博: http://weibo.com/Yshiba
YY频道: 88354001
****/
define('ACC', true);
require "../include/init.php";
$goods = new GoodsModel();
$_POST['goods_weight'] *= $_POST['weight_unit'];
$data = array();
$data = $goods->_facade($_POST);
// 自动过滤
$data = $goods->_autoFill($data);
// 自动填充
if (!$goods->_validate($data)) {
    echo '数据不合法<br />';
    echo implode(',', $goods->getErr());
}
if ($goods->add($data)) {
    echo '商品发布成功';
} else {
    echo '商品发布失败';
}