Entrust.php 24 KB

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