/
home
/
pay
/
server
/
app
/
Http
/
Controllers
/
Customer
/
File Upload :
llllll
Current File: /home/pay/server/app/Http/Controllers/Customer/CustomerController.php
<?php namespace App\Http\Controllers\Customer; use App\DB\Te\TableEngine; use App\Http\Controllers\Admin\CustomerController as adm_cu; use App\Http\Controllers\Controller; use App\Models\Address; use App\Models\Customer; use App\Models\User; use App\Models\TransactionsAdmin; use Illuminate\Http\Request; use Rooyesh\Wallet\models\Wallet; use Rooyesh\Wallet\models\Transaction; use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Http; //use App\Models\Price; //use Carbon\Carbon; //use Illuminate\Support\Facades\Http; class CustomerController extends Controller { public function me() { $user = Customer::findOrFail(auth('customer')->id()); $wallet = Wallet::where('owner', $user->id) ->where('owner_type', $user->type) ->whereNull('fund_id') ->first() ?? new Wallet(); // $wallet->gold_sum = round(Transaction::where('customer_id', $user->id)->sum('gold'), 2); $wallet->gold_sum = round(Wallet::where('owner', $user->id)->sum('gold'), 2); $user->wallet = $wallet; return response()->json($user); } public function updateMe(Request $request) { try { $customer = Customer::findOrFail(auth('customer')->id()); $updateData = $request->except(['referral_id', 'referral_to_id']); if (isset($request->fname) && isset($request->lname)) { $updateData['name'] = "$request->fname $request->lname"; } if ($request->has('credential_id')) { $updateData['credential_id'] = $request->credential_id; } $customer->update($updateData); if (!$customer->is_legal) { $nationalCode = $customer->n_code; $mobileNumber = $customer->mobile; Storage::put('accessTokenGibit', ['accessToken']); Storage::put('refreshTokenGibit', ['refreshToken']); $response = Http::withToken(Storage::get('accessTokenGibit')) ->get("https://napi.jibit.ir/ide/v1/services/matching?nationalCode=".$nationalCode."&mobileNumber=".$mobileNumber)->json(); if ($response['code']== "forbidden"){ $response = Http::withToken(Storage::get('refreshTokenGibit')) ->post("https://napi.jibit.ir/ide/v1/tokens/generate",[ 'apiKey' => "J5WxrPxPOg", 'secretKey' => "7dgeE70xQXsQL7r36j3wif6X9", ])->json(); Storage::put('accessTokenGibit', $response['accessToken']); Storage::put('refreshTokenGibit', $response['refreshToken']); $response = Http::withToken(Storage::get('accessTokenGibit')) ->get("https://napi.jibit.ir/ide/v1/services/matching?nationalCode=".$nationalCode."&mobileNumber=".$mobileNumber)->json(); } if (isset($response['matched']) and $response['matched']== true ) { $customer->is_legal = 1; $customer->save(); } else { // This block will handle the case where the code doesn't match // if (isset($response['code']) and $response['code'] === 'mobileNumber.not_valid') { // return response()->json(['message' => "کد ملی تطابق ندارد",'response' =>$response], 422); // } else { // // This block will handle other errors from the $response variable // return response()->json(['response' => $response], 422); // } return response()->json(['message' => "کد ملی تطابق ندارد",'response' =>$response], 422); } } return response()->json(true); } catch (\Exception $e) { // نمایش 400 کاراکتر اول از پیام خطا $errorMessage = substr($e->getMessage(), 0, 400); return response()->json(['error' => $errorMessage], 500); } } public function active_finger() { $customer = Customer::findOrFail(auth('customer')->id()); if ($customer->finger_print) { $customer->finger_print = false; // Set to false if currently true } else { $customer->finger_print = true; // Set to true if currently false } $customer->save(); return response()->json($customer); } public function imFrom($code) { $referrer = Customer::where('referral_id', $code)->first(); if ($referrer) { // Define the reward amount $rewardAmount = 200000; // Adjusted reward amount as per the new requirement // Update the referred customer with the referral code $newCustomer = auth('customer')->user(); // Assuming the new customer is authenticated $newCustomer->referral_id = $code; $newCustomer->save(); // Construct the SMS message $message = sprintf( "%s با کد معرف شما ثبت نام کرد.\nکیف پول شما %d ریال به عنوان پاداش شارژ شد.\n%s", $newCustomer->name, $rewardAmount, $this->Config('name_fa') ); // Send SMS to the referrer $this->Send($referrer->mobile, $message); return response()->json(['message' => 'Referral reward processed and SMS sent to referrer.'], 200); } else { return response()->json(['error' => 'کد نامعتبر میباشد'], 422); } } public function i_have(Request $request) { $user = auth('customer')->user(); $customer_referral_id = Customer::where("id",$user['id'])->first()->referral_id; $return['users'] = Customer::where("referral_to_id",$customer_referral_id)->get(); $return['gifts'] = TransactionsAdmin::with(['withdraw','order',"user",'customerTo','customer'])->where("customer_to_id",$user->id)->get(); $return['usersSum'] =$return['users']->count(); $return['giftsSum'] =number_format($return['gifts']->sum('gold'), 3); return response()->json($return); } }
Copyright ©2k19 -
Hexid
|
Tex7ure