Deliver.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\QcodeLarge;
  4. use app\admin\model\QcodeSmall;
  5. use app\common\controller\Backend;
  6. use app\admin\model\QcodeProduct;
  7. use app\admin\model\QcodeCompany;
  8. use app\admin\model\QcodeBach;
  9. use app\admin\model\QcodeExport;
  10. use fast\Arr;
  11. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  12. use PhpOffice\PhpSpreadsheet\Style\Alignment;
  13. use PhpOffice\PhpSpreadsheet\Exception;
  14. use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
  15. use app\admin\model\QcodeGoods;
  16. use think\Session;
  17. class Deliver extends Backend
  18. {
  19. /**
  20. * 首页
  21. * @return string|\think\response\Json
  22. * @throws \think\Exception
  23. */
  24. public function index()
  25. {
  26. return $this->view->fetch();
  27. }
  28. /**
  29. * 大件发货列表
  30. * @return string|\think\response\Json
  31. * @throws \think\Exception
  32. * @throws \think\db\exception\DataNotFoundException
  33. * @throws \think\db\exception\ModelNotFoundException
  34. * @throws \think\exception\DbException
  35. */
  36. public function lager()
  37. {
  38. $company = new QcodeCompany();
  39. $product = new QcodeProduct();
  40. $large = new QcodeLarge();
  41. $bach = new QcodeBach();
  42. $small = new QcodeSmall();
  43. $this->request->filter(['strip_tags', 'trim']);
  44. if (false === $this->request->isAjax()) {
  45. return $this->view->fetch();
  46. }
  47. if ($this->request->request('keyField')) {
  48. return $this->selectpage();
  49. }
  50. // 接收参数
  51. $userInfo = Session::get('admin');
  52. $where = [
  53. 'delete_time'=> ''
  54. ];
  55. $filter = input('filter');
  56. $filter = json_decode($filter,true);
  57. $whereList = [
  58. 'delete_time'=>'',
  59. ];
  60. //样品编号查询
  61. if (isset($filter['matter_name'])){
  62. $whereList['matter_no'] =$filter['matter_name'];
  63. }
  64. if (isset($filter['bach'])){
  65. $whereList['bach_num'] = $filter['bach'];
  66. }
  67. if (isset($filter['manufacture_date'])){
  68. $begin = substr($filter['manufacture_date'],0,19);
  69. $end = substr($filter['manufacture_date'],22);
  70. $begin = (int)date('ymd',strtotime($begin));
  71. $end = (int)date('ymd',strtotime($end));
  72. $whereList['manufacture_date'] = ['between',[$begin,$end]];
  73. }
  74. $bach_list = $bach->name($userInfo['company'].'_'.'qcode_bach')->where($whereList)->column('_id');
  75. $bach_id = [];
  76. foreach ($bach_list as $v){
  77. $id = substr(json_encode($v),9,-2);
  78. array_push($bach_id,$id);
  79. }
  80. $order = input('order');
  81. $offset = input('offset');
  82. $limit = input('limit');
  83. $total = $large->name($userInfo['company'].'_'.'qcode_large')->where($where)->whereIn('bach_id',$bach_id)->count();
  84. $large_list = $large->name($userInfo['company'].'_'.'qcode_large')
  85. ->order('creat_time',$order)
  86. ->where($where)
  87. ->whereIn('bach_id',$bach_id)
  88. ->skip($offset)
  89. ->limit($limit)
  90. ->select();
  91. $list=[];
  92. foreach ($large_list as $k=>$v) {
  93. $bach_detail = $bach->name($userInfo['company'].'_'.'qcode_bach')->where('_id',$v['bach_id'])->find();
  94. $list[$k]['id'] = substr(json_encode($v['_id']),9,-2);
  95. $list[$k]['bach'] = $bach_detail['bach_num'];
  96. $list[$k]['l_flow'] = $bach_detail['l_flow']+$k;
  97. $list[$k]['matter_name'] = $bach_detail['matter_name'];
  98. $list[$k]['manufacture_date'] = date('Y-m-d',strtotime('20'.$bach_detail['manufacture_date']));
  99. $list[$k]['code'] = $v['code'];
  100. $small_num = $small->name($userInfo['company'].'_'.'qcode_small')->where('large_id',substr(json_encode($v['_id']),9,-2))->count();
  101. $list[$k]['small_num'] = $small_num;
  102. }
  103. $result = ['total'=>$total,'rows'=>$list];
  104. return json($result);
  105. }
  106. /**
  107. * 小件列表
  108. * @return \think\response\Json
  109. * @throws \think\Exception
  110. * @throws \think\db\exception\DataNotFoundException
  111. * @throws \think\db\exception\ModelNotFoundException
  112. * @throws \think\exception\DbException
  113. */
  114. public function smallList()
  115. {
  116. $userinfo = Session::get('admin');
  117. $lager = new QcodeLarge();
  118. $small = new QcodeSmall();
  119. if ($this->request->isAjax() === false){
  120. $this->error('请求错误');
  121. }
  122. $lager_list = input('search');
  123. $order = input('order');
  124. $offset = input('offset');
  125. $limit = input('limit');
  126. $lagerList = explode(',',$lager_list);
  127. $smallList = $small->name($userinfo['company'].'_'.'qcode_small')
  128. ->whereIn('large_id',$lagerList)
  129. // ->order('l_flow',$order)
  130. ->skip($offset)
  131. ->limit($limit)
  132. ->select();
  133. $total = $small->name($userinfo['company'].'_'.'qcode_small')->whereIn('large_id',$lagerList)->count();
  134. $list = [];
  135. foreach ($smallList as $k=>$v){
  136. $list[$k] = [
  137. 'code' => $v['code'],
  138. 'l_flow' => $v['l_flow'],
  139. 'print_num' => $v['p_nums'],
  140. 'status' => $v['status'],
  141. ];
  142. }
  143. return json(['total'=>$total,'rows'=>$list]);
  144. }
  145. /**
  146. * 导出发货
  147. * @return void
  148. * @throws \think\Exception
  149. * @throws \think\db\exception\DataNotFoundException
  150. * @throws \think\db\exception\ModelNotFoundException
  151. * @throws \think\exception\DbException
  152. */
  153. public function print()
  154. {
  155. $userinfo = Session::get('admin');
  156. $lager = new QcodeLarge();
  157. $bach = new QcodeBach();
  158. $small = new QcodeSmall();
  159. $export = new QcodeExport();
  160. if ($this->request->isAjax() === false){
  161. $this->error('请求错误');
  162. }
  163. $lager_id = input('lager_id');
  164. if ($lager_id === ''){
  165. $this->error('请至少选择一个大件');
  166. }
  167. $lagerId = [];
  168. if (strpos($lager_id,',') === false){
  169. $lagerId[0] = $lager_id;
  170. }else{
  171. $lagerId = explode(',',$lager_id);
  172. }
  173. $lager_num = count($lagerId);
  174. $bach_id = [];
  175. foreach ($lagerId as $k=>$v){
  176. $lagerList = $lager->name($userinfo['company'].'_'.'qcode_large')->where('_id',$v)->find();
  177. $bachList = $bach->name($userinfo['company'].'_'.'qcode_bach')->where('_id',$lagerList['bach_id'])->find();
  178. $bach_id[$k] = substr(json_encode($bachList['_id']),9,-2);
  179. }
  180. $bach_id = array_unique($bach_id);
  181. $data = [];
  182. foreach ($bach_id as $k=>$v){
  183. $m = 1;$n =0;
  184. $large_str = '';
  185. foreach ($lagerId as $key=>$value){
  186. $lagerList = $lager->name($userinfo['company'].'_'.'qcode_large')->where('_id',$value)->find();
  187. if($v === $lagerList['bach_id']){
  188. $m++;
  189. $large_str = $large_str.substr(json_encode($lagerList['_id']),9,-2).',';
  190. }
  191. }
  192. $large_str = substr($large_str,0,strlen($large_str)-1);
  193. foreach (explode(',',$large_str) as $kk=>$vv){
  194. $n = $n + $small->name($userinfo['company'].'_'.'qcode_small')->where('large_id',$vv)->count();
  195. }
  196. $bachDetail = $bach->name($userinfo['company'].'_'.'qcode_bach')->where('_id',$v)->find();
  197. if ($bachDetail['box_num'] === 1){
  198. $mater_type = 2;
  199. }else{
  200. $mater_type = 1;
  201. }
  202. // $file_dir = $this->exportExcel($v,$large_str,$userinfo['company'],$m,$n);
  203. $data[$k] = [
  204. 'username' => $bachDetail['supplier_name'],
  205. 'matter_name' => $bachDetail['matter_name'],
  206. 'matter_no' => $bachDetail['matter_no'],
  207. 'large_str' => $large_str,
  208. 'large_num' => $lager_num,
  209. 'small_num' => $n,
  210. 'status' => 0,
  211. 'num' => $bachDetail['s_weight'],
  212. 'bach_num' => $bachDetail['bach_num'],
  213. 'mater_type' => $mater_type,
  214. 'note' => '',
  215. 'user_id' => $userinfo['id'],
  216. 'create_time' => time(),
  217. 'file_dir' => '',
  218. 'company_id' => $userinfo['company'],
  219. ];
  220. $res = $export->save($data[$k]);
  221. }
  222. $this->success();
  223. }
  224. /**
  225. * 生成excel
  226. * @param $bach_id
  227. * @param $large_str
  228. * @param $company
  229. * @param $large_num
  230. * @param $small_num
  231. * @return string
  232. * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
  233. * @throws \think\db\exception\DataNotFoundException
  234. * @throws \think\db\exception\ModelNotFoundException
  235. * @throws \think\exception\DbException
  236. */
  237. public function exportExcel($bach_id,$large_str,$company,$large_num,$small_num)
  238. {
  239. $bach = new QcodeBach();
  240. $large = new QcodeLarge();
  241. $small = new QcodeSmall();
  242. $bachList = $bach->name($company . '_' . 'qcode_bach')->where('_id', $bach_id)->find();
  243. $data = [
  244. 'supplier_name' => $bachList['supplier_name'],
  245. 'supplier_no' => $bachList['supplier_code'],
  246. 'matter_name' => $bachList['matter_name'],
  247. 'matter_no' => $bachList['matter_no'],
  248. 'manufacture_date' => $bachList['manufacture_date'],
  249. 'print_date' => $bachList['print_date'],
  250. 'box_num' => $large_num,
  251. 'tray_num' => $bachList['tray_num'],
  252. 'small_num' => $small_num,
  253. 'l_reservation' => $bachList['l_reservation'],
  254. 's_reservation' => $bachList['s_reservation'],
  255. 'l_flow' => $bachList['l_flow'],
  256. 's_flow' => $bachList['s_flow'],
  257. 'l_weight' => $bachList['l_weight'],
  258. 's_weight' => $bachList['s_weight'],
  259. 'code' => [],
  260. ];
  261. $large_id = explode(',', $large_str);
  262. foreach ($large_id as $k => $v) {
  263. $largeList = $large->name($company . '_' . 'qcode_large')->where('_id', $v)->find();
  264. $small_list = $small->name($company . '_' . 'qcode_small')->where('large_id', $v)->select();
  265. foreach ($small_list as $value) {
  266. $code = [
  267. 'large_code' => $largeList['code'],
  268. 'small_code' => $value['code'],
  269. ];
  270. $data['code'][] = $code;
  271. }
  272. }
  273. $objexcel = new Spreadsheet();
  274. $sheet = $objexcel->getActiveSheet();
  275. //设置全局单元格垂直居中
  276. // $objexcel->getDefaultStyle()->getAlignment()->setVertical(Alignment::HORIZONTAL_CENTER);
  277. // //设置全局单元格水平居中
  278. // $objexcel->getDefaultStyle()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
  279. // //设置全局单元格自动换行
  280. // $objexcel->getDefaultStyle()->getAlignment()->setWrapText(true);
  281. //设置单元格宽度
  282. $sheet->getDefaultColumnDimension()->setWidth(25);
  283. //设置表头
  284. // $sheet->setCellValue('A1', '文件流水号');
  285. // $sheet->setCellValue('A2', '订单号');
  286. // $sheet->setCellValue('A3', '供应商');
  287. // $sheet->setCellValue('A4', '供应商代码');
  288. // $sheet->setCellValue('A5', '物料名称');
  289. // $sheet->setCellValue('A6', '物料代码');
  290. // $sheet->setCellValue('A7', '生产日期');
  291. // $sheet->setCellValue('A8', '打码日期');
  292. // $sheet->setCellValue('A9', '大件数量');
  293. // $sheet->setCellValue('A10', '托盘小件数量');
  294. // $sheet->setCellValue('A11', '小件总数量');
  295. // $sheet->setCellValue('C3', '大件预留码');
  296. // $sheet->setCellValue('C5', '小件预留码');
  297. // $sheet->setCellValue('C7', '大件开始流水号');
  298. // $sheet->setCellValue('C9', '小件开始流水号');
  299. // $sheet->setCellValue('C11', '大件重量(Kg)');
  300. // $sheet->setCellValue('C13', '小件重量(Kg)');
  301. // $sheet->setCellValue('A15', '大件二维码');
  302. // $sheet->setCellValue('B15', '大件条码(预留)');
  303. // $sheet->setCellValue('C15', '小件二维码');
  304. // $sheet->setCellValue('D15', '小件条码(预留)');
  305. //插入表格数据
  306. // $sheet->getCell('B3')->setValue(isset($data['supplier_name'])?$data['supplier_name']:'');
  307. // $sheet->getCell('B4')->setValue(isset($data['supplier_no'])?$data['supplier_no']:'');
  308. // $sheet->getCell('B5')->setValue(isset($data['matter_name'])?$data['matter_name']:'');
  309. // $sheet->getCell('B6')->setValue(isset($data['matter_no'])?$data['matter_no']:'');
  310. // $sheet->getCell('B7')->setValue(isset($data['manufacture_date'])?$data['manufacture_date']:'');
  311. // $sheet->getCell('B8')->setValue(isset($data['print_date'])?$data['print_date']:'');
  312. // $sheet->getCell('B9')->setValue(isset($data['box_num'])?$data['box_num']:'');
  313. // $sheet->getCell('B10')->setValue(isset($data['tray_num'])?$data['tray_num']:'');
  314. // $sheet->getCell('B11')->setValue(isset($data['small_num'])?$data['small_num']:'');
  315. // $sheet->getCell('C4')->setValue(isset($data['l_reservation'])?$data['l_reservation']:'');
  316. // $sheet->getCell('C6')->setValue(isset($data['s_reservation'])?$data['s_reservation']:'');
  317. // $sheet->getCell('C8')->setValue(isset($data['l_flow'])?$data['l_flow']:'');
  318. // $sheet->getCell('C10')->setValue(isset($data['s_flow'])?$data['s_flow']:'');
  319. // $sheet->getCell('C12')->setValue(isset($data['l_weight'])?$data['l_weight']:'');
  320. // $sheet->getCell('C14')->setValue(isset($data['s_flow'])?$data['s_flow']:'');
  321. // foreach ($data['code'] as $v){
  322. // $sheet->getCell('A16')->setValue(isset($v['large_code'])?$v['large_code']:'');
  323. // $sheet->getCell('B16')->setValue('');
  324. // $sheet->getCell('C16')->setValue(isset($v['small_code'])?$v['small_code']:'');
  325. // $sheet->getCell('D16')->setValue('');
  326. // }
  327. //文件另存
  328. $filename = date('Ymd',time()).rand(100,999).'_'.$data['supplier_name'].'_'.$data['matter_name'].'_'.$data['small_num'].'.xlsx';
  329. // $filename = iconv("utf-8","gb2312",$filename);
  330. header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  331. header('Content-Disposition: attachment;filename="'.$filename.'"');
  332. header('Cache-Control: max-age=0');
  333. header("Content-Type:text/html;charset=utf-8");
  334. // if(is_dir(ROOT_PATH.'public/uploads/export/') == null)
  335. // {
  336. // mkdir(ROOT_PATH.'public/uploads/export/',0777,true);
  337. // }
  338. $writer = new Xlsx($objexcel);
  339. // $writer->save($filename);
  340. $writer->save(ROOT_PATH.'public/uploads/export'.DS.$filename);
  341. return 'public/uploads/export/'.$filename;
  342. }
  343. //批次发货审批
  344. public function apply()
  345. {
  346. $export = new QcodeExport();
  347. $this->request->filter(['strip_tags', 'trim']);
  348. if (false === $this->request->isAjax()) {
  349. return $this->view->fetch();
  350. }
  351. if ($this->request->request('keyField')) {
  352. return $this->selectpage();
  353. }
  354. // 接收参数
  355. $userInfo = Session::get('admin');
  356. $where = [
  357. 'company_id' => $userInfo['company'],
  358. 'delete_time'=> ''
  359. ];
  360. $filter = input('filter');
  361. $filter = json_decode($filter,true);
  362. //样品编号查询
  363. if (isset($filter['matter_name'])){
  364. $where['matter_no'] =$filter['matter_name'];
  365. }
  366. if (isset($filter['username'])){
  367. $where['username'] = $filter['username'];
  368. }
  369. if (isset($filter['status'])){
  370. $where['status'] = (int)$filter['status'];
  371. }
  372. if (isset($filter['create_time'])){
  373. $begin = substr($filter['create_time'],0,19);
  374. $end = substr($filter['create_time'],22);
  375. $begin = strtotime($begin);
  376. $end = strtotime($end);
  377. $where['create_time'] = ['between',[$begin,$end]];
  378. }
  379. $order = input('order');
  380. $offset = input('offset');
  381. $limit = input('limit');
  382. $total = $export->where($where)->count();
  383. $export_list = $export
  384. ->order('_id',$order)
  385. ->where($where)
  386. ->whereIn('status',[0,1])
  387. ->skip($offset)
  388. ->limit($limit)
  389. ->select();
  390. $list=[];
  391. foreach ($export_list as $k=>$v) {
  392. $list[$k]['id'] = substr(json_encode($v['_id']),9,-2);
  393. $list[$k]['matter_name'] = $v['matter_name'];
  394. $list[$k]['matter_no'] = $v['matter_no'];
  395. $list[$k]['username'] = $v['username'];
  396. $list[$k]['large_num'] = $v['large_num'];
  397. $list[$k]['small_num'] = $v['small_num'];
  398. $list[$k]['create_time'] = $v['create_time'];
  399. $list[$k]['file_dir'] = $v['file_dir'];
  400. $list[$k]['status'] = $v['status'];
  401. }
  402. $result = ['total'=>$total,'rows'=>$list];
  403. return json($result);
  404. }
  405. //批次发货申请删除
  406. public function apply_del($ids)
  407. {
  408. $export = new QcodeExport();
  409. if (empty($ids)){
  410. $this->error('请求错误');
  411. }
  412. $res = $export->where('_id',$ids)->update(['delete_time'=>date('Y-m-d H:i:s',time())]);
  413. if ($res === false){
  414. $this->error('删除失败');
  415. }
  416. $this->success('成功');
  417. }
  418. public function goods($ids)
  419. {
  420. $this->view->assign('ids',$ids);
  421. return $this->view->fetch();
  422. }
  423. //批次发货提交
  424. public function apply_add()
  425. {
  426. $goods = new QcodeGoods();
  427. $export = new QcodeExport();
  428. $userinfo = Session::get('admin');
  429. if ($this->request->isAjax() === false){
  430. $this->error('请求错误');
  431. }
  432. $ids = input('ids');
  433. $order_number = input('order_number');
  434. $deliveryman = input('deliveryman');
  435. $shr_phone = input('shr_phone');
  436. $plate_number = input('plate_number');
  437. $note = input('note');
  438. $id_list = [];
  439. if (strpos($ids,',') === false){
  440. $id_list[0] = $ids;
  441. }else{
  442. $id_list = explode(',',$ids);
  443. }
  444. $update_status = $export->where('company_id',$userinfo['company'])->whereIn('_id',$id_list)->update(['status'=>2]);
  445. if ($update_status){
  446. $export_list = $export->whereIn('_id',$id_list)->select();
  447. $daterq = date('ymd',time());
  448. $data = [
  449. 'shdh' => substr($daterq,2,2).' '.substr($daterq,2,6).mt_rand(1000,9999),
  450. 'order_number' => $order_number,
  451. 'deliveryman' => $deliveryman,
  452. 'shr_phone' => $shr_phone,
  453. 'plate_number' => $plate_number,
  454. 'shrq_date' => '',
  455. 'supplier_name' => $export_list[0]['username'],
  456. 'supplier_id' => $userinfo['id'],
  457. 'user_id' => $userinfo['id'],
  458. 'status' => 0,
  459. 'export_id' => $ids,
  460. 'create_time' => time(),
  461. 'note' => $note,
  462. 'company_id' => $userinfo['company'],
  463. ];
  464. $data['qrcode_add'] = $this->Qrcode($data['shdh']);
  465. $res = $goods->save($data);
  466. if ($res === false){
  467. $this->error('失败');
  468. }
  469. $this->success('成功');
  470. }else{
  471. $this->error('失败');
  472. }
  473. }
  474. //生成二维码
  475. public function Qrcode($url)
  476. {
  477. $level=2;
  478. $size=5;
  479. Vendor('phpqrcode.phpqrcode');//加载生成二维码的核心类
  480. $errorCorrectionLevel =intval($level) ;//容错级别
  481. $matrixPointSize = intval($size);//生成图片大小
  482. //生成二维码图片
  483. $object = new \QRcode();
  484. //打开缓冲区
  485. ob_start();
  486. $object->png($url, false, $errorCorrectionLevel, $matrixPointSize, 2);
  487. //这里就是把生成的图片流从缓冲区保存到内存对象上,使用base64_encode变成编码字符串,通过json返回给页面。
  488. $imageString = base64_encode(ob_get_contents());
  489. //关闭缓冲区
  490. ob_end_clean();
  491. //把生成的base64字符串返回给前端
  492. return 'data:image/png;base64,'.$imageString;
  493. }
  494. //发货单
  495. public function dispatch()
  496. {
  497. return $this->view->fetch();
  498. }
  499. /**
  500. * 获取辅料名称
  501. * @return \think\response\Json
  502. * @throws \think\db\exception\DataNotFoundException
  503. * @throws \think\db\exception\ModelNotFoundException
  504. * @throws \think\exception\DbException
  505. */
  506. public function matterName()
  507. {
  508. $userinfo = Session::get('admin');
  509. $lager = new QcodeLarge();
  510. $bach = new QcodeBach();
  511. $bach_id = $lager->name($userinfo['company'].'_'.'qcode_large')->where('delete_time','')->column('bach_id');
  512. $matter_name = [];
  513. if (!empty($bach_id)){
  514. foreach ($bach_id as $v){
  515. $bach_list = $bach->name($userinfo['company'].'_'.'qcode_bach')->where('_id',$v)->find();
  516. $matter_name[$bach_list['matter_no']] = $bach_list['matter_name'];
  517. }
  518. }
  519. $matter_name = array_unique($matter_name);
  520. return json($matter_name);
  521. }
  522. public function receive()
  523. {
  524. //当前是否为关联查询
  525. $this->relationSearch = false;
  526. //设置过滤方法
  527. $this->request->filter(['strip_tags', 'trim']);
  528. if ($this->request->isAjax()) {
  529. //如果发送的来源是Selectpage,则转发到Selectpage
  530. if ($this->request->request('keyField')) {
  531. return $this->selectpage();
  532. }
  533. $where = [
  534. 'delete_time'=> ''
  535. ];
  536. $req = input();
  537. $req['sort'] == 'id' ? $sort = '_id' : $sort = $req['sort'];
  538. $order = $req['order'];
  539. $offset = $req['offset'];
  540. $limit = $req['limit'];
  541. // 构造模糊查询条件
  542. // $regex = new MongoDB\BSON\Regex('.*abc.*', 'i');
  543. // $filter = ['field' => $regex];
  544. $filter = json_decode($req['filter'], true);
  545. foreach ($filter as $k => $v){
  546. $where[$k] = new \MongoDB\BSON\Regex($v);
  547. }
  548. $goods = new QcodeGoods();
  549. $total = $goods->where($where)
  550. ->order($sort,$order)
  551. ->skip($offset)
  552. ->select();
  553. $list = $goods->where($where)
  554. ->order($sort,$order)
  555. ->limit($limit)
  556. ->skip($offset)
  557. ->select();
  558. foreach ($list as $k=>$v) {
  559. $oid = $v['_id']->jsonSerialize();
  560. $list[$k]['id'] = $oid['$oid'];
  561. }
  562. $result = array("total" => count($total), "rows" => $list);
  563. return json($result);
  564. }
  565. return $this->view->fetch();
  566. }
  567. }