ApplyBatchController.class.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  1. <?php
  2. /**
  3. * author Gentle
  4. * intro 申请批次
  5. */
  6. namespace Admin\Controller;
  7. use Think\Page;
  8. class ApplyBatchController extends AdminController
  9. {
  10. /**
  11. * author Gentle
  12. * intro 类初始化方法
  13. * param
  14. * return
  15. */
  16. public function _initialize()
  17. {
  18. parent::_initialize(); // TODO: Change the autogenerated stub
  19. $this->uid = session('user_auth.uid');
  20. // $this->redundancy_s = 0.1;//冗码率
  21. $this->redundancy_s = 0;//冗码率修改为0 时间:2017年11月30日16:22:17
  22. }
  23. /**
  24. * author Gentle
  25. * intro 获取用户组
  26. * param
  27. */
  28. public function getGroups()
  29. {
  30. $uid = $this->uid;
  31. $admin_access_model = D(Admin_access);
  32. $groups = $admin_access_model->where('uid=' . $uid)->getField('group');//1 超级管理 2 印刷厂 3 中烟
  33. return $groups;
  34. }
  35. /**
  36. * author Gentle
  37. * intro 申请批次首页
  38. * param
  39. */
  40. public function index()
  41. {
  42. /**
  43. * @author Gentle
  44. * @tro 遍历展示产品名称、盒型
  45. * @time 2017年9月11日09:35:58
  46. */
  47. if (session('user_auth.uid') == 1) {
  48. $this->success('暂不支持管理员操作');
  49. exit;
  50. }
  51. $printer_list = M(Admin_access)
  52. ->join('__ADMIN_USER__ ON __ADMIN_USER__.id = __ADMIN_ACCESS__.uid')
  53. ->field('QR_ADMIN_USER.id printer_id,QR_ADMIN_USER.nickname printer_name')
  54. ->where('QR_ADMIN_ACCESS.group=2')->order('QR_ADMIN_USER.id asc')->select();
  55. foreach ($printer_list as $val) {
  56. $printer[] = $val;
  57. }
  58. $factory_model = D(Factory);
  59. $list2 = $factory_model->field('id,name')->where('id>0')->order('id asc')->select();
  60. foreach ($list2 as $val) {
  61. $factory_result[] = $val;
  62. $factory_id[] = $val['id'];
  63. }
  64. $product_model = D(Product);
  65. $list = $product_model->field('id,name')->where('factory_id IN (' . implode(',', $factory_id) . ')')->order('id asc')->select();
  66. foreach ($list as $val) {
  67. $product_result[] = $val;
  68. $product_id[] = $val['id'];
  69. }
  70. //暂时不使用
  71. $list2 = M(Product_box_type)
  72. ->join('__BOX_TYPE__ ON __BOX_TYPE__.id = __PRODUCT_BOX_TYPE__.box_type_id')
  73. ->field('QR_BOX_TYPE.id type_id,QR_BOX_TYPE.name box_type_name')
  74. ->where('QR_PRODUCT_BOX_TYPE.product_id>0')->order('QR_PRODUCT_BOX_TYPE.id asc')->select();
  75. foreach ($list2 as $val) {
  76. $box_type_result[] = $val['type_id'];
  77. }
  78. $this->assign('printer', $printer);
  79. $this->assign('product_result', $product_result);
  80. $this->assign('factory_result', $factory_result);
  81. $this->assign('meta_title', '申请批次');
  82. $this->display();
  83. }
  84. /**
  85. * author Gentle
  86. * intro 申请批次列表页面
  87. * param
  88. */
  89. public function applyList()
  90. {
  91. /**
  92. * @author Gentle
  93. * @tro 遍历展示申请批次列表
  94. * @time 2017年9月12日14:17:17
  95. */
  96. //分页
  97. $bach = M(Bach);
  98. $uid = $this->uid;
  99. $groups = $this->GetGroups();
  100. if ($groups == '3') {
  101. $where = 'QR_BACH.owner_id=' . $uid;
  102. $page = new Page(
  103. $bach->where('owner_id=' . $uid)->count(),
  104. C('ADMIN_PAGE_ROWS')
  105. );
  106. } else if ($groups == '2') {
  107. $where = 'QR_BACH.printer_id=' . $uid;
  108. $page = new Page(
  109. $bach->where('printer_id=' . $uid)->count(),
  110. C('ADMIN_PAGE_ROWS')
  111. );
  112. } else {
  113. $where = 'QR_BACH.id > 0';
  114. $page = new Page(
  115. $bach->where('id>0')->count(),
  116. C('ADMIN_PAGE_ROWS')
  117. );
  118. }
  119. $show = $page->show();
  120. $bach_list = M(Bach)
  121. ->join('__ADMIN_USER__ ON __ADMIN_USER__.id = __BACH__.printer_id')
  122. ->field('QR_BACH.id bach_id,QR_BACH.name bach_name,QR_BACH.add_time,QR_ADMIN_USER.nickname printer_name')
  123. ->limit($page->firstRow . ',' . $page->listRows)
  124. ->where($where)->order('QR_BACH.id desc')->select();
  125. $task = M(Task);
  126. foreach ($bach_list as $value) {
  127. $task_ids[] = $task->field('id')->where('bach_id=' . $value['bach_id'])->order('id desc')->select();
  128. }
  129. foreach ($task_ids as $vals) {
  130. foreach ($vals as $val) {
  131. $task_list[] = M(Task)
  132. ->join('__FACTORY__ ON __FACTORY__.id=__TASK__.factory_id ')
  133. ->join('__ADMIN_USER__ ON __ADMIN_USER__.id = __TASK__.printer_id')
  134. ->join('__PRODUCT_BOX_TYPE__ ON __PRODUCT_BOX_TYPE__.id=__TASK__.product_id')
  135. ->join('__PRODUCT__ ON __PRODUCT__.id=__PRODUCT_BOX_TYPE__.product_id')
  136. ->join('__BOX_TYPE__ ON __BOX_TYPE__.id=__PRODUCT_BOX_TYPE__.box_type_id')
  137. ->field('QR_TASK.id task_id,QR_TASK.quality,QR_TASK.bach_id,QR_PRODUCT.name product_name,QR_BOX_TYPE.name box_type_name')->where('QR_TASK.id= ' . $val['id'])->select();
  138. }
  139. }
  140. foreach ($task_list as $val) {
  141. foreach ($val as $v) {
  142. $task_list2[] = $v;
  143. }
  144. }
  145. $this->assign('bach_page', $show);
  146. $this->assign('bach_list', $bach_list);
  147. $this->assign('task_list2', $task_list2);
  148. $this->assign('meta_title', '批次列表');
  149. $this->display();
  150. }
  151. /**
  152. * author Gentle
  153. * intro 任务列表页面
  154. * param
  155. */
  156. public function taskList()
  157. {
  158. /**
  159. * @author Gentle
  160. * @tro 遍历展示申请批次列表
  161. * @time 2017年9月15日13:17:17
  162. */
  163. if (empty($_GET['bach_id'])) {
  164. $this->error('批次id不能为空');
  165. }
  166. $bach_id = $_GET['bach_id'];
  167. //分页
  168. $task = M(Task);
  169. $page = new Page(
  170. $task->where('bach_id=' . $bach_id)->count(),
  171. C('ADMIN_PAGE_ROWS')
  172. );
  173. $show = $page->show();
  174. $task_ids = $task->field('id')->where('bach_id=' . $bach_id)->order('id desc')->select();
  175. foreach ($task_ids as $val) {
  176. $task_list[] = M(Task)
  177. ->join('__FACTORY__ ON __FACTORY__.id=__TASK__.factory_id ')
  178. ->join('__ADMIN_USER__ ON __ADMIN_USER__.id = __TASK__.printer_id')
  179. ->join('__PRODUCT_BOX_TYPE__ ON __PRODUCT_BOX_TYPE__.id=__TASK__.product_id')
  180. ->join('__PRODUCT__ ON __PRODUCT__.id=__PRODUCT_BOX_TYPE__.product_id')
  181. ->join('__BOX_TYPE__ ON __BOX_TYPE__.id=__PRODUCT_BOX_TYPE__.box_type_id')
  182. ->field('printer_id,QR_PRODUCT_BOX_TYPE.id product_id,QR_ADMIN_USER.nickname printer_name,QR_TASK.id task_id,QR_TASK.checked_num,QR_TASK.wrong_num,QR_TASK.name task_name,QR_TASK.quality,QR_TASK.add_time,QR_TASK.is_verif,QR_TASK.bach_id,QR_TASK.status,QR_FACTORY.name factory_name,QR_PRODUCT.name product_name,QR_BOX_TYPE.name box_type_name')->where('QR_TASK.id= ' . $val['id'])->find();
  183. }
  184. foreach ($task_list as &$val) {
  185. $val['checked_num'] = $val['checked_num']/10000;
  186. $val['wrong_numck_num'] = $val['wrong_num']/10000;
  187. }
  188. unset($val);
  189. $this->assign('task_page', $show);
  190. $this->assign('task_list', $task_list);
  191. $this->assign('meta_title', '任务列表');
  192. $this->display();
  193. }
  194. /**
  195. * author Gentle
  196. * intro 任务详情页面
  197. * param 2017年9月15日15:31:22
  198. */
  199. public function taskDetail()
  200. {
  201. /**
  202. * @author Gentle
  203. * @tro 批次详情页面展示
  204. * @time 2017年9月13日19:27:28
  205. */
  206. if (empty($_GET['task_id'])) {
  207. $this->error('任务id不能为空');
  208. }
  209. $task_id = $_GET['task_id'];
  210. $task_detail = M(Task)
  211. ->join('__FACTORY__ ON __FACTORY__.id=__TASK__.factory_id ')
  212. ->join('__PRODUCT_BOX_TYPE__ ON __PRODUCT_BOX_TYPE__.id=__TASK__.product_id')
  213. ->join('__PRODUCT__ ON __PRODUCT__.id=__PRODUCT_BOX_TYPE__.product_id')
  214. ->join('__BOX_TYPE__ ON __BOX_TYPE__.id=__PRODUCT_BOX_TYPE__.box_type_id')
  215. ->field('QR_TASK.id task_id,QR_TASK.printer_id printer_id,QR_TASK.name task_name,QR_TASK.bach_id,QR_TASK.lock,QR_TASK.quality,QR_TASK.redundancy,QR_TASK.add_time,QR_TASK.is_verif,QR_TASK.bach_id,QR_TASK.status,QR_TASK.checked_num,QR_TASK.wrong_num,QR_FACTORY.name factory_name,qr_product_box_type.id product_id,QR_PRODUCT.name product_name,QR_BOX_TYPE.name box_type_name')
  216. ->where('QR_TASK.id=' . $task_id)->order('QR_TASK.id asc')->select();
  217. $task_detail[0][checked_num] = $task_detail[0][checked_num]/10000;
  218. $task_detail[0][wrong_num] = $task_detail[0][wrong_num]/10000;
  219. /*
  220. foreach ($task_detail as $k=>$v){
  221. $task_ids=M('task')->where(array('name'=>$v['task_name']))->getField('id',true);
  222. if(in_array($v['task_id'],$task_ids)){
  223. }
  224. }*/
  225. $this->assign('task_detail', $task_detail);
  226. $this->assign('meta_title', '任务详情');
  227. $this->assign('redundancy_s', ($this->redundancy_s)*100);
  228. $this->display();
  229. }
  230. /**
  231. * author Gentle
  232. * intro 申请批次方法
  233. * param
  234. * return bool
  235. */
  236. public function applyForm()
  237. {
  238. if (IS_POST) {
  239. $bach_object = D("Bach");
  240. $bach_product_object = D("Bach_product");
  241. $task_object = D("Task");
  242. //校验$_POST数据
  243. if (empty($_POST['product_id'])) {
  244. alert(array('info' => '产品不能为空', 'status' => 2));
  245. exit;
  246. }
  247. if (empty($_POST['factory_id'])) {
  248. alert(array('info' => '工厂名称不能为空', 'status' => 3));
  249. exit;
  250. }
  251. if (empty($_POST['printer_id'])) {
  252. alert(array('info' => '印刷厂名称不能为空', 'status' => 4));
  253. exit;
  254. }
  255. if (empty($_POST['code_num1']) and empty($_POST['code_num2'])) {
  256. alert(array('info' => '条盒、小包数量不能都小于0', 'status' => 5));
  257. exit;
  258. }
  259. $product_id = $_POST['product_id'];
  260. $factory_id = $_POST['factory_id'];
  261. $printer_id = $_POST['printer_id'];
  262. $is_verif = (int)$_POST['is_verif'];
  263. $remark = $_POST['remark'];
  264. $code_num = [
  265. 'code_num1' => $_POST['code_num1'],
  266. 'code_num2' => $_POST['code_num2']
  267. ];
  268. //查找产品、类别关联表
  269. $product_box_type_ids = M(Product_box_type)
  270. ->field('id')
  271. ->where('product_id=' . $product_id)->order('box_type_id asc')->select();
  272. foreach ($product_box_type_ids as $val) {
  273. $product_box_type_id[] = $val['id'];
  274. }
  275. $data = [];
  276. $data['name'] = 'MNYH_' . date("Ymdhi", time());
  277. $data['add_time'] = time();
  278. $data['remark'] = $remark;
  279. $data['printer_id'] = $printer_id;
  280. $data['owner_id'] = $this->uid;
  281. $param = [];
  282. $param['product_id'] = $product_id;
  283. $param['is_verif'] = $is_verif;
  284. $param['add_time'] = time();
  285. $param['remark'] = $remark;
  286. $param1 = $param;
  287. $param2 = $param;
  288. $param1['num'] = $code_num['code_num1'];
  289. $param1['product_id'] = $product_box_type_id[0];
  290. $param2['num'] = $code_num['code_num2'];
  291. $param2['product_id'] = $product_box_type_id[1];
  292. $add_param = [
  293. $param1,
  294. $param2
  295. ];
  296. $params = [];
  297. $params['name'] = $data['name'];
  298. $params['factory_id'] = $factory_id;
  299. $params['is_verif'] = $is_verif;
  300. $params['add_time'] = time();
  301. $params['remark'] = $remark;
  302. $params['status'] = '0';
  303. $params['printer_id'] = $printer_id;
  304. $params['owner_id'] = $this->uid;
  305. $params1 = $params;
  306. $params2 = $params;
  307. $params1['quality'] = $code_num['code_num1'];
  308. $params1['redundancy'] = $code_num['code_num1'] * $this->redundancy_s;
  309. $params1['product_id'] = $product_box_type_id[0];
  310. $params2['quality'] = $code_num['code_num2'];
  311. $params2['redundancy'] = $code_num['code_num2'] * $this->redundancy_s;
  312. $params2['product_id'] = $product_box_type_id[1];
  313. if ($data && $add_param) {
  314. $bach_id = $bach_object->add($data);
  315. $param1['bach_id'] = $bach_id;
  316. $param2['bach_id'] = $bach_id;
  317. if(empty($code_num['code_num1']) and !empty($code_num['code_num2'])){
  318. $add_param = $param2;
  319. $bach_product_id = $bach_product_object->add($add_param);
  320. }else if(empty($code_num['code_num2']) and !empty($code_num['code_num1'])){
  321. $add_param = $param1;
  322. $bach_product_id = $bach_product_object->add($add_param);
  323. }else{
  324. $add_param = [
  325. $param1,
  326. $param2
  327. ];
  328. $bach_product_id = $bach_product_object->addAll($add_param);
  329. }
  330. if ($bach_id && $bach_product_id) {
  331. $params1['bach_id'] = $bach_id;
  332. $params2['bach_id'] = $bach_id;
  333. if(empty($code_num['code_num1']) and !empty($code_num['code_num2'])){
  334. $add_params = $params2;
  335. $task_id = $task_object->add($add_params);
  336. }else if(empty($code_num['code_num2']) and !empty($code_num['code_num1'])){
  337. $add_params = $params1;
  338. $task_id = $task_object->add($add_params);
  339. }else{
  340. $add_params = [
  341. $params1,
  342. $params2
  343. ];
  344. $task_id = $task_object->addAll($add_params);
  345. }
  346. if ($task_id) {
  347. alert(array('info' => '申请成功', 'url' => "index.php?s=/Admin/ApplyBatch/applylist.html", 'status' => 1));
  348. } else {
  349. alert(array('info' => '申请失败', 'url' => "index.php?s=/Admin/ApplyBatch/Index.html", 'status' => 0));
  350. }
  351. } else {
  352. $this->error($bach_object->getError());
  353. }
  354. } else {
  355. $this->error($bach_object->getError());
  356. }
  357. } else {
  358. // 跳转到申请批次页面
  359. header("Location: {:U('ApplyBatch/applylist')}");
  360. }
  361. }
  362. /**
  363. * author Gentle
  364. * intro 批次补单申请页面
  365. * param
  366. */
  367. public function addTaskIndex()
  368. {
  369. if (empty($_GET['task_id'])) {
  370. $this->error('补单任务id不能为空');
  371. }
  372. $task_id = $_GET['task_id'];
  373. $task_model = D("Task");
  374. $tasks = $task_model->field('bach_id')->where('id=' . $task_id)->order('id asc')->find();
  375. $bach_id = $tasks['bach_id'];
  376. $bach_model = D("Bach");
  377. $bach_name = $bach_model->field('name')->where('id=' . $bach_id)->order('id asc')->find();
  378. $bach_contents['task_id'] = $task_id;
  379. $bach_contents['bach_id'] = $bach_id;
  380. $bach_contents['bach_name'] = $bach_name['name'];
  381. $task_list = $task_model->field('product_id')->where('bach_id=' . $bach_id)->order('id asc')->select();
  382. if (empty($task_list)) {
  383. $this->error('您未创建过该任务,请核对任务后操作!');
  384. }
  385. foreach ($task_list as $val) {
  386. $product_id[] = $val['product_id'];
  387. $product_id = array_unique($product_id);
  388. }
  389. foreach ($product_id as $val) {
  390. $product_contents[] = M(Box_type)
  391. ->join('__PRODUCT_BOX_TYPE__ ON __PRODUCT_BOX_TYPE__.box_type_id = __BOX_TYPE__.id')
  392. ->field('QR_PRODUCT_BOX_TYPE.id product_id,QR_BOX_TYPE.name box_type_name')
  393. ->where('QR_PRODUCT_BOX_TYPE.id=' . $val)->order('QR_PRODUCT_BOX_TYPE.id asc')->select();
  394. }
  395. foreach ($product_contents as $val) {
  396. foreach ($val as $v) {
  397. $product_contents_list[] = $v;
  398. }
  399. }
  400. $this->assign('bach_contents', $bach_contents);
  401. $this->assign('product_contents_list', $product_contents_list);
  402. $this->assign('meta_title', '任务补单申请');
  403. $this->display();
  404. }
  405. /**
  406. * author Gentle
  407. * intro 批次补单申请方法
  408. * param
  409. */
  410. public function addTaskForm()
  411. {
  412. if ($_POST) {
  413. //校验$_POST数据
  414. if (empty($_POST['bach_id'])) {
  415. alert(array('info' => '补单批次id不能为空', 'status' => 2));
  416. exit;
  417. }
  418. if (empty($_POST['product_id'])) {
  419. alert(array('info' => '补单产品盒型不能为空', 'status' => 3));
  420. exit;
  421. }
  422. if (empty($_POST['code_num'])) {
  423. alert(array('info' => '补单产品数量不能为空', 'status' => 4));
  424. exit;
  425. }
  426. $datas['bach_id'] = $_POST['bach_id'];
  427. $datas['product_id'] = $_POST['product_id'];
  428. $datas['quality'] = $_POST['code_num'];
  429. $datas['redundancy'] = $_POST['code_num'] * $this->redundancy_s;
  430. $datas['remark'] = $_POST['remark'];
  431. $datas['add_time'] = time();
  432. $task_model = D("Task");
  433. $task_contents = $task_model->field('name,factory_id,is_verif,printer_id,owner_id')->where('bach_id=' . $_POST['bach_id'])->order('id asc')->find();
  434. $data = array_merge($datas, $task_contents);
  435. $task_id = $task_model->add($data);
  436. if ($task_id) {
  437. alert(array('info' => '补单申请成功', 'url' => "index.php?s=/Admin/ApplyBatch/tasklist/bach_id/" . $_POST['bach_id'] . ".html", 'status' => 1));
  438. } else {
  439. alert(array('info' => '补单申请失败', 'url' => "index.php?s=/Admin/ApplyBatch/addTaskIndex/bach_id/" . $_POST['bach_id'] . ".html", 'status' => 0));
  440. }
  441. }
  442. }
  443. /**
  444. * author Gentle
  445. * intro 调用下载函数
  446. * param
  447. */
  448. public function downloadZip()
  449. {
  450. $bach_name = I('bach_name');
  451. $printer_id = I('printer_id');
  452. if (!downZip($bach_name, $printer_id)) {
  453. $this->error('文件不存在,请联系管理员');
  454. }
  455. }
  456. }