コード例 #1
0
ファイル: api_1_0_goods.php プロジェクト: noikiy/MyShop
 /**
  * 设置库存
  * @param 设置库存的数据值包括Goods_id
  * @author DreamDream
  * @return 设置库存是否成功
  */
 function set_goods_bn($data)
 {
     safeVar($data);
     if (!($rs = $this->db->exec('select bn from sdb_goods where goods_id=' . intval($data['goods_id'])))) {
         $this->api_response('fail', 'data fail', $data, 'can not find the goods');
     }
     unset($data['goods_id']);
     $aData = $this->varify_date_whole($data);
     $sql = $this->db->getUpdateSQL($rs, $aData);
     if (!$this->db->exec($sql)) {
         $this->api_response('fail', 'db error', $data);
     }
     return $this->api_response('true');
 }
コード例 #2
0
ファイル: kernel.php プロジェクト: dalinhuang/shopexts
 function kernel()
 {
     set_error_handler(array(&$this, "errorHandler"));
     $this->_halt_err_level = E_ERROR | E_USER_ERROR | E_CORE_ERROR | E_PARSE;
     $this->_start = $this->microtime();
     $GLOBALS['system'] =& $this;
     if (!get_magic_quotes_gpc()) {
         safeVar($_GET);
         safeVar($_POST);
         safeVar($_COOKIE);
     }
     set_include_path(CORE_DIR . '/include' . PATH_SEPARATOR . '.');
     require 'defined.php';
     error_reporting(E_ALL);
     if (defined('WITH_MEMCACHE') && WITH_MEMCACHE) {
         $this->init_memcache();
     }
     if (!defined('HOME_DIR') || defined('WITHOUT_CACHE') && WITHOUT_CACHE) {
         $this->cache = new nocache();
     } else {
         require 'cachemgr.php';
         if (defined('WITH_MEMCACHE') && WITH_MEMCACHE) {
             require PLUGIN_DIR . '/functions/cache_memcache.php';
             $this->cache = new cache_memcache();
         } elseif (defined('CACHE_METHOD')) {
             require PLUGIN_DIR . '/functions/' . CACHE_METHOD . '.php';
             $cache_method = CACHE_METHOD;
             $this->cache = new $cache_method();
         } elseif (php_sapi_name() == 'isapi') {
             require 'secache.php';
             require 'secache_no_flock.php';
             $this->cache = new secache_no_flock();
         } else {
             require 'secache.php';
             $this->cache = new secache();
         }
     }
     require 'setmgr.php';
     $this->__setting = new setmgr();
     $this->set_timezone(SERVER_TIMEZONE);
 }
