shopDeliveryModel = new ShopDeliveryModel(); if (!str_contains($this->userinfo['role'], "4")) { $this->error(__('没有权限' . $this->userinfo['role'])); } } //首页 public function index(StockConfig $stockConfig) { $data = []; $data['today'] = ScanLog::where('user_id', $this->userinfo['id'])->whereTime('createtime', 'today')->count(); $data['yesterday'] = ScanLog::where('user_id', $this->userinfo['id'])->whereTime('createtime', 'yesterday')->count(); $this->success('ok', $data); } //添加出入库 public function scan(ScanLog $scanLog) { $data = $this->request->post(); $result = false; Db::startTrans(); $insert_data = []; try { validate(WorkerValidate::class)->scene('scan')->check($data); //$resData = $stockService::setGoOutStock($this->userinfo['id'], $data); $time = time(); $insert_data = [ 'user_id' => $this->userinfo['id'], 'code' => $data['code'], 'order_status' => 0, 'remark' => '未找到单号', 'order_data' => [], 'createtime'=>date('Y-m-d H:i:s',$time) ]; $sql_data = $this->shopDeliveryModel->where('waybill_no', $data['code'])->find(); if (!empty($sql_data)) { $result = $sql_data->save([ 'user_id' => $this->userinfo['id'], 'entry_time' => $time, 'updatetime' => $time ]); if ($result) { $insert_data['order_status'] = 1; $insert_data['remark'] = '录入成功'; } else { $insert_data['remark'] = '录入失败'; } $entry_time=$sql_data['entry_time']; if(!empty($sql_data['entry_time'])){ $entry_time=date('Y-m-d H:i:s',$sql_data['entry_time']); } switch ($sql_data['incubator']) { case 1: $sql_data['incubator_title']='单层保温'; break; case 2: $sql_data['incubator_title']='双层保温'; break; default: $sql_data['incubator_title']='不是保温箱'; break; } $sql_data['entry_time']=$entry_time; $insert_data['order_data']=$sql_data; } $result = $scanLog->save($insert_data); Db::commit(); } catch (ValidateException $e) { return $this->error($e->getError()); } catch (\Exception $e) { Db::rollback(); $this->error($e->getMessage()); } if ($result === false) { $this->error(__('没有新增任何数据')); } $this->success('', $insert_data); } //扫描记录 public function scanlog(ScanLog $scanLog) { $where = []; $limit = $this->request->post('limit/d', 10); //条数 $time = $this->request->post('create_time/s'); //日期 if (!empty($type)) $where[] = ['a.type', '=', $type]; if (!empty($type_id)) $where[] = ['a.type_id', '=', $type_id]; if (!empty($spec_id)) $where[] = ['a.variety_id', '=', $spec_id]; if (!empty($time)) { $arr = explode(',', $time); $where[] = ['a.createtime', '>=', strtotime($arr[0])]; $where[] = ['a.createtime', '<=', strtotime($arr[1])]; } $list = ScanLog::where('user_id', $this->userinfo['id']) ->whereTime('createtime', 'today') ->order('id desc') ->paginate($limit); $this->success('ok', $list); } }