with = []; $this->select = ['*']; $search=['name','mobile']; $this->query = Customer::with($this->with,'wallet')->where('is_archive',false)->where('type',1); // $this->query = Customer::where('is_archive',false)->get(); parent::__construct(Customer::class, $this->with, $this->select, 'customer', $this->query, $search); } /** * @param $id * @return \Illuminate\Http\JsonResponse */ public function listUser(){ $user = Customer::with(['wallet'])->select('id','name','mobile','type')->get(); return response()->json($user); } public function updateAdmin(Request $request , $id) { $data = $request->all(); if (isset($data['mobile']) && !is_null($data['mobile'])){ $check_mobile = Customer::where('mobile',$data['mobile']) ->where('id','<>',$id) ->first(); if (!is_null($check_mobile)){ throw new UnprocessableEntityHttpException('این شماره همراه توسط شخص دیگری در حال استفاده است'); } } if (isset($data['gold'])){ $user = Customer::find($id); if ($user) { $user->gold = $data['gold']; $user->save(); $user["g"]=true; } } $user["u"] = Customer::findOrFail($id)->update($data); return response()->json($user); } public function referrals(Request $request,$customer_id) { $customer_referral_id = Customer::where("id",$customer_id)->first()->referral_id; $query_table = Customer::where("referral_to_id",$customer_referral_id); TableEngine::create($query_table, $request) ->initSearch($this->search) ->select(['*',Customer::$SELECT_TYPE_STR]) ->export($query_table); return response()->json($query_table); } public function funds(Request $request,$customer_id) { $query_table = Wallet::with(['fund'])->where('owner', $customer_id); // Adjust columns as per your schema TableEngine::create($query_table, $request) ->initSearch($this->search) ->select(['id', 'owner', 'cash', 'gold','fund_id','created_at', 'updated_at']) ->export($query_table); return response()->json($query_table); } public function archive($id){ $query = Customer::findOrFail($id); $query->update([ 'is_archive'=>!$query->is_archive ]); return response()->json(true); } public function tableWallets(Request $request){ $query_table = Customer::with(['wallet','referral'])->where("is_archive",false)/*->where('type',1)*/; TableEngine::create($query_table, $request) ->initSearch($this->search) ->select(['*',Customer::$SELECT_TYPE_STR]) ->export($query_table); return response()->json($query_table); } public function archiveTable(Request $request) { $query_table = Customer::with($this->with)->where("is_archive",true)/*->where('type',1)*/; TableEngine::create($query_table, $request) ->initSearch($this->search) ->select($this->select) ->export($query_table); return response()->json($query_table); } /** * @param $id * @return \Illuminate\Http\JsonResponse */ public function active($id){ $query = Customer::findOrFail($id); $active = !$query->active; $query->update([ 'active'=>!$query->active ]); if ($active){ $message ='اکانت شما توسط کارشناس سیستم تایید شد '."\n". 'با رفتن به لینک زیر وارد حساب کاربری خود شوید'."\n". $this->Config('app_url')."\n". 'با تشکر'.$this->Config('name_fa'); } else{ $message ='اکانت شما توسط کارشناس سیستم غیر فعال شد '."\n". 'با کارشناسان ما تماس بگیرید'."\n". 'با تشکر'.$this->Config('name_fa'); } $this->Send($query->mobile,$message); return response()->json(true); } public function changeTradeActive($id){ $query = Customer::findOrFail($id); $query->update([ 'trade_active'=>!$query->trade_active ]); return response()->json(true); } // single customer------------------- public function singleArchiveTable(Request $request) { $query_table = Customer::with($this->with)->where("is_archive",true)->where('type',2); TableEngine::create($query_table, $request) ->initSearch($this->search) ->select($this->select) ->export($query_table); return response()->json($query_table); } public function singleCustomerTable(Request $request) { $query_table = Customer::with($this->with)->where("is_archive",false)->where('type',2); TableEngine::create($query_table, $request) ->initSearch($this->search) ->select($this->select) ->export($query_table); return response()->json($query_table); } public function MakeValidByAdmin(Request $request,$id) { $customer = Customer::with('referral')->where('id', $id)->first(); if ($customer->is_legal == 2 or $customer->is_legal == 3){ return response()->json(true); } $customer->is_legal = 2; $customer->save(); if ($this->Config('has_page_earn_money') == 'true') { $referrer = $customer->referrer(); if ( $referrer && Customer::where('referral_to_id', $referrer->referral_id)->where('is_legal', '!=', 0)->count() < 4 ) { $gift_for_inviter = $this->Config('gift_for_referrer'); $gift_for_invited = $this->Config('gift_for_referral'); $companyName = $this->Config('name_fa'); $companyurl = $this->Config('app_url'); $total_referrals = Customer::where('referral_to_id', $referrer->referral_id)->where('is_legal', '!=', 0)->get()->count(); $referral_limit = Setting::where('key', 'referral_limit')->first(); $gift_permision = $referral_limit->is_active ? $total_referrals < $referral_limit->value ? true : false : true ; if ($gift_permision && $gift_for_inviter > 0) { // dd($gift_for_inviter > 0, $gift_for_invited > 0); $Withdraw = Withdraw::create([ 'user_id' => $customer->id, 'customer_id' => $referrer->id, "cash" => 0, "gold" => $gift_for_inviter, 'sts' => 5, ]); $wallet_interface = new WalletInterface($referrer->id, 2); new TransactionInterface($wallet_interface, $_inp = [ "cash" => 0, "gold" => $gift_for_inviter, 'expire_at' => now(), 'active' => true, 'title' => 'پاداش بابت معرفی', 'withdraw_id' => $Withdraw->id, 'start_at' => now(), ], 8, true, false); $transaction = Transaction::where('customer_id', $referrer->id)->latest()->first(); TransactionsAdmin::create([ 'customer_id' => $customer->id, 'customer_to_id' => $referrer->id, 'user_id' => $customer->id, 'wallet' => null, // یا مقدار مناسب دیگری 'transaction_id' => $transaction->id, 'cash' => 0, 'note' => 'پاداش بابت معرفی', 'type' => 1, // یا مقدار مناسب دیگری 'gold' => $gift_for_inviter, 'balance_cash' => 0, // یا مقدار مناسب دیگری 'withdraw_id' => $Withdraw->id, ]); $referrerWallet = Wallet::where('owner', $referrer->id)->first(); if($this->Config('send_to_tahesab') == "true"){ try { $tahesab = new TahesabController(); $tahesab->referrerGoldReward( $customer, (float) $gift_for_inviter, 'پاداش بابت معرفی' ); }catch (\Exception $e){ return response($e->getMessage(), 500); } } $message = "سلام {$referrer->name} عزیز،\n\n{$gift_for_inviter} گرم طلا بابت معرفی {$customer->name} به حساب شما واریز شد.\nموجودی فعلی: {$referrerWallet->gold} گرم.\n\nاطلاعات بیشتر: $companyurl\n\nبا احترام،\n$companyName"; $this->Send($referrer->mobile, $message); } if($gift_for_invited > 0 ){ $Withdraw = Withdraw::create([ 'user_id' => $customer->id, 'customer_id' => $customer->id, "cash" => 0, "gold" => $gift_for_invited, 'sts' => 5, ]); $wallet_interface = new WalletInterface($customer->id, 2); new TransactionInterface($wallet_interface, $_inp = [ "cash" => 0, "gold" => $gift_for_invited, 'expire_at' => now(), 'active' => true, 'title' => 'پاداش بابت ثبت نام', 'withdraw_id' => $Withdraw->id, 'start_at' => now(), ], 8, true, false); $transaction = Transaction::where('customer_id', $customer->id)->latest()->first(); TransactionsAdmin::create([ 'customer_id' => $customer->id, 'customer_to_id' => $customer->referal->id, 'user_id' => $customer->id, 'wallet' => null, // یا مقدار مناسب دیگری 'transaction_id' => $transaction->id, 'cash' => 0, 'note' => 'پاداش بابت ثبت نام', 'type' => 1, // یا مقدار مناسب دیگری 'gold' => (float)$gift_for_invited, 'balance_cash' => 0, // یا مقدار مناسب دیگری 'withdraw_id' => $Withdraw->id, ]); $referrerWallet = Wallet::where('owner', $customer->id)->first(); if($this->Config('send_to_tahesab') == "true"){ try { $tahesab = new TahesabController(); $tahesab->goldReward([ 'customer_id' => $customer->id, 'value' => $gift_for_invited, 'desc' => 'پاداش بابت ثبت نام', ]); }catch (\Exception $e){ return response($e->getMessage(), 500); } } $message = "سلام " . $customer->name . " عزیز،\n\n" . $gift_for_invited . " گرم طلا بابت ثبت نام " . " به حساب شما واریز شد.\n" . "موجودی فعلی: " . $referrerWallet->gold . " گرم.\n\n" . "اطلاعات بیشتر: " . $companyurl . "\n\n" . "با احترام،\n" . $companyName; $this->Send($customer->mobile, $message); } } } $companyName = $this->Config('name_fa'); $companyurl = $this->Config('app_url'); $message ='حساب کاربری شما توسط کارشناس سیستم تایید شد '."\n". 'با رفتن به لینک زیر وارد حساب کاربری خود شوید'."\n". $this->Config('app_url')."\n". 'با تشکر'.$this->Config('name_fa'); $this->Send($customer->mobile, $message); $referrer = $customer->referral; // if ($referrer) { // if (Customer::where('referral_to_id', $referrer->referral_id)->get()->count()<=$referrer->add_user_limit) { // $referrerWallet = Wallet::where('owner',$customer->referral->id)->first(); // $message = "سلام {$referrer->name} عزیز،\n\n{$gift_for_invite} گرم طلا بابت معرفی {$customer->name} به حساب شما واریز شد.\nموجودی فعلی: {$referrerWallet->gold} گرم.\n\nاطلاعات بیشتر: $companyurl\n\nبا احترام،\n$companyName"; // $this->Send($referrer->mobile, $message); // } // } return response()->json(true); } public function cardChecker(Request $request){ if (strlen($request->cart_number) != 16) { throw new UnprocessableEntityHttpException('شماره کارت اشتباه می‌باشد.'); } if (empty($request->national_code)) { throw new UnprocessableEntityHttpException('لطفا شماره ملی وارد کنید.'); } if(!empty($request->birth_date)){ $birth_date = Verta::instance(Carbon::parse($request->birth_date))->format('Ymd'); } $card_number = preg_replace('/\D/', '', $request->cart_number); $response = $this->jibit("cartMatching", $card_number, $request->national_code, $birth_date ?? null); if(isset($response['refresh'])){ unset($response['refresh']); } if(!empty($response)){ if(!empty($response['message'])){ throw new UnprocessableEntityHttpException($response['message']); }else{ return response()->json($response); } }else{ throw new UnprocessableEntityHttpException('ارتباط با سامانه قطع میباشد.'); } } }