$order_number]]; } public function customerEdit($data,$user){ list($status,$msg) = $this->customerRule($data,$user, false); if(!$status) return [$status,$msg]; try { DB::beginTransaction(); $model = PaymentReceipt::where('id',$data['id'])->first(); $model->data_order_no = $data['data_order_no']; $model->data_type = $data['data_type']; $model->type = $data['type']; $model->amount = $data['amount'] ?? 0; $model->mark = $data['mark'] ?? ''; $model->save(); $time = time(); PaymentReceiptInfo::where('del_time',0) ->where('payment_receipt_id',$data['id']) ->update(['del_time' => $time]); if(! empty($data['file'])){ $insert = []; foreach ($data['file'] as $value){ $insert[] = [ 'payment_receipt_id' => $model->id, 'file' => $value['url'], 'type' => PaymentReceiptInfo::type_one, 'name' => $value['name'], 'crt_time' => $time, ]; } PaymentReceiptInfo::insert($insert); } if(! empty($data['employee_one'])){ $insert = []; foreach ($data['employee_one'] as $value){ $insert[] = [ 'payment_receipt_id' => $model->id, 'data_id' => $value, 'type' => PaymentReceiptInfo::type_two, 'crt_time' => $time, ]; } PaymentReceiptInfo::insert($insert); } DB::commit(); }catch (\Exception $exception){ DB::rollBack(); return [false,$exception->getMessage()]; } return [true,'']; } public function customerAdd($data,$user){ list($status,$msg) = $this->customerRule($data,$user); if(!$status) return [$status,$msg]; try { DB::beginTransaction(); $model = new PaymentReceipt(); $model->order_number = $data['order_number']; $model->data_order_no = $data['data_order_no']; $model->data_type = $data['data_type']; $model->type = $data['type']; $model->amount = $data['amount'] ?? 0; $model->mark = $data['mark'] ?? ''; $model->crt_id = $user['id']; $model->depart_id = $data['depart_id']; $model->top_depart_id = $data['top_depart_id']; $model->save(); $time = time(); if(! empty($data['file'])){ $insert = []; foreach ($data['file'] as $value){ $insert[] = [ 'payment_receipt_id' => $model->id, 'file' => $value['url'], 'type' => PaymentReceiptInfo::type_one, 'name' => $value['name'], 'crt_time' => $time, ]; } PaymentReceiptInfo::insert($insert); } if(! empty($data['employee_one'])){ $insert = []; foreach ($data['employee_one'] as $value){ $insert[] = [ 'payment_receipt_id' => $model->id, 'data_id' => $value, 'type' => PaymentReceiptInfo::type_two, 'crt_time' => $time, ]; } PaymentReceiptInfo::insert($insert); } DB::commit(); }catch (\Exception $exception){ DB::rollBack(); return [false,$exception->getMessage()]; } return [true,'']; } public function customerDel($data){ if($this->isEmpty($data,'id')) return [false,'请选择数据!']; $booking = PaymentReceipt::where('del_time',0)->where('id',$data['id'])->first(); if(empty($booking)) return [false,'收付款单不存在或已被删除']; $booking = $booking->toArray(); if($booking['state'] != PaymentReceipt::STATE_ZERO) return [false,'请确认收付款单状态,删除失败']; try { DB::beginTransaction(); $time = time(); PaymentReceipt::where('id',$data['id'])->update([ 'del_time'=> $time ]); PaymentReceiptInfo::where('del_time',0) ->where('payment_receipt_id',$data['id']) ->update(['del_time' => $time]); DB::commit(); }catch (\Exception $exception){ DB::rollBack(); return [false,$exception->getMessage()]; } return [true,'']; } public function customerDetail($data){ if($this->isEmpty($data,'id')) return [false,'请选择数据!']; $customer = PaymentReceipt::where('del_time',0) ->where('id',$data['id']) ->first(); if(empty($customer)) return [false,'记录不存在或已被删除']; $customer = $customer->toArray(); $customer['state_title'] = PaymentReceipt::$name[$customer['state']] ?? ""; $customer['type_title'] = PaymentReceipt::$model_type[$customer['type']] ?? ""; $customer['crt_name'] = Employee::where('id',$customer['crt_id'])->value('emp_name'); $customer['crt_time'] = $customer['crt_time'] ? date("Y-m-d H:i:s",$customer['crt_time']): ''; $file = PaymentReceiptInfo::where('del_time',0) ->where('payment_receipt_id',$data['id']) ->get()->toArray(); $emp_id = []; foreach ($file as $value){ if(in_array($value['type'],PaymentReceiptInfo::$man)){ $emp_id[] = $value['data_id']; } } $emp_map = Employee::whereIn('id',array_unique($emp_id)) ->where('del_time',0) ->pluck('emp_name','id') ->toArray(); $customer['file'] = $customer['employee_one'] = []; foreach ($file as $value){ if($value['type'] == PaymentReceiptInfo::type_one){ $tmp = [ 'url' => $value['file'], 'name' => $value['name'], ]; $customer['file'][] = $tmp; }elseif (in_array($value['type'],PaymentReceiptInfo::$man)){ $tt = $emp_map[$value['data_id']] ?? ''; if(! empty($tt)){ $tmp = [ 'id' => $value['data_id'], 'name' => $emp_map[$value['data_id']] ?? '', ]; if($value['type'] == PaymentReceiptInfo::type_two){ $customer['employee_one'][] = $tmp; } } } } return [true, $customer]; } public function customerList($data,$user){ $model = PaymentReceipt::Clear($user,$data); $model = $model->where('del_time',0) ->select('type','id','data_type','order_number','data_order_no','amount','account','pay_way','crt_id','crt_time','mark','state') ->orderby('id', 'desc'); if(isset($data['state'])) $model->where('state', $data['state']); if(! empty($data['data_order_no'])) $model->where('data_order_no', 'LIKE', '%'.$data['data_order_no'].'%'); if(! empty($data['order_number'])) $model->where('order_number', 'LIKE', '%'.$data['order_number'].'%'); if(! empty($data['data_type'])) $model->where('data_type', $data['data_type']); if(! empty($data['type'])) $model->where('type', $data['type']); if(! empty($data['account'])) $model->where('account',$data['account']); if(! empty($data['pay_way'])) $model->where('pay_way',$data['pay_way']); if(! empty($data['mark'])) $model->where('mark', 'LIKE', '%'.$data['mark'].'%'); if(! empty($data['crt_time'][0]) && ! empty($data['crt_time'][1])) { $return = $this->changeDateToTimeStampAboutRange($data['crt_time']); $model->where('crt_time','>=',$return[0]); $model->where('crt_time','<=',$return[1]); } if(! empty($data['belong'])){ $id = (new RangeService())->paymentReceiptSearch($data); $model->whereIn('id',$id); } $list = $this->limit($model,'',$data); $list = $this->fillData($list); return [true, $list]; } public function customerRule(&$data, $user, $is_add = true){ if(empty($data['order_number'])) return [false,'收付款单编号不能为空']; if(empty($data['data_order_no'])) return [false,'关联单号不能为空']; if(empty($data['data_type'])) return [false,'单号类型不能为空']; if(empty($data['type'])) return [false,'金额类型不能为空']; if(empty($data['amount'])) return [false,'金额不能为空']; $res = $this->checkNumber($data['amount']); if(! $res) return [false, '金额请输入不超过两位小数并且大于0的数值']; //所属部门 以及 顶级部门 if(empty($data['depart_id'])) { $data['depart_id'] = $this->getDepart($user); $data['top_depart_id'] = $user['depart_map'][$data['depart_id']] ?? 0; } if($is_add){ $bool = PaymentReceipt::where('del_time',0) ->where('order_number',$data['order_number']) ->exists(); if($bool) return [false,'收付款单编号已存在,请重新获取']; }else{ if(empty($data['id'])) return [false,'ID不能为空']; $booking = PaymentReceipt::where('del_time',0)->where('id',$data['id'])->first(); if(empty($booking)) return [false,'收付款单不存在或已被删除']; $booking = $booking->toArray(); if($booking['state'] != PaymentReceipt::STATE_ZERO) return [false,'请确认收付款单状态,编辑失败']; } return [true, '']; } public function fillData($data){ if(empty($data['data'])) return $data; $emp = Employee::whereIn('id',array_unique(array_column($data['data'],'crt_id'))) ->pluck('emp_name','id') ->toArray(); $array = array_unique(array_merge_recursive(array_column($data['data'],'account'),array_column($data['data'],'pay_way'))); $basic_map = BasicType::whereIn('id',$array) ->pluck('title','id') ->toArray(); foreach ($data['data'] as $key => $value){ $data['data'][$key]['crt_time'] = $value['crt_time'] ? date('Y-m-d H:i:s',$value['crt_time']) : ''; $data['data'][$key]['crt_name'] = $emp[$value['crt_id']] ?? ''; $data['data'][$key]['state_title'] = PaymentReceipt::$name[$value['state']] ?? ''; $data['data'][$key]['type_title'] = PaymentReceipt::$model_type[$value['type']] ?? ''; $data['data'][$key]['data_type_title'] = PaymentReceipt::$data_type[$value['data_type']] ?? ''; $data['data'][$key]['account_title'] = $basic_map[$value['account']] ?? ''; $data['data'][$key]['pay_way_title'] = $basic_map[$value['pay_way']] ?? ''; } return $data; } }