コード例 #3
0
 /**
  * dearler_id,bn,name,specvalue
  *
  */
 function match_goods($data)
 {
     safeVar($data);
     $s_dealer_id = $data['dealer_id'];
     $s_bn = $data['bn'];
     $s_name = $data['name'];
     $s_specvalue = $data['specvalue'];
     $s_status = $data['status'];
     $member = array();
     $result['alert_num'] = $this->system->getConf('system.product.alert.num');
     $obj_member = $this->load_api_instance('verify_member_valid', '2.0');
     $obj_member->verify_member_valid($s_dealer_id, $member);
     //根据经销商ID验证会员记录有效性
     $obj_payments = $this->load_api_instance('search_payments_by_order', '2.0');
     $count_goods = 0;
     $goods_id = array();
     if (!$s_status) {
         if (!empty($s_bn)) {
             $where = array();
             $where[] = 'g.goods_id = p.goods_id';
             $where[] = 'p.bn LIKE \'' . $s_bn . '%\'';
             $where[] = 'g.marketable="true"';
             $where[] = 'g.disabled="false"';
             $filter = $this->_filter($where, $data);
             $goods_list_bn = $this->db->select('SELECT DISTINCT g.goods_id,g.cat_id,g.brand_id FROM sdb_goods AS g, sdb_products AS p' . $filter);
         } else {
             $goods_list_bn = array();
         }
         if ($goods_list_bn) {
             //搜索货号是否有搜索结果
             if (count($goods_list_bn) > 10) {
                 //超过10个搜索结果,按商品名称搜索
                 $where = array();
                 $where[] = 'g.goods_id = p.goods_id';
                 $where[] = 'p.bn LIKE \'' . $s_bn . '%\'';
                 $where[] = 'p.name LIKE \'%' . $s_name . '%\'';
                 $where[] = 'g.marketable="true"';
                 $where[] = 'g.disabled="false"';
                 $filter = $this->_filter($where, $data);
                 $goods_list_name = $this->db->select('SELECT DISTINCT g.goods_id,g.cat_id,g.brand_id FROM sdb_goods AS g, sdb_products AS p' . $filter);
                 if ($goods_list_name) {
                     //货品名称搜索有结果
                     $tmp_goods_list = $this->db->select('SELECT DISTINCT g.goods_id FROM sdb_goods AS g, sdb_products AS p where g.goods_id = p.goods_id and g.marketable="true" and g.disabled="false" and p.bn LIKE \'' . $s_bn . '%\' and p.name LIKE \'%' . $s_name . '%\'');
                     $count_goods = count($tmp_goods_list);
                     $goods_list = $goods_list_name;
                 } else {
                     //
                     $tmp_goods_list = $this->db->select('SELECT DISTINCT g.goods_id FROM sdb_goods AS g, sdb_products AS p where g.goods_id = p.goods_id and g.marketable="true" and g.disabled="false" and p.bn LIKE \'' . $s_bn . '%\'');
                     $count_goods = count($tmp_goods_list);
                     $goods_list = $goods_list_bn;
                 }
             } else {
                 $tmp_goods_list = $this->db->select('SELECT DISTINCT g.goods_id FROM sdb_goods AS g, sdb_products AS p where g.goods_id = p.goods_id and g.marketable="true" and g.disabled="false" and p.bn LIKE \'' . $s_bn . '%\'');
                 $count_goods = count($tmp_goods_list);
                 $goods_list = $goods_list_bn;
             }
         } else {
             //货号搜不到,搜商品名称
             if (!empty($s_name)) {
                 $where = array();
                 $where[] = 'g.goods_id = p.goods_id';
                 $where[] = 'p.name LIKE \'%' . $s_name . '%\'';
                 $where[] = 'g.marketable="true"';
                 $where[] = 'g.disabled="false"';
                 $filter = $this->_filter($where, $data);
                 $goods_list_name = $this->db->select('SELECT DISTINCT g.goods_id,g.cat_id,g.brand_id FROM sdb_goods AS g, sdb_products AS p' . $filter);
             } else {
                 $goods_list_name = array();
             }
             $tmp_goods_list = $this->db->select('SELECT DISTINCT g.goods_id FROM sdb_goods AS g, sdb_products AS p where g.goods_id = p.goods_id and g.marketable="true" and g.disabled="false" and p.name LIKE \'%' . $s_name . '%\'');
             $count_goods = count($tmp_goods_list);
             if ($goods_list_name) {
                 //有结果
                 $goods_list = $goods_list_name;
             } else {
                 //无结果
                 $goods_list = array();
             }
         }
     } else {
         if (!empty($s_bn)) {
             $goods_list = $this->db->select('SELECT DISTINCT g.goods_id,g.cat_id,g.brand_id FROM sdb_goods AS g, sdb_products AS p where g.goods_id = p.goods_id and g.marketable="true" and g.disabled="false" and p.bn=\'' . $s_bn . '\'');
         } else {
             if (!empty($s_name)) {
                 $goods_list = $this->db->select('SELECT DISTINCT g.goods_id,g.cat_id,g.brand_id FROM sdb_goods AS g, sdb_products AS p where g.goods_id = p.goods_id and g.marketable="true" and g.disabled="false" and p.name=\'' . $s_name . '\'');
             } else {
                 $goods_list = false;
             }
         }
         if ($goods_list) {
             $count_goods = 1;
         }
     }
     if (!empty($goods_list)) {
         //检查会员的代销权限
         $goods_list = $this->_checkDealerPurview($member, $goods_list);
         //检查会员的代销权限
         foreach ($goods_list as $k => $goods_info) {
             //删除没有代销权限的商品
             if ($goods_info['is_dealer'] == true) {
                 $goods_id[] = $goods_info['goods_id'];
             }
         }
         if (count($goods_id) == 1) {
             $is_compare = true;
         } else {
             $is_compare = false;
         }
         $return = array();
         foreach ($goods_id as $k => $v) {
             $goods_info = $this->db->selectrow("SELECT g.bn,g.name,g.brand,c.cat_name,g.thumbnail_pic,g.spec,g.spec_desc,g.pdt_desc FROM sdb_goods AS g,sdb_goods_cat AS c WHERE g.goods_id=" . $v . " AND g.cat_id=c.cat_id");
             $return[$k]['bn'] = $goods_info['bn'];
             $return[$k]['name'] = $goods_info['name'];
             $return[$k]['brand'] = $goods_info['brand'];
             $return[$k]['cat_name'] = $goods_info['cat_name'];
             $return[$k]['link'] = $this->system->base_url() . "index.php?ctl=product&p[0]=" . $v;
             $thumbnail_pic = explode("|", $goods_info['thumbnail_pic']);
             $return[$k]['thumbnail_pic'] = empty($goods_info['thumbnail_pic']) ? "" : (count($thumbnail_pic) == 3 ? $this->system->base_url() . $thumbnail_pic[0] : $thumbnail_pic[0]);
             $spec = unserialize($goods_info['spec']);
             $spec_desc = unserialize($goods_info['spec_desc']);
             $pdt_desc = unserialize($goods_info['pdt_desc']);
             $return[$k]['pdt'] = array();
             //if(!empty($pdt_desc)){
             $product_info = $this->db->select("SELECT product_id,bn,name,props,weight,store,freez,price FROM sdb_products WHERE goods_id=" . $v);
             foreach ($product_info as $product) {
                 $tmp_product = array();
                 $tmp_product['bn'] = $product['bn'];
                 $tmp_product['name'] = $product['name'];
                 $tmp_product['weight'] = $product['weight'];
                 $tmp_product['store'] = $product['store'];
                 $tmp_product['freez'] = $product['freez'];
                 $tmp_product['member_price'] = $obj_payments->changer($this->get_product_lv_price($member['member_lv_id'], $product['product_id'], $product['price']));
                 $tmp_product['default'] = 'false';
                 $props = unserialize($product['props']);
                 if (!empty($pdt_desc)) {
                     if ($is_compare) {
                         if ($s_bn == $product['bn']) {
                             $tmp_product['default'] = 'true';
                         } else {
                             foreach ($props['spec'] as $spec_id => $spec) {
                                 if ($spec == $s_specvalue) {
                                     $tmp_product['default'] = 'true';
                                     break;
                                 }
                             }
                         }
                     }
                 } else {
                     $tmp_product['default'] = 'true';
                 }
                 foreach ($props['spec'] as $spec_id => $spec) {
                     $spec_info = $this->db->selectrow("SELECT spec_name,spec_type FROM sdb_specification WHERE spec_id=" . $spec_id);
                     $spec_name = $spec_info['spec_name'];
                     $spec_type = $spec_info['spec_type'];
                     $tmp_product['props'][$spec_id]['spec_name'] = $spec_name;
                     $tmp_product['props'][$spec_id]['spec_type'] = $spec_type;
                     $spec_value_id = $props['spec_value_id'][$spec_id];
                     $spec_private_value_id = $props['spec_private_value_id'][$spec_id];
                     $spec_value_info = $this->db->selectrow("SELECT spec_value,spec_image FROM sdb_spec_values WHERE spec_value_id=" . $spec_value_id);
                     $spec_image = explode("|", $spec_value_info['spec_image']);
                     $spec_value_name = $spec_desc[$spec_id][$spec_private_value_id]['spec_value'];
                     $tmp_product['props'][$spec_id]['spec_value'] = array($spec_value_id => array('spec_value_name' => $spec_value_name, 'spec_image' => empty($spec_value_info['spec_image']) ? "" : (count($spec_image) == 3 ? $this->system->base_url() . $spec_image[0] : $spec_image[0])));
                     $tmp_product['props'][$spec_id]['spec_value'][$spec_value_id]['spec_goods_images'] = array();
                     if (!empty($spec_desc[$spec_id][$spec_private_value_id]['spec_goods_images'])) {
                         $spec_goods_image_ids = explode(",", $spec_desc[$spec_id][$spec_private_value_id]['spec_goods_images']);
                         foreach ($spec_goods_image_ids as $spec_goods_image_id) {
                             $gimage_info = $this->db->selectrow("SELECT thumbnail FROM sdb_gimages WHERE gimage_id=" . $spec_goods_image_id);
                             $thumbnail = explode("|", $gimage_info['thumbnail']);
                             $tmp_product['props'][$spec_id]['spec_value'][$spec_value_id]['spec_goods_images'][$spec_goods_image_id] = empty($gimage_info['thumbnail']) ? "" : (count($thumbnail) == 3 ? $this->system->base_url() . $thumbnail[0] : $thumbnail[0]);
                         }
                     }
                 }
                 $return[$k]['pdt'][$product['product_id']] = $tmp_product;
             }
             //}
             $return[$k]['count'] = $count_goods;
         }
     } else {
         $return = "";
     }
     $result['data_info'] = $return;
     $this->api_response('true', false, $result);
 }
