|
@@ -16,6 +16,7 @@ use addons\qingdongams\model\Flow;
|
|
|
use addons\qingdongams\model\Message;
|
|
|
use addons\qingdongams\model\OperationLog;
|
|
|
use addons\qingdongams\model\Product;
|
|
|
+use addons\qingdongams\model\StaffRole;
|
|
|
use addons\qingdongams\model\StaffSignIn;
|
|
|
use addons\qingdongams\model\WorkorderLogistics;
|
|
|
use addons\qingdongams\model\WorkorderProgress;
|
|
@@ -31,6 +32,7 @@ use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
|
|
use PhpOffice\PhpSpreadsheet\Style\Alignment;
|
|
|
use PhpOffice\PhpSpreadsheet\Style\Font;
|
|
|
+
|
|
|
/**
|
|
|
* 工单管理
|
|
|
* @icon fa fa-user
|
|
@@ -38,7 +40,7 @@ use PhpOffice\PhpSpreadsheet\Style\Font;
|
|
|
class Workorder extends Base
|
|
|
{
|
|
|
protected $relationSearch = true;
|
|
|
- protected $searchFields = 'id,workorder_number,title';
|
|
|
+ protected $searchFields = 'id,workorder_number,title';
|
|
|
/**
|
|
|
* @var \addons\qingdongams\model\Workorder
|
|
|
*/
|
|
@@ -54,55 +56,56 @@ class Workorder extends Base
|
|
|
|
|
|
}
|
|
|
|
|
|
- public function excel(){
|
|
|
- // 创建Excel对象
|
|
|
+ public function excel()
|
|
|
+ {
|
|
|
+ // 创建Excel对象
|
|
|
$spreadsheet = new Spreadsheet();
|
|
|
$sheet = $spreadsheet->getActiveSheet();
|
|
|
- $map=[];
|
|
|
- $wheres=[];
|
|
|
- $createtime = input('createtime','');
|
|
|
- if($createtime && $createtime !='null '){
|
|
|
- $start = date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),1,date("Y")));
|
|
|
- $end = date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("t"),date("Y")));
|
|
|
- $wheres['createtime'] = array('between',array(strtotime($start),strtotime($end)));
|
|
|
- }
|
|
|
- $owner_staff_id = input('owner_staff_id','');
|
|
|
-
|
|
|
+ $map = [];
|
|
|
+ $wheres = [];
|
|
|
+ $createtime = input('createtime', '');
|
|
|
+ if ($createtime && $createtime != 'null ') {
|
|
|
+ $start = date("Y-m-d H:i:s", mktime(0, 0, 0, date("m"), 1, date("Y")));
|
|
|
+ $end = date("Y-m-d H:i:s", mktime(23, 59, 59, date("m"), date("t"), date("Y")));
|
|
|
+ $wheres['createtime'] = array('between', array(strtotime($start), strtotime($end)));
|
|
|
+ }
|
|
|
+ $owner_staff_id = input('owner_staff_id', '');
|
|
|
+
|
|
|
// dump($owner_staff_id);
|
|
|
- if($owner_staff_id>0){
|
|
|
+ if ($owner_staff_id > 0) {
|
|
|
$map['owner_staff_id'] = $owner_staff_id;
|
|
|
}
|
|
|
$whereStaff = function ($query) {
|
|
|
$query->where('create_staff_id|owner_staff_id', 'in', Staff::getMyStaffIds())
|
|
|
->whereOr('', 'exp', "FIND_IN_SET({$this->_staff->id},show_staff_id)");
|
|
|
};
|
|
|
-
|
|
|
+
|
|
|
$list = $this->model->where($map)->where($wheres)->where($whereStaff)->with(['customer', 'contacts'])->order('id desc')->select();
|
|
|
|
|
|
// 设置列宽
|
|
|
- $sheet->getColumnDimension('A')->setWidth(15);
|
|
|
- $sheet->getColumnDimension('B')->setWidth(20);
|
|
|
- $sheet->getColumnDimension('C')->setWidth(25);
|
|
|
- $sheet->getColumnDimension('D')->setWidth(25);
|
|
|
- $sheet->getColumnDimension('E')->setWidth(25);
|
|
|
- $sheet->getColumnDimension('F')->setWidth(25);
|
|
|
- $sheet->getColumnDimension('G')->setWidth(25);
|
|
|
-
|
|
|
- // 设置标题栏样式
|
|
|
- $titleStyle = $sheet->getStyle('A1:G1');
|
|
|
- $titleStyle->getFont()->setBold(true);
|
|
|
- $titleStyle->getFont()->setSize(14);
|
|
|
- $titleStyle->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
|
|
|
+ $sheet->getColumnDimension('A')->setWidth(15);
|
|
|
+ $sheet->getColumnDimension('B')->setWidth(20);
|
|
|
+ $sheet->getColumnDimension('C')->setWidth(25);
|
|
|
+ $sheet->getColumnDimension('D')->setWidth(25);
|
|
|
+ $sheet->getColumnDimension('E')->setWidth(25);
|
|
|
+ $sheet->getColumnDimension('F')->setWidth(25);
|
|
|
+ $sheet->getColumnDimension('G')->setWidth(25);
|
|
|
+
|
|
|
+ // 设置标题栏样式
|
|
|
+ $titleStyle = $sheet->getStyle('A1:G1');
|
|
|
+ $titleStyle->getFont()->setBold(true);
|
|
|
+ $titleStyle->getFont()->setSize(14);
|
|
|
+ $titleStyle->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
|
|
|
// 设置标题栏
|
|
|
- $sheet->setCellValue('A1', '工单编号');
|
|
|
- $sheet->setCellValue('B1', '工单标题');
|
|
|
- $sheet->setCellValue('C1', '工单类型');
|
|
|
- $sheet->setCellValue('D1', '工单状态');
|
|
|
- $sheet->setCellValue('E1', '客户名称');
|
|
|
- $sheet->setCellValue('F1', '联系人');
|
|
|
- $sheet->setCellValue('G1', '创建时间');
|
|
|
+ $sheet->setCellValue('A1', '工单编号');
|
|
|
+ $sheet->setCellValue('B1', '工单标题');
|
|
|
+ $sheet->setCellValue('C1', '工单类型');
|
|
|
+ $sheet->setCellValue('D1', '工单状态');
|
|
|
+ $sheet->setCellValue('E1', '客户名称');
|
|
|
+ $sheet->setCellValue('F1', '联系人');
|
|
|
+ $sheet->setCellValue('G1', '创建时间');
|
|
|
// $sheet->setCellValue('H1', '负责人');
|
|
|
- // 填充数据
|
|
|
+ // 填充数据
|
|
|
$row = 2;
|
|
|
foreach ($list as $item) {
|
|
|
$sheet->setCellValue('A' . $row, $item['workorder_number']);
|
|
@@ -110,25 +113,25 @@ class Workorder extends Base
|
|
|
$sheet->setCellValue('C' . $row, $item['workorder_type']);
|
|
|
$sheet->setCellValue('D' . $row, $item['schedule']);
|
|
|
$sheet->setCellValue('E' . $row, $item['customer']['name'] ?? '-');
|
|
|
- $sheet->setCellValue('F' . $row, !empty($item['contacts'])? $item['contacts']['name']:'');
|
|
|
+ $sheet->setCellValue('F' . $row, !empty($item['contacts']) ? $item['contacts']['name'] : '');
|
|
|
$sheet->setCellValue('G' . $row, $item['createtime']);
|
|
|
// $sheet->setCellValue('H' . $row, $item['age']);
|
|
|
$row++;
|
|
|
}
|
|
|
- // 设置保存路径及文件名
|
|
|
- $filename = 'data_export.xlsx';
|
|
|
- $filePath = './' . $filename;
|
|
|
-
|
|
|
- // 保存Excel文件
|
|
|
- $writer = new Xlsx($spreadsheet);
|
|
|
- $writer->save($filePath);
|
|
|
-
|
|
|
- // 下载Excel文件
|
|
|
- header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
|
|
- header('Content-Disposition: attachment;filename="' . $filename . '.xlsx"');
|
|
|
- header('Cache-Control: max-age=0');
|
|
|
- $writer->save('php://output');
|
|
|
- exit;
|
|
|
+ // 设置保存路径及文件名
|
|
|
+ $filename = 'data_export.xlsx';
|
|
|
+ $filePath = './' . $filename;
|
|
|
+
|
|
|
+ // 保存Excel文件
|
|
|
+ $writer = new Xlsx($spreadsheet);
|
|
|
+ $writer->save($filePath);
|
|
|
+
|
|
|
+ // 下载Excel文件
|
|
|
+ header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
|
|
+ header('Content-Disposition: attachment;filename="' . $filename . '.xlsx"');
|
|
|
+ header('Cache-Control: max-age=0');
|
|
|
+ $writer->save('php://output');
|
|
|
+ exit;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -138,33 +141,33 @@ class Workorder extends Base
|
|
|
{
|
|
|
//设置过滤方法
|
|
|
$this->request->filter(['strip_tags', 'trim']);
|
|
|
- $need = input('need','','trim');
|
|
|
+ $need = input('need', '', 'trim');
|
|
|
if ($this->request->isAjax()) {
|
|
|
//如果发送的来源是Selectpage,则转发到Selectpage
|
|
|
if ($this->request->request('keyField')) {
|
|
|
return $this->selectpage();
|
|
|
}
|
|
|
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
|
|
|
- $createtime = input('createtime','');
|
|
|
+ $createtime = input('createtime', '');
|
|
|
$wheres = [];
|
|
|
- if($need && $need == 'workorder'){
|
|
|
+ if ($need && $need == 'workorder') {
|
|
|
$wheres['status'] = 1;
|
|
|
}
|
|
|
- if($createtime && $createtime != 'null'){
|
|
|
- $start = date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),1,date("Y")));
|
|
|
- $end = date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("t"),date("Y")));
|
|
|
- $wheres['createtime'] = array('between',array(strtotime($start),strtotime($end)));
|
|
|
+ if ($createtime && $createtime != 'null') {
|
|
|
+ $start = date("Y-m-d H:i:s", mktime(0, 0, 0, date("m"), 1, date("Y")));
|
|
|
+ $end = date("Y-m-d H:i:s", mktime(23, 59, 59, date("m"), date("t"), date("Y")));
|
|
|
+ $wheres['createtime'] = array('between', array(strtotime($start), strtotime($end)));
|
|
|
}
|
|
|
$map = [];
|
|
|
- $status_index = input('status_index','');
|
|
|
+ $status_index = input('status_index', '');
|
|
|
// dump($status_index);
|
|
|
- if($status_index>0){
|
|
|
+ if ($status_index > 0) {
|
|
|
$map['status'] = $status_index;
|
|
|
}
|
|
|
- $owner_staff_id = input('owner_staff_id','');
|
|
|
-
|
|
|
+ $owner_staff_id = input('owner_staff_id', '');
|
|
|
+
|
|
|
// dump($owner_staff_id);
|
|
|
- if($owner_staff_id>0){
|
|
|
+ if ($owner_staff_id > 0) {
|
|
|
$map['owner_staff_id'] = $owner_staff_id;
|
|
|
}
|
|
|
$whereStaff = function ($query) {
|
|
@@ -172,7 +175,7 @@ class Workorder extends Base
|
|
|
->whereOr('', 'exp', "FIND_IN_SET({$this->_staff->id},show_staff_id)");
|
|
|
};
|
|
|
// dump($map);
|
|
|
- $list = $this->model->with(['customer', 'contacts','ownerStaff'])->where($where)->where($map)->where($wheres)->where($whereStaff)->order('id desc')->paginate($limit);
|
|
|
+ $list = $this->model->with(['customer', 'contacts', 'ownerStaff'])->where($where)->where($map)->where($wheres)->where($whereStaff)->order('id desc')->paginate($limit);
|
|
|
|
|
|
foreach ($list as $value) {
|
|
|
if ($value['owner_staff']) {
|
|
@@ -198,33 +201,33 @@ class Workorder extends Base
|
|
|
{
|
|
|
//设置过滤方法
|
|
|
$this->request->filter(['strip_tags', 'trim']);
|
|
|
- $need = input('need','','trim');
|
|
|
+ $need = input('need', '', 'trim');
|
|
|
if ($this->request->isAjax()) {
|
|
|
//如果发送的来源是Selectpage,则转发到Selectpage
|
|
|
if ($this->request->request('keyField')) {
|
|
|
return $this->selectpage();
|
|
|
}
|
|
|
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
|
|
|
- $createtime = input('createtime','');
|
|
|
+ $createtime = input('createtime', '');
|
|
|
$wheres = [];
|
|
|
- if($need && $need == 'workorder'){
|
|
|
+ if ($need && $need == 'workorder') {
|
|
|
$wheres['status'] = 1;
|
|
|
}
|
|
|
- if($createtime && $createtime !='null '){
|
|
|
- $start = date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),1,date("Y")));
|
|
|
- $end = date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("t"),date("Y")));
|
|
|
- $wheres['createtime'] = array('between',array(strtotime($start),strtotime($end)));
|
|
|
+ if ($createtime && $createtime != 'null ') {
|
|
|
+ $start = date("Y-m-d H:i:s", mktime(0, 0, 0, date("m"), 1, date("Y")));
|
|
|
+ $end = date("Y-m-d H:i:s", mktime(23, 59, 59, date("m"), date("t"), date("Y")));
|
|
|
+ $wheres['createtime'] = array('between', array(strtotime($start), strtotime($end)));
|
|
|
}
|
|
|
$map = [];
|
|
|
- $status_index = input('status_index','');
|
|
|
+ $status_index = input('status_index', '');
|
|
|
// dump($status_index);
|
|
|
- if($status_index>0){
|
|
|
+ if ($status_index > 0) {
|
|
|
$map['status'] = $status_index;
|
|
|
}
|
|
|
- $owner_staff_id = input('owner_staff_id','');
|
|
|
-
|
|
|
+ $owner_staff_id = input('owner_staff_id', '');
|
|
|
+
|
|
|
// dump($owner_staff_id);
|
|
|
- if($owner_staff_id>0){
|
|
|
+ if ($owner_staff_id > 0) {
|
|
|
$map['owner_staff_id'] = $owner_staff_id;
|
|
|
}
|
|
|
$whereStaff = function ($query) {
|
|
@@ -232,7 +235,7 @@ class Workorder extends Base
|
|
|
->whereOr('', 'exp', "FIND_IN_SET({$this->_staff->id},show_staff_id)");
|
|
|
};
|
|
|
// dump($map);
|
|
|
- $list = $this->model->where($where)->where($map)->where($wheres)->where($whereStaff)->with(['customer', 'contacts','ownerStaff'])->order('id desc')->paginate(5);
|
|
|
+ $list = $this->model->where($where)->where($map)->where($wheres)->where($whereStaff)->with(['customer', 'contacts', 'ownerStaff'])->order('id desc')->paginate(5);
|
|
|
$result = array("total" => $list->total(), "rows" => $list->items());
|
|
|
|
|
|
return json($result);
|
|
@@ -248,20 +251,20 @@ class Workorder extends Base
|
|
|
|
|
|
if ($this->request->isAjax()) {
|
|
|
$params = $this->request->post('row/a');
|
|
|
- if(isset($params['product'])){
|
|
|
- if (!$params['product'] || $params['product'] =='[]') {
|
|
|
+ if (isset($params['product'])) {
|
|
|
+ if (!$params['product'] || $params['product'] == '[]') {
|
|
|
$this->error('请选择产品');
|
|
|
}
|
|
|
- }else if(isset($params['customer_product_id'])){
|
|
|
- if (!$params['customer_product_id'] || $params['customer_product_id'] =='[]') {
|
|
|
+ } else if (isset($params['customer_product_id'])) {
|
|
|
+ if (!$params['customer_product_id'] || $params['customer_product_id'] == '[]') {
|
|
|
$this->error('请选择产品');
|
|
|
}
|
|
|
- }else if(isset($params['product_part'])){
|
|
|
- if (!$params['product_part'] || $params['product_part'] =='[]') {
|
|
|
+ } else if (isset($params['product_part'])) {
|
|
|
+ if (!$params['product_part'] || $params['product_part'] == '[]') {
|
|
|
$this->error('请选择产品');
|
|
|
}
|
|
|
- }else if(isset($params['device_ids'])){
|
|
|
- if (!$params['device_ids'] || $params['device_ids'] =='[]') {
|
|
|
+ } else if (isset($params['device_ids'])) {
|
|
|
+ if (!$params['device_ids'] || $params['device_ids'] == '[]') {
|
|
|
$this->error('请选择设备');
|
|
|
}
|
|
|
}
|
|
@@ -276,45 +279,45 @@ class Workorder extends Base
|
|
|
$this->error('工单编号已存在');
|
|
|
}
|
|
|
// try {
|
|
|
- if (isset($params['files'])) {
|
|
|
- $params['files'] = File::getId($params['files']);
|
|
|
- }
|
|
|
- if (isset($params['file_ids'])) {
|
|
|
- $params['file_ids'] = File::getId($params['file_ids']);
|
|
|
- }
|
|
|
- if (isset($params['product'])) {
|
|
|
- $params['product'] = json_decode($params['product'], true);
|
|
|
- }
|
|
|
- if (isset($params['parts'])) {
|
|
|
- $params['parts'] = json_decode($params['parts'], true);
|
|
|
- }
|
|
|
- if (isset($params['customer_product_id'])) {
|
|
|
- $params['customer_product_id'] = json_decode($params['customer_product_id'], true);
|
|
|
- $customer_product_id = [];
|
|
|
- foreach ($params['customer_product_id'] as $v) {
|
|
|
- $customer_product_id[] = $v['customer_product_id'];
|
|
|
- }
|
|
|
- $params['customer_product_id'] = implode(',', $customer_product_id);
|
|
|
+ if (isset($params['files'])) {
|
|
|
+ $params['files'] = File::getId($params['files']);
|
|
|
+ }
|
|
|
+ if (isset($params['file_ids'])) {
|
|
|
+ $params['file_ids'] = File::getId($params['file_ids']);
|
|
|
+ }
|
|
|
+ if (isset($params['product'])) {
|
|
|
+ $params['product'] = json_decode($params['product'], true);
|
|
|
+ }
|
|
|
+ if (isset($params['parts'])) {
|
|
|
+ $params['parts'] = json_decode($params['parts'], true);
|
|
|
+ }
|
|
|
+ if (isset($params['customer_product_id'])) {
|
|
|
+ $params['customer_product_id'] = json_decode($params['customer_product_id'], true);
|
|
|
+ $customer_product_id = [];
|
|
|
+ foreach ($params['customer_product_id'] as $v) {
|
|
|
+ $customer_product_id[] = $v['customer_product_id'];
|
|
|
}
|
|
|
- if (isset($params['product_part'])) {
|
|
|
- $params['product_part'] = json_decode($params['product_part'], true);
|
|
|
- $customer_product_id = [];
|
|
|
- foreach ($params['product_part'] as $v){
|
|
|
- $customer_product_id[] = $v['customer_product_id'];
|
|
|
- }
|
|
|
- $params['customer_product_id'] = implode(',', $customer_product_id);
|
|
|
+ $params['customer_product_id'] = implode(',', $customer_product_id);
|
|
|
+ }
|
|
|
+ if (isset($params['product_part'])) {
|
|
|
+ $params['product_part'] = json_decode($params['product_part'], true);
|
|
|
+ $customer_product_id = [];
|
|
|
+ foreach ($params['product_part'] as $v) {
|
|
|
+ $customer_product_id[] = $v['customer_product_id'];
|
|
|
}
|
|
|
+ $params['customer_product_id'] = implode(',', $customer_product_id);
|
|
|
+ }
|
|
|
|
|
|
- if (isset($params['device_ids'])) {
|
|
|
- $params['device_ids'] = json_decode($params['device_ids'], true);
|
|
|
- $customer_product_id = [];
|
|
|
- foreach ($params['device_ids'] as $v){
|
|
|
- $customer_product_id[] = $v['customer_product_id'];
|
|
|
- }
|
|
|
- $params['device_ids'] = implode(',', $customer_product_id);
|
|
|
+ if (isset($params['device_ids'])) {
|
|
|
+ $params['device_ids'] = json_decode($params['device_ids'], true);
|
|
|
+ $customer_product_id = [];
|
|
|
+ foreach ($params['device_ids'] as $v) {
|
|
|
+ $customer_product_id[] = $v['customer_product_id'];
|
|
|
}
|
|
|
- $result = WorkorderModel::createWorkorder($params);
|
|
|
- Db::commit();
|
|
|
+ $params['device_ids'] = implode(',', $customer_product_id);
|
|
|
+ }
|
|
|
+ $result = WorkorderModel::createWorkorder($params);
|
|
|
+ Db::commit();
|
|
|
// } catch (Exception $e) {
|
|
|
// Db::rollback();
|
|
|
// $this->error($e->getMessage());
|
|
@@ -354,21 +357,21 @@ class Workorder extends Base
|
|
|
}
|
|
|
|
|
|
//编辑
|
|
|
- public function edit($ids=null)
|
|
|
+ public function edit($ids = null)
|
|
|
{
|
|
|
|
|
|
if ($this->request->isAjax()) {
|
|
|
$params = $this->request->post('row/a');
|
|
|
- if(isset($params['product'])){
|
|
|
- if (!$params['product'] || $params['product'] =='[]') {
|
|
|
+ if (isset($params['product'])) {
|
|
|
+ if (!$params['product'] || $params['product'] == '[]') {
|
|
|
$this->error('请选择产品');
|
|
|
}
|
|
|
- }else if(isset($params['customer_product_id'])){
|
|
|
- if (!$params['customer_product_id'] || $params['customer_product_id'] =='[]') {
|
|
|
+ } else if (isset($params['customer_product_id'])) {
|
|
|
+ if (!$params['customer_product_id'] || $params['customer_product_id'] == '[]') {
|
|
|
$this->error('请选择产品');
|
|
|
}
|
|
|
- }else if(isset($params['product_part'])){
|
|
|
- if (!$params['product_part'] || $params['product_part'] =='[]') {
|
|
|
+ } else if (isset($params['product_part'])) {
|
|
|
+ if (!$params['product_part'] || $params['product_part'] == '[]') {
|
|
|
$this->error('请选择产品');
|
|
|
}
|
|
|
}
|
|
@@ -418,29 +421,29 @@ class Workorder extends Base
|
|
|
$this->error('工单不存在');
|
|
|
}
|
|
|
$workorder = $workorder->toArray();
|
|
|
- $workorder['customer_product_id']=explode(',',$workorder['customer_product_id']);
|
|
|
- $customer_product=[];
|
|
|
- foreach ($workorder['customer_product_id'] as $pid){
|
|
|
- $cp=CustomerProduct::where(['id'=>$pid])->with(['product'])->find();
|
|
|
- $cp['customer_product_id']=$pid;
|
|
|
- $customer_product[]=$cp;
|
|
|
- }
|
|
|
- $workorder['customer_product']= $customer_product;
|
|
|
- $files=[];
|
|
|
+ $workorder['customer_product_id'] = explode(',', $workorder['customer_product_id']);
|
|
|
+ $customer_product = [];
|
|
|
+ foreach ($workorder['customer_product_id'] as $pid) {
|
|
|
+ $cp = CustomerProduct::where(['id' => $pid])->with(['product'])->find();
|
|
|
+ $cp['customer_product_id'] = $pid;
|
|
|
+ $customer_product[] = $cp;
|
|
|
+ }
|
|
|
+ $workorder['customer_product'] = $customer_product;
|
|
|
+ $files = [];
|
|
|
foreach ($workorder['file'] as $f) {
|
|
|
$files[] = $f['file_path'];
|
|
|
}
|
|
|
- if($workorder['product_part']){
|
|
|
- $product_part=[];
|
|
|
- foreach ($workorder['product_part'] as $v){
|
|
|
+ if ($workorder['product_part']) {
|
|
|
+ $product_part = [];
|
|
|
+ foreach ($workorder['product_part'] as $v) {
|
|
|
|
|
|
- $v['customer_product_id']=$v['id'];
|
|
|
- $product_part[]=$v;
|
|
|
+ $v['customer_product_id'] = $v['id'];
|
|
|
+ $product_part[] = $v;
|
|
|
}
|
|
|
- $workorder['product_part']=$product_part;
|
|
|
+ $workorder['product_part'] = $product_part;
|
|
|
}
|
|
|
- $workorder['files']=implode(',',$files);
|
|
|
- $workorder_type=$workorder['workorder_type'];
|
|
|
+ $workorder['files'] = implode(',', $files);
|
|
|
+ $workorder_type = $workorder['workorder_type'];
|
|
|
$this->assign('row', $workorder);
|
|
|
$this->assign('workorder_type', $workorder_type);
|
|
|
$this->assign('staffs', Staff::getList());
|
|
@@ -485,10 +488,10 @@ class Workorder extends Base
|
|
|
//工单详情
|
|
|
public function detail($ids = null)
|
|
|
{
|
|
|
- $types = input('types','workorder');
|
|
|
+ $types = input('types', 'workorder');
|
|
|
// 基本信息
|
|
|
$workorder = WorkorderModel::where(['id' => $ids])->with(['createStaff',
|
|
|
- 'contacts', 'customer', 'ownerStaff', 'file', 'getevent', 'visit','createPerson'])->find();
|
|
|
+ 'contacts', 'customer', 'ownerStaff', 'file', 'getevent', 'visit', 'createPerson'])->find();
|
|
|
if (empty($workorder)) {
|
|
|
$this->error('工单不存在');
|
|
|
}
|
|
@@ -496,14 +499,19 @@ class Workorder extends Base
|
|
|
if (empty($workorder)) {
|
|
|
$this->error('信息不存在');
|
|
|
}
|
|
|
- if (!in_array($this->_staff->id, explode(',', $workorder['show_staff_id']))
|
|
|
- && !in_array($workorder['owner_staff_id'], Staff::getLowerStaffId()) && $this->_staff->id != $workorder['create_staff_id']) {
|
|
|
- $this->error('权限不足,无法查看工单','',403);
|
|
|
+ if ($this->_staff->id != 15) {
|
|
|
+ $role_type = StaffRole::where(['id' => $this->_staff->role])->value('role_type');
|
|
|
+ if ($role_type != 6) {
|
|
|
+ if (!in_array($this->_staff->id, explode(',', $workorder['show_staff_id']))
|
|
|
+ && !in_array($workorder['owner_staff_id'], Staff::getLowerStaffId()) && $this->_staff->id != $workorder['create_staff_id']) {
|
|
|
+ $this->error('权限不足,无法查看工单', '', 403);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//设备列表
|
|
|
- if($workorder['device_ids']){
|
|
|
- $workorder['device_list']=$this->Equipmentdevice->where(array('id'=>array('in',$workorder['device_ids'])))->select();
|
|
|
+ if ($workorder['device_ids']) {
|
|
|
+ $workorder['device_list'] = $this->Equipmentdevice->where(array('id' => array('in', $workorder['device_ids'])))->select();
|
|
|
}
|
|
|
|
|
|
|
|
@@ -515,26 +523,26 @@ class Workorder extends Base
|
|
|
}
|
|
|
if (empty($workorder['contacts'])) {
|
|
|
$workorder['contacts'] = Contacts::where(['customer_id' => $workorder['customer_id']])->order('is_major desc')->field('id,customer_id,name,mobile,mobilecode,region')->find();
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
// dump($workorder);
|
|
|
// if (empty($workorder['kehuinfo'])) {
|
|
|
// $workorder['kehuinfo'] = Contacts::where(['id' => $workorder['customer_id']])->order('is_major desc')->field('id,customer_id,name,mobile,mobilecode,region')->find();
|
|
|
|
|
|
// }
|
|
|
-
|
|
|
+
|
|
|
if ($workorder['aftermarket_type_ids']) {
|
|
|
$names = AftermarketType::where(['id' => ['in', explode(',', $workorder['aftermarket_type_ids'])]])->column('name');
|
|
|
$workorder['aftermarket_type_ids'] = implode(',', $names);
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
$workorder['is_revoke'] = 0;//是否可以撤销
|
|
|
$workorder['is_operation'] = 0;//是否可以操作
|
|
|
$workorder['is_operation_visit'] = 0;//操作回访
|
|
|
$workorder['is_financial'] = 0;//是否财务审核
|
|
|
$workorder['is_leader'] = 0;//是否可以录入费用
|
|
|
- if ($workorder['create_staff_id'] == $this->_staff->id || in_array($workorder['create_staff_id'], Staff::getLowerStaffId()) ) {
|
|
|
+ if ($workorder['create_staff_id'] == $this->_staff->id || in_array($workorder['create_staff_id'], Staff::getLowerStaffId())) {
|
|
|
//是否可以撤销
|
|
|
$workorder['is_revoke'] = 1;
|
|
|
}
|
|
@@ -553,7 +561,7 @@ class Workorder extends Base
|
|
|
//操作回访
|
|
|
$workorder['is_operation_visit'] = 1;
|
|
|
|
|
|
- if ($workorder['status'] == 3 && $workorder['is_pay'] == 1 && $workorder['is_financial_audit'] == 0 ) {
|
|
|
+ if ($workorder['status'] == 3 && $workorder['is_pay'] == 1 && $workorder['is_financial_audit'] == 0) {
|
|
|
//是否财务审核
|
|
|
$workorder['is_financial'] = 1;
|
|
|
}
|
|
@@ -614,7 +622,7 @@ class Workorder extends Base
|
|
|
$model = new WorkorderProgress();
|
|
|
$staffsProgress = $model->where(['workorder_id' => $ids])->with(['createStaff'])->select();
|
|
|
|
|
|
- $this->assign('staffsProgress',$staffsProgress);
|
|
|
+ $this->assign('staffsProgress', $staffsProgress);
|
|
|
|
|
|
$where = [];
|
|
|
$where['relation_type'] = 'workorder';
|
|
@@ -628,8 +636,8 @@ class Workorder extends Base
|
|
|
$assist_task = collection($assist_task)->toArray();
|
|
|
|
|
|
|
|
|
- $this->assign('examine_record',ExamineRecord::getList(ExamineRecord::WORKORDER_TYPE,$ids));
|
|
|
- $this->assign('flow',Flow::getstepdetail(Flow::WORKORDER_STATUS, $ids));
|
|
|
+ $this->assign('examine_record', ExamineRecord::getList(ExamineRecord::WORKORDER_TYPE, $ids));
|
|
|
+ $this->assign('flow', Flow::getstepdetail(Flow::WORKORDER_STATUS, $ids));
|
|
|
|
|
|
$this->assign('assist_task', $assist_task);
|
|
|
$this->assign('logistics', $logistics);
|
|
@@ -645,9 +653,10 @@ class Workorder extends Base
|
|
|
}
|
|
|
|
|
|
//获取费用
|
|
|
- public function get_consume($ids = null) {
|
|
|
+ public function get_consume($ids = null)
|
|
|
+ {
|
|
|
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
|
|
|
- $list = Consume::where([
|
|
|
+ $list = Consume::where([
|
|
|
'relation_type' => 'workorder',
|
|
|
'relation_id' => $ids,
|
|
|
])->with(['staff'])->order('id desc')->paginate($limit);
|
|
@@ -675,7 +684,7 @@ class Workorder extends Base
|
|
|
|
|
|
Db::startTrans();
|
|
|
try {
|
|
|
- WorkorderModel::transferWorkorder($id,$dep_id, $staff_id, $desc);
|
|
|
+ WorkorderModel::transferWorkorder($id, $dep_id, $staff_id, $desc);
|
|
|
Db::commit();
|
|
|
} catch (Exception $e) {
|
|
|
Db::rollback();
|
|
@@ -764,12 +773,12 @@ class Workorder extends Base
|
|
|
}
|
|
|
|
|
|
//接受工单
|
|
|
- public function accept_order($ids=null)
|
|
|
+ public function accept_order($ids = null)
|
|
|
{
|
|
|
$params = $this->request->post();
|
|
|
- if(!$ids){
|
|
|
+ if (!$ids) {
|
|
|
$params['id'] = isset($params['id']) ? $params['id'] : '';
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
$params['id'] = $ids;
|
|
|
}
|
|
|
if (empty($params['id'])) {
|
|
@@ -835,7 +844,7 @@ class Workorder extends Base
|
|
|
if (empty($row)) {
|
|
|
$this->error('工单不存在');
|
|
|
}
|
|
|
- $row['customer_product']='';
|
|
|
+ $row['customer_product'] = '';
|
|
|
if ($row['customer_product_id']) {
|
|
|
$customer_product_ids = explode(',', $row['customer_product_id']);
|
|
|
$row['customer_product'] = CustomerProduct::where(['id' => ['in', $customer_product_ids]])->with(['product'])->select();
|
|
@@ -1052,8 +1061,10 @@ class Workorder extends Base
|
|
|
$this->view->assign('row', $row);
|
|
|
return $this->view->fetch();
|
|
|
}
|
|
|
+
|
|
|
//电话工单完成
|
|
|
- public function complete_mobile($ids=null){
|
|
|
+ public function complete_mobile($ids = null)
|
|
|
+ {
|
|
|
|
|
|
if ($this->request->isAjax()) {
|
|
|
$params = $this->request->post('row/a');
|
|
@@ -1065,10 +1076,10 @@ class Workorder extends Base
|
|
|
}
|
|
|
Db::startTrans();
|
|
|
try {
|
|
|
- if($params['is_part'] == 1){
|
|
|
- $params['use_parts']=[];
|
|
|
- }else{
|
|
|
- $params['use_parts']=json_decode($params['use_parts'],true);
|
|
|
+ if ($params['is_part'] == 1) {
|
|
|
+ $params['use_parts'] = [];
|
|
|
+ } else {
|
|
|
+ $params['use_parts'] = json_decode($params['use_parts'], true);
|
|
|
}
|
|
|
WorkorderModel::completeWorkorder($id, $desc, $params);
|
|
|
//协助任务完成
|
|
@@ -1089,6 +1100,7 @@ class Workorder extends Base
|
|
|
$this->view->assign('row', $row);
|
|
|
return $this->view->fetch();
|
|
|
}
|
|
|
+
|
|
|
//工单失败
|
|
|
public function fail_workorder($ids = null)
|
|
|
{
|
|
@@ -1191,16 +1203,16 @@ class Workorder extends Base
|
|
|
if ($this->request->isAjax()) {
|
|
|
$params = $this->request->post('row/a');
|
|
|
$relation_type = Comment::ASSIST_EVENT_TYPE;
|
|
|
- if(empty($params['id'])){
|
|
|
+ if (empty($params['id'])) {
|
|
|
$this->error('评论ID不能为空');
|
|
|
}
|
|
|
- if(empty($params['content'])){
|
|
|
+ if (empty($params['content'])) {
|
|
|
$this->error('评论内容不能为空');
|
|
|
}
|
|
|
$relation_id = $params['id'];
|
|
|
$content = $params['content'];
|
|
|
- $files = $params['file_ids']??'';
|
|
|
- $files=File::getId($files);
|
|
|
+ $files = $params['file_ids'] ?? '';
|
|
|
+ $files = File::getId($files);
|
|
|
$staff = Staff::info();
|
|
|
Comment::addComment($content, $files, $relation_id, $relation_type, $staff->id);
|
|
|
$this->success('评论成功');
|
|
@@ -1306,9 +1318,9 @@ class Workorder extends Base
|
|
|
|
|
|
if ($this->request->isAjax()) {
|
|
|
$params = $this->request->post('row/a');
|
|
|
- $params['workorder_id']=$ids;
|
|
|
- $result=WorkorderModel::addProgress($params);
|
|
|
- if($result){
|
|
|
+ $params['workorder_id'] = $ids;
|
|
|
+ $result = WorkorderModel::addProgress($params);
|
|
|
+ if ($result) {
|
|
|
$this->success('操作成功');
|
|
|
}
|
|
|
$this->error('操作失败');
|
|
@@ -1475,13 +1487,13 @@ class Workorder extends Base
|
|
|
$list = \addons\qingdongams\model\JointFollow::where(['relation_type' => JointFollow::WORKORDER_TYPE, 'relation_id' => $ids])->with(['staff'])->paginate($limit);
|
|
|
$total = $list->total();
|
|
|
$stfflist = $list->toArray()['data'];
|
|
|
- foreach ($stfflist as $k => $value){
|
|
|
- if ($value['roles'] == 1){
|
|
|
+ foreach ($stfflist as $k => $value) {
|
|
|
+ if ($value['roles'] == 1) {
|
|
|
$stfflist[$k]['is_edit'] = '负责人';
|
|
|
- }else{
|
|
|
- $stfflist[$k]['is_edit'] = $value['is_edit'] == 1?'读写':'只读';
|
|
|
+ } else {
|
|
|
+ $stfflist[$k]['is_edit'] = $value['is_edit'] == 1 ? '读写' : '只读';
|
|
|
}
|
|
|
- $stfflist[$k]['roles'] = $value['roles'] == 1?'负责人':'团队成员';
|
|
|
+ $stfflist[$k]['roles'] = $value['roles'] == 1 ? '负责人' : '团队成员';
|
|
|
}
|
|
|
$result = array("total" => $total, "rows" => $stfflist);
|
|
|
|
|
@@ -1489,7 +1501,8 @@ class Workorder extends Base
|
|
|
}
|
|
|
|
|
|
|
|
|
- public function set_team($ids = null){
|
|
|
+ public function set_team($ids = null)
|
|
|
+ {
|
|
|
if ($this->request->isPost()) {
|
|
|
$params = $this->request->post("row/a");
|
|
|
if ($params) {
|
|
@@ -1501,15 +1514,15 @@ class Workorder extends Base
|
|
|
if (empty($model)) {
|
|
|
$this->error('客户不存在');
|
|
|
}
|
|
|
- foreach ($staff as $k=>$v) {
|
|
|
+ foreach ($staff as $k => $v) {
|
|
|
if ($v['roles'] == 1) {//负责人
|
|
|
$find = JointFollow::where(['relation_type' => JointFollow::WORKORDER_TYPE,
|
|
|
'relation_id' => $id,
|
|
|
'roles' => 1
|
|
|
])->find();
|
|
|
- if($v['id'] != $find['staff_id']){
|
|
|
+ if ($v['id'] != $find['staff_id']) {
|
|
|
\addons\qingdongams\model\Workorder::transfer($id, $v['id']);
|
|
|
- JointFollow::where(['id'=>$find['id']])->update(['staff_id'=>$v['id']]);
|
|
|
+ JointFollow::where(['id' => $find['id']])->update(['staff_id' => $v['id']]);
|
|
|
$model = \addons\qingdongams\model\Workorder::get($id);
|
|
|
}
|
|
|
unset($staff[$k]);
|
|
@@ -1529,7 +1542,7 @@ class Workorder extends Base
|
|
|
'roles' => 1
|
|
|
])->find();
|
|
|
foreach ($staff as $v) {
|
|
|
- if($v['id'] != $find['staff_id']) {
|
|
|
+ if ($v['id'] != $find['staff_id']) {
|
|
|
$add[] = [
|
|
|
'relation_type' => $jointFollow::WORKORDER_TYPE,
|
|
|
'relation_id' => $id,
|
|
@@ -1546,12 +1559,12 @@ class Workorder extends Base
|
|
|
}
|
|
|
$this->error(__('Parameter %s can not be empty', ''));
|
|
|
}
|
|
|
- $list = \addons\qingdongams\model\JointFollow::where(['relation_type' => JointFollow::WORKORDER_TYPE, 'relation_id' => $ids,'roles' => 2])->with(['staff'])->select();
|
|
|
+ $list = \addons\qingdongams\model\JointFollow::where(['relation_type' => JointFollow::WORKORDER_TYPE, 'relation_id' => $ids, 'roles' => 2])->with(['staff'])->select();
|
|
|
$staffs = Staff::getList();
|
|
|
- $principal = \addons\qingdongams\model\JointFollow::where(['relation_type' => JointFollow::WORKORDER_TYPE, 'relation_id' => $ids,'roles' => 1])->with(['staff'])->find();
|
|
|
+ $principal = \addons\qingdongams\model\JointFollow::where(['relation_type' => JointFollow::WORKORDER_TYPE, 'relation_id' => $ids, 'roles' => 1])->with(['staff'])->find();
|
|
|
$this->assign('staffs', $staffs);
|
|
|
$this->assign('principal', $principal);
|
|
|
- $this->assign('id',$ids);
|
|
|
+ $this->assign('id', $ids);
|
|
|
$this->assign('list', $list);
|
|
|
return $this->view->fetch();
|
|
|
}
|