Entrust.php 25 KB

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