📄 shopex46.php
字号:
/* 查询品牌列表 name => id */
$brand_list = array();
$sql = "SELECT brand_id, brand_name FROM " . $ecs->table('brand');
$res = $db->query($sql);
while ($row = $db->fetchRow($res))
{
$brand_list[$row['brand_name']] = $row['brand_id'];
}
/* 取得商店设置 */
$sql = "SELECT offer_pointtype, offer_pointnum FROM ".$this->sprefix."mall_offer WHERE offerid = '1'";
$config = $this->sdb->getRow($sql);
/* 查询商品并处理 */
$sql = "SELECT * FROM ".$this->sprefix."mall_goods";
$res = $this->sdb->query($sql);
while ($row = $this->sdb->fetchRow($res))
{
$goods = array();
$goods['goods_id'] = $row['gid'];
$goods['cat_id'] = $row['catid'];
$goods['goods_sn'] = ecs_iconv($this->scharset, $this->tcharset, addslashes($row['bn']));
$goods['goods_name'] = ecs_iconv($this->scharset, $this->tcharset, addslashes($row['goods']));
$goods['brand_id'] = trim($row['brand']) == '' ? '0' : $brand_list[ecs_iconv($this->scharset, $this->tcharset, addslashes($row['brand']))];
$goods['goods_number'] = $row['storage'];
$goods['goods_weight'] = $row['weight'];
$goods['market_price'] = $row['priceintro'];
$goods['shop_price'] = $row['ifdiscreteness'] == '1' ? $row['basicprice'] : $row['price'];
if ($row['tejia2'] == '1')
{
$goods['promote_price'] = $goods['shop_price'];
$goods['promote_start_date'] = gmtime();
$goods['promote_end_date'] = local_strtotime('+1 weeks');
}
$goods['warn_number'] = $row['ifalarm'] == '1' ? $row['alarmnum'] : '0';
$goods['goods_brief'] = ecs_iconv($this->scharset, $this->tcharset, addslashes($row['intro']));
$goods['goods_desc'] = str_replace('pictures/newsimg/', $this->tdocroot . '/images/upload/', ecs_iconv($this->scharset, $this->tcharset, addslashes($row['memo'])));
$goods['is_real'] = '1';
$goods['is_on_sale'] = $row['shop_iffb'];
$goods['is_alone_sale'] = '1';
$goods['add_time'] = $row['uptime'];
$goods['sort_order'] = $row['offer_ord'];
$goods['is_delete'] = '0';
$goods['is_best'] = $row['recommand2'];
$goods['is_new'] = $row['new2'];
$goods['is_hot'] = $row['hot2'];
$goods['is_promote'] = $row['tejia2'];
$goods['goods_type'] = $row['catid'];
/* 图片:如果没有本地文件,取远程图片 */
$file = $this->troot . '/images/' . date('Ym') . '/small_' . $row['gid'];
if (file_exists($file. '.jpg'))
{
$goods['goods_thumb'] = 'images/' . date('Ym') . '/small_' . $row['gid'] . '.jpg';
}
elseif (file_exists($file. '.jpeg'))
{
$goods['goods_thumb'] = 'images/' . date('Ym') . '/small_' . $row['gid'] . '.jpeg';
}
elseif (file_exists($file. '.gif'))
{
$goods['goods_thumb'] = 'images/' . date('Ym') . '/small_' . $row['gid'] . '.gif';
}
elseif (file_exists($file. '.png'))
{
$goods['goods_thumb'] = 'images/' . date('Ym') . '/small_' . $row['gid'] . '.png';
}
else
{
$goods['goods_thumb'] = $row['smallimgremote'];
}
$file = $this->troot . '/images/' . date('Ym') . '/big_' . $row['gid'];
if (file_exists($file. '.jpg'))
{
$goods['goods_img'] = 'images/' . date('Ym') . '/big_' . $row['gid'] . '.jpg';
$goods['original_img'] = 'images/' . date('Ym') . '/original_' . $row['gid'] . '.jpg';
}
elseif (file_exists($file. '.jpeg'))
{
$goods['goods_img'] = 'images/' . date('Ym') . '/big_' . $row['gid'] . '.jpeg';
$goods['original_img'] = 'images/' . date('Ym') . '/original_' . $row['gid'] . '.jpeg';
}
elseif (file_exists($file. '.gif'))
{
$goods['goods_img'] = 'images/' . date('Ym') . '/big_' . $row['gid'] . '.gif';
$goods['original_img'] = 'images/' . date('Ym') . '/original_' . $row['gid'] . '.gif';
}
elseif (file_exists($file. '.png'))
{
$goods['goods_img'] = 'images/' . date('Ym') . '/big_' . $row['gid'] . '.png';
$goods['orinigal_img'] = 'images/' . date('Ym') . '/original_' . $row['gid'] . '.png';
}
else
{
$goods['goods_img'] = $row['bigimgremote'];
}
/* 积分:根据商店设置 */
if ($config['offer_pointtype'] == '0')
{
/* 不使用积分 */
$goods['integral'] = '0';
}
elseif ($config['offer_pointtype'] == '1')
{
/* 按比例 */
$goods['integral'] = round($goods['shop_price'] * $config['offer_pointnum']);
}
else
{
/* 自定义 */
$goods['integral'] = $row['point'];
}
/* 插入 */
if (!$db->autoExecute($ecs->table('goods'), $goods, 'INSERT', '', 'SILENT'))
{
//return $db->error();
}
/* 扩展分类 */
if ($row['linkclass'] != '')
{
$goods_cat = array();
$goods_cat['goods_id'] = $row['gid'];
$cat_id_list = explode(',', trim($row['linkclass'], ','));
foreach ($cat_id_list as $cat_id)
{
$goods_cat['cat_id'] = $cat_id;
if (!$db->autoExecute($ecs->table('goods_cat'), $goods_cat, 'INSERT', '', 'SILENT'))
{
//return $db->error();
}
}
}
/* 取得该分类的所有属性 */
$attr_list = array();
$sql = "SELECT * FROM " . $ecs->table('attribute') . " WHERE cat_id = '$row[catid]'";
$res1 = $db->query($sql);
while ($attr = $db->fetchRow($res1))
{
$attr_list[$attr['sort_order']] = $attr['attr_id'];
}
/* 商品属性 */
if ($attr_list)
{
$goods_attr = array();
$goods_attr['goods_id'] = $row['gid'];
for ($i = 1; $i <= 40; $i++)
{
if (trim($row['attr' . $i]) != '')
{
$goods_attr['attr_id'] = $attr_list[$i];
$goods_attr['attr_value'] = trim(ecs_iconv($this->scharset, $this->tcharset, $row['attr' . $i]));
if (!$db->autoExecute($ecs->table('goods_attr'), $goods_attr, 'INSERT', '', 'SILENT'))
{
//return $db->error();
}
}
}
}
/* 商品相册 */
if ($row['multi_image'])
{
$goods_gallery = array();
$goods_gallery['goods_id'] = $row['gid'];
$img_list = explode('&&&', $row['multi_image']);
foreach ($img_list as $img)
{
if (substr($img, 0, 7) == 'http://')
{
$goods_gallery['img_url'] = $img;
}
else
{
make_dir('images/' . date('Ym') . '/');
$goods_gallery['img_url'] = 'images/' . date('Ym') . '/big_' . $img;
$goods_gallery['img_original'] = 'images/' . date('Ym') . '/original_' . $img;
}
if (!$db->autoExecute($ecs->table('goods_gallery'), $goods_gallery, 'INSERT', '', 'SILENT'))
{
//return $db->error();
}
}
}
}
/* 关联商品 */
$sql = "SELECT * FROM ".$this->sprefix."mall_offer_linkgoods";
$res = $this->sdb->query($sql);
while ($row = $this->sdb->fetchRow($res))
{
$link_goods = array();
$link_goods['goods_id'] = $row['pgid'];
$link_goods['link_goods_id'] = $row['sgid'];
$link_goods['is_double'] = $row['type'];
if (!$db->autoExecute($ecs->table('link_goods'), $link_goods, 'INSERT', '', 'SILENT'))
{
//return $db->error();
}
if ($row['type'] == '1')
{
$link_goods = array();
$link_goods['goods_id'] = $row['sgid'];
$link_goods['link_goods_id'] = $row['pgid'];
$link_goods['is_double'] = $row['type'];
if (!$db->autoExecute($ecs->table('link_goods'), $link_goods, 'INSERT', '', 'SILENT'))
{
//return $db->error();
}
}
}
/* 组合商品 */
/* 返回成功 */
return TRUE;
}
/**
* 会员等级、会员、会员价格
*/
function process_users()
{
global $db, $ecs;
/* 清空会员、会员等级、会员价格、用户红包、用户地址 */
truncate_table('user_rank');
truncate_table('users');
truncate_table('user_address');
truncate_table('user_bonus');
truncate_table('member_price');
truncate_table('user_account');
/* 查询并插入会员等级 */
$sql = "SELECT * FROM ".$this->sprefix."mall_member_level order by point desc";
$res = $this->sdb->query($sql);
$max_points = 50000;
while ($row = $this->sdb->fetchRow($res))
{
$user_rank = array();
$user_rank['rank_id'] = $row['levelid'];
$user_rank['rank_name'] = ecs_iconv($this->scharset, $this->tcharset, addslashes($row['name']));
$user_rank['min_points'] = $row['point'];
$user_rank['max_points'] = $max_points;
$user_rank['discount'] = round($row['discount'] * 100);
$user_rank['show_price'] = '1';
$user_rank['special_rank'] = '0';
if (!$db->autoExecute($ecs->table('user_rank'), $user_rank, 'INSERT', '', 'SILENT'))
{
//return $db->error();
}
$max_points = $row['point'] - 1;
}
/* 查询并插入会员 */
$sql = "SELECT * FROM ".$this->sprefix."mall_member";
$res = $this->sdb->query($sql);
while ($row = $this->sdb->fetchRow($res))
{
$user = array();
$user['user_id'] = $row['userid'];
$user['email'] = $row['email'];
$user['user_name'] = ecs_iconv($this->scharset, $this->tcharset, addslashes($row['user']));
$user['password'] = $row['password'];
$user['question'] = ecs_iconv($this->scharset, $this->tcharset, addslashes($row['pw_question']));
$user['answer'] = ecs_iconv($this->scharset, $this->tcharset, addslashes($row['pw_answer']));
$user['sex'] = $row['sex'];
if (!empty($row['birthday']))
{
$birthday = strtotime($row['birthday']);
if ($birthday != -1 && $birthday !== false)
{
$user['birthday'] = date('Y-m-d', $birthday);
}
}
$user['user_money'] = $row['advance'];
$user['pay_points'] = $row['point'];
$user['rank_points'] = $row['point'];
$user['reg_time'] = $row['regtime'];
$user['last_login'] = $row['regtime'];
$user['last_ip'] = $row['ip'];
$user['visit_count'] = '1';
$user['user_rank'] = '0';
if (!$db->autoExecute($ecs->table('users'), $user, 'INSERT', '', 'SILENT'))
{
//return $db->error();
}
uc_call('uc_user_register', array($user['user_name'], $user['password'], $user['email']));
}
/* 收货人地址 */
$sql = "SELECT * FROM ".$this->sprefix."mall_member_receiver";
$res = $this->sdb->query($sql);
while ($row = $this->sdb->fetchRow($res))
{
$address = array();
$address['address_id'] = $row['receiveid'];
$address['address_name'] = ecs_iconv($this->scharset, $this->tcharset, addslashes($row['name']));
$address['user_id'] = $row['memberid'];
$address['consignee'] = ecs_iconv($this->scharset, $this->tcharset, addslashes($row['name']));
$address['email'] = $row['email'];
$address['address'] = ecs_iconv($this->scharset, $this->tcharset, addslashes($row['address']));
$address['zipcode'] = $row['zipcode'];
$address['tel'] = $row['telphone'];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -