|
|
@@ -3,56 +3,71 @@
|
|
|
namespace App\Services;
|
|
|
|
|
|
use App\DeliveryAppointment;
|
|
|
+use App\DeliveryAppointmentCar;
|
|
|
use App\Traits\ServiceAppAop;
|
|
|
use App\ReceivingTask;
|
|
|
use Illuminate\Support\Carbon;
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
use Ramsey\Uuid\Uuid;
|
|
|
|
|
|
class ReceivingTaskService
|
|
|
{
|
|
|
use ServiceAppAop;
|
|
|
- protected $modelClass=ReceivingTask::class;
|
|
|
+
|
|
|
+ protected $modelClass = ReceivingTask::class;
|
|
|
+
|
|
|
+ private $itemService;
|
|
|
+
|
|
|
+ public function __construct()
|
|
|
+ {
|
|
|
+ $this->itemService =app(ReceivingTaskItemService::class);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
public function endTask($receivingTaskNumber)
|
|
|
{
|
|
|
- ReceivingTask::query()->where('number',$receivingTaskNumber)->update(['status' => '完成']);
|
|
|
+ ReceivingTask::query()->where('number', $receivingTaskNumber)->update(['status' => '完成']);
|
|
|
}
|
|
|
|
|
|
- public function executionTask($receivingTaskNumber){
|
|
|
- ReceivingTask::query()->where('number',$receivingTaskNumber)->update(['status' => '进行中']);
|
|
|
+ public function executionTask($receivingTaskNumber)
|
|
|
+ {
|
|
|
+ ReceivingTask::query()->where('number', $receivingTaskNumber)->update(['status' => '进行中']);
|
|
|
}
|
|
|
|
|
|
- public function createReceivingTask($params,DeliveryAppointment $deliveryAppointment): ReceivingTask
|
|
|
+ public function createReceivingTask(DeliveryAppointmentCar $delivery_appointment_car, $params): ReceivingTask
|
|
|
{
|
|
|
// 生成入库任务号
|
|
|
$task_number = $this->buildTaskNumber();
|
|
|
$params['number'] = $task_number;
|
|
|
- $params['delivery_appointment_id'] = $deliveryAppointment; // 预约号
|
|
|
-
|
|
|
- /** @var ReceivingTask $receivingTask */
|
|
|
- $receivingTask = ReceivingTask::query()->create($params);
|
|
|
-
|
|
|
- $asn_nos = $params['asn_nos'];
|
|
|
-
|
|
|
- $receivingTask->items()->insert( array_map(function($item){
|
|
|
- return ['asn_no' => $item];
|
|
|
- },$asn_nos));
|
|
|
- $this->saveImage($receivingTask,$params['file']);
|
|
|
+ $params['delivery_appointment_car_id'] = $delivery_appointment_car->id; // 预约号
|
|
|
+ $receivingTask = new ReceivingTask($params);
|
|
|
+ DB::transaction(function () use ($delivery_appointment_car, $params, &$receivingTask) {
|
|
|
+ $receivingTask->save();
|
|
|
+ if ($receivingTask->id) {
|
|
|
+ try {
|
|
|
+ $this->itemService->createItems($receivingTask,$params['asn_nos'] ?? []);
|
|
|
+ $this->saveImage($receivingTask, $params['driving_license_image']);
|
|
|
+ DB::commit();
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ DB::rollBack();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
return $receivingTask;
|
|
|
}
|
|
|
|
|
|
- public function saveImage(ReceivingTask $receivingTask,$image): bool
|
|
|
+ public function saveImage(ReceivingTask $receivingTask, $image): bool
|
|
|
{
|
|
|
if (!$this->checkImage($image)) return false;
|
|
|
$tmpFile = $image->getRealPath();
|
|
|
$fileSuffix = $image->getClientOriginalExtension();
|
|
|
$dirPath = $this->getStorageDirPath();
|
|
|
$fileName = date('ymd') . '-' . Uuid::uuid1();
|
|
|
- $pathName = $dirPath . $fileName .'.' . $fileSuffix;
|
|
|
+ $pathName = $dirPath . $fileName . '.' . $fileSuffix;
|
|
|
$result = move_uploaded_file($tmpFile, $pathName);
|
|
|
- if(!$result) return false;
|
|
|
+ if (!$result) return false;
|
|
|
$receivingTask->file()->create(
|
|
|
- [ 'url' => '/files/receivingTask/'.$fileName, 'type' => $fileSuffix,'table_name'=>$receivingTask->getTable()]
|
|
|
+ ['url' => '/files/receivingTask/' . $fileName, 'type' => $fileSuffix, 'table_name' => $receivingTask->getTable()]
|
|
|
);
|
|
|
return true;
|
|
|
}
|
|
|
@@ -63,32 +78,44 @@ class ReceivingTaskService
|
|
|
$fileSuffix = $image->getClientOriginalExtension();
|
|
|
if (!is_uploaded_file($tmpFile)) return false;
|
|
|
if ($image->getSize() > 5 * 1024 * 1024) return false;
|
|
|
- if (!in_array($fileSuffix,[ 'gif','image','jpeg','jpg','png','svg'])) return false;
|
|
|
+ if (!in_array($fileSuffix, ['gif', 'image', 'jpeg', 'jpg', 'png', 'svg'])) return false;
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
|
|
|
public function getStorageDirPath(): string
|
|
|
{
|
|
|
- $path = ['app','public','files','receivingTask'];
|
|
|
- $path = join(DIRECTORY_SEPARATOR,$path);
|
|
|
+ $path = ['app', 'public', 'files', 'receivingTask'];
|
|
|
+ $path = join(DIRECTORY_SEPARATOR, $path);
|
|
|
$dirPath = storage_path($path);
|
|
|
if (!file_exists($dirPath)) {
|
|
|
mkdir($dirPath);
|
|
|
}
|
|
|
- return $dirPath.DIRECTORY_SEPARATOR;
|
|
|
+ return $dirPath . DIRECTORY_SEPARATOR;
|
|
|
}
|
|
|
|
|
|
- public function buildTaskNumber():string
|
|
|
+ public function buildTaskNumber(): string
|
|
|
{
|
|
|
$year_month_day = Carbon::now()->format("Ymd");
|
|
|
$current = Carbon::now()->format("Y-m-d");
|
|
|
$count = ReceivingTask::query()
|
|
|
- ->where('created_at','>=' ,$current.' 00:00:00')
|
|
|
- ->where('created_at','<=' ,$current.' 23.59.59')
|
|
|
+ ->where('created_at', '>=', $current . ' 00:00:00')
|
|
|
+ ->where('created_at', '<=', $current . ' 23.59.59')
|
|
|
->count();
|
|
|
$count++;
|
|
|
- $count = sprintf('%03s', $count);
|
|
|
- return "SH$year_month_day".$count;
|
|
|
+ $count = sprintf('%03s', $count);
|
|
|
+ return "SH$year_month_day" . $count;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 完结昨天未完成的工单
|
|
|
+ */
|
|
|
+ public function endReceivingTask(){
|
|
|
+ $yesterday = Carbon::now()->subDays(1)->format("Y-m-d");
|
|
|
+ ReceivingTask::query()
|
|
|
+ ->where('created_at', '>=', $yesterday . ' 00:00:00')
|
|
|
+ ->where('created_at', '<=', $yesterday . ' 23.59.59')
|
|
|
+ ->update(['status'=>'完成']);
|
|
|
+
|
|
|
}
|
|
|
}
|