コード例 #4
0
ファイル: api_b2b_2_0_product.php プロジェクト: noikiy/MyShop
 /**
  * 冻结库存
  *
  * @param int $product_id
  * @param int $store
  *
  * @return 冻结库存
  */
 function update_product_store($bn, $store, $flag = 'freeze')
 {
     safeVar($bn);
     $product = $this->db->selectrow('select product_id,store,freez from sdb_products where bn="' . $bn . '"');
     if ($product) {
         $freez = $product['freez'];
         if (is_null($freez)) {
             $this->db->exec('UPDATE sdb_products SET freez = 0 WHERE bn = "' . $bn . '" AND freez IS NULL');
             $freez = 0;
         }
         if ($flag == 'freeze') {
             $this->db->exec('UPDATE sdb_products SET freez = freez + ' . intval($store) . ' WHERE bn = "' . $bn . '"');
         } else {
             if ($freez < $store) {
                 if ($freez != 0) {
                     $this->db->exec('UPDATE sdb_products SET freez = 0 WHERE bn = "' . $bn . '"');
                 }
             } else {
                 $this->db->exec('UPDATE sdb_products SET freez = freez - ' . intval($store) . ' WHERE bn = "' . $bn . '"');
             }
         }
     }
 }
コード例 #5
0
ファイル: api_b2b_1_0_product.php プロジェクト: noikiy/cxe
 /**
  * 下采购单过滤无效的商品数据,并组织数据提供给order_item
  *
  * @param array $member 
  * @param array $arr_order_item 
  *
  * @return boolean
  */
 function filter_product_invalid($member, $arr_order_item, &$filter_order_item)
 {
     if (is_array($arr_order_item) && count($arr_order_item) > 0) {
         safeVar($arr_order_item);
         $arr_goods = array();
         $is_buy = false;
         foreach ($arr_order_item as $k => $order_item) {
             $product = $this->db->selectrow('select goods_id,product_id,store,freez,pdt_desc,name,weight,cost,price,disabled from sdb_products where bn="' . $order_item['supplier_bn'] . '"');
             if (!$product) {
                 //验证订单货品是否存在
                 $this->api_response('fail', 'data fail', $result, '订单货品(' . $order_item['supplier_bn'] . ')不存在');
             }
             if (!isset($arr_goods[$product['goods_id']])) {
                 $goods = $this->db->selectrow('select goods_id,cat_id,brand_id,type_id,marketable,disabled from sdb_goods where goods_id=' . intval($product['goods_id']));
                 if (!$goods) {
                     //验证订单货品的商品是否存在
                     $this->api_response('fail', 'data fail', $result, '订单商品(' . $product['goods_id'] . ')不存在');
                 }
                 $arr_goods[$product['goods_id']] = $goods;
             }
             if ($arr_goods[$product['goods_id']]['marketable'] == 'false' || $arr_goods[$product['goods_id']]['disabled'] == 'true') {
                 //验证订单商品是否发布
                 $this->api_response('fail', 'data fail', $result, '订单商品(' . $product['goods_id'] . ')未发布不能下单');
             }
             if ($product['disabled'] == 'true') {
                 //验证订单货品是否发布
                 $this->api_response('fail', 'data fail', $result, '订单货品(' . $order_item['supplier_bn'] . ')未发布不能下单');
             }
             if ($product['price'] != $order_item['price']) {
                 //验证订单价格与供货商价格是否一致
                 $this->api_response('fail', 'data fail', $result, '订单货品(' . $order_item['supplier_bn'] . ')供应商价格或者库存变动,请重新询价后下单');
             }
             $product['freez'] = !is_null($product['freez']) ? $product['freez'] : 0;
             if ($product['store'] === 0) {
                 //验证订单上货品是否有库存
                 //$this->api_response('fail','data fail',$result,'订单货品('.$order_item['supplier_bn'].')无库存');
                 continue;
             }
             if (!is_null($product['store'])) {
                 if ($product['store'] - $product['freez'] <= 0) {
                     //检查货品是否有可下单库存
                     //$this->api_response('fail','data fail',$result,'订单货品('.$order_item['supplier_bn'].')没有可下单库存');
                     continue;
                 }
             }
             if (!is_null($product['store']) && $order_item['nums'] > $product['store'] - $product['freez']) {
                 $order_item['nums'] = $product['store'] - $product['freez'];
                 //有多少库存就下多少库存
             }
             $product = array_merge($product, $order_item);
             $product['type_id'] = $goods['type_id'];
             //商品类型ID
             $product['amount'] = $order_item['nums'] * $order_item['price'];
             //货品总价
             $product['amount_weight'] = $order_item['nums'] * $product['weight'];
             //货品总重
             $product['score'] = 0;
             //积分默认为0
             $product['bn'] = $order_item['supplier_bn'];
             //经销商货号
             $product['name'] = $product['pdt_desc'] ? $product['name'] . '(' . $product['pdt_desc'] . ')' : $product['name'];
             $is_buy = true;
             unset($product['store']);
             unset($product['freez']);
             $filter_order_item[$k] = $product;
         }
         if (!$is_buy) {
             $this->api_response('fail', 'data fail', $result, '供应商价格或者库存变动,请重新询价后下单');
         }
         $obj_product_line = $this->load_api_instance('search_product_line', '1.0');
         $obj_product_line->checkDealerPurview($member, $arr_goods);
         //检查会员的代销权限
     } else {
         $this->api_response('fail', 'data fail', $result, '同步订单商品数据不存在');
     }
 }