|
@@ -8,6 +8,9 @@ use App\Model\Box;
|
|
|
use App\Model\DispatchSub;
|
|
|
use App\Model\Employee;
|
|
|
use App\Model\InOutRecord;
|
|
|
+use App\Model\Process;
|
|
|
+use App\Model\ReportWorking;
|
|
|
+use App\Model\ReportWorkingDetail;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
class ApplyOrderService extends Service
|
|
@@ -474,4 +477,247 @@ class ApplyOrderService extends Service
|
|
|
|
|
|
return [true, ''];
|
|
|
}
|
|
|
+
|
|
|
+ //报工
|
|
|
+ public function reportWorkingEdit($data, $user){
|
|
|
+ list($status,$msg) = $this->MaterialRule($data,false);
|
|
|
+ if(!$status) return [$status,$msg];
|
|
|
+
|
|
|
+ DB::beginTransaction();
|
|
|
+ try{
|
|
|
+ $time = time();
|
|
|
+ $model = new ReportWorking();
|
|
|
+ $model = $model->where('id',$data['id'])->first();
|
|
|
+ $model->report_time = $data['report_time'];
|
|
|
+ $model->mark = $data['mark']?? "";
|
|
|
+ $model->save();
|
|
|
+ $id = $model->id;
|
|
|
+
|
|
|
+ ReportWorkingDetail::where('del_time',0)->where('report_working_id',$id)->update([
|
|
|
+ 'del_time' => $time
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $detail_insert = [];
|
|
|
+ foreach ($data['order_data'] as $v){
|
|
|
+ $detail_insert[] = [
|
|
|
+ 'report_working_id' => $id,
|
|
|
+ 'data_id' => $v['id'],
|
|
|
+ 'quantity' => $v['quantity'] ?? 0,
|
|
|
+ 'process_id' => $v['process_id'] ?? 0,
|
|
|
+ 'finished_id' => $v['finished_id'] ?? 0,
|
|
|
+ 'crt_time' => $time,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ ReportWorkingDetail::insert($detail_insert);
|
|
|
+
|
|
|
+ DB::commit();
|
|
|
+ }catch (\Exception $e){
|
|
|
+ DB::rollBack();
|
|
|
+ return [false,$e->getMessage()];
|
|
|
+ }
|
|
|
+ return [true,''];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function reportWorkingAdd($data,$user){
|
|
|
+ list($status,$msg) = $this->reportWorkingRule($data);
|
|
|
+ if(!$status) return [$status,$msg];
|
|
|
+
|
|
|
+ DB::beginTransaction();
|
|
|
+ try{
|
|
|
+ $time = time();
|
|
|
+ $model = new ReportWorking();
|
|
|
+ $model->order_number = $data['order_number'];
|
|
|
+ $model->report_time = $data['report_time'];
|
|
|
+ $model->mark = $data['mark']?? "";
|
|
|
+ $model->crt_id = $user['id'];
|
|
|
+ $model->save();
|
|
|
+ $id = $model->id;
|
|
|
+
|
|
|
+ $detail_insert = [];
|
|
|
+ foreach ($data['order_data'] as $v){
|
|
|
+ $detail_insert[] = [
|
|
|
+ 'report_working_id' => $id,
|
|
|
+ 'data_id' => $v['id'],
|
|
|
+ 'quantity' => $v['quantity'] ?? 0,
|
|
|
+ 'process_id' => $v['process_id'] ?? 0,
|
|
|
+ 'finished_id' => $v['finished_id'] ?? 0,
|
|
|
+ 'crt_time' => $time,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ ReportWorkingDetail::insert($detail_insert);
|
|
|
+
|
|
|
+ DB::commit();
|
|
|
+ }catch (\Exception $e){
|
|
|
+ DB::rollBack();
|
|
|
+ return [false,$e->getMessage()];
|
|
|
+ }
|
|
|
+
|
|
|
+ return [true, ''];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function reportWorkingDel($data){
|
|
|
+ if($this->isEmpty($data,'id')) return [false,'ID必须!'];
|
|
|
+
|
|
|
+ $apply = ReportWorking::where('id',$data['id'])->first();
|
|
|
+ if($apply->del_time > 0) return [false,'报工单不存在或已被删除'];
|
|
|
+ if($apply->state != ReportWorking::state_zero) return [false, '报工单已审核,删除失败'];
|
|
|
+
|
|
|
+ $time = time();
|
|
|
+ try {
|
|
|
+ DB::beginTransaction();
|
|
|
+
|
|
|
+ $apply->del_time = $time;
|
|
|
+ $apply->save();
|
|
|
+
|
|
|
+ ReportWorkingDetail::where('del_time', 0)->where('report_working_id',$data['id'])->update([
|
|
|
+ 'del_time'=>time()
|
|
|
+ ]);
|
|
|
+
|
|
|
+ DB::commit();
|
|
|
+ }catch (\Throwable $exception){
|
|
|
+ DB::rollBack();
|
|
|
+ return [false, $exception->getMessage()];
|
|
|
+ }
|
|
|
+
|
|
|
+ return [true,''];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function reportWorkingList($data){
|
|
|
+ $model = ReportWorking::where('del_time',0)
|
|
|
+ ->select('*')
|
|
|
+ ->orderBy('id','desc');
|
|
|
+
|
|
|
+ if(isset($data['status'])) $model->where('status', $data['status']);
|
|
|
+ if(! empty($data['order_number'])) $model->where('order_number', 'LIKE', '%'.$data['order_number'].'%');
|
|
|
+ if(! empty($data['crt_id'])) $model->where('crt_id', $data['crt_id']);
|
|
|
+ if(! empty($data['report_time'][0]) && ! empty($data['report_time'][1])) $model->whereBetween('report_time',[$data['report_time'][0],$data['report_time'][1]]);
|
|
|
+ if(! empty($data['crt_time'][0]) && ! empty($data['crt_time'][1])) $model->whereBetween('crt_time',[$data['crt_time'][0],$data['crt_time'][1]]);
|
|
|
+
|
|
|
+ $list = $this->limit($model,'',$data);
|
|
|
+ $list = $this->reportWorkingfillData($list);
|
|
|
+
|
|
|
+ return [true,$list];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function reportWorkingfillData($data){
|
|
|
+ if(empty($data['data'])) return $data;
|
|
|
+
|
|
|
+ $emp = Employee::whereIn('id',array_unique(array_column($data['data'],'crt_id')))
|
|
|
+ ->pluck('emp_name','id')
|
|
|
+ ->toArray();
|
|
|
+
|
|
|
+ foreach ($data['data'] as $key => $value){
|
|
|
+ $data['data'][$key]['report_time'] = $value['report_time'] ? date('Y-m-d H:i:s',$value['report_time']) : '';
|
|
|
+ $data['data'][$key]['crt_time'] = $value['crt_time'] ? date('Y-m-d H:i:s',$value['crt_time']) : '';
|
|
|
+ $data['data'][$key]['status_title'] = ReportWorking::$state_name[$value['status']] ?? "";
|
|
|
+ $data['data'][$key]['crt_name'] = $emp[$value['crt_id']] ?? '';
|
|
|
+ }
|
|
|
+
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function reportWorkingDetail($data){
|
|
|
+ if($this->isEmpty($data,'id')) return [false,'ID不能为空!'];
|
|
|
+ $id = $data['id'];
|
|
|
+ $detail = ReportWorking::where('del_time',0)
|
|
|
+ ->where('id',$id)
|
|
|
+ ->first();
|
|
|
+ if(empty($detail)) return [false,'报工单不存在或已被删除'];
|
|
|
+ $detail = $detail->toArray();
|
|
|
+ $apply_d = ReportWorkingDetail::where('del_time', 0)
|
|
|
+ ->where('report_working_id', $id)
|
|
|
+ ->get()->toArray();
|
|
|
+ $apply_id = array_column($apply_d, 'data_id');
|
|
|
+
|
|
|
+ //派工单
|
|
|
+ $d = DispatchSub::where('del_time',0)
|
|
|
+ ->whereIn('id', $apply_id)
|
|
|
+ ->select('id', 'dispatch_no as order_no', 'product_title','technology_material','wood_name','product_no','process_id','product_unit','price')
|
|
|
+ ->get()->toArray();
|
|
|
+ $d_tmp = array_column($d,null,'id');
|
|
|
+
|
|
|
+ $process_map = Process::whereIn('id',array_unique(array_column($d,'process_id')))
|
|
|
+ ->pluck('title','id')
|
|
|
+ ->toArray();
|
|
|
+ $return = [];
|
|
|
+ foreach ($apply_d as $t){
|
|
|
+ $tmp = $d_tmp[$t['data_id']] ?? [];
|
|
|
+
|
|
|
+ $return[] = [
|
|
|
+ 'id' => $t['data_id'] ?? 0,
|
|
|
+ 'quantity' => $t['quantity'] ?? 0,
|
|
|
+ 'product_no' => $tmp['product_no'] ?? "",
|
|
|
+ 'product_title' => $tmp['product_title'] ?? "",
|
|
|
+ 'product_size' => $tmp['product_size'] ?? "",
|
|
|
+ 'product_unit' => $tmp['product_unit'] ?? "",
|
|
|
+ 'technology_material' => $tmp['technology_material'] ?? "",
|
|
|
+ 'wood_name' => $tmp['wood_name'] ?? "",
|
|
|
+ 'order_no' => $tmp['order_no'] ?? "",
|
|
|
+ 'process_id' => $tmp['process_id'] ?? 0,
|
|
|
+ 'process_title' => $process_map[$tmp['process_id']] ?? "",
|
|
|
+ 'price' => $tmp['price'] ?? 0,
|
|
|
+ 'total' => bcmul(($tmp['price'] ?? 0),$t['quantity'],2)
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ $detail['order_data'] = $return;
|
|
|
+
|
|
|
+ return [true, $detail];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function reportWorkingRule(&$data,$is_add = true){
|
|
|
+ if($this->isEmpty($data,'apply_id')) return [false,'申请人不能为空'];
|
|
|
+ if($this->isEmpty($data,'report_time')) return [false,'报工时间不能为空'];
|
|
|
+ if(empty($data['order_data'])) return [false, '报工单详细信息不能为空'];
|
|
|
+ foreach ($data['order_data'] as $value){
|
|
|
+ if(empty($value['id'])) return [false, '报工单详细信息ID不能为空'];
|
|
|
+ if(empty($value['quantity'])) return [false, '报工单详细信息数量不能为空'];
|
|
|
+ if(empty($value['process_id'])) return [false, '报工单详细信息工序不能为空'];
|
|
|
+ }
|
|
|
+
|
|
|
+ $id = array_unique(array_column($data['order_data'],'id'));
|
|
|
+ $dispatch = DispatchSub::where('del_time',0)
|
|
|
+ ->whereIn('id', $id)
|
|
|
+ ->select('id', 'dispatch_no', 'status')
|
|
|
+ ->get()->toArray();
|
|
|
+ if(count($dispatch) != count($id)) return [false, '派工单信息错误,请重新选择'];
|
|
|
+
|
|
|
+ if($is_add){
|
|
|
+ $data['order_number'] = $this->setOrderNO2();
|
|
|
+ if(empty($data['order_number'])) return [false, '报工单唯一标识生成失败'];
|
|
|
+ }else{
|
|
|
+ if(empty($data['id'])) return [false, '报工单唯一标识不能为空'];
|
|
|
+ if(empty($data['order_number'])) return [false, '报工单唯一标识不能为空'];
|
|
|
+ $apply = ReportWorking::where('id', $data['id'])->where('del_time', 0)->first();
|
|
|
+ if(empty($apply)) return [false, '报工单不存在或已被删除'];
|
|
|
+ if($apply->status != 0) return [false, '报工单已审核,编辑失败'];
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return [true,''];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function setOrderNO2(){
|
|
|
+ $str = date('Ymd',time());
|
|
|
+
|
|
|
+ $model = new ReportWorking();
|
|
|
+ $order_number = $model->where('order_number','Like','%'. $str . '%')
|
|
|
+ ->max('order_number');
|
|
|
+
|
|
|
+ if(empty($order_number)){
|
|
|
+ $number = str_pad(1,3,'0',STR_PAD_LEFT);
|
|
|
+ $number = $str . $number;
|
|
|
+ }else{
|
|
|
+ $tmp = substr($order_number, -3);
|
|
|
+ $tmp = $tmp + 1;
|
|
|
+
|
|
|
+ //超过999
|
|
|
+ if(strlen($tmp) > 3) return '';
|
|
|
+
|
|
|
+ $number = str_pad($tmp,3,'0',STR_PAD_LEFT);
|
|
|
+ $number = $str . $number;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $number;
|
|
|
+ }
|
|
|
}
|