|
|
@@ -17,7 +17,6 @@ class OrganizationService extends Service
|
|
|
DB::beginTransaction();
|
|
|
|
|
|
$model = Organization::where('id',$data['id'])->first();
|
|
|
- $model->code = $data['code'] ?? '';
|
|
|
$model->title = $data['title'] ?? '';
|
|
|
$model->industry_name = $data['industry_name'] ?? "";
|
|
|
$model->industry_ranking = $data['industry_ranking'] ?? "";
|
|
|
@@ -53,7 +52,7 @@ class OrganizationService extends Service
|
|
|
DB::beginTransaction();
|
|
|
|
|
|
$model = new Organization();
|
|
|
- $model->code = $data['code'] ?? '';
|
|
|
+ $model->code = $this->generateCode($user['id']);
|
|
|
$model->title = $data['title'] ?? '';
|
|
|
$model->industry_name = $data['industry_name'] ?? "";
|
|
|
$model->industry_ranking = $data['industry_ranking'] ?? "";
|
|
|
@@ -72,6 +71,9 @@ class OrganizationService extends Service
|
|
|
DB::commit();
|
|
|
}catch (\Exception $exception){
|
|
|
DB::rollBack();
|
|
|
+ if (str_contains($exception->getMessage(), '1062') || str_contains($exception->getMessage(), 'Duplicate entry')) {
|
|
|
+ return [false, '网络波动,请重新操作!'];
|
|
|
+ }
|
|
|
return [false,$exception->getMessage()];
|
|
|
}
|
|
|
|
|
|
@@ -95,14 +97,11 @@ class OrganizationService extends Service
|
|
|
if(! empty($data['receipt_list'])){
|
|
|
$receipt = [];
|
|
|
foreach ($data['receipt_list'] as $value){
|
|
|
- $start_time = strtotime($value['start_time'] . "-01");
|
|
|
- $end_time = strtotime($value['end_time'] . "-01");
|
|
|
if(empty($value['receipt'])) continue;
|
|
|
$receipt[] = [
|
|
|
'organization_id' => $id,
|
|
|
'type' => $value['type'],
|
|
|
- 'start_time' => $start_time,
|
|
|
- 'end_time' => $end_time,
|
|
|
+ 'year' => $value['year'],
|
|
|
'receipt' => $value['receipt'],
|
|
|
'crt_time' => $time,
|
|
|
];
|
|
|
@@ -141,8 +140,7 @@ class OrganizationService extends Service
|
|
|
}elseif(in_array($value['type'], [OrganizationDetails::type_three])){
|
|
|
$receipt[] = [
|
|
|
'type' => $value['type'],
|
|
|
- 'start_time' => date("Y-m", $value['start_time']),
|
|
|
- 'end_time' => date("Y-m", $value['end_time']),
|
|
|
+ 'year' => $value['year'],
|
|
|
'receipt' => $value['receipt'],
|
|
|
];
|
|
|
}else{
|
|
|
@@ -241,7 +239,6 @@ class OrganizationService extends Service
|
|
|
}
|
|
|
|
|
|
public function organizationRule(&$data, $user, $is_add = true){
|
|
|
- if(empty($data['code'])) return [false, '编码不能为空'];
|
|
|
if(empty($data['title'])) return [false, '名称不能为空'];
|
|
|
if(empty($data['type']) || ! isset(Organization::$type_name[$data['type']])) return [false, '组织类型错误'];
|
|
|
if(! empty($data['founding_time'])) $data['founding_time'] = $this->changeDateToDate($data['founding_time']);
|
|
|
@@ -256,10 +253,10 @@ class OrganizationService extends Service
|
|
|
if(! empty($data['receipt_list'])){
|
|
|
foreach ($data['receipt_list'] as $value){
|
|
|
if(empty($value['type'])) return [false, '营收信息类型不能为空'];
|
|
|
- if(empty($value['start_time']) || empty($value['end_time'])) return [false, '营收日期范围不能为空'];
|
|
|
- $start_time = strtotime($value['start_time'] . "-01");
|
|
|
- $end_time = strtotime($value['end_time'] . "-01");
|
|
|
- if(! $start_time || ! $end_time) return [false, '营收日期范围错误'];
|
|
|
+ if(empty($value['year'])) return [false, '营收年份不能为空'];
|
|
|
+// $start_time = strtotime($value['start_time'] . "-01");
|
|
|
+// $end_time = strtotime($value['end_time'] . "-01");
|
|
|
+// if(! $start_time) return [false, '营收日期范围错误'];
|
|
|
if(empty($value['receipt'])) return [false, '营收数据不能为空'];
|
|
|
}
|
|
|
}
|
|
|
@@ -274,19 +271,14 @@ class OrganizationService extends Service
|
|
|
}
|
|
|
|
|
|
if($is_add){
|
|
|
- $bool = Organization::where('code',$data['code'])
|
|
|
- ->where('crt_id', $user['id'])
|
|
|
- ->where('del_time',0)
|
|
|
- ->exists();
|
|
|
+
|
|
|
}else{
|
|
|
if(empty($data['id'])) return [false,'ID不能为空'];
|
|
|
- $bool = Organization::where('code',$data['code'])
|
|
|
- ->where('crt_id', $user['id'])
|
|
|
- ->where('id','<>',$data['id'])
|
|
|
+ $bool = Organization::where('id', $data['id'])
|
|
|
->where('del_time',0)
|
|
|
->exists();
|
|
|
+ if(! $bool) return [false, '组织不存在或已被删除'];
|
|
|
}
|
|
|
- if($bool) return [false, '编码已存在'];
|
|
|
|
|
|
return [true, $data];
|
|
|
}
|
|
|
@@ -304,4 +296,31 @@ class OrganizationService extends Service
|
|
|
|
|
|
return $data;
|
|
|
}
|
|
|
+
|
|
|
+ public function generateCode($crt_id)
|
|
|
+ {
|
|
|
+ return DB::transaction(function () use ($crt_id) {
|
|
|
+
|
|
|
+ // 加行级锁 FOR UPDATE,避免并发重复
|
|
|
+ $maxCode = Organization::where('crt_id', $crt_id)
|
|
|
+ ->lockForUpdate()
|
|
|
+ ->max('code');
|
|
|
+
|
|
|
+ // 转数字
|
|
|
+ $num = intval($maxCode);
|
|
|
+
|
|
|
+ // +1
|
|
|
+ $num++;
|
|
|
+
|
|
|
+ // 小于 10000 → 保留 4 位前导零
|
|
|
+ if ($num < 10000) {
|
|
|
+ $code = str_pad($num, 4, '0', STR_PAD_LEFT);
|
|
|
+ } else {
|
|
|
+ $code = (string)$num; // 大于等于10000则直接用数字
|
|
|
+ }
|
|
|
+
|
|
|
+ return $code;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
}
|