1192 lines
58 KiB
PHP
1192 lines
58 KiB
PHP
<?php
|
|
|
|
namespace App\Controller;
|
|
|
|
use App\Entity\BankAccount;
|
|
use App\Entity\Business;
|
|
use App\Entity\Cashdesk;
|
|
use App\Entity\ChangeReport;
|
|
use App\Entity\Commodity;
|
|
use App\Entity\HesabdariDoc;
|
|
use App\Entity\Money;
|
|
use App\Entity\Person;
|
|
use App\Entity\Registry;
|
|
use App\Entity\Settings;
|
|
use App\Entity\StoreroomTicket;
|
|
use App\Entity\User;
|
|
use App\Entity\UserToken;
|
|
use App\Entity\WalletTransaction;
|
|
use App\Service\Extractor;
|
|
use App\Service\Jdate;
|
|
use App\Service\JsonResp;
|
|
use App\Service\Log;
|
|
use App\Service\Notification;
|
|
use App\Service\Provider;
|
|
use App\Service\registryMGR;
|
|
use App\Service\SMS;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use Exception;
|
|
use Symfony\Bundle\FrameworkBundle\Console\Application;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Component\Console\Input\ArrayInput;
|
|
use Symfony\Component\Console\Output\BufferedOutput;
|
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\HttpKernel\KernelInterface;
|
|
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
|
|
use Symfony\Component\Routing\Annotation\Route;
|
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
|
use Symfony\Component\Security\Http\Attribute\CurrentUser;
|
|
|
|
class AdminController extends AbstractController
|
|
{
|
|
/**
|
|
* @throws Exception
|
|
*/
|
|
#[Route('/api/admin/sync/database', name: 'app_admin_sync_database')]
|
|
public function app_admin_sync_database(KernelInterface $kernel): JsonResponse
|
|
{
|
|
$application = new Application($kernel);
|
|
$application->setAutoExit(false);
|
|
|
|
$input = new ArrayInput([
|
|
'command' => 'doctrine:schema:update',
|
|
// (optional) define the value of command arguments
|
|
'--force' => true,
|
|
'--complete' => true
|
|
]);
|
|
|
|
// You can use NullOutput() if you don't need the output
|
|
$output = new BufferedOutput();
|
|
$application->run($input, $output);
|
|
|
|
// return the output, don't use if you used NullOutput()
|
|
$content = $output->fetch();
|
|
return $this->json([
|
|
'message' => $content,
|
|
]);
|
|
}
|
|
|
|
#[Route('/api/admin/users/list', name: 'admin_users_list')]
|
|
public function admin_users_list(Jdate $jdate, #[CurrentUser] ?User $user, UserPasswordHasherInterface $userPasswordHasher, EntityManagerInterface $entityManager, Request $request): Response
|
|
{
|
|
$users = $entityManager->getRepository(User::class)->findBy([], ['id' => 'DESC']);
|
|
$resp = [];
|
|
foreach ($users as $user) {
|
|
$temp = [];
|
|
$temp['id'] = $user->getId();
|
|
$temp['email'] = $user->getEmail();
|
|
$temp['mobile'] = $user->getMobile();
|
|
$temp['fullname'] = $user->getFullName();
|
|
$temp['status'] = $user->isActive();
|
|
$temp['dateRegister'] = $jdate->jdate('Y/n/d', $user->getDateRegister());
|
|
$temp['bidCount'] = count($entityManager->getRepository(Business::class)->findBy(['owner' => $user]));
|
|
$resp[] = $temp;
|
|
}
|
|
return $this->json($resp);
|
|
}
|
|
|
|
#[Route('/api/admin/user/info/{id}', name: 'admin_user_info')]
|
|
public function admin_user_info(string $id, Jdate $jdate, #[CurrentUser] ?User $user, UserPasswordHasherInterface $userPasswordHasher, EntityManagerInterface $entityManager, Request $request): Response
|
|
{
|
|
$user = $entityManager->getRepository(User::class)->find($id);
|
|
$temp = [];
|
|
$temp['id'] = $user->getId();
|
|
$temp['email'] = $user->getEmail();
|
|
$temp['mobile'] = $user->getMobile();
|
|
$temp['fullname'] = $user->getFullName();
|
|
$temp['status'] = $user->isActive();
|
|
$temp['dateRegister'] = $jdate->jdate('Y/n/d', $user->getDateRegister());
|
|
$temp['bidCount'] = count($entityManager->getRepository(Business::class)->findBy(['owner' => $user]));
|
|
return $this->json($temp);
|
|
}
|
|
|
|
#[Route('/api/admin/business/info/{id}', name: 'admin_business_info')]
|
|
public function admin_business_info(string $id, Jdate $jdate, #[CurrentUser] ?User $user, UserPasswordHasherInterface $userPasswordHasher, EntityManagerInterface $entityManager, Request $request): Response
|
|
{
|
|
$bid = $entityManager->getRepository(Business::class)->find($id);
|
|
if (!$bid)
|
|
throw $this->createNotFoundException();
|
|
$resp = [];
|
|
$resp['id'] = $bid->getId();
|
|
$resp['name'] = $bid->getName();
|
|
$resp['owner'] = $bid->getOwner()->getFullName();
|
|
return $this->json($resp);
|
|
}
|
|
#[Route('/api/admin/business/list', name: 'admin_business_list')]
|
|
public function admin_business_list(Jdate $jdate, #[CurrentUser] ?User $user, UserPasswordHasherInterface $userPasswordHasher, EntityManagerInterface $entityManager, Request $request): Response
|
|
{
|
|
$items = $entityManager->getRepository(Business::class)->findBy([], ['id' => 'DESC']);
|
|
$resp = [];
|
|
foreach ($items as $item) {
|
|
$temp = [];
|
|
$temp['id'] = $item->getId();
|
|
$temp['name'] = $item->getName();
|
|
$temp['owner'] = $item->getOwner()->getFullName();
|
|
$temp['ownerMobile'] = $item->getOwner()->getMobile();
|
|
$temp['dateRegister'] = $jdate->jdate('Y/n/d', $item->getDateSubmit());
|
|
$temp['commodityCount'] = count($entityManager->getRepository(Commodity::class)->findBy(['bid' => $item]));
|
|
$temp['personsCount'] = count($entityManager->getRepository(Person::class)->findBy(['bid' => $item]));
|
|
$temp['hesabdariDocsCount'] = count($entityManager->getRepository(HesabdariDoc::class)->findBy(['bid' => $item]));
|
|
$temp['StoreroomDocsCount'] = count($entityManager->getRepository(StoreroomTicket::class)->findBy(['bid' => $item]));
|
|
|
|
$resp[] = $temp;
|
|
}
|
|
return $this->json($resp);
|
|
}
|
|
|
|
#[Route('/api/admin/business/count', name: 'admin_business_count')]
|
|
public function admin_business_count(Jdate $jdate, #[CurrentUser] ?User $user, UserPasswordHasherInterface $userPasswordHasher, EntityManagerInterface $entityManager, Request $request): Response
|
|
{
|
|
return $this->json($entityManager->getRepository(Business::class)->countAll());
|
|
}
|
|
|
|
#[Route('/api/admin/users/count', name: 'admin_users_count')]
|
|
public function admin_users_count(Extractor $extractor, #[CurrentUser] ?User $user, UserPasswordHasherInterface $userPasswordHasher, EntityManagerInterface $entityManager, Request $request): Response
|
|
{
|
|
return $this->json($extractor->operationSuccess($entityManager->getRepository(User::class)->countAll()));
|
|
}
|
|
|
|
#[Route('/api/admin/business/search', name: 'admin_business_list_search')]
|
|
public function admin_business_list_search(Extractor $extractor, Jdate $jdate, #[CurrentUser] ?User $user, UserPasswordHasherInterface $userPasswordHasher, EntityManagerInterface $entityManager, Request $request): Response
|
|
{
|
|
$params = [];
|
|
if ($content = $request->getContent()) {
|
|
$params = json_decode($content, true);
|
|
}
|
|
$items = $entityManager->getRepository(Business::class)->findByPage($params['options']['page'], $params['options']['rowsPerPage'], $params['search']);
|
|
$resp = [];
|
|
foreach ($items as $item) {
|
|
$temp = [];
|
|
$temp['id'] = $item->getId();
|
|
$temp['name'] = $item->getName();
|
|
$temp['owner'] = $item->getOwner()->getFullName();
|
|
$temp['ownerMobile'] = $item->getOwner()->getMobile();
|
|
$temp['dateRegister'] = $jdate->jdate('Y/n/d', $item->getDateSubmit());
|
|
$temp['commodityCount'] = count($entityManager->getRepository(Commodity::class)->findBy(['bid' => $item]));
|
|
$temp['personsCount'] = count($entityManager->getRepository(Person::class)->findBy(['bid' => $item]));
|
|
$temp['hesabdariDocsCount'] = count($entityManager->getRepository(HesabdariDoc::class)->findBy(['bid' => $item]));
|
|
$temp['StoreroomDocsCount'] = count($entityManager->getRepository(StoreroomTicket::class)->findBy(['bid' => $item]));
|
|
$resp[] = $temp;
|
|
}
|
|
return $this->json($extractor->operationSuccess($resp));
|
|
}
|
|
|
|
#[Route('/api/admin/users/search', name: 'admin_users_list_search', methods: ['POST'])]
|
|
public function admin_users_list_search(
|
|
Extractor $extractor,
|
|
Jdate $jdate,
|
|
#[CurrentUser] ?User $user,
|
|
EntityManagerInterface $entityManager,
|
|
Request $request
|
|
): Response {
|
|
$params = json_decode($request->getContent(), true) ?? [];
|
|
|
|
// پارامترهای صفحهبندی و مرتبسازی
|
|
$pagination = $params['pagination'] ?? ['page' => 1, 'limit' => 10];
|
|
$sort = $params['sort'] ?? ['sortBy' => 'id', 'sortDesc' => true];
|
|
$filters = $params['filters'] ?? [];
|
|
|
|
$page = max(1, $pagination['page'] ?? 1);
|
|
$limit = max(1, min(100, $pagination['limit'] ?? 10));
|
|
$offset = ($page - 1) * $limit;
|
|
|
|
// ساخت کوئری پایه
|
|
$queryBuilder = $entityManager->createQueryBuilder()
|
|
->select('u')
|
|
->from(User::class, 'u');
|
|
|
|
// اعمال فیلترها و جستجو
|
|
if (!empty($filters['search'])) {
|
|
$searchTerm = $filters['search'];
|
|
$queryBuilder->andWhere(
|
|
$queryBuilder->expr()->orX(
|
|
'u.email LIKE :search',
|
|
'u.fullName LIKE :search',
|
|
'u.mobile LIKE :search',
|
|
'u.dateRegister LIKE :search',
|
|
'u.invateCode LIKE :search'
|
|
)
|
|
)
|
|
->setParameter('search', "%$searchTerm%");
|
|
}
|
|
|
|
// اعمال فیلترهای وضعیت
|
|
if (isset($filters['status'])) {
|
|
$queryBuilder->andWhere('u.active = :status')
|
|
->setParameter('status', $filters['status']);
|
|
}
|
|
|
|
// اعمال مرتبسازی
|
|
$sortField = $sort['sortBy'] ?? 'id';
|
|
$sortDirection = ($sort['sortDesc'] ?? true) ? 'DESC' : 'ASC';
|
|
|
|
// اطمینان از اینکه فیلد مرتبسازی معتبر است
|
|
$allowedSortFields = ['id', 'email', 'fullName', 'mobile', 'dateRegister', 'active'];
|
|
if (in_array($sortField, $allowedSortFields)) {
|
|
$queryBuilder->orderBy("u.$sortField", $sortDirection);
|
|
} else {
|
|
$queryBuilder->orderBy('u.id', 'DESC');
|
|
}
|
|
|
|
// محاسبه تعداد کل نتایج
|
|
$totalItemsQuery = clone $queryBuilder;
|
|
$totalItems = $totalItemsQuery->select('COUNT(u.id)')
|
|
->getQuery()
|
|
->getSingleScalarResult();
|
|
|
|
// اعمال صفحهبندی
|
|
$queryBuilder->setFirstResult($offset)
|
|
->setMaxResults($limit);
|
|
|
|
// دریافت نتایج
|
|
$items = $queryBuilder->getQuery()->getResult();
|
|
|
|
// تبدیل نتایج به فرمت مورد نظر
|
|
$resp = [];
|
|
foreach ($items as $item) {
|
|
$temp = [
|
|
'id' => $item->getId(),
|
|
'email' => $item->getEmail(),
|
|
'mobile' => $item->getMobile(),
|
|
'fullname' => $item->getFullName(),
|
|
'status' => $item->isActive(),
|
|
'dateRegister' => $jdate->jdate('Y/n/d', $item->getDateRegister()),
|
|
'bidCount' => count($entityManager->getRepository(Business::class)->findBy(['owner' => $item])),
|
|
'roles' => $item->getRoles(),
|
|
'inviteCode' => $item->getInvateCode()
|
|
];
|
|
$resp[] = $temp;
|
|
}
|
|
|
|
return $this->json([
|
|
'status' => 'success',
|
|
'message' => 'عملیات با موفقیت انجام شد',
|
|
'data' => [
|
|
'items' => $resp,
|
|
'total' => (int) $totalItems,
|
|
'page' => $page,
|
|
'limit' => $limit,
|
|
'totalPages' => ceil($totalItems / $limit)
|
|
]
|
|
]);
|
|
}
|
|
|
|
#[Route('/api/admin/settings/sms/info', name: 'admin_settings_sms_info')]
|
|
public function admin_settings_sms_info(Jdate $jdate, #[CurrentUser] ?User $user, UserPasswordHasherInterface $userPasswordHasher, EntityManagerInterface $entityManager, Request $request): Response
|
|
{
|
|
$item = $entityManager->getRepository(Settings::class)->findAll()[0];
|
|
$resp = [];
|
|
$url = 'https://console.melipayamak.com/api/receive/credit/' . $item->getMelipayamakToken();
|
|
$ch = curl_init($url);
|
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
curl_setopt(
|
|
$ch,
|
|
CURLOPT_HTTPHEADER,
|
|
array(
|
|
'Content-Type: application/json',
|
|
'Content-Length: 0'
|
|
)
|
|
);
|
|
$result = curl_exec($ch);
|
|
$err = curl_error($ch);
|
|
$result = json_decode($result, true, JSON_PRETTY_PRINT);
|
|
curl_close($ch);
|
|
if ($err) {
|
|
throw $this->createAccessDeniedException($err);
|
|
} else {
|
|
$resp['balanceCount'] = $result['amount'];
|
|
}
|
|
$resp['username'] = $item->getPayamakUsername();
|
|
$resp['password'] = $item->getPayamakPassword();
|
|
$resp['token'] = $item->getMelipayamakToken();
|
|
return $this->json($resp);
|
|
}
|
|
#[Route('/api/admin/settings/sms/info/save', name: 'admin_settings_sms_info_save')]
|
|
public function admin_settings_sms_info_save(Jdate $jdate, #[CurrentUser] ?User $user, UserPasswordHasherInterface $userPasswordHasher, EntityManagerInterface $entityManager, Request $request): Response
|
|
{
|
|
$params = [];
|
|
if ($content = $request->getContent()) {
|
|
$params = json_decode($content, true);
|
|
}
|
|
if (array_key_exists('username', $params) && array_key_exists('password', $params) && array_key_exists('token', $params)) {
|
|
$item = $entityManager->getRepository(Settings::class)->findAll()[0];
|
|
$item->setPayamakPassword($params['password']);
|
|
$item->setPayamakUsername($params['username']);
|
|
$item->setMelipayamakToken($params['token']);
|
|
$entityManager->persist($item);
|
|
$entityManager->flush();
|
|
return $this->json(['result' => 1]);
|
|
}
|
|
throw $this->createNotFoundException();
|
|
}
|
|
|
|
#[Route('/api/admin/sms/plan/info', name: 'admin_sms_plan_info')]
|
|
public function admin_sms_plan_info(registryMGR $registryMGR, Jdate $jdate, #[CurrentUser] ?User $user, UserPasswordHasherInterface $userPasswordHasher, EntityManagerInterface $entityManager, Request $request): Response
|
|
{
|
|
|
|
$resp = [];
|
|
$resp['username'] = $registryMGR->get('sms', 'username');
|
|
$resp['password'] = $registryMGR->get('sms', 'password');
|
|
$resp['token'] = $registryMGR->get('sms', 'token');
|
|
$resp['walletpay'] = $registryMGR->get('sms', 'walletPay');
|
|
$resp['changePassword'] = $registryMGR->get('sms', 'changePassword');
|
|
$resp['recPassword'] = $registryMGR->get('sms', 'recPassword');
|
|
$resp['f2a'] = $registryMGR->get('sms', 'f2a');
|
|
$resp['ticketReplay'] = $registryMGR->get('sms', 'ticketReplay');
|
|
$resp['ticketRec'] = $registryMGR->get('sms', 'ticketRec');
|
|
$resp['fromNum'] = $registryMGR->get('sms', 'fromNum');
|
|
$resp['sharefaktor'] = $registryMGR->get('sms', 'sharefaktor');
|
|
$resp['plan'] = $registryMGR->get('sms', 'plan');
|
|
$resp['chequeInput'] = $registryMGR->get('sms', 'chequeInput');
|
|
$resp['passChequeInput'] = $registryMGR->get('sms', 'passChequeInput');
|
|
$resp['rejectChequeInput'] = $registryMGR->get('sms', 'rejectChequeInput');
|
|
$resp['plugRepservice'] = [
|
|
'get' => $registryMGR->get('sms', 'plugRepserviceStateGet'),
|
|
'getback' => $registryMGR->get('sms', 'plugRepserviceStateGetback'),
|
|
'repaired' => $registryMGR->get('sms', 'plugRepserviceStateRepaired'),
|
|
'unrepaired' => $registryMGR->get('sms', 'plugRepserviceStateUnrepired'),
|
|
'creating' => $registryMGR->get('sms', 'plugRepserviceStateCreating'),
|
|
'created' => $registryMGR->get('sms', 'plugRepserviceStateCreated')
|
|
];
|
|
$resp['plugAccpro'] = [
|
|
'sharefaktor' => $registryMGR->get('sms', 'plugAccproSharefaktor'),
|
|
'storeroomSmsOther' => $registryMGR->get('sms', 'plugAccproStoreroomSmsOther'),
|
|
'storeroomSmsBarbari' => $registryMGR->get('sms', 'plugAccproStoreroomSmsBarbari'),
|
|
'chequeInput' => $registryMGR->get('sms', 'plugAccproChequeInput'),
|
|
'passChequeInput' => $registryMGR->get('sms', 'plugAccproPassChequeInput'),
|
|
'rejectChequeInput' => $registryMGR->get('sms', 'plugAccproRejectChequeInput')
|
|
];
|
|
$resp['plugWarranty'] = [
|
|
'sendSerial' => $registryMGR->get('sms', 'plugWarrantySendSerial'),
|
|
];
|
|
return $this->json($resp);
|
|
}
|
|
|
|
#[Route('/api/admin/sms/plan/info/save', name: 'admin_sms_plan_info_save')]
|
|
public function admin_sms_plan_info_save(registryMGR $registryMGR, Jdate $jdate, #[CurrentUser] ?User $user, UserPasswordHasherInterface $userPasswordHasher, EntityManagerInterface $entityManager, Request $request): Response
|
|
{
|
|
$params = [];
|
|
if ($content = $request->getContent()) {
|
|
$params = json_decode($content, true);
|
|
}
|
|
|
|
if (array_key_exists('username', $params))
|
|
$registryMGR->update('sms', 'username', $params['username'] ?? '');
|
|
if (array_key_exists('password', $params))
|
|
$registryMGR->update('sms', 'password', $params['password'] ?? '');
|
|
if (array_key_exists('token', $params))
|
|
$registryMGR->update('sms', 'token', $params['token'] ?? '');
|
|
|
|
if (array_key_exists('walletpay', $params))
|
|
$registryMGR->update('sms', 'walletpay', $params['walletpay'] ?? '');
|
|
if (array_key_exists('changePassword', $params))
|
|
$registryMGR->update('sms', 'changePassword', $params['changePassword'] ?? '');
|
|
if (array_key_exists('recPassword', $params))
|
|
$registryMGR->update('sms', 'recPassword', $params['recPassword'] ?? '');
|
|
if (array_key_exists('f2a', $params))
|
|
$registryMGR->update('sms', 'f2a', $params['f2a'] ?? '');
|
|
if (array_key_exists('ticketReplay', $params))
|
|
$registryMGR->update('sms', 'ticketReplay', $params['ticketReplay'] ?? '');
|
|
if (array_key_exists('ticketRec', $params))
|
|
$registryMGR->update('sms', 'ticketRec', $params['ticketRec'] ?? '');
|
|
if (array_key_exists('fromNum', $params))
|
|
$registryMGR->update('sms', 'fromNum', $params['fromNum'] ?? '');
|
|
if (array_key_exists('sharefaktor', $params))
|
|
$registryMGR->update('sms', 'sharefaktor', $params['sharefaktor'] ?? '');
|
|
if (array_key_exists('plan', $params))
|
|
$registryMGR->update('sms', 'plan', $params['plan'] ?? '');
|
|
if (array_key_exists('chequeInput', $params))
|
|
$registryMGR->update('sms', 'chequeInput', $params['chequeInput'] ?? '');
|
|
if (array_key_exists('passChequeInput', $params))
|
|
$registryMGR->update('sms', 'passChequeInput', $params['passChequeInput'] ?? '');
|
|
if (array_key_exists('rejectChequeInput', $params))
|
|
$registryMGR->update('sms', 'rejectChequeInput', $params['rejectChequeInput'] ?? '');
|
|
|
|
if (array_key_exists('plugRepservice', $params)) {
|
|
if (array_key_exists('get', $params['plugRepservice']))
|
|
$registryMGR->update('sms', 'plugRepserviceStateGet', $params['plugRepservice']['get'] ?? '');
|
|
if (array_key_exists('repaired', $params['plugRepservice']))
|
|
$registryMGR->update('sms', 'plugRepserviceStateRepaired', $params['plugRepservice']['repaired'] ?? '');
|
|
if (array_key_exists('unrepaired', $params['plugRepservice']))
|
|
$registryMGR->update('sms', 'plugRepserviceStateUnrepired', $params['plugRepservice']['unrepaired'] ?? '');
|
|
if (array_key_exists('getback', $params['plugRepservice']))
|
|
$registryMGR->update('sms', 'plugRepserviceStateGetback', $params['plugRepservice']['getback'] ?? '');
|
|
if (array_key_exists('creating', $params['plugRepservice']))
|
|
$registryMGR->update('sms', 'plugRepserviceStateCreating', $params['plugRepservice']['creating'] ?? '');
|
|
if (array_key_exists('created', $params['plugRepservice']))
|
|
$registryMGR->update('sms', 'plugRepserviceStateCreated', $params['plugRepservice']['created'] ?? '');
|
|
}
|
|
if (array_key_exists('plugAccpro', $params)) {
|
|
if (array_key_exists('sharefaktor', $params['plugAccpro']))
|
|
$registryMGR->update('sms', 'plugAccproSharefaktor', $params['plugAccpro']['sharefaktor'] ?? '');
|
|
if (array_key_exists('storeroomSmsBarbari', $params['plugAccpro']))
|
|
$registryMGR->update('sms', 'plugAccproStoreroomSmsBarbari', $params['plugAccpro']['storeroomSmsBarbari'] ?? '');
|
|
if (array_key_exists('storeroomSmsOther', $params['plugAccpro']))
|
|
$registryMGR->update('sms', 'plugAccproStoreroomSmsOther', $params['plugAccpro']['storeroomSmsOther'] ?? '');
|
|
if (array_key_exists('chequeInput', $params['plugAccpro']))
|
|
$registryMGR->update('sms', 'plugAccproChequeInput', $params['plugAccpro']['chequeInput'] ?? '');
|
|
if (array_key_exists('passChequeInput', $params['plugAccpro']))
|
|
$registryMGR->update('sms', 'plugAccproPassChequeInput', $params['plugAccpro']['passChequeInput'] ?? '');
|
|
if (array_key_exists('rejectChequeInput', $params['plugAccpro']))
|
|
$registryMGR->update('sms', 'plugAccproRejectChequeInput', $params['plugAccpro']['rejectChequeInput'] ?? '');
|
|
}
|
|
if (array_key_exists('plugWarranty', $params)) {
|
|
if (array_key_exists('sendSerial', $params['plugWarranty']))
|
|
$registryMGR->update('sms', 'plugWarrantySendSerial', $params['plugWarranty']['sendSerial'] ?? '');
|
|
}
|
|
return $this->json(JsonResp::success());
|
|
}
|
|
|
|
#[Route('/api/admin/settings/system/info', name: 'admin_settings_system_info')]
|
|
public function admin_settings_system_info(registryMGR $registryMGR, Jdate $jdate, #[CurrentUser] ?User $user, UserPasswordHasherInterface $userPasswordHasher, EntityManagerInterface $entityManager, Request $request): Response
|
|
{
|
|
$item = $entityManager->getRepository(Settings::class)->findAll()[0];
|
|
$resp = [];
|
|
$resp['keywords'] = $item->getSiteKeywords();
|
|
$resp['description'] = $item->getDiscription();
|
|
$resp['scripts'] = $item->getScripts();
|
|
$resp['zarinpal'] = $registryMGR->get('system', key: 'zarinpalKey');;
|
|
$resp['footerScripts'] = $item->getFooterScripts();
|
|
$resp['appSite'] = $item->getAppSite();
|
|
$resp['footer'] = $item->getFooter();
|
|
$resp['activeGateway'] = $registryMGR->get('system', key: 'activeGateway');
|
|
$resp['parsianGatewayAPI'] = $registryMGR->get('system', key: 'parsianGatewayAPI');
|
|
$resp['paypingKey'] = $registryMGR->get('system', key: 'paypingKey');
|
|
$resp['bitpayKey'] = $registryMGR->get('system', key: 'bitpayKey');
|
|
$resp['inquiryPanel'] = $registryMGR->get('system', key: 'inquiryPanel');
|
|
$resp['inquiryZohalAPIKey'] = $registryMGR->get('system', key: 'inquiryZohalAPIKey');
|
|
$resp['enablePostalCodeToAddress'] = $registryMGR->get('system', key: 'enablePostalCodeToAddress');
|
|
$resp['inquiryPanelEnable'] = $registryMGR->get('system', key: 'inquiryPanelEnable');
|
|
$resp['postalCodeToAddressFee'] = $registryMGR->get('system', key: 'postalCodeToAddressFee');
|
|
$resp['enableCardToSheba'] = $registryMGR->get('system', key: 'enableCardToSheba');
|
|
$resp['cardToShebaFee'] = $registryMGR->get('system', key: 'cardToShebaFee');
|
|
$resp['enableAccountToSheba'] = $registryMGR->get('system', key: 'enableAccountToSheba');
|
|
$resp['accountToShebaFee'] = $registryMGR->get('system', key: 'accountToShebaFee');
|
|
|
|
// تنظیمات جادوگر هوش مصنوعی
|
|
$resp['aiEnabled'] = $registryMGR->get('system', key: 'aiEnabled');
|
|
$resp['aiAgentSource'] = $registryMGR->get('system', key: 'aiAgentSource');
|
|
$resp['aiModel'] = $registryMGR->get('system', key: 'aiModel');
|
|
$resp['aiApiKey'] = $registryMGR->get('system', key: 'aiApiKey');
|
|
$resp['localModelAddress'] = $registryMGR->get('system', key: 'localModelAddress');
|
|
$resp['inputTokenPrice'] = $registryMGR->get('system', key: 'inputTokenPrice');
|
|
$resp['outputTokenPrice'] = $registryMGR->get('system', key: 'outputTokenPrice');
|
|
$resp['aiPrompt'] = $registryMGR->get('system', key: 'aiPrompt');
|
|
$resp['aiDebugMode'] = $registryMGR->get('system', key: 'aiDebugMode');
|
|
|
|
return $this->json($resp);
|
|
}
|
|
|
|
|
|
#[Route('/api/admin/settings/system/info/save', name: 'admin_settings_system_info_save')]
|
|
public function admin_settings_system_info_save(registryMGR $registryMGR, EntityManagerInterface $entityManager, Request $request): Response
|
|
{
|
|
$params = [];
|
|
if ($content = $request->getContent()) {
|
|
$params = json_decode($content, true);
|
|
}
|
|
if (array_key_exists('keywords', $params) && array_key_exists('description', $params)) {
|
|
$item = $entityManager->getRepository(Settings::class)->findAll()[0];
|
|
$item->setSiteKeywords($params['keywords']);
|
|
$item->setDiscription($params['description']);
|
|
$item->setScripts($params['scripts']);
|
|
$registryMGR->update('system', 'zarinpalKey', $params['zarinpal'] ?? '');
|
|
$item->setFooterScripts($params['footerScripts']);
|
|
$item->setAppSite($params['appSite']);
|
|
$item->setFooter($params['footer']);
|
|
$registryMGR->update('system', 'activeGateway', $params['activeGateway'] ?? '');
|
|
$registryMGR->update('system', 'parsianGatewayAPI', $params['parsianGatewayAPI'] ?? '');
|
|
$registryMGR->update('system', 'paypingKey', $params['paypingKey'] ?? '');
|
|
$registryMGR->update('system', 'bitpayKey', $params['bitpayKey'] ?? '');
|
|
$registryMGR->update('system', 'inquiryPanel', $params['inquiryPanel'] ?? '');
|
|
$registryMGR->update('system', 'inquiryZohalAPIKey', $params['inquiryZohalAPIKey'] ?? '');
|
|
$registryMGR->update('system', 'enablePostalCodeToAddress', $params['enablePostalCodeToAddress'] ?? '');
|
|
$registryMGR->update('system', 'inquiryPanelEnable', $params['inquiryPanelEnable'] ?? '');
|
|
$registryMGR->update('system', 'postalCodeToAddressFee', $params['postalCodeToAddressFee'] ?? '');
|
|
$registryMGR->update('system', 'enableCardToSheba', $params['enableCardToSheba'] ?? '');
|
|
$registryMGR->update('system', 'cardToShebaFee', $params['cardToShebaFee'] ?? '');
|
|
$registryMGR->update('system', 'enableAccountToSheba', $params['enableAccountToSheba'] ?? '');
|
|
$registryMGR->update('system', 'accountToShebaFee', $params['accountToShebaFee'] ?? '');
|
|
|
|
// ذخیره تنظیمات جادوگر هوش مصنوعی
|
|
if (array_key_exists('aiEnabled', $params))
|
|
$registryMGR->update('system', 'aiEnabled', $params['aiEnabled'] ?? '');
|
|
if (array_key_exists('aiAgentSource', $params))
|
|
$registryMGR->update('system', 'aiAgentSource', $params['aiAgentSource'] ?? '');
|
|
if (array_key_exists('aiModel', $params))
|
|
$registryMGR->update('system', 'aiModel', $params['aiModel'] ?? '');
|
|
if (array_key_exists('aiApiKey', $params))
|
|
$registryMGR->update('system', 'aiApiKey', $params['aiApiKey'] ?? '');
|
|
if (array_key_exists('localModelAddress', $params))
|
|
$registryMGR->update('system', 'localModelAddress', $params['localModelAddress'] ?? '');
|
|
if (array_key_exists('inputTokenPrice', $params))
|
|
$registryMGR->update('system', 'inputTokenPrice', $params['inputTokenPrice'] ?? '');
|
|
if (array_key_exists('outputTokenPrice', $params))
|
|
$registryMGR->update('system', 'outputTokenPrice', $params['outputTokenPrice'] ?? '');
|
|
if (array_key_exists('aiPrompt', $params))
|
|
$registryMGR->update('system', 'aiPrompt', $params['aiPrompt'] ?? '');
|
|
if (array_key_exists('aiDebugMode', $params))
|
|
$registryMGR->update('system', 'aiDebugMode', $params['aiDebugMode'] ?? '');
|
|
|
|
$entityManager->persist($item);
|
|
$entityManager->flush();
|
|
return $this->json(['result' => 1]);
|
|
}
|
|
throw $this->createNotFoundException();
|
|
}
|
|
|
|
#[Route('/api/admin/reportchange/lists', name: 'app_admin_reportchange_list')]
|
|
public function app_admin_reportchange_list(Jdate $jdate, Provider $provider, EntityManagerInterface $entityManager): JsonResponse
|
|
{
|
|
$rows = $entityManager->getRepository(ChangeReport::class)->findBy([], ['id' => 'DESC']);
|
|
foreach ($rows as $row) {
|
|
$row->setDateSubmit($jdate->jdate('Y/n/d', $row->getDateSubmit()));
|
|
}
|
|
return $this->json($provider->ArrayEntity2ArrayJustIncludes($rows, ['getDateSubmit', 'getVersion', 'getId']));
|
|
}
|
|
|
|
#[Route('/api/admin/reportchange/delete/{id}', name: 'app_admin_reportchange_delete')]
|
|
public function app_admin_reportchange_delete(string $id, EntityManagerInterface $entityManager): JsonResponse
|
|
{
|
|
$item = $entityManager->getRepository(ChangeReport::class)->find($id);
|
|
if ($item) {
|
|
$entityManager->remove($item);
|
|
$entityManager->flush();
|
|
}
|
|
return $this->json(['result' => 1]);
|
|
}
|
|
|
|
#[Route('/api/admin/reportchange/get/{id}', name: 'app_admin_reportchange_get')]
|
|
public function app_admin_reportchange_get(string $id, EntityManagerInterface $entityManager): JsonResponse
|
|
{
|
|
$item = $entityManager->getRepository(ChangeReport::class)->find($id);
|
|
if (!$item)
|
|
throw $this->createNotFoundException();
|
|
return $this->json($item);
|
|
}
|
|
|
|
#[Route('/api/admin/reportchange/mod/{id}', name: 'app_admin_reportchange_mod')]
|
|
public function app_admin_reportchange_mod(Request $request, EntityManagerInterface $entityManager, int $id = 0): JsonResponse
|
|
{
|
|
$item = new ChangeReport();
|
|
$item->setDateSubmit(time());
|
|
|
|
if ($id != 0) {
|
|
$item = $entityManager->getRepository(ChangeReport::class)->find($id);
|
|
if (!$item)
|
|
throw $this->createNotFoundException();
|
|
else
|
|
$item->setDateSubmit(time());
|
|
}
|
|
$params = [];
|
|
if ($content = $request->getContent()) {
|
|
$params = json_decode($content, true);
|
|
}
|
|
if (array_key_exists('version', $params) && array_key_exists('body', $params)) {
|
|
$item->setBody($params['body']);
|
|
$item->setVersion($params['version']);
|
|
} else
|
|
throw $this->createNotFoundException();
|
|
$entityManager->persist($item);
|
|
$entityManager->flush();
|
|
return $this->json(['result' => 1]);
|
|
}
|
|
|
|
#[Route('/api/admin/wallets/list', name: 'app_admin_wallets_list')]
|
|
public function app_admin_wallets_list(Jdate $jdate, Provider $provider, EntityManagerInterface $entityManager): JsonResponse
|
|
{
|
|
$bids = $entityManager->getRepository(Business::class)->findBy(['walletEnable' => true]);
|
|
$resp = [];
|
|
foreach ($bids as $bid) {
|
|
$temp = [];
|
|
$walletPays = $entityManager->getRepository(WalletTransaction::class)->findBy(['bid' => $bid, 'type' => 'pay']);
|
|
$totalPays = 0;
|
|
foreach ($walletPays as $walletPay) {
|
|
$totalPays += $walletPay->getAmount();
|
|
}
|
|
$temp['totalPays'] = $totalPays;
|
|
|
|
// محاسبه درآمد از تراکنشهای sell
|
|
$walletSells = $entityManager->getRepository(WalletTransaction::class)->findBy(['bid' => $bid, 'type' => 'sell']);
|
|
$totalIncome = 0;
|
|
foreach ($walletSells as $walletSell) {
|
|
$totalIncome += (float) $walletSell->getAmount();
|
|
}
|
|
$temp['totalIncome'] = $totalIncome;
|
|
|
|
// محاسبه موجودی (درآمد - هزینه)
|
|
$temp['walletBalance'] = $totalIncome - $totalPays;
|
|
|
|
$temp['id'] = $bid->getId();
|
|
$temp['bidName'] = $bid->getName();
|
|
$temp['walletEnabled'] = $bid->isWalletEnable();
|
|
if ($bid->isWalletEnable()) {
|
|
$temp['bankAcName'] = $bid->getWalletMatchBank()->getName();
|
|
$temp['bankAcShaba'] = $bid->getWalletMatchBank()->getShaba();
|
|
$temp['bankAcOwner'] = $bid->getWalletMatchBank()->getOwner();
|
|
$temp['bankAcCardNum'] = $bid->getWalletMatchBank()->getCardNum();
|
|
}
|
|
|
|
$resp[] = $temp;
|
|
}
|
|
return $this->json($resp);
|
|
}
|
|
|
|
#[Route('/api/admin/wallets/transactions/list', name: 'app_admin_wallets_transactions_list')]
|
|
public function app_admin_wallets_transactions_list(Jdate $jdate, Provider $provider, EntityManagerInterface $entityManager): JsonResponse
|
|
{
|
|
$items = $entityManager->getRepository(WalletTransaction::class)->findAll();
|
|
$resp = [];
|
|
foreach ($items as $item) {
|
|
$temp = [];
|
|
$temp['id'] = $item->getId();
|
|
$temp['bidName'] = $item->getBid()->getName();
|
|
$temp['walletEnabled'] = $item->getBid()->isWalletEnable();
|
|
$temp['bankAcName'] = $item->getBid()->getWalletMatchBank()->getName();
|
|
$temp['bankAcShaba'] = $item->getBid()->getWalletMatchBank()->getShaba();
|
|
$temp['bankAcOwner'] = $item->getBid()->getWalletMatchBank()->getOwner();
|
|
$temp['bankAcCardNum'] = $item->getBid()->getWalletMatchBank()->getCardNum();
|
|
$temp['type'] = $item->getType();
|
|
$temp['cardPan'] = $item->getCardPan();
|
|
$temp['refID'] = $item->getRefID();
|
|
$temp['shaba'] = $item->getShaba();
|
|
$temp['amount'] = $item->getAmount();
|
|
$temp['dateSubmit'] = $jdate->jdate('Y/n/d H:i', $item->getDateSubmit());
|
|
$temp['gatePay'] = $item->getGatePay();
|
|
$resp[] = $temp;
|
|
}
|
|
return $this->json($resp);
|
|
}
|
|
|
|
#[Route('/api/admin/wallets/transactions/insert', name: 'app_admin_wallets_transactions_insert')]
|
|
public function app_admin_wallets_transactions_insert(registryMGR $registryMGR, SMS $SMS, Jdate $jdate, Notification $notification, Request $request, EntityManagerInterface $entityManager): JsonResponse
|
|
{
|
|
$params = [];
|
|
if ($content = $request->getContent()) {
|
|
$params = json_decode($content, true);
|
|
}
|
|
if (array_key_exists('bank', $params) && array_key_exists('refID', $params) && array_key_exists('bid', $params) && array_key_exists('amount', $params) && array_key_exists('shaba', $params) && array_key_exists('card', $params)) {
|
|
$bid = $entityManager->getRepository(Business::class)->find($params['bid']['id']);
|
|
if (!$bid)
|
|
throw $this->createNotFoundException();
|
|
$item = new WalletTransaction();
|
|
$item->setBid($bid);
|
|
$item->setType('pay');
|
|
$item->setShaba($params['shaba']);
|
|
$item->setAmount($params['amount']);
|
|
$item->setCardPan($params['card']);
|
|
$item->setDateSubmit(time());
|
|
$item->setDes('تراکنش تسویه کیف پول');
|
|
$item->setRefID($params['refID']);
|
|
$item->setGatePay($params['bank']);
|
|
$item->setBank($bid->getWalletMatchBank()->getName());
|
|
$entityManager->persist($item);
|
|
$entityManager->flush();
|
|
$notification->insert('تسویه کیف پول انجام شد.', '/acc/wallet/view', $bid, $bid->getOwner());
|
|
$SMS->send(
|
|
[$bid->getName()],
|
|
$registryMGR->get('sms', 'walletpay'),
|
|
$bid->getOwner()->getMobile()
|
|
);
|
|
return $this->json(['result' => 1]);
|
|
}
|
|
throw $this->createNotFoundException();
|
|
}
|
|
|
|
#[Route('/api/admin/logs/last', name: 'api_admin_logs_last')]
|
|
public function api_admin_logs_last(Extractor $extractor, Jdate $jdate, EntityManagerInterface $entityManager): JsonResponse
|
|
{
|
|
$logs = $entityManager->getRepository(\App\Entity\Log::class)->findBy([], ['id' => 'DESC'], 250);
|
|
$temps = [];
|
|
$logs = array_reverse($logs);
|
|
foreach ($logs as $log) {
|
|
$temp = [];
|
|
if ($log->getUser())
|
|
$temp['user'] = $log->getUser()->getFullName();
|
|
else
|
|
$temp['user'] = '';
|
|
$temp['des'] = $log->getDes();
|
|
$temp['part'] = $log->getPart();
|
|
$temp['bid'] = $log->getBid()->getName();
|
|
$temp['date'] = $jdate->jdate('Y/n/d H:i', $log->getDateSubmit());
|
|
$temp['ipaddress'] = $log->getIpaddress();
|
|
$temps[] = $temp;
|
|
}
|
|
return $this->json($extractor->operationSuccess(array_reverse($temps)));
|
|
}
|
|
|
|
#[Route('/api/admin/onlineusers/list', name: 'api_admin_online_users_list')]
|
|
public function api_admin_online_users_list(Extractor $extractor, Jdate $jdate, EntityManagerInterface $entityManager): JsonResponse
|
|
{
|
|
$tokens = $entityManager->getRepository(UserToken::class)->getOnlines(120);
|
|
$res = [];
|
|
foreach ($tokens as $token) {
|
|
$res[] = [
|
|
'name' => $token->getUser()->getFullName(),
|
|
'email' => $token->getUser()->getEmail(),
|
|
'mobile' => $token->getUser()->getMobile(),
|
|
'lastActive' => $token->getLastActive() - time(),
|
|
];
|
|
}
|
|
return $this->json($res);
|
|
}
|
|
|
|
#[Route('/api/admin/business/charge/add', name: 'admin_business_charge_add', methods: ['POST'])]
|
|
public function admin_business_charge_add(
|
|
Request $request,
|
|
EntityManagerInterface $entityManager,
|
|
Log $logService,
|
|
Jdate $jdate
|
|
): JsonResponse {
|
|
$params = json_decode($request->getContent(), true);
|
|
|
|
if (!isset($params['businessId']) || !isset($params['amount']) || !isset($params['description'])) {
|
|
return $this->json(['success' => false, 'message' => 'تمام فیلدهای ضروری را وارد کنید']);
|
|
}
|
|
|
|
$business = $entityManager->getRepository(Business::class)->find($params['businessId']);
|
|
if (!$business) {
|
|
return $this->json(['success' => false, 'message' => 'کسب و کار یافت نشد']);
|
|
}
|
|
|
|
$currentCharge = (float) ($business->getSmsCharge() ?? 0);
|
|
$newAmount = (float) $params['amount'];
|
|
$newCharge = $currentCharge + $newAmount;
|
|
|
|
$business->setSmsCharge((string) $newCharge);
|
|
$entityManager->persist($business);
|
|
$entityManager->flush();
|
|
|
|
// ثبت لاگ
|
|
$logService->insert(
|
|
'مدیریت اعتبار',
|
|
"افزایش اعتبار پیامک به مبلغ {$newAmount} ریال. اعتبار قبلی: {$currentCharge} ریال، اعتبار جدید: {$newCharge} ریال. توضیحات: {$params['description']}",
|
|
$this->getUser(),
|
|
$business
|
|
);
|
|
|
|
return $this->json([
|
|
'success' => true,
|
|
'message' => 'اعتبار با موفقیت افزایش یافت',
|
|
'data' => [
|
|
'previousCharge' => $currentCharge,
|
|
'newCharge' => $newCharge,
|
|
'addedAmount' => $newAmount
|
|
]
|
|
]);
|
|
}
|
|
|
|
#[Route('/api/admin/business/plugin/activate', name: 'admin_business_plugin_activate', methods: ['POST'])]
|
|
public function admin_business_plugin_activate(
|
|
Request $request,
|
|
EntityManagerInterface $entityManager,
|
|
Log $logService
|
|
): JsonResponse {
|
|
$params = json_decode($request->getContent(), true);
|
|
|
|
if (!isset($params['businessId']) || !isset($params['pluginCode']) || !isset($params['duration'])) {
|
|
return $this->json(['success' => false, 'message' => 'تمام فیلدهای ضروری را وارد کنید']);
|
|
}
|
|
|
|
$business = $entityManager->getRepository(Business::class)->find($params['businessId']);
|
|
if (!$business) {
|
|
return $this->json(['success' => false, 'message' => 'کسب و کار یافت نشد']);
|
|
}
|
|
|
|
$pluginProduct = $entityManager->getRepository(\App\Entity\PluginProdect::class)->findOneBy(['code' => $params['pluginCode']]);
|
|
if (!$pluginProduct) {
|
|
return $this->json(['success' => false, 'message' => 'افزونه یافت نشد']);
|
|
}
|
|
|
|
// بررسی اینکه آیا افزونه قبلاً فعال شده یا خیر
|
|
$existingPlugin = $entityManager->getRepository(\App\Entity\Plugin::class)->findOneBy([
|
|
'bid' => $business,
|
|
'name' => $params['pluginCode']
|
|
]);
|
|
|
|
$currentTime = time();
|
|
$expireTime = $currentTime + ($params['duration'] * 86400); // تبدیل روز به ثانیه
|
|
|
|
if ($existingPlugin) {
|
|
// اگر افزونه قبلاً فعال بوده، تاریخ انقضا را تمدید کن
|
|
$oldExpire = $existingPlugin->getDateExpire();
|
|
$existingPlugin->setDateExpire((string) $expireTime);
|
|
$existingPlugin->setStatus('100');
|
|
$entityManager->persist($existingPlugin);
|
|
} else {
|
|
// ایجاد افزونه جدید
|
|
$plugin = new \App\Entity\Plugin();
|
|
$plugin->setBid($business);
|
|
$plugin->setName($params['pluginCode']);
|
|
$plugin->setDateSubmit((string) $currentTime);
|
|
$plugin->setDateExpire((string) $expireTime);
|
|
$plugin->setStatus('100');
|
|
$plugin->setSubmitter($this->getUser());
|
|
$plugin->setPrice('0'); // رایگان برای ادمین
|
|
$plugin->setDes($params['description'] ?? 'فعالسازی توسط ادمین');
|
|
$entityManager->persist($plugin);
|
|
}
|
|
|
|
$entityManager->flush();
|
|
|
|
// ثبت لاگ
|
|
$durationText = $params['duration'] . ' روز';
|
|
$logService->insert(
|
|
'مدیریت افزونه',
|
|
"فعالسازی افزونه {$pluginProduct->getName()} برای مدت {$durationText}. توضیحات: " . (isset($params['description']) ? $params['description'] : 'فعالسازی توسط ادمین'),
|
|
$this->getUser(),
|
|
$business
|
|
);
|
|
|
|
return $this->json([
|
|
'success' => true,
|
|
'message' => 'افزونه با موفقیت فعال شد',
|
|
'data' => [
|
|
'pluginName' => $pluginProduct->getName(),
|
|
'expireDate' => date('Y-m-d H:i:s', $expireTime),
|
|
'duration' => $params['duration']
|
|
]
|
|
]);
|
|
}
|
|
|
|
#[Route('/api/admin/business/report/{id}', name: 'admin_business_report', methods: ['GET'])]
|
|
public function admin_business_report(
|
|
string $id,
|
|
EntityManagerInterface $entityManager,
|
|
Jdate $jdate
|
|
): JsonResponse {
|
|
$business = $entityManager->getRepository(Business::class)->find($id);
|
|
if (!$business) {
|
|
return $this->json(['success' => false, 'message' => 'کسب و کار یافت نشد']);
|
|
}
|
|
|
|
// آمار اشخاص
|
|
$personsCount = count($entityManager->getRepository(\App\Entity\Person::class)->findBy(['bid' => $business]));
|
|
|
|
// آمار کالا و خدمات
|
|
$commodityCount = count($entityManager->getRepository(\App\Entity\Commodity::class)->findBy(['bid' => $business]));
|
|
|
|
// آمار اسناد حسابداری
|
|
$hesabdariDocsCount = count($entityManager->getRepository(\App\Entity\HesabdariDoc::class)->findBy(['bid' => $business]));
|
|
|
|
// آمار اسناد انبار
|
|
$storeroomDocsCount = count($entityManager->getRepository(\App\Entity\StoreroomTicket::class)->findBy(['bid' => $business]));
|
|
|
|
// آمار بانکها
|
|
$bankAccountsCount = count($entityManager->getRepository(\App\Entity\BankAccount::class)->findBy(['bid' => $business]));
|
|
|
|
// آمار سالهای مالی
|
|
$yearsCount = count($entityManager->getRepository(\App\Entity\Year::class)->findBy(['bid' => $business]));
|
|
|
|
// آمار افزونههای فعال
|
|
$activePlugins = $entityManager->getRepository(\App\Entity\Plugin::class)->findBy([
|
|
'bid' => $business,
|
|
'status' => '100'
|
|
]);
|
|
$activePluginsCount = count($activePlugins);
|
|
|
|
// لیست افزونههای فعال
|
|
$activePluginsList = [];
|
|
foreach ($activePlugins as $plugin) {
|
|
$pluginProduct = $entityManager->getRepository(\App\Entity\PluginProdect::class)->findOneBy(['code' => $plugin->getName()]);
|
|
$activePluginsList[] = [
|
|
'name' => $pluginProduct ? $pluginProduct->getName() : $plugin->getName(),
|
|
'expireDate' => $jdate->jdate('Y/n/d H:i', $plugin->getDateExpire()),
|
|
'isExpired' => $plugin->getDateExpire() < time()
|
|
];
|
|
}
|
|
|
|
// محاسبه فضای آرشیو
|
|
$archiveFiles = $entityManager->getRepository(\App\Entity\ArchiveFile::class)->findBy(['bid' => $business]);
|
|
$totalArchiveSize = 0;
|
|
foreach ($archiveFiles as $file) {
|
|
$totalArchiveSize += (int) ($file->getFileSize() ? $file->getFileSize() : 0);
|
|
}
|
|
|
|
// آمار کیف پول
|
|
$walletTransactions = $entityManager->getRepository(\App\Entity\WalletTransaction::class)->findBy(['bid' => $business]);
|
|
$walletIncome = 0;
|
|
$walletExpense = 0;
|
|
foreach ($walletTransactions as $transaction) {
|
|
if ($transaction->getType() === 'sell') {
|
|
$walletIncome += (float) $transaction->getAmount();
|
|
} elseif ($transaction->getType() === 'pay') {
|
|
$walletExpense += (float) $transaction->getAmount();
|
|
}
|
|
}
|
|
|
|
$report = [
|
|
'businessInfo' => [
|
|
'id' => $business->getId(),
|
|
'name' => $business->getName(),
|
|
'legalName' => $business->getLegalName(),
|
|
'owner' => $business->getOwner()->getFullName(),
|
|
'ownerMobile' => $business->getOwner()->getMobile(),
|
|
'ownerEmail' => $business->getOwner()->getEmail(),
|
|
'dateRegister' => $jdate->jdate('Y/n/d H:i', $business->getDateSubmit()),
|
|
'field' => $business->getField(),
|
|
'type' => $business->getType(),
|
|
'address' => $business->getAddress(),
|
|
'tel' => $business->getTel(),
|
|
'mobile' => $business->getMobile(),
|
|
'email' => $business->getEmail(),
|
|
'website' => $business->getWesite(),
|
|
'shenasemeli' => $business->getShenasemeli(),
|
|
'codeeghtesadi' => $business->getCodeeghtesadi(),
|
|
'shomaresabt' => $business->getShomaresabt(),
|
|
'country' => $business->getCountry(),
|
|
'ostan' => $business->getOstan(),
|
|
'shahrestan' => $business->getShahrestan(),
|
|
'postalcode' => $business->getPostalcode(),
|
|
'maliyatafzode' => $business->getMaliyatafzode(),
|
|
'avatar' => $business->getAvatar(),
|
|
'sealFile' => $business->getSealFile(),
|
|
],
|
|
'statistics' => [
|
|
'personsCount' => $personsCount,
|
|
'commodityCount' => $commodityCount,
|
|
'hesabdariDocsCount' => $hesabdariDocsCount,
|
|
'storeroomDocsCount' => $storeroomDocsCount,
|
|
'bankAccountsCount' => $bankAccountsCount,
|
|
'yearsCount' => $yearsCount,
|
|
'activePluginsCount' => $activePluginsCount,
|
|
],
|
|
'financial' => [
|
|
'smsCharge' => (float) ($business->getSmsCharge() ?? 0),
|
|
'walletEnabled' => $business->isWalletEnable(),
|
|
'walletIncome' => $walletIncome,
|
|
'walletExpense' => $walletExpense,
|
|
'walletBalance' => $walletIncome - $walletExpense,
|
|
],
|
|
'storage' => [
|
|
'archiveSize' => $business->getArchiveSize(),
|
|
'totalArchiveSize' => $totalArchiveSize,
|
|
'archiveFilesCount' => count($archiveFiles),
|
|
],
|
|
'plugins' => [
|
|
'activeCount' => $activePluginsCount,
|
|
'activeList' => $activePluginsList,
|
|
],
|
|
'features' => [
|
|
'storeOnline' => $business->isStoreOnline(),
|
|
'shortlinks' => $business->isShortlinks(),
|
|
'walletEnable' => $business->isWalletEnable(),
|
|
'commodityUpdateSellPriceAuto' => $business->isCommodityUpdateSellPriceAuto(),
|
|
'commodityUpdateBuyPriceAuto' => $business->isCommodityUpdateBuyPriceAuto(),
|
|
'profitCalcType' => $business->getProfitCalcType(),
|
|
]
|
|
];
|
|
|
|
return $this->json([
|
|
'success' => true,
|
|
'data' => $report
|
|
]);
|
|
}
|
|
|
|
#[Route('/api/admin/business/wallet/balance/{id}', name: 'admin_business_wallet_balance', methods: ['GET'])]
|
|
public function admin_business_wallet_balance(
|
|
string $id,
|
|
EntityManagerInterface $entityManager,
|
|
Jdate $jdate
|
|
): JsonResponse {
|
|
$business = $entityManager->getRepository(Business::class)->find($id);
|
|
if (!$business) {
|
|
return $this->json(['success' => false, 'message' => 'کسب و کار یافت نشد']);
|
|
}
|
|
|
|
if (!$business->isWalletEnable()) {
|
|
return $this->json(['success' => false, 'message' => 'کیف پول برای این کسب و کار فعال نیست']);
|
|
}
|
|
|
|
// محاسبه موجودی با استفاده از repository
|
|
$walletBalance = $entityManager->getRepository(\App\Entity\WalletTransaction::class)->calculateWalletBalance($business);
|
|
|
|
// محاسبه درآمد و هزینه جداگانه
|
|
$walletSells = $entityManager->getRepository(\App\Entity\WalletTransaction::class)->findBy(['bid' => $business, 'type' => 'sell']);
|
|
$walletPays = $entityManager->getRepository(\App\Entity\WalletTransaction::class)->findBy(['bid' => $business, 'type' => 'pay']);
|
|
|
|
$totalIncome = 0;
|
|
foreach ($walletSells as $sell) {
|
|
$totalIncome += (float) $sell->getAmount();
|
|
}
|
|
|
|
$totalExpense = 0;
|
|
foreach ($walletPays as $pay) {
|
|
$totalExpense += (float) $pay->getAmount();
|
|
}
|
|
|
|
return $this->json([
|
|
'success' => true,
|
|
'data' => [
|
|
'businessId' => $business->getId(),
|
|
'businessName' => $business->getName(),
|
|
'walletBalance' => $walletBalance,
|
|
'totalIncome' => $totalIncome,
|
|
'totalExpense' => $totalExpense,
|
|
'transactionsCount' => [
|
|
'sell' => count($walletSells),
|
|
'pay' => count($walletPays)
|
|
],
|
|
'lastTransactions' => [
|
|
'sells' => array_slice(array_map(function($sell) use ($jdate) {
|
|
return [
|
|
'id' => $sell->getId(),
|
|
'amount' => (float) $sell->getAmount(),
|
|
'date' => $jdate->jdate('Y/n/d H:i', $sell->getDateSubmit()),
|
|
'description' => $sell->getDes()
|
|
];
|
|
}, $walletSells), 0, 5),
|
|
'pays' => array_slice(array_map(function($pay) use ($jdate) {
|
|
return [
|
|
'id' => $pay->getId(),
|
|
'amount' => (float) $pay->getAmount(),
|
|
'date' => $jdate->jdate('Y/n/d H:i', $pay->getDateSubmit()),
|
|
'description' => $pay->getDes(),
|
|
'refID' => $pay->getRefID()
|
|
];
|
|
}, $walletPays), 0, 5)
|
|
]
|
|
]
|
|
]);
|
|
}
|
|
|
|
#[Route('/api/admin/business/wallet/transactions/{id}', name: 'admin_business_wallet_transactions', methods: ['GET'])]
|
|
public function admin_business_wallet_transactions(
|
|
string $id,
|
|
EntityManagerInterface $entityManager,
|
|
Jdate $jdate,
|
|
Request $request
|
|
): JsonResponse {
|
|
$business = $entityManager->getRepository(Business::class)->find($id);
|
|
if (!$business) {
|
|
return $this->json(['success' => false, 'message' => 'کسب و کار یافت نشد']);
|
|
}
|
|
|
|
if (!$business->isWalletEnable()) {
|
|
return $this->json(['success' => false, 'message' => 'کیف پول برای این کسب و کار فعال نیست']);
|
|
}
|
|
|
|
// پارامترهای صفحهبندی
|
|
$page = max(1, (int) ($request->query->get('page', 1)));
|
|
$limit = max(1, min(100, (int) ($request->query->get('limit', 20))));
|
|
$offset = ($page - 1) * $limit;
|
|
|
|
// فیلتر نوع تراکنش
|
|
$type = $request->query->get('type'); // 'sell' یا 'pay' یا null برای همه
|
|
|
|
$qb = $entityManager->createQueryBuilder();
|
|
$qb->select('w')
|
|
->from(\App\Entity\WalletTransaction::class, 'w')
|
|
->where('w.bid = :business')
|
|
->setParameter('business', $business)
|
|
->orderBy('w.dateSubmit', 'DESC');
|
|
|
|
if ($type && in_array($type, ['sell', 'pay'])) {
|
|
$qb->andWhere('w.type = :type')
|
|
->setParameter('type', $type);
|
|
}
|
|
|
|
// محاسبه تعداد کل
|
|
$countQb = clone $qb;
|
|
$totalCount = $countQb->select('COUNT(w.id)')->getQuery()->getSingleScalarResult();
|
|
|
|
// اعمال صفحهبندی
|
|
$qb->setFirstResult($offset)
|
|
->setMaxResults($limit);
|
|
|
|
$transactions = $qb->getQuery()->getResult();
|
|
|
|
$transactionsData = [];
|
|
foreach ($transactions as $transaction) {
|
|
$transactionsData[] = [
|
|
'id' => $transaction->getId(),
|
|
'type' => $transaction->getType(),
|
|
'amount' => (float) $transaction->getAmount(),
|
|
'date' => $jdate->jdate('Y/n/d H:i', $transaction->getDateSubmit()),
|
|
'description' => $transaction->getDes(),
|
|
'refID' => $transaction->getRefID(),
|
|
'shaba' => $transaction->getShaba(),
|
|
'cardPan' => $transaction->getCardPan(),
|
|
'gatePay' => $transaction->getGatePay(),
|
|
'bank' => $transaction->getBank(),
|
|
'submitter' => $transaction->getSubmitter() ? $transaction->getSubmitter()->getFullName() : null
|
|
];
|
|
}
|
|
|
|
return $this->json([
|
|
'success' => true,
|
|
'data' => [
|
|
'businessId' => $business->getId(),
|
|
'businessName' => $business->getName(),
|
|
'transactions' => $transactionsData,
|
|
'pagination' => [
|
|
'page' => $page,
|
|
'limit' => $limit,
|
|
'total' => (int) $totalCount,
|
|
'totalPages' => ceil($totalCount / $limit)
|
|
]
|
|
]
|
|
]);
|
|
}
|
|
|
|
#[Route('/api/admin/business/plugins/list/{id}', name: 'admin_business_plugins_list', methods: ['GET'])]
|
|
public function admin_business_plugins_list(
|
|
string $id,
|
|
EntityManagerInterface $entityManager,
|
|
Jdate $jdate
|
|
): JsonResponse {
|
|
$business = $entityManager->getRepository(Business::class)->find($id);
|
|
if (!$business) {
|
|
return $this->json(['success' => false, 'message' => 'کسب و کار یافت نشد']);
|
|
}
|
|
|
|
// دریافت همه افزونههای موجود
|
|
$allPlugins = $entityManager->getRepository(\App\Entity\PluginProdect::class)->findAll();
|
|
|
|
// دریافت افزونههای فعال این کسب و کار
|
|
$businessPlugins = $entityManager->getRepository(\App\Entity\Plugin::class)->findBy([
|
|
'bid' => $business,
|
|
'status' => '100'
|
|
]);
|
|
$businessPluginCodes = array_map(fn($p) => $p->getName(), $businessPlugins);
|
|
|
|
$pluginsList = [];
|
|
foreach ($allPlugins as $plugin) {
|
|
$isActive = in_array($plugin->getCode(), $businessPluginCodes);
|
|
$businessPlugin = null;
|
|
|
|
if ($isActive) {
|
|
$businessPlugin = $entityManager->getRepository(\App\Entity\Plugin::class)->findOneBy([
|
|
'bid' => $business,
|
|
'name' => $plugin->getCode(),
|
|
'status' => '100'
|
|
]);
|
|
}
|
|
|
|
$pluginsList[] = [
|
|
'id' => $plugin->getId(),
|
|
'name' => $plugin->getName(),
|
|
'code' => $plugin->getCode(),
|
|
'price' => $plugin->getPrice(),
|
|
'timeLabel' => $plugin->getTimelabel(),
|
|
'icon' => $plugin->getIcon(),
|
|
'defaultOn' => $plugin->isDefaultOn(),
|
|
'isActive' => $isActive,
|
|
'expireDate' => $businessPlugin ? $jdate->jdate('Y/n/d H:i', $businessPlugin->getDateExpire()) : null,
|
|
'isExpired' => $businessPlugin ? $businessPlugin->getDateExpire() < time() : false,
|
|
'status' => $businessPlugin ? $businessPlugin->getStatus() : null,
|
|
];
|
|
}
|
|
|
|
return $this->json([
|
|
'success' => true,
|
|
'data' => $pluginsList
|
|
]);
|
|
}
|
|
|
|
}
|