add plugin controller to system
This commit is contained in:
parent
a962372289
commit
b935fdf6b2
|
@ -3,3 +3,7 @@ controllers:
|
||||||
path: ../src/Controller/
|
path: ../src/Controller/
|
||||||
namespace: App\Controller
|
namespace: App\Controller
|
||||||
type: attribute
|
type: attribute
|
||||||
|
app.swagger_ui:
|
||||||
|
path: /doc/api
|
||||||
|
methods: GET
|
||||||
|
defaults: { _controller: nelmio_api_doc.controller.swagger_ui }
|
||||||
|
|
|
@ -113,9 +113,9 @@ class CommodityController extends AbstractController
|
||||||
$temp['priceSell'] = $item->getPriceSell();
|
$temp['priceSell'] = $item->getPriceSell();
|
||||||
$temp['code'] = $item->getCode();
|
$temp['code'] = $item->getCode();
|
||||||
$temp['cat'] = null;
|
$temp['cat'] = null;
|
||||||
if ($item->getCat()){
|
if ($item->getCat()) {
|
||||||
$temp['cat'] = $item->getCat()->getName();
|
$temp['cat'] = $item->getCat()->getName();
|
||||||
$temp['catData'] = Explore::ExploreCommodityCat($item->getCat());
|
$temp['catData'] = Explore::ExploreCommodityCat($item->getCat());
|
||||||
}
|
}
|
||||||
$temp['khadamat'] = false;
|
$temp['khadamat'] = false;
|
||||||
if ($item->isKhadamat())
|
if ($item->isKhadamat())
|
||||||
|
@ -1315,4 +1315,150 @@ class CommodityController extends AbstractController
|
||||||
$log->insert('کالا/خدمات', 'قیمت تعدادی از کالاها به صورت گروهی ویرایش شد.', $this->getUser(), $acc['bid']->getId());
|
$log->insert('کالا/خدمات', 'قیمت تعدادی از کالاها به صورت گروهی ویرایش شد.', $this->getUser(), $acc['bid']->getId());
|
||||||
return $this->json($extractor->operationSuccess());
|
return $this->json($extractor->operationSuccess());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Route("/api/commodities/search", name="search_commodities", methods={"POST"})
|
||||||
|
*/
|
||||||
|
public function searchCommodities(Access $access, EntityManagerInterface $entityManagerInterface, Request $request): JsonResponse
|
||||||
|
{
|
||||||
|
$acc = $access->hasRole('commodity');
|
||||||
|
if (!$acc) {
|
||||||
|
throw $this->createAccessDeniedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
// لیست فیلدهای ممنوعه
|
||||||
|
$forbiddenFields = ['id', 'bid', 'submitter'];
|
||||||
|
|
||||||
|
// پارامترهای صفحهبندی
|
||||||
|
$page = max(1, $request->query->getInt('page', 1));
|
||||||
|
$limit = max(1, $request->query->getInt('limit', 10));
|
||||||
|
|
||||||
|
// دریافت فیلترهای ارسالی
|
||||||
|
$filters = json_decode($request->getContent(), true);
|
||||||
|
if (!is_array($filters)) {
|
||||||
|
$filters = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
// ساخت کوئری
|
||||||
|
$qb = $entityManagerInterface->getRepository(Commodity::class)->createQueryBuilder('c');
|
||||||
|
|
||||||
|
// شرط ثابت: bid.id همیشه برابر با $acc['bid']
|
||||||
|
$qb->andWhere('c.bid = :bid')
|
||||||
|
->setParameter('bid', $acc['bid']);
|
||||||
|
|
||||||
|
// اعمال فیلترهای کاربر
|
||||||
|
foreach ($filters as $field => $condition) {
|
||||||
|
if (in_array($field, $forbiddenFields)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isset($condition['operator']) || !isset($condition['value'])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$operator = $condition['operator'];
|
||||||
|
$value = $condition['value'];
|
||||||
|
$paramName = str_replace('.', '_', $field) . '_param';
|
||||||
|
|
||||||
|
switch ($operator) {
|
||||||
|
case '=':
|
||||||
|
$qb->andWhere("c.$field = :$paramName")
|
||||||
|
->setParameter($paramName, $value);
|
||||||
|
break;
|
||||||
|
case '>':
|
||||||
|
$qb->andWhere("c.$field > :$paramName")
|
||||||
|
->setParameter($paramName, $value);
|
||||||
|
break;
|
||||||
|
case '<':
|
||||||
|
$qb->andWhere("c.$field < :$paramName")
|
||||||
|
->setParameter($paramName, $value);
|
||||||
|
break;
|
||||||
|
case '%':
|
||||||
|
$qb->andWhere("c.$field LIKE :$paramName")
|
||||||
|
->setParameter($paramName, "%$value%");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// مرتبسازی پیشفرض بر اساس code (نزولی)
|
||||||
|
$qb->orderBy('c.code', 'DESC');
|
||||||
|
|
||||||
|
// شمارش کل نتایج
|
||||||
|
$countQb = clone $qb;
|
||||||
|
$totalItems = $countQb->select('COUNT(c.id)')->getQuery()->getSingleScalarResult();
|
||||||
|
|
||||||
|
// اعمال صفحهبندی
|
||||||
|
$qb->setFirstResult(($page - 1) * $limit)
|
||||||
|
->setMaxResults($limit);
|
||||||
|
|
||||||
|
// اجرای کوئری
|
||||||
|
$results = $qb->getQuery()->getResult();
|
||||||
|
|
||||||
|
// تبدیل نتایج به آرایه
|
||||||
|
$data = array_map(function (Commodity $item) use ($entityManagerInterface, $acc): array {
|
||||||
|
$temp = [];
|
||||||
|
$temp['id'] = $item->getId();
|
||||||
|
$temp['name'] = $item->getName();
|
||||||
|
$temp['unit'] = $item->getUnit()->getName();
|
||||||
|
$temp['des'] = $item->getDes();
|
||||||
|
$temp['priceBuy'] = $item->getPriceBuy();
|
||||||
|
$temp['speedAccess'] = $item->isSpeedAccess();
|
||||||
|
$temp['priceSell'] = $item->getPriceSell();
|
||||||
|
$temp['code'] = $item->getCode();
|
||||||
|
$temp['cat'] = null;
|
||||||
|
if ($item->getCat()) {
|
||||||
|
$temp['cat'] = $item->getCat()->getName();
|
||||||
|
$temp['catData'] = Explore::ExploreCommodityCat($item->getCat());
|
||||||
|
}
|
||||||
|
$temp['khadamat'] = false;
|
||||||
|
if ($item->isKhadamat()) {
|
||||||
|
$temp['khadamat'] = true;
|
||||||
|
}
|
||||||
|
$temp['withoutTax'] = false;
|
||||||
|
if ($item->isWithoutTax()) {
|
||||||
|
$temp['withoutTax'] = true;
|
||||||
|
}
|
||||||
|
$temp['commodityCountCheck'] = $item->isCommodityCountCheck();
|
||||||
|
$temp['minOrderCount'] = $item->getMinOrderCount();
|
||||||
|
$temp['dayLoading'] = $item->getDayLoading();
|
||||||
|
$temp['orderPoint'] = $item->getOrderPoint();
|
||||||
|
$temp['unitData'] = [
|
||||||
|
'name' => $item->getUnit()->getName(),
|
||||||
|
'floatNumber' => $item->getUnit()->getFloatNumber(),
|
||||||
|
];
|
||||||
|
$temp['barcodes'] = $item->getBarcodes();
|
||||||
|
// محاسبه موجودی
|
||||||
|
if ($item->isKhadamat()) {
|
||||||
|
$temp['count'] = 0;
|
||||||
|
} else {
|
||||||
|
$rows = $entityManagerInterface->getRepository(HesabdariRow::class)->findBy([
|
||||||
|
'bid' => $acc['bid'],
|
||||||
|
'commodity' => $item
|
||||||
|
]);
|
||||||
|
$count = 0;
|
||||||
|
foreach ($rows as $row) {
|
||||||
|
if ($row->getDoc()->getType() == 'buy') {
|
||||||
|
$count += $row->getCommdityCount();
|
||||||
|
} elseif ($row->getDoc()->getType() == 'sell') {
|
||||||
|
$count -= $row->getCommdityCount();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$temp['count'] = $count;
|
||||||
|
}
|
||||||
|
return $temp;
|
||||||
|
}, $results);
|
||||||
|
|
||||||
|
// اطلاعات صفحهبندی
|
||||||
|
$totalPages = ceil($totalItems / $limit);
|
||||||
|
|
||||||
|
return new JsonResponse([
|
||||||
|
'results' => $data,
|
||||||
|
'pagination' => [
|
||||||
|
'current_page' => $page,
|
||||||
|
'per_page' => $limit,
|
||||||
|
'total_items' => $totalItems,
|
||||||
|
'total_pages' => $totalPages,
|
||||||
|
],
|
||||||
|
], 200);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -302,7 +302,7 @@ class PersonsController extends AbstractController
|
||||||
$person->setCompany($params['company']);
|
$person->setCompany($params['company']);
|
||||||
if (array_key_exists('prelabel', $params)) {
|
if (array_key_exists('prelabel', $params)) {
|
||||||
if ($params['prelabel'] != '') {
|
if ($params['prelabel'] != '') {
|
||||||
$prelabel = $entityManager->getRepository(PersonPrelabel::class)->findOneBy(['code' => $params['prelabel']['code']]);
|
$prelabel = $entityManager->getRepository(PersonPrelabel::class)->findOneBy(['label' => $params['prelabel']]);
|
||||||
if ($prelabel) {
|
if ($prelabel) {
|
||||||
$person->setPrelabel($prelabel);
|
$person->setPrelabel($prelabel);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,11 +2,10 @@
|
||||||
|
|
||||||
namespace App\Controller;
|
namespace App\Controller;
|
||||||
|
|
||||||
use App\Entity\Business;
|
|
||||||
use App\Entity\Plugin;
|
use App\Entity\Plugin;
|
||||||
use App\Entity\PluginProdect;
|
use App\Entity\PluginProdect;
|
||||||
use App\Entity\Settings;
|
|
||||||
use App\Service\Access;
|
use App\Service\Access;
|
||||||
|
use App\Service\Extractor;
|
||||||
use App\Service\Jdate;
|
use App\Service\Jdate;
|
||||||
use App\Service\Log;
|
use App\Service\Log;
|
||||||
use App\Service\PayMGR;
|
use App\Service\PayMGR;
|
||||||
|
@ -18,128 +17,351 @@ use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Routing\Annotation\Route;
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||||
|
use OpenApi\Annotations as OA;
|
||||||
|
|
||||||
class PluginController extends AbstractController
|
class PluginController extends AbstractController
|
||||||
{
|
{
|
||||||
#[Route('/api/plugin/get/info/{id}', name: 'api_plugin_get_info')]
|
private const PRICE_MULTIPLIER = 1.09; // ضریب قیمت به صورت ثابت برای محاسبه
|
||||||
public function api_plugin_get_info(string $id, Access $access, Jdate $jdate, EntityManagerInterface $entityManager, Log $log): JsonResponse
|
|
||||||
|
/**
|
||||||
|
* بررسی دسترسی کاربر با نقش مشخص
|
||||||
|
*
|
||||||
|
* @param Access $access سرویس مدیریت دسترسی
|
||||||
|
* @param string $role نقش مورد نیاز
|
||||||
|
* @return array اطلاعات دسترسی کاربر
|
||||||
|
* @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException در صورت عدم دسترسی
|
||||||
|
*/
|
||||||
|
private function checkAccess(Access $access, string $role): array
|
||||||
{
|
{
|
||||||
$acc = $access->hasRole('join');
|
$acc = $access->hasRole($role);
|
||||||
if (!$acc)
|
if (!$acc) {
|
||||||
throw $this->createAccessDeniedException();
|
throw $this->createAccessDeniedException('شما دسترسی لازم را ندارید.');
|
||||||
$item = $entityManager->getRepository(PluginProdect::class)->findOneBy([
|
}
|
||||||
'code' => $id
|
return $acc;
|
||||||
]);
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* دریافت اطلاعات یک افزونه خاص
|
||||||
|
*
|
||||||
|
* @OA\Post(
|
||||||
|
* path="/api/plugin/get/info/{id}",
|
||||||
|
* summary="دریافت اطلاعات افزونه با کد مشخص",
|
||||||
|
* tags={"Plugins"},
|
||||||
|
* @OA\Parameter(
|
||||||
|
* name="id",
|
||||||
|
* in="path",
|
||||||
|
* description="کد افزونه",
|
||||||
|
* required=true,
|
||||||
|
* @OA\Schema(type="string")
|
||||||
|
* ),
|
||||||
|
* @OA\Response(
|
||||||
|
* response=200,
|
||||||
|
* description="اطلاعات افزونه",
|
||||||
|
* @OA\JsonContent(ref="#/components/schemas/PluginProdect")
|
||||||
|
* ),
|
||||||
|
* @OA\Response(response=403, description="دسترسی غیرمجاز"),
|
||||||
|
* @OA\Response(response=404, description="افزونه یافت نشد")
|
||||||
|
* )
|
||||||
|
*/
|
||||||
|
#[Route('/api/plugin/get/info/{id}', name: 'api_plugin_get_info', methods: ["POST"])]
|
||||||
|
public function api_plugin_get_info(string $id, Access $access, EntityManagerInterface $entityManager): JsonResponse
|
||||||
|
{
|
||||||
|
$this->checkAccess($access, 'join');
|
||||||
|
$item = $entityManager->getRepository(PluginProdect::class)->findOneBy(['code' => $id])
|
||||||
|
?? throw $this->createNotFoundException('افزونه یافت نشد');
|
||||||
return $this->json($item);
|
return $this->json($item);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Route('/api/plugin/insert/{id}', name: 'api_plugin_insert')]
|
/**
|
||||||
|
* ثبت یک افزونه جدید و ایجاد درخواست پرداخت
|
||||||
|
*
|
||||||
|
* @OA\Post(
|
||||||
|
* path="/api/plugin/insert/{id}",
|
||||||
|
* summary="ثبت افزونه جدید و صدور فاکتور پرداخت",
|
||||||
|
* tags={"Plugins"},
|
||||||
|
* @OA\Parameter(
|
||||||
|
* name="id",
|
||||||
|
* in="path",
|
||||||
|
* description="شناسه محصول افزونه",
|
||||||
|
* required=true,
|
||||||
|
* @OA\Schema(type="string")
|
||||||
|
* ),
|
||||||
|
* @OA\Response(
|
||||||
|
* response=200,
|
||||||
|
* description="نتیجه درخواست پرداخت",
|
||||||
|
* @OA\JsonContent(type="object")
|
||||||
|
* ),
|
||||||
|
* @OA\Response(response=403, description="دسترسی غیرمجاز"),
|
||||||
|
* @OA\Response(response=404, description="افزونه یافت نشد")
|
||||||
|
* )
|
||||||
|
*/
|
||||||
|
#[Route('/api/plugin/insert/{id}', name: 'api_plugin_insert', methods: ["POST"])]
|
||||||
public function api_plugin_insert(string $id, Log $log, twigFunctions $twigFunctions, PayMGR $payMGR, Access $access, EntityManagerInterface $entityManager): Response
|
public function api_plugin_insert(string $id, Log $log, twigFunctions $twigFunctions, PayMGR $payMGR, Access $access, EntityManagerInterface $entityManager): Response
|
||||||
{
|
{
|
||||||
$acc = $access->hasRole('join');
|
$acc = $this->checkAccess($access, 'join');
|
||||||
if (!$acc)
|
$pp = $entityManager->getRepository(PluginProdect::class)->find($id)
|
||||||
throw $this->createAccessDeniedException();
|
?? throw $this->createNotFoundException('افزونه یافت نشد');
|
||||||
$pp = $entityManager->getRepository(PluginProdect::class)->find($id);
|
|
||||||
if (!$pp)
|
|
||||||
throw $this->createNotFoundException('plugin not found');
|
|
||||||
//get system settings
|
|
||||||
$settings = $twigFunctions->systemSettings();
|
|
||||||
$plugin = new Plugin();
|
$plugin = new Plugin();
|
||||||
$plugin->setBid($acc['bid']);
|
$plugin->setBid($acc['bid'])
|
||||||
$plugin->setSubmitter($this->getUser());
|
->setSubmitter($this->getUser())
|
||||||
$plugin->setDateSubmit(time());
|
->setDateSubmit(time())
|
||||||
$plugin->setStatus(0);
|
->setStatus(0)
|
||||||
$plugin->setDes($pp->getName());
|
->setDes($pp->getName())
|
||||||
$plugin->setName($pp->getCode());
|
->setName($pp->getCode())
|
||||||
$plugin->setPrice(($pp->getPrice() * 109) / 10);
|
->setPrice($pp->getPrice() * self::PRICE_MULTIPLIER)
|
||||||
$plugin->setDateExpire(time() + $pp->getTimestamp());
|
->setDateExpire(time() + $pp->getTimestamp());
|
||||||
|
|
||||||
$entityManager->persist($plugin);
|
$entityManager->persist($plugin);
|
||||||
$entityManager->flush();
|
|
||||||
$result = $payMGR->createRequest(($pp->getPrice() * 109) / 10, $this->generateUrl('api_plugin_buy_verify', ['id' => $plugin->getId()], UrlGeneratorInterface::ABSOLUTE_URL), 'خرید فضای ابری');
|
$result = $payMGR->createRequest(
|
||||||
if ($result['Success']) {
|
$plugin->getPrice(),
|
||||||
$plugin->setGatePay($result['gate']);
|
$this->generateUrl('api_plugin_buy_verify', ['id' => $plugin->getId()], UrlGeneratorInterface::ABSOLUTE_URL),
|
||||||
$plugin->setVerifyCode($result['authkey']);
|
'خرید فضای ابری'
|
||||||
$entityManager->persist($plugin);
|
);
|
||||||
$entityManager->flush();
|
|
||||||
$entityManager->persist($plugin);
|
if ($result['Success'] ?? false) {
|
||||||
$entityManager->flush();
|
$plugin->setGatePay($result['gate'])
|
||||||
|
->setVerifyCode($result['authkey']);
|
||||||
$log->insert('بازار افزونهها', 'صدور فاکتور افزونه ' . $pp->getName(), $this->getUser(), $acc['bid']);
|
$log->insert('بازار افزونهها', 'صدور فاکتور افزونه ' . $pp->getName(), $this->getUser(), $acc['bid']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$entityManager->flush();
|
||||||
return $this->json($result);
|
return $this->json($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Route('/api/plugin/buy/verify/{id}', name: 'api_plugin_buy_verify')]
|
/**
|
||||||
|
* تأیید پرداخت خرید افزونه
|
||||||
|
*
|
||||||
|
* @OA\Post(
|
||||||
|
* path="/api/plugin/buy/verify/{id}",
|
||||||
|
* summary="تأیید پرداخت و فعالسازی افزونه",
|
||||||
|
* tags={"Plugins"},
|
||||||
|
* @OA\Parameter(
|
||||||
|
* name="id",
|
||||||
|
* in="path",
|
||||||
|
* description="شناسه افزونه",
|
||||||
|
* required=true,
|
||||||
|
* @OA\Schema(type="string")
|
||||||
|
* ),
|
||||||
|
* @OA\Response(response=200, description="پرداخت موفق و فعالسازی افزونه"),
|
||||||
|
* @OA\Response(response=400, description="پرداخت ناموفق"),
|
||||||
|
* @OA\Response(response=404, description="افزونه یافت نشد")
|
||||||
|
* )
|
||||||
|
*/
|
||||||
|
#[Route('/api/plugin/buy/verify/{id}', name: 'api_plugin_buy_verify', methods: ["POST"])]
|
||||||
public function api_plugin_buy_verify(string $id, twigFunctions $twigFunctions, PayMGR $payMGR, Request $request, EntityManagerInterface $entityManager, Log $log): Response
|
public function api_plugin_buy_verify(string $id, twigFunctions $twigFunctions, PayMGR $payMGR, Request $request, EntityManagerInterface $entityManager, Log $log): Response
|
||||||
{
|
{
|
||||||
$req = $entityManager->getRepository(Plugin::class)->find($id);
|
$req = $entityManager->getRepository(Plugin::class)->find($id)
|
||||||
if (!$req)
|
?? throw $this->createNotFoundException('درخواست افزونه یافت نشد');
|
||||||
throw $this->createNotFoundException('');
|
|
||||||
$res = $payMGR->verify($req->getPrice(), $req->getVerifyCode(), $request);
|
$res = $payMGR->verify($req->getPrice(), $req->getVerifyCode(), $request);
|
||||||
if ($res['Success'] == false) {
|
|
||||||
|
if (!($res['Success'] ?? false)) {
|
||||||
$log->insert(
|
$log->insert(
|
||||||
'بازار افزونهها' . $req->getName(),
|
'بازار افزونهها ' . $req->getName(),
|
||||||
'پرداخت ناموفق صورتحساب خرید افزونه',
|
'پرداخت ناموفق صورتحساب خرید افزونه',
|
||||||
$req->getSubmitter(),
|
$req->getSubmitter(),
|
||||||
$req->getBid()
|
$req->getBid()
|
||||||
);
|
);
|
||||||
return $this->render('buy/fail.html.twig', ['results' => $res]);
|
return $this->render('buy/fail.html.twig', ['results' => $res]);
|
||||||
} else {
|
|
||||||
$req->setStatus(100);
|
|
||||||
$req->setRefID($res['refID']);
|
|
||||||
$req->setCardPan($res['card_pan']);
|
|
||||||
$entityManager->persist($req);
|
|
||||||
$entityManager->flush();
|
|
||||||
$log->insert(
|
|
||||||
'افزونه ' . $req->getName(),
|
|
||||||
'افزونه جدید خریداری و فعال شد.',
|
|
||||||
$req->getSubmitter(),
|
|
||||||
$req->getBid()
|
|
||||||
);
|
|
||||||
return $this->render('buy/success.html.twig', ['req' => $req]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$req->setStatus(100)
|
||||||
|
->setRefID($res['refID'] ?? '')
|
||||||
|
->setCardPan($res['card_pan'] ?? '');
|
||||||
|
$entityManager->persist($req);
|
||||||
|
$entityManager->flush();
|
||||||
|
$log->insert(
|
||||||
|
'افزونه ' . $req->getName(),
|
||||||
|
'افزونه جدید خریداری و فعال شد.',
|
||||||
|
$req->getSubmitter(),
|
||||||
|
$req->getBid()
|
||||||
|
);
|
||||||
|
return $this->render('buy/success.html.twig', ['req' => $req]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Route('/api/plugin/get/actives', name: 'api_plugin_get_actives')]
|
/**
|
||||||
public function api_plugin_get_actives(Access $access, Jdate $jdate, EntityManagerInterface $entityManager, Log $log): JsonResponse
|
* دریافت لیست افزونههای فعال
|
||||||
|
*
|
||||||
|
* @OA\Post(
|
||||||
|
* path="/api/plugin/get/actives",
|
||||||
|
* summary="دریافت افزونههای فعال برای کسبوکار",
|
||||||
|
* tags={"Plugins"},
|
||||||
|
* @OA\Response(
|
||||||
|
* response=200,
|
||||||
|
* description="لیست افزونههای فعال",
|
||||||
|
* @OA\JsonContent(type="object")
|
||||||
|
* ),
|
||||||
|
* @OA\Response(response=403, description="دسترسی غیرمجاز")
|
||||||
|
* )
|
||||||
|
*/
|
||||||
|
#[Route('/api/plugin/get/actives', name: 'api_plugin_get_actives', methods: ["POST"])]
|
||||||
|
public function api_plugin_get_actives(Access $access, Jdate $jdate, EntityManagerInterface $entityManager): JsonResponse
|
||||||
{
|
{
|
||||||
$acc = $access->hasRole('join');
|
$acc = $this->checkAccess($access, 'join');
|
||||||
if (!$acc)
|
|
||||||
throw $this->createAccessDeniedException();
|
|
||||||
$plugins = $entityManager->getRepository(Plugin::class)->findActivePlugins($acc['bid']);
|
$plugins = $entityManager->getRepository(Plugin::class)->findActivePlugins($acc['bid']);
|
||||||
$temp = [];
|
$temp = [];
|
||||||
|
|
||||||
foreach ($plugins as $plugin) {
|
foreach ($plugins as $plugin) {
|
||||||
$plugin->setDateExpire($jdate->jdate('Y/n/d', $plugin->getDateExpire()));
|
$pluginName = $plugin->getName();
|
||||||
$temp[$plugin->getName()] = $plugin;
|
$temp[$pluginName] = $temp[$pluginName] ?? [
|
||||||
|
'id' => $plugin->getId(),
|
||||||
|
'dateExpire' => $jdate->jdate('Y/n/d', $plugin->getDateExpire()),
|
||||||
|
'name' => $pluginName,
|
||||||
|
'des' => $plugin->getDes(),
|
||||||
|
'dateSubmit' => $plugin->getDateSubmit()
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$pluginProducts = $entityManager->getRepository(PluginProdect::class)->findBy(['defaultOn' => true]);
|
||||||
|
foreach ($pluginProducts as $plugin) {
|
||||||
|
$pluginName = $plugin->getCode();
|
||||||
|
$temp[$pluginName] = $temp[$pluginName] ?? [
|
||||||
|
'id' => $plugin->getId(),
|
||||||
|
'dateExpire' => $jdate->jdate('Y/n/d', time() + 96200),
|
||||||
|
'name' => $pluginName,
|
||||||
|
'des' => $plugin->getName(),
|
||||||
|
'dateSubmit' => time(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
return $this->json($temp);
|
return $this->json($temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Route('/api/plugin/get/paids', name: 'api_plugin_get_paids')]
|
/**
|
||||||
public function api_plugin_get_paids(Access $access, Jdate $jdate, EntityManagerInterface $entityManager, Log $log): JsonResponse
|
* دریافت لیست افزونههای پرداختشده
|
||||||
|
*
|
||||||
|
* @OA\Post(
|
||||||
|
* path="/api/plugin/get/paids",
|
||||||
|
* summary="دریافت افزونههای پرداختشده برای کسبوکار",
|
||||||
|
* tags={"Plugins"},
|
||||||
|
* @OA\Response(
|
||||||
|
* response=200,
|
||||||
|
* description="لیست افزونههای پرداختشده",
|
||||||
|
* @OA\JsonContent(type="array", @OA\Items(ref="#/components/schemas/Plugin"))
|
||||||
|
* ),
|
||||||
|
* @OA\Response(response=403, description="دسترسی غیرمجاز")
|
||||||
|
* )
|
||||||
|
*/
|
||||||
|
#[Route('/api/plugin/get/paids', name: 'api_plugin_get_paids', methods: ["POST"])]
|
||||||
|
public function api_plugin_get_paids(Access $access, Jdate $jdate, EntityManagerInterface $entityManager): JsonResponse
|
||||||
{
|
{
|
||||||
$acc = $access->hasRole('join');
|
$acc = $this->checkAccess($access, 'join');
|
||||||
if (!$acc)
|
$plugins = $entityManager->getRepository(Plugin::class)->findBy(['bid' => $acc['bid']]);
|
||||||
throw $this->createAccessDeniedException();
|
|
||||||
$plugins = $entityManager->getRepository(Plugin::class)->findBy([
|
|
||||||
'bid' => $acc['bid'],
|
|
||||||
]);
|
|
||||||
$temp = [];
|
|
||||||
foreach ($plugins as $plugin) {
|
foreach ($plugins as $plugin) {
|
||||||
$plugin->setDateExpire($jdate->jdate('Y/n/d', $plugin->getDateExpire()));
|
$plugin->setDateExpire($jdate->jdate('Y/n/d', $plugin->getDateExpire()));
|
||||||
$plugin->setDateSubmit($jdate->jdate('Y/n/d', $plugin->getDateSubmit()));
|
$plugin->setDateSubmit($jdate->jdate('Y/n/d', $plugin->getDateSubmit()));
|
||||||
$plugin->setPrice(number_format($plugin->getPrice()));
|
$plugin->setPrice(number_format($plugin->getPrice()));
|
||||||
|
|
||||||
}
|
}
|
||||||
return $this->json($plugins);
|
|
||||||
}
|
|
||||||
#[Route('/api/plugin/get/all', name: 'api_plugin_get_all')]
|
|
||||||
public function api_plugin_get_all(Access $access, Jdate $jdate, EntityManagerInterface $entityManager, Log $log): JsonResponse
|
|
||||||
{
|
|
||||||
$acc = $access->hasRole('join');
|
|
||||||
if (!$acc)
|
|
||||||
throw $this->createAccessDeniedException();
|
|
||||||
$plugins = $entityManager->getRepository(PluginProdect::class)->findAll();
|
|
||||||
return $this->json($plugins);
|
return $this->json($plugins);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* دریافت همه افزونههای موجود (غیر پیشفرض)
|
||||||
|
*
|
||||||
|
* @OA\Post(
|
||||||
|
* path="/api/plugin/get/all",
|
||||||
|
* summary="دریافت همه افزونههای غیر پیشفرض",
|
||||||
|
* tags={"Plugins"},
|
||||||
|
* @OA\Response(
|
||||||
|
* response=200,
|
||||||
|
* description="لیست افزونهها",
|
||||||
|
* @OA\JsonContent(type="array", @OA\Items(ref="#/components/schemas/PluginProdect"))
|
||||||
|
* ),
|
||||||
|
* @OA\Response(response=403, description="دسترسی غیرمجاز")
|
||||||
|
* )
|
||||||
|
*/
|
||||||
|
#[Route('/api/plugin/get/all', name: 'api_plugin_get_all', methods: ["POST"])]
|
||||||
|
public function api_plugin_get_all(Access $access, EntityManagerInterface $entityManager): JsonResponse
|
||||||
|
{
|
||||||
|
$this->checkAccess($access, 'join');
|
||||||
|
$plugins = $entityManager->getRepository(PluginProdect::class)
|
||||||
|
->createQueryBuilder('p')
|
||||||
|
->where('p.defaultOn = :falseValue OR p.defaultOn IS NULL')
|
||||||
|
->setParameter('falseValue', false)
|
||||||
|
->getQuery()
|
||||||
|
->getResult();
|
||||||
|
|
||||||
|
return $this->json($plugins);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* دریافت لیست همه افزونهها (برای ادمین)
|
||||||
|
*
|
||||||
|
* @OA\Post(
|
||||||
|
* path="/api/admin/plugins/list",
|
||||||
|
* summary="دریافت لیست کامل افزونهها (ادمین)",
|
||||||
|
* tags={"Admin Plugins"},
|
||||||
|
* @OA\Response(
|
||||||
|
* response=200,
|
||||||
|
* description="لیست همه افزونهها",
|
||||||
|
* @OA\JsonContent(type="array", @OA\Items(type="object"))
|
||||||
|
* )
|
||||||
|
* )
|
||||||
|
*/
|
||||||
|
#[Route('/api/admin/plugins/list', name: 'api_admin_plugins_get_all', methods: ["POST"])]
|
||||||
|
public function api_admin_plugins_get_all(EntityManagerInterface $entityManager): JsonResponse
|
||||||
|
{
|
||||||
|
$plugins = $entityManager->getRepository(PluginProdect::class)->findAll();
|
||||||
|
$res = array_map(fn($plugin) => [
|
||||||
|
'id' => $plugin->getId(),
|
||||||
|
'name' => $plugin->getName(),
|
||||||
|
'price' => $plugin->getPrice(),
|
||||||
|
'time' => $plugin->getTimestamp(),
|
||||||
|
'defaultOn' => $plugin->isDefaultOn(),
|
||||||
|
'timeLabel' => $plugin->getTimelabel(),
|
||||||
|
], $plugins);
|
||||||
|
|
||||||
|
return $this->json($res);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* بهروزرسانی اطلاعات یک افزونه (برای ادمین)
|
||||||
|
*
|
||||||
|
* @OA\Post(
|
||||||
|
* path="/api/admin/plugin/update/data",
|
||||||
|
* summary="بهروزرسانی اطلاعات افزونه (ادمین)",
|
||||||
|
* tags={"Admin Plugins"},
|
||||||
|
* @OA\RequestBody(
|
||||||
|
* required=true,
|
||||||
|
* @OA\JsonContent(
|
||||||
|
* type="object",
|
||||||
|
* @OA\Property(property="id", type="string", description="شناسه افزونه"),
|
||||||
|
* @OA\Property(property="name", type="string", description="نام افزونه"),
|
||||||
|
* @OA\Property(property="price", type="number", description="قیمت"),
|
||||||
|
* @OA\Property(property="time", type="integer", description="مدت زمان"),
|
||||||
|
* @OA\Property(property="timeLabel", type="string", description="برچسب زمان"),
|
||||||
|
* @OA\Property(property="defaultOn", type="boolean", description="وضعیت پیشفرض")
|
||||||
|
* )
|
||||||
|
* ),
|
||||||
|
* @OA\Response(response=200, description="بهروزرسانی موفق"),
|
||||||
|
* @OA\Response(response=400, description="پارامترها ناقص"),
|
||||||
|
* @OA\Response(response=404, description="افزونه یافت نشد")
|
||||||
|
* )
|
||||||
|
*/
|
||||||
|
#[Route('/api/admin/plugin/update/data', name: 'api_admin_plugin_update_data', methods: ["POST"])]
|
||||||
|
public function api_admin_plugin_update_data(Extractor $extractor, Request $request, EntityManagerInterface $entityManager): JsonResponse
|
||||||
|
{
|
||||||
|
$params = $request->getPayload()->all();
|
||||||
|
if (!isset($params['id'])) {
|
||||||
|
return $this->json($extractor->paramsNotSend());
|
||||||
|
}
|
||||||
|
|
||||||
|
$plugin = $entityManager->getRepository(PluginProdect::class)->find($params['id'])
|
||||||
|
?? throw $this->createNotFoundException('افزونه یافت نشد');
|
||||||
|
|
||||||
|
$plugin->setPrice($params['price'] ?? $plugin->getPrice())
|
||||||
|
->setName($params['name'] ?? $plugin->getName())
|
||||||
|
->setTimelabel($params['timeLabel'] ?? $plugin->getTimelabel())
|
||||||
|
->setDefaultOn($params['defaultOn'] ?? $plugin->isDefaultOn())
|
||||||
|
->setTimestamp($params['time'] ?? $plugin->getTimestamp());
|
||||||
|
|
||||||
|
$entityManager->persist($plugin);
|
||||||
|
$entityManager->flush();
|
||||||
|
|
||||||
|
return $this->json($extractor->operationSuccess());
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -31,6 +31,9 @@ class PluginProdect
|
||||||
#[ORM\Column(length: 255, nullable: true)]
|
#[ORM\Column(length: 255, nullable: true)]
|
||||||
private ?string $icon = null;
|
private ?string $icon = null;
|
||||||
|
|
||||||
|
#[ORM\Column(nullable: true)]
|
||||||
|
private ?bool $defaultOn = null;
|
||||||
|
|
||||||
public function getId(): ?int
|
public function getId(): ?int
|
||||||
{
|
{
|
||||||
return $this->id;
|
return $this->id;
|
||||||
|
@ -107,4 +110,16 @@ class PluginProdect
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isDefaultOn(): ?bool
|
||||||
|
{
|
||||||
|
return $this->defaultOn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDefaultOn(?bool $defaultOn): static
|
||||||
|
{
|
||||||
|
$this->defaultOn = $defaultOn;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -313,7 +313,7 @@ class Explore
|
||||||
'birthday' => $person->getBirthday(),
|
'birthday' => $person->getBirthday(),
|
||||||
'speedAccess' => $person->isSpeedAccess(),
|
'speedAccess' => $person->isSpeedAccess(),
|
||||||
'address' => $person->getAddress(),
|
'address' => $person->getAddress(),
|
||||||
'prelabel' => '',
|
'prelabel' => null,
|
||||||
];
|
];
|
||||||
if ($person->getPrelabel()) {
|
if ($person->getPrelabel()) {
|
||||||
$res['prelabel'] = $person->getPrelabel()->getLabel();
|
$res['prelabel'] = $person->getPrelabel()->getLabel();
|
||||||
|
|
|
@ -50,6 +50,7 @@ class Extractor
|
||||||
public function notFound($data = '')
|
public function notFound($data = '')
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
'Success' => false,
|
||||||
'code' => 404,
|
'code' => 404,
|
||||||
'data' => $data,
|
'data' => $data,
|
||||||
'message' => 'item not found'
|
'message' => 'item not found'
|
||||||
|
@ -59,6 +60,7 @@ class Extractor
|
||||||
public function paramsNotSend()
|
public function paramsNotSend()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
'Success' => false,
|
||||||
'code' => 101,
|
'code' => 101,
|
||||||
'data' => '',
|
'data' => '',
|
||||||
'message' => 'parameters not send currectly'
|
'message' => 'parameters not send currectly'
|
||||||
|
|
|
@ -166,7 +166,7 @@ class PayMGR
|
||||||
$res['Success'] = true;
|
$res['Success'] = true;
|
||||||
$res['status'] = 100;
|
$res['status'] = 100;
|
||||||
$res['refID'] = $_POST["RRN"];
|
$res['refID'] = $_POST["RRN"];
|
||||||
$res['card_pan'] = $result->CardNumberMasked;
|
$res['card_pan'] = $result->ConfirmPaymentResult->CardNumberMasked;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $res;
|
return $res;
|
||||||
|
|
Loading…
Reference in a new issue