auth->getUser(); $this->user_id = $user->id; $this->company_id = $user->company_id; } /** * 工单列表 * @return void */ public function list() { $page = $this->request->get('page', 1); $limit = $this->request->get('limit', 10); $category_id = $this->request->get('category_id');//分类 $search_type = $this->request->get('search_type');//part 参与 ;charge 负责 $search_input = $this->request->get('search_input'); $search_company_id = $this->request->get('search_company_id'); $status = $this->request->get('status'); $user = $this->auth->getUser(); $user_type = $this->isCompanyUser($user);//用户类型 general 普通员工; admin 企业管理员; customer 客户 $fields = 'id,category_id,company_id,ht_number,prj_name,mgr_id,mgr_phone,customer_company,job_location,detail_address,build_status,member_ids,iqc_id,status'; //默认只展示登陆用户绑定企业数据 $query = ProjectWorkerOrder::field($fields); $company_ids = ProjectCompanyUser::getCompanyIds($user->id); if ($search_company_id) { $company_ids = $search_company_id; } if ($company_ids) { if (is_array($company_ids)) { $query->whereIn('company_id', $company_ids[0]); } else { $query->whereIn('company_id', $company_ids); } } if($category_id) { $query->where('category_id', $category_id); } if ($search_input) { $query->where('prj_name|ht_number','like', "%".$search_input."%"); } if ($status != '') { $query->where('status', $status); } //用户类型 switch ($user_type) { case 'general': if ($search_type == 'part') { $query->where('', 'exp', Db::raw("FIND_IN_SET($this->user_id,member_ids)")); } elseif ($search_input == 'charge') { $query->where('mgr_id', $this->user_id); } else { $query->where('', 'exp', Db::raw("FIND_IN_SET($this->user_id,member_ids) or mgr_id = $this->user_id")); } break; case 'admin': break; case 'customer': $query->where('customer_phone', $user->mobile); } // $data = $query->fetchSql()->select(); // $this->success('1', $data); $data = $query->order('id DESC')->paginate($limit)->toArray(); foreach ($data['data'] as &$value) { $value['build_status'] = $value['build_status'] ? $value['build_status'] : "未开始"; } $this->success(__('Success'),$data); } /** * 工单详情 * @return void */ public function detail() { $order_id = $this->request->get('order_id'); if (!$order_id) { $this->error(__('Parameter error')); } $data = ProjectWorkerOrder::where('id', $order_id)->find(); if (!$data) { $this->success(__('Success'),null); } $data->hidden(['mgr_id','category_id','iqc_id','job_location','detail_address', 'member_ids','create_time', 'update_time', 'after_sale_status']); $category_info = ProjectCategory::getProgress($order_id,$data['category_id']); $data = array_merge($data->toArray(), $category_info); $data['build_status'] = $data['build_status'] ? $data['build_status'] : "未开始"; $this->success(__('Success'),$data); } /** * 提交工单 * @return void */ public function submit() { $post = $this->request->post(); $res = $this->validate($post, 'project.submit'); if(true !== $res) { $this->error($res); } $companyIds = ProjectCompanyUser::getCompanyIds($this->user_id); $post['company_id'] = $companyIds ? $companyIds[0] : 0; $post['user_id'] = $this->user_id; $res = ProjectWorkerOrder::create($post); if ($res) { $this->success('添加成功', $res); } } /** * 添加售后进展 * @return void */ public function addOrderProgressAndSales() { $post = $this->request->post(); $res = $this->validate($post, 'project.addOrderProgressAndSales'); if (true !== $res) { $this->error($res); } $post['add_user'] = $this->user_id; $res = ProjectOrderAfterSales::add($post); if ($res) { $this->success('添加成功'); } } /** * 订单流程完成状态 */ public function updateFlowStatus() { $post = $this->request->post(); if (empty($post['flow_id']) || empty($post['order_id'])){ $this->error('参数错误'); } $user = $this->auth->getUser(); //验证工单是否存在 $order = ProjectWorkerOrder::where('id', $post['order_id'])->find(); if (!$order) { $this->error('工单不存在'); } //验证流程是否存在 $flow = ProjectCategoryFlow::where('id', $post['flow_id'])->find(); if (!$flow) { $this->error('流程不存在'); } //验证流程是否完成 $obj = ProjectOrderFlow::where('flow_id', $post['flow_id'])->where('order_id', $post['order_id'])->find(); if ($obj) { if ($obj['status'] == 1) { $this->error('该工单进度已完成'); } $obj->status = 1; $obj->phone = $user->mobile; $obj->save(); } else { //添加流程完成记录 $insertData = [ 'flow_id' => $post['flow_id'], 'order_id' => $post['order_id'], 'status' => 1, 'create_time' => time(), 'phone' => $user->mobile ]; ProjectOrderFlow::add($insertData); } $this->success('更新成功'); } /** * 工单完成状态更新 */ public function updateOrderStatus() { $order_id = $this->request->post('order_id'); if (empty($order_id)) { $this->error('参数错误'); } //验证流程是否都完成 $order = ProjectWorkerOrder::get($order_id); if ($order) { //获取完成的流程 $wc_flow = ProjectOrderFlow::where('order_id', $order_id)->where('status', 1)->count(); //待完成的流程 $dwc_flow = ProjectCategoryFlow::where('category_id', $order['category_id'])->count(); if ($dwc_flow != $wc_flow) { $this->error('存在未完成的流程,工单状态无法完成'); } $order->status = 1; $order->save(); } $this->success('更新成功'); } /** * 获取售后单 */ public function getSalesOrder() { $order_id = $this->request->get('order_id'); $res = ProjectOrderAfterSales::getSales($order_id); foreach ($res as &$row) { $row['images'] = ProjectCategory::imagesFormat($row['images']); } $this->success('获取成功',$res); } /** * 获取项目配置 * @return void */ public function getProjectConfig() { $data = ProjectCategory::getList(); $this->success('获取成功',$data); } /** * 获取用户列表 * @return void */ public function getUserList() { $company_id = $this->request->get('company_id');//企业id if (!$company_id) { $this->error('参数错误'); } //展示选择企业下的用户 $user_ids = ProjectCompanyUser::getUserIds($company_id); $data = \app\common\model\User::getUserByIds($user_ids); $this->success('获取成功',$data); } /** * 添加材料单 */ public function addMaterialOrder() { $order_id = $this->request->post('order_id'); $material_ids = $this->request->post('material_ids'); if (!$order_id || !$material_ids) { $this->error('参数错误'); } $params = [ 'order_id' => $order_id, 'material_ids' => $material_ids ]; $res = ProjectOrderMaterial::getInfo($order_id); if ($res) { $ret = ProjectOrderMaterial::update($params, ['order_id' => $order_id]); } else { $ret = ProjectOrderMaterial::create($params); } if ($ret) { $this->success('保存成功',[]); } } /** * 获取材料模板 */ public function getMaterialTemp() { $ret = ProjectMaterialTemplate::getList(); $this->success('获取成功',$ret); } /** * 获取材料配置 */ public function getMaterial() { $ret = ProjectMaterial::getList(); $this->success('获取成功', $ret); } /** * 获取材料单 */ public function getMaterialOrder() { $order_id = $this->request->get('order_id'); $ret = ProjectOrderMaterial::getListByOrderId($order_id); $this->success('获取成功',$ret); } /** * 判断用户是不是企业用户或者工程客户 * @return string */ public function isCompanyUser($user) { $user_type = 'general'; //是否企业管理员用户 $data = $this->auth->isCompanyAdminNew($user->id,$user->company_id); if ($data) { $user_type = 'admin'; }else { $order = ProjectWorkerOrder::where('customer_phone', $user->mobile)->select(); if ($order) { $user_type = 'customer'; } } return $user_type; } public function isProjectAuth() { $comp_user = ProjectCompanyUser::getCompanyIds($this->user_id); $order = ProjectWorkerOrder::where('customer_phone', $this->auth->getUser()->mobile)->select(); if ($comp_user) { $this->success('success',1); } if ($order) { $this->success('success',2); } $this->success('success', 0); } public function isSign() { $comp_user = ProjectCompanyUser::getCompanyIds($this->user_id); $order = ProjectWorkerOrder::where('customer_phone', $this->auth->getUser()->mobile)->select(); $urlType = 2; if ($comp_user) { $urlType = 1; } if ($order) { $urlType = 2; } return $urlType; } public function getTemplateHtml() { $flow_id = $this->request->get('flow_id'); $order_id = $this->request->get('order_id'); $res = ProjectCategoryFlow::get($flow_id); $user = $this->auth->getUser(); // var_dump($res->toArray()); $phone = $user->mobile; $htmlUrl = ''; //e签宝签署流程开始 if (!empty($res['sign_url']) && !empty($res['sign_fileId'])) { $signFlow = new SignFlow(); $obj = ProjectOrderFlow::where('flow_id', $flow_id)->where('order_id', $order_id)->find(); if ($obj['phone']) { $phone = $obj['phone']; } list($page,$x,$y) = $this->getLoaction($res['sign_url']); $company = ProjectWorkerOrder::getCompanyInfo($order_id); // var_dump($company);exit(); $flowId = $obj['sign_flowId']; if (empty($flowId)) { $flowId = $signFlow->createByFile($res['sign_fileId'],$res['id'],$order_id,$phone,$page,$x,$y,$company); $obj->sign_flowId = $flowId; $obj->save(); } $signFlow = new SignFlow(); $url_type = $this->isSign(); $htmlUrl = $signFlow->getSignUrl($flowId,$company,$phone,$url_type); } $this->success('success', $htmlUrl); } public function getTemplateFileUrl() { $template = new Template(); $flow_id = $this->request->get('flow_id'); $order_id = $this->request->get('order_id'); $user = $this->auth->getUser(); $res = ProjectCategoryFlow::get($flow_id); $obj = ProjectOrderFlow::where('flow_id', $flow_id)->where('order_id', $order_id)->find(); if (empty($obj)) { //模板填写 添加流程开始记录 $insertData = [ 'flow_id' => $flow_id, 'order_id' => $order_id, 'create_time' => time(), 'phone' => $user->mobile,//记录用签署合同的手机号 查看合同用 ]; ProjectOrderFlow::add($insertData); } $htmlUrl = ''; $msg = ''; //返回用户填写H5 有签署模板ID 并且模板未填写才去取填写地址 if ($obj['template_status'] == 1) { $this->success('模板已填写完成',1); } if ($res['sign_templateId']) { if ($res['sign_templateId'] == '89ad871246c845b0aed67eeb33047bfe') {//调试申请单 $order = ProjectWorkerOrder::get($order_id); $data = [ 'username' => $order['customer_name'] ?? '', 'phone' => $order['customer_phone'] ?? '', 'ht_number' => $order['ht_number']?? '', 'address' => $order['job_location'].$order['job_location'], 'mgr_name' => \app\common\model\User::get($order['mgr_id'])->nickname ?? '', ]; $htmlUrl = $template->docTemplateFileUrl($flow_id,$res['sign_templateId'],$order_id,$data); } else { $htmlUrl = $template->docTemplateFileUrl2($flow_id,$res['sign_templateId'],$order_id); } } $this->success($msg, $htmlUrl); } public function getTemplateStatus() { $flow_id = $this->request->get('flow_id'); $order_id = $this->request->get('order_id'); $obj = ProjectOrderFlow::where('flow_id', $flow_id)->where('order_id', $order_id)->find(); $status = 0; if ($obj) { $status = $obj->template_status; } $this->success('获取填写状态',['tempStatus' => $status]); } public function getLoaction($type) { if ($type == 1) { $page = ['1', '1']; $x = [147,400]; $y = [300,300]; } if ($type == 2) {//新风系统验收协议 $page = ['1', '1']; $x = [200,450]; $y = [180,180]; } if ($type == 3) {//锅炉地暖验收协议 $page = ['3', '3']; $x = [220,420]; $y = [156,156]; } if ($type == 4) {//锅炉水系统验收协议 $page = ['2', '2']; $x = [220,420]; $y = [120,120]; } if ($type == 5) {//空调氟系统验收协议 $page = ['3', '3']; $x = [207,430]; $y = [430,430]; } if ($type == 7) {//空调水系统验收协议 $page = ['4', '4']; $x = [208,430]; $y = [371,366]; } return [$page, $x ,$y]; } }