ecshop 批量生成订单信息

<?php
/**
 * ecshop 给商品添加随机添加订单信息
 * @author Abner
 * qq :346882795
 * email: Abner3721@163.com
 * 
 * */


define('IN_ECS', true);

require(dirname(__FILE__) . '/includes/init.php');





//取出所有商品的信息
$gsql = 'SELECT * FROM ' .$GLOBALS['ecs'] -> table('goods'). 'WHERE 1';
$gdata = $db -> getAll($gsql);


//根据商品id生成订单信息
foreach($gdata as $k => $v)
{
    //评论的数量
    $comment_num = $db->getOne("SELECT count(comment_id) id FROM " .$GLOBALS['ecs'] -> table('comment'). " WHERE `id_value` = {$v['goods_id']}");
    $goods_number = $comment_num + mt_rand(1,50);
    $ogsql = 'INSERT INTO' .$GLOBALS['ecs'] -> table('order_goods'). 
    "(`order_id`, `goods_id`, `goods_name`, `goods_sn`, `product_id`, `goods_number`, `market_price`, `goods_price`, `send_number`, `is_real`, `parent_id`, `is_gift`, `comment_state`, `shaidan_state`, `send_store_number`, `send_store_id`) VALUES ".
    "(7, {$v['goods_id']}, '{$v['goods_name']}', '{$v['goods_sn']}', 0, {$goods_number}, {$v['market_price']}, {$v['shop_price']}, 0, 1, 0, 0, 0, 0, 0, 0)";
    
    $res = $db -> query($ogsql);
    if($res)
        echo "<span style='color:green'>{$v['goods_id']} 插入成功! </span><br/>";
    else
        echo "<span style='color:red'>{$v['goods_id']} 插入失败! </span><br/>";
        
}

 

posted @ 2016-05-24 09:41  Abner3721  阅读(1141)  评论(0编辑  收藏  举报