Entrust.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\controller\Backend;
  4. use \think\Session;
  5. use \think\Db;
  6. /**
  7. * 委托管理管理
  8. *
  9. * @icon fa fa-circle-o
  10. */
  11. class Entrust extends Backend
  12. {
  13. /**
  14. * Entrust模型对象
  15. * @var \app\admin\model\Entrust
  16. */
  17. protected $model = null;
  18. protected $searchFields = 'no,name,bach,sell_bach,company';
  19. public function _initialize()
  20. {
  21. parent::_initialize();
  22. $this->model = new \app\admin\model\Entrust;
  23. $this->view->assign("statusList", $this->model->getStatusList());
  24. }
  25. /**
  26. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  27. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  28. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  29. */
  30. /**
  31. * 查看
  32. *
  33. * @return string|Json
  34. * @throws \think\Exception
  35. * @throws DbException
  36. */
  37. public function index()
  38. {
  39. //设置过滤方法
  40. $this->request->filter(['strip_tags', 'trim']);
  41. if (false === $this->request->isAjax()) {
  42. return $this->view->fetch();
  43. }
  44. //如果发送的来源是 Selectpage,则转发到 Selectpage
  45. if ($this->request->request('keyField')) {
  46. return $this->selectpage();
  47. }
  48. [$where, $sort, $order, $offset, $limit] = $this->buildparams();
  49. $user_id = Session::get('admin')['id'];
  50. if ($user_id == 1){//超级管理员
  51. $list = $this->model
  52. ->where($where)
  53. ->order($sort, $order)
  54. ->paginate($limit);
  55. }else{
  56. $userinfo = Db::name('admin')->where('id',$user_id)->find();
  57. $pidList = Db::name('company')->where('pid',$userinfo['company'])->select();
  58. $map = [];
  59. if (!empty($pidList)){//总公司
  60. $pid = [];
  61. foreach ($pidList as $key=>$value){
  62. $pid[$key] = $value['id'];
  63. }
  64. $map['work_unit'] = array('in',$pid);
  65. }else{//分公司
  66. $map['work_unit'] = $userinfo['company'];
  67. }
  68. $list = $this->model
  69. ->where($where)
  70. ->where($map)
  71. ->order($sort, $order)
  72. ->paginate($limit);
  73. }
  74. $result = ['total' => $list->total(), 'rows' => $list->items()];
  75. return json($result);
  76. }
  77. /**
  78. * 添加
  79. *
  80. * @return string
  81. * @throws \think\Exception
  82. */
  83. public function add()
  84. {
  85. if (false === $this->request->isPost()) {
  86. $user_id = Session::get('admin')['id'];
  87. $company_id = Db::name('admin')->where('id',$user_id)->value('company');
  88. $company = Db::name('company')->where('pid',$company_id)->column('id,name');
  89. if (empty($company)){
  90. $company = Db::name('company')->where('id',$company_id)->column('id,name');
  91. }
  92. $this->assign('company',$company);
  93. return $this->view->fetch();
  94. }
  95. $params = $this->request->post('row/a');
  96. if (empty($params)) {
  97. $this->error(__('Parameter %s can not be empty', ''));
  98. }
  99. $params['name'] = preg_replace('/\s+/','',$params['name']);//去掉所有空格
  100. $params['user_id'] = Session::get('admin')['id'];
  101. $userinfo = Db::name('admin')->where('id',$params['user_id'])->find();
  102. $params['project'] = implode(',',$params['project']);
  103. $params['report_grant'] = implode(',',$params['report_grant']);
  104. $params['sample_stand'] = implode(',',$params['sample_stand']);
  105. $params['user_name'] = $userinfo['username'];
  106. $params['work_unit'] = $userinfo['company'];
  107. $params['work_name'] = Db::name('company')->where('id',$userinfo['company'])->value('name');
  108. $params['company'] = Db::name('company')->where('id',$params['company'])->value('name');
  109. $is_exit = false;//默认样品编号唯一
  110. if ($params['is_two'] == 1){//双样
  111. for ($i=0;$i<2;$i++){
  112. $data[$i] = $params;
  113. $data[$i]['sample_no'] = $params['sample_no'].'-'.($i+1);
  114. $is_exit = Db::name('entrust')->where('sample_no',$data[$i]['sample_no'])->find();
  115. if ($is_exit){
  116. $is_exit = true;
  117. }
  118. }
  119. }else{//单样
  120. $data[0] = $params;
  121. $is_exit = Db::name('entrust')->where('sample_no',$params['sample_no'])->find();
  122. if ($is_exit){
  123. $is_exit = true;
  124. }
  125. }
  126. if ($is_exit === true){
  127. $this->error('样品编号已存在,请关闭此页面后重新打开!');
  128. }
  129. $result = false;
  130. Db::startTrans();
  131. try {
  132. //是否采用模型验证
  133. if ($this->modelValidate) {
  134. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  135. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
  136. $this->model->validateFailException()->validate($validate);
  137. }
  138. $result = $this->model->saveAll($data);
  139. Db::commit();
  140. } catch (ValidateException|PDOException|Exception $e) {
  141. Db::rollback();
  142. $this->error($e->getMessage());
  143. }
  144. if ($result === false) {
  145. $this->error(__('No rows were inserted'));
  146. }
  147. $this->success();
  148. }
  149. /**
  150. * 编辑
  151. *
  152. * @param $ids
  153. * @return string
  154. * @throws DbException
  155. * @throws \think\Exception
  156. */
  157. public function edit($ids = null)
  158. {
  159. $row = $this->model->get($ids);
  160. if (!$row) {
  161. $this->error(__('No Results were found'));
  162. }
  163. $adminIds = $this->getDataLimitAdminIds();
  164. if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
  165. $this->error(__('You have no permission'));
  166. }
  167. if (false === $this->request->isPost()) {
  168. $user_id = Session::get('admin')['id'];
  169. $company_id = Db::name('admin')->where('id',$user_id)->value('company');
  170. $pid = Db::name('company')->where('id',$company_id)->value('pid');
  171. $company = Db::name('company')->where('pid',$pid)->column('id,name');
  172. $report_grant = explode(',',$row['report_grant']);
  173. $sample_stand = explode(',',$row['sample_stand']);
  174. $this->assign('company',$company);
  175. $this->assign('report_grant',$report_grant);
  176. $this->assign('sample_stand',$sample_stand);
  177. $this->view->assign('row', $row);
  178. return $this->view->fetch();
  179. }
  180. $params = $this->request->post('row/a');
  181. if (empty($params)) {
  182. $this->error(__('Parameter %s can not be empty', ''));
  183. }
  184. $params['project'] = implode(',',$params['project']);
  185. $params['report_grant'] = implode(',',$params['report_grant']);
  186. $params['sample_stand'] = implode(',',$params['sample_stand']);
  187. $params = $this->preExcludeFields($params);
  188. $result = false;
  189. Db::startTrans();
  190. try {
  191. //是否采用模型验证
  192. if ($this->modelValidate) {
  193. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  194. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  195. $row->validateFailException()->validate($validate);
  196. }
  197. $result = $row->allowField(true)->save($params);
  198. Db::commit();
  199. } catch (ValidateException|PDOException|Exception $e) {
  200. Db::rollback();
  201. $this->error($e->getMessage());
  202. }
  203. if (false === $result) {
  204. $this->error(__('No rows were updated'));
  205. }
  206. $this->success();
  207. }
  208. /**
  209. * 删除
  210. *
  211. * @param $ids
  212. * @return void
  213. * @throws DbException
  214. * @throws DataNotFoundException
  215. * @throws ModelNotFoundException
  216. */
  217. public function del($ids = null)
  218. {
  219. if (false === $this->request->isPost()) {
  220. $this->error(__("Invalid parameters"));
  221. }
  222. $ids = $ids ?: $this->request->post("ids");
  223. if (empty($ids)) {
  224. $this->error(__('Parameter %s can not be empty', 'ids'));
  225. }
  226. $idList = explode(',',$ids);
  227. $canDel = true;
  228. foreach ($idList as $key => $value){
  229. $row = $this->model->get($ids);
  230. if (!empty($row['gather_id'])){
  231. $tab = $row['gather_tab'] == 'gather_txt_check_gc'?'gather_txt_gc':'gather_txt_gcms';
  232. $id = $row['gather_id'];
  233. $res = Db::name($tab)->where('id',$id)->find();
  234. if ($res['status'] == 1){
  235. $canDel = false;
  236. }
  237. }
  238. }
  239. if ($canDel === false){
  240. $this->error('检测数据已确认,无法删除!');
  241. }
  242. $pk = $this->model->getPk();
  243. $adminIds = $this->getDataLimitAdminIds();
  244. if (is_array($adminIds)) {
  245. $this->model->where($this->dataLimitField, 'in', $adminIds);
  246. }
  247. $list = $this->model->where($pk, 'in', $ids)->select();
  248. $count = 0;
  249. Db::startTrans();
  250. try {
  251. foreach ($list as $item) {
  252. $count += $item->delete();
  253. }
  254. Db::commit();
  255. } catch (PDOException|Exception $e) {
  256. Db::rollback();
  257. $this->error($e->getMessage());
  258. }
  259. if ($count) {
  260. $this->success();
  261. }
  262. $this->error(__('No rows were deleted'));
  263. }
  264. //提交到检测
  265. public function submit(){
  266. if (false === $this->request->isPost()) {
  267. $id = input('id');
  268. $judgeData = Db::name('item_judge')->whereNull('delete')->column('id,name');
  269. $this->view->assign('judgeData', $judgeData);
  270. $this->view->assign('id', $id);
  271. return $this->view->fetch();
  272. }
  273. $id = input('id');//委托单id
  274. $temp_id = input('temp');//判定标准id
  275. if (empty($id) || empty($temp_id)){
  276. $this->error('参数错误');
  277. }
  278. /***
  279. * 提交后,更新此数据的 判定标准、委托状态
  280. * 根据数据文件名称绑定检测数据
  281. * 生成检测结果
  282. */
  283. $entrust = Db::name('entrust')->where('id',$id)->find();
  284. /***
  285. * 无法确认是哪台机器(GC、GCMS)检测
  286. * 1、先去找gcms表 没有查到数据 再找gc表
  287. */
  288. $data_txt = $entrust['sample_no'].'MS.D'; //如果是GCMS机台,数据文件为委托编号+MS.D
  289. $gather_gcms = Db::name('gather_txt_gcms')->where('data_txt_name',$data_txt)->order('id desc')->find();
  290. if (empty($gather_gcms)){
  291. $data_txt_gc = $entrust['sample_no'].'.D';
  292. $gather_gc = Db::name('gather_txt_gc')->where('data_txt_name',$data_txt_gc)->order('id desc')->find();
  293. if (empty($gather_gc)){
  294. $this->error('未获取到检测数据');
  295. }
  296. $gather = $gather_gc;
  297. $gather_tab = 'gather_txt_check_gc';
  298. }else{
  299. $gather = $gather_gcms;
  300. $gather_tab = 'gather_txt_check_gcms';
  301. }
  302. $detail_data = Db::name($gather_tab)->where('pid',$gather['id'])->field('chemical_compound,potency')->select();
  303. $is_qualified = [];//默认合格,当有一项不合格时,判定此次检测不合格
  304. $dis= 0;//溶剂残留总量
  305. $dis_impurity_data = [];//溶剂杂质总量
  306. $ben_total_data = [];//苯系物总量
  307. $ben = 0; //苯含量
  308. $all_dis_data = []; //所有杂质含量数组
  309. $ethanol = 0; //乙醇含量
  310. $dis_impurity_arr = ['甲醇','丙酮','正丁醇','苯','2-乙氧基乙醇','4-甲基-2-戊酮','甲苯','乙酸正丁酯','乙苯','间对二甲苯','邻-二甲苯','苯乙烯','2-乙氧基乙基乙酸酯','环己酮'];
  311. $ben_arr = ['甲苯','乙苯','间对二甲苯','邻-二甲苯'];
  312. foreach ($detail_data as $key=>$value){
  313. $all_dis_data[$key] = $value['potency'];
  314. if ($value['chemical_compound'] == '乙醇'){//乙醇含量
  315. $ethanol = $value['potency'];
  316. }
  317. if ($value['chemical_compound'] == '苯'){//苯含量
  318. $ben = $value['potency'];
  319. }
  320. if (in_array($value['chemical_compound'],$dis_impurity_arr)){//溶剂杂质总量
  321. $dis_impurity_data[$value['chemical_compound']] = $value['potency'];
  322. }
  323. if (in_array($value['chemical_compound'],$ben_arr)){//苯系物总量
  324. $ben_total_data[$value['chemical_compound']] = $value['potency'];
  325. }
  326. }
  327. $judge = Db::name('item_judge_detail')->where('pid',$temp_id)->select();
  328. $sum_all_dis_data = array_sum($all_dis_data);
  329. $dis = $sum_all_dis_data - $ethanol; //残留总量
  330. $dis_impurity = array_sum($dis_impurity_data); //杂质总量
  331. $ben_total = array_sum($ben_total_data); //苯系物重量
  332. foreach ($judge as $k=>$v){
  333. if ($v['params'] == '溶剂残留总量'){
  334. if ( $dis < $v['max']){
  335. $is_qualified[$k] = 1;
  336. }else{
  337. $is_qualified[$k] = 0;
  338. }
  339. }if ($v['params'] == '溶剂杂质总量' || $v['params'] == '总量'){
  340. if ( $dis_impurity < $v['max']){
  341. $is_qualified[$k] = 1;
  342. }else{
  343. $is_qualified[$k] = 0;
  344. }
  345. }if ($v['params'] == '溶剂杂质苯系物' || $v['params'] == '苯系物'){
  346. if ( $ben_total < $v['max']){
  347. $is_qualified[$k] = 1;
  348. }else{
  349. $is_qualified[$k] = 0;
  350. }
  351. }if ($v['params'] == '溶剂杂质苯' || $v['params'] == '苯'){
  352. if ($ben < $v['max']){
  353. $is_qualified[$k] = 1;
  354. }else{
  355. $is_qualified[$k] = 0;
  356. }
  357. }
  358. }
  359. $is_pass = array_sum($is_qualified);//4项都合格,sum=4才判定合格 不等于4就说明有不合格的
  360. $params = [];//检测结果数据
  361. $params['judge'] = 0;
  362. if ($is_pass == 4){
  363. $params['judge'] = 1;
  364. }
  365. $params['entrust_no'] = $entrust['no'];
  366. $params['entrust_id'] = $entrust['id'];
  367. $params['machine'] = 'GCMS';
  368. if ($gather_tab == 'gather_txt_check_gc'){
  369. $params['machine'] = 'GC';
  370. }
  371. $params['name'] = $entrust['name'];
  372. $params['bach'] = $entrust['bach'];
  373. $params['sample_no'] = $entrust['sample_no'];
  374. $params['standard_id'] = $temp_id;
  375. $params['standard_name'] = $judge[0]['name'];
  376. $params['dis'] = $dis;
  377. $params['dis_impurity'] = $dis_impurity;
  378. $params['ben_total'] = $ben_total;
  379. $params['ben'] = $ben;
  380. $params['unit'] = 'mg/m2';
  381. $params['create'] = date('Y-m-d H:i:s');
  382. $params['maker'] = Session::get('admin')['username'];
  383. $params['params'] = Db::name('item_judge')->where('id',$temp_id)->value('list_name');
  384. $params['userid'] = Session::get('admin')['id'];;
  385. $params['status'] = 0;
  386. $params['work_unit'] = $entrust['work_unit'];
  387. $params['work_name'] = $entrust['work_name'];
  388. //更新数据
  389. $entrust_update = [];
  390. $entrust_update['standard_id'] =$temp_id;
  391. $entrust_update['standard_name'] =$judge[0]['name'];
  392. $entrust_update['status'] =2;
  393. $entrust_update['gather_id'] =$gather['id'];
  394. $entrust_update['gather_tab'] = $gather_tab;
  395. //日志记录
  396. $log = [];
  397. $log['userid'] = Session::get('admin')['id'];
  398. $log['username'] = Session::get('admin')['username'];
  399. $log['operate'] = '提交委托单id值为'.$id.'到检测';
  400. $log['content'] = '选用检测标准为:"'.$entrust_update['standard_name'].'",检测数据为:'.$gather_tab.'/'.$gather['id'];
  401. $log['e_id'] = $id;
  402. $log['create'] = date('Y-m-d H:i:s');
  403. $result = true;
  404. Db::startTrans();
  405. try {
  406. /***
  407. * 提交后,更新此数据的 判定标准、委托状态
  408. * 根据批次号绑定检测数据
  409. * 生成检测结果
  410. */
  411. $entrust_res = Db::name('entrust')->where('id',$id)->update($entrust_update);
  412. $res_check = Db::name('res')->insert($params);
  413. $log_res = Db::name('entrust_log')->insert($log);
  414. if (!$log_res || !$res_check){
  415. $result = false;
  416. }
  417. Db::commit();
  418. } catch (ValidateException|PDOException|Exception $e) {
  419. Db::rollback();
  420. $this->error($e->getMessage());
  421. }
  422. if ($result === false) {
  423. $this->error(__('No rows were inserted'));
  424. }
  425. $this->success();
  426. }
  427. //日志查看
  428. public function log(){
  429. //设置过滤方法
  430. $this->request->filter(['strip_tags', 'trim']);
  431. $params = $this->request->param("ids");
  432. if (false === $this->request->isAjax()) {
  433. $this->view->assign('id', $params);
  434. return $this->view->fetch();
  435. }
  436. //如果发送的来源是 Selectpage,则转发到 Selectpage
  437. if ($this->request->request('keyField')) {
  438. return $this->selectpage();
  439. }
  440. $id = $this->request->param("ids");
  441. $map = [];
  442. if (!empty($params)){
  443. $map['e_id'] = $id;
  444. }
  445. // print_r($map);die;
  446. [$where, $sort, $order, $offset, $limit] = $this->buildparams();
  447. $list = Db::name('entrust_log')
  448. ->where($map)
  449. ->order($sort, $order)
  450. ->paginate($limit);
  451. $result = ['total' => $list->total(), 'rows' => $list->items()];
  452. return json($result);
  453. }
  454. //检测数据查看
  455. public function data(){
  456. $params = input('id');
  457. if (empty($params)){
  458. $this->error('参数错误');
  459. }
  460. $gather_id = Db::name('entrust')->where('id',$params)->find();
  461. if (empty($gather_id['gather_id'])){
  462. $this->error('此委托单还未提交检测,暂无检测数据');
  463. }
  464. //此处根据实际获取到的采集表的数据 gather_tab 去对应表里查数据 重新写一个gc表格页面 js加代码
  465. if ($gather_id['gather_tab'] == 'gather_txt_check_gcms'){
  466. $gather = Db::name('gather_txt_gcms')->where('id',$gather_id['gather_id'])->find();
  467. $data = Db::name('gather_txt_check_gcms')->where('pid',$gather_id['gather_id'])->select();
  468. $this->view->assign('gather', $gather);
  469. $this->view->assign('data', $data);
  470. $this->view->assign('id', $params);
  471. return $this->view->fetch();
  472. }else if ($gather_id['gather_tab'] == 'gather_txt_check_gc'){
  473. $gather = Db::name('gather_txt_gc')->where('id',$gather_id['gather_id'])->find();
  474. $data = Db::name('gather_txt_check_gc')->where('pid',$gather_id['gather_id'])->select();
  475. $this->view->assign('gather', $gather);
  476. $this->view->assign('data', $data);
  477. $this->view->assign('id', $params);
  478. return $this->fetch('datagc');
  479. }
  480. }
  481. //检测数据确认
  482. public function dataSure(){
  483. $params = input('id');
  484. if (empty($params)){
  485. $this->error('参数错误');
  486. }
  487. $gather_id = Db::name('entrust')->where('id',$params)->find();
  488. if (empty($gather_id['gather_id'])){
  489. $this->error('此委托单还未提交检测,暂无检测数据');
  490. }
  491. if ($gather_id['gather_tab'] == 'gather_txt_check_gcms'){
  492. Db::name('gather_txt_gcms')->where('id',$gather_id['gather_id'])->setField('status',1);
  493. }else{
  494. Db::name('gather_txt_gc')->where('id',$gather_id['gather_id'])->setField('status',1);
  495. }
  496. $this->success('确认成功');
  497. }
  498. //委托单页面
  499. public function commissionsheet(){
  500. //获取样品名称
  501. $id = input('id');
  502. if (empty($id)){
  503. $this->error('参数错误');
  504. }
  505. $this->assign('name',Db::name('entrust')->where('id',$id)->find());
  506. //委托单上传
  507. return $this->view->fetch();
  508. }
  509. //委托单上传
  510. public function commissionsheetup(){
  511. $params = [];
  512. if (true === $this->request->isPost()){
  513. $params['entrust_user'] = input('entrust_user');
  514. $params['entrust_time'] = input('entrust_time');
  515. $params['entrust_id'] = input('entrust_id');
  516. $params['name'] = input('name');
  517. $params['status'] = input('status');
  518. $params['num'] = input('num');
  519. $params['project'] = input('project');
  520. $params['no'] = input('no');
  521. $params['requirement'] = input('requirement');
  522. $params['reportnumber'] = input('reportnumber');
  523. $params['deal'] = input('deal');
  524. $params['condition'] = input('condition');
  525. $params['isue'] = input('isue');
  526. $params['testcost'] = input('testcost');
  527. $params['standard'] = input('standard');
  528. }
  529. $judgment = Db::name('entrust_print')->where('entrust_user',$params['entrust_user'])
  530. ->where('entrust_id',$params['entrust_id'])
  531. ->where('entrust_time',$params['entrust_time'])
  532. ->where('name',$params['name'])
  533. ->where('no',$params['no'])->find();
  534. if (empty($judgment)){
  535. $res = Db::name('entrust_print')->insert($params);
  536. if (!empty($res)){
  537. $this->success();
  538. }
  539. }else{
  540. $this->error('该委托单已存在,不需要重新添加');
  541. }
  542. }
  543. //委托单批量打印页面
  544. public function printing(){
  545. $datas=$res = array();
  546. if ($this->request->isGet()){
  547. $ids =explode(',',$this->request->get('ids')) ;
  548. for($i=0;$i<count($ids);$i++){
  549. $datas[$i] = Db::name('entrust')->where('id',$ids[$i])->find();
  550. $res['entrust_id'][$i]=$datas[$i]['no'];
  551. $res['set'][$i]['name'] = $datas[$i]['name'];
  552. $res['set'][$i]['no'] = $datas[$i]['sample_no'];
  553. }
  554. $res['entrust_time'] = $datas[0]['create'];
  555. $res['entrust_id'] = implode('、',array_unique($res['entrust_id']));
  556. $this->view->assign('row',$res);
  557. }
  558. return $this->view->fetch();
  559. }
  560. //委托单批量上传
  561. public function printingup(){
  562. $params = [];
  563. if (true === $this->request->isPost()){
  564. $sampledata = input('sampledata/a');
  565. for ($i=0;$i<count($sampledata);$i++){
  566. $params['entrust_user'] = input('entrust_user');
  567. $params['entrust_time'] = input('entrust_time');
  568. $params['entrust_id'] = input('entrust_id');
  569. $params['requirement'] = input('requirement');
  570. $params['reportnumber'] = input('reportnumber');
  571. $params['deal'] = input('deal');
  572. $params['condition'] = input('condition');
  573. $params['isue'] = input('isue');
  574. $params['testcost'] = input('testcost');
  575. $params['standard'] = input('standard');
  576. $params['name'] = $sampledata[$i][0];
  577. $params['status'] = $sampledata[$i][1];
  578. $params['num'] = $sampledata[$i][2];
  579. $params['project'] = $sampledata[$i][3];
  580. $params['no'] = $sampledata[$i][4];
  581. $res[$i] = Db::name('entrust_print')->insert($params);
  582. }
  583. if (!empty($res)){
  584. $this->success();
  585. }
  586. }
  587. }
  588. //生成委托单号
  589. public function getNo(){
  590. $params = input('temp');
  591. $company = input('company');
  592. if (empty($params) || empty($company)){
  593. $this->error('参数错误');
  594. }
  595. $num = Db::name('entrust')->where('sample_no','like','%'.$params.'%')->whereTime('create','d')->count();
  596. if ($company == '亚欣'){//亚欣送样从100开始
  597. $num = $num+100;
  598. }else{
  599. $num = $num+1;
  600. }
  601. if ($num < 10){
  602. $num = '0'.$num;
  603. }
  604. //一位样品代号+8位日期+当前样品代号第几次送样
  605. $sample_no = date('Ymd').$num;
  606. return array('code'=>1,'data'=>$sample_no);
  607. }
  608. }