CompanyGoods.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\model\MateGoodsLog;
  4. use app\common\util\ExcelUtil;
  5. use think\App;
  6. use think\Db;
  7. use think\Exception;
  8. class CompanyGoods extends Auth
  9. {
  10. public function __construct(App $app = null) {
  11. parent::__construct($app);
  12. $this->model = new \app\common\model\MateGoods();
  13. $this->table = $this->model->table;
  14. }
  15. public function index(){
  16. if(request()->isAjax()){
  17. //分页参数
  18. $length = input('rows',10,'intval'); //每页条数
  19. $page = input('page',1,'intval'); //第几页
  20. $start = ($page - 1) * $length; //分页开始位置
  21. //排序
  22. $sortRow = input('sidx','id','trim'); //排序列
  23. $sort = input('sord','desc','trim'); //排序方式
  24. $order = $sortRow.' '.$sort;
  25. $title = input('title','','trim');
  26. if($title){
  27. $map[] = ['title','like','%'.$title.'%'];
  28. }
  29. $enable = input('enable','','trim');
  30. if($enable != ''){
  31. $map[] = ['enable','=',$enable];
  32. }
  33. $having = '1=1';
  34. $snums = input('kc_status','','trim');
  35. if($snums == 1) { // 正常
  36. $having = 'mnums >= 0 and nnums >= 0';
  37. }else if($snums == 2){ // 偏多
  38. $having = 'mnums < 0';
  39. }else if($snums == 3){ // 偏少
  40. $having = 'nnums < 0';
  41. }
  42. $cate_id = input('cate_id','','trim');
  43. if($cate_id != ''){
  44. $map[] = ['cate_id','=',$cate_id];
  45. }
  46. $map[] = ['del','=',0];
  47. $map[] = ['org_id','=',$this->orgId];
  48. $map= empty($map) ? true: $map;
  49. //数据查询
  50. $lists =db($this->table)
  51. // ->field('id,price,nums,type,title,unit,brand,total_price,spec,buy_time,remark,create_time,enable,cate_id,s_limit,x_limit,IFNULL(s_limit-nums,0) as mnums,IFNULL(nums- x_limit,0) as nnums')
  52. ->where($map)
  53. ->limit($start,$length)
  54. // ->group('id')
  55. // ->having($having)
  56. ->order($order)
  57. ->select();
  58. foreach ($lists as $k=>$v){
  59. $lists[$k]['cate_name'] = Db::name('mate_cate')->where('id',$v['cate_id'])->value('title');
  60. $kc_txt = '正常';
  61. // if($lists[$k]['s_limit'] != 0 && $lists[$k]['x_limit'] != 0){
  62. // if($lists[$k]['s_limit'] > 0 && $v['nums'] > $lists[$k]['s_limit']){
  63. // $kc_txt = '<span style="color: #DCAC6C">偏多</span> ';
  64. // }
  65. // if($lists[$k]['s_limit'] > 0 && $v['nums'] < $lists[$k]['s_limit']){
  66. // $kc_txt = '<span style="color: red">偏少</span> ';
  67. // }
  68. // }
  69. if($v['s_limit'] > 0){
  70. if($v['nums'] > $v['s_limit']){
  71. $kc_txt = '<span style="color: #DCAC6C">偏多</span> ';
  72. }elseif ($v['nums'] < $v['s_limit'] && $v['nums'] > $v['x_limit']){
  73. $kc_txt = '正常';
  74. }elseif ($v['nums'] == 0 || $v['nums'] < $v['x_limit']){
  75. $kc_txt = '<span style="color: red">偏少</span> ';
  76. }
  77. }
  78. $lists[$k]['kc_txt'] = $kc_txt;
  79. }
  80. //数据返回
  81. $totalCount = db($this->table)->where($map)->count();
  82. $totalPage = ceil($totalCount/$length);
  83. $result['page'] = $page;
  84. $result['total'] = $totalPage;
  85. $result['records'] = $totalCount;
  86. $result['rows'] = $lists;
  87. return json($result);
  88. }else{
  89. $this->assign('meta_title','物品管理');
  90. $cate = Db::name('mate_cate')
  91. ->where('enable',1)
  92. ->where('del',0)
  93. ->where('org_id',$this->orgId)
  94. ->select();
  95. $this->assign('cate',$cate);
  96. return $this->fetch();
  97. }
  98. }
  99. public function selectGoods(){
  100. if(request()->isAjax()){
  101. //分页参数
  102. $length = input('rows',10,'intval'); //每页条数
  103. $page = input('page',1,'intval'); //第几页
  104. $start = ($page - 1) * $length; //分页开始位置
  105. //排序
  106. $sortRow = input('sidx','id','trim'); //排序列
  107. $sort = input('sord','desc','trim'); //排序方式
  108. $order = $sortRow.' '.$sort;
  109. $title = input('title','','trim');
  110. if($title){
  111. $map[] = ['title','like','%'.$title.'%'];
  112. }
  113. $map[] = ['enable','=',1];
  114. $map[] = ['del','=',0];
  115. $map[] = ['org_id','=',$this->orgId];
  116. $map= empty($map) ? true: $map;
  117. //数据查询
  118. $lists =db($this->table)
  119. ->where($map)->limit($start,$length)
  120. ->order($order)->select();
  121. //数据返回
  122. $totalCount = db($this->table)->where($map)->count();
  123. $totalPage = ceil($totalCount/$length);
  124. $result['page'] = $page;
  125. $result['total'] = $totalPage;
  126. $result['records'] = $totalCount;
  127. $result['rows'] = $lists;
  128. return json($result);
  129. }else{
  130. return $this->fetch();
  131. }
  132. }
  133. /**
  134. * 新增/编辑
  135. */
  136. public function add($id=0){
  137. $model = $this->model;
  138. if(request()->isPost()){
  139. $res = $model->updates();
  140. if($res){
  141. $this->success('操作成功',url('index'));
  142. }else{
  143. $this->error($model->getError());
  144. }
  145. }else{
  146. $meta_title = '新增物品';
  147. if($id){
  148. $info =db($this->table)->where('id',$id)->find();
  149. $this->assign('info',$info);
  150. $meta_title = '编辑物品';
  151. }
  152. $cate = Db::name('mate_cate')->where('del',0)->where('org_id',$this->orgId)->select();
  153. $this->assign('cate',$cate);
  154. $this->assign('meta_title',$meta_title);
  155. return $this->fetch();
  156. }
  157. }
  158. /**
  159. * 删除记录
  160. * @param int $id
  161. */
  162. public function del($id=0){
  163. if(!$id){
  164. $this->error('参数错误');
  165. }
  166. if(db('mate_apply_goods')->where('goods_id',$id)->find()){
  167. $this->error('该商品有入库或出库记录,暂不能删除');
  168. }
  169. $res = db($this->table)->where('id',$id)->update(['del'=>1]);
  170. if($res){
  171. $this->success('删除成功');
  172. }else{
  173. $this->error('删除失败');
  174. }
  175. }
  176. /**
  177. * 改变字段值
  178. * @param int $fv
  179. * @param string $fn
  180. * @param int $fv
  181. */
  182. public function changeField($id=0,$fn='',$fv=0){
  183. if(!$fn||!$id){
  184. $this->error('参数错误');
  185. }
  186. $res = db($this->table)->where('id',$id)->update([$fn => $fv]);
  187. if($res){
  188. $this->success('操作成功');
  189. }else{
  190. $this->error('操作失败');
  191. }
  192. }
  193. /**
  194. * 处置
  195. */
  196. public function option($id=0){
  197. $model = new MateGoodsLog();
  198. if(request()->isPost()){
  199. $data = request()->post();
  200. if(empty($data['nums'])) $this->error('请输入数量');
  201. if(empty($data['remark'])) $this->error('请输入备注');
  202. $info = db('mate_goods')
  203. ->where('id',$id)
  204. ->find();
  205. if($info['nums'] <$data['nums']) $this->error('库存数量不足');
  206. $sData = [
  207. 'org_id'=>$this->orgId,
  208. 'goods_id'=>$id,
  209. 'nums'=>$data['nums'],
  210. 'remark'=>$data['remark'],
  211. 'price'=>$info['price'],
  212. ];
  213. Db::startTrans();
  214. try{
  215. $res = $model->saveData($sData);
  216. if(!$res){
  217. \exception($model->getError());
  218. }
  219. $ret = Db::name('mate_goods')->where('id',$id)->setDec('nums',$data['nums']);
  220. if(!$ret){
  221. \exception('操作失败');
  222. }
  223. Db::commit();
  224. }catch (Exception $e){
  225. Db::rollback();
  226. $this->error($e->getMessage());
  227. }
  228. $this->success('操作成功');
  229. }else{
  230. $this->assign('id',$id);
  231. return $this->fetch();
  232. }
  233. }
  234. public function import(){
  235. return $this->fetch();
  236. }
  237. /**
  238. * 下载点模板
  239. */
  240. public function downloadtem(){
  241. set_time_limit(0);
  242. ini_set("memory_limit","512M");
  243. include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
  244. $types = model('Address')->getTypes();
  245. ksort($types);
  246. $fileName = '物品模板.xlsx';
  247. $excel = new \PHPExcel();
  248. $sheet = $excel->setActiveSheetIndex(0);
  249. $arr = array('A','B','C','D','E','F');
  250. foreach($arr as $k=>$v){
  251. $excel->getActiveSheet()->getStyle($v)->getAlignment()->setWrapText(true);//换行
  252. $excel->getActiveSheet()->getStyle($v.'1')->getFont()->setBold(true);
  253. $excel->getActiveSheet()->getColumnDimension($v)->setWidth(18);
  254. }
  255. $sheet->setCellValueByColumnAndRow(0,1,'名称');
  256. $sheet->setCellValueByColumnAndRow(1,1,'分类');
  257. $sheet->setCellValueByColumnAndRow(2,1,'单位');
  258. $sheet->setCellValueByColumnAndRow(3,1,'品牌');
  259. $sheet->setCellValueByColumnAndRow(4,1,'规格');
  260. $sheet->setCellValueByColumnAndRow(5,1,'类型(固定资产/耗材)');
  261. $sheet->setCellValueByColumnAndRow(6,1,'备注');
  262. $excel->getActiveSheet()->setCellValue('A2', '测试物品');
  263. $excel->getActiveSheet()->setCellValue('B2', '测试分类编号(2)');
  264. $excel->getActiveSheet()->setCellValue('C2', '个');
  265. $excel->getActiveSheet()->setCellValue('D2', '格力');
  266. $excel->getActiveSheet()->setCellValue('E2', '10个/包');
  267. $excel->getActiveSheet()->setCellValue('F2', '固定资产');
  268. $excel->getActiveSheet()->setCellValue('G2', 'xxxx');
  269. ob_end_clean();//清除缓冲区,避免乱码
  270. header('Content-Type: application/vnd.ms-excel');
  271. header('Content-Disposition: attachment;filename="'.$fileName.'"');
  272. header('Cache-Control: max-age=0');
  273. $objWriter = \PHPExcel_IOFactory::createWriter($excel, 'Excel2007');
  274. $objWriter->save('php://output'); //文件通过浏览器下载
  275. }
  276. /**
  277. * 导入
  278. */
  279. public function importexcel(){
  280. set_time_limit(0);
  281. ini_set("memory_limit", -1);
  282. ob_flush();//清空缓存
  283. flush();//刷新缓存
  284. include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
  285. $orgId = $this->orgId;
  286. if(request()->file()) {
  287. $file = request()->file('file');
  288. //获取文件后缀
  289. $e = explode('.',$_FILES['file']['name']);
  290. $ext = $e[count($e)-1];
  291. if($ext == 'xls'){
  292. \PHPExcel_IOFactory::createReader( 'Excel5');
  293. }else{
  294. \PHPExcel_IOFactory::createReader('Excel2007');
  295. }
  296. $newArr=['xls','xlsx'];
  297. if(!in_array($ext,$newArr)){
  298. exit('文件格式不正确');
  299. }
  300. // 移动到框架应用根目录/uploads/ 目录下
  301. $info = $file->validate([ 'size'=>config('app.max_upload_file_size') ])
  302. ->move(env('root_path') . 'public' . DIRECTORY_SEPARATOR . 'uploads'. DIRECTORY_SEPARATOR . 'files');
  303. if(!$info){
  304. exit('文件上传失败');
  305. }
  306. $img = './uploads/files/' . $info->getSaveName();
  307. $filePath = str_replace('\\', '/', $img);
  308. $newPath = \PHPExcel_IOFactory::load($filePath);
  309. $excelArray = $newPath->getsheet(0)->toArray(); //转换为数组格式
  310. array_shift($excelArray); //删除第一个数组(标题);
  311. $a = [
  312. '固定资产'=>1,
  313. '耗材'=>2,
  314. ];
  315. if(empty($excelArray)){
  316. exit('文件内容为空');
  317. }
  318. foreach ($excelArray as $k => $v) {
  319. if(!$v[0]){
  320. echo "<font color=\"red\" style='margin-left: 20px;font-size: 17px'>第".($k+1)."行,名称为空,未导入</font><br />";
  321. continue;
  322. }
  323. $cateId = 0;
  324. if(trim($v[1])){
  325. $cateId = Db::name('mate_cate')->where('id',$v[1])->value('id');
  326. if(empty($cateId)){
  327. $ps =[
  328. 'title'=>$v[1],
  329. 'org_id'=>$this->orgId,
  330. 'create_time'=>getTime(),
  331. ];
  332. $cateId = Db::name('mate_cate')->insertGetId($ps);
  333. }
  334. }
  335. if(!$v[5]){
  336. echo "<font color=\"red\" style='margin-left: 20px;font-size: 17px'>第".($k+1)."行,类型为空,未导入</font><br />";
  337. continue;
  338. }
  339. $check = Db::name('mate_goods')
  340. ->where('del',0)
  341. ->where('title',$v[0])
  342. ->find();
  343. if($check){
  344. echo "<font color=\"red\" style='margin-left: 20px;font-size: 17px'>第".($k+1)."行,名称已存在,未导入</font><br />";
  345. continue;
  346. }
  347. if(!isset($a[$v[5]])){
  348. echo "<font color=\"red\" style='margin-left: 20px;font-size: 17px'>第".($k+1)."行,类型格式错误,未导入</font><br />";
  349. continue;
  350. }
  351. $rData = [
  352. 'org_id'=>$this->orgId,
  353. 'title'=>$v[0],
  354. 'cate_id'=>$cateId?$cateId:0,
  355. 'unit'=>$v[2],
  356. 'brand'=>$v[3],
  357. 'spec'=>$v[4],
  358. 'type'=>$a[$v[5]],
  359. 'remark'=>$v[6],
  360. 'create_time'=>getTime(),
  361. 'buy_time'=>date('Y-m-d')
  362. ];
  363. $ret=Db::name('mate_goods')->insert($rData);
  364. if(!$ret){
  365. echo "<font color=\"red\" style='margin-left: 20px;font-size: 17px'>第".($k+1)."行,导入失败</font><br />";
  366. }else{
  367. echo "<font color=\"green\" style='margin-left:20px;font-size: 17px'>第".($k+1)."行,导入成功</font><br />";
  368. }
  369. }
  370. }else{
  371. exit('请上传文件');
  372. }
  373. }
  374. public function xhtj(){
  375. $cur = date('Y-m-d');
  376. $start = input('start', date('Y-m-d', strtotime('' . $cur . ' -1 month')));
  377. $end = input('end', date('Y-m-d'));
  378. $start1 = $start . ' 00:00:00';
  379. $end1 = $end . ' 23:59:59';
  380. $list = $this->xhtjData($start1, $end1);
  381. $this->assign('list', $list['list']);
  382. $this->assign('zj', $list['zj']);
  383. $this->assign('start', $start);
  384. $this->assign('end', $end);
  385. return $this->fetch();
  386. }
  387. public function xhtjData($start1, $end1){
  388. $map[] = ['ma.create_time', '>=', $start1];
  389. $map[] = ['ma.create_time', '<=', $end1];
  390. $map[] = ['ma.org_id', '=', $this->orgId];
  391. $list = Db::name('mate_apply')
  392. ->alias('ma')
  393. ->join('mate_apply_goods mag','ma.id=mag.apply_id')
  394. ->join('mate_goods mg','mg.id=mag.goods_id')
  395. ->where($map)
  396. ->field('mag.goods_id,mag.price,mg.title')
  397. ->group('mag.goods_id')
  398. ->select();
  399. foreach ($list as $k => $v) {
  400. $list[$k]['num'] = Db::name('mate_apply')
  401. ->alias('ma')
  402. ->join('mate_apply_goods mag','ma.id=mag.apply_id')
  403. ->join('mate_goods mg','mg.id=mag.goods_id')
  404. ->where('mag.goods_id',$v['goods_id'])
  405. ->where($map)
  406. ->sum('mag.nums');
  407. $list[$k]['total_price'] = round($list[$k]['num']*$v['price'],1);
  408. }
  409. $map1[] = ['tm.create_time', '>=', $start1];
  410. $map1[] = ['tm.create_time', '<=', $end1];
  411. $map1[] = ['tm.org_id', '=', $this->orgId];
  412. $list1 = Db::name('todo_mate')
  413. ->alias('tm')
  414. ->join('todo_mate_item tmi','tmi.todo_mate_id=tm.id')
  415. ->join('mate_goods mg','mg.id=tmi.items_id')
  416. ->where($map1)
  417. ->group('tmi.items_id')
  418. ->field('tmi.items_id as goods_id,tmi.money as price,mg.title')
  419. ->select();
  420. foreach ($list1 as $k=>$v){
  421. $list1[$k]['num'] = Db::name('todo_mate')
  422. ->alias('tm')
  423. ->join('todo_mate_item tmi','tmi.todo_mate_id=tm.id')
  424. ->where($map1)
  425. ->where('tmi.items_id',$v['goods_id'])
  426. ->sum('tmi.total');
  427. $list1[$k]['total_price'] = round($list1[$k]['num']*$v['price'],1);
  428. }
  429. // $map2[] = ['mau.create_time', '>=', $start1];
  430. // $map2[] = ['mau.create_time', '<=', $end1];
  431. // $map2[] = ['mau.org_id', '=', $this->orgId];
  432. // $list2 = Db::name('mate_apply_use')
  433. // ->alias('mau')
  434. // ->join('mate_apply_use_goods maug','mau.id=maug.apply_id')
  435. // ->join('mate_goods mg','mg.id=maug.goods_id')
  436. // ->where($map2)
  437. // ->field('maug.goods_id,maug.price,mg.title')
  438. // ->group('maug.goods_id')
  439. // ->select();
  440. //
  441. // foreach ($list2 as $k => $v) {
  442. // $list2[$k]['num'] = Db::name('mate_apply_use')
  443. // ->alias('mau')
  444. // ->join('mate_apply_use_goods maug','mau.id=maug.apply_id')
  445. // ->join('mate_goods mg','mg.id=maug.goods_id')
  446. // ->where('maug.goods_id',$v['goods_id'])
  447. // ->where($map2)
  448. // ->sum('maug.nums');
  449. // $list2[$k]['total_price'] = round($list2[$k]['num']*$v['price'],1);
  450. // }
  451. foreach ($list as $k=>$v){
  452. $totalPrice = 0;
  453. $tnum = 0;
  454. foreach ($list1 as $kk=>$vv){
  455. if($v['goods_id'] == $vv['goods_id']){
  456. $totalPrice = $v['total_price'] + $vv['total_price'];
  457. $tnum = $v['num'] + $vv['num'];
  458. unset($list1[$kk]);
  459. }
  460. /* foreach ($list2 as $kkk=>$vvv){
  461. if($v['goods_id'] == $vv['goods_id']){
  462. $totalPrice = $v['total_price'] + $vv['total_price'];
  463. $tnum = $v['num'] + $vv['num'];
  464. unset($list1[$kk]);
  465. }elseif ($v['goods_id'] == $vvv['goods_id']){
  466. $totalPrice = $v['total_price'] + $vvv['total_price'];
  467. $tnum = $v['num'] + $vvv['num'];
  468. unset($list2[$kkk]);
  469. }elseif ($v['goods_id'] == $vv['goods_id'] && $v['goods_id'] == $vvv['goods_id']){
  470. $totalPrice = $v['total_price'] + $vv['total_price'] + $vvv['total_price'];
  471. $tnum = $v['num'] + $vv['num'] + $vvv['num'];
  472. unset($list1[$kk]);
  473. unset($list2[$kkk]);
  474. }
  475. }*/
  476. }
  477. if($totalPrice > 0 && $tnum > 0){
  478. $list[$k]['total_price'] = $totalPrice;
  479. $list[$k]['num'] = $tnum;
  480. }
  481. }
  482. $array = array_merge($list,$list1);
  483. $zj = 0;
  484. foreach ($array as $k=>$v){
  485. $zj +=$v['total_price'];
  486. }
  487. return ['list'=>$array,'zj'=>$zj];
  488. }
  489. public function qrcode($id=0){
  490. $info = Db::name('mate_goods')->where('id',$id)->find();
  491. $code = get_qrcode_str('mate_goods',$id);
  492. $this->assign('code',$code);
  493. $this->assign('info',$info);
  494. return $this->fetch();
  495. }
  496. public function wptj(){
  497. $cur = date('Y-m-d');
  498. $start = input('start', date('Y-m-d', strtotime('' . $cur . ' -1 month')));
  499. $end = input('end', date('Y-m-d'));
  500. $start1 = $start . ' 00:00:00';
  501. $end1 = $end . ' 23:59:59';
  502. $title = input('title','','trim');
  503. $cateTitle = input('cateTitle','');
  504. $list = $this->wptjData($start1, $end1,$title,$cateTitle);
  505. $this->assign('list', $list);
  506. $this->assign('start', $start);
  507. $this->assign('end', $end);
  508. $this->assign('title', $title);
  509. $this->assign('cateTitle', $cateTitle);
  510. return $this->fetch();
  511. }
  512. public function wptjData($start1, $end1,$title,$cateTitle) {
  513. $map1[] = ['ma.create_time', '>=', $start1];
  514. $map1[] = ['ma.create_time', '<=', $end1];
  515. $map =[];
  516. if($title){
  517. $map[] = ['title','like','%'.$title.'%'];
  518. }
  519. if($cateTitle){
  520. $cateIds = Db::name('mate_cate')->where('title','like','%'.$cateTitle.'%')->column('id');
  521. $map[] = ['cate_id','in',$cateIds];
  522. }
  523. $list = Db::name('mate_goods')
  524. ->where('org_id', $this->orgId)
  525. ->where('del', 0)
  526. ->where('enable', 1)
  527. ->where($map)
  528. ->select();
  529. foreach ($list as $k => $v) {
  530. $list[$k]['ck'] = Db::name('mate_apply')
  531. ->alias('ma')
  532. ->join('mate_apply_goods mag','mag.apply_id=ma.id')
  533. ->where('ma.type',1)
  534. ->where('mag.goods_id',$v['id'])
  535. ->where($map1)
  536. ->sum('mag.nums');
  537. $list[$k]['rk'] = Db::name('mate_apply')
  538. ->alias('ma')
  539. ->join('mate_apply_goods mag','mag.apply_id=ma.id')
  540. ->where('ma.type',2)
  541. ->where('mag.goods_id',$v['id'])
  542. ->where($map1)
  543. ->sum('mag.nums');
  544. $tt = '';
  545. if($v['consume'] == 1){
  546. $tt ='使用消耗';
  547. }elseif ($v['consume'] == 2){
  548. $tt ='出库消耗';
  549. }
  550. $list[$k]['consume_title'] = $tt;
  551. $list[$k]['cate_title'] = Db::name('mate_cate')->where('id',$v['cate_id'])->value('title');
  552. }
  553. return $list;
  554. }
  555. public function wptjDataExport() {
  556. $cur = date('Y-m-d');
  557. $start = input('start', date('Y-m-d', strtotime('' . $cur . ' -1 week')));
  558. $end = input('end', date('Y-m-d'));
  559. $start1 = $start . ' 00:00:00';
  560. $end1 = $end . ' 23:59:59';
  561. $title = input('title','','trim');
  562. $cateTitle = input('cateTitle','');
  563. $list = $this->wptjData($start1, $end1,$title,$cateTitle);
  564. $filename = '物品统计';
  565. $header = [
  566. ['title' => '分类', 'name' => 'cate_title','width'=>'20'],
  567. ['title' => '物品名称', 'name' => 'title','width'=>'20'],
  568. ['title' => '品牌', 'name' => 'brand','width'=>'20'],
  569. ['title' => '规格', 'name' => 'spec','width'=>'20'],
  570. ['title' => '入库数量', 'name' => 'ck','width'=>'20'],
  571. ['title' => '出库数量', 'name' => 'rk','width'=>'20'],
  572. ['title' => '当前余量', 'name' => 'nums','width'=>'20'],
  573. ['title' => '类型', 'name' => 'consume_title','width'=>'20'],
  574. ];
  575. ExcelUtil::export($filename,$header,$list);
  576. }
  577. }