load->driver('cache'); // 加载缓存驱动 $this->load->_model("Model_logic_order","logic_order"); } public function ckct() { $this->_json_error("获取成功",200,[]); } public function savescan(){ if($this->input->method(TRUE) != 'POST'){ $this->_json_error('请求方式错误','500'); } $json_str = $this->input->raw_input_stream; $data = json_decode($json_str,true); if(empty($data['number'])){ $this->_json_error('参数错误','500'); } $imglist = $data['imglist']; if(empty($imglist)){ $this->_json_error('未上传出库图片','500'); } foreach($imglist as $k => $v){ $imglist[$k] = str_replace($this->show_url, '', $v); } $orderinfo = $this->logic_order->getInfo("number = '".$data['number']."'"); if(empty($orderinfo)){ $this->_json_error('订单不存在','500'); } if($orderinfo['waybill'] != $data['waybill']){ $this->_json_error('运单号和数据库存储不一致','500'); } $query = $this->db->get_where('scanimgs', ['number' => $data['number']]); $info = $query->row_array(); if(!empty($info)){ $img_list = json_decode($info['imgs'],true); $time = time(); array_unshift($img_list,['imgurl'=>$imglist,'addtime'=>$time]); $this->db->where('id',$info['id'])->update('scanimgs', [ 'imgs' => json_encode($img_list), 'updatetime' => $time] ); if($this->db->affected_rows() > 0){ $this->_json_error('保存成功','200'); }else{ $this->_json_error('保存失败','500'); } }else{ $time = time(); $img_list = [ [ "imgurl"=>$imglist, "addtime"=>$time ] ]; $res = $this->db->from('scanimgs')->insert( [ 'number' => $orderinfo['number'], 'shop'=>$orderinfo['shop'], 'plat'=>$orderinfo['lv_platform'], 'addtime'=>$time, "imgs"=>json_encode($img_list), 'updatetime'=>$time, ] ); if($res){ $this->_json_error('保存成功','200'); }else{ $this->_json_error('保存失败','500'); } } } }