2026-01-24 14:03:11 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
|
|
|
|
|
|
use App\DB\Te\TableEngine;
|
|
|
|
|
use App\Http\Controllers\SuperController;
|
2026-04-26 20:09:21 +00:00
|
|
|
use App\Models\Cnt;
|
2026-01-24 14:03:11 +00:00
|
|
|
use App\Models\Customer;
|
|
|
|
|
use App\Models\TransactionsAdmin;
|
|
|
|
|
use App\Models\Withdraw;
|
2026-04-26 20:09:21 +00:00
|
|
|
use Carbon\Carbon;
|
|
|
|
|
use Hekmatinasser\Verta\Verta;
|
2026-01-24 14:03:11 +00:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Rooyesh\Wallet\interfaces\TransactionInterface;
|
|
|
|
|
use Rooyesh\Wallet\interfaces\WalletInterface;
|
|
|
|
|
use Rooyesh\Wallet\models\Transaction;
|
|
|
|
|
use Rooyesh\Wallet\models\Wallet;
|
|
|
|
|
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
|
|
|
|
|
|
|
|
|
|
class CustomerController extends SuperController
|
|
|
|
|
{
|
|
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
$this->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 && Customer::where('referral_to_id', $customer->referral->referral_id)->where('is_legal', "!=",0)->count() < 4) {
|
|
|
|
|
$gift_for_inviter = 0.002;
|
|
|
|
|
$gift_for_invited = 0.003;
|
|
|
|
|
$Withdraw = Withdraw::create([
|
|
|
|
|
'user_id' => $customer->id,
|
|
|
|
|
'customer_id' => $customer->referral->id,
|
|
|
|
|
"cash" => 0,
|
|
|
|
|
"gold" => $gift_for_invited,
|
|
|
|
|
'sts' => 5,
|
|
|
|
|
]);
|
|
|
|
|
$wallet_interface = new WalletInterface($customer->referral->id, 2);
|
|
|
|
|
new TransactionInterface($wallet_interface, $_inp = [
|
|
|
|
|
"cash" => 0,
|
|
|
|
|
"gold"=> $gift_for_invited,
|
|
|
|
|
'expire_at'=>now(),
|
|
|
|
|
'active'=>true,
|
|
|
|
|
'withdraw_id' =>$Withdraw->id,
|
|
|
|
|
'start_at'=>now(),
|
|
|
|
|
], 8, true,false);
|
|
|
|
|
|
|
|
|
|
$transaction = Transaction::where('customer_id', $customer->referral->id)->latest()->first();
|
|
|
|
|
TransactionsAdmin::create([
|
|
|
|
|
'customer_id' => $customer->id,
|
|
|
|
|
'customer_to_id' => $customer->referral->id,
|
|
|
|
|
'user_id' => $customer->id,
|
|
|
|
|
'wallet' => null, // یا مقدار مناسب دیگری
|
|
|
|
|
'transaction_id' => $transaction->id ,
|
|
|
|
|
'cash' => 0,
|
|
|
|
|
'note' => 'پاداش بابت معرفی',
|
|
|
|
|
'type' => 1, // یا مقدار مناسب دیگری
|
|
|
|
|
'gold' => $gift_for_invited,
|
|
|
|
|
'balance_cash' => 0, // یا مقدار مناسب دیگری
|
|
|
|
|
'withdraw_id' => $Withdraw->id,
|
|
|
|
|
]);
|
|
|
|
|
$Withdraw = Withdraw::create([
|
|
|
|
|
'user_id' => $customer->id,
|
|
|
|
|
'customer_id' => $customer->id,
|
|
|
|
|
"cash" => 0,
|
|
|
|
|
"gold" => $gift_for_inviter,
|
|
|
|
|
'sts' => 5,
|
|
|
|
|
]);
|
|
|
|
|
$wallet_interface = new WalletInterface($customer->id, 2);
|
|
|
|
|
new TransactionInterface($wallet_interface, $_inp = [
|
|
|
|
|
"cash" => 0,
|
|
|
|
|
"gold"=> $gift_for_inviter,
|
|
|
|
|
'expire_at'=>now(),
|
|
|
|
|
'active'=>true,
|
|
|
|
|
'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->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,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$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);
|
|
|
|
|
}
|
2026-04-26 20:09:21 +00:00
|
|
|
|
|
|
|
|
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)){
|
|
|
|
|
throw new UnprocessableEntityHttpException('لطفا تاریخ تولد وارد کنید.');
|
|
|
|
|
}
|
|
|
|
|
$birth_date = Verta::instance(Carbon::parse($request->birth_date))->format('Ymd');
|
|
|
|
|
$card_number = preg_replace('/\D/', '', $request->cart_number);
|
|
|
|
|
|
|
|
|
|
// dd("ok");
|
|
|
|
|
|
|
|
|
|
$response = $this->jibit("cartMatching", $card_number, $request->national_code, $birth_date);
|
|
|
|
|
|
|
|
|
|
if(!empty($response)){
|
|
|
|
|
if (isset($response['cartData'])) {
|
|
|
|
|
unset($response['refresh']);
|
|
|
|
|
return response()->json($response);
|
|
|
|
|
}elseif(!empty($response['message'])){
|
|
|
|
|
throw new UnprocessableEntityHttpException($response['message']);
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
throw new UnprocessableEntityHttpException('ارتباط با سامانه قطع میباشد.');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-24 14:03:11 +00:00
|
|
|
}
|