数组处理:根据不同数据库的来源信息,商户进行挑选购入后的统一操作

    xiaoxiao2021-04-18  67

    平台上的商品数据来自于两个互不相干的数据库,事前经过中间表进行统一处理,现在进行商户对挑选加入到自身商户商品表的操作。

    直接贴代码,同样有每行解析,重要的是想出来的一种想法。

    public function add_ik(){//添加ttp到整合表 $fr_present_id=$this->input->post("fr_present_id");//接收status+goods_id+来源的库ttp还是llf+#号 //echo $fr_present_id; $goods_id=str_replace(",","",$fr_present_id);//因为是传递多个,用逗号进行分割,所以进行对逗号的取代 $cat=substr($goods_id,-4,3);//判断来源ttp还是llf //$status=substr($goods_id,-1,1); //$goods_id=str_replace("$status","",$goods_id); $hh=explode("#",$goods_id);//#号来做区分划分 $hh=array_filter($hh);//过滤空数组 //print_r($hh); $lijunsheng=array();//开新数组 //$goods_info = array(); foreach ($hh as $value) { $status=substr($value,0,1); if ($status=="2") {//这个是状态,2为没选择过的商品 $cat=substr($value,-3,3);//这个是源自哪个数据库的商品 if ($cat=="llf") {//区分处理,这个是app的数据 $goods_info = array(); $value=str_replace("$cat","",$value); $value=substr($value,1,5); $where=array('gallery_id'=>$value); $llf_info=$this->gallery_model->getone_llf($where); //print_r($llf_info); $goods_info['goods_id']=$llf_info['gallery_id']."llf";//有做删减 $goods_info['goods_sn']=$llf_info['present_no']; $goods_info['goods_name']=$llf_info['name']; $goods_info['marketPrice']=$llf_info['price']; $goods_info['costPrice']=$llf_info['sell_price']; $goods_info['desc']=$llf_info['order_by']; $goods_info['cat_id']=$llf_info['type_ids']; $goods_info['original_img']=$llf_info['images']; //print_r($goods_info); //die; $insert_id=$this->gallery_model->shangjia_add_goods($goods_info); $lijunsheng[]=$insert_id; //die; } else {//这个是平台自身的数据 $value=str_replace("$cat","",$value); $value=substr($value,1,5); $where=array('goods_id'=>$value); $goods_info=$this->gallery_model->getone($where);//通过查商品数据库然后将信息带回到商户的商品库中 $goods_info['goods_id']=$goods_info['goods_id']."ttp"; //print_r( $goods_info); $insert_id=$this->gallery_model->shangjia_add_goods($goods_info); $lijunsheng[]=$insert_id; } } } if($lijunsheng != null){ exit("2"); }else{ exit("1"); } }

    转载请注明原文地址: https://ju.6miu.com/read-675490.html

    最新回复(0)