|
|
@@ -0,0 +1,535 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace app\admin\controller;
|
|
|
+
|
|
|
+use app\admin\model\QcodeLarge;
|
|
|
+use app\admin\model\QcodeSmall;
|
|
|
+use app\common\controller\Backend;
|
|
|
+use app\admin\model\QcodeProduct;
|
|
|
+use app\admin\model\QcodeCompany;
|
|
|
+use app\admin\model\QcodeBach;
|
|
|
+use app\admin\model\QcodeExport;
|
|
|
+use fast\Arr;
|
|
|
+use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
|
+use PhpOffice\PhpSpreadsheet\Style\Alignment;
|
|
|
+use PhpOffice\PhpSpreadsheet\Exception;
|
|
|
+use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
|
|
+use app\admin\model\QcodeGoods;
|
|
|
+use think\Session;
|
|
|
+
|
|
|
+class Deliver extends Backend
|
|
|
+{
|
|
|
+ /**
|
|
|
+ * 首页
|
|
|
+ * @return string|\think\response\Json
|
|
|
+ * @throws \think\Exception
|
|
|
+ */
|
|
|
+ public function index()
|
|
|
+ {
|
|
|
+ return $this->view->fetch();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 大件发货列表
|
|
|
+ * @return string|\think\response\Json
|
|
|
+ * @throws \think\Exception
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
+ * @throws \think\exception\DbException
|
|
|
+ */
|
|
|
+ public function lager()
|
|
|
+ {
|
|
|
+ $company = new QcodeCompany();
|
|
|
+ $product = new QcodeProduct();
|
|
|
+ $large = new QcodeLarge();
|
|
|
+ $bach = new QcodeBach();
|
|
|
+ $small = new QcodeSmall();
|
|
|
+ $this->request->filter(['strip_tags', 'trim']);
|
|
|
+ if (false === $this->request->isAjax()) {
|
|
|
+ return $this->view->fetch();
|
|
|
+ }
|
|
|
+ if ($this->request->request('keyField')) {
|
|
|
+ return $this->selectpage();
|
|
|
+ }
|
|
|
+ // 接收参数
|
|
|
+ $userInfo = Session::get('admin');
|
|
|
+ $where = [
|
|
|
+ 'delete_time'=> ''
|
|
|
+ ];
|
|
|
+ $filter = input('filter');
|
|
|
+ $filter = json_decode($filter,true);
|
|
|
+ $whereList = [
|
|
|
+ 'delete_time'=>'',
|
|
|
+ ];
|
|
|
+ //样品编号查询
|
|
|
+ if (isset($filter['matter_name'])){
|
|
|
+ $whereList['matter_no'] =$filter['matter_name'];
|
|
|
+ }
|
|
|
+ if (isset($filter['bach'])){
|
|
|
+ $whereList['bach_num'] = $filter['bach'];
|
|
|
+ }
|
|
|
+ if (isset($filter['manufacture_date'])){
|
|
|
+ $begin = substr($filter['manufacture_date'],0,19);
|
|
|
+ $end = substr($filter['manufacture_date'],22);
|
|
|
+ $begin = (int)date('ymd',strtotime($begin));
|
|
|
+ $end = (int)date('ymd',strtotime($end));
|
|
|
+ $whereList['manufacture_date'] = ['between',[$begin,$end]];
|
|
|
+ }
|
|
|
+
|
|
|
+ $bach_list = $bach->name($userInfo['company'].'_'.'qcode_bach')->where($whereList)->column('_id');
|
|
|
+ $bach_id = [];
|
|
|
+ foreach ($bach_list as $v){
|
|
|
+ $id = substr(json_encode($v),9,-2);
|
|
|
+ array_push($bach_id,$id);
|
|
|
+ }
|
|
|
+ $order = input('order');
|
|
|
+ $offset = input('offset');
|
|
|
+ $limit = input('limit');
|
|
|
+ $total = $large->name($userInfo['company'].'_'.'qcode_large')->where($where)->whereIn('bach_id',$bach_id)->count();
|
|
|
+ $large_list = $large->name($userInfo['company'].'_'.'qcode_large')
|
|
|
+ ->order('creat_time',$order)
|
|
|
+ ->where($where)
|
|
|
+ ->whereIn('bach_id',$bach_id)
|
|
|
+ ->skip($offset)
|
|
|
+ ->limit($limit)
|
|
|
+ ->select();
|
|
|
+ $list=[];
|
|
|
+ foreach ($large_list as $k=>$v) {
|
|
|
+ $bach_detail = $bach->name($userInfo['company'].'_'.'qcode_bach')->where('_id',$v['bach_id'])->find();
|
|
|
+ $list[$k]['id'] = substr(json_encode($v['_id']),9,-2);
|
|
|
+ $list[$k]['bach'] = $bach_detail['bach_num'];
|
|
|
+ $list[$k]['l_flow'] = $bach_detail['l_flow']+$k;
|
|
|
+ $list[$k]['matter_name'] = $bach_detail['matter_name'];
|
|
|
+ $list[$k]['manufacture_date'] = date('Y-m-d',strtotime('20'.$bach_detail['manufacture_date']));
|
|
|
+ $list[$k]['code'] = $v['code'];
|
|
|
+ $small_num = $small->name($userInfo['company'].'_'.'qcode_small')->where('large_id',substr(json_encode($v['_id']),9,-2))->count();
|
|
|
+ $list[$k]['small_num'] = $small_num;
|
|
|
+ }
|
|
|
+ $result = ['total'=>$total,'rows'=>$list];
|
|
|
+ return json($result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 小件列表
|
|
|
+ * @return \think\response\Json
|
|
|
+ * @throws \think\Exception
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
+ * @throws \think\exception\DbException
|
|
|
+ */
|
|
|
+ public function smallList()
|
|
|
+ {
|
|
|
+ $userinfo = Session::get('admin');
|
|
|
+ $lager = new QcodeLarge();
|
|
|
+ $small = new QcodeSmall();
|
|
|
+ if ($this->request->isAjax() === false){
|
|
|
+ $this->error('请求错误');
|
|
|
+ }
|
|
|
+ $lager_list = input('search');
|
|
|
+ $order = input('order');
|
|
|
+ $offset = input('offset');
|
|
|
+ $limit = input('limit');
|
|
|
+ $lagerList = explode(',',$lager_list);
|
|
|
+ $smallList = $small->name($userinfo['company'].'_'.'qcode_small')
|
|
|
+ ->whereIn('large_id',$lagerList)
|
|
|
+// ->order('l_flow',$order)
|
|
|
+ ->skip($offset)
|
|
|
+ ->limit($limit)
|
|
|
+ ->select();
|
|
|
+ $total = $small->name($userinfo['company'].'_'.'qcode_small')->whereIn('large_id',$lagerList)->count();
|
|
|
+ $list = [];
|
|
|
+ foreach ($smallList as $k=>$v){
|
|
|
+ $list[$k] = [
|
|
|
+ 'code' => $v['code'],
|
|
|
+ 'l_flow' => $v['l_flow'],
|
|
|
+ 'print_num' => $v['p_nums'],
|
|
|
+ 'status' => $v['status'],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ return json(['total'=>$total,'rows'=>$list]);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导出发货
|
|
|
+ * @return void
|
|
|
+ * @throws \think\Exception
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
+ * @throws \think\exception\DbException
|
|
|
+ */
|
|
|
+ public function print()
|
|
|
+ {
|
|
|
+ $userinfo = Session::get('admin');
|
|
|
+ $lager = new QcodeLarge();
|
|
|
+ $bach = new QcodeBach();
|
|
|
+ $small = new QcodeSmall();
|
|
|
+ $export = new QcodeExport();
|
|
|
+ if ($this->request->isAjax() === false){
|
|
|
+ $this->error('请求错误');
|
|
|
+ }
|
|
|
+ $lager_id = input('lager_id');
|
|
|
+ if ($lager_id === ''){
|
|
|
+ $this->error('请至少选择一个大件');
|
|
|
+ }
|
|
|
+ $lagerId = [];
|
|
|
+ if (strpos($lager_id,',') === false){
|
|
|
+ $lagerId[0] = $lager_id;
|
|
|
+ }else{
|
|
|
+ $lagerId = explode(',',$lager_id);
|
|
|
+ }
|
|
|
+ $lager_num = count($lagerId);
|
|
|
+ $bach_id = [];
|
|
|
+ foreach ($lagerId as $k=>$v){
|
|
|
+ $lagerList = $lager->name($userinfo['company'].'_'.'qcode_large')->where('_id',$v)->find();
|
|
|
+ $bachList = $bach->name($userinfo['company'].'_'.'qcode_bach')->where('_id',$lagerList['bach_id'])->find();
|
|
|
+ $bach_id[$k] = substr(json_encode($bachList['_id']),9,-2);
|
|
|
+ }
|
|
|
+ $bach_id = array_unique($bach_id);
|
|
|
+ $data = [];
|
|
|
+ foreach ($bach_id as $k=>$v){
|
|
|
+ $m = 1;$n =0;
|
|
|
+ $large_str = '';
|
|
|
+ foreach ($lagerId as $key=>$value){
|
|
|
+ $lagerList = $lager->name($userinfo['company'].'_'.'qcode_large')->where('_id',$value)->find();
|
|
|
+ if($v === $lagerList['bach_id']){
|
|
|
+ $m++;
|
|
|
+ $large_str = $large_str.substr(json_encode($lagerList['_id']),9,-2).',';
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ $large_str = substr($large_str,0,strlen($large_str)-1);
|
|
|
+ foreach (explode(',',$large_str) as $kk=>$vv){
|
|
|
+ $n = $n + $small->name($userinfo['company'].'_'.'qcode_small')->where('large_id',$vv)->count();
|
|
|
+ }
|
|
|
+ $bachDetail = $bach->name($userinfo['company'].'_'.'qcode_bach')->where('_id',$v)->find();
|
|
|
+ if ($bachDetail['box_num'] === 1){
|
|
|
+ $mater_type = 2;
|
|
|
+ }else{
|
|
|
+ $mater_type = 1;
|
|
|
+ }
|
|
|
+// $file_dir = $this->exportExcel($v,$large_str,$userinfo['company'],$m,$n);
|
|
|
+ $data[$k] = [
|
|
|
+ 'username' => $bachDetail['supplier_name'],
|
|
|
+ 'matter_name' => $bachDetail['matter_name'],
|
|
|
+ 'matter_no' => $bachDetail['matter_no'],
|
|
|
+ 'large_str' => $large_str,
|
|
|
+ 'large_num' => $lager_num,
|
|
|
+ 'small_num' => $n,
|
|
|
+ 'status' => 0,
|
|
|
+ 'num' => $bachDetail['s_weight'],
|
|
|
+ 'bach_num' => $bachDetail['bach_num'],
|
|
|
+ 'mater_type' => $mater_type,
|
|
|
+ 'note' => '',
|
|
|
+ 'user_id' => $userinfo['id'],
|
|
|
+ 'create_time' => time(),
|
|
|
+ 'file_dir' => '',
|
|
|
+ 'company_id' => $userinfo['company'],
|
|
|
+ ];
|
|
|
+ $res = $export->save($data[$k]);
|
|
|
+ }
|
|
|
+ $this->success();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成excel
|
|
|
+ * @param $bach_id
|
|
|
+ * @param $large_str
|
|
|
+ * @param $company
|
|
|
+ * @param $large_num
|
|
|
+ * @param $small_num
|
|
|
+ * @return string
|
|
|
+ * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
+ * @throws \think\exception\DbException
|
|
|
+ */
|
|
|
+ public function exportExcel($bach_id,$large_str,$company,$large_num,$small_num)
|
|
|
+ {
|
|
|
+ $bach = new QcodeBach();
|
|
|
+ $large = new QcodeLarge();
|
|
|
+ $small = new QcodeSmall();
|
|
|
+ $bachList = $bach->name($company . '_' . 'qcode_bach')->where('_id', $bach_id)->find();
|
|
|
+ $data = [
|
|
|
+ 'supplier_name' => $bachList['supplier_name'],
|
|
|
+ 'supplier_no' => $bachList['supplier_code'],
|
|
|
+ 'matter_name' => $bachList['matter_name'],
|
|
|
+ 'matter_no' => $bachList['matter_no'],
|
|
|
+ 'manufacture_date' => $bachList['manufacture_date'],
|
|
|
+ 'print_date' => $bachList['print_date'],
|
|
|
+ 'box_num' => $large_num,
|
|
|
+ 'tray_num' => $bachList['tray_num'],
|
|
|
+ 'small_num' => $small_num,
|
|
|
+ 'l_reservation' => $bachList['l_reservation'],
|
|
|
+ 's_reservation' => $bachList['s_reservation'],
|
|
|
+ 'l_flow' => $bachList['l_flow'],
|
|
|
+ 's_flow' => $bachList['s_flow'],
|
|
|
+ 'l_weight' => $bachList['l_weight'],
|
|
|
+ 's_weight' => $bachList['s_weight'],
|
|
|
+ 'code' => [],
|
|
|
+ ];
|
|
|
+ $large_id = explode(',', $large_str);
|
|
|
+ foreach ($large_id as $k => $v) {
|
|
|
+ $largeList = $large->name($company . '_' . 'qcode_large')->where('_id', $v)->find();
|
|
|
+ $small_list = $small->name($company . '_' . 'qcode_small')->where('large_id', $v)->select();
|
|
|
+
|
|
|
+ foreach ($small_list as $value) {
|
|
|
+ $code = [
|
|
|
+ 'large_code' => $largeList['code'],
|
|
|
+ 'small_code' => $value['code'],
|
|
|
+ ];
|
|
|
+ $data['code'][] = $code;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $objexcel = new Spreadsheet();
|
|
|
+ $sheet = $objexcel->getActiveSheet();
|
|
|
+ //设置全局单元格垂直居中
|
|
|
+// $objexcel->getDefaultStyle()->getAlignment()->setVertical(Alignment::HORIZONTAL_CENTER);
|
|
|
+// //设置全局单元格水平居中
|
|
|
+// $objexcel->getDefaultStyle()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
|
|
|
+// //设置全局单元格自动换行
|
|
|
+// $objexcel->getDefaultStyle()->getAlignment()->setWrapText(true);
|
|
|
+ //设置单元格宽度
|
|
|
+ $sheet->getDefaultColumnDimension()->setWidth(25);
|
|
|
+ //设置表头
|
|
|
+// $sheet->setCellValue('A1', '文件流水号');
|
|
|
+// $sheet->setCellValue('A2', '订单号');
|
|
|
+// $sheet->setCellValue('A3', '供应商');
|
|
|
+// $sheet->setCellValue('A4', '供应商代码');
|
|
|
+// $sheet->setCellValue('A5', '物料名称');
|
|
|
+// $sheet->setCellValue('A6', '物料代码');
|
|
|
+// $sheet->setCellValue('A7', '生产日期');
|
|
|
+// $sheet->setCellValue('A8', '打码日期');
|
|
|
+// $sheet->setCellValue('A9', '大件数量');
|
|
|
+// $sheet->setCellValue('A10', '托盘小件数量');
|
|
|
+// $sheet->setCellValue('A11', '小件总数量');
|
|
|
+// $sheet->setCellValue('C3', '大件预留码');
|
|
|
+// $sheet->setCellValue('C5', '小件预留码');
|
|
|
+// $sheet->setCellValue('C7', '大件开始流水号');
|
|
|
+// $sheet->setCellValue('C9', '小件开始流水号');
|
|
|
+// $sheet->setCellValue('C11', '大件重量(Kg)');
|
|
|
+// $sheet->setCellValue('C13', '小件重量(Kg)');
|
|
|
+// $sheet->setCellValue('A15', '大件二维码');
|
|
|
+// $sheet->setCellValue('B15', '大件条码(预留)');
|
|
|
+// $sheet->setCellValue('C15', '小件二维码');
|
|
|
+// $sheet->setCellValue('D15', '小件条码(预留)');
|
|
|
+ //插入表格数据
|
|
|
+// $sheet->getCell('B3')->setValue(isset($data['supplier_name'])?$data['supplier_name']:'');
|
|
|
+// $sheet->getCell('B4')->setValue(isset($data['supplier_no'])?$data['supplier_no']:'');
|
|
|
+// $sheet->getCell('B5')->setValue(isset($data['matter_name'])?$data['matter_name']:'');
|
|
|
+// $sheet->getCell('B6')->setValue(isset($data['matter_no'])?$data['matter_no']:'');
|
|
|
+// $sheet->getCell('B7')->setValue(isset($data['manufacture_date'])?$data['manufacture_date']:'');
|
|
|
+// $sheet->getCell('B8')->setValue(isset($data['print_date'])?$data['print_date']:'');
|
|
|
+// $sheet->getCell('B9')->setValue(isset($data['box_num'])?$data['box_num']:'');
|
|
|
+// $sheet->getCell('B10')->setValue(isset($data['tray_num'])?$data['tray_num']:'');
|
|
|
+// $sheet->getCell('B11')->setValue(isset($data['small_num'])?$data['small_num']:'');
|
|
|
+// $sheet->getCell('C4')->setValue(isset($data['l_reservation'])?$data['l_reservation']:'');
|
|
|
+// $sheet->getCell('C6')->setValue(isset($data['s_reservation'])?$data['s_reservation']:'');
|
|
|
+// $sheet->getCell('C8')->setValue(isset($data['l_flow'])?$data['l_flow']:'');
|
|
|
+// $sheet->getCell('C10')->setValue(isset($data['s_flow'])?$data['s_flow']:'');
|
|
|
+// $sheet->getCell('C12')->setValue(isset($data['l_weight'])?$data['l_weight']:'');
|
|
|
+// $sheet->getCell('C14')->setValue(isset($data['s_flow'])?$data['s_flow']:'');
|
|
|
+// foreach ($data['code'] as $v){
|
|
|
+// $sheet->getCell('A16')->setValue(isset($v['large_code'])?$v['large_code']:'');
|
|
|
+// $sheet->getCell('B16')->setValue('');
|
|
|
+// $sheet->getCell('C16')->setValue(isset($v['small_code'])?$v['small_code']:'');
|
|
|
+// $sheet->getCell('D16')->setValue('');
|
|
|
+// }
|
|
|
+ //文件另存
|
|
|
+ $filename = date('Ymd',time()).rand(100,999).'_'.$data['supplier_name'].'_'.$data['matter_name'].'_'.$data['small_num'].'.xlsx';
|
|
|
+// $filename = iconv("utf-8","gb2312",$filename);
|
|
|
+ header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
|
|
+ header('Content-Disposition: attachment;filename="'.$filename.'"');
|
|
|
+ header('Cache-Control: max-age=0');
|
|
|
+ header("Content-Type:text/html;charset=utf-8");
|
|
|
+// if(is_dir(ROOT_PATH.'public/uploads/export/') == null)
|
|
|
+// {
|
|
|
+// mkdir(ROOT_PATH.'public/uploads/export/',0777,true);
|
|
|
+// }
|
|
|
+ $writer = new Xlsx($objexcel);
|
|
|
+// $writer->save($filename);
|
|
|
+ $writer->save(ROOT_PATH.'public/uploads/export'.DS.$filename);
|
|
|
+ return 'public/uploads/export/'.$filename;
|
|
|
+ }
|
|
|
+ //批次发货审批
|
|
|
+ public function apply()
|
|
|
+ {
|
|
|
+ $export = new QcodeExport();
|
|
|
+ $this->request->filter(['strip_tags', 'trim']);
|
|
|
+ if (false === $this->request->isAjax()) {
|
|
|
+ return $this->view->fetch();
|
|
|
+ }
|
|
|
+ if ($this->request->request('keyField')) {
|
|
|
+ return $this->selectpage();
|
|
|
+ }
|
|
|
+ // 接收参数
|
|
|
+ $userInfo = Session::get('admin');
|
|
|
+ $where = [
|
|
|
+ 'company_id' => $userInfo['company'],
|
|
|
+ 'delete_time'=> ''
|
|
|
+ ];
|
|
|
+ $filter = input('filter');
|
|
|
+ $filter = json_decode($filter,true);
|
|
|
+ //样品编号查询
|
|
|
+ if (isset($filter['matter_name'])){
|
|
|
+ $where['matter_no'] =$filter['matter_name'];
|
|
|
+ }
|
|
|
+ if (isset($filter['username'])){
|
|
|
+ $where['username'] = $filter['username'];
|
|
|
+ }
|
|
|
+ if (isset($filter['status'])){
|
|
|
+ $where['status'] = (int)$filter['status'];
|
|
|
+ }
|
|
|
+ if (isset($filter['create_time'])){
|
|
|
+ $begin = substr($filter['create_time'],0,19);
|
|
|
+ $end = substr($filter['create_time'],22);
|
|
|
+ $begin = strtotime($begin);
|
|
|
+ $end = strtotime($end);
|
|
|
+ $where['create_time'] = ['between',[$begin,$end]];
|
|
|
+ }
|
|
|
+ $order = input('order');
|
|
|
+ $offset = input('offset');
|
|
|
+ $limit = input('limit');
|
|
|
+ $total = $export->where($where)->count();
|
|
|
+ $export_list = $export
|
|
|
+ ->order('_id',$order)
|
|
|
+ ->where($where)
|
|
|
+ ->whereIn('status',[0,1])
|
|
|
+ ->skip($offset)
|
|
|
+ ->limit($limit)
|
|
|
+ ->select();
|
|
|
+ $list=[];
|
|
|
+ foreach ($export_list as $k=>$v) {
|
|
|
+ $list[$k]['id'] = substr(json_encode($v['_id']),9,-2);
|
|
|
+ $list[$k]['matter_name'] = $v['matter_name'];
|
|
|
+ $list[$k]['matter_no'] = $v['matter_no'];
|
|
|
+ $list[$k]['username'] = $v['username'];
|
|
|
+ $list[$k]['large_num'] = $v['large_num'];
|
|
|
+ $list[$k]['small_num'] = $v['small_num'];
|
|
|
+ $list[$k]['create_time'] = $v['create_time'];
|
|
|
+ $list[$k]['file_dir'] = $v['file_dir'];
|
|
|
+ $list[$k]['status'] = $v['status'];
|
|
|
+ }
|
|
|
+ $result = ['total'=>$total,'rows'=>$list];
|
|
|
+ return json($result);
|
|
|
+ }
|
|
|
+ //批次发货申请删除
|
|
|
+ public function apply_del($ids)
|
|
|
+ {
|
|
|
+ $export = new QcodeExport();
|
|
|
+ if (empty($ids)){
|
|
|
+ $this->error('请求错误');
|
|
|
+ }
|
|
|
+ $res = $export->where('_id',$ids)->update(['delete_time'=>date('Y-m-d H:i:s',time())]);
|
|
|
+ if ($res === false){
|
|
|
+ $this->error('删除失败');
|
|
|
+ }
|
|
|
+ $this->success('成功');
|
|
|
+ }
|
|
|
+ public function goods($ids)
|
|
|
+ {
|
|
|
+ $this->view->assign('ids',$ids);
|
|
|
+ return $this->view->fetch();
|
|
|
+ }
|
|
|
+ //批次发货提交
|
|
|
+ public function apply_add()
|
|
|
+ {
|
|
|
+ $goods = new QcodeGoods();
|
|
|
+ $export = new QcodeExport();
|
|
|
+ $userinfo = Session::get('admin');
|
|
|
+ if ($this->request->isAjax() === false){
|
|
|
+ $this->error('请求错误');
|
|
|
+ }
|
|
|
+ $ids = input('ids');
|
|
|
+ $order_number = input('order_number');
|
|
|
+ $deliveryman = input('deliveryman');
|
|
|
+ $shr_phone = input('shr_phone');
|
|
|
+ $plate_number = input('plate_number');
|
|
|
+ $note = input('note');
|
|
|
+ $id_list = [];
|
|
|
+ if (strpos($ids,',') === false){
|
|
|
+ $id_list[0] = $ids;
|
|
|
+ }else{
|
|
|
+ $id_list = explode(',',$ids);
|
|
|
+ }
|
|
|
+ $update_status = $export->where('company_id',$userinfo['company'])->whereIn('_id',$id_list)->update(['status'=>2]);
|
|
|
+ if ($update_status){
|
|
|
+ $export_list = $export->whereIn('_id',$id_list)->select();
|
|
|
+ $daterq = date('ymd',time());
|
|
|
+
|
|
|
+ $data = [
|
|
|
+ 'shdh' => substr($daterq,2,2).' '.substr($daterq,2,6).mt_rand(1000,9999),
|
|
|
+ 'order_number' => $order_number,
|
|
|
+ 'deliveryman' => $deliveryman,
|
|
|
+ 'shr_phone' => $shr_phone,
|
|
|
+ 'plate_number' => $plate_number,
|
|
|
+ 'shrq_date' => '',
|
|
|
+ 'supplier_name' => $export_list[0]['username'],
|
|
|
+ 'supplier_id' => $userinfo['id'],
|
|
|
+ 'user_id' => $userinfo['id'],
|
|
|
+ 'status' => 0,
|
|
|
+ 'export_id' => $ids,
|
|
|
+ 'create_time' => time(),
|
|
|
+ 'note' => $note,
|
|
|
+ 'company_id' => $userinfo['company'],
|
|
|
+ ];
|
|
|
+ $data['qrcode_add'] = $this->Qrcode($data['shdh']);
|
|
|
+ $res = $goods->save($data);
|
|
|
+ if ($res === false){
|
|
|
+ $this->error('失败');
|
|
|
+ }
|
|
|
+ $this->success('成功');
|
|
|
+ }else{
|
|
|
+ $this->error('失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //生成二维码
|
|
|
+ public function Qrcode($url)
|
|
|
+ {
|
|
|
+ $level=2;
|
|
|
+ $size=5;
|
|
|
+ Vendor('phpqrcode.phpqrcode');//加载生成二维码的核心类
|
|
|
+ $errorCorrectionLevel =intval($level) ;//容错级别
|
|
|
+ $matrixPointSize = intval($size);//生成图片大小
|
|
|
+ //生成二维码图片
|
|
|
+ $object = new \QRcode();
|
|
|
+ //打开缓冲区
|
|
|
+ ob_start();
|
|
|
+ $object->png($url, false, $errorCorrectionLevel, $matrixPointSize, 2);
|
|
|
+ //这里就是把生成的图片流从缓冲区保存到内存对象上,使用base64_encode变成编码字符串,通过json返回给页面。
|
|
|
+ $imageString = base64_encode(ob_get_contents());
|
|
|
+ //关闭缓冲区
|
|
|
+ ob_end_clean();
|
|
|
+ //把生成的base64字符串返回给前端
|
|
|
+ return 'data:image/png;base64,'.$imageString;
|
|
|
+ }
|
|
|
+ //发货单
|
|
|
+ public function dispatch()
|
|
|
+ {
|
|
|
+ return $this->view->fetch();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取辅料名称
|
|
|
+ * @return \think\response\Json
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
+ * @throws \think\exception\DbException
|
|
|
+ */
|
|
|
+ public function matterName()
|
|
|
+ {
|
|
|
+ $userinfo = Session::get('admin');
|
|
|
+ $lager = new QcodeLarge();
|
|
|
+ $bach = new QcodeBach();
|
|
|
+ $bach_id = $lager->name($userinfo['company'].'_'.'qcode_large')->where('delete_time','')->column('bach_id');
|
|
|
+ $matter_name = [];
|
|
|
+ if (!empty($bach_id)){
|
|
|
+ foreach ($bach_id as $v){
|
|
|
+ $bach_list = $bach->name($userinfo['company'].'_'.'qcode_bach')->where('_id',$v)->find();
|
|
|
+ $matter_name[$bach_list['matter_no']] = $bach_list['matter_name'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $matter_name = array_unique($matter_name);
|
|
|
+ return json($matter_name);
|
|
|
+ }
|
|
|
+}
|