提交 5d3becc4 authored 作者: 窦斌's avatar 窦斌

edit

上级 9ace42cc
<?php
namespace App\Http\Controllers\Api\MobileWeb;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Requests\Validators\Api\MobileWeb\BillingModuleValidator;
use BlueCity\Core\Inc\ErrorInc;
use App\Services\Api\MobileWeb\BillingModuleService;
// 移动端-账单列表
class BillingModuleController extends Controller
{
// 列表每页显示数据个数
protected $show_count = 10;
public function __construct()
{
$this->dataValidator = new BillingModuleValidator();
}
// 列表
public function index(Request $request)
{
// 验证数据
$error_message = $this->dataValidator->indexValidator($request->all());
if ($error_message) {
return response()->json(['ErrorCode'=>ErrorInc::INVALID_PARAM, 'ErrorMessage'=>$error_message->first(), 'Data'=>[$error_message]]);
}
$return_data = BillingModuleService::index($request->all(), $this->show_count);
return $return_data;
}
// 查看凭证
public function checkVoucher(Request $request)
{
// 验证数据
$error_message = $this->dataValidator->checkInfoValidator($request->all());
if ($error_message) {
return response()->json(['ErrorCode'=>ErrorInc::INVALID_PARAM, 'ErrorMessage'=>$error_message->first(), 'Data'=>[$error_message]]);
}
$return_data = BillingModuleService::checkVoucher($request->all());
return response()->json($return_data);
}
// 查看详情
public function checkInfo(Request $request)
{
// 验证数据
$error_message = $this->dataValidator->checkInfoValidator($request->all());
if ($error_message) {
return response()->json(['ErrorCode'=>ErrorInc::INVALID_PARAM, 'ErrorMessage'=>$error_message->first(), 'Data'=>[$error_message]]);
}
$return_data = BillingModuleService::checkInfo($request->all());
return response()->json($return_data);
}
// 确认账单
public function affirmBill(Request $request)
{
// 验证数据
$error_message = $this->dataValidator->affirmBillValidator($request->all());
if ($error_message) {
return response()->json(['ErrorCode'=>ErrorInc::INVALID_PARAM, 'ErrorMessage'=>$error_message->first(), 'Data'=>[$error_message]]);
}
$return_data = BillingModuleService::affirmBill($request->all());
return response()->json($return_data);
}
// 上传发票
public function uploadInvoice(Request $request)
{
// 验证数据
$error_message = $this->dataValidator->uploadInvoiceValidator($request->all());
if ($error_message) {
return response()->json(['ErrorCode'=>ErrorInc::INVALID_PARAM, 'ErrorMessage'=>$error_message->first(), 'Data'=>[$error_message]]);
}
$return_data = BillingModuleService::uploadInvoice($request->all());
return response()->json($return_data);
}
}
<?php
namespace App\Http\Controllers\Api\MobileWeb;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Requests\Validators\Api\MobileWeb\OrderListValidator;
use BlueCity\Core\Inc\ErrorInc;
use App\Services\Api\MobileWeb\OrderListService;
// 移动端-工单列表
class OrderListController extends Controller
{
// 列表每页显示数据个数
protected $show_count = 4;
public function __construct()
{
$this->dataValidator = new OrderListValidator();
}
// 列表
public function index(Request $request)
{
// 验证数据
$error_message = $this->dataValidator->indexValidator($request->all());
if ($error_message) {
return response()->json(['ErrorCode'=>ErrorInc::INVALID_PARAM, 'ErrorMessage'=>$error_message->first(), 'Data'=>[$error_message]]);
}
$return_data = OrderListService::index($request->all(), $this->show_count,1);
return $return_data;
}
// 接单
public function receiving(Request $request)
{
// 验证数据
$error_message = $this->dataValidator->receivingStartValidator($request->all());
if ($error_message) {
return response()->json(['ErrorCode'=>ErrorInc::INVALID_PARAM, 'ErrorMessage'=>$error_message->first(), 'Data'=>[$error_message]]);
}
$input = $request->all();
if($input['type']==1){
$return_data = OrderListService::getPerson($request->all(),$request['old_install_id']);
}
if($input['type']==2) {
$error_message = $this->dataValidator->receivingValidator($request->all());
if ($error_message) {
return response()->json(['ErrorCode'=>ErrorInc::INVALID_PARAM, 'ErrorMessage'=>$error_message->first(), 'Data'=>[$error_message]]);
}
$return_data = OrderListService::receiving($request->all());
}
return response()->json($return_data);
}
// 拒单
public function refuse(Request $request)
{
// 验证数据
$error_message = $this->dataValidator->refuseValidator($request->all());
if ($error_message) {
return response()->json(['ErrorCode'=>ErrorInc::INVALID_PARAM, 'ErrorMessage'=>$error_message->first(), 'Data'=>[$error_message]]);
}
$return_data = OrderListService::refuse($request->all());
return response()->json($return_data);
}
// 检验
public function inspect(Request $request)
{
// 验证数据
$error_message = $this->dataValidator->startInstallValidator($request->all());
if ($error_message) {
return response()->json(['ErrorCode'=>ErrorInc::INVALID_PARAM, 'ErrorMessage'=>$error_message->first(), 'Data'=>[$error_message]]);
}
$return_data = OrderListService::inspect($request->all());
return response()->json($return_data);
}
// 开始安装
public function startInstall(Request $request)
{
// 验证数据
$error_message = $this->dataValidator->startInstallValidator($request->all());
if ($error_message) {
return response()->json(['ErrorCode'=>ErrorInc::INVALID_PARAM, 'ErrorMessage'=>$error_message->first(), 'Data'=>[$error_message]]);
}
$return_data = OrderListService::startInstall($request->all());
return response()->json($return_data);
}
// 安装反馈
public function installFeedback(Request $request)
{
// 验证数据
$error_message = $this->dataValidator->installFeedbackValidator($request->all());
if ($error_message) {
return response()->json(['ErrorCode'=>ErrorInc::INVALID_PARAM, 'ErrorMessage'=>$error_message->first(), 'Data'=>[$error_message]]);
}
$return_data = OrderListService::installFeedback($request->all());
return response()->json($return_data);
}
// 获取反馈信息
public function getFeedback(Request $request)
{
// 验证数据
$error_message = $this->dataValidator->startInstallValidator($request->all());
if ($error_message) {
return response()->json(['ErrorCode'=>ErrorInc::INVALID_PARAM, 'ErrorMessage'=>$error_message->first(), 'Data'=>[$error_message]]);
}
$return_data = OrderListService::getFeedback($request->all());
return response()->json($return_data);
}
// 详情
public function info(Request $request)
{
// 验证数据
$error_message = $this->dataValidator->startInstallValidator($request->all());
if ($error_message) {
return response()->json(['ErrorCode'=>ErrorInc::INVALID_PARAM, 'ErrorMessage'=>$error_message->first(), 'Data'=>[$error_message]]);
}
$return_data = OrderListService::info($request->all());
return response()->json($return_data);
}
// 获取技师
public function getInstallPerson(Request $request)
{
// 验证数据
$error_message = $this->dataValidator->indexValidator($request->all());
if ($error_message) {
return response()->json(['ErrorCode'=>ErrorInc::INVALID_PARAM, 'ErrorMessage'=>$error_message->first(), 'Data'=>[$error_message]]);
}
$return_data = OrderListService::getInstallPerson($request->all());
return response()->json($return_data);
}
// 获取标签
public function getLabel(Request $request)
{
// 验证数据
$error_message = $this->dataValidator->indexValidator($request->all());
if ($error_message) {
return response()->json(['ErrorCode'=>ErrorInc::INVALID_PARAM, 'ErrorMessage'=>$error_message->first(), 'Data'=>[$error_message]]);
}
$return_data = OrderListService::getLabel($request->all());
return response()->json($return_data);
}
// 获取操作记录
public function operatingRecord(Request $request)
{
// 验证数据
$error_message = $this->dataValidator->operatingRecordValidator($request->all());
if ($error_message) {
return response()->json(['ErrorCode'=>ErrorInc::INVALID_PARAM, 'ErrorMessage'=>$error_message->first(), 'Data'=>[$error_message]]);
}
$return_data = OrderListService::operatingRecord($request->all());
return response()->json($return_data);
}
// 图片反馈
public function imageFeedback(Request $request)
{
// 验证数据
$error_message = $this->dataValidator->imageFeedbackValidator($request->all());
if ($error_message) {
return response()->json(['ErrorCode'=>ErrorInc::INVALID_PARAM, 'ErrorMessage'=>$error_message->first(), 'Data'=>[$error_message]]);
}
$return_data = OrderListService::imageFeedback($request->all());
return response()->json($return_data);
}
// 车牌反馈
public function LicenseFeedback(Request $request)
{
// 验证数据
$error_message = $this->dataValidator->LicenseFeedbackValidator($request->all());
if ($error_message) {
return response()->json(['ErrorCode'=>ErrorInc::INVALID_PARAM, 'ErrorMessage'=>$error_message->first(), 'Data'=>[$error_message]]);
}
$return_data = OrderListService::LicenseFeedback($request->all());
return response()->json($return_data);
}
}
<?php
namespace App\Http\Controllers\Api\MobileWeb;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Requests\Validators\Api\MobileWeb\ServiceEvaluationValidator;
use BlueCity\Core\Inc\ErrorInc;
use App\Services\Api\MobileWeb\ServiceEvaluationService;
// 移动端-账单列表
class ServiceEvaluationController extends Controller
{
// 列表每页显示数据个数
protected $show_count = 10;
public function __construct()
{
$this->dataValidator = new ServiceEvaluationValidator();
}
// 列表
public function index(Request $request)
{
// 验证数据
$error_message = $this->dataValidator->indexValidator($request->all());
if ($error_message) {
return response()->json(['ErrorCode'=>ErrorInc::INVALID_PARAM, 'ErrorMessage'=>$error_message->first(), 'Data'=>[$error_message]]);
}
$return_data = ServiceEvaluationService::index($request->all(), $this->show_count);
return $return_data;
}
}
<?php
namespace App\Http\Controllers\Api\MobileWeb;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Requests\Validators\Api\MobileWeb\TechnicianValidator;
use BlueCity\Core\Inc\ErrorInc;
use App\Services\Api\MobileWeb\TechnicianService;
// 移动端-技师管理
class TechnicianController extends Controller
{
// 列表每页显示数据个数
protected $show_count = 10;
public function __construct()
{
$this->dataValidator = new TechnicianValidator();
}
// 列表
public function index(Request $request)
{
$return_data = TechnicianService::index($request->all(), $this->show_count);
return $return_data;
}
// 技师新增
public function add(Request $request)
{
// 验证数据
$error_message = $this->dataValidator->addValidator($request->all());
if ($error_message) {
return response()->json(['ErrorCode'=>ErrorInc::INVALID_PARAM, 'ErrorMessage'=>$error_message->first(), 'data'=>[$error_message]]);
}
$return_data = TechnicianService::add($request);
return response()->json($return_data);
}
// 技师编辑
public function edit(Request $request)
{
// 验证数据
$error_message = $this->dataValidator->editShowValidator($request->all());
if ($error_message) {
return response()->json(['ErrorCode'=>ErrorInc::INVALID_PARAM, 'ErrorMessage'=>$error_message->first(), 'data'=>[$error_message]]);
}
if ($request['type'] == 1) {
$return_data = TechnicianService::editShow($request);
return response()->json($return_data);
}
// 编辑提交验证数据
$error_message = $this->dataValidator->addValidator($request->all());
if ($error_message) {
return response()->json(['ErrorCode'=>ErrorInc::INVALID_PARAM, 'ErrorMessage'=>$error_message->first(), 'data'=>[$error_message]]);
}
$return_data = TechnicianService::edit($request);
return response()->json($return_data);
}
// 修改密码
public function changePassword(Request $request)
{
// 验证数据
$error_message = $this->dataValidator->changePasswordValidator($request->all());
if ($error_message) {
return response()->json(['ErrorCode'=>ErrorInc::INVALID_PARAM, 'ErrorMessage'=>$error_message->first(), 'data'=>[$error_message]]);
}
$return_data = TechnicianService::changePassword($request->all());
return response()->json($return_data);
}
// 删除
public function delete(Request $request)
{
// 验证数据
$error_message = $this->dataValidator->deleteValidator($request->all());
if ($error_message) {
return response()->json(['ErrorCode'=>ErrorInc::INVALID_PARAM, 'ErrorMessage'=>$error_message->first(), 'data'=>[$error_message]]);
}
$return_data = TechnicianService::delete($request->all());
return response()->json($return_data);
}
}
...@@ -60,5 +60,6 @@ class Kernel extends HttpKernel ...@@ -60,5 +60,6 @@ class Kernel extends HttpKernel
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'requestpc'=>\App\Http\Middleware\RequestPcMiddleware::class, 'requestpc'=>\App\Http\Middleware\RequestPcMiddleware::class,
'RequestApp'=>\App\Http\Middleware\RequestAppMiddleware::class, 'RequestApp'=>\App\Http\Middleware\RequestAppMiddleware::class,
'WebLogin'=>\App\Http\Middleware\WebLogin::class,
]; ];
} }
...@@ -18,38 +18,52 @@ class WebLogin ...@@ -18,38 +18,52 @@ class WebLogin
public function handle($request, Closure $next) public function handle($request, Closure $next)
{ {
if(!$request->exists('api_token')){ if(!$request->exists('api_token')){
return response()->json(["ErrorCode"=>300,'ErrorMessage'=>'api_token失效,请重新登录!','data'=>'']); return response()->json(["ErrorCode"=>300,'ErrorMessage'=>'api_token失效:检索码01,请重新登录!','data'=>'']);
}
if(!$request->exists('session_company_id')){
return response()->json(["ErrorCode"=>300,'ErrorMessage'=>'api_token失效:检索码05,请重新登录!','data'=>'']);
}
if(!$request->exists('session_install_id')){
return response()->json(["ErrorCode"=>300,'ErrorMessage'=>'api_token失效:检索码06,请重新登录!','data'=>'']);
} }
$request['api_token_old'] = $request['api_token']; $request['api_token_old'] = $request['api_token'];
// 解密api_token,如果不是系统生成的token会解密失败 // 解密api_token,如果不是系统生成的token会解密失败
try{ try{
$api_token = Crypt::decrypt($request['api_token']); $api_token = Crypt::decrypt($request['api_token']);
}catch (\Exception $e){ }catch (\Exception $e){
return response()->json(["ErrorCode"=>300,'ErrorMessage'=>'api_token失效,请重新登录!2','data'=>'']); return response()->json(["ErrorCode"=>300,'ErrorMessage'=>'api_token失效:检索码02,请重新登录!','data'=>'']);
} }
// 拿到token获取登录表信息 // 拿到token获取登录表信息
$login_web = DB::table('login_web') $login_web = DB::table('login_web')
->where('api_token','=',$api_token) ->where('api_token','=',$api_token)
->select('lowe_last_login','api_token') ->select('lowe_last_login','api_token','company_id','install_id','admin_id','user_type')
->first(); ->first();
if(empty($login_web)){ if(empty($login_web)){
return response()->json(["ErrorCode"=>300,'ErrorMessage'=>'api_token失效,请重新登录!3','data'=>'']); return response()->json(["ErrorCode"=>300,'ErrorMessage'=>'api_token失效:检索码03,请重新登录!','data'=>'']);
} }
// 当前时间 // 当前时间
$hours = time(); $hours = time();
// 如果最后登录时间小于当前时间,说明登陆过期 // 如果最后登录时间小于当前时间,说明登陆过期
if($login_web->lowe_last_login < $hours){ if($login_web['lowe_last_login'] < $hours){
return response()->json(["ErrorCode"=>300, 'ErrorMessage'=>'登陆过期,请重新登录', 'data'=>'']); return response()->json(["ErrorCode"=>300, 'ErrorMessage'=>'登陆过期,请重新登录', 'data'=>'']);
} }
if($request['session_company_id'] !=$login_web['company_id'] || $request['session_install_id'] !=$login_web['install_id']){
return response()->json(["ErrorCode"=>300,'ErrorMessage'=>'api_token失效:检索码04,请重新登录!','data'=>'']);
}
$now_time = $hours + 10*60*60; $now_time = $hours + 10*60*60;
if ($now_time > $login_web->lowe_last_login) { if ($now_time > $login_web['lowe_last_login']) {
// 每隔2个小时更新一次,降低更新次数,如果登录时间超过2个小时在操作就当前时间加12小时 // 每隔2个小时更新一次,降低更新次数,如果登录时间超过2个小时在操作就当前时间加12小时
DB::table('login_web')->where('api_token','=',$api_token)->update(['lowe_last_login'=>$hours + 12*60*60]); DB::table('login_web')->where('api_token','=',$api_token)->update(['lowe_last_login'=>$hours + 12*60*60]);
} }
$request['api_token'] = $api_token;//赋值解密后的token值 $request['api_token'] = $api_token;//赋值解密后的token值
$session['user_type'] = $login_web['user_type'];//用户账号类型
$session['company_id'] = $login_web['company_id'];//公司id
$session['install_id'] = $login_web['install_id'];//操作人id
$session['admin_id'] = $login_web['admin_id'];//所属服务商id
$session['install_name'] = $login_web['install_name'];//操作人信息
$request['session'] = $session;
return $next($request); return $next($request);
} }
} }
...@@ -24,16 +24,13 @@ class OrderListValidator extends FormRequest ...@@ -24,16 +24,13 @@ class OrderListValidator extends FormRequest
{ {
// 自定义错误消息 // 自定义错误消息
$messages = [ $messages = [
'install_id.required' => '请输入账号id', 'stauas.required' => '请输入订单状态',
'install_id.integer' => '参数错误', 'stauas.integer' => '参数错误',
'admin_id.required' => '请输入服务商id',
'admin_id.integer' => '参数错误',
]; ];
// 数据验证 // 数据验证
$validator = Validator::make($data, [ $validator = Validator::make($data, [
'install_id' => 'required|integer|min:1', 'stauas' => 'required|integer|min:1',
'admin_id' => 'required|integer|min:1',
], $messages); ], $messages);
// 判断数据验证是否成功 // 判断数据验证是否成功
...@@ -64,25 +61,42 @@ class OrderListValidator extends FormRequest ...@@ -64,25 +61,42 @@ class OrderListValidator extends FormRequest
return $validator->errors(); return $validator->errors();
} }
} }
// 接单验证器入口
public function receivingStartValidator($data)
{
// 自定义错误消息
$messages = [
'type.required' => '请输入请求类型',
'type.in' => '参数错误',
'id.required' => '请输入工单id',
'id.integer' => '参数错误',
];
// 数据验证
$validator = Validator::make($data, [
'type' => [//类型1强制登录2不登录
'required',
Rule::in(['1', '2']),
],
'id' => 'required|integer|min:1',
], $messages);
// 判断数据验证是否成功
if ($validator->fails()) {
return $validator->errors();
}
}
// 接单验证器 // 接单验证器
public function receivingValidator($data) public function receivingValidator($data)
{ {
// 自定义错误消息 // 自定义错误消息
$messages = [ $messages = [
'install_id.required' => '参数错误',
'admin_id.required' => '参数错误',
'id.required' => '请输入工单id',
'id.integer' => '参数错误',
'receive_install_id.required' => '请选择安装人员', 'receive_install_id.required' => '请选择安装人员',
'receive_install_id.integer' => '参数错误', 'receive_install_id.integer' => '参数错误',
]; ];
// 数据验证 // 数据验证
$validator = Validator::make($data, [ $validator = Validator::make($data, [
'install_id' => 'required|integer|min:1',
'admin_id' => 'required|integer|min:1',
'id' => 'required|integer|min:1',
'receive_install_id' => 'required|integer|min:1', 'receive_install_id' => 'required|integer|min:1',
], $messages); ], $messages);
......
...@@ -18,10 +18,12 @@ class LoginService ...@@ -18,10 +18,12 @@ class LoginService
{ {
if ($request['user_type'] == 1) { //技师登录 if ($request['user_type'] == 1) { //技师登录
// 查询登录账号数据 // 查询登录账号数据
$find_person = InstallPerson::where('delet_y', 1) $find_person = DB::table('install_person as install')
->leftJoin('admin as adm', 'install.admin_id', '=', 'adm.id')
->where('delet_y', 1)
->where('check_code', $request['account']) ->where('check_code', $request['account'])
->where('install_password', md5($request['password'])) ->where('install_password', md5($request['password']))
->select('id', 'check_code', 'install_name', 'install_phone', 'install_is_type', 'admin_id') ->select('install.id', 'check_code', 'install_name', 'install_phone', 'install_is_type', 'admin_id','company_id','admin_groupnew')
->first(); ->first();
} elseif($request['user_type'] == 2) { //服务商登录 } elseif($request['user_type'] == 2) { //服务商登录
//判定是否有公司名称字段 //判定是否有公司名称字段
...@@ -34,9 +36,10 @@ class LoginService ...@@ -34,9 +36,10 @@ class LoginService
$find_person = DB::table('admin as adm') $find_person = DB::table('admin as adm')
->leftJoin('admin_infor as adin', 'adin.admin_id', '=', 'adm.id') ->leftJoin('admin_infor as adin', 'adin.admin_id', '=', 'adm.id')
->where('admin_acc', $request['account']) ->where('admin_acc', $request['account'])
->where('company_id', $company_id)
->whereIn('admin_groupnew', [2,3]) ->whereIn('admin_groupnew', [2,3])
->where('admin_password', md5($request['password'])) ->where('admin_password', md5($request['password']))
->select('adm.id', 'admin_acc as check_code', 'admin_name as install_name', 'phone as install_phone', 'enable as install_is_type', 'adm.id as admin_id') ->select('adm.id', 'admin_acc as check_code', 'admin_name as install_name', 'phone as install_phone', 'enable as install_is_type', 'adm.id as admin_id','admin_groupnew','company_id')
->first(); ->first();
$find_person = CommonService::dataToArray($find_person); $find_person = CommonService::dataToArray($find_person);
} }
...@@ -46,7 +49,9 @@ class LoginService ...@@ -46,7 +49,9 @@ class LoginService
if ($find_person['install_is_type'] != 1) { if ($find_person['install_is_type'] != 1) {
return ['ErrorCode' => 203, 'ErrorMessage' => '当前账号已停用!', 'data' => '']; return ['ErrorCode' => 203, 'ErrorMessage' => '当前账号已停用!', 'data' => ''];
} }
if($request['user_type'] == 2 && $find_person['admin_groupnew']==3){
$request['user_type'] = 3;
}
if ($request['openid']) { if ($request['openid']) {
// 微信授权绑定用户信息 // 微信授权绑定用户信息
$bingding_res = self::accreditBinding($request, $find_person); $bingding_res = self::accreditBinding($request, $find_person);
...@@ -70,12 +75,13 @@ class LoginService ...@@ -70,12 +75,13 @@ class LoginService
$lote_data['install_name'] = $find_person['install_name']??""; //账号姓名 $lote_data['install_name'] = $find_person['install_name']??""; //账号姓名
$lote_data['install_phone'] = $find_person['install_phone']; //手机号 $lote_data['install_phone'] = $find_person['install_phone']; //手机号
$lote_data['admin_id'] = $find_person['admin_id']; //所属服务中心id $lote_data['admin_id'] = $find_person['admin_id']; //所属服务中心id
$lote_data['user_type'] = $request['user_type']; //登录类型:1技师2服务商 $lote_data['user_type'] = $request['user_type']; //登录类型:1技师2服务商3经销商
$lote_data['company_id'] = $find_person['company_id']; //所属公司id
$lote_data['role_auth'] = ''; $lote_data['role_auth'] = '';
$lote_data['auth_routes'] = ''; $lote_data['auth_routes'] = '';
$lote_res = DB::table('login_web')->insert($lote_data); $lote_res = DB::table('login_web')->insert($lote_data);
if (empty($lote_res)) { if (empty($lote_res)) {
return ["ErrorCode" => 204, 'ErrorMessage' => '登录失败!1', 'data' => '{}']; return ["ErrorCode" => 204, 'ErrorMessage' => '登录失败!1', 'data' => ''];
} }
// 返回数据 // 返回数据
...@@ -86,6 +92,7 @@ class LoginService ...@@ -86,6 +92,7 @@ class LoginService
'install_phone' => $find_person['install_phone'], 'install_phone' => $find_person['install_phone'],
'install_id' => $find_person['id'], 'install_id' => $find_person['id'],
'admin_id' => $find_person['admin_id'], 'admin_id' => $find_person['admin_id'],
'company_id' => $find_person['company_id'],
]; ];
return ['ErrorCode' => 1, 'ErrorMessage' => '登录成功', 'data' => $return_data]; return ['ErrorCode' => 1, 'ErrorMessage' => '登录成功', 'data' => $return_data];
} }
...@@ -94,7 +101,7 @@ class LoginService ...@@ -94,7 +101,7 @@ class LoginService
// 当前时间大于最后登陆时间,登录时间已过期,重新登录 // 当前时间大于最后登陆时间,登录时间已过期,重新登录
// login_type 值为1 强制登录 // login_type 值为1 强制登录
if ($now_time > $find_login->lowe_last_login || $request['login_type'] == 1) { if ($now_time > $find_login['lowe_last_login'] || $request['login_type'] == 1) {
//修改登陆状态 //修改登陆状态
$lote_data['install_id'] = $find_person['id']; //账号id $lote_data['install_id'] = $find_person['id']; //账号id
$lote_data['lowe_last_login'] = time() + $expiration_time; //最后登陆时间 $lote_data['lowe_last_login'] = time() + $expiration_time; //最后登陆时间
...@@ -103,11 +110,13 @@ class LoginService ...@@ -103,11 +110,13 @@ class LoginService
$lote_data['install_name'] = $find_person['install_name']; //账号姓名 $lote_data['install_name'] = $find_person['install_name']; //账号姓名
$lote_data['install_phone'] = $find_person['install_phone']; //手机号 $lote_data['install_phone'] = $find_person['install_phone']; //手机号
$lote_data['admin_id'] = $find_person['admin_id']; //所属服务中心id $lote_data['admin_id'] = $find_person['admin_id']; //所属服务中心id
$lote_data['user_type'] = $request['user_type']; //登录类型:1技师2服务商3经销商
$lote_data['company_id'] = $find_person['company_id']; //所属公司id
$lote_res = DB::table('login_web') $lote_res = DB::table('login_web')
->where('lowe_id', $find_login->lowe_id) ->where('lowe_id', $find_login['lowe_id'])
->update($lote_data); ->update($lote_data);
if (empty($lote_res)) { if (empty($lote_res)) {
return ["ErrorCode" => 500, 'ErrorMessage' => '登录失败!2', 'data' => '{}']; return ["ErrorCode" => 500, 'ErrorMessage' => '登录失败!2', 'data' => ''];
} }
// 返回数据 // 返回数据
...@@ -118,10 +127,11 @@ class LoginService ...@@ -118,10 +127,11 @@ class LoginService
'install_phone' => $find_person['install_phone'], 'install_phone' => $find_person['install_phone'],
'install_id' => $find_person['id'], 'install_id' => $find_person['id'],
'admin_id' => $find_person['admin_id'], 'admin_id' => $find_person['admin_id'],
'company_id' => $find_person['company_id'],
]; ];
return ['ErrorCode' => 1, 'ErrorMessage' => '登录成功', 'data' => $return_data]; return ['ErrorCode' => 1, 'ErrorMessage' => '登录成功', 'data' => $return_data];
} else { } else {
return ["ErrorCode" => 400, 'ErrorMessage' => '该用户已经登录', 'data' => '{}']; return ["ErrorCode" => 400, 'ErrorMessage' => '该用户已经登录', 'data' => ''];
} }
} }
......
...@@ -7,53 +7,63 @@ use Illuminate\Support\Facades\Request; ...@@ -7,53 +7,63 @@ use Illuminate\Support\Facades\Request;
use Illuminate\Support\Facades\Redis; use Illuminate\Support\Facades\Redis;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use BlueCity\Core\Inc\ErrorInc; use BlueCity\Core\Inc\ErrorInc;
use App\Models\{Orders, InstallPerson}; use App\Models\{Admin,
use App\Services\{BmmcService, Api\OrderManage\OrdersVehicleService}; GhPrice,
use App\Services\Api\Common\{CommonService}; GoodsBrand,
InstallLine,
Management,
Note,
OrderList,
OrderMsg,
Orders,
InstallPerson,
OrderTime,
SettlementList,
SettlementMoney,
SubmitPlease,
User};
use App\Services\{BmmcService, Api\OrderManage\OrdersVehicleService, CommonService};
class OrderListService extends Model class OrderListService extends Model
{ {
// 列表查询 // 列表查询
public static function index($request, $show_count = 10,$type=1) public static function index($request, $show_count = 10)
{ {
if($type==2){ $session = $request['session'];
return static::tempFunction($request, $show_count);
}
if (!isset($request['user_type'])) {
$request['user_type'] = 1;
}
// 查询列表 // 查询列表
$list_data = DB::table('orders as ol') $list_data = DB::table('order_list as ol')
->leftJoin('user as u', 'ol.new_customer_id', '=', 'u.id') ->leftJoin('user as u', 'ol.customer_id', '=', 'u.id')
->where('ser_id', $request['admin_id']) //服务商id ->where('ser_id', $session['admin_id']) //服务商id
->where('is_delete', 1) //是否删除:1正常2删除 ->where('is_delete', 1) //是否删除:1正常2删除
->whereIn("orders_sertatus",[1,2,4,5,6]) // 限制服务状态下的订单
->where(function ($query) use ($request) { ->where(function ($query) use ($request) {
// 安装人员 // 安装人员
if (!empty($request['install_id']) && $request['user_type'] == 1) { if (!empty($session['install_id']) && $session['user_type'] == 1) {
$query->where('intall_id', $request['install_id']); $query->where('intall_id', $session['install_id']);
} }
// 状态 // 状态
if (!empty($request['stauas'])) { if (!empty($request['stauas'])) {
if($request['stauas']==1){ if($request['stauas']==1){
// 未接单 // 未接单
$query->where("orders_sertatus",1); $query->whereIn("stauas",[10,20]);
}elseif($request['stauas']==2){
// 已接单
$query->where("stauas",'>',20)->where('stauas','!=',50)->where('stauas','!=',55);
}elseif($request['stauas']==3){ }elseif($request['stauas']==3){
// 已接单,但是不包括已完成 // 安装中
$query->whereIn("orders_sertatus",[2,4,5]); $query->where("stauas",30);
}elseif($request['stauas']==4){
// 已完成
$query->whereIn("stauas",[34,40]);
} }
} }
// 技师服务状态:0未派单1未接单2已接单3已拒单4已检验5安装中6已安装完成
if (!empty($request['service_state'])) {
$query->where('orders_sertatus', $request['service_state']);
}
}) })
->select('ol.id', 'ol.sys_num', 'order_num', 'ol.sys_num as serial_number','ol.reminder', 'p_id', 'orders_sertatus as service_state','ol.lock_type as lock_state', 'intall_person', 'intall_phone', 'crma_id', 'ol.distrib_time as create_time', 'shr_name', 'shr_phone', 'shr_sheng', 'shr_shi', 'shr_xian', 'shr_adress','company_id','admin_id') ->select('ol.id', 'order_num', 'serial_number', 'p_id','stauas', 'locklist_type', 'ol.sys_num','manhourfee', 'intall_person', 'intall_phone', 'day_time', 'order_goods_id', 'shr_name', 'shr_phone', 'shr_sheng', 'shr_shi', 'shr_xian', 'shr_adress','company_id','ser_id','get_time');
->orderby('ol.distrib_time', 'desc') if($request['stauas']!=1){
->paginate($show_count); $list_data = $list_data->orderby('get_time', 'desc');
}
$list_data = $list_data->orderby('ol.id', 'desc');
$list_data = $list_data->paginate($show_count);
$page['count'] = 0; $page['count'] = 0;
$page['page'] = 0; $page['page'] = 0;
$page['page_size'] = $show_count; $page['page_size'] = $show_count;
...@@ -65,99 +75,87 @@ class OrderListService extends Model ...@@ -65,99 +75,87 @@ class OrderListService extends Model
$list_items = $list_data->items(); $list_items = $list_data->items();
if ($list_items) { if ($list_items) {
$list_items = objectToArray($list_items); $list_items = CommonService::dataToArray($list_items);
$p_id = array_unique(array_column($list_items, 'p_id')); //来源id $company_id = array_unique(array_column($list_items, 'company_id')); //派单公司id
$crma_id = array_unique(array_column($list_items, 'crma_id')); //施工工艺id $good_id = array_unique(array_column($list_items, 'order_goods_id')); //订单商品表id
$orli_id = array_unique(array_column($list_items, 'id')); //工单id $serial_number = array_unique(array_column($list_items, 'serial_number')); //工单号
$company_id = array_unique(array_column($list_items, 'company_id')); //公司id //工单商品信息
$admin_id = array_unique(array_column($list_items, 'admin_id')); //派单人id $goods_name = OrderMsg::whereIn('id',$good_id)->select('goods_name','goods_id','goods_num','id')->get();
if($goods_name){
$goods_name = CommonService::dataToArray($goods_name);
$goods_name = CommonService::jointArrayKey($goods_name, 'id');
}
//查询派单公司信息 //查询派单公司信息
$company_data = DB::table('company_data') $company_data = DB::table('company')
->whereIn('cm_id', $company_id) ->whereIn('com_id', $company_id)
->pluck('cm_name', 'cm_id')->toArray(); ->pluck('com_name', 'com_id')->toArray();
//派单人电话 $getStauasName = self::getStauasName();
$admin_phone = DB::table('admin_infor') //施工节点
->whereIn('admin_id', $admin_id) $installLine = InstallLine::whereIn("line_serm",$serial_number)->select('line_serm','line_state')->get();
->pluck('phone', 'admin_id')->toArray(); if($installLine){
// 查询平台信息 $installLine = CommonService::dataToArray($installLine);
$find_pt_data = DB::table('pt') $installLine = CommonService::jointArrayKey($installLine, 'line_serm');
->whereIn('id', $p_id) }
->pluck('pt_name', 'id')->toArray();
// 查询施工工艺信息
$find_craft_data = DB::table('craft_manage')
->whereIn('crma_id', $crma_id)
->pluck('crma_name', 'crma_id')->toArray();
foreach ($list_items as $key => $value) { foreach ($list_items as $key => $value) {
// reminder $list_items[$key]['stauasName'] = $getStauasName[$value['stauas']]['name'];
$list_items[$key]['reminder_count']=$value['reminder']==1?1:0; // 是否锁定
// 计算总服务费
$list_items[$key]['orli_actual_price']=(float)Db::table('order_list')
->where('sys_num',$value['sys_num'])
->where('ser_id', $request['admin_id'])
->where('is_delete', 1)
->sum("negotiated_price");
// 计算已完成数量
$list_items[$key]['complete_num']=(int)Db::table('order_list')
->where('sys_num',$value['sys_num'])
->where('ser_id', $request['admin_id'])
->where('is_delete', 1)
->where('service_state', 6)
->where('orli_reject', 1)
->count();
// 订单状态处理
if($value['service_state']==1){
$list_items[$key]['stauas']=1;
}elseif(in_array($value['service_state'],[2,4,5])){
$list_items[$key]['stauas']=3;
}else{
$list_items[$key]['stauas']=4;
}
// 业务来源
if (isset($find_pt_data[$value['p_id']])) {
$list_items[$key]['pt_name'] = $find_pt_data[$value['p_id']];
} else {
$list_items[$key]['pt_name'] = '';
}
//派单公司 //派单公司
if (isset($company_data[$value['company_id']])) { if (isset($company_data[$value['company_id']])) {
$list_items[$key]['company_name'] = $company_data[$value['company_id']]; $list_items[$key]['company_name'] = $company_data[$value['company_id']];
} else { } else {
$list_items[$key]['company_name'] = ''; $list_items[$key]['company_name'] = '';
} }
//派单人电话 // 获取第一个字符
if (isset($admin_phone[$value['admin_id']])) { if(in_array($value['stauas'],[10,20])){
$list_items[$key]['admin_phone'] = $admin_phone[$value['admin_id']]; $list_items[$key]['shr_phone'] = substr_replace($list_items[$key]['shr_phone'], '****', 3, 4);
} else {
$list_items[$key]['admin_phone'] = '未设置';
}
if (isset($find_craft_data[$value['crma_id']])) {
$list_items[$key]['crma_name'] = $find_craft_data[$value['crma_id']];
} else {
$list_items[$key]['crma_name'] = '';
} }
$list_items[$key]['carmodel']=Note::where('note_type','客户车型')->where('orders_id',$value['sys_num'])->value('note_content');//车型信息
// 计算接单耗时 $list_items[$key]['goods_name']=$goods_name[$value['order_goods_id']]['goods_name'];
$consu_create_time = DB::table('orderserver_time') $list_items[$key]['goods_num']=$goods_name[$value['order_goods_id']]['goods_num'];
->where('ser_id',$request['admin_id']) if($value['stauas']>20){
->where('serial_number',$value['sys_num']) $list_items[$key]['goods_price'] = SettlementMoney::where('sem_synum',$value['sys_num'])->where('sem_type',1)->sum('sem_price');
->where('order_num',$value['order_num']) }else{
->where('is_type','接单时间') $list_items[$key]['goods_price'] = GhPrice::where('goods_id',$goods_name[$value['order_goods_id']]['goods_id'])->where('ser_id',$value['ser_id'])->value('supply_price');
->orderBy('id','desc') if(!$list_items[$key]['goods_price']){
->select('create_time') $list_items[$key]['goods_price'] = GhPrice::where('goods_id',$goods_name[$value['order_goods_id']]['goods_id'])->where('ser_id',0)->value('supply_price');
->first(); }
$list_items[$key]['time_consuming'] = '';
if(!empty($consu_create_time)){
$list_items[$key]['time_consuming']=calculateTimeInterval($value['create_time'], $consu_create_time->create_time);
} }
// 获取第一个字符
$mb_first = mb_substr($value['shr_name'], 0, 1, 'utf-8'); $mb_first = mb_substr($value['shr_name'], 0, 1, 'utf-8');
$list_items[$key]['first_name'] = $mb_first; $list_items[$key]['first_name'] = $mb_first;
$list_items[$key]['shr_phone'] = substr_replace($list_items[$key]['shr_phone'], '****', 3, 4); $list_items[$key]['button'] = [];
$list_items[$key]['orders_vehicle'] = OrdersVehicleService::getOrderVehicle($value['sys_num']); if($value['locklist_type'] != 2){
if(in_array($value['stauas'],[10,20])){
$list_items[$key]['button'] = [['action'=>'receiving','name'=>'接单'],['action'=>'refuse','name'=>'拒单']];
}elseif($value['stauas'] == 30){
if($request['stauas']==2){
$list_items[$key]['button'][] = ['action'=>'transferOfOrder','name'=>'改派'];
}if($request['stauas']==3){
$list_items[$key]['button'][] = ['action'=>'contact','name'=>'预约时间'];
if(isset($installLine[$value['serial_number']]['line_state'])){
switch ( $installLine[$value['serial_number']]['line_state'] ){
case 2:
$list_items[$key]['button'][] = ['action'=>'lineStart','name'=>'出发'];
break;
case 3:
$list_items[$key]['button'][] = ['action'=>'lineArrive','name'=>'抵达'];
break;
case 4:
$list_items[$key]['button'][] = ['action'=>'startInstall','name'=>'开始安装'];
break;
case 5:
$list_items[$key]['button'][] = ['action'=>'installFeedback','name'=>'申请完成'];
break;
default:
;
break;
}
}
}
$list_items[$key]['button'][] = ['action'=>'copyInfo','name'=>'复制信息'];
}elseif($value['stauas'] == 34 || $value['stauas'] == 40){
$list_items[$key]['button'] = [['action'=>'copyInfo','name'=>'复制信息']];
}
}
} }
$page['count'] = $list_data->total(); //总数据个数 $page['count'] = $list_data->total(); //总数据个数
$page['page'] = $list_data->currentPage(); //当前页面页码 $page['page'] = $list_data->currentPage(); //当前页面页码
...@@ -167,35 +165,9 @@ class OrderListService extends Model ...@@ -167,35 +165,9 @@ class OrderListService extends Model
$data['page'] = $page; $data['page'] = $page;
} }
// 查询施工的状态统计数据
$state_count = DB::table('orders')
->where('is_delete', 1)
->where('ser_id', $request['admin_id']) //服务商id
->whereIn("orders_sertatus",[1,2,4,5,6])
->where(function ($query) use ($request) {
// 安装人员
if (!empty($request['install_id']) && $request['user_type'] == 1) {
$query->where('intall_id', $request['install_id']);
}
})
->select(DB::raw('count(*) as count, orders_sertatus as stauas'))
->groupBy('orders_sertatus')
->get();
if ($state_count) {
$state_count = objectToArray($state_count);
}
$data['state_count'] = $state_count;
// 查询接单的状态统计数据,改为用上面查询出来的组装就行,因为数据格式完全变了,从订单表查了,所以根据上面的状态就可以获取数量了 // 查询接单的状态统计数据,改为用上面查询出来的组装就行,因为数据格式完全变了,从订单表查了,所以根据上面的状态就可以获取数量了
$wjd_num=0; $wjd_num=0;
$yjd_num=0; $yjd_num=0;
foreach ($state_count as $key => $val) {
if($val['stauas']==1){
$wjd_num+=$val['count'];
}elseif(in_array($val['stauas'],[2,4,5])){
$yjd_num+=$val['count'];
}
}
$stauas_count=[]; $stauas_count=[];
if($wjd_num > 0){ if($wjd_num > 0){
$stauas_count[]=['count'=>$wjd_num,'stauas'=>1]; $stauas_count[]=['count'=>$wjd_num,'stauas'=>1];
...@@ -212,268 +184,294 @@ class OrderListService extends Model ...@@ -212,268 +184,294 @@ class OrderListService extends Model
} }
} }
public static function tempFunction($request, $show_count = 10) /**|---------------------------------------------------------------------------------
{ * @name 获取接单技师
if (!isset($request['user_type'])) { * @param int $request 请求参数
$request['user_type'] = 1; * @param int $old_install_id 老技师id
} * @retrun \Illuminate\Http\JsonResponse
// 查询列表 * @author dou 2024/9/10 16:36
$list_data = DB::table('order_list as ol') * |---------------------------------------------------------------------------------
->leftJoin('user as u', 'ol.customer_id', '=', 'u.id') */
->where('ser_id', $request['admin_id']) //服务商id public static function getPerson ( $request , $old_install_id = 0 ){
->where('is_delete', 1) //是否删除:1正常2删除 $session = $request['session'];
->where(function ($query) use ($request) { $order_list = OrderList::where('id',$request['id'])->select('ser_id','customer_id')->first();
// 安装人员 if($order_list){
if (!empty($request['install_id']) && $request['user_type'] == 1) { $dress = User::where('id',$order_list['customer_id'])->select('shr_sheng','shr_shi','shr_xian','shr_adress')->first();
$query->where('install_id', $request['install_id']); $end = CommonService::jingwei($dress['shr_sheng'], $dress['shr_sheng'].$dress['shr_shi'].$dress['shr_xian'].$dress['shr_adress']);
} if(empty($old_install_id)) {
// 状态 $list = InstallPerson::where('install_is_type',1)
if (!empty($request['stauas'])) { ->where('delet_y',1)
$query->where('stauas', $request['stauas']); ->where('admin_id',$session['admin_id'])
->select('id','install_name','longitude','latitude','install_province','install_city','install_cuntry','install_address')
->get();
}else{
$list = InstallPerson::where('install_is_type',1)
->where('delet_y',1)
->where('admin_id',$session['admin_id'])
->where('id','!=',$old_install_id)
->select('id','install_name','longitude','latitude','install_province','install_city','install_cuntry','install_address')
->get();
}
if($list){
$list = CommonService::dataToArray($list);
foreach( $list as $kri => $vri ){
if($vri['longitude'] && $vri['latitude']){
$start = $vri['longitude'].','.$vri['latitude'];
}else{
$start = CommonService::jingwei($vri['install_province'],$vri['install_province'].$vri['install_city'].$vri['install_cuntry'].$vri['install_address']);
}
if($vri['install_address']=='' || $start ==''){
$list[$kri]['juli'] = '';
$list[$kri]['jl'] = 100000;
$lists[] = $list[$kri];
unset($list[$kri]);continue;
}else{
$jingwei[] = $start;
}
} }
// 技师服务状态:0未派单1未接单2已接单3已拒单4已检验5安装中5已安装完成 if(!empty($jingwei) && !empty($end)){
if (!empty($request['service_state'])) { $jingwei = implode('|', $jingwei);
$query->where('service_state', $request['service_state']); $res = CommonService::juli($jingwei,$end,2);
}else{
$res = [];
} }
}) $num_ = 0;
->select('ol.id', 'ol.sys_num', 'order_num', 'serial_number', 'p_id', 'stauas', 'service_state', 'intall_person', 'intall_phone', 'lock_state', 'negotiated_price as orli_actual_price', 'crma_id', 'reminder_count', 'ol.create_time', 'shr_name', 'shr_phone', 'shr_sheng', 'shr_shi', 'shr_xian', 'shr_adress') foreach ($list as $k => $v) {
->orderby('ol.id', 'desc') if (!isset($res[$num_])) {
->paginate($show_count); $list[$k]['juli'] = '';
$page['count'] = 0; $list[$k]['jl'] = 100000;
$page['page'] = 0; } else {
$page['page_size'] = $show_count; $list[$k]['juli'] = round($res[$num_]['distance']/1000,2) . '公里';
$page['allPage'] = 0; $list[$k]['jl'] = round($res[$num_]['distance']/1000,2);
$data['list'] = []; }
$data['page'] = $page; $num_++;
$list_items = $list_data->items();
if ($list_items) {
$list_items = objectToArray($list_items);
// dd($list_items);
$p_id = array_unique(array_column($list_items, 'p_id')); //来源id
$crma_id = array_unique(array_column($list_items, 'crma_id')); //施工工艺id
$orli_id = array_unique(array_column($list_items, 'id')); //工单id
// 查询平台信息
$find_pt_data = DB::table('pt')
->whereIn('id', $p_id)
->pluck('pt_name', 'id')->toArray();
// 查询施工工艺信息
$find_craft_data = DB::table('craft_manage')
->whereIn('crma_id', $crma_id)
->pluck('crma_name', 'crma_id')->toArray();
// 查询接单时间数据
$find_receive_duration = DB::table('order_list_details')
->whereIn('orli_id', $orli_id)
->pluck('receive_duration', 'orli_id')->toArray();
foreach ($list_items as $key => $value) {
// 业务来源
if (isset($find_pt_data[$value['p_id']])) {
$list_items[$key]['pt_name'] = $find_pt_data[$value['p_id']];
} else {
$list_items[$key]['pt_name'] = '';
} }
if (isset($find_craft_data[$value['crma_id']])) { if(!empty($lists) && !empty($list)) {
$list_items[$key]['crma_name'] = $find_craft_data[$value['crma_id']]; $list = array_merge($list, $lists);
} else { }elseif (!empty($lists)){
$list_items[$key]['crma_name'] = ''; $list = $lists;
} }
if (isset($find_receive_duration[$value['id']])) { $list = CommonService::resetListKey($list);
$list_items[$key]['time_consuming'] = $find_receive_duration[$value['id']]; foreach($list as $k => $v){
} else { $num[]=$v['jl'];
$list_items[$key]['time_consuming'] = ''; if($v['jl'] == 100000){
unset($list[$k]['jl']);
}
} }
// 获取第一个字符 array_multisort($num, SORT_NUMERIC ,SORT_ASC, $list);
$mb_first = mb_substr($value['shr_name'], 0, 1, 'utf-8'); return ['ErrorCode' => ErrorInc::DATA_EMPTY, 'ErrorMessage' => '暂无数据', 'Data' => $list];
$list_items[$key]['first_name'] = $mb_first; }else{
return ['ErrorCode' => ErrorInc::DATA_EMPTY, 'ErrorMessage' => '无可派单技师', 'Data' => $list];
$list_items[$key]['orders_vehicle'] = OrdersVehicleService::getOrderVehicle($value['sys_num']);
} }
$page['count'] = $list_data->total(); //总数据个数 }else{
$page['page'] = $list_data->currentPage(); //当前页面页码 return ['ErrorCode' => ErrorInc::DATA_EMPTY, 'ErrorMessage' => '未获取订单信息', 'Data' => ''];
$page['page_size'] = $show_count; //一页显示多少个
$page['allPage'] = $list_data->lastPage(); //表示最后一页的页码
$data['list'] = $list_items;
$data['page'] = $page;
}
// 查询施工的状态统计数据
$state_count = DB::table('order_list')
->where('is_delete', 1)
->where('ser_id', $request['admin_id']) //服务商id
->where(function ($query) use ($request) {
// 安装人员
if (!empty($request['install_id']) && $request['user_type'] == 1) {
$query->where('install_id', $request['install_id']);
}
})
->select(DB::raw('count(*) as count, service_state as stauas'))
->groupBy('service_state')
->get()->toArray();
$data['state_count'] = $state_count;
// 查询接单的状态统计数据
$stauas_count = DB::table('order_list')
->where('is_delete', 1)
->where('ser_id', $request['admin_id']) //服务商id
->where(function ($query) use ($request) {
// 安装人员
if (!empty($request['install_id']) && $request['user_type'] == 1) {
$query->where('install_id', $request['install_id']);
}
})
->select(DB::raw('count(*) as count, stauas'))
->groupBy('stauas')
->get()->toArray();
$data['stauas_count'] = $stauas_count;
if ($data['list']) {
return ['ErrorCode' => 1, 'ErrorMessage' => '成功', 'Data' => $data];
} else {
return ['ErrorCode' => ErrorInc::DATA_EMPTY, 'ErrorMessage' => '暂无数据', 'Data' => $data];
} }
} }
// 接单 // 接单
public static function receiving($request) public static function receiving($request)
{ {
$session = $request['session'];
// 查询服务单表信息 // 查询服务单表信息
$find_order = DB::table('orders')->where('id', $request['id']) $orderListArr = OrderList::where('id',$request['id'])
->where('is_delete', 1) ->where('is_delete', 1)
->select('id', 'sys_num', 'order_num', 'order_status', 'lock_type', 'ser_id', 'p_id', 'seco_id', 'customer_id', 'create_time','distrib_time', 'orders_sertatus')
->first(); ->first();
if(empty($orderListArr)){
// 判断是否已派单
if (empty($find_order)) {
return ['ErrorCode' => ErrorInc::DATA_EMPTY, 'ErrorMessage' => '未查询到订单', 'Data' => []]; return ['ErrorCode' => ErrorInc::DATA_EMPTY, 'ErrorMessage' => '未查询到订单', 'Data' => []];
} }
$find_order = objectToArray($find_order); $orderListArr = CommonService::dataToArray($orderListArr);
// 判断是否派单是否锁定 // 判断是否派单是否锁定
if($find_order['order_status'] != 5){ if(in_array($orderListArr['stauas'], [10,20])){
return ['ErrorCode' => ErrorInc::BUSINESS_FORBID, 'ErrorMessage' => '当前服务单不是待接单状态!', 'Data' => []]; return ['ErrorCode' => ErrorInc::BUSINESS_FORBID, 'ErrorMessage' => '当前服务单不是待接单状态!', 'Data' => []];
} }
if ($find_order['lock_type'] != 1) { if ($orderListArr['locklist_type'] != 1) {
return ['ErrorCode' => ErrorInc::BUSINESS_FORBID, 'ErrorMessage' => '当前服务单已锁定,无法接单!', 'Data' => []]; return ['ErrorCode' => ErrorInc::BUSINESS_FORBID, 'ErrorMessage' => '当前服务单已锁定,无法接单!', 'Data' => []];
} }
$MsgArr = OrderMsg::where('id',$orderListArr['order_goods_id'])
// 获取所有的工单数据 ->select("goods_id","goods_name","goods_brand","goods_price")
$order_list = DB::table('order_list') ->first();
->where('sys_num', $find_order['sys_num']) $goods_name = $MsgArr['goods_name'];
->where('is_delete', 1) $goods_id = $MsgArr['goods_id'];
->select('id', 'serial_number', 'stauas','create_time', 'service_state', 'negotiated_price','company_id','lock_state') $goods_brands = $MsgArr['goods_brand'];
->get(); $goods_name=trim($goods_name,',');
if (empty($order_list)) { $goods_id=trim($goods_id,',');
return ['ErrorCode' => ErrorInc::DATA_EMPTY, 'ErrorMessage' => '未查询到服务工单', 'Data' => []]; $instArr = InstallPerson::where('id',$request['receive_install_id'])
->select("install_name","install_phone","plate_num")
->first();
if(!$instArr){
return ['ErrorCode' => ErrorInc::BUSINESS_FORBID, 'ErrorMessage' => '技师不存在!', 'Data' => []];
} }
$order_list = objectToArray($order_list); $supply_price = GhPrice::where('goods_id',$MsgArr['goods_id'])
// 顺便判断一下工单状态 ->where('ser_id',$orderListArr['ser_id'])
foreach ($order_list as $key => $val) { ->orderBy('id','Desc')
if ($val['service_state'] != 1) { ->value('supply_price');
return ['ErrorCode' => ErrorInc::BUSINESS_FORBID, 'ErrorMessage' => '当前工单不是待接单状态!', 'Data' => []]; if(!$supply_price){
$supply_price = GhPrice::where('goods_id',$MsgArr['goods_id'])
->where('ser_id',0)
->orderBy('id','Desc')
->value('supply_price');
if(!$supply_price){
$supply_price='0.00';
} }
} }
//end Dong
$user_info = CommonService::webgetUserInfo($request['api_token']); $arr['sys_num']=$orderListArr['sys_num']; //系统单号
// 查询安装人员信息 $arr['order_num']=$orderListArr['order_num']; //平台单号
$find_person = InstallPerson::where('id', $request['receive_install_id']) $arr['serial_number']=$_POST['order_id']; //关联的order_list_id
->where('admin_id', $find_order['ser_id']) $arr['msg_id']=$orderListArr['order_goods_id']; //关联msg_id
->where('delet_y', 1) $arr['p_id']=$orderListArr['p_id']; //平台id
->select('id', 'install_name', 'install_phone') $arr['list_id']=$orderListArr['serial_number']; //派工单编号
->first(); $arr['ser_id']=$orderListArr['ser_id']; //服务中心id
if (empty($find_person)) { $arr['type']=2; //出售方式
return ['ErrorCode' => ErrorInc::DATA_EMPTY, 'ErrorMessage' => '未查询到安装人员', 'Data' => []]; // 上门安装
$arr['installperson']=$_POST['id']; // 安装人id
$arr['intall_person']=$instArr['install_name'];// 安装人名称
$arr['intall_phone']=$instArr['install_phone'];// 安装人电话
$is_bool="到店安装";
$info['installation']=2;//安装分类(上门安装)
// 供货价
$arr['order_price']=$supply_price; //供货价
// 总金额
$all_price=$supply_price; //Dong
$arr['all_price']=$all_price;
// 结算状态
$arr['sett_status']=1;
// 工单状态
$arr['list_service_type']=30;
// 客户id
$arr['customer_id']=$orderListArr['customer_id'];
$arr['category']=$orderListArr['category'];
$arr['sel_type']=$orderListArr['orli_type'];
$arr['pay_types']=$orderListArr['pay_typel'];//支付方式
$arr['goods_brand']=$goods_brands;
// 锁定状态
$submit_stauas = SubmitPlease::where('submit_sys_num',$orderListArr['sys_num'])->where('msg_id',$orderListArr['order_goods_id'])->orderBy('id','DESC')->value('submit_stauas');
if($submit_stauas==1){
$arr['locked']=2;
} }
/**追 溯**/
DB::beginTransaction(); $times=date('Y-m-d H:i:s');
// 更改订单表信息 $sometime=substr(date('Y-m-d H:i:s',strtotime("$times-2 month")),0,10);//入仓时间
$order_data=[]; $info['goods_name']=$goods_name;//产品名称
$order_data['orders_sertatus'] = 2; $info['manufacturer']=GoodsBrand::where("brand_name",$MsgArr['goods_brand'])
$order_data['order_status'] = 7; //订单状态:5施工未接单(服务已派单)6施工已接单7施工中8施工完成 ->where('company_id',$orderListArr['company_id'])
$order_data['intall_id'] = $find_person['id']; //安装人员id ->value('brand_remark');//生产厂家
$order_data['intall_person'] = $find_person['install_name']; //安装人员姓名 $info['transport']=$sometime;//入仓时间
$order_data['intall_phone'] = $find_person['install_phone']; //安装师傅电话 $info['order_time']=substr($times,0,10);//下单时间
$order_data['update_time'] = date('Y-m-d H:i:s'); $info['install_one']=$instArr['install_name'];//安装人
$ord_edit_res = Orders::where('id', $find_order['id'])->update($order_data); $info['replacing_time']=substr(date('Y-m-d H:i:s',strtotime('+2 year')),0,10);//建议更换时间
/**派工单**/
$post['stauas']=30;//派工单状态
// 更改工单信息 $post['install_id']=$_POST['id'];//安装人id
$service_data=[]; $post['intall_person']=$instArr['install_name'];//安装人姓名
$service_data['stauas'] = 3; //1未接单2已接单【废弃】3安装中4完成待审核 $post['intall_phone']=$instArr['install_phone'];//安装人电话
$service_data['service_state'] = 2; //技师服务状态:0未派单1未接单2已接单 $post['goods_brand']=$goods_brands;
$service_data['install_id'] = $find_person['id']; //安装人员id $post['goods_type']=3; //接单直接到安装中,略过检验 Dong
$service_data['intall_person'] = $find_person['install_name']; //安装人 $post['get_time']=date("Y-m-d H:i:s");
$service_data['intall_phone'] = $find_person['install_phone']; //安装师傅电话 /**订 单**/
$deor_res = DB::table('order_list') $get['order_status']=30;//订单状态
->where('sys_num', $find_order['sys_num']) $get['intall_person']=$instArr['install_name'];//安装人姓名
->where('is_delete', 1) $get['intall_phone']=$instArr['install_phone'];//安装人电话
->update($service_data); $returncount = OrderList::where('sys_num',$orderListArr['sys_num'])
$settlement_res=true; ->where('stauas',20)
$add_semo_res =true; ->count();
$now_time = date('Y-m-d H:i:s'); if($returncount==1){
$serial_numArr=[]; $restOrderList = OrderList::where('id',$request['id'])->update($post);
// 生成服务工单的结算数据 $restOrder = Orders::where('sys_num',$orderListArr['sys_num'])->update($get);
foreach ($order_list as $key => $val) { if($restOrderList && $restOrder){
$serial_numArr[]=$val['serial_number']; $restult=1;
$settlement_data=[]; }else{
$settlement_data['sys_num'] = $find_order['sys_num']; $restult=0;
$settlement_data['order_num'] = $find_order['order_num'];
$settlement_data['serial_number'] = $val['serial_number'];
$settlement_data['list_id'] = $val['id'];
// 服务工单结算单号
// $wat_num = 'JF' . date("YmdHis") . str_pad(rand(0, 999), 3, '0', STR_PAD_LEFT);
// $settlement_data['wat_num'] = $wat_num;
$settlement_data['p_id'] = $find_order['p_id'];
$settlement_data['ser_id'] = $find_order['ser_id'];
$settlement_data['seco_id'] = $find_order['seco_id'];
$settlement_data['installperson'] = $find_person['id'];
$settlement_data['intall_person'] = $find_person['install_name'];
$settlement_data['intall_phone'] = $find_person['install_phone'];
$settlement_data['customer_id'] = $find_order['customer_id'];
$settlement_data['lock_state'] = $val['lock_state'];
$settlement_data['all_price'] = $val['negotiated_price'];
$settlement_data['order_price'] = $val['negotiated_price'];
$settlement_data['list_service_type'] = $service_data['stauas'];
$settlement_data['company_id'] = $val['company_id'];
$settl_res = DB::table('settlement_list')->insertGetId($settlement_data);
if(!$settl_res){
$settlement_res=$settl_res;
} }
}else{
// 生成结算金额明细表 $restOrderList = OrderList::where('id',$request['id'])->update($post);
$add_semo_data=[]; if($restOrderList){
$add_semo_data['sem_slid'] = $settl_res; //结算信息id $restult=1;
$add_semo_data['sem_synum'] = $find_order['sys_num']; //结算单系统单号 }else{
$add_semo_data['sem_price'] = $val['negotiated_price']; //结算金额 $restult=0;
$add_semo_data['sem_type'] = 1; //金额类型1:供货价;2接单奖励;3:接单惩罚;4:撤销补助;5:代收金额;6:待付金额;7:完成奖励;8:加急奖励;9:夜间奖励
$add_semo_data['sem_creacter'] = $user_info->install_name; //金额添加人
$add_semo_data['add_time'] = $now_time; //添加时间
$semo_res = DB::table('settlement_money')->insert($add_semo_data);
if(!$semo_res){
$add_semo_res=$semo_res;
} }
timeLog($val['serial_number'], $find_order['order_num'], $user_info->install_name, "接单时间", date('Y-m-d H:i:s'));
} }
if($restult==1){
Management::where('trace_code',$orderListArr['serial_number'])->update($info);
$arr['company_id']=$orderListArr['company_id'];
$dou=SettlementList::insertGetId($arr);
if($dou){
self::calculates($dou,$orderListArr,$supply_price,$supply_price,$session);//计算奖惩金额以及评分
}
$weixin['ser_id'] = $_POST['id'];
$weixin['order_num'] = $orderListArr['order_num']; //平台单号
$weixin['goods_name'] = '安装服务';//$v['goods_name'];
$weixin['serial_number'] = $orderListArr['serial_number'];
$weixin['install_type'] = 2;
CommonService::requestPost('http://zptzchat.bluearp.com/m/index.php/BindingAccount/push_order', $weixin);
//begin Dong
$company_name=M('admin')->where("`id`='".$orderListArr['ser_id']."'")->field("`admin_acc`,`company_name`,`reward`")->find();//服务中心名称
$company_name = Admin::where('id',$orderListArr['ser_id'])->select("admin_acc","company_name","reward")->first();//服务中心名称
$douId = SettlementList::where('list_id',$orderListArr['serial_number'])->value('id');
$res = SettlementMoney::where('sem_slid',$douId)->where('sem_type',17)->first();
if(!$res){
$payout_time=M('order_time')->where("serial_number='".$orderListArr['serial_number']."' and is_type='接单时间'")->order('id DESC')->getField('create_time');//获取奖罚起始时间
$money_type=M('setmoney_type')->where("sety_id=17")->getField("sety_id,sety_price");//->select();
$zero1=time();//strtotime (date("Y-m-d H:i:s")); //当前时间 ,注意H 是24小时 h是12小时
$zero2=strtotime ($payout_time); //过年时间,不能写2014-1-21 24:00:00 这样不对
$guonian=($zero1-$zero2)/60; //60s*60min*24h
if($guonian<=17 && $company_name['reward']){
$money['sem_slid']=$douId;
$money['sem_synum']=$orderListArr['sys_num'];
$money['sem_creacter']=$company_name['admin_acc'];
$money['sem_price']=$money_type[17];
$money['sem_type']=17;
$settlement_money->add($money);
$all_price['all_price']=$settlement_money->where("sem_slid='".$douId."'")->SUM('sem_price');
$settlement_list->where("id='".$douId."'")->save($all_price);
}
}
//end Dong
$content = "订单".$is_bool."(".$orderListArr['serial_number'].")";
$this->operating_time($orderListArr['serial_number'],'接单时间',date("Y-m-d H-i-s"),$orderListArr['sys_num']);//订单操作时间
$this->add_thistory($orderListArr['serial_number'],'tih_acceptime',date("Y-m-d H:i:s"),$orderListArr['ser_id'],2);//添加历史时间
$this->inserting_log('接单1,',$orderListArr['sys_num'],$content,'派工单');//日志
//同步天猫
$pt_type = M('pt')->where("`id`='".$orderListArr['p_id']."'")->getField('pt_type');
if($pt_type==3) {
$arr_up['inspectionStation'] = M('admin')->where("`id`='" . $orderListArr['ser_id'] . "'")->getField('company_name');
$arr_up['workOrderId'] = $orderListArr['order_num'];
$arr_up['carNumber'] = $instArr['plate_num'] ? $instArr['plate_num'] : '暂无';
$arr_up['workerName'] = $instArr['install_name'];
$arr_up['workerMobile'] = $instArr['install_phone'];
$arr_up['channel'] = M('tm_proprietary')->where("`order_id`='" . $orderListArr['order_num'] . "'")->getField('channel');//
$arr_up['timestamp'] = time() . '000';
$arr_up['appKey'] = '2024032216801';
$arr_up['app_key'] = '2024032216801';
$arr_up['sign'] = $this->getSign($arr_up, 'b1e5c75530052abf221bfc9f3d2a591bdfa4ed7f');
// $url = 'https://opengw.ncarzone.com/api/workorder/uploadworker?';
$url = 'https://opengw.ncarzone.com/api/workorder/uploadworker';
ksort($arr_up);
foreach ($arr_up as $k => $v) {
if (strpos($v, ' ')) {
$urldata[] = $k . "=" . urlencode($v);
} else {
$urldata[] = $k . "=" . $v;
}
}
$urldata = implode("&", $urldata);
$ret_up = $this->requestPost($url, $urldata);
$file_path = "./filedata/tm_uploadworker".date("Ym").".txt";
$myfile = fopen($file_path, "a");
$txt = date("Y-m-d H:i:s").$ret_up.'---'.$url.'---'.$urldata."\r\n";
fwrite($myfile, $txt);
fclose($myfile);
// 生成服务工单详情数据 }
$list_details=[]; echo 1;exit;
$list_details['orli_receive_time'] = $now_time; //工单接单时间 }else{
$diff_time = calculateTimeInterval($find_order['distrib_time'], $now_time); echo 2;exit;
$list_details['receive_duration'] = $diff_time; //接单时长
$list_details['update_time'] = $now_time;
$orld_res = DB::table('order_list_details')
->whereIn('serial_number', $serial_numArr)
->update($list_details);
if ($ord_edit_res && $deor_res && $settlement_res && $orld_res && $add_semo_res) {
sertimeLog($find_order['sys_num'], $find_order['order_num'], $user_info->install_name, "接单时间", date('Y-m-d H:i:s'),$find_order['ser_id']);
DB::commit();
czrzLog("接单,", $find_order['sys_num'], "移动端-接单", "订单系统", request::ip(), $user_info->install_name);
return ['ErrorCode' => 1, 'ErrorMessage' => '接单成功', 'Data' => []];
} else {
DB::rollback();
return ['ErrorCode' => 500, 'ErrorMessage' => '接单失败', 'Data' => []];
} }
} }
...@@ -1169,4 +1167,57 @@ class OrderListService extends Model ...@@ -1169,4 +1167,57 @@ class OrderListService extends Model
->get()->toArray(); ->get()->toArray();
return ['ErrorCode' => 1, 'ErrorMessage' => '获取成功', 'Data' => $find_data]; return ['ErrorCode' => 1, 'ErrorMessage' => '获取成功', 'Data' => $find_data];
} }
/**|---------------------------------------------------------------------------------
* @name 工单状态
* @param string $type
* @retrun /multitype:array
* @author dou 2024/9/10 10:51
* |---------------------------------------------------------------------------------
*/
public static function getStauasName ( $type = true ){
$stauasName = [['type'=>'10','name'=>'未接单'],['type'=>'20','name'=>'未接单'],['type'=>'30','name'=>'安装中'],['type'=>'34','name'=>'待审核'],['type'=>'40','name'=>'已完成']];
if($type){
$stauasName = CommonService::jointArrayKey($stauasName, 'type');
}
return $stauasName;
}
#计算奖惩金额以及评分
function calculates($dou,$orderListArr,$supply_price,$manhourfee,$session){
#商品供货金额
$money['sem_slid'] = $dou;
$money['sem_synum'] = $orderListArr['sys_num'];
$money['sem_price'] = $manhourfee;
$money['sem_creacter'] = $session['install_name'];
$money['sem_type'] = 1;
$money['add_time'] = date("Y-m-d H:i:s");
SettlementMoney::insert($money);
// #开始计算奖惩金额以及评分
// $payout_time = OrderTime::where('serial_number',$orderListArr['serial_number'])
// ->where('is_type','起始时间')
// ->orderBy('id','DESC')
// ->value('create_time');//获取奖罚起始时间
// $zero1 = time();
// $zero2 = strtotime($payout_time);
// $guonian = ($zero1-$zero2)/60;
// #计算评分
// if($guonian<=5){
// $score['orsc_grade'] = 5;
// }if($guonian>5 && $guonian<=10){
// $score['orsc_grade'] = 2;
// }if($guonian>10){
// $score['orsc_grade'] = 1;
// }
// $score['orsc_sernum'] = $orderListArr['serial_number'];
// $score['orsc_slid'] = $dou;
// $score['orsc_creacter'] = $session['install_name'];
// $score['orsc_type'] = 1;
// DB::table("order_score")->insert($score);
// //默认生成平台评分十分
// $scoreq['orsc_grade'] = 5;
// $scoreq['orsc_sernum'] = $orderListArr['serial_number'];
// $scoreq['orsc_slid'] = $dou;
// $scoreq['orsc_creacter'] = $session['install_name'];
// $scoreq['orsc_type']=2;
// DB::table("order_score")->insert($score);
}
} }
...@@ -104,7 +104,7 @@ return [ ...@@ -104,7 +104,7 @@ return [
| |
*/ */
'key' => env('APP_KEY'), 'key' => 'base64:Qz/ncZnpyltqLHyovv/WxZQW6XPZPk8pvEuh6IeBSG0=',//env('APP_KEY'),
'cipher' => 'AES-256-CBC', 'cipher' => 'AES-256-CBC',
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论