提交 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
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'requestpc'=>\App\Http\Middleware\RequestPcMiddleware::class,
'RequestApp'=>\App\Http\Middleware\RequestAppMiddleware::class,
'WebLogin'=>\App\Http\Middleware\WebLogin::class,
];
}
......@@ -18,38 +18,52 @@ class WebLogin
public function handle($request, Closure $next)
{
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'];
// 解密api_token,如果不是系统生成的token会解密失败
try{
$api_token = Crypt::decrypt($request['api_token']);
}catch (\Exception $e){
return response()->json(["ErrorCode"=>300,'ErrorMessage'=>'api_token失效,请重新登录!2','data'=>'']);
return response()->json(["ErrorCode"=>300,'ErrorMessage'=>'api_token失效:检索码02,请重新登录!','data'=>'']);
}
// 拿到token获取登录表信息
$login_web = DB::table('login_web')
->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();
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();
// 如果最后登录时间小于当前时间,说明登陆过期
if($login_web->lowe_last_login < $hours){
if($login_web['lowe_last_login'] < $hours){
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;
if ($now_time > $login_web->lowe_last_login) {
if ($now_time > $login_web['lowe_last_login']) {
// 每隔2个小时更新一次,降低更新次数,如果登录时间超过2个小时在操作就当前时间加12小时
DB::table('login_web')->where('api_token','=',$api_token)->update(['lowe_last_login'=>$hours + 12*60*60]);
}
$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);
}
}
......@@ -24,16 +24,13 @@ class OrderListValidator extends FormRequest
{
// 自定义错误消息
$messages = [
'install_id.required' => '请输入账号id',
'install_id.integer' => '参数错误',
'admin_id.required' => '请输入服务商id',
'admin_id.integer' => '参数错误',
'stauas.required' => '请输入订单状态',
'stauas.integer' => '参数错误',
];
// 数据验证
$validator = Validator::make($data, [
'install_id' => 'required|integer|min:1',
'admin_id' => 'required|integer|min:1',
'stauas' => 'required|integer|min:1',
], $messages);
// 判断数据验证是否成功
......@@ -64,25 +61,42 @@ class OrderListValidator extends FormRequest
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)
{
// 自定义错误消息
$messages = [
'install_id.required' => '参数错误',
'admin_id.required' => '参数错误',
'id.required' => '请输入工单id',
'id.integer' => '参数错误',
'receive_install_id.required' => '请选择安装人员',
'receive_install_id.integer' => '参数错误',
];
// 数据验证
$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',
], $messages);
......
......@@ -18,10 +18,12 @@ class LoginService
{
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('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();
} elseif($request['user_type'] == 2) { //服务商登录
//判定是否有公司名称字段
......@@ -34,9 +36,10 @@ class LoginService
$find_person = DB::table('admin as adm')
->leftJoin('admin_infor as adin', 'adin.admin_id', '=', 'adm.id')
->where('admin_acc', $request['account'])
->where('company_id', $company_id)
->whereIn('admin_groupnew', [2,3])
->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();
$find_person = CommonService::dataToArray($find_person);
}
......@@ -46,7 +49,9 @@ class LoginService
if ($find_person['install_is_type'] != 1) {
return ['ErrorCode' => 203, 'ErrorMessage' => '当前账号已停用!', 'data' => ''];
}
if($request['user_type'] == 2 && $find_person['admin_groupnew']==3){
$request['user_type'] = 3;
}
if ($request['openid']) {
// 微信授权绑定用户信息
$bingding_res = self::accreditBinding($request, $find_person);
......@@ -70,12 +75,13 @@ class LoginService
$lote_data['install_name'] = $find_person['install_name']??""; //账号姓名
$lote_data['install_phone'] = $find_person['install_phone']; //手机号
$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['auth_routes'] = '';
$lote_res = DB::table('login_web')->insert($lote_data);
if (empty($lote_res)) {
return ["ErrorCode" => 204, 'ErrorMessage' => '登录失败!1', 'data' => '{}'];
return ["ErrorCode" => 204, 'ErrorMessage' => '登录失败!1', 'data' => ''];
}
// 返回数据
......@@ -86,6 +92,7 @@ class LoginService
'install_phone' => $find_person['install_phone'],
'install_id' => $find_person['id'],
'admin_id' => $find_person['admin_id'],
'company_id' => $find_person['company_id'],
];
return ['ErrorCode' => 1, 'ErrorMessage' => '登录成功', 'data' => $return_data];
}
......@@ -94,7 +101,7 @@ class LoginService
// 当前时间大于最后登陆时间,登录时间已过期,重新登录
// 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['lowe_last_login'] = time() + $expiration_time; //最后登陆时间
......@@ -103,11 +110,13 @@ class LoginService
$lote_data['install_name'] = $find_person['install_name']; //账号姓名
$lote_data['install_phone'] = $find_person['install_phone']; //手机号
$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')
->where('lowe_id', $find_login->lowe_id)
->where('lowe_id', $find_login['lowe_id'])
->update($lote_data);
if (empty($lote_res)) {
return ["ErrorCode" => 500, 'ErrorMessage' => '登录失败!2', 'data' => '{}'];
return ["ErrorCode" => 500, 'ErrorMessage' => '登录失败!2', 'data' => ''];
}
// 返回数据
......@@ -118,10 +127,11 @@ class LoginService
'install_phone' => $find_person['install_phone'],
'install_id' => $find_person['id'],
'admin_id' => $find_person['admin_id'],
'company_id' => $find_person['company_id'],
];
return ['ErrorCode' => 1, 'ErrorMessage' => '登录成功', 'data' => $return_data];
} else {
return ["ErrorCode" => 400, 'ErrorMessage' => '该用户已经登录', 'data' => '{}'];
return ["ErrorCode" => 400, 'ErrorMessage' => '该用户已经登录', 'data' => ''];
}
}
......
......@@ -7,53 +7,63 @@ use Illuminate\Support\Facades\Request;
use Illuminate\Support\Facades\Redis;
use Illuminate\Support\Facades\DB;
use BlueCity\Core\Inc\ErrorInc;
use App\Models\{Orders, InstallPerson};
use App\Services\{BmmcService, Api\OrderManage\OrdersVehicleService};
use App\Services\Api\Common\{CommonService};
use App\Models\{Admin,
GhPrice,
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
{
// 列表查询
public static function index($request, $show_count = 10,$type=1)
public static function index($request, $show_count = 10)
{
if($type==2){
return static::tempFunction($request, $show_count);
}
if (!isset($request['user_type'])) {
$request['user_type'] = 1;
}
$session = $request['session'];
// 查询列表
$list_data = DB::table('orders as ol')
->leftJoin('user as u', 'ol.new_customer_id', '=', 'u.id')
->where('ser_id', $request['admin_id']) //服务商id
$list_data = DB::table('order_list as ol')
->leftJoin('user as u', 'ol.customer_id', '=', 'u.id')
->where('ser_id', $session['admin_id']) //服务商id
->where('is_delete', 1) //是否删除:1正常2删除
->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']);
if (!empty($session['install_id']) && $session['user_type'] == 1) {
$query->where('intall_id', $session['install_id']);
}
// 状态
if (!empty($request['stauas'])) {
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){
// 已接单,但是不包括已完成
$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')
->orderby('ol.distrib_time', 'desc')
->paginate($show_count);
->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');
if($request['stauas']!=1){
$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['page'] = 0;
$page['page_size'] = $show_count;
......@@ -65,99 +75,87 @@ class OrderListService extends Model
$list_items = $list_data->items();
if ($list_items) {
$list_items = objectToArray($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
$company_id = array_unique(array_column($list_items, 'company_id')); //公司id
$admin_id = array_unique(array_column($list_items, 'admin_id')); //派单人id
//查询派单公司信息
$company_data = DB::table('company_data')
->whereIn('cm_id', $company_id)
->pluck('cm_name', 'cm_id')->toArray();
//派单人电话
$admin_phone = DB::table('admin_infor')
->whereIn('admin_id', $admin_id)
->pluck('phone', 'admin_id')->toArray();
// 查询平台信息
$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();
foreach ($list_items as $key => $value) {
// reminder
$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;
$list_items = CommonService::dataToArray($list_items);
$company_id = array_unique(array_column($list_items, 'company_id')); //派单公司id
$good_id = array_unique(array_column($list_items, 'order_goods_id')); //订单商品表id
$serial_number = array_unique(array_column($list_items, 'serial_number')); //工单号
//工单商品信息
$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');
}
// 业务来源
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'] = '';
//查询派单公司信息
$company_data = DB::table('company')
->whereIn('com_id', $company_id)
->pluck('com_name', 'com_id')->toArray();
$getStauasName = self::getStauasName();
//施工节点
$installLine = InstallLine::whereIn("line_serm",$serial_number)->select('line_serm','line_state')->get();
if($installLine){
$installLine = CommonService::dataToArray($installLine);
$installLine = CommonService::jointArrayKey($installLine, 'line_serm');
}
foreach ($list_items as $key => $value) {
$list_items[$key]['stauasName'] = $getStauasName[$value['stauas']]['name'];
//派单公司
if (isset($company_data[$value['company_id']])) {
$list_items[$key]['company_name'] = $company_data[$value['company_id']];
} else {
$list_items[$key]['company_name'] = '';
}
//派单人电话
if (isset($admin_phone[$value['admin_id']])) {
$list_items[$key]['admin_phone'] = $admin_phone[$value['admin_id']];
} else {
$list_items[$key]['admin_phone'] = '未设置';
// 获取第一个字符
if(in_array($value['stauas'],[10,20])){
$list_items[$key]['shr_phone'] = substr_replace($list_items[$key]['shr_phone'], '****', 3, 4);
}
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'];
$list_items[$key]['goods_num']=$goods_name[$value['order_goods_id']]['goods_num'];
if($value['stauas']>20){
$list_items[$key]['goods_price'] = SettlementMoney::where('sem_synum',$value['sys_num'])->where('sem_type',1)->sum('sem_price');
}else{
$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');
if(!$list_items[$key]['goods_price']){
$list_items[$key]['goods_price'] = GhPrice::where('goods_id',$goods_name[$value['order_goods_id']]['goods_id'])->where('ser_id',0)->value('supply_price');
}
// 计算接单耗时
$consu_create_time = DB::table('orderserver_time')
->where('ser_id',$request['admin_id'])
->where('serial_number',$value['sys_num'])
->where('order_num',$value['order_num'])
->where('is_type','接单时间')
->orderBy('id','desc')
->select('create_time')
->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');
$list_items[$key]['first_name'] = $mb_first;
$list_items[$key]['shr_phone'] = substr_replace($list_items[$key]['shr_phone'], '****', 3, 4);
$list_items[$key]['orders_vehicle'] = OrdersVehicleService::getOrderVehicle($value['sys_num']);
$list_items[$key]['button'] = [];
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['page'] = $list_data->currentPage(); //当前页面页码
......@@ -167,35 +165,9 @@ class OrderListService extends Model
$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;
$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=[];
if($wjd_num > 0){
$stauas_count[]=['count'=>$wjd_num,'stauas'=>1];
......@@ -212,268 +184,294 @@ class OrderListService extends Model
}
}
public static function tempFunction($request, $show_count = 10)
{
if (!isset($request['user_type'])) {
$request['user_type'] = 1;
/**|---------------------------------------------------------------------------------
* @name 获取接单技师
* @param int $request 请求参数
* @param int $old_install_id 老技师id
* @retrun \Illuminate\Http\JsonResponse
* @author dou 2024/9/10 16:36
* |---------------------------------------------------------------------------------
*/
public static function getPerson ( $request , $old_install_id = 0 ){
$session = $request['session'];
$order_list = OrderList::where('id',$request['id'])->select('ser_id','customer_id')->first();
if($order_list){
$dress = User::where('id',$order_list['customer_id'])->select('shr_sheng','shr_shi','shr_xian','shr_adress')->first();
$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)
->where('delet_y',1)
->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();
}
// 查询列表
$list_data = DB::table('order_list as ol')
->leftJoin('user as u', 'ol.customer_id', '=', 'u.id')
->where('ser_id', $request['admin_id']) //服务商id
->where('is_delete', 1) //是否删除:1正常2删除
->where(function ($query) use ($request) {
// 安装人员
if (!empty($request['install_id']) && $request['user_type'] == 1) {
$query->where('install_id', $request['install_id']);
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 (!empty($request['stauas'])) {
$query->where('stauas', $request['stauas']);
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($request['service_state'])) {
$query->where('service_state', $request['service_state']);
}
})
->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')
->orderby('ol.id', 'desc')
->paginate($show_count);
$page['count'] = 0;
$page['page'] = 0;
$page['page_size'] = $show_count;
$page['allPage'] = 0;
$data['list'] = [];
$data['page'] = $page;
$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(!empty($jingwei) && !empty($end)){
$jingwei = implode('|', $jingwei);
$res = CommonService::juli($jingwei,$end,2);
}else{
$res = [];
}
if (isset($find_craft_data[$value['crma_id']])) {
$list_items[$key]['crma_name'] = $find_craft_data[$value['crma_id']];
$num_ = 0;
foreach ($list as $k => $v) {
if (!isset($res[$num_])) {
$list[$k]['juli'] = '';
$list[$k]['jl'] = 100000;
} else {
$list_items[$key]['crma_name'] = '';
$list[$k]['juli'] = round($res[$num_]['distance']/1000,2) . '公里';
$list[$k]['jl'] = round($res[$num_]['distance']/1000,2);
}
if (isset($find_receive_duration[$value['id']])) {
$list_items[$key]['time_consuming'] = $find_receive_duration[$value['id']];
} else {
$list_items[$key]['time_consuming'] = '';
$num_++;
}
// 获取第一个字符
$mb_first = mb_substr($value['shr_name'], 0, 1, 'utf-8');
$list_items[$key]['first_name'] = $mb_first;
$list_items[$key]['orders_vehicle'] = OrdersVehicleService::getOrderVehicle($value['sys_num']);
if(!empty($lists) && !empty($list)) {
$list = array_merge($list, $lists);
}elseif (!empty($lists)){
$list = $lists;
}
$page['count'] = $list_data->total(); //总数据个数
$page['page'] = $list_data->currentPage(); //当前页面页码
$page['page_size'] = $show_count; //一页显示多少个
$page['allPage'] = $list_data->lastPage(); //表示最后一页的页码
$data['list'] = $list_items;
$data['page'] = $page;
$list = CommonService::resetListKey($list);
foreach($list as $k => $v){
$num[]=$v['jl'];
if($v['jl'] == 100000){
unset($list[$k]['jl']);
}
// 查询施工的状态统计数据
$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']);
array_multisort($num, SORT_NUMERIC ,SORT_ASC, $list);
return ['ErrorCode' => ErrorInc::DATA_EMPTY, 'ErrorMessage' => '暂无数据', 'Data' => $list];
}else{
return ['ErrorCode' => ErrorInc::DATA_EMPTY, 'ErrorMessage' => '无可派单技师', 'Data' => $list];
}
})
->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];
}else{
return ['ErrorCode' => ErrorInc::DATA_EMPTY, 'ErrorMessage' => '未获取订单信息', 'Data' => ''];
}
}
// 接单
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)
->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();
// 判断是否已派单
if (empty($find_order)) {
if(empty($orderListArr)){
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' => []];
}
if ($find_order['lock_type'] != 1) {
if ($orderListArr['locklist_type'] != 1) {
return ['ErrorCode' => ErrorInc::BUSINESS_FORBID, 'ErrorMessage' => '当前服务单已锁定,无法接单!', 'Data' => []];
}
// 获取所有的工单数据
$order_list = DB::table('order_list')
->where('sys_num', $find_order['sys_num'])
->where('is_delete', 1)
->select('id', 'serial_number', 'stauas','create_time', 'service_state', 'negotiated_price','company_id','lock_state')
->get();
if (empty($order_list)) {
return ['ErrorCode' => ErrorInc::DATA_EMPTY, 'ErrorMessage' => '未查询到服务工单', 'Data' => []];
}
$order_list = objectToArray($order_list);
// 顺便判断一下工单状态
foreach ($order_list as $key => $val) {
if ($val['service_state'] != 1) {
return ['ErrorCode' => ErrorInc::BUSINESS_FORBID, 'ErrorMessage' => '当前工单不是待接单状态!', 'Data' => []];
}
}
$user_info = CommonService::webgetUserInfo($request['api_token']);
// 查询安装人员信息
$find_person = InstallPerson::where('id', $request['receive_install_id'])
->where('admin_id', $find_order['ser_id'])
->where('delet_y', 1)
->select('id', 'install_name', 'install_phone')
$MsgArr = OrderMsg::where('id',$orderListArr['order_goods_id'])
->select("goods_id","goods_name","goods_brand","goods_price")
->first();
if (empty($find_person)) {
return ['ErrorCode' => ErrorInc::DATA_EMPTY, 'ErrorMessage' => '未查询到安装人员', 'Data' => []];
$goods_name = $MsgArr['goods_name'];
$goods_id = $MsgArr['goods_id'];
$goods_brands = $MsgArr['goods_brand'];
$goods_name=trim($goods_name,',');
$goods_id=trim($goods_id,',');
$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' => []];
}
$supply_price = GhPrice::where('goods_id',$MsgArr['goods_id'])
->where('ser_id',$orderListArr['ser_id'])
->orderBy('id','Desc')
->value('supply_price');
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
$arr['sys_num']=$orderListArr['sys_num']; //系统单号
$arr['order_num']=$orderListArr['order_num']; //平台单号
$arr['serial_number']=$_POST['order_id']; //关联的order_list_id
$arr['msg_id']=$orderListArr['order_goods_id']; //关联msg_id
$arr['p_id']=$orderListArr['p_id']; //平台id
$arr['list_id']=$orderListArr['serial_number']; //派工单编号
$arr['ser_id']=$orderListArr['ser_id']; //服务中心id
$arr['type']=2; //出售方式
// 上门安装
$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;
}
/**追 溯**/
$times=date('Y-m-d H:i:s');
$sometime=substr(date('Y-m-d H:i:s',strtotime("$times-2 month")),0,10);//入仓时间
$info['goods_name']=$goods_name;//产品名称
$info['manufacturer']=GoodsBrand::where("brand_name",$MsgArr['goods_brand'])
->where('company_id',$orderListArr['company_id'])
->value('brand_remark');//生产厂家
$info['transport']=$sometime;//入仓时间
$info['order_time']=substr($times,0,10);//下单时间
$info['install_one']=$instArr['install_name'];//安装人
$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
$post['intall_person']=$instArr['install_name'];//安装人姓名
$post['intall_phone']=$instArr['install_phone'];//安装人电话
$post['goods_brand']=$goods_brands;
$post['goods_type']=3; //接单直接到安装中,略过检验 Dong
$post['get_time']=date("Y-m-d H:i:s");
/**订 单**/
$get['order_status']=30;//订单状态
$get['intall_person']=$instArr['install_name'];//安装人姓名
$get['intall_phone']=$instArr['install_phone'];//安装人电话
$returncount = OrderList::where('sys_num',$orderListArr['sys_num'])
->where('stauas',20)
->count();
if($returncount==1){
$restOrderList = OrderList::where('id',$request['id'])->update($post);
$restOrder = Orders::where('sys_num',$orderListArr['sys_num'])->update($get);
if($restOrderList && $restOrder){
$restult=1;
}else{
$restult=0;
}
DB::beginTransaction();
// 更改订单表信息
$order_data=[];
$order_data['orders_sertatus'] = 2;
$order_data['order_status'] = 7; //订单状态:5施工未接单(服务已派单)6施工已接单7施工中8施工完成
$order_data['intall_id'] = $find_person['id']; //安装人员id
$order_data['intall_person'] = $find_person['install_name']; //安装人员姓名
$order_data['intall_phone'] = $find_person['install_phone']; //安装师傅电话
$order_data['update_time'] = date('Y-m-d H:i:s');
$ord_edit_res = Orders::where('id', $find_order['id'])->update($order_data);
// 更改工单信息
$service_data=[];
$service_data['stauas'] = 3; //1未接单2已接单【废弃】3安装中4完成待审核
$service_data['service_state'] = 2; //技师服务状态:0未派单1未接单2已接单
$service_data['install_id'] = $find_person['id']; //安装人员id
$service_data['intall_person'] = $find_person['install_name']; //安装人
$service_data['intall_phone'] = $find_person['install_phone']; //安装师傅电话
$deor_res = DB::table('order_list')
->where('sys_num', $find_order['sys_num'])
->where('is_delete', 1)
->update($service_data);
$settlement_res=true;
$add_semo_res =true;
$now_time = date('Y-m-d H:i:s');
$serial_numArr=[];
// 生成服务工单的结算数据
foreach ($order_list as $key => $val) {
$serial_numArr[]=$val['serial_number'];
$settlement_data=[];
$settlement_data['sys_num'] = $find_order['sys_num'];
$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);
if($restOrderList){
$restult=1;
}else{
$restult=0;
}
}
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;
}
// 生成结算金额明细表
$add_semo_data=[];
$add_semo_data['sem_slid'] = $settl_res; //结算信息id
$add_semo_data['sem_synum'] = $find_order['sys_num']; //结算单系统单号
$add_semo_data['sem_price'] = $val['negotiated_price']; //结算金额
$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;
}
$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);
timeLog($val['serial_number'], $find_order['order_num'], $user_info->install_name, "接单时间", date('Y-m-d H:i:s'));
}
// 生成服务工单详情数据
$list_details=[];
$list_details['orli_receive_time'] = $now_time; //工单接单时间
$diff_time = calculateTimeInterval($find_order['distrib_time'], $now_time);
$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' => []];
echo 1;exit;
}else{
echo 2;exit;
}
}
......@@ -1169,4 +1167,57 @@ class OrderListService extends Model
->get()->toArray();
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 [
|
*/
'key' => env('APP_KEY'),
'key' => 'base64:Qz/ncZnpyltqLHyovv/WxZQW6XPZPk8pvEuh6IeBSG0=',//env('APP_KEY'),
'cipher' => 'AES-256-CBC',
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论