| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472 |
- <?php
- /**
- * author Gentle
- * intro 申请批次
- */
- namespace Admin\Controller;
- use Think\Page;
- class ApplyBatchController extends AdminController
- {
- /**
- * author Gentle
- * intro 类初始化方法
- * param
- * return
- */
- public function _initialize()
- {
- parent::_initialize(); // TODO: Change the autogenerated stub
- $this->uid = session('user_auth.uid');
- $this->redundancy_s = 0.1;//冗码率
- }
- /**
- * author Gentle
- * intro 获取用户组
- * param
- */
- public function getGroups()
- {
- $uid = $this->uid;
- $admin_access_model = D(Admin_access);
- $groups = $admin_access_model->where('uid=' . $uid)->getField('group');//1 超级管理 2 印刷厂 3 中烟
- return $groups;
- }
- /**
- * author Gentle
- * intro 申请批次首页
- * param
- */
- public function index()
- {
- /**
- * @author Gentle
- * @tro 遍历展示产品名称、盒型
- * @time 2017年9月11日09:35:58
- */
- if (session('user_auth.uid') == 1) {
- $this->success('暂不支持管理员操作');
- exit;
- }
- $printer_list = M(Admin_access)
- ->join('__ADMIN_USER__ ON __ADMIN_USER__.id = __ADMIN_ACCESS__.uid')
- ->field('QR_ADMIN_USER.id printer_id,QR_ADMIN_USER.nickname printer_name')
- ->where('QR_ADMIN_ACCESS.group=2')->order('QR_ADMIN_USER.id asc')->select();
- foreach ($printer_list as $val) {
- $printer[] = $val;
- }
- $factory_model = D(Factory);
- $list2 = $factory_model->field('id,name')->where('id>0')->order('id asc')->select();
- foreach ($list2 as $val) {
- $factory_result[] = $val;
- $factory_id[] = $val['id'];
- }
- $product_model = D(Product);
- $list = $product_model->field('id,name')->where('factory_id IN (' . implode(',', $factory_id) . ')')->order('id asc')->select();
- foreach ($list as $val) {
- $product_result[] = $val;
- $product_id[] = $val['id'];
- }
- //暂时不使用
- $list2 = M(Product_box_type)
- ->join('__BOX_TYPE__ ON __BOX_TYPE__.id = __PRODUCT_BOX_TYPE__.box_type_id')
- ->field('QR_BOX_TYPE.id type_id,QR_BOX_TYPE.name box_type_name')
- ->where('QR_PRODUCT_BOX_TYPE.product_id>0')->order('QR_PRODUCT_BOX_TYPE.id asc')->select();
- foreach ($list2 as $val) {
- $box_type_result[] = $val['type_id'];
- }
- $this->assign('printer', $printer);
- $this->assign('product_result', $product_result);
- $this->assign('factory_result', $factory_result);
- $this->assign('meta_title', '申请批次');
- $this->display();
- }
- /**
- * author Gentle
- * intro 申请批次列表页面
- * param
- */
- public function applyList()
- {
- /**
- * @author Gentle
- * @tro 遍历展示申请批次列表
- * @time 2017年9月12日14:17:17
- */
- //分页
- $bach = M(Bach);
- $uid = $this->uid;
- $groups = $this->GetGroups();
- if ($groups == '3') {
- $where = 'QR_BACH.owner_id=' . $uid;
- $page = new Page(
- $bach->where('owner_id=' . $uid)->count(),
- C('ADMIN_PAGE_ROWS')
- );
- } else if ($groups == '2') {
- $where = 'QR_BACH.printer_id=' . $uid;
- $page = new Page(
- $bach->where('printer_id=' . $uid)->count(),
- C('ADMIN_PAGE_ROWS')
- );
- } else {
- $where = 'QR_BACH.id > 0';
- $page = new Page(
- $bach->where('id>0')->count(),
- C('ADMIN_PAGE_ROWS')
- );
- }
- $show = $page->show();
- $bach_list = M(Bach)
- ->join('__ADMIN_USER__ ON __ADMIN_USER__.id = __BACH__.printer_id')
- ->field('QR_BACH.id bach_id,QR_BACH.name bach_name,QR_BACH.add_time,QR_ADMIN_USER.nickname printer_name')
- ->limit($page->firstRow . ',' . $page->listRows)
- ->where($where)->order('QR_BACH.id desc')->select();
- $task = M(Task);
- foreach ($bach_list as $value) {
- $task_ids[] = $task->field('id')->where('bach_id=' . $value['bach_id'])->order('id desc')->select();
- }
- foreach ($task_ids as $vals) {
- foreach ($vals as $val) {
- $task_list[] = M(Task)
- ->join('__FACTORY__ ON __FACTORY__.id=__TASK__.factory_id ')
- ->join('__ADMIN_USER__ ON __ADMIN_USER__.id = __TASK__.printer_id')
- ->join('__PRODUCT_BOX_TYPE__ ON __PRODUCT_BOX_TYPE__.id=__TASK__.product_id')
- ->join('__PRODUCT__ ON __PRODUCT__.id=__PRODUCT_BOX_TYPE__.product_id')
- ->join('__BOX_TYPE__ ON __BOX_TYPE__.id=__PRODUCT_BOX_TYPE__.box_type_id')
- ->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();
- }
- }
- foreach ($task_list as $val) {
- foreach ($val as $v) {
- $task_list2[] = $v;
- }
- }
- $this->assign('bach_page', $show);
- $this->assign('bach_list', $bach_list);
- $this->assign('task_list2', $task_list2);
- $this->assign('meta_title', '批次列表');
- $this->display();
- }
- /**
- * author Gentle
- * intro 任务列表页面
- * param
- */
- public function taskList()
- {
- /**
- * @author Gentle
- * @tro 遍历展示申请批次列表
- * @time 2017年9月15日13:17:17
- */
- if (empty($_GET['bach_id'])) {
- $this->error('批次id不能为空');
- }
- $bach_id = $_GET['bach_id'];
- //分页
- $task = M(Task);
- $page = new Page(
- $task->where('bach_id=' . $bach_id)->count(),
- C('ADMIN_PAGE_ROWS')
- );
- $show = $page->show();
- $task_ids = $task->field('id')->where('bach_id=' . $bach_id)->order('id desc')->select();
- foreach ($task_ids as $val) {
- $task_list[] = M(Task)
- ->join('__FACTORY__ ON __FACTORY__.id=__TASK__.factory_id ')
- ->join('__ADMIN_USER__ ON __ADMIN_USER__.id = __TASK__.printer_id')
- ->join('__PRODUCT_BOX_TYPE__ ON __PRODUCT_BOX_TYPE__.id=__TASK__.product_id')
- ->join('__PRODUCT__ ON __PRODUCT__.id=__PRODUCT_BOX_TYPE__.product_id')
- ->join('__BOX_TYPE__ ON __BOX_TYPE__.id=__PRODUCT_BOX_TYPE__.box_type_id')
- ->field('printer_id,QR_PRODUCT_BOX_TYPE.id product_id,QR_ADMIN_USER.nickname printer_name,QR_TASK.id task_id,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'])->select();
- }
- foreach ($task_list as $val) {
- foreach ($val as $v) {
- $task_list2[] = $v;
- }
- }
- $this->assign('task_page', $show);
- $this->assign('task_list', $task_list2);
- $this->assign('meta_title', '任务列表');
- $this->display();
- }
- /**
- * author Gentle
- * intro 任务详情页面
- * param 2017年9月15日15:31:22
- */
- public function taskDetail()
- {
- /**
- * @author Gentle
- * @tro 批次详情页面展示
- * @time 2017年9月13日19:27:28
- */
- if (empty($_GET['task_id'])) {
- $this->error('任务id不能为空');
- }
- $task_id = $_GET['task_id'];
- $task_detail = M(Task)
- ->join('__FACTORY__ ON __FACTORY__.id=__TASK__.factory_id ')
- ->join('__PRODUCT_BOX_TYPE__ ON __PRODUCT_BOX_TYPE__.id=__TASK__.product_id')
- ->join('__PRODUCT__ ON __PRODUCT__.id=__PRODUCT_BOX_TYPE__.product_id')
- ->join('__BOX_TYPE__ ON __BOX_TYPE__.id=__PRODUCT_BOX_TYPE__.box_type_id')
- ->field('QR_TASK.id task_id,QR_TASK.name task_name,QR_TASK.bach_id,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.name product_name,QR_BOX_TYPE.name box_type_name')
- ->where('QR_TASK.id=' . $task_id)->order('QR_TASK.id asc')->select();
- /*
- foreach ($task_detail as $k=>$v){
- $task_ids=M('task')->where(array('name'=>$v['task_name']))->getField('id',true);
- if(in_array($v['task_id'],$task_ids)){
- }
- }*/
- $this->assign('task_detail', $task_detail);
- $this->assign('meta_title', '任务详情');
- $this->display();
- }
- /**
- * author Gentle
- * intro 申请批次方法
- * param
- * return bool
- */
- public function applyForm()
- {
- if (IS_POST) {
- $bach_object = D("Bach");
- $bach_product_object = D("Bach_product");
- $task_object = D("Task");
- //校验$_POST数据
- if (empty($_POST['product_id'])) {
- alert(array('info' => '产品不能为空', 'status' => 2));
- exit;
- }
- if (empty($_POST['factory_id'])) {
- alert(array('info' => '工厂名称不能为空', 'status' => 3));
- exit;
- }
- if (empty($_POST['printer_id'])) {
- alert(array('info' => '印刷厂名称不能为空', 'status' => 4));
- exit;
- }
- if (empty($_POST['code_num1']) or empty($_POST['code_num2'])) {
- alert(array('info' => '条盒、小包数量都不能小于0', 'status' => 5));
- exit;
- }
- $product_id = $_POST['product_id'];
- $factory_id = $_POST['factory_id'];
- $printer_id = $_POST['printer_id'];
- $is_verif = (int)$_POST['is_verif'];
- $remark = $_POST['remark'];
- $code_num = [
- 'code_num1' => $_POST['code_num1'],
- 'code_num2' => $_POST['code_num2']
- ];
- //查找产品、类别关联表
- $product_box_type_ids = M(Product_box_type)
- ->field('id')
- ->where('product_id=' . $product_id)->order('box_type_id asc')->select();
- foreach ($product_box_type_ids as $val) {
- $product_box_type_id[] = $val['id'];
- }
- $data = [];
- $data['name'] = 'MNYH_' . date("Ymdhi", time());
- $data['add_time'] = time();
- $data['remark'] = $remark;
- $data['printer_id'] = $printer_id;
- $data['owner_id'] = $this->uid;
- $param = [];
- $param['product_id'] = $product_id;
- $param['is_verif'] = $is_verif;
- $param['add_time'] = time();
- $param['remark'] = $remark;
- $param1 = $param;
- $param2 = $param;
- $param1['num'] = $code_num['code_num1'];
- $param1['product_id'] = $product_box_type_id[0];
- $param2['num'] = $code_num['code_num2'];
- $param2['product_id'] = $product_box_type_id[1];
- $add_param = [
- $param1,
- $param2
- ];
- $params = [];
- $params['name'] = $data['name'];
- $params['factory_id'] = $factory_id;
- $params['is_verif'] = $is_verif;
- $params['add_time'] = time();
- $params['remark'] = $remark;
- $params['status'] = '0';
- $params['printer_id'] = $printer_id;
- $params['owner_id'] = $this->uid;
- $params1 = $params;
- $params2 = $params;
- $params1['quality'] = $code_num['code_num1'];
- $params1['redundancy'] = $code_num['code_num1'] * $this->redundancy_s;
- $params1['product_id'] = $product_box_type_id[0];
- $params2['quality'] = $code_num['code_num2'];
- $params2['redundancy'] = $code_num['code_num2'] * $this->redundancy_s;
- $params2['product_id'] = $product_box_type_id[1];
- if ($data && $add_param) {
- $bach_id = $bach_object->add($data);
- $param1['bach_id'] = $bach_id;
- $param2['bach_id'] = $bach_id;
- $add_param = [
- $param1,
- $param2
- ];
- $bach_product_id = $bach_product_object->addAll($add_param);
- if ($bach_id && $bach_product_id) {
- $params1['bach_id'] = $bach_id;
- $params2['bach_id'] = $bach_id;
- $add_params = [
- $params1,
- $params2
- ];
- $task_id = $task_object->addAll($add_params);
- if ($task_id) {
- alert(array('info' => '申请成功', 'url' => "index.php?s=/Admin/ApplyBatch/applylist.html", 'status' => 1));
- } else {
- alert(array('info' => '申请失败', 'url' => "index.php?s=/Admin/ApplyBatch/Index.html", 'status' => 0));
- }
- } else {
- $this->error($bach_object->getError());
- }
- } else {
- $this->error($bach_object->getError());
- }
- } else {
- // 跳转到申请批次页面
- header("Location: {:U('ApplyBatch/applylist')}");
- }
- }
- /**
- * author Gentle
- * intro 批次补单申请页面
- * param
- */
- public function addTaskIndex()
- {
- if (empty($_GET['task_id'])) {
- $this->error('补单任务id不能为空');
- }
- $task_id = $_GET['task_id'];
- $task_model = D("Task");
- $tasks = $task_model->field('bach_id')->where('id=' . $task_id)->order('id asc')->find();
- $bach_id = $tasks['bach_id'];
- $bach_model = D("Bach");
- $bach_name = $bach_model->field('name')->where('id=' . $bach_id)->order('id asc')->find();
- $bach_contents['task_id'] = $task_id;
- $bach_contents['bach_id'] = $bach_id;
- $bach_contents['bach_name'] = $bach_name['name'];
- $task_list = $task_model->field('product_id')->where('bach_id=' . $bach_id)->order('id asc')->select();
- if (empty($task_list)) {
- $this->error('您未创建过该任务,请核对任务后操作!');
- }
- foreach ($task_list as $val) {
- $product_id[] = $val['product_id'];
- $product_id = array_unique($product_id);
- }
- foreach ($product_id as $val) {
- $product_contents[] = M(Box_type)
- ->join('__PRODUCT_BOX_TYPE__ ON __PRODUCT_BOX_TYPE__.box_type_id = __BOX_TYPE__.id')
- ->field('QR_PRODUCT_BOX_TYPE.id product_id,QR_BOX_TYPE.name box_type_name')
- ->where('QR_PRODUCT_BOX_TYPE.id=' . $val)->order('QR_PRODUCT_BOX_TYPE.id asc')->select();
- }
- foreach ($product_contents as $val) {
- foreach ($val as $v) {
- $product_contents_list[] = $v;
- }
- }
- $this->assign('bach_contents', $bach_contents);
- $this->assign('product_contents_list', $product_contents_list);
- $this->assign('meta_title', '任务补单申请');
- $this->display();
- }
- /**
- * author Gentle
- * intro 批次补单申请方法
- * param
- */
- public function addTaskForm()
- {
- if ($_POST) {
- //校验$_POST数据
- if (empty($_POST['bach_id'])) {
- alert(array('info' => '补单批次id不能为空', 'status' => 2));
- exit;
- }
- if (empty($_POST['product_id'])) {
- alert(array('info' => '补单产品盒型不能为空', 'status' => 3));
- exit;
- }
- if (empty($_POST['code_num'])) {
- alert(array('info' => '补单产品数量不能为空', 'status' => 4));
- exit;
- }
- $datas['bach_id'] = $_POST['bach_id'];
- $datas['product_id'] = $_POST['product_id'];
- $datas['quality'] = $_POST['code_num'];
- $datas['redundancy'] = $_POST['code_num'] * $this->redundancy_s;
- $datas['remark'] = $_POST['remark'];
- $datas['add_time'] = time();
- $task_model = D("Task");
- $task_contents = $task_model->field('name,factory_id,is_verif,printer_id,owner_id')->where('bach_id=' . $_POST['bach_id'])->order('id asc')->find();
- $data = array_merge($datas, $task_contents);
- $task_id = $task_model->add($data);
- if ($task_id) {
- alert(array('info' => '补单申请成功', 'url' => "index.php?s=/Admin/ApplyBatch/tasklist/bach_id/" . $_POST['bach_id'] . ".html", 'status' => 1));
- } else {
- alert(array('info' => '补单申请失败', 'url' => "index.php?s=/Admin/ApplyBatch/addTaskIndex/bach_id/" . $_POST['bach_id'] . ".html", 'status' => 0));
- }
- }
- }
- /**
- * author Gentle
- * intro 调用下载函数
- * param
- */
- public function downloadZip()
- {
- $bach_name = I('bach_name');
- $printer_id = I('printer_id');
- if (!downZip($bach_name, $printer_id)) {
- $this->error('文件不存在,请联系管理员');
- }
- }
- }
|