Entrust.php 28 KB

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