MaterialBoxModelController.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Components\AsyncResponse;
  4. use App\MaterialBoxModel;
  5. use App\Owner;
  6. use Illuminate\Support\Facades\Validator;
  7. class MaterialBoxModelController extends Controller
  8. {
  9. use AsyncResponse;
  10. public function index()
  11. {
  12. $models = MaterialBoxModel::query()->get();
  13. return view("maintenance.materialBoxModel.index",compact("models"));
  14. }
  15. public function save()
  16. {
  17. $id = request("id");
  18. $errors = Validator::make(request()->input(), [
  19. 'code'=>['required',$id?"unique:material_box_models,code,$id":"unique:material_box_models,code"],
  20. 'maximum_kind'=>['required',"integer","min:1"],
  21. 'description'=>['nullable'],
  22. ],[
  23. 'integer'=>':attribute 非法参数',
  24. 'required'=>':attribute 必填',
  25. 'unique'=>':attribute 已存在',
  26. ],[
  27. 'code'=>'编码',
  28. 'maximum_kind'=>'最大商品种类',
  29. 'description'=>'说明',
  30. ]);
  31. if ($errors->errors()->count())$this->success(["errors"=>$errors->errors()]);
  32. if (!$id) $this->success(MaterialBoxModel::query()->create([
  33. 'code' => request("code"),
  34. 'maximum_kind' => request("maximum_kind"),
  35. 'description' => request("description"),
  36. ]));
  37. $model = MaterialBoxModel::query()->find($id);
  38. if (!$model)$this->error("模型不存在");
  39. $model->update(request()->only(["code",'maximum_kind',"description"]));
  40. $this->success($model);
  41. }
  42. public function destroy()
  43. {
  44. $this->success(MaterialBoxModel::destroy(request("id")));
  45. }
  46. public function ownerSequence()
  47. {
  48. $owners = app("OwnerService")->getIntersectPermitting(["id","name","model_sequence"]);
  49. $models = MaterialBoxModel::query()->get();
  50. return view("maintenance.materialBoxModel.modelSequence",compact("owners","models"));
  51. }
  52. public function updateModelSequence()
  53. {
  54. $sequence = request("sequence");
  55. $this->success(Owner::query()->where("id",request("id"))->update([
  56. "model_sequence" => $sequence ?: null
  57. ]));
  58. }
  59. }