|
@@ -0,0 +1,177 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace App\Service;
|
|
|
+
|
|
|
+use App\Model\Employee;
|
|
|
+use App\Model\GiveOut;
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 发放
|
|
|
+ */
|
|
|
+class GiveOutService extends Service
|
|
|
+{
|
|
|
+ public function giveOutEdit($data,$user){
|
|
|
+ list($status,$msg) = $this->giveOutRule($data, $user, false);
|
|
|
+ if(!$status) return [$status,$msg];
|
|
|
+
|
|
|
+ try {
|
|
|
+ DB::beginTransaction();
|
|
|
+
|
|
|
+ $model = GiveOut::where('id',$data['id'])->first();
|
|
|
+ $model->give_out_amount = $data['give_out_amount'] ?? 0;
|
|
|
+ $model->employee_id_1 = $data['employee_id_1'] ?? 0;
|
|
|
+ $model->employee_id_1_title = $data['employee_id_1_title'] ?? "";
|
|
|
+ $model->send_time = $data['send_time'] ?? 0;
|
|
|
+ $model->start_time = $data['start_time'] ?? 0;
|
|
|
+ $model->end_time = $data['end_time'] ?? 0;
|
|
|
+ $model->save();
|
|
|
+
|
|
|
+ DB::commit();
|
|
|
+ }catch (\Exception $exception){
|
|
|
+ DB::rollBack();
|
|
|
+ return [false,$exception->getMessage()];
|
|
|
+ }
|
|
|
+
|
|
|
+ return [true, ''];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function giveOutAdd($data,$user){
|
|
|
+ list($status,$msg) = $this->giveOutRule($data, $user);
|
|
|
+ if(!$status) return [$status,$msg];
|
|
|
+
|
|
|
+ try {
|
|
|
+ DB::beginTransaction();
|
|
|
+
|
|
|
+ $model = new GiveOut();
|
|
|
+ $model->give_out_amount = $data['give_out_amount'] ?? 0;
|
|
|
+ $model->employee_id_1 = $data['employee_id_1'] ?? 0;
|
|
|
+ $model->employee_id_1_title = $data['employee_id_1_title'] ?? "";
|
|
|
+ $model->send_time = $data['send_time'] ?? 0;
|
|
|
+ $model->start_time = $data['start_time'] ?? 0;
|
|
|
+ $model->end_time = $data['end_time'] ?? 0;
|
|
|
+ $model->crt_id = $user['id'];
|
|
|
+ $model->save();
|
|
|
+
|
|
|
+ DB::commit();
|
|
|
+ }catch (\Exception $exception){
|
|
|
+ DB::rollBack();
|
|
|
+ return [false,$exception->getMessage()];
|
|
|
+ }
|
|
|
+
|
|
|
+ return [true, ''];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function giveOutDel($data){
|
|
|
+ if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
|
|
|
+
|
|
|
+ try {
|
|
|
+ DB::beginTransaction();
|
|
|
+ $time = time();
|
|
|
+
|
|
|
+ GiveOut::where('del_time',0)
|
|
|
+ ->whereIn('id',$data['id'])
|
|
|
+ ->update(['del_time' => $time]);
|
|
|
+
|
|
|
+ DB::commit();
|
|
|
+ }catch (\Exception $exception){
|
|
|
+ DB::rollBack();
|
|
|
+ return [false,$exception->getMessage()];
|
|
|
+ }
|
|
|
+
|
|
|
+ return [true, ''];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function giveOutDetail($data,$user){
|
|
|
+ if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
|
|
|
+ $customer = GiveOut::where('del_time',0)
|
|
|
+ ->where('id',$data['id'])
|
|
|
+ ->first();
|
|
|
+ if(empty($customer)) return [false,'发放记录不存在或已被删除'];
|
|
|
+ $customer = $customer->toArray();
|
|
|
+
|
|
|
+ $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']): '';
|
|
|
+
|
|
|
+ return [true, $customer];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function giveOutCommon($data,$user, $field = []){
|
|
|
+ if(empty($field)) $field = GiveOut::$field;
|
|
|
+
|
|
|
+ $model = GiveOut::where('del_time',0)
|
|
|
+ ->select($field)
|
|
|
+ ->orderby('id', 'desc');
|
|
|
+
|
|
|
+ if(! empty($data['employee_id_1_title'])) $model->where('employee_id_1_title', 'LIKE', '%'.$data['employee_id_1_title'].'%');
|
|
|
+ if(! empty($data['send_time'][0]) && ! empty($data['send_time'][1])) {
|
|
|
+ $return = $this->changeDateToTimeStampAboutRange($data['send_time']);
|
|
|
+ $model->where('send_time','>=',$return[0]);
|
|
|
+ $model->where('send_time','<=',$return[1]);
|
|
|
+ }
|
|
|
+ if(! empty($data['belong_time'][0]) && ! empty($data['belong_time'][1])) {
|
|
|
+ $return = $this->changeDateToTimeStampAboutRange($data['belong_time']);
|
|
|
+ $model->where('start_time','>=',$return[0]);
|
|
|
+ $model->where('end_time','<=',$return[1]);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $model;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function giveOutList($data,$user){
|
|
|
+ $model = $this->giveOutCommon($data, $user);
|
|
|
+ $list = $this->limit($model,'',$data);
|
|
|
+ $list = $this->fillData($list,$user,$data);
|
|
|
+
|
|
|
+ return [true, $list];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function giveOutRule(&$data, $user, $is_add = true){
|
|
|
+ if(empty($data['give_out_amount'])) return [false, '分红已发金额不能为空'];
|
|
|
+ $res = $this->checkNumber($data['give_out_amount'],2,'positive');
|
|
|
+ if(! $res['valid']) return [false,'分红已发金额:' . $res['error']];
|
|
|
+ if(empty($data['employee_id_1'])) return [false, '业务员不能为空'];
|
|
|
+ $employee = Employee::where('del_time',0)
|
|
|
+ ->where('id',$data['employee_id_1'])
|
|
|
+ ->first();
|
|
|
+ if(empty($employee)) return [false, '业务员不存在或已被删除'];
|
|
|
+ $data['employee_id_1_title'] = $employee->emp_name;
|
|
|
+
|
|
|
+ if(empty($data['send_time'])) return [false, '发放日期不能为空'];
|
|
|
+ $data['send_time'] = $this->changeDateToDate($data['send_time']);
|
|
|
+ if($data['send_time'] == null) return [false, '发放日期错误'];
|
|
|
+
|
|
|
+ if(empty($data['belong_time'])) return [false, '归属日期不能为空'];
|
|
|
+ list($start_time,$end_time) = $this->changeDateToTimeStampAboutRange($data['belong_time'], false);
|
|
|
+ if ($start_time === null || $end_time === null || $start_time > $end_time) return [false, "归属日期的区间无效"];
|
|
|
+ $data['start_time'] = $start_time;
|
|
|
+ $data['end_time'] = $start_time;
|
|
|
+
|
|
|
+ if($is_add){
|
|
|
+
|
|
|
+ }else{
|
|
|
+ if(empty($data['id'])) return [false,'ID不能为空'];
|
|
|
+ $bool = GiveOut::where('id',$data['id'])
|
|
|
+ ->where('del_time',0)
|
|
|
+ ->exists();
|
|
|
+ if(! $bool) return [false,'发放记录不存在或已被删除'];
|
|
|
+ }
|
|
|
+
|
|
|
+ return [true, $data];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function fillData($data, $user, $search){
|
|
|
+ if(empty($data['data'])) return $data;
|
|
|
+
|
|
|
+ foreach ($data['data'] as $key => $value){
|
|
|
+ $data['data'][$key]['send_time'] = $value['send_time'] ? date('Y-m-d',$value['send_time']) : '';
|
|
|
+ $start = $value['start_time'] ? date('Y-m-d',$value['start_time']) : '';
|
|
|
+ $end = $value['end_time'] ? date('Y-m-d',$value['end_time']) : '';
|
|
|
+ $string = "";
|
|
|
+ if(! empty($start) && ! empty($end)) $string = $start . "-" . $end;
|
|
|
+ $data['data'][$key]['belong_time'] = $string;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+}
|