Entrust.php 28 KB

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