Outwarehouse.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3. class Outwarehouse extends Lyapi_Controller{
  4. private $show_url = "https://lyerposs.wepolicy.cn";
  5. // 注意:登录接口不能受基础控制器的登录校验,可以覆盖构造方法或单独处理
  6. public function __construct() {
  7. // 这里不执行登录校验,只加载缓存驱动
  8. parent::__construct(); // 暂时注释,或者使用一个新的不校验的基类
  9. // 简便做法:复制 Lyapi_Controller 的部分代码但不调用 _check_api_auth
  10. // $this->load->driver('cache'); // 加载缓存驱动
  11. $this->load->_model("Model_logic_order","logic_order");
  12. }
  13. public function ckct() {
  14. $this->_json_error("获取成功",200,[]);
  15. }
  16. public function savescan(){
  17. if($this->input->method(TRUE) != 'POST'){
  18. $this->_json_error('请求方式错误','500');
  19. }
  20. $json_str = $this->input->raw_input_stream;
  21. $data = json_decode($json_str,true);
  22. if(empty($data['number'])){
  23. $this->_json_error('参数错误','500');
  24. }
  25. $imglist = $data['imglist'];
  26. if(empty($imglist)){
  27. $this->_json_error('未上传出库图片','500');
  28. }
  29. foreach($imglist as $k => $v){
  30. $imglist[$k] = str_replace($this->show_url, '', $v);
  31. }
  32. $orderinfo = $this->logic_order->getInfo("number = '".$data['number']."'");
  33. if(empty($orderinfo)){
  34. $this->_json_error('订单不存在','500');
  35. }
  36. if($orderinfo['waybill'] != $data['waybill']){
  37. $this->_json_error('运单号和数据库存储不一致','500');
  38. }
  39. $query = $this->db->get_where('scanimgs', ['number' => $data['number']]);
  40. $info = $query->row_array();
  41. if(!empty($info)){
  42. $img_list = json_decode($info['imgs'],true);
  43. $time = time();
  44. array_unshift($img_list,['imgurl'=>$imglist,'addtime'=>$time]);
  45. $this->db->where('id',$info['id'])->update('scanimgs', [
  46. 'imgs' => json_encode($img_list),
  47. 'updatetime' => $time]
  48. );
  49. if($this->db->affected_rows() > 0){
  50. $this->_json_error('保存成功','200');
  51. }else{
  52. $this->_json_error('保存失败','500');
  53. }
  54. }else{
  55. $time = time();
  56. $img_list = [
  57. [
  58. "imgurl"=>$imglist,
  59. "addtime"=>$time
  60. ]
  61. ];
  62. $res = $this->db->insert(
  63. 'scanimgs',
  64. [
  65. 'number' => $orderinfo['number'],
  66. 'shop'=>$orderinfo['shop'],
  67. 'plat'=>$orderinfo['lv_platform'],
  68. 'addtime'=>$time,
  69. "imgs"=>json_encode($img_list),
  70. 'updatetime'=>$time,
  71. ]
  72. );
  73. if($res){
  74. $this->_json_error('保存成功','200');
  75. }else{
  76. $this->_json_error('保存失败','500');
  77. }
  78. }
  79. }
  80. }