From b935fdf6b2866fdcc7837b4cb2d43b786d4abdbf Mon Sep 17 00:00:00 2001 From: Babak Alizadeh Date: Fri, 28 Feb 2025 18:31:39 +0000 Subject: [PATCH] add plugin controller to system --- hesabixCore/config/routes.yaml | 4 + .../src/Controller/CommodityController.php | 152 ++++++- .../src/Controller/PersonsController.php | 2 +- .../src/Controller/PluginController.php | 386 ++++++++++++++---- hesabixCore/src/Entity/PluginProdect.php | 15 + hesabixCore/src/Service/Explore.php | 2 +- hesabixCore/src/Service/Extractor.php | 2 + hesabixCore/src/Service/PayMGR.php | 2 +- 8 files changed, 477 insertions(+), 88 deletions(-) diff --git a/hesabixCore/config/routes.yaml b/hesabixCore/config/routes.yaml index 41ef814..8b50345 100644 --- a/hesabixCore/config/routes.yaml +++ b/hesabixCore/config/routes.yaml @@ -3,3 +3,7 @@ controllers: path: ../src/Controller/ namespace: App\Controller type: attribute +app.swagger_ui: + path: /doc/api + methods: GET + defaults: { _controller: nelmio_api_doc.controller.swagger_ui } diff --git a/hesabixCore/src/Controller/CommodityController.php b/hesabixCore/src/Controller/CommodityController.php index a85dac5..19c0907 100644 --- a/hesabixCore/src/Controller/CommodityController.php +++ b/hesabixCore/src/Controller/CommodityController.php @@ -113,9 +113,9 @@ class CommodityController extends AbstractController $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()); + if ($item->getCat()) { + $temp['cat'] = $item->getCat()->getName(); + $temp['catData'] = Explore::ExploreCommodityCat($item->getCat()); } $temp['khadamat'] = false; if ($item->isKhadamat()) @@ -1315,4 +1315,150 @@ class CommodityController extends AbstractController $log->insert('کالا/خدمات', 'قیمت تعدادی از کالا‌ها به صورت گروهی ویرایش شد.', $this->getUser(), $acc['bid']->getId()); 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); + } } diff --git a/hesabixCore/src/Controller/PersonsController.php b/hesabixCore/src/Controller/PersonsController.php index 40da3f9..3b4ea21 100644 --- a/hesabixCore/src/Controller/PersonsController.php +++ b/hesabixCore/src/Controller/PersonsController.php @@ -302,7 +302,7 @@ class PersonsController extends AbstractController $person->setCompany($params['company']); if (array_key_exists('prelabel', $params)) { if ($params['prelabel'] != '') { - $prelabel = $entityManager->getRepository(PersonPrelabel::class)->findOneBy(['code' => $params['prelabel']['code']]); + $prelabel = $entityManager->getRepository(PersonPrelabel::class)->findOneBy(['label' => $params['prelabel']]); if ($prelabel) { $person->setPrelabel($prelabel); } diff --git a/hesabixCore/src/Controller/PluginController.php b/hesabixCore/src/Controller/PluginController.php index 5ad4664..8e542e3 100644 --- a/hesabixCore/src/Controller/PluginController.php +++ b/hesabixCore/src/Controller/PluginController.php @@ -2,11 +2,10 @@ namespace App\Controller; -use App\Entity\Business; use App\Entity\Plugin; use App\Entity\PluginProdect; -use App\Entity\Settings; use App\Service\Access; +use App\Service\Extractor; use App\Service\Jdate; use App\Service\Log; use App\Service\PayMGR; @@ -18,128 +17,351 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; +use OpenApi\Annotations as OA; class PluginController extends AbstractController { - #[Route('/api/plugin/get/info/{id}', name: 'api_plugin_get_info')] - public function api_plugin_get_info(string $id, Access $access, Jdate $jdate, EntityManagerInterface $entityManager, Log $log): JsonResponse + private const PRICE_MULTIPLIER = 1.09; // ضریب قیمت به صورت ثابت برای محاسبه + + /** + * بررسی دسترسی کاربر با نقش مشخص + * + * @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'); - if (!$acc) - throw $this->createAccessDeniedException(); - $item = $entityManager->getRepository(PluginProdect::class)->findOneBy([ - 'code' => $id - ]); + $acc = $access->hasRole($role); + if (!$acc) { + throw $this->createAccessDeniedException('شما دسترسی لازم را ندارید.'); + } + 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); } - #[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 { - $acc = $access->hasRole('join'); - if (!$acc) - throw $this->createAccessDeniedException(); - $pp = $entityManager->getRepository(PluginProdect::class)->find($id); - if (!$pp) - throw $this->createNotFoundException('plugin not found'); - //get system settings - $settings = $twigFunctions->systemSettings(); + $acc = $this->checkAccess($access, 'join'); + $pp = $entityManager->getRepository(PluginProdect::class)->find($id) + ?? throw $this->createNotFoundException('افزونه یافت نشد'); + $plugin = new Plugin(); - $plugin->setBid($acc['bid']); - $plugin->setSubmitter($this->getUser()); - $plugin->setDateSubmit(time()); - $plugin->setStatus(0); - $plugin->setDes($pp->getName()); - $plugin->setName($pp->getCode()); - $plugin->setPrice(($pp->getPrice() * 109) / 10); - $plugin->setDateExpire(time() + $pp->getTimestamp()); + $plugin->setBid($acc['bid']) + ->setSubmitter($this->getUser()) + ->setDateSubmit(time()) + ->setStatus(0) + ->setDes($pp->getName()) + ->setName($pp->getCode()) + ->setPrice($pp->getPrice() * self::PRICE_MULTIPLIER) + ->setDateExpire(time() + $pp->getTimestamp()); + $entityManager->persist($plugin); - $entityManager->flush(); - $result = $payMGR->createRequest(($pp->getPrice() * 109) / 10, $this->generateUrl('api_plugin_buy_verify', ['id' => $plugin->getId()], UrlGeneratorInterface::ABSOLUTE_URL), 'خرید فضای ابری'); - if ($result['Success']) { - $plugin->setGatePay($result['gate']); - $plugin->setVerifyCode($result['authkey']); - $entityManager->persist($plugin); - $entityManager->flush(); - $entityManager->persist($plugin); - $entityManager->flush(); + + $result = $payMGR->createRequest( + $plugin->getPrice(), + $this->generateUrl('api_plugin_buy_verify', ['id' => $plugin->getId()], UrlGeneratorInterface::ABSOLUTE_URL), + 'خرید فضای ابری' + ); + + if ($result['Success'] ?? false) { + $plugin->setGatePay($result['gate']) + ->setVerifyCode($result['authkey']); $log->insert('بازار افزونه‌ها', 'صدور فاکتور افزونه ' . $pp->getName(), $this->getUser(), $acc['bid']); } + + $entityManager->flush(); 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 { - $req = $entityManager->getRepository(Plugin::class)->find($id); - if (!$req) - throw $this->createNotFoundException(''); + $req = $entityManager->getRepository(Plugin::class)->find($id) + ?? throw $this->createNotFoundException('درخواست افزونه یافت نشد'); + $res = $payMGR->verify($req->getPrice(), $req->getVerifyCode(), $request); - if ($res['Success'] == false) { + + if (!($res['Success'] ?? false)) { $log->insert( - 'بازار افزونه‌ها' . $req->getName(), + 'بازار افزونه‌ها ' . $req->getName(), 'پرداخت ناموفق صورت‌حساب خرید افزونه', $req->getSubmitter(), $req->getBid() ); 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'); - if (!$acc) - throw $this->createAccessDeniedException(); + $acc = $this->checkAccess($access, 'join'); $plugins = $entityManager->getRepository(Plugin::class)->findActivePlugins($acc['bid']); $temp = []; + foreach ($plugins as $plugin) { - $plugin->setDateExpire($jdate->jdate('Y/n/d', $plugin->getDateExpire())); - $temp[$plugin->getName()] = $plugin; + $pluginName = $plugin->getName(); + $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); } - #[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'); - if (!$acc) - throw $this->createAccessDeniedException(); - $plugins = $entityManager->getRepository(Plugin::class)->findBy([ - 'bid' => $acc['bid'], - ]); - $temp = []; + $acc = $this->checkAccess($access, 'join'); + $plugins = $entityManager->getRepository(Plugin::class)->findBy(['bid' => $acc['bid']]); + foreach ($plugins as $plugin) { $plugin->setDateExpire($jdate->jdate('Y/n/d', $plugin->getDateExpire())); $plugin->setDateSubmit($jdate->jdate('Y/n/d', $plugin->getDateSubmit())); $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); } -} + /** + * دریافت همه افزونه‌های موجود (غیر پیش‌فرض) + * + * @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()); + } +} \ No newline at end of file diff --git a/hesabixCore/src/Entity/PluginProdect.php b/hesabixCore/src/Entity/PluginProdect.php index 5baade3..06b3354 100644 --- a/hesabixCore/src/Entity/PluginProdect.php +++ b/hesabixCore/src/Entity/PluginProdect.php @@ -31,6 +31,9 @@ class PluginProdect #[ORM\Column(length: 255, nullable: true)] private ?string $icon = null; + #[ORM\Column(nullable: true)] + private ?bool $defaultOn = null; + public function getId(): ?int { return $this->id; @@ -107,4 +110,16 @@ class PluginProdect return $this; } + + public function isDefaultOn(): ?bool + { + return $this->defaultOn; + } + + public function setDefaultOn(?bool $defaultOn): static + { + $this->defaultOn = $defaultOn; + + return $this; + } } diff --git a/hesabixCore/src/Service/Explore.php b/hesabixCore/src/Service/Explore.php index 6e4a056..d575db4 100644 --- a/hesabixCore/src/Service/Explore.php +++ b/hesabixCore/src/Service/Explore.php @@ -313,7 +313,7 @@ class Explore 'birthday' => $person->getBirthday(), 'speedAccess' => $person->isSpeedAccess(), 'address' => $person->getAddress(), - 'prelabel' => '', + 'prelabel' => null, ]; if ($person->getPrelabel()) { $res['prelabel'] = $person->getPrelabel()->getLabel(); diff --git a/hesabixCore/src/Service/Extractor.php b/hesabixCore/src/Service/Extractor.php index 47618d2..f88ab92 100644 --- a/hesabixCore/src/Service/Extractor.php +++ b/hesabixCore/src/Service/Extractor.php @@ -50,6 +50,7 @@ class Extractor public function notFound($data = '') { return [ + 'Success' => false, 'code' => 404, 'data' => $data, 'message' => 'item not found' @@ -59,6 +60,7 @@ class Extractor public function paramsNotSend() { return [ + 'Success' => false, 'code' => 101, 'data' => '', 'message' => 'parameters not send currectly' diff --git a/hesabixCore/src/Service/PayMGR.php b/hesabixCore/src/Service/PayMGR.php index d3a0ace..27dbdb7 100644 --- a/hesabixCore/src/Service/PayMGR.php +++ b/hesabixCore/src/Service/PayMGR.php @@ -166,7 +166,7 @@ class PayMGR $res['Success'] = true; $res['status'] = 100; $res['refID'] = $_POST["RRN"]; - $res['card_pan'] = $result->CardNumberMasked; + $res['card_pan'] = $result->ConfirmPaymentResult->CardNumberMasked; } } return $res;