OrderFreezeController.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Components\AsyncResponse;
  4. use App\OrderFreeze;
  5. class OrderFreezeController extends Controller
  6. {
  7. use AsyncResponse;
  8. public function index()
  9. {
  10. $this->gate("订单管理-自动冻结");
  11. $freezes = OrderFreeze::query()->with(["logistic:id,name","province:id,name","city:id,name","location:id,name"])
  12. ->orderByDesc("id")->where("status",0)
  13. ->paginate(request("paginate") ?? 50);
  14. return view("order.index.freeze",compact("freezes"));
  15. }
  16. public function store()
  17. {
  18. $this->gate("订单管理-自动冻结");
  19. $freeze = OrderFreeze::query()->where("logistic_id",request("logistic_id"))
  20. ->where("province_id",request("province_id"))
  21. ->where("city_id",request("city_id"))->where("status",0)
  22. ->where("location_id",request("location_id"))->first();
  23. if ($freeze && $freeze->id!=request("id"))$this->error("已存在冻结选项,无需重复录入");
  24. $obj = [
  25. "logistic_id" => request("logistic_id"),
  26. "province_id" => request("province_id"),
  27. "city_id" => request("city_id"),
  28. "location_id" => request("location_id"),
  29. ];
  30. if (request("id")){
  31. $freeze = OrderFreeze::query()->find(request("id"));
  32. $freeze->update($obj);
  33. }else $freeze = OrderFreeze::query()->create($obj);
  34. app("OrderFreezeService")->refreshFreezes();
  35. $freeze->load(["logistic:id,name","province:id,name","city:id,name","location:id,name"]);
  36. $this->success($freeze);
  37. }
  38. public function delFreeze()
  39. {
  40. $this->gate("订单管理-自动冻结");
  41. if (!request("id"))$this->error("非法参数");
  42. OrderFreeze::query()->where("id",request("id"))->update(["status"=>1]);
  43. app("OrderFreezeService")->refreshFreezes();
  44. $this->success();
  45. }
  46. }