Blog

Ecshop功能改造范例

一. 看图: a) 二. 当管理员选中此图片后,将其图片的ID,设计者的ID,设计者的Name传入SESSION中暂时储存,同时并发增加商品表单,当添加商品成功后返回的商品ID,一并存入”ecs_downpic”表中储存,方便处理成衣商品与图片和设计者的一对一关系. 三. 具体的实现示例: a) <a href="goods.php?act=down_goods&id={$value.id}">下单成衣</a>
  1. i. Href地址中的参数,第一个传入的action,第二个传了一个id值过去.方便处理.
b) goods.php,我们得加入的实现代码.
  1. i. elseif ($_REQUEST ['act'] == 'down_goods')
    1. 1. 首先知道模板点击之后,处理代码的地方,实现代码的地方在这个if语块中.
  2. ii. 得定义一个处理结果的连接.
    1. 1. $link [] = array ('href' => 'goods.php?act=add', 'text' => '添加成衣商品' );
a) 告诉代码,所有操作完成之后,连接是什么,会到哪里去.
  1. iii. $id = isset ( $_REQUEST ['id'] ) ? $_REQUEST ['id'] : 0;
    1. 1. 接收我们刚传过来的id,因为需要这个id去找一些我们想要的数据.
  2. iv. 我们在这个功能中,首先得找到图片信息,然后去找到图片的设计者,最终达到商品和设计者之间的一种关系.
    1. 1. 那么首先我们得根据我们传过来的id,去找到指定的图片信息:
a) $sql = 'SELECT * FROM ' . $GLOBALS ['ecs']->table ( 'uploadimg' ) . ' WHERE id = ' . $id . ''; b) $result = $db->getRow ( $sql );
  1. 2. 我们得到了图片的信息,那么因为图片和设计者是存在一种关系的,通过用户的user_id,我们可以得到用户的信息.那么我们去找到指定的用户信息.
a) if ($result ['user_id'] != 0) { b) $sql = ' SELECT user_id,user_name FROM ' . $GLOBALS ['ecs']->table ( 'users' ) . ' WHERE user_id = ' . $result ['user_id'] . ''; c) $res = $db->getRow ( $sql ); d) }
  1. 3. 我们通过图片的指定user_id去找到了用户信息,那么我们把该要保存的信息,暂时放到SESSION 当中去.
a) $_SESSION ['pic_id'] = $result ['id']; b) $_SESSION ['design_id'] = $result ['user_id']; c) $_SESSION ['design_name'] = $result ['user_name'];
  1. 4. 那么我们需要把这些SESSION的数据存入到另外一张表中去,这样方便之后的调用.
a) 创建一张”ecs_downpic”,表中就是一个id,图片的id,设计者的id,设计者的name,图片成衣后的id,我们把这几个数据存入表中.看图: b)
  1. 5. 创建后,我们得把这些数据存入数据库,存入之前,我们得确定一个图片只能下单成衣一次,那么数据是唯一性的,不能存在一个图片有多条数据的.
a) 首先我们得确定,这个表中没有我们传入当前图片的数据.
  1. i. $sql = "SELECT * FROM " .$GLOBALS['ecs']->table('downpic') . " WHERE pic_id = ".$result['id'];
  2. ii. $values = $db->getRow ( $sql );
b) 找出的数据,我们得判断下,看不存在的话,我们再把当前图片的信息存入表中:
  1. 1. if (empty ( $values )) {
  2. 2. $sql = "INSERT INTO " . $GLOBALS ['ecs']->table ( 'downpic' ) . " (pic_id,design_id,design_name) VALUES(" . $_SESSION ['pic_id'] . "," . $_SESSION ['design_id'] . ",'" . $_SESSION ['design_name'] . "')";
  3. 3. $query = $db->query ( $sql );
  4. 4. $downid = $db->insert_id ();
  5. 5. if ($query) {
  6. 6. sys_msg ( '下单成衣成功', 0, $link );
  7. 7. } else {
  8. 8. sys_msg ( '下单成衣失败', 1, $link );
  9. 9. }
c) 我们成功存入一条数据后,我们要把存入数据的id返回回来,也把它封装到SESSION中去.
  1. i. $_SESSION ['down_id'] = $downid;
  2. ii. if ($query) {
  3. iii. sys_msg ( '下单成衣成功', 0, $link );
  4. iv. } else {
  5. v. sys_msg ( '下单成衣失败', 1, $link );
  6. vi. }
  7. v. 我们把图片信息及用户的信息存入表中,之后就是添加商品成功之后,把商品的id存入ecs_downpic.实现代码:
    1. 1. 在添加商品成功之后,会得到返回后的商品id.
    2. 2. 得到之后,我们只需在后面加载我们需要更新的sql即好.实现代码:
a) admin/goods.php中添加商品的代码,goods.php684行会看到db->query($sql); b) 687行代码会看到 $is_insert ? $db->insert_id () : $_REQUEST ['goods_id']; 得到添加此商品完返回的商品id. c) 实现更新ecs_downpic表中,更新当前图片的商品id,达成商品和设计者的关系.我们在这需要获取到SESSION刚才封装的成衣id,down_id.然后更具down_id,去更新我们的数据.代码实现: d) if ($goods_id) { e) $sql = "UPDATE " . $ecs->table ( 'downpic' ) . ' SET shop_id = ' . $goods_id . ' WHERE id = ' . $_SESSION ['down_id']; f) $db->query ( $sql ); g) } 完整代码: goods.php?action=down_goods elseif ($_REQUEST ['act'] == 'down_goods') { $link [] = array ('href' => 'goods.php?act=add', 'text' => '添加成衣商品' ); $id = isset ( $_REQUEST ['id'] ) ? $_REQUEST ['id'] : 0; if ($id != 0) { $sql = 'SELECT * FROM ' . $GLOBALS ['ecs']->table ( 'uploadimg' ) . ' WHERE id = ' . $id . ''; $result = $db->getRow ( $sql ); if ($result ['user_id'] != 0) { $sql = ' SELECT user_id,user_name FROM ' . $GLOBALS ['ecs']->table ( 'users' ) . ' WHERE user_id = ' . $result ['user_id'] . ''; $res = $db->getRow ( $sql ); } $result ['user_name'] = $res ['user_name']; if ($result) { $_SESSION ['pic_id'] = $result ['id']; $_SESSION ['design_id'] = $result ['user_id']; $_SESSION ['design_name'] = $result ['user_name']; $sql = "SELECT * FROM " .$GLOBALS['ecs']->table('downpic') . " WHERE pic_id = ".$result['id']; $values = $db->getRow ( $sql ); if (empty ( $values )) { $sql = "INSERT INTO " . $GLOBALS ['ecs']->table ( 'downpic' ) . " (pic_id,design_id,design_name) VALUES(" . $_SESSION ['pic_id'] . "," . $_SESSION ['design_id'] . ",'" . $_SESSION ['design_name'] . "')"; $query = $db->query ( $sql ); $downid = $db->insert_id (); $_SESSION ['down_id'] = $downid; if ($query) { sys_msg ( '下单成衣成功', 0, $link ); } else { sys_msg ( '下单成衣失败', 1, $link ); } } else { sys_msg ( '下单成衣失败', 1, $link ); } } } } goods.php?act=insert 的代码 if ($goods_id) { $sql = "UPDATE " . $ecs->table ( 'downpic' ) . ' SET shop_id = ' . $goods_id . ' WHERE id = ' . $_SESSION ['down_id']; $db->query ( $sql ); } 具体的Ecshop的一个小功能改造已经完成.剩下的就是你去怎么把数据调用显示到你想实现的地方了.呵呵…

Words translated by CCJK

146,096,379

Request a call or contact us

  •  

    Call ccjk.support for professional assistance

  •  

    Click Here to leave us a message and be as detailed as possible.

We are Certified

Our Client Satisfaction

rating for previous quarte

4.00
  •  
    Inquiry Form

    Please take few minutes to fill
    inquiry form and get Free Quote

  •  
    Request a Call

    Click to receive Free Call, Our
    Representative will contact you

  •  
    Leave a Message

    Please leave us a message and
    be as detailed as possible

Over 95% of our clients recommend our language services to others


Copyright © CCJK Technologies Co., Ltd. 2000-2017. All rights reserved.
TOP