123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php
- namespace App\Http\Controllers\Admin\Flow;
- use App\Http\Controllers\Controller;
- use App\Http\Models\FlowInfoTpl;
- use App\Http\Models\FlowStageTpl;
- use Illuminate\Http\Request;
- /**
- * 项目管理 详情下 的新版流程 模板
- * Class TplController
- * @package App\Http\Controllers\Admin\Flow
- */
- class TplController extends Controller
- {
- //新版流程 模板
- public function tplIndex($siteId){
- $tplStageList = FlowStageTpl::query()->with('infoTplList')->orderBy('sort')->get();
- return view('admin.flow.tpl', [
- 'siteId' => $siteId,
- 'tplStageList' => $tplStageList
- ]);
- }
- //模板保存
- public function tplSave(Request $request)
- {
- $dataList = $request->input('dataList')??[];
- $stepIds = array_column($dataList, 'step_id');
- $stageIds = FlowStageTpl::query()->pluck('id')->toArray();
- $delIds = array_diff($stageIds, $stepIds);
- if ($delIds) {
- FlowStageTpl::query()->whereIn('id', $delIds)->delete();
- }
- $mapInfoIds=FlowInfoTpl::query()->select(['id','stage_id'])->get()->groupBy('stage_id')->toArray();
- foreach ($dataList as $step) {
- $stepChildren=$step['children'] ?? [];
- if (empty($step['step_id'])) {
- $stage = FlowStageTpl::query()->create([
- 'title' => $step['step_title'],
- ]);
- foreach ($stepChildren as $item) {
- FlowInfoTpl::query()->create([
- 'stage_id' => $stage->id,
- 'detail_list' => ($item['children'] ?? []),
- ]);
- }
- } else {
- $infoIds=array_column($mapInfoIds[$step['step_id']]??[],'id');
- $dataInfoIds=array_column($stepChildren,'info_id');
- $infoDelIds=array_diff($infoIds,$dataInfoIds);
- if ($infoIds){
- FlowInfoTpl::query()->whereIn('id', $infoDelIds)->delete();
- }
- FlowStageTpl::query()->where(['id' => $step['step_id']])->update(['title' => $step['step_title']]);
- foreach ($stepChildren as $item) {
- if (empty($item['info_id'])) {
- FlowInfoTpl::query()->create([
- 'stage_id' => $step['step_id'],
- 'detail_list' => ($item['children'] ?? []),
- ]);
- } else {
- FlowInfoTpl::query()->where(['id' => $item['info_id']])->update([
- 'detail_list' => json_encode($item['children'] ?? []),
- ]);
- }
- }
- }
- }
- return response()->json(['message' => '操作成功']);
- }
- }
|