Entrust.php 24 KB

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