| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <?php
- defined('BASEPATH') OR exit('No direct script access allowed');
- class Outwarehouse extends Lyapi_Controller{
- private $show_url = "https://lyerposs.wepolicy.cn";
- // 注意:登录接口不能受基础控制器的登录校验,可以覆盖构造方法或单独处理
- public function __construct() {
- // 这里不执行登录校验,只加载缓存驱动
- parent::__construct(); // 暂时注释,或者使用一个新的不校验的基类
- // 简便做法:复制 Lyapi_Controller 的部分代码但不调用 _check_api_auth
- // $this->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');
- }
- }
- }
- }
|