ExchangeController.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use App\Models\Exchange;
  4. use Illuminate\Http\Request;
  5. use App\Http\Requests;
  6. use Illuminate\Support\Facades\Config;
  7. class ExchangeController extends AdminController
  8. {
  9. /*权限验证规则*/
  10. protected $validateRules = [
  11. 'real_name' => 'required|max:32',
  12. 'phone' => 'required|regex:/^1[3456789]{1}\d{9}$/',
  13. 'email' => 'required|email|max:64',
  14. 'comment' => 'max:512'
  15. ];
  16. /**
  17. * Display a listing of the resource.
  18. *
  19. * @return \Illuminate\Http\Response
  20. */
  21. public function index(Request $request)
  22. {
  23. $exchanges = Exchange::orderBy('created_at','desc')->paginate(Config::get('tipask.admin.page_size'));
  24. return view('admin.exchange.index')->with('exchanges',$exchanges);
  25. }
  26. /**
  27. * Show the form for creating a new resource.
  28. *
  29. * @return \Illuminate\Http\Response
  30. */
  31. public function create()
  32. {
  33. //
  34. }
  35. /**
  36. * Store a newly created resource in storage.
  37. *
  38. * @param \Illuminate\Http\Request $request
  39. * @return \Illuminate\Http\Response
  40. */
  41. public function store(Request $request)
  42. {
  43. //
  44. }
  45. /**
  46. * Display the specified resource.
  47. *
  48. * @param int $id
  49. * @return \Illuminate\Http\Response
  50. */
  51. public function show($id)
  52. {
  53. //
  54. }
  55. /**
  56. * Show the form for editing the specified resource.
  57. *
  58. * @param int $id
  59. * @return \Illuminate\Http\Response
  60. */
  61. public function edit($id)
  62. {
  63. $exchange = Exchange::find($id);
  64. return view("admin.exchange.edit")->with('exchange',$exchange);
  65. }
  66. /**
  67. * Update the specified resource in storage.
  68. *
  69. * @param \Illuminate\Http\Request $request
  70. * @param int $id
  71. * @return \Illuminate\Http\Response
  72. */
  73. public function update(Request $request, $id)
  74. {
  75. $exchange = Exchange::find($id);
  76. if(!$exchange){
  77. return $this->error(route('admin.exchange.index'),'记录不存在,请核实');
  78. }
  79. $this->validate($request,$this->validateRules);
  80. $data = $request->all();
  81. $exchange->update($data);
  82. return $this->success(route('admin.exchange.index'),'兑换记录修改成功');
  83. }
  84. /*修改兑换记录状态*/
  85. public function changeStatus($id,$status)
  86. {
  87. $exchange = Exchange::find($id);
  88. if(!$exchange){
  89. return $this->error(route('admin.exchange.index'),'记录不存在,请核实');
  90. }
  91. if($status === 'success' && $exchange->status ===0 ){
  92. $exchange->update(['status'=>1]);
  93. }else if($status === 'failed' && $exchange->status ===0 ){
  94. $exchange->update(['status'=>4]);
  95. }
  96. return $this->success(route('admin.exchange.index'),'兑换记录状态修改成功');
  97. }
  98. /**
  99. * Remove the specified resource from storage.
  100. *
  101. * @param int $id
  102. * @return \Illuminate\Http\Response
  103. */
  104. public function destroy($id)
  105. {
  106. //
  107. }
  108. }