芝麻web文件管理V1.00
编辑当前文件:/home/qrafawbu/store.kwesioben.com/app/Http/Controllers/api/v2/seller/ShippingMethodController.php
json([ 'auth-001' => translate('Your existing session token does not authorize you any more') ], 401); } $validator = Validator::make($request->all(), [ 'title' => 'required|max:200', 'duration' => 'required', 'cost' => 'numeric' ]); if ($validator->errors()->count() > 0) { return response()->json(['errors' => Helpers::error_processor($validator)]); } DB::table('shipping_methods')->insert([ 'creator_id' => $seller['id'], 'creator_type' => 'seller', 'title' => $request['title'], 'duration' => $request['duration'], 'cost' => BackEndHelper::currency_to_usd($request['cost']), 'status' => 1, 'created_at' => now(), 'updated_at' => now() ]); return response()->json(['message' => translate('successfully_added')], 200); } public function list(Request $request) { $data = Helpers::get_seller_by_token($request); if ($data['success'] == 1) { $seller = $data['data']; } else { return response()->json([ 'auth-001' => translate('Your existing session token does not authorize you any more') ], 401); } return response()->json(ShippingMethod::where(['creator_type' => 'seller', 'creator_id' => $seller['id']])->get(), 200); } public function status_update(Request $request) { $data = Helpers::get_seller_by_token($request); if ($data['success'] == 1) { $seller = $data['data']; } else { return response()->json([ 'auth-001' => translate('Your existing session token does not authorize you any more') ], 401); } $validator = Validator::make($request->all(), [ 'id' => 'required', 'status' => 'required|in:1,0', ]); if ($validator->errors()->count() > 0) { return response()->json(['errors' => Helpers::error_processor($validator)]); } ShippingMethod::where(['id' => $request['id'], 'creator_id' => $seller['id']])->update([ 'status' => $request['status'] ]); return response()->json(['message' => translate('successfully_status_updated')], 200); } public function edit(Request $request, $id) { $data = Helpers::get_seller_by_token($request); if ($data['success'] == 1) { $seller = $data['data']; } else { return response()->json([ 'auth-001' => translate('Your existing session token does not authorize you any more') ], 401); } $method = ShippingMethod::where(['id' => $id, 'creator_id' => $seller['id']])->first(); if (isset($method)) { return response()->json($method, 200); } return response()->json(['message' => translate('data_not_found')], 200); } public function update(Request $request, $id) { $data = Helpers::get_seller_by_token($request); if ($data['success'] == 1) { $seller = $data['data']; } else { return response()->json([ 'auth-001' => translate('Your existing session token does not authorize you any more') ], 401); } $validator = Validator::make($request->all(), [ 'title' => 'required|max:200', 'duration' => 'required', 'cost' => 'numeric' ]); if ($validator->errors()->count() > 0) { return response()->json(['errors' => Helpers::error_processor($validator)]); } DB::table('shipping_methods')->where(['id' => $id, 'creator_id' => $seller['id']])->update([ 'title' => $request['title'], 'duration' => $request['duration'], 'cost' => BackEndHelper::currency_to_usd($request['cost']), 'status' => 1, 'created_at' => now(), 'updated_at' => now() ]); return response()->json(['message' => translate('successfully_updated')], 200); } public function delete(Request $request) { $data = Helpers::get_seller_by_token($request); if ($data['success'] == 1) { $seller = $data['data']; } else { return response()->json([ 'auth-001' => translate('Your existing session token does not authorize you any more') ], 401); } ShippingMethod::where(['id' => $request->id, 'creator_id' => $seller['id']])->delete(); return response()->json(['message' => translate('successfully_deleted')], 200); } }