QuantizationService.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  1. <?php
  2. namespace App\Service;
  3. use App\Model\CustomerSupply;
  4. use App\Model\Dimension;
  5. use App\Model\Employee;
  6. use App\Model\Quantization;
  7. use App\Model\QuantizationCreate;
  8. use App\Model\QuantizationCreateDetails;
  9. use App\Model\QuantizationDetails;
  10. use Illuminate\Support\Facades\DB;
  11. class QuantizationService extends Service
  12. {
  13. //量化档案-----------------------------------------------
  14. public function quantizationEdit($data,$user){
  15. list($status,$msg) = $this->quantizationRule($data, $user, false);
  16. if(!$status) return [$status,$msg];
  17. try {
  18. DB::beginTransaction();
  19. $model = Quantization::where('id',$data['id'])->first();
  20. $model->title = $data['title'] ?? '';
  21. $model->code = $data['code'] ?? '';
  22. $model->is_use = $data['is_use'] ?? 0;
  23. $model->save();
  24. $time = time();
  25. QuantizationDetails::where('del_time',0)
  26. ->where('quantization_id', $data['id'])
  27. ->update(['del_time' => $time]);
  28. $this->saveDetail($model->id, $time, $data);
  29. DB::commit();
  30. }catch (\Exception $exception){
  31. DB::rollBack();
  32. return [false,$exception->getMessage()];
  33. }
  34. return [true, ''];
  35. }
  36. public function quantizationAdd($data,$user){
  37. list($status,$msg) = $this->quantizationRule($data, $user);
  38. if(!$status) return [$status,$msg];
  39. try {
  40. DB::beginTransaction();
  41. $model = new Quantization();
  42. $model->title = $data['title'] ?? '';
  43. $model->code = $data['code'] ?? '';
  44. $model->is_use = $data['is_use'] ?? 0;
  45. $model->type = $data['type'] ?? 0;
  46. $model->crt_id = $user['id'];
  47. $model->save();
  48. $time = time();
  49. $this->saveDetail($model->id, $time, $data);
  50. DB::commit();
  51. }catch (\Exception $exception){
  52. DB::rollBack();
  53. return [false,$exception->getMessage()];
  54. }
  55. return [true, ''];
  56. }
  57. private function saveDetail($id, $time, $data){
  58. foreach ($data['details'] as $value) {
  59. // 插入父级
  60. $parent = QuantizationDetails::create([
  61. 'quantization_id' => $id,
  62. 'title' => $value['title'],
  63. 'rate' => $value['rate'],
  64. 'parent_id' => 0, // 顶层 parent_id = 0
  65. 'crt_time' => $time,
  66. ]);
  67. // 再处理子级
  68. if (! empty($value['details_son'])) {
  69. foreach ($value['details_son'] as $son) {
  70. $detailsSonData[] = [
  71. 'quantization_id' => $id,
  72. 'title' => $son['title'],
  73. 'parent_id' => $parent->id, // 子级关联父级 id
  74. 'crt_time' => $time,
  75. ];
  76. }
  77. }
  78. }
  79. // 批量插入子级
  80. if (!empty($detailsSonData)) QuantizationDetails::insert($detailsSonData);
  81. }
  82. private function getDetail($id){
  83. // 查所有数据
  84. $all = QuantizationDetails::where('quantization_id', $id)
  85. ->where('del_time', 0)
  86. ->orderBy('id','asc')
  87. ->get()
  88. ->toArray();
  89. // 按 parent_id 分组
  90. $grouped = [];
  91. foreach ($all as $item) {
  92. $grouped[$item['parent_id']][] = $item;
  93. }
  94. $result = [];
  95. // 只取 parent_id = 0 的父级
  96. if (!empty($grouped[0])) {
  97. foreach ($grouped[0] as $parent) {
  98. $parent['details_son'] = $grouped[$parent['id']] ?? (object)[];
  99. $result[] = $parent;
  100. }
  101. }
  102. return $result;
  103. }
  104. public function quantizationDel($data){
  105. if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
  106. try {
  107. DB::beginTransaction();
  108. $time = time();
  109. Quantization::where('del_time',0)
  110. ->whereIn('id',$data['id'])
  111. ->update(['del_time' => $time]);
  112. QuantizationDetails::where('del_time',0)
  113. ->whereIn('quantization_id', $data['id'])
  114. ->update(['del_time' => $time]);
  115. DB::commit();
  116. }catch (\Exception $exception){
  117. DB::rollBack();
  118. return [false,$exception->getMessage()];
  119. }
  120. return [true, ''];
  121. }
  122. public function quantizationDetail($data,$user){
  123. if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
  124. $customer = Quantization::where('del_time',0)
  125. ->where('id',$data['id'])
  126. ->first();
  127. if(empty($customer)) return [false,'量化档案不存在或已被删除'];
  128. $customer = $customer->toArray();
  129. $details = $this->getDetail($customer['id']);
  130. $customer['details'] = $details;
  131. $customer['crt_name'] = Employee::where('id',$customer['crt_id'])->value('emp_name');
  132. $customer['crt_time'] = $customer['crt_time'] ? date("Y-m-d H:i:s",$customer['crt_time']): '';
  133. return [true, $customer];
  134. }
  135. public function quantizationCommon($data,$user, $field = []){
  136. if(empty($field)) $field = Quantization::$field;
  137. $model = Quantization::where('del_time',0)
  138. ->select($field)
  139. ->orderby('id', 'desc');
  140. if(! empty($data['code'])) $model->where('code', 'LIKE', '%'.$data['code'].'%');
  141. if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
  142. if(! empty($data['type'])) $model->where('type', $data['type']);
  143. if(! empty($data['id'])) $model->whereIn('id', $data['id']);
  144. if(isset($data['is_use'])) $model->where('is_use', $data['is_use']);
  145. if(! empty($data['crt_time'][0]) && ! empty($data['crt_time'][1])) {
  146. $return = $this->changeDateToTimeStampAboutRange($data['crt_time']);
  147. $model->where('crt_time','>=',$return[0]);
  148. $model->where('crt_time','<=',$return[1]);
  149. }
  150. return $model;
  151. }
  152. public function quantizationList($data,$user){
  153. $model = $this->quantizationCommon($data, $user);
  154. $list = $this->limit($model,'',$data);
  155. $list = $this->fillData($list,$user);
  156. return [true, $list];
  157. }
  158. public function quantizationRule(&$data, $user, $is_add = true){
  159. if(empty($data['type'])) return [false, '量化档案类型类型不能为空'];
  160. if(! isset(Quantization::$type_name[$data['type']])) return [false, '量化档案类型错误'];
  161. if(empty($data['title'])) return [false, '名称不能为空'];
  162. if(empty($data['code'])) return [false, '编码不能为空'];
  163. if(empty($data['details'])) return [false, '评价明细不能为空'];
  164. foreach ($data['details'] as $key => $value) {
  165. $rowNum = $key + 1;
  166. // 校验外层 title 不能为空
  167. if (empty($value['title'])) {
  168. return [false, "第{$rowNum}行的评价名称不能为空"];
  169. }
  170. // 校验外层 title 不重复
  171. if (!isset($titleSet)) $titleSet = [];
  172. if (in_array($value['title'], $titleSet)) {
  173. return [false, "第{$rowNum}行的评价名称 [{$value['title']}] 重复"];
  174. }
  175. $titleSet[] = $value['title'];
  176. // 校验占比
  177. if (empty($value['rate']) || ! is_numeric($value['rate']) || floatval($value['rate']) <= 0.0) {
  178. return [false, "第{$rowNum}行的占比填写错误"];
  179. }
  180. // 明细不能为空
  181. if (! empty($value['details_son'])) {
  182. // 校验明细中 title 不重复
  183. $sonTitleSet = [];
  184. foreach ($value['details_son'] as $sonKey => $val) {
  185. $sonRowNum = $sonKey + 1;
  186. if (empty($val['title'])) {
  187. return [false, "第{$rowNum}行下的第{$sonRowNum}个明细名称不能为空"];
  188. }
  189. if (in_array($val['title'], $sonTitleSet)) {
  190. return [false, "第{$rowNum}行下的明细名称 [{$val['title']}] 重复"];
  191. }
  192. $sonTitleSet[] = $val['title'];
  193. }
  194. }
  195. }
  196. $rate_total = floatval(array_sum(array_column($data['details'],'rate')));
  197. if($rate_total != 100.0) return [false, '占比之和必须等于100'];
  198. if($is_add){
  199. $bool = Quantization::where('code',$data['code'])
  200. ->where('del_time',0)
  201. ->exists();
  202. }else{
  203. if(empty($data['id'])) return [false,'ID不能为空'];
  204. $bool = Quantization::where('code',$data['code'])
  205. ->where('id','<>',$data['id'])
  206. ->where('del_time',0)
  207. ->exists();
  208. }
  209. if($bool) return [false,'编码已存在'];
  210. return [true, $data];
  211. }
  212. public function fillData($data, $user){
  213. if(empty($data['data'])) return $data;
  214. $emp = (new EmployeeService())->getEmployeeMap(array_unique(array_column($data['data'],'id')));
  215. foreach ($data['data'] as $key => $value){
  216. $data['data'][$key]['crt_time'] = $value['crt_time'] ? date('Y-m-d H:i:s',$value['crt_time']) : '';
  217. $data['data'][$key]['crt_name'] = $emp[$value['crt_id']] ?? '';
  218. $data['data'][$key]['is_use_title'] = Quantization::$is_use_name[$value['is_use']] ?? '';
  219. $data['data'][$key]['type_title'] = Quantization::$type_name[$value['type']] ?? '';
  220. }
  221. return $data;
  222. }
  223. //量化档案-----------------------------------------------
  224. //量化创建-----------------------------------------------
  225. public function quantizationCreateEdit($data,$user){
  226. list($status,$msg) = $this->quantizationCreateRule($data, $user, false);
  227. if(!$status) return [$status,$msg];
  228. try {
  229. DB::beginTransaction();
  230. $model = QuantizationCreate::where('id',$data['id'])->first();
  231. $model->customer_supply_id = $data['customer_supply_id'];
  232. $model->quantization_id = $data['quantization_id'];
  233. $model->start_time = $data['start_time'] ?? 0;
  234. $model->end_time = $data['end_time'] ?? 0;
  235. $model->products = $data['products'] ?? '';
  236. $model->score = $data['score'] ?? 0;
  237. $model->save();
  238. $time = time();
  239. QuantizationCreateDetails::where('del_time',0)
  240. ->where('quantization_create_id', $data['id'])
  241. ->update(['del_time' => $time]);
  242. $this->saveDetail1($model->id, $time, $data);
  243. DB::commit();
  244. }catch (\Exception $exception){
  245. DB::rollBack();
  246. return [false,$exception->getMessage()];
  247. }
  248. return [true, ''];
  249. }
  250. public function quantizationCreateAdd($data,$user){
  251. list($status,$msg) = $this->quantizationCreateRule($data, $user);
  252. if(!$status) return [$status,$msg];
  253. try {
  254. DB::beginTransaction();
  255. $model = new QuantizationCreate();
  256. $model->customer_supply_id = $data['customer_supply_id'];
  257. $model->quantization_id = $data['quantization_id'];
  258. $model->start_time = $data['start_time'] ?? 0;
  259. $model->end_time = $data['end_time'] ?? 0;
  260. $model->products = $data['products'] ?? '';
  261. $model->score = $data['score'] ?? 0;
  262. $model->type = $data['type'] ?? 0;
  263. $model->crt_id = $user['id'];
  264. $model->save();
  265. $time = time();
  266. $this->saveDetail1($model->id, $time, $data);
  267. DB::commit();
  268. }catch (\Exception $exception){
  269. DB::rollBack();
  270. return [false,$exception->getMessage()];
  271. }
  272. return [true, ''];
  273. }
  274. private function saveDetail1($id, $time, $data){
  275. foreach ($data['details'] as $value) {
  276. // 插入父级
  277. $parent = QuantizationDetails::create([
  278. 'quantization_create_id' => $id,
  279. 'title' => $value['title'],
  280. 'rate' => $value['rate'],
  281. 'parent_id' => 0, // 顶层 parent_id = 0
  282. 'crt_time' => $time,
  283. 'dimension_id' => $value['dimension_id'] ?? 0,
  284. 'score' => $value['score'] ?? 0,
  285. ]);
  286. // 再处理子级
  287. if (! empty($value['details_son'])) {
  288. foreach ($value['details_son'] as $son) {
  289. $detailsSonData[] = [
  290. 'quantization_create_id' => $id,
  291. 'title' => $son['title'],
  292. 'parent_id' => $parent->id, // 子级关联父级 id
  293. 'crt_time' => $time,
  294. 'dimension_id' => $value['dimension_id'] ?? 0,
  295. 'score' => $value['score'] ?? 0,
  296. ];
  297. }
  298. }
  299. }
  300. // 批量插入子级
  301. if (!empty($detailsSonData)) QuantizationCreateDetails::insert($detailsSonData);
  302. }
  303. private function getDetail1($id){
  304. // 查所有数据
  305. $all = QuantizationCreateDetails::where('quantization_create_id', $id)
  306. ->where('del_time', 0)
  307. ->orderBy('id','asc')
  308. ->get()
  309. ->toArray();
  310. $map = Dimension::whereIn('id',array_unique(array_filter(array_column($all,'dimension_id'))))
  311. ->pluck('title','id')
  312. ->toArray();
  313. // 按 parent_id 分组
  314. $grouped = [];
  315. foreach ($all as $item) {
  316. $item['dimension_title'] = $map[$item['dimension_id']] ?? "";
  317. $grouped[$item['parent_id']][] = $item;
  318. }
  319. $result = [];
  320. // 只取 parent_id = 0 的父级
  321. if (!empty($grouped[0])) {
  322. foreach ($grouped[0] as $parent) {
  323. $parent['details_son'] = $grouped[$parent['id']] ?? (object)[];
  324. $result[] = $parent;
  325. }
  326. }
  327. return $result;
  328. }
  329. public function quantizationCreateDel($data){
  330. if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
  331. try {
  332. DB::beginTransaction();
  333. $time = time();
  334. QuantizationCreate::where('del_time',0)
  335. ->whereIn('id',$data['id'])
  336. ->update(['del_time' => $time]);
  337. QuantizationCreateDetails::where('del_time',0)
  338. ->whereIn('quantization_create_id', $data['id'])
  339. ->update(['del_time' => $time]);
  340. DB::commit();
  341. }catch (\Exception $exception){
  342. DB::rollBack();
  343. return [false,$exception->getMessage()];
  344. }
  345. return [true, ''];
  346. }
  347. public function quantizationCreateDetail($data,$user){
  348. if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
  349. $customer = QuantizationCreate::where('del_time',0)
  350. ->where('id',$data['id'])
  351. ->first();
  352. if(empty($customer)) return [false,'量化信息不存在或已被删除'];
  353. $customer = $customer->toArray();
  354. $emp_2 = (new CustomerSupplyService())->getEmployeeMap([$customer['customer_supply_id']],'detail');
  355. $e = $emp_2[$customer['customer_supply_id']] ?? [];
  356. $customer['organization_title'] = $e['organization_title'] ?? "";
  357. $customer['customer_supply_title'] = $e['title'] ?? "";
  358. $customer['customer_supply_code'] = $e['code'] ?? "";
  359. $customer['quantization_title'] = Quantization::where('id', $customer['quantization_id'])->value('title');
  360. $details = $this->getDetail1($customer['id']);
  361. $customer['details'] = $details;
  362. $customer['crt_name'] = Employee::where('id',$customer['crt_id'])->value('emp_name');
  363. $customer['crt_time'] = $customer['crt_time'] ? date("Y-m-d H:i:s",$customer['crt_time']): '';
  364. return [true, $customer];
  365. }
  366. public function quantizationCreateCommon($data,$user, $field = []){
  367. if(empty($data['type']) || ! isset(QuantizationCreate::$type_name[$data['type']])) return [false, '类型不存在或错误'];
  368. if(empty($field)) $field = QuantizationCreate::$field;
  369. $model = QuantizationCreate::Clear($user,$data);
  370. $model->where('del_time',0)
  371. ->select($field)
  372. ->orderby('id', 'desc');
  373. if(! empty($data['type'])) $model->where('type', $data['type']);
  374. if(! empty($data['id'])) $model->whereIn('id', $data['id']);
  375. if(! empty($data['crt_time'][0]) && ! empty($data['crt_time'][1])) {
  376. $return = $this->changeDateToTimeStampAboutRange($data['crt_time']);
  377. $model->where('crt_time','>=',$return[0]);
  378. $model->where('crt_time','<=',$return[1]);
  379. }
  380. if(! empty($data['zq'][0]) && ! empty($data['zq'][1])) {
  381. $return = $this->changeDateToTimeStampAboutRange($data['zq']);
  382. $model->where('start_time','>=',$return[0]);
  383. $model->where('end_time','<=',$return[1]);
  384. }
  385. return [true, $model];
  386. }
  387. public function quantizationCreateList($data,$user){
  388. list($status,$model) = $this->quantizationCreateCommon($data, $user);
  389. if(! $status) return [false,$model];
  390. $list = $this->limit($model,'',$data);
  391. $list = $this->fillCreateData($list,$user);
  392. return [true, $list];
  393. }
  394. public function quantizationCreateRule(&$data, $user, $is_add = true){
  395. if(empty($data['type'])) return [false, '量化档案类型类型不能为空'];
  396. if(empty($data['quantization_id'])) return [false, '量化档案ID不能为空'];
  397. $q = Quantization::where('del_time',0)
  398. ->where('id', $data['quantization_id'])
  399. ->first();
  400. if(empty($q)) return [false, '引用的档案不存在或已被删除'];
  401. $q = $q->toArray();
  402. if(! isset(QuantizationCreate::$type_name[$data['type']])) return [false, '量化档案类型错误'];
  403. if($q['type'] != $data['type']) return [false, '引用档案类型与量化档案类型不一致'];
  404. if($data['type'] == QuantizationCreate::type_two){
  405. if(empty($data['start_time']) || empty($data['end_time'])) return [false, '周期不能为空'];
  406. $data['start_time'] = $this->changeDateToDate($data['start_time']);
  407. $data['end_time'] = $this->changeDateToDate($data['end_time']);
  408. }
  409. if(empty($data['customer_supply_id'])) return [false, '人员id不能为空'];
  410. $bool = CustomerSupply::where('del_time',0)
  411. ->where('id',$data['customer_supply_id'])
  412. ->exists();
  413. if(! $bool) return [false, '人员不存在或已被删除'];
  414. if(! isset($data['score'])) return [false, '分数不存在'];
  415. $res = $this->checkNumber($data['score']);
  416. if(! $res['valid']) return [false,'分数:' . $res['error']];
  417. if(empty($data['details'])) return [false, '量化详情不能为空'];
  418. foreach ($data['details'] as $key => $value) {
  419. $rowNum = $key + 1;
  420. // 校验外层 title 不能为空
  421. if (empty($value['title'])) return [false, "第{$rowNum}行的评价名称不能为空"];
  422. // 校验占比
  423. if (empty($value['rate']) || ! is_numeric($value['rate']) || floatval($value['rate']) <= 0.0) {
  424. return [false, "第{$rowNum}行的占比错误"];
  425. }
  426. // 明细不能为空
  427. if (! empty($value['details_son'])) {
  428. foreach ($value['details_son'] as $sonKey => $val) {
  429. $sonRowNum = $sonKey + 1;
  430. if (empty($val['title'])) return [false, "第{$rowNum}行下的第{$sonRowNum}个明细名称不能为空"];
  431. if (empty($val['dimension_id'])) return [false, "第{$rowNum}行下的第{$sonRowNum}个明细的维度选项不能为空"];
  432. }
  433. }else{
  434. if(empty($value['dimension_id'])) return [false, "第{$rowNum}行的维度选项不能为空"];
  435. }
  436. }
  437. if ($is_add) {
  438. if ($data['type'] == QuantizationCreate::type_one) {
  439. // 能力量化:只允许唯一一份
  440. $bool = QuantizationCreate::where('customer_supply_id', $data['customer_supply_id'])
  441. ->where('type', QuantizationCreate::type_one)
  442. ->where('del_time', 0)
  443. ->exists();
  444. if ($bool) {
  445. return [false, '该人员已创建能力量化档案,请勿重复创建'];
  446. }
  447. } else {
  448. $startTime = $data['start_time'];
  449. $endTime = $data['end_time'];
  450. // 合作量化:检查时间区间重叠
  451. $bool = QuantizationCreate::where('customer_supply_id', $data['customer_supply_id'])
  452. ->where('type', QuantizationCreate::type_two) // 建议限定 type,防止误匹配
  453. ->where('del_time', 0)
  454. ->where(function($query) use ($startTime, $endTime) {
  455. $query->where('start', '<=', $endTime)
  456. ->where('end', '>=', $startTime);
  457. })
  458. ->exists();
  459. if ($bool) {
  460. return [false, '该人员在该周期内已创建合作量化档案,请勿重复创建'];
  461. }
  462. }
  463. } else {
  464. // 编辑模式
  465. if (empty($data['id'])) return [false, 'ID不能为空'];
  466. $id = $data['id'];
  467. if ($data['type'] == QuantizationCreate::type_one) {
  468. $bool = QuantizationCreate::where('customer_supply_id', $data['customer_supply_id'])
  469. ->where('type', QuantizationCreate::type_one)
  470. ->where('id', '<>', $id)
  471. ->where('del_time', 0)
  472. ->exists();
  473. if ($bool) return [false, '该人员已创建能力量化档案,请勿重复创建'];
  474. } else {
  475. $bool = QuantizationCreate::where('customer_supply_id', $data['customer_supply_id'])
  476. ->where('type', QuantizationCreate::type_two)
  477. ->where('del_time', 0)
  478. ->where(function($query) use ($startTime, $endTime) {
  479. $query->where('start', '<=', $endTime)
  480. ->where('end', '>=', $startTime);
  481. })
  482. ->where('id', '<>', $id)
  483. ->exists();
  484. if ($bool) return [false, '该人员在该周期内已创建合作量化档案,请勿重复创建'];
  485. }
  486. }
  487. return [true, $data];
  488. }
  489. public function fillCreateData($data, $user){
  490. if(empty($data['data'])) return $data;
  491. $emp = (new EmployeeService())->getEmployeeMap(array_unique(array_column($data['data'],'id')));
  492. $emp_2 = (new CustomerSupplyService())->getEmployeeMap(array_unique(array_column($data['data'],'customer_supply_id')),'detail');
  493. foreach ($data['data'] as $key => $value){
  494. $data['data'][$key]['crt_time'] = $value['crt_time'] ? date('Y-m-d H:i:s',$value['crt_time']) : '';
  495. $data['data'][$key]['start_time'] = $value['start_time'] ? date('Y-m-d',$value['start_time']) : '';
  496. $data['data'][$key]['end_time'] = $value['end_time'] ? date('Y-m-d',$value['end_time']) : '';
  497. $data['data'][$key]['crt_name'] = $emp[$value['crt_id']] ?? '';
  498. $data['data'][$key]['type_title'] = QuantizationCreate::$type_name[$value['type']] ?? '';
  499. $e = $emp_2[$value['id']] ?? [];
  500. $data['data'][$key]['organization_title'] = $e['organization_title'] ?? "";
  501. $data['data'][$key]['customer_supply_title'] = $e['title'] ?? "";
  502. $data['data'][$key]['customer_supply_code'] = $e['code'] ?? "";
  503. $data['data'][$key]['result'] = $this->fillDataResult($value);
  504. }
  505. return $data;
  506. }
  507. private function fillDataResult($value)
  508. {
  509. $score = isset($value['score']) ? floatval($value['score']) : 0;
  510. $type = $value['type'] ?? null;
  511. if ($type == QuantizationCreate::type_one) {
  512. if ($score < 50) return '不合格';
  513. if ($score < 70) return '改善后评估';
  514. return '合格';
  515. }
  516. // 其他类型
  517. return $score < 60 ? '不合格' : '合格';
  518. }
  519. //量化创建-----------------------------------------------
  520. }