|
@@ -3,6 +3,7 @@
|
|
namespace App\Http\Controllers\Api\mini;
|
|
namespace App\Http\Controllers\Api\mini;
|
|
|
|
|
|
use App\Models\Device;
|
|
use App\Models\Device;
|
|
|
|
+use App\Models\DeviceName;
|
|
use App\Models\InnerDevice;
|
|
use App\Models\InnerDevice;
|
|
use App\Models\Option;
|
|
use App\Models\Option;
|
|
use App\Models\Order;
|
|
use App\Models\Order;
|
|
@@ -10,6 +11,9 @@ use App\Models\OrderDevice;
|
|
use App\Models\Project;
|
|
use App\Models\Project;
|
|
use App\Models\ProjectRole;
|
|
use App\Models\ProjectRole;
|
|
use App\Models\ProjectUser;
|
|
use App\Models\ProjectUser;
|
|
|
|
+use App\Models\RentType;
|
|
|
|
+use App\Models\Spec;
|
|
|
|
+use App\Models\WorkPoint;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Illuminate\Support\Facades\Log;
|
|
@@ -47,21 +51,50 @@ class OrderController extends BaseController
|
|
$total = 0;
|
|
$total = 0;
|
|
foreach($devices as $device) {
|
|
foreach($devices as $device) {
|
|
$price = $this->transMoney($device['price']);
|
|
$price = $this->transMoney($device['price']);
|
|
- OrderDevice::create([
|
|
|
|
- 'name' => $device['name'],
|
|
|
|
|
|
+ $data = $this->getNameSpecRent($device);
|
|
|
|
+ OrderDevice::create(array_merge([
|
|
'order_id' => $order->id,
|
|
'order_id' => $order->id,
|
|
- 'device_id' => $device['type_id'],
|
|
|
|
'quantity' => $device['quantity'],
|
|
'quantity' => $device['quantity'],
|
|
'price' => $price,
|
|
'price' => $price,
|
|
'start_date' => $device['start_date'],
|
|
'start_date' => $device['start_date'],
|
|
'end_date' => $device['end_date']
|
|
'end_date' => $device['end_date']
|
|
- ]);
|
|
|
|
|
|
+ ], $data));
|
|
$total = $total + ($price * (int)$device['quantity']);
|
|
$total = $total + ($price * (int)$device['quantity']);
|
|
}
|
|
}
|
|
$order->update(['money' => $total]);
|
|
$order->update(['money' => $total]);
|
|
return $this->success();
|
|
return $this->success();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public function getNameSpecRent($data)
|
|
|
|
+ {
|
|
|
|
+ $device = Device::find($data['type_id']);
|
|
|
|
+
|
|
|
|
+ $rent_type = RentType::firstOrCreate([
|
|
|
|
+ 'name' => $data['rent']
|
|
|
|
+ ]);
|
|
|
|
+ if(!$device) return [
|
|
|
|
+ 'device_id' => '',
|
|
|
|
+ 'device_name_id' => '',
|
|
|
|
+ 'spec_id' => '',
|
|
|
|
+ 'rent_type_id' => $rent_type->id
|
|
|
|
+ ];
|
|
|
|
+ $device_name = DeviceName::firstOrCreate([
|
|
|
|
+ 'device_id' => $device->id,
|
|
|
|
+ 'name' => $data['name']
|
|
|
|
+ ]);
|
|
|
|
+ $spec = Spec::firstOrCreate([
|
|
|
|
+ 'device_id' => $device->id,
|
|
|
|
+ 'device_name_id' => $device_name->id,
|
|
|
|
+ 'name' => $data['spec']
|
|
|
|
+ ]);
|
|
|
|
+ return [
|
|
|
|
+ 'device_id' => $device->id,
|
|
|
|
+ 'device_name_id' => $device_name->id,
|
|
|
|
+ 'spec_id' => $spec->id,
|
|
|
|
+ 'rent_type_id' => $rent_type->id
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+
|
|
public function createInner(Request $request)
|
|
public function createInner(Request $request)
|
|
{
|
|
{
|
|
$project = Project::find($request->input('project_id'));
|
|
$project = Project::find($request->input('project_id'));
|
|
@@ -70,14 +103,18 @@ class OrderController extends BaseController
|
|
$using_id = Option::get('inner_devices', 'status', 'using');
|
|
$using_id = Option::get('inner_devices', 'status', 'using');
|
|
$free_id = Option::get('inner_devices', 'status', 'free');
|
|
$free_id = Option::get('inner_devices', 'status', 'free');
|
|
|
|
|
|
- foreach($devices as $device) {
|
|
|
|
- $device = InnerDevice::find($device['id']);
|
|
|
|
- if($device->status != $free_id) {
|
|
|
|
- $status = Option::find($device->status);
|
|
|
|
- $msg = $device['name'] . ($status ? $status['name'] : '使用中') . ',不能使用';
|
|
|
|
- return $this->error(['msg' => $msg]);
|
|
|
|
|
|
+ // 续租时不检查设备使用状态
|
|
|
|
+ if(!$request->input('type') || $request->input('type') != 're-rent') {
|
|
|
|
+ foreach($devices as $device) {
|
|
|
|
+ $device = InnerDevice::find($device['id']);
|
|
|
|
+ if($device->status != $free_id) {
|
|
|
|
+ $status = Option::find($device->status);
|
|
|
|
+ $msg = $device['name'] . ($status ? $status['name'] : '使用中') . ',不能使用';
|
|
|
|
+ return $this->error(['msg' => $msg]);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
$user = Auth::guard('mini')->user();
|
|
$user = Auth::guard('mini')->user();
|
|
$project_role_id = $request->input('is_draft') == 1 ? ProjectRole::getByKey('machine', 'id') : ProjectRole::getByKey('assist', 'id');
|
|
$project_role_id = $request->input('is_draft') == 1 ? ProjectRole::getByKey('machine', 'id') : ProjectRole::getByKey('assist', 'id');
|
|
$option = Option::get('orders', 'status', 'checking');
|
|
$option = Option::get('orders', 'status', 'checking');
|
|
@@ -98,15 +135,17 @@ class OrderController extends BaseController
|
|
OrderDevice::create([
|
|
OrderDevice::create([
|
|
'name' => $device['name'],
|
|
'name' => $device['name'],
|
|
'order_id' => $order->id,
|
|
'order_id' => $order->id,
|
|
- 'device_id' => $device['id'],
|
|
|
|
|
|
+ 'inner_device_id' => $device['id'],
|
|
'start_date' => $device['start_date'],
|
|
'start_date' => $device['start_date'],
|
|
'end_date' => $device['end_date']
|
|
'end_date' => $device['end_date']
|
|
]);
|
|
]);
|
|
if($device['id']) {
|
|
if($device['id']) {
|
|
InnerDevice::find($device['id'])->update([
|
|
InnerDevice::find($device['id'])->update([
|
|
|
|
+ 'project_id' => $order['project_id'],
|
|
'status' => $using_id,
|
|
'status' => $using_id,
|
|
'start_date' => $device['start_date'],
|
|
'start_date' => $device['start_date'],
|
|
- 'end_date' => $device['end_date']
|
|
|
|
|
|
+ 'end_date' => $device['end_date'],
|
|
|
|
+ 'work_point_id' => $request->input('work_point_id')
|
|
]);
|
|
]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -151,25 +190,104 @@ class OrderController extends BaseController
|
|
return $this->success();
|
|
return $this->success();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public function updateInner(Request $request)
|
|
|
|
+ {
|
|
|
|
+ $order = $this->model->find($request->input('id'));
|
|
|
|
+ if(!$order) return $this->error(['msg' => '找不到订单']);
|
|
|
|
+ $user = Auth::guard('mini')->user();
|
|
|
|
+ $project_role_id = $request->input('is_draft') == 1 ? ProjectRole::getByKey('work', 'id') : ProjectRole::getByKey('machine', 'id');
|
|
|
|
+ $type = $request->input('type');
|
|
|
|
+ $option = Option::get('orders', 'status', 'checking');
|
|
|
|
+ if($type == 'back') {
|
|
|
|
+ $option = Option::get('orders', 'status', 'back');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $res = $order->update([
|
|
|
|
+ 'work_point_id' => $request->input('work_point_id'),
|
|
|
|
+ 'remark' => $request->input('remark'),
|
|
|
|
+ 'is_draft' => $request->input('is_draft'),
|
|
|
|
+ 'status' => $option,
|
|
|
|
+ 'user_id' => $user->id,
|
|
|
|
+ 'project_role_id' => $project_role_id
|
|
|
|
+ ]);
|
|
|
|
+ if(!$res) return $this->error(['msg' => '订单修改失败']);
|
|
|
|
+ $devices = $request->input('devices');
|
|
|
|
+ if($type == 'back') {
|
|
|
|
+ foreach($devices as $device) {
|
|
|
|
+ if($device['id']) {
|
|
|
|
+ InnerDevice::find($device['id'])->update([
|
|
|
|
+ 'project_id' => '',
|
|
|
|
+ 'start_date' => '',
|
|
|
|
+ 'end_date' => '',
|
|
|
|
+ 'work_point_id' => '',
|
|
|
|
+ 'status' => Option::get('inner_devices', 'status', 'free')
|
|
|
|
+ ]);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ OrderDevice::where('order_id', '=', $order->id)->delete();
|
|
|
|
+ foreach($devices as $device) {
|
|
|
|
+ OrderDevice::create([
|
|
|
|
+ 'name' => $device['name'],
|
|
|
|
+ 'order_id' => $order->id,
|
|
|
|
+ 'device_id' => $device['id'],
|
|
|
|
+ 'start_date' => $device['start_date'],
|
|
|
|
+ 'end_date' => $device['end_date']
|
|
|
|
+ ]);
|
|
|
|
+ if($device['id']) {
|
|
|
|
+ InnerDevice::find($device['id'])->update([
|
|
|
|
+ 'start_date' => $device['start_date'],
|
|
|
|
+ 'end_date' => $device['end_date'],
|
|
|
|
+ 'work_point_id' => $request->input('work_point_id')
|
|
|
|
+ ]);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return $this->success();
|
|
|
|
+ }
|
|
|
|
+
|
|
public function get(Request $request)
|
|
public function get(Request $request)
|
|
{
|
|
{
|
|
- $items = $this->model->where('project_id', $request->input('project_id'))->where('is_draft', 2);
|
|
|
|
|
|
+ $items = $this->model->join('users', 'orders.user_id', '=', 'users.id')->select('orders.*', 'users.id as user_id', 'users.name');
|
|
|
|
+ $search_items = [
|
|
|
|
+ ['project_id', $request->input('project_id')],
|
|
|
|
+ ['is_draft', 2]
|
|
|
|
+ ];
|
|
if($request->input('status')) {
|
|
if($request->input('status')) {
|
|
$status = Option::get('orders', 'status', $request->input('status'));
|
|
$status = Option::get('orders', 'status', $request->input('status'));
|
|
- if($status) $items = $items->where('status', $status);
|
|
|
|
|
|
+ if($status) {
|
|
|
|
+ array_push($search_items, ['status', '=', $status]);
|
|
|
|
+ };
|
|
}
|
|
}
|
|
- $equal_items = ['work_point_id'];
|
|
|
|
|
|
+ $equal_items = ['work_point_id', 'type'];
|
|
foreach ($equal_items as $item) {
|
|
foreach ($equal_items as $item) {
|
|
if($request->input($item)) {
|
|
if($request->input($item)) {
|
|
- $items = $items->where($item, '=', $request->input($item));
|
|
|
|
|
|
+ array_push($search_items, [$item, '=', $request->input($item)]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- $items = $items->orderBy('created_at', 'desc');
|
|
|
|
|
|
+ $items = $items->where($search_items);
|
|
|
|
+ if($request->input('keyword')) {
|
|
|
|
+ $keyword = '%' . $request->input('keyword') . '%';
|
|
|
|
+ $items = $items->where(function ($query) use($keyword) {
|
|
|
|
+ $query->where('order_number', 'like', $keyword)->orWhere('users.name', 'like', $keyword);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ $items = $items->orderBy('updated_at', 'desc');
|
|
$items = $items->paginate();
|
|
$items = $items->paginate();
|
|
|
|
+ $type = $request->input('type');
|
|
|
|
+ $type = $type ? $type : 0;
|
|
foreach($items as $item) {
|
|
foreach($items as $item) {
|
|
- $item->devices = OrderDevice::where('order_id', $item->id)->get();
|
|
|
|
- foreach($item->devices as $device) {
|
|
|
|
- $device->type = $device->device ? $device->device->name : '';
|
|
|
|
|
|
+ if($type == 1) {
|
|
|
|
+ $item->devices = OrderDevice::where('order_id', $item->id)->get();
|
|
|
|
+ foreach($item->devices as $device) {
|
|
|
|
+ $device->device = Device::find($device->device_id);
|
|
|
|
+ $device->device_name = DeviceName::find($device->device_name_id);
|
|
|
|
+ $device->spec = Spec::find($device->spec_id);
|
|
|
|
+ $device->rent_type = RentType::find($device->rent_type_id);
|
|
|
|
+ }
|
|
|
|
+ } else if($type == 2) {
|
|
|
|
+ $item->devices = $item->innerDevices;
|
|
}
|
|
}
|
|
$item->user_name = $item->user ? $item->user->name : '';
|
|
$item->user_name = $item->user ? $item->user->name : '';
|
|
$this->formatOrder($item);
|
|
$this->formatOrder($item);
|
|
@@ -190,9 +308,14 @@ class OrderController extends BaseController
|
|
|
|
|
|
public function detail(Request $request)
|
|
public function detail(Request $request)
|
|
{
|
|
{
|
|
- $order = $this->model->with('project', 'workPoint', 'devices', 'user')->find($request->input('id'));
|
|
|
|
|
|
+ $order = $this->model->with('project', 'workPoint', 'devices', 'user', 'innerDevices')->find($request->input('id'));
|
|
if(!$order) return $this->error(['msg' => '找不到订单']);
|
|
if(!$order) return $this->error(['msg' => '找不到订单']);
|
|
$this->formatOrder($order);
|
|
$this->formatOrder($order);
|
|
|
|
+ foreach($order['innerDevices'] as $device) {
|
|
|
|
+ $device->status = Option::find($device->status);
|
|
|
|
+ $device->spec = Spec::find($device->spec);
|
|
|
|
+ $device->work_point = WorkPoint::find($device->work_point_id);
|
|
|
|
+ }
|
|
return $this->success(['data' => $order]);
|
|
return $this->success(['data' => $order]);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -222,20 +345,24 @@ class OrderController extends BaseController
|
|
if(!$project_role) return $this->error(['msg' => '找不到角色']);
|
|
if(!$project_role) return $this->error(['msg' => '找不到角色']);
|
|
$status = Option::get('orders', 'status', $request->input('type'));
|
|
$status = Option::get('orders', 'status', $request->input('type'));
|
|
|
|
|
|
- // 工区负责人确认通过
|
|
|
|
|
|
+ $is_inner = $order->type == 2;
|
|
|
|
+ // 工区负责人或机电负责人确认通过
|
|
if($request->input('type') == 'confirm') {
|
|
if($request->input('type') == 'confirm') {
|
|
$status = Option::get('orders', 'status', 'pass');
|
|
$status = Option::get('orders', 'status', 'pass');
|
|
$next_project_role_id = $project_role->id;
|
|
$next_project_role_id = $project_role->id;
|
|
} else if($request->input('type') == 're-submit') {
|
|
} else if($request->input('type') == 're-submit') {
|
|
$status = Option::get('orders', 'status', 'checking');
|
|
$status = Option::get('orders', 'status', 'checking');
|
|
- $next_project_role_id = $project_role->getNext('id');
|
|
|
|
- } else {
|
|
|
|
- if($request->input('type') == 'reject' || $project_role->key == 'manager') {
|
|
|
|
- $next_project_role_id = ProjectRole::getByKey('work', 'id');
|
|
|
|
|
|
+ $next_project_role_id = $project_role->getNext('id', $is_inner);
|
|
|
|
+ } else if($request->input('type') == 'reject') {
|
|
|
|
+ if($is_inner) {
|
|
|
|
+ $next_project_role_id = ProjectRole::getByKey('machine', 'id');
|
|
} else {
|
|
} else {
|
|
- $next_project_role_id = $project_role->getNext('id');
|
|
|
|
|
|
+ $next_project_role_id = ProjectRole::getByKey('work', 'id');
|
|
}
|
|
}
|
|
|
|
+ } else {
|
|
|
|
+ $next_project_role_id = $project_role->getNext('id', $is_inner);
|
|
}
|
|
}
|
|
|
|
+
|
|
$res = $order->update([
|
|
$res = $order->update([
|
|
'status' => $status,
|
|
'status' => $status,
|
|
'last_project_role_id' => $project_role->id,
|
|
'last_project_role_id' => $project_role->id,
|