commit
cd0619dc60
3856 changed files with 584571 additions and 0 deletions
@ -0,0 +1,15 @@ |
||||
root = true |
||||
|
||||
[*] |
||||
charset = utf-8 |
||||
end_of_line = lf |
||||
insert_final_newline = true |
||||
indent_style = space |
||||
indent_size = 4 |
||||
trim_trailing_whitespace = true |
||||
|
||||
[*.md] |
||||
trim_trailing_whitespace = false |
||||
|
||||
[*.{yml,yaml}] |
||||
indent_size = 2 |
@ -0,0 +1,50 @@ |
||||
APP_NAME=Laravel |
||||
APP_ENV=local |
||||
APP_KEY=base64:/NC6CNBiDJb2vV4fRviEsMqy5gKbePRgk44JGkZFAYY= |
||||
APP_DEBUG=true |
||||
APP_URL=http://localhost |
||||
APP_MODE=dev |
||||
|
||||
LOG_CHANNEL=stack |
||||
LOG_LEVEL=debug |
||||
|
||||
DB_CONNECTION=mysql |
||||
DB_HOST=127.0.0.1 |
||||
DB_PORT=3306 |
||||
DB_DATABASE=stackfood |
||||
DB_USERNAME=root |
||||
DB_PASSWORD= |
||||
|
||||
BROADCAST_DRIVER=log |
||||
CACHE_DRIVER=file |
||||
QUEUE_CONNECTION=sync |
||||
SESSION_DRIVER=file |
||||
SESSION_LIFETIME=120 |
||||
|
||||
MEMCACHED_HOST=127.0.0.1 |
||||
|
||||
REDIS_HOST=127.0.0.1 |
||||
REDIS_PASSWORD=null |
||||
REDIS_PORT=6379 |
||||
|
||||
MAIL_MAILER=smtp |
||||
MAIL_HOST=mailhog |
||||
MAIL_PORT=1025 |
||||
MAIL_USERNAME=null |
||||
MAIL_PASSWORD=null |
||||
MAIL_ENCRYPTION=null |
||||
MAIL_FROM_ADDRESS=null |
||||
MAIL_FROM_NAME="${APP_NAME}" |
||||
|
||||
AWS_ACCESS_KEY_ID= |
||||
AWS_SECRET_ACCESS_KEY= |
||||
AWS_DEFAULT_REGION=us-east-1 |
||||
AWS_BUCKET= |
||||
|
||||
PUSHER_APP_ID= |
||||
PUSHER_APP_KEY= |
||||
PUSHER_APP_SECRET= |
||||
PUSHER_APP_CLUSTER=mt1 |
||||
|
||||
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" |
||||
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" |
@ -0,0 +1,5 @@ |
||||
* text=auto |
||||
*.css linguist-vendored |
||||
*.scss linguist-vendored |
||||
*.js linguist-vendored |
||||
CHANGELOG.md export-ignore |
@ -0,0 +1,14 @@ |
||||
/node_modules |
||||
/public/hot |
||||
/public/storage |
||||
/storage/*.key |
||||
/vendor |
||||
.env |
||||
.env.backup |
||||
.phpunit.result.cache |
||||
docker-compose.override.yml |
||||
Homestead.json |
||||
Homestead.yaml |
||||
npm-debug.log |
||||
yarn-error.log |
||||
error_log |
@ -0,0 +1,30 @@ |
||||
<IfModule mod_rewrite.c> |
||||
<IfModule mod_negotiation.c> |
||||
Options -MultiViews -Indexes |
||||
</IfModule> |
||||
|
||||
RewriteEngine On |
||||
|
||||
# Handle Authorization Header |
||||
RewriteCond %{HTTP:Authorization} . |
||||
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] |
||||
|
||||
# Redirect Trailing Slashes If Not A Folder... |
||||
RewriteCond %{REQUEST_FILENAME} !-d |
||||
RewriteCond %{REQUEST_URI} (.+)/$ |
||||
RewriteRule ^ %1 [L,R=301] |
||||
|
||||
# Send Requests To Front Controller... |
||||
RewriteCond %{REQUEST_FILENAME} !-d |
||||
RewriteCond %{REQUEST_FILENAME} !-f |
||||
RewriteRule ^ index.php [L] |
||||
|
||||
# cors |
||||
Header set Access-Control-Allow-Origin "*" |
||||
</IfModule> |
||||
|
||||
# Hide a specific file |
||||
<Files .env> |
||||
Order allow,deny |
||||
Deny from all |
||||
</Files> |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,47 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" |
||||
xmlns:xs="http://www.w3.org/2001/XMLSchema"> |
||||
<xs:element name="framework" type="frameworkType"/> |
||||
<xs:complexType name="commandType"> |
||||
<xs:all> |
||||
<xs:element type="xs:string" name="name" minOccurs="1" maxOccurs="1"/> |
||||
<xs:element type="xs:string" name="params" minOccurs="0" maxOccurs="1"/> |
||||
<xs:element type="xs:string" name="help" minOccurs="0" maxOccurs="1"/> |
||||
<xs:element type="optionsBeforeType" name="optionsBefore" minOccurs="0" maxOccurs="1"/> |
||||
</xs:all> |
||||
</xs:complexType> |
||||
<xs:complexType name="frameworkType"> |
||||
<xs:sequence> |
||||
<xs:element type="xs:string" name="extraData" minOccurs="0" maxOccurs="1"/> |
||||
<xs:element type="commandType" name="command" maxOccurs="unbounded" minOccurs="0"/> |
||||
<xs:element type="xs:string" name="help" minOccurs="0" maxOccurs="1"/> |
||||
</xs:sequence> |
||||
<xs:attribute type="xs:string" name="name" use="required"/> |
||||
<xs:attribute type="xs:string" name="invoke" use="required"/> |
||||
<xs:attribute type="xs:string" name="alias" use="required"/> |
||||
<xs:attribute type="xs:boolean" name="enabled" use="required"/> |
||||
<xs:attribute type="xs:integer" name="version" use="required"/> |
||||
<xs:attribute type="xs:string" name="frameworkId" use="optional"/> |
||||
</xs:complexType> |
||||
<xs:complexType name="optionsBeforeType"> |
||||
<xs:sequence> |
||||
<xs:element type="optionType" name="option" maxOccurs="unbounded" minOccurs="0"/> |
||||
</xs:sequence> |
||||
</xs:complexType> |
||||
<xs:complexType name="optionType"> |
||||
<xs:sequence> |
||||
<xs:element type="xs:string" name="help" minOccurs="0" maxOccurs="1"/> |
||||
</xs:sequence> |
||||
<xs:attribute type="xs:string" name="name" use="required"/> |
||||
<xs:attribute type="xs:string" name="shortcut" use="optional"/> |
||||
<xs:attribute name="pattern" use="optional"> |
||||
<xs:simpleType> |
||||
<xs:restriction base="xs:string"> |
||||
<xs:enumeration value="space"/> |
||||
<xs:enumeration value="equals"/> |
||||
<xs:enumeration value="unknown"/> |
||||
</xs:restriction> |
||||
</xs:simpleType> |
||||
</xs:attribute> |
||||
</xs:complexType> |
||||
</xs:schema> |
@ -0,0 +1,8 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project version="4"> |
||||
<component name="ProjectModuleManager"> |
||||
<modules> |
||||
<module fileurl="file://$PROJECT_DIR$/.idea/stackfood.iml" filepath="$PROJECT_DIR$/.idea/stackfood.iml" /> |
||||
</modules> |
||||
</component> |
||||
</project> |
@ -0,0 +1,174 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project version="4"> |
||||
<component name="PhpIncludePathManager"> |
||||
<include_path> |
||||
<path value="$PROJECT_DIR$/vendor/nunomaduro/collision" /> |
||||
<path value="$PROJECT_DIR$/vendor/intervention/image" /> |
||||
<path value="$PROJECT_DIR$/vendor/doctrine/inflector" /> |
||||
<path value="$PROJECT_DIR$/vendor/doctrine/instantiator" /> |
||||
<path value="$PROJECT_DIR$/vendor/mockery/mockery" /> |
||||
<path value="$PROJECT_DIR$/vendor/doctrine/lexer" /> |
||||
<path value="$PROJECT_DIR$/vendor/vlucas/phpdotenv" /> |
||||
<path value="$PROJECT_DIR$/vendor/phpunit/php-timer" /> |
||||
<path value="$PROJECT_DIR$/vendor/phpunit/php-file-iterator" /> |
||||
<path value="$PROJECT_DIR$/vendor/phpunit/php-invoker" /> |
||||
<path value="$PROJECT_DIR$/vendor/phpunit/php-text-template" /> |
||||
<path value="$PROJECT_DIR$/vendor/graham-campbell/result-type" /> |
||||
<path value="$PROJECT_DIR$/vendor/phpunit/php-code-coverage" /> |
||||
<path value="$PROJECT_DIR$/vendor/myclabs/deep-copy" /> |
||||
<path value="$PROJECT_DIR$/vendor/swiftmailer/swiftmailer" /> |
||||
<path value="$PROJECT_DIR$/vendor/egulias/email-validator" /> |
||||
<path value="$PROJECT_DIR$/vendor/phar-io/version" /> |
||||
<path value="$PROJECT_DIR$/vendor/phar-io/manifest" /> |
||||
<path value="$PROJECT_DIR$/vendor/brian2694/laravel-toastr" /> |
||||
<path value="$PROJECT_DIR$/vendor/fideloper/proxy" /> |
||||
<path value="$PROJECT_DIR$/vendor/psr/simple-cache" /> |
||||
<path value="$PROJECT_DIR$/vendor/psr/log" /> |
||||
<path value="$PROJECT_DIR$/vendor/psr/event-dispatcher" /> |
||||
<path value="$PROJECT_DIR$/vendor/fakerphp/faker" /> |
||||
<path value="$PROJECT_DIR$/vendor/fruitcake/laravel-cors" /> |
||||
<path value="$PROJECT_DIR$/vendor/psr/http-message" /> |
||||
<path value="$PROJECT_DIR$/vendor/psr/http-client" /> |
||||
<path value="$PROJECT_DIR$/vendor/psr/container" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/string" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/deprecation-contracts" /> |
||||
<path value="$PROJECT_DIR$/vendor/filp/whoops" /> |
||||
<path value="$PROJECT_DIR$/vendor/ramsey/uuid" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/mime" /> |
||||
<path value="$PROJECT_DIR$/vendor/ramsey/collection" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/service-contracts" /> |
||||
<path value="$PROJECT_DIR$/vendor/phpoption/phpoption" /> |
||||
<path value="$PROJECT_DIR$/vendor/webmozart/assert" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/var-dumper" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-intl-idn" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-iconv" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-php80" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/error-handler" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/routing" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/css-selector" /> |
||||
<path value="$PROJECT_DIR$/vendor/league/commonmark" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/event-dispatcher" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-intl-grapheme" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-ctype" /> |
||||
<path value="$PROJECT_DIR$/vendor/ralouphie/getallheaders" /> |
||||
<path value="$PROJECT_DIR$/vendor/nikic/php-parser" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/console" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/event-dispatcher-contracts" /> |
||||
<path value="$PROJECT_DIR$/vendor/phpunit/phpunit" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-php72" /> |
||||
<path value="$PROJECT_DIR$/vendor/guzzlehttp/guzzle" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/process" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-php73" /> |
||||
<path value="$PROJECT_DIR$/vendor/sebastian/complexity" /> |
||||
<path value="$PROJECT_DIR$/vendor/guzzlehttp/promises" /> |
||||
<path value="$PROJECT_DIR$/vendor/nesbot/carbon" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-intl-normalizer" /> |
||||
<path value="$PROJECT_DIR$/vendor/sebastian/global-state" /> |
||||
<path value="$PROJECT_DIR$/vendor/guzzlehttp/psr7" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/finder" /> |
||||
<path value="$PROJECT_DIR$/vendor/sebastian/object-reflector" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/http-kernel" /> |
||||
<path value="$PROJECT_DIR$/vendor/sebastian/recursion-context" /> |
||||
<path value="$PROJECT_DIR$/vendor/psy/psysh" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-mbstring" /> |
||||
<path value="$PROJECT_DIR$/vendor/sebastian/cli-parser" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/translation" /> |
||||
<path value="$PROJECT_DIR$/vendor/sebastian/object-enumerator" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/http-foundation" /> |
||||
<path value="$PROJECT_DIR$/vendor/sebastian/diff" /> |
||||
<path value="$PROJECT_DIR$/vendor/laravel/sail" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/translation-contracts" /> |
||||
<path value="$PROJECT_DIR$/vendor/sebastian/lines-of-code" /> |
||||
<path value="$PROJECT_DIR$/vendor/sebastian/version" /> |
||||
<path value="$PROJECT_DIR$/vendor/sebastian/type" /> |
||||
<path value="$PROJECT_DIR$/vendor/sebastian/exporter" /> |
||||
<path value="$PROJECT_DIR$/vendor/asm89/stack-cors" /> |
||||
<path value="$PROJECT_DIR$/vendor/sebastian/comparator" /> |
||||
<path value="$PROJECT_DIR$/vendor/sebastian/code-unit" /> |
||||
<path value="$PROJECT_DIR$/vendor/sebastian/environment" /> |
||||
<path value="$PROJECT_DIR$/vendor/sebastian/code-unit-reverse-lookup" /> |
||||
<path value="$PROJECT_DIR$/vendor/sebastian/resource-operations" /> |
||||
<path value="$PROJECT_DIR$/vendor/brick/math" /> |
||||
<path value="$PROJECT_DIR$/vendor/tijsverkoyen/css-to-inline-styles" /> |
||||
<path value="$PROJECT_DIR$/vendor/league/mime-type-detection" /> |
||||
<path value="$PROJECT_DIR$/vendor/league/flysystem" /> |
||||
<path value="$PROJECT_DIR$/vendor/laravel/framework" /> |
||||
<path value="$PROJECT_DIR$/vendor/laravel/tinker" /> |
||||
<path value="$PROJECT_DIR$/vendor/dragonmantank/cron-expression" /> |
||||
<path value="$PROJECT_DIR$/vendor/monolog/monolog" /> |
||||
<path value="$PROJECT_DIR$/vendor/phpspec/prophecy" /> |
||||
<path value="$PROJECT_DIR$/vendor/composer" /> |
||||
<path value="$PROJECT_DIR$/vendor/hamcrest/hamcrest-php" /> |
||||
<path value="$PROJECT_DIR$/vendor/opis/closure" /> |
||||
<path value="$PROJECT_DIR$/vendor/phpdocumentor/reflection-docblock" /> |
||||
<path value="$PROJECT_DIR$/vendor/phpdocumentor/reflection-common" /> |
||||
<path value="$PROJECT_DIR$/vendor/phpdocumentor/type-resolver" /> |
||||
<path value="$PROJECT_DIR$/vendor/voku/portable-ascii" /> |
||||
<path value="$PROJECT_DIR$/vendor/facade/ignition-contracts" /> |
||||
<path value="$PROJECT_DIR$/vendor/facade/ignition" /> |
||||
<path value="$PROJECT_DIR$/vendor/facade/flare-client-php" /> |
||||
<path value="$PROJECT_DIR$/vendor/theseer/tokenizer" /> |
||||
<path value="$PROJECT_DIR$/vendor/jmikola/geojson" /> |
||||
<path value="$PROJECT_DIR$/vendor/grimzy/laravel-mysql-spatial" /> |
||||
<path value="$PROJECT_DIR$/vendor/geo-io/interface" /> |
||||
<path value="$PROJECT_DIR$/vendor/geo-io/wkb-parser" /> |
||||
<path value="$PROJECT_DIR$/vendor/maximebf/debugbar" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/debug" /> |
||||
<path value="$PROJECT_DIR$/vendor/doctrine/dbal" /> |
||||
<path value="$PROJECT_DIR$/vendor/doctrine/cache" /> |
||||
<path value="$PROJECT_DIR$/vendor/doctrine/deprecations" /> |
||||
<path value="$PROJECT_DIR$/vendor/doctrine/event-manager" /> |
||||
<path value="$PROJECT_DIR$/vendor/barryvdh/laravel-debugbar" /> |
||||
<path value="$PROJECT_DIR$/vendor/unicodeveloper/laravel-paystack" /> |
||||
<path value="$PROJECT_DIR$/vendor/firebase/php-jwt" /> |
||||
<path value="$PROJECT_DIR$/vendor/paypal/rest-api-sdk-php" /> |
||||
<path value="$PROJECT_DIR$/vendor/laravel/passport" /> |
||||
<path value="$PROJECT_DIR$/vendor/paragonie/constant_time_encoding" /> |
||||
<path value="$PROJECT_DIR$/vendor/paragonie/random_compat" /> |
||||
<path value="$PROJECT_DIR$/vendor/madnest/madzipper" /> |
||||
<path value="$PROJECT_DIR$/vendor/php-http/message-factory" /> |
||||
<path value="$PROJECT_DIR$/vendor/phpseclib/phpseclib" /> |
||||
<path value="$PROJECT_DIR$/vendor/rmccue/requests" /> |
||||
<path value="$PROJECT_DIR$/vendor/league/event" /> |
||||
<path value="$PROJECT_DIR$/vendor/league/oauth2-server" /> |
||||
<path value="$PROJECT_DIR$/vendor/nyholm/psr7" /> |
||||
<path value="$PROJECT_DIR$/vendor/psr/http-factory" /> |
||||
<path value="$PROJECT_DIR$/vendor/defuse/php-encryption" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/psr-http-message-bridge" /> |
||||
<path value="$PROJECT_DIR$/vendor/razorpay/razorpay" /> |
||||
<path value="$PROJECT_DIR$/vendor/stripe/stripe-php" /> |
||||
<path value="$PROJECT_DIR$/vendor/lcobucci/clock" /> |
||||
<path value="$PROJECT_DIR$/vendor/lcobucci/jwt" /> |
||||
<path value="$PROJECT_DIR$/vendor/twilio/sdk" /> |
||||
<path value="$PROJECT_DIR$/vendor/dflydev/dot-access-data" /> |
||||
<path value="$PROJECT_DIR$/vendor/nette/schema" /> |
||||
<path value="$PROJECT_DIR$/vendor/nette/utils" /> |
||||
<path value="$PROJECT_DIR$/vendor/league/config" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-php81" /> |
||||
<path value="$PROJECT_DIR$/vendor/vonage/client-core" /> |
||||
<path value="$PROJECT_DIR$/vendor/vonage/client" /> |
||||
<path value="$PROJECT_DIR$/vendor/vonage/nexmo-bridge" /> |
||||
<path value="$PROJECT_DIR$/vendor/nexmo/laravel" /> |
||||
<path value="$PROJECT_DIR$/vendor/laminas/laminas-diactoros" /> |
||||
<path value="$PROJECT_DIR$/vendor/laravelpkg/laravelchk" /> |
||||
<path value="$PROJECT_DIR$/vendor/box/spout" /> |
||||
<path value="$PROJECT_DIR$/vendor/psr/cache" /> |
||||
<path value="$PROJECT_DIR$/vendor/barryvdh/laravel-cors" /> |
||||
<path value="$PROJECT_DIR$/vendor/doctrine/annotations" /> |
||||
<path value="$PROJECT_DIR$/vendor/doctrine/persistence" /> |
||||
<path value="$PROJECT_DIR$/vendor/doctrine/common" /> |
||||
<path value="$PROJECT_DIR$/vendor/doctrine/collections" /> |
||||
<path value="$PROJECT_DIR$/vendor/kingflamez/laravelrave" /> |
||||
<path value="$PROJECT_DIR$/vendor/mercadopago/dx-php" /> |
||||
<path value="$PROJECT_DIR$/vendor/rap2hpoutre/fast-excel" /> |
||||
<path value="$PROJECT_DIR$/vendor/gregwar/captcha" /> |
||||
<path value="$PROJECT_DIR$/vendor/laravel/serializable-closure" /> |
||||
</include_path> |
||||
</component> |
||||
<component name="PhpProjectSharedConfiguration" php_language_level="7.3" /> |
||||
<component name="PhpUnit"> |
||||
<phpunit_settings> |
||||
<PhpUnitSettings configuration_file_path="$PROJECT_DIR$/phpunit.xml" custom_loader_path="$PROJECT_DIR$/vendor/autoload.php" use_configuration_file="true" /> |
||||
</phpunit_settings> |
||||
</component> |
||||
</project> |
@ -0,0 +1,10 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project version="4"> |
||||
<component name="PHPUnit"> |
||||
<option name="directories"> |
||||
<list> |
||||
<option value="$PROJECT_DIR$/tests" /> |
||||
</list> |
||||
</option> |
||||
</component> |
||||
</project> |
@ -0,0 +1,17 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<module type="WEB_MODULE" version="4"> |
||||
<component name="NewModuleRootManager"> |
||||
<content url="file://$MODULE_DIR$"> |
||||
<sourceFolder url="file://$MODULE_DIR$/app" isTestSource="false" packagePrefix="App\" /> |
||||
<sourceFolder url="file://$MODULE_DIR$/database/factories" isTestSource="false" packagePrefix="Database\Factories\" /> |
||||
<sourceFolder url="file://$MODULE_DIR$/database/seeders" isTestSource="false" packagePrefix="Database\Seeders\" /> |
||||
<sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" /> |
||||
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" packagePrefix="Tests\" /> |
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/laravelpkg/laravelchk" /> |
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/gregwar/captcha" /> |
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/laravel/serializable-closure" /> |
||||
</content> |
||||
<orderEntry type="inheritedJdk" /> |
||||
<orderEntry type="sourceFolder" forTests="false" /> |
||||
</component> |
||||
</module> |
@ -0,0 +1,6 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project version="4"> |
||||
<component name="VcsDirectoryMappings"> |
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" /> |
||||
</component> |
||||
</project> |
@ -0,0 +1,309 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project version="4"> |
||||
<component name="AutoImportSettings"> |
||||
<option name="autoReloadType" value="SELECTIVE" /> |
||||
</component> |
||||
<component name="ChangeListManager"> |
||||
<list default="true" id="8de7019d-e2bb-4d1b-9272-623980507709" name="Default Changelist" comment=""> |
||||
<change afterPath="$PROJECT_DIR$/installation/backup/database.sql" afterDir="false" /> |
||||
<change afterPath="$PROJECT_DIR$/installation/backup/public.zip" afterDir="false" /> |
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> |
||||
<change beforePath="$PROJECT_DIR$/installation/database.sql" beforeDir="false" afterPath="$PROJECT_DIR$/installation/database.sql" afterDir="false" /> |
||||
<change beforePath="$PROJECT_DIR$/installation/public.zip" beforeDir="false" afterPath="$PROJECT_DIR$/installation/public.zip" afterDir="false" /> |
||||
</list> |
||||
<option name="SHOW_DIALOG" value="false" /> |
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" /> |
||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" /> |
||||
<option name="LAST_RESOLUTION" value="IGNORE" /> |
||||
</component> |
||||
<component name="ComposerSettings" doNotAsk="true" synchronizationState="SYNCHRONIZE"> |
||||
<pharConfigPath>$PROJECT_DIR$/composer.json</pharConfigPath> |
||||
<execution /> |
||||
</component> |
||||
<component name="Git.Settings"> |
||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" /> |
||||
</component> |
||||
<component name="HighlightingSettingsPerFile"> |
||||
<setting file="file://$PROJECT_DIR$/composer.json" root0="FORCE_HIGHLIGHTING" /> |
||||
<setting file="file://$PROJECT_DIR$/.env" root0="FORCE_HIGHLIGHTING" /> |
||||
<setting file="file://$PROJECT_DIR$/resources/views/welcome.blade.php" root0="FORCE_HIGHLIGHTING" root1="FORCE_HIGHLIGHTING" root2="FORCE_HIGHLIGHTING" /> |
||||
<setting file="file://$PROJECT_DIR$/app/Providers/ConfigServiceProvider.php" root0="FORCE_HIGHLIGHTING" root1="FORCE_HIGHLIGHTING" /> |
||||
<setting file="file://$PROJECT_DIR$/app/Http/Controllers/Api/V2/LsLibController.php" root0="FORCE_HIGHLIGHTING" root1="FORCE_HIGHLIGHTING" /> |
||||
<setting file="file://$PROJECT_DIR$/app/Providers/RouteServiceProvider.php" root0="FORCE_HIGHLIGHTING" root1="FORCE_HIGHLIGHTING" /> |
||||
<setting file="file://$PROJECT_DIR$/resources/views/admin-views/partials/_top-restaurants.blade.php" root0="FORCE_HIGHLIGHTING" root1="FORCE_HIGHLIGHTING" root2="FORCE_HIGHLIGHTING" /> |
||||
<setting file="file://$PROJECT_DIR$/routes/api/v2/api.php" root0="FORCE_HIGHLIGHTING" root1="FORCE_HIGHLIGHTING" /> |
||||
<setting file="file://$PROJECT_DIR$/vendor/laravelpkg/laravelchk/src/Http/Controllers/LaravelchkController.php" root0="FORCE_HIGHLIGHTING" root1="FORCE_HIGHLIGHTING" /> |
||||
</component> |
||||
<component name="MarkdownSettingsMigration"> |
||||
<option name="stateVersion" value="1" /> |
||||
</component> |
||||
<component name="PhpWorkspaceProjectConfiguration"> |
||||
<include_path> |
||||
<path value="$PROJECT_DIR$/vendor/nunomaduro/collision" /> |
||||
<path value="$PROJECT_DIR$/vendor/intervention/image" /> |
||||
<path value="$PROJECT_DIR$/vendor/doctrine/inflector" /> |
||||
<path value="$PROJECT_DIR$/vendor/doctrine/instantiator" /> |
||||
<path value="$PROJECT_DIR$/vendor/mockery/mockery" /> |
||||
<path value="$PROJECT_DIR$/vendor/doctrine/lexer" /> |
||||
<path value="$PROJECT_DIR$/vendor/vlucas/phpdotenv" /> |
||||
<path value="$PROJECT_DIR$/vendor/phpunit/php-timer" /> |
||||
<path value="$PROJECT_DIR$/vendor/phpunit/php-file-iterator" /> |
||||
<path value="$PROJECT_DIR$/vendor/phpunit/php-invoker" /> |
||||
<path value="$PROJECT_DIR$/vendor/phpunit/php-text-template" /> |
||||
<path value="$PROJECT_DIR$/vendor/graham-campbell/result-type" /> |
||||
<path value="$PROJECT_DIR$/vendor/phpunit/php-code-coverage" /> |
||||
<path value="$PROJECT_DIR$/vendor/myclabs/deep-copy" /> |
||||
<path value="$PROJECT_DIR$/vendor/swiftmailer/swiftmailer" /> |
||||
<path value="$PROJECT_DIR$/vendor/egulias/email-validator" /> |
||||
<path value="$PROJECT_DIR$/vendor/phar-io/version" /> |
||||
<path value="$PROJECT_DIR$/vendor/phar-io/manifest" /> |
||||
<path value="$PROJECT_DIR$/vendor/brian2694/laravel-toastr" /> |
||||
<path value="$PROJECT_DIR$/vendor/fideloper/proxy" /> |
||||
<path value="$PROJECT_DIR$/vendor/psr/simple-cache" /> |
||||
<path value="$PROJECT_DIR$/vendor/psr/log" /> |
||||
<path value="$PROJECT_DIR$/vendor/psr/event-dispatcher" /> |
||||
<path value="$PROJECT_DIR$/vendor/fakerphp/faker" /> |
||||
<path value="$PROJECT_DIR$/vendor/fruitcake/laravel-cors" /> |
||||
<path value="$PROJECT_DIR$/vendor/psr/http-message" /> |
||||
<path value="$PROJECT_DIR$/vendor/psr/http-client" /> |
||||
<path value="$PROJECT_DIR$/vendor/psr/container" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/string" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/deprecation-contracts" /> |
||||
<path value="$PROJECT_DIR$/vendor/filp/whoops" /> |
||||
<path value="$PROJECT_DIR$/vendor/ramsey/uuid" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/mime" /> |
||||
<path value="$PROJECT_DIR$/vendor/ramsey/collection" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/service-contracts" /> |
||||
<path value="$PROJECT_DIR$/vendor/phpoption/phpoption" /> |
||||
<path value="$PROJECT_DIR$/vendor/webmozart/assert" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/var-dumper" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-intl-idn" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-iconv" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-php80" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/error-handler" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/routing" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/css-selector" /> |
||||
<path value="$PROJECT_DIR$/vendor/league/commonmark" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/event-dispatcher" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-intl-grapheme" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-ctype" /> |
||||
<path value="$PROJECT_DIR$/vendor/ralouphie/getallheaders" /> |
||||
<path value="$PROJECT_DIR$/vendor/nikic/php-parser" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/console" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/event-dispatcher-contracts" /> |
||||
<path value="$PROJECT_DIR$/vendor/phpunit/phpunit" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-php72" /> |
||||
<path value="$PROJECT_DIR$/vendor/guzzlehttp/guzzle" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/process" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-php73" /> |
||||
<path value="$PROJECT_DIR$/vendor/sebastian/complexity" /> |
||||
<path value="$PROJECT_DIR$/vendor/guzzlehttp/promises" /> |
||||
<path value="$PROJECT_DIR$/vendor/nesbot/carbon" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-intl-normalizer" /> |
||||
<path value="$PROJECT_DIR$/vendor/sebastian/global-state" /> |
||||
<path value="$PROJECT_DIR$/vendor/guzzlehttp/psr7" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/finder" /> |
||||
<path value="$PROJECT_DIR$/vendor/sebastian/object-reflector" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/http-kernel" /> |
||||
<path value="$PROJECT_DIR$/vendor/sebastian/recursion-context" /> |
||||
<path value="$PROJECT_DIR$/vendor/psy/psysh" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-mbstring" /> |
||||
<path value="$PROJECT_DIR$/vendor/sebastian/cli-parser" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/translation" /> |
||||
<path value="$PROJECT_DIR$/vendor/sebastian/object-enumerator" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/http-foundation" /> |
||||
<path value="$PROJECT_DIR$/vendor/sebastian/diff" /> |
||||
<path value="$PROJECT_DIR$/vendor/laravel/sail" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/translation-contracts" /> |
||||
<path value="$PROJECT_DIR$/vendor/sebastian/lines-of-code" /> |
||||
<path value="$PROJECT_DIR$/vendor/sebastian/version" /> |
||||
<path value="$PROJECT_DIR$/vendor/sebastian/type" /> |
||||
<path value="$PROJECT_DIR$/vendor/sebastian/exporter" /> |
||||
<path value="$PROJECT_DIR$/vendor/asm89/stack-cors" /> |
||||
<path value="$PROJECT_DIR$/vendor/sebastian/comparator" /> |
||||
<path value="$PROJECT_DIR$/vendor/sebastian/code-unit" /> |
||||
<path value="$PROJECT_DIR$/vendor/sebastian/environment" /> |
||||
<path value="$PROJECT_DIR$/vendor/sebastian/code-unit-reverse-lookup" /> |
||||
<path value="$PROJECT_DIR$/vendor/sebastian/resource-operations" /> |
||||
<path value="$PROJECT_DIR$/vendor/brick/math" /> |
||||
<path value="$PROJECT_DIR$/vendor/tijsverkoyen/css-to-inline-styles" /> |
||||
<path value="$PROJECT_DIR$/vendor/league/mime-type-detection" /> |
||||
<path value="$PROJECT_DIR$/vendor/league/flysystem" /> |
||||
<path value="$PROJECT_DIR$/vendor/laravel/framework" /> |
||||
<path value="$PROJECT_DIR$/vendor/laravel/tinker" /> |
||||
<path value="$PROJECT_DIR$/vendor/dragonmantank/cron-expression" /> |
||||
<path value="$PROJECT_DIR$/vendor/monolog/monolog" /> |
||||
<path value="$PROJECT_DIR$/vendor/phpspec/prophecy" /> |
||||
<path value="$PROJECT_DIR$/vendor/composer" /> |
||||
<path value="$PROJECT_DIR$/vendor/hamcrest/hamcrest-php" /> |
||||
<path value="$PROJECT_DIR$/vendor/opis/closure" /> |
||||
<path value="$PROJECT_DIR$/vendor/phpdocumentor/reflection-docblock" /> |
||||
<path value="$PROJECT_DIR$/vendor/phpdocumentor/reflection-common" /> |
||||
<path value="$PROJECT_DIR$/vendor/phpdocumentor/type-resolver" /> |
||||
<path value="$PROJECT_DIR$/vendor/voku/portable-ascii" /> |
||||
<path value="$PROJECT_DIR$/vendor/facade/ignition-contracts" /> |
||||
<path value="$PROJECT_DIR$/vendor/facade/ignition" /> |
||||
<path value="$PROJECT_DIR$/vendor/facade/flare-client-php" /> |
||||
<path value="$PROJECT_DIR$/vendor/theseer/tokenizer" /> |
||||
<path value="$PROJECT_DIR$/vendor/jmikola/geojson" /> |
||||
<path value="$PROJECT_DIR$/vendor/grimzy/laravel-mysql-spatial" /> |
||||
<path value="$PROJECT_DIR$/vendor/geo-io/interface" /> |
||||
<path value="$PROJECT_DIR$/vendor/geo-io/wkb-parser" /> |
||||
<path value="$PROJECT_DIR$/vendor/maximebf/debugbar" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/debug" /> |
||||
<path value="$PROJECT_DIR$/vendor/doctrine/dbal" /> |
||||
<path value="$PROJECT_DIR$/vendor/doctrine/cache" /> |
||||
<path value="$PROJECT_DIR$/vendor/doctrine/deprecations" /> |
||||
<path value="$PROJECT_DIR$/vendor/doctrine/event-manager" /> |
||||
<path value="$PROJECT_DIR$/vendor/barryvdh/laravel-debugbar" /> |
||||
<path value="$PROJECT_DIR$/vendor/unicodeveloper/laravel-paystack" /> |
||||
<path value="$PROJECT_DIR$/vendor/firebase/php-jwt" /> |
||||
<path value="$PROJECT_DIR$/vendor/paypal/rest-api-sdk-php" /> |
||||
<path value="$PROJECT_DIR$/vendor/laravel/passport" /> |
||||
<path value="$PROJECT_DIR$/vendor/paragonie/constant_time_encoding" /> |
||||
<path value="$PROJECT_DIR$/vendor/paragonie/random_compat" /> |
||||
<path value="$PROJECT_DIR$/vendor/madnest/madzipper" /> |
||||
<path value="$PROJECT_DIR$/vendor/php-http/message-factory" /> |
||||
<path value="$PROJECT_DIR$/vendor/phpseclib/phpseclib" /> |
||||
<path value="$PROJECT_DIR$/vendor/rmccue/requests" /> |
||||
<path value="$PROJECT_DIR$/vendor/league/event" /> |
||||
<path value="$PROJECT_DIR$/vendor/league/oauth2-server" /> |
||||
<path value="$PROJECT_DIR$/vendor/nyholm/psr7" /> |
||||
<path value="$PROJECT_DIR$/vendor/psr/http-factory" /> |
||||
<path value="$PROJECT_DIR$/vendor/defuse/php-encryption" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/psr-http-message-bridge" /> |
||||
<path value="$PROJECT_DIR$/vendor/razorpay/razorpay" /> |
||||
<path value="$PROJECT_DIR$/vendor/stripe/stripe-php" /> |
||||
<path value="$PROJECT_DIR$/vendor/lcobucci/clock" /> |
||||
<path value="$PROJECT_DIR$/vendor/lcobucci/jwt" /> |
||||
<path value="$PROJECT_DIR$/vendor/twilio/sdk" /> |
||||
<path value="$PROJECT_DIR$/vendor/dflydev/dot-access-data" /> |
||||
<path value="$PROJECT_DIR$/vendor/nette/schema" /> |
||||
<path value="$PROJECT_DIR$/vendor/nette/utils" /> |
||||
<path value="$PROJECT_DIR$/vendor/league/config" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-php81" /> |
||||
<path value="$PROJECT_DIR$/vendor/vonage/client-core" /> |
||||
<path value="$PROJECT_DIR$/vendor/vonage/client" /> |
||||
<path value="$PROJECT_DIR$/vendor/vonage/nexmo-bridge" /> |
||||
<path value="$PROJECT_DIR$/vendor/nexmo/laravel" /> |
||||
<path value="$PROJECT_DIR$/vendor/laminas/laminas-diactoros" /> |
||||
<path value="$PROJECT_DIR$/vendor/laravelpkg/laravelchk" /> |
||||
<path value="$PROJECT_DIR$/vendor/box/spout" /> |
||||
<path value="$PROJECT_DIR$/vendor/psr/cache" /> |
||||
<path value="$PROJECT_DIR$/vendor/barryvdh/laravel-cors" /> |
||||
<path value="$PROJECT_DIR$/vendor/doctrine/annotations" /> |
||||
<path value="$PROJECT_DIR$/vendor/doctrine/persistence" /> |
||||
<path value="$PROJECT_DIR$/vendor/doctrine/common" /> |
||||
<path value="$PROJECT_DIR$/vendor/doctrine/collections" /> |
||||
<path value="$PROJECT_DIR$/vendor/kingflamez/laravelrave" /> |
||||
<path value="$PROJECT_DIR$/vendor/mercadopago/dx-php" /> |
||||
<path value="$PROJECT_DIR$/vendor/rap2hpoutre/fast-excel" /> |
||||
<path value="$PROJECT_DIR$/vendor/gregwar/captcha" /> |
||||
<path value="$PROJECT_DIR$/vendor/laravel/serializable-closure" /> |
||||
<path value="$PROJECT_DIR$/vendor/symfony/http-client-contracts" /> |
||||
<path value="$PROJECT_DIR$/vendor/laminas/laminas-zendframework-bridge" /> |
||||
<path value="$PROJECT_DIR$/vendor/mollie/mollie-api-php" /> |
||||
</include_path> |
||||
</component> |
||||
<component name="ProjectId" id="1so3PMyTUJvxPdKFIlLR0f0vb9q" /> |
||||
<component name="ProjectLevelVcsManager"> |
||||
<ConfirmationsSetting value="2" id="Add" /> |
||||
</component> |
||||
<component name="ProjectViewState"> |
||||
<option name="hideEmptyMiddlePackages" value="true" /> |
||||
<option name="showLibraryContents" value="true" /> |
||||
</component> |
||||
<component name="PropertiesComponent"> |
||||
<property name="ASKED_ADD_EXTERNAL_FILES" value="true" /> |
||||
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true" /> |
||||
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" /> |
||||
<property name="WebServerToolWindowFactoryState" value="false" /> |
||||
<property name="last_opened_file_path" value="$PROJECT_DIR$/installation" /> |
||||
<property name="node.js.detected.package.eslint" value="true" /> |
||||
<property name="node.js.detected.package.tslint" value="true" /> |
||||
<property name="node.js.selected.package.eslint" value="(autodetect)" /> |
||||
<property name="node.js.selected.package.tslint" value="(autodetect)" /> |
||||
<property name="nodejs_package_manager_path" value="npm" /> |
||||
<property name="settings.editor.selected.configurable" value="preferences.lookFeel" /> |
||||
<property name="vue.rearranger.settings.migration" value="true" /> |
||||
</component> |
||||
<component name="RecentsManager"> |
||||
<key name="CopyFile.RECENT_KEYS"> |
||||
<recent name="$PROJECT_DIR$/installation" /> |
||||
<recent name="$PROJECT_DIR$/installation/backup" /> |
||||
<recent name="$PROJECT_DIR$/public/assets/landing/image" /> |
||||
<recent name="$PROJECT_DIR$/routes" /> |
||||
<recent name="$PROJECT_DIR$/resources/views" /> |
||||
</key> |
||||
<key name="MoveFile.RECENT_KEYS"> |
||||
<recent name="$PROJECT_DIR$/installation/backup" /> |
||||
<recent name="$PROJECT_DIR$/app/Http/Controllers/Api/V2" /> |
||||
</key> |
||||
</component> |
||||
<component name="RunManager"> |
||||
<configuration name="phpunit.xml" type="PHPUnitRunConfigurationType" factoryName="PHPUnit"> |
||||
<TestRunner scope="XML" /> |
||||
<method v="2" /> |
||||
</configuration> |
||||
</component> |
||||
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" /> |
||||
<component name="TaskManager"> |
||||
<task active="true" id="Default" summary="Default task"> |
||||
<changelist id="8de7019d-e2bb-4d1b-9272-623980507709" name="Default Changelist" comment="" /> |
||||
<created>1621525090097</created> |
||||
<option name="number" value="Default" /> |
||||
<option name="presentableId" value="Default" /> |
||||
<updated>1621525090097</updated> |
||||
<workItem from="1621525091709" duration="5820000" /> |
||||
<workItem from="1621601896347" duration="7000" /> |
||||
<workItem from="1621653222009" duration="16000" /> |
||||
<workItem from="1623130139364" duration="1244000" /> |
||||
<workItem from="1626609230855" duration="13329000" /> |
||||
<workItem from="1626708460787" duration="4837000" /> |
||||
<workItem from="1627115565104" duration="17120000" /> |
||||
<workItem from="1627212684497" duration="6530000" /> |
||||
<workItem from="1627291739470" duration="16321000" /> |
||||
<workItem from="1627374136528" duration="3655000" /> |
||||
<workItem from="1627395813322" duration="8896000" /> |
||||
<workItem from="1627547109663" duration="16286000" /> |
||||
<workItem from="1627730840335" duration="256000" /> |
||||
<workItem from="1627981977577" duration="642000" /> |
||||
<workItem from="1627983270219" duration="4639000" /> |
||||
<workItem from="1628331639884" duration="8198000" /> |
||||
<workItem from="1628502185725" duration="9217000" /> |
||||
<workItem from="1629281510804" duration="12219000" /> |
||||
<workItem from="1629360595835" duration="15360000" /> |
||||
<workItem from="1629435726523" duration="15462000" /> |
||||
<workItem from="1629533617948" duration="17454000" /> |
||||
<workItem from="1629556941206" duration="10000" /> |
||||
<workItem from="1629556990279" duration="10120000" /> |
||||
<workItem from="1629620487327" duration="6554000" /> |
||||
<workItem from="1629706927243" duration="1074000" /> |
||||
<workItem from="1629726455626" duration="158000" /> |
||||
<workItem from="1629732568054" duration="889000" /> |
||||
<workItem from="1630572899496" duration="188000" /> |
||||
<workItem from="1630577437426" duration="219000" /> |
||||
<workItem from="1630593998936" duration="7885000" /> |
||||
<workItem from="1630742509256" duration="11000" /> |
||||
<workItem from="1630746551123" duration="2315000" /> |
||||
</task> |
||||
<servers /> |
||||
</component> |
||||
<component name="TypeScriptGeneratedFilesManager"> |
||||
<option name="version" value="3" /> |
||||
</component> |
||||
<component name="Vcs.Log.Tabs.Properties"> |
||||
<option name="TAB_STATES"> |
||||
<map> |
||||
<entry key="MAIN"> |
||||
<value> |
||||
<State /> |
||||
</value> |
||||
</entry> |
||||
</map> |
||||
</option> |
||||
</component> |
||||
<component name="VcsManagerConfiguration"> |
||||
<option name="ADD_EXTERNAL_FILES_SILENTLY" value="true" /> |
||||
</component> |
||||
</project> |
@ -0,0 +1,13 @@ |
||||
php: |
||||
preset: laravel |
||||
disabled: |
||||
- no_unused_imports |
||||
finder: |
||||
not-name: |
||||
- index.php |
||||
- server.php |
||||
js: |
||||
finder: |
||||
not-name: |
||||
- webpack.mix.js |
||||
css: true |
@ -0,0 +1,5 @@ |
||||
{ |
||||
"recommendations": [ |
||||
"erlangparasu.goto-route-controller-laravel" |
||||
] |
||||
} |
@ -0,0 +1,74 @@ |
||||
<p align="center"><a href="https://laravel.com" target="_blank"><img src="https://raw.githubusercontent.com/laravel/art/master/logo-lockup/5%20SVG/2%20CMYK/1%20Full%20Color/laravel-logolockup-cmyk-red.svg" width="400"></a></p> |
||||
|
||||
<p align="center"> |
||||
<a href="https://travis-ci.org/laravel/framework"><img src="https://travis-ci.org/laravel/framework.svg" alt="Build Status"></a> |
||||
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/dt/laravel/framework" alt="Total Downloads"></a> |
||||
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/v/laravel/framework" alt="Latest Stable Version"></a> |
||||
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/l/laravel/framework" alt="License"></a> |
||||
</p> |
||||
|
||||
## About Laravel |
||||
|
||||
Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experience to be truly fulfilling. Laravel takes the pain out of development by easing common tasks used in many web projects, such as: |
||||
|
||||
- [Simple, fast routing engine](https://laravel.com/docs/routing). |
||||
- [Powerful dependency injection container](https://laravel.com/docs/container). |
||||
- Multiple back-ends for [session](https://laravel.com/docs/session) and [cache](https://laravel.com/docs/cache) storage. |
||||
- Expressive, intuitive [database ORM](https://laravel.com/docs/eloquent). |
||||
- Database agnostic [schema migrations](https://laravel.com/docs/migrations). |
||||
- [Robust background job processing](https://laravel.com/docs/queues). |
||||
- [Real-time event broadcasting](https://laravel.com/docs/broadcasting). |
||||
|
||||
Laravel is accessible, powerful, and provides tools required for large, robust applications. |
||||
|
||||
## Learning Laravel |
||||
|
||||
Laravel has the most extensive and thorough [documentation](https://laravel.com/docs) and video tutorial library of all modern web application frameworks, making it a breeze to get started with the framework. |
||||
|
||||
If you don't feel like reading, [Laracasts](https://laracasts.com) can help. Laracasts contains over 1500 video tutorials on a range of topics including Laravel, modern PHP, unit testing, and JavaScript. Boost your skills by digging into our comprehensive video library. |
||||
|
||||
## Laravel Sponsors |
||||
|
||||
We would like to extend our thanks to the following sponsors for funding Laravel development. If you are interested in becoming a sponsor, please visit the Laravel [Patreon page](https://patreon.com/taylorotwell). |
||||
|
||||
### Premium Partners |
||||
|
||||
- **[Vehikl](https://vehikl.com/)** |
||||
- **[Tighten Co.](https://tighten.co)** |
||||
- **[Kirschbaum Development Group](https://kirschbaumdevelopment.com)** |
||||
- **[64 Robots](https://64robots.com)** |
||||
- **[Cubet Techno Labs](https://cubettech.com)** |
||||
- **[Cyber-Duck](https://cyber-duck.co.uk)** |
||||
- **[Many](https://www.many.co.uk)** |
||||
- **[Webdock, Fast VPS Hosting](https://www.webdock.io/en)** |
||||
- **[DevSquad](https://devsquad.com)** |
||||
- **[Curotec](https://www.curotec.com/services/technologies/laravel/)** |
||||
- **[OP.GG](https://op.gg)** |
||||
|
||||
## Contributing |
||||
|
||||
Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the [Laravel documentation](https://laravel.com/docs/contributions). |
||||
|
||||
## Code of Conduct |
||||
|
||||
In order to ensure that the Laravel community is welcoming to all, please review and abide by the [Code of Conduct](https://laravel.com/docs/contributions#code-of-conduct). |
||||
|
||||
## Security Vulnerabilities |
||||
|
||||
If you discover a security vulnerability within Laravel, please send an e-mail to Taylor Otwell via [taylor@laravel.com](mailto:taylor@laravel.com). All security vulnerabilities will be promptly addressed. |
||||
|
||||
## License |
||||
|
||||
The Laravel framework is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT). |
||||
|
||||
|
||||
## Design changed: |
||||
#theme.minc619.css-> removed: |
||||
.page-header{ |
||||
border-bottom:.0625rem solid #e7eaf3; |
||||
margin-bottom:2.25rem |
||||
} |
||||
#vendoe.min.css-> = |
||||
.select2-container--default .select2-selection--single{ |
||||
background-color:#fff;display: block;width: 100%;height: calc(1.6em + 1.21875rem);padding: .54688rem .875rem;font-size: .875rem;font-weight: 400;line-height: 1.6;color: #1e2022;background-color: #fff;background-clip: padding-box;border: .0625rem solid #e7eaf3;border-radius: .3125rem;transition: border-color .15s ease-in-out,box-shadow .15s ease-in-out; |
||||
} |
@ -0,0 +1,45 @@ |
||||
<?php |
||||
|
||||
namespace App\CentralLogics; |
||||
|
||||
use App\Models\Banner; |
||||
use App\Models\Food; |
||||
use App\Models\Restaurant; |
||||
use App\CentralLogics\Helpers; |
||||
|
||||
class BannerLogic |
||||
{ |
||||
public static function get_banners($zone_id) |
||||
{ |
||||
$banners = Banner::active()->whereIn('zone_id', $zone_id)->get(); |
||||
$data = []; |
||||
foreach($banners as $banner) |
||||
{ |
||||
if($banner->type=='restaurant_wise') |
||||
{ |
||||
$restaurant = Restaurant::find($banner->data); |
||||
$data[]=[ |
||||
'id'=>$banner->id, |
||||
'title'=>$banner->title, |
||||
'type'=>$banner->type, |
||||
'image'=>$banner->image, |
||||
'restaurant'=> $restaurant?Helpers::restaurant_data_formatting($restaurant, false):null, |
||||
'food'=>null |
||||
]; |
||||
} |
||||
if($banner->type=='item_wise') |
||||
{ |
||||
$food = Food::find($banner->data); |
||||
$data[]=[ |
||||
'id'=>$banner->id, |
||||
'title'=>$banner->title, |
||||
'type'=>$banner->type, |
||||
'image'=>$banner->image, |
||||
'restaurant'=> null, |
||||
'food'=> $food?Helpers::product_data_formatting($food, false, false, app()->getLocale()):null, |
||||
]; |
||||
} |
||||
} |
||||
return $data; |
||||
} |
||||
} |
@ -0,0 +1,38 @@ |
||||
<?php |
||||
|
||||
namespace App\CentralLogics; |
||||
|
||||
use App\Models\Campaign; |
||||
use App\CentralLogics\Helpers; |
||||
|
||||
class CampaignLogic |
||||
{ |
||||
public static function get_basic_campaigns($restaurant_id, $limit = 25, $offset = 1) |
||||
{ |
||||
$data = []; |
||||
$paginator=Campaign::with('restaurants')->latest()->paginate($limit, ['*'], 'page', $offset); |
||||
foreach ($paginator->items() as $item) { |
||||
$variations = []; |
||||
$restaurant_ids = count($item->restaurants)?$item->restaurants->pluck('id')->toArray():[]; |
||||
if($item->start_date) |
||||
{ |
||||
$item['available_date_starts']=$item->start_date->format('Y-m-d'); |
||||
unset($item['start_date']); |
||||
} |
||||
if($item->end_date) |
||||
{ |
||||
$item['available_date_ends']=$item->end_date->format('Y-m-d'); |
||||
unset($item['end_date']); |
||||
} |
||||
$item['is_joined'] = in_array($restaurant_id, $restaurant_ids)?true:false; |
||||
unset($item['restaurants']); |
||||
array_push($data, $item); |
||||
} |
||||
return [ |
||||
'total_size' => $paginator->total(), |
||||
'limit' => $limit, |
||||
'offset' => $offset, |
||||
'campaigns' => $data |
||||
]; |
||||
} |
||||
} |
@ -0,0 +1,92 @@ |
||||
<?php |
||||
|
||||
namespace App\CentralLogics; |
||||
|
||||
use App\Models\Category; |
||||
use App\Models\Food; |
||||
use App\Models\Restaurant; |
||||
|
||||
class CategoryLogic |
||||
{ |
||||
public static function parents() |
||||
{ |
||||
return Category::where('position', 0)->get(); |
||||
} |
||||
|
||||
public static function child($parent_id) |
||||
{ |
||||
return Category::where(['parent_id' => $parent_id])->get(); |
||||
} |
||||
|
||||
public static function products($category_id, array $zone_id, int $limit,int $offset, $type) |
||||
{ |
||||
$paginator = Food::whereHas('restaurant', function($query)use($zone_id){ |
||||
return $query->whereIn('zone_id', $zone_id); |
||||
}) |
||||
->whereHas('category',function($q)use($category_id){ |
||||
return $q->whereId($category_id)->orWhere('parent_id', $category_id); |
||||
}) |
||||
->active()->type($type)->latest()->paginate($limit, ['*'], 'page', $offset); |
||||
|
||||
return [ |
||||
'total_size' => $paginator->total(), |
||||
'limit' => $limit, |
||||
'offset' => $offset, |
||||
'products' => $paginator->items() |
||||
]; |
||||
} |
||||
|
||||
|
||||
public static function restaurants($category_id, array $zone_id, int $limit,int $offset, $type,$longitude=0,$latitude=0) |
||||
{ |
||||
$paginator = Restaurant::withOpen($longitude,$latitude)->whereIn('zone_id', $zone_id) |
||||
->whereHas('foods.category', function($query)use($category_id){ |
||||
return $query->whereId($category_id)->orWhere('parent_id', $category_id); |
||||
}) |
||||
// ->whereHas('category',function($q)use($category_id){ |
||||
// return $q->whereId($category_id)->orWhere('parent_id', $category_id); |
||||
// }) |
||||
->active()->type($type)->latest()->paginate($limit, ['*'], 'page', $offset); |
||||
|
||||
return [ |
||||
'total_size' => $paginator->total(), |
||||
'limit' => $limit, |
||||
'offset' => $offset, |
||||
'restaurants' => $paginator->items() |
||||
]; |
||||
} |
||||
|
||||
|
||||
public static function all_products($id) |
||||
{ |
||||
$cate_ids=[]; |
||||
array_push($cate_ids,(int)$id); |
||||
foreach (CategoryLogic::child($id) as $ch1){ |
||||
array_push($cate_ids,$ch1['id']); |
||||
foreach (CategoryLogic::child($ch1['id']) as $ch2){ |
||||
array_push($cate_ids,$ch2['id']); |
||||
} |
||||
} |
||||
|
||||
return Food::whereIn('category_id', $cate_ids)->get(); |
||||
} |
||||
|
||||
|
||||
public static function format_export_category($category) |
||||
{ |
||||
$storage = []; |
||||
foreach($category as $item) |
||||
{ |
||||
$storage[] = [ |
||||
'id'=>$item->id, |
||||
'name'=>$item->name, |
||||
'image'=>$item->image, |
||||
'parent_id'=>$item->parent_id, |
||||
'position'=>$item->position, |
||||
'priority'=>$item->priority, |
||||
]; |
||||
} |
||||
|
||||
return $storage; |
||||
} |
||||
} |
@ -0,0 +1,89 @@ |
||||
<?php |
||||
|
||||
namespace App\CentralLogics; |
||||
|
||||
use App\Models\Order; |
||||
use App\Models\Restaurant; |
||||
use Carbon\Carbon; |
||||
|
||||
class CouponLogic |
||||
{ |
||||
public static function get_discount($coupon, $order_amount) |
||||
{ |
||||
$discount_ammount = 0; |
||||
if($coupon->discount_type=='percent' && $coupon->discount > 0) |
||||
{ |
||||
$discount_ammount = $order_amount* ($coupon->discount/100); |
||||
} |
||||
else |
||||
{ |
||||
$discount_ammount = $coupon->discount; |
||||
} |
||||
if($coupon->max_discount > 0) |
||||
{ |
||||
$discount_ammount = $discount_ammount > $coupon->max_discount?$coupon->max_discount:$discount_ammount; |
||||
} |
||||
return $discount_ammount; |
||||
} |
||||
|
||||
public static function is_valide($coupon, $user_id, $restaurant_id) |
||||
{ |
||||
|
||||
$start_date = Carbon::parse($coupon->start_date); |
||||
$expire_date = Carbon::parse($coupon->expire_date); |
||||
$customer_ids=json_decode($coupon->customer_id, true); |
||||
|
||||
$today = Carbon::now(); |
||||
if($start_date->format('Y-m-d') > $today->format('Y-m-d') || $expire_date->format('Y-m-d') < $today->format('Y-m-d')) |
||||
{ |
||||
return 407; //coupon expire |
||||
} |
||||
|
||||
if($coupon->coupon_type == 'restaurant_wise' && !in_array($restaurant_id, json_decode($coupon->data, true))) |
||||
{ |
||||
return 404; |
||||
} |
||||
if($coupon->created_by == 'vendor' && $restaurant_id != $coupon->restaurant_id ){ |
||||
return 404; |
||||
} |
||||
|
||||
if((!in_array("all", $customer_ids) && !in_array($user_id,$customer_ids)) ){ |
||||
return 408; //unauthorized user |
||||
} |
||||
|
||||
else if($coupon->coupon_type == 'zone_wise') |
||||
{ |
||||
if(json_decode($coupon->data, true)){ |
||||
$data = Restaurant::whereIn('zone_id',json_decode($coupon->data, true))->where('id', $restaurant_id)->first(); |
||||
if(!$data) |
||||
{ |
||||
return 404; |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
return 404; |
||||
} |
||||
} |
||||
else if($coupon->coupon_type == 'first_order') |
||||
{ |
||||
$total = Order::where(['user_id' => $user_id])->count(); |
||||
if ($total < $coupon['limit']) { |
||||
return 200; |
||||
}else{ |
||||
return 406;//Limite orer |
||||
} |
||||
} |
||||
if ($coupon['limit'] == null) { |
||||
return 200; |
||||
} else { |
||||
$total = Order::where(['user_id' => $user_id, 'coupon_code' => $coupon['code']])->count(); |
||||
if ($total < $coupon['limit']) { |
||||
return 200; |
||||
}else{ |
||||
return 406;//Limite orer |
||||
} |
||||
} |
||||
return 404; //not found |
||||
} |
||||
} |
@ -0,0 +1,119 @@ |
||||
<?php |
||||
|
||||
namespace App\CentralLogics; |
||||
|
||||
use App\Models\BusinessSetting; |
||||
use App\Models\LoyaltyPointTransaction; |
||||
use App\Models\User; |
||||
use App\Models\WalletTransaction; |
||||
use Illuminate\Support\Facades\DB; |
||||
|
||||
class CustomerLogic{ |
||||
public static function create_wallet_transaction($user_id, float $amount, $transaction_type, $referance) |
||||
{ |
||||
if(BusinessSetting::where('key','wallet_status')->first()->value != 1) return false; |
||||
|
||||
$user = User::find($user_id); |
||||
$current_balance = $user->wallet_balance; |
||||
|
||||
$wallet_transaction = new WalletTransaction(); |
||||
$wallet_transaction->user_id = $user->id; |
||||
$wallet_transaction->transaction_id = \Str::uuid(); |
||||
$wallet_transaction->reference = $referance; |
||||
$wallet_transaction->transaction_type = $transaction_type; |
||||
|
||||
$debit = 0.0; |
||||
$credit = 0.0; |
||||
|
||||
if(in_array($transaction_type, ['add_fund_by_admin','add_fund','order_refund','loyalty_point', 'referrer'])) |
||||
{ |
||||
$credit = $amount; |
||||
if($transaction_type == 'add_fund') |
||||
{ |
||||
$wallet_transaction->admin_bonus = $amount*BusinessSetting::where('key','wallet_add_fund_bonus')->first()->value/100; |
||||
} |
||||
else if($transaction_type == 'loyalty_point') |
||||
{ |
||||
$credit = (int)($amount / BusinessSetting::where('key','loyalty_point_exchange_rate')->first()->value); |
||||
} |
||||
} |
||||
else if($transaction_type == 'order_place') |
||||
{ |
||||
$debit = $amount; |
||||
} |
||||
|
||||
$wallet_transaction->credit = $credit; |
||||
$wallet_transaction->debit = $debit; |
||||
$wallet_transaction->balance = $current_balance + $credit - $debit; |
||||
$wallet_transaction->created_at = now(); |
||||
$wallet_transaction->updated_at = now(); |
||||
$user->wallet_balance = $current_balance + $credit - $debit; |
||||
|
||||
try{ |
||||
DB::beginTransaction(); |
||||
$user->save(); |
||||
$wallet_transaction->save(); |
||||
DB::commit(); |
||||
if(in_array($transaction_type, ['loyalty_point','order_place','add_fund_by_admin', 'referrer'])) return $wallet_transaction; |
||||
return true; |
||||
}catch(\Exception $ex) |
||||
{ |
||||
info($ex); |
||||
DB::rollback(); |
||||
|
||||
return false; |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
public static function create_loyalty_point_transaction($user_id, $referance, $amount, $transaction_type) |
||||
{ |
||||
$settings = array_column(BusinessSetting::whereIn('key',['loyalty_point_status','loyalty_point_exchange_rate','loyalty_point_item_purchase_point'])->get()->toArray(), 'value','key'); |
||||
if($settings['loyalty_point_status'] != 1) |
||||
{ |
||||
return true; |
||||
} |
||||
|
||||
$credit = 0; |
||||
$debit = 0; |
||||
$user = User::find($user_id); |
||||
|
||||
$loyalty_point_transaction = new LoyaltyPointTransaction(); |
||||
$loyalty_point_transaction->user_id = $user->id; |
||||
$loyalty_point_transaction->transaction_id = \Str::uuid(); |
||||
$loyalty_point_transaction->reference = $referance; |
||||
$loyalty_point_transaction->transaction_type = $transaction_type; |
||||
|
||||
if($transaction_type=='order_place') |
||||
{ |
||||
$credit = (int)($amount * $settings['loyalty_point_item_purchase_point']/100); |
||||
} |
||||
else if($transaction_type=='point_to_wallet') |
||||
{ |
||||
$debit = $amount; |
||||
} |
||||
|
||||
$current_balance = $user->loyalty_point + $credit - $debit; |
||||
$loyalty_point_transaction->balance = $current_balance; |
||||
$loyalty_point_transaction->credit = $credit; |
||||
$loyalty_point_transaction->debit = $debit; |
||||
$loyalty_point_transaction->created_at = now(); |
||||
$loyalty_point_transaction->updated_at = now(); |
||||
$user->loyalty_point = $current_balance; |
||||
|
||||
try{ |
||||
DB::beginTransaction(); |
||||
$user->save(); |
||||
$loyalty_point_transaction->save(); |
||||
DB::commit(); |
||||
return true; |
||||
}catch(\Exception $ex) |
||||
{ |
||||
info($ex); |
||||
DB::rollback(); |
||||
|
||||
return false; |
||||
} |
||||
return false; |
||||
} |
||||
} |
@ -0,0 +1,55 @@ |
||||
<?php |
||||
|
||||
namespace App\CentralLogics; |
||||
|
||||
use Illuminate\Support\Facades\Storage; |
||||
|
||||
|
||||
class FileManagerLogic |
||||
{ |
||||
private static function get_file_name($path) |
||||
{ |
||||
$temp = explode('/',$path); |
||||
return end($temp); |
||||
} |
||||
|
||||
private static function get_file_ext($name) |
||||
{ |
||||
$temp = explode('.',$name); |
||||
return end($temp); |
||||
} |
||||
|
||||
private static function get_path_for_db($full_path) |
||||
{ |
||||
$temp = explode('/',$full_path, 3); |
||||
return end($temp); |
||||
} |
||||
|
||||
public static function format_file_and_folders($files, $type) |
||||
{ |
||||
$data = []; |
||||
foreach($files as $file) |
||||
{ |
||||
$name = self::get_file_name($file); |
||||
$ext = self::get_file_ext($name); |
||||
$path = ''; |
||||
if($type == 'file') |
||||
{ |
||||
$path = $file; |
||||
} |
||||
if($type == 'folder') |
||||
{ |
||||
$path = $file; |
||||
} |
||||
if(in_array($ext, ['jpg', 'png', 'jpeg', 'gif', 'bmp', 'tif', 'tiff']) || $type=='folder') |
||||
$data[] = [ |
||||
'name'=> $name, |
||||
'path'=> $path, |
||||
'db_path'=> self::get_path_for_db($file), |
||||
'type'=>$type |
||||
]; |
||||
} |
||||
return $data; |
||||
} |
||||
|
||||
} |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,561 @@ |
||||
<?php |
||||
|
||||
namespace App\CentralLogics; |
||||
|
||||
use App\Models\Food; |
||||
use App\Models\User; |
||||
use App\Models\Admin; |
||||
use App\Models\Order; |
||||
use App\Models\Incentive; |
||||
use App\Models\AdminWallet; |
||||
use Illuminate\Support\Str; |
||||
use App\Models\IncentiveLog; |
||||
use App\Models\BusinessSetting; |
||||
use App\Models\OrderTransaction; |
||||
use App\Models\RestaurantWallet; |
||||
use App\Models\DeliveryManWallet; |
||||
use Illuminate\Support\Facades\DB; |
||||
use Illuminate\Support\Facades\Mail; |
||||
use App\Models\Subscription; |
||||
use App\Models\SubscriptionLog; |
||||
use Exception; |
||||
|
||||
class OrderLogic |
||||
{ |
||||
public static function gen_unique_id() |
||||
{ |
||||
return rand(1000, 9999) . '-' . Str::random(5) . '-' . time(); |
||||
} |
||||
|
||||
public static function track_order($order_id) |
||||
{ |
||||
return Helpers::order_data_formatting(Order::with(['details', 'delivery_man.rating'])->where(['id' => $order_id])->first(), false); |
||||
} |
||||
|
||||
public static function place_order($customer_id, $email, $customer_info, $cart, $payment_method, $discount, $coupon_code = null) |
||||
{ |
||||
try { |
||||
$or = [ |
||||
'id' => 100000 + Order::all()->count() + 1, |
||||
'user_id' => $customer_id, |
||||
'order_amount' => CartManager::cart_grand_total($cart) - $discount, |
||||
'payment_status' => 'unpaid', |
||||
'order_status' => 'pending', |
||||
'payment_method' => $payment_method, |
||||
'transaction_ref' => null, |
||||
'discount_amount' => $discount, |
||||
'coupon_code' => $coupon_code, |
||||
'discount_type' => $discount == 0 ? null : 'coupon_discount', |
||||
'shipping_address' => $customer_info['address_id'], |
||||
'created_at' => now(), |
||||
'updated_at' => now() |
||||
]; |
||||
|
||||
$o_id = DB::table('orders')->insertGetId($or); |
||||
|
||||
foreach ($cart as $c) { |
||||
$product = Food::where('id', $c['id'])->first(); |
||||
$or_d = [ |
||||
'order_id' => $o_id, |
||||
'food_id' => $c['id'], |
||||
'seller_id' => $product->added_by == 'seller' ? $product->user_id : '0', |
||||
'product_details' => $product, |
||||
'qty' => $c['quantity'], |
||||
'price' => $c['price'], |
||||
'tax' => $c['tax'] * $c['quantity'], |
||||
'discount' => $c['discount'] * $c['quantity'], |
||||
'discount_type' => 'discount_on_product', |
||||
'variant' => $c['variant'], |
||||
'variation' => json_encode($c['variations']), |
||||
'delivery_status' => 'pending', |
||||
'shipping_method_id' => $c['shipping_method_id'], |
||||
'payment_status' => 'unpaid', |
||||
'created_at' => now(), |
||||
'updated_at' => now() |
||||
]; |
||||
DB::table('order_details')->insert($or_d); |
||||
} |
||||
if(config('mail.status')) |
||||
{ |
||||
Mail::to($email)->send(new \App\Mail\OrderPlaced($o_id)); |
||||
} |
||||
|
||||
} catch (\Exception $e) { |
||||
|
||||
} |
||||
|
||||
return $o_id; |
||||
} |
||||
|
||||
public static function updated_order_calculation($order) |
||||
{ |
||||
return true; |
||||
} |
||||
|
||||
//here |
||||
public static function create_transaction($order, $received_by=false, $status = null) |
||||
{ |
||||
$comission = !isset($order->restaurant->comission)?\App\Models\BusinessSetting::where('key','admin_commission')->first()->value:$order->restaurant->comission; |
||||
|
||||
$admin_subsidy = 0; |
||||
$amount_admin = 0; |
||||
$restaurant_d_amount = 0; |
||||
$admin_coupon_discount_subsidy =0; |
||||
$restaurant_subsidy =0; |
||||
$restaurant_coupon_discount_subsidy =0; |
||||
$restaurant_discount_amount=0; |
||||
$restaurant= $order->restaurant; |
||||
$rest_sub = $restaurant->restaurant_sub; |
||||
|
||||
// free delivery by admin |
||||
if($order->free_delivery_by == 'admin') |
||||
{ |
||||
$admin_subsidy = $order->original_delivery_charge; |
||||
Helpers::expenseCreate($order->original_delivery_charge,'free_delivery',now(),$order->id,$order->free_delivery_by); |
||||
} |
||||
// free delivery by restaurant |
||||
if($order->free_delivery_by == 'vendor') |
||||
{ |
||||
$restaurant_subsidy = $order->original_delivery_charge; |
||||
Helpers::expenseCreate($order->original_delivery_charge,'free_delivery',now(),$order->id,$order->free_delivery_by,$order->restaurant->id); |
||||
} |
||||
// coupon discount by Admin |
||||
if($order->coupon_created_by == 'admin') |
||||
{ |
||||
$admin_coupon_discount_subsidy = $order->coupon_discount_amount; |
||||
Helpers::expenseCreate($admin_coupon_discount_subsidy,'coupon_discount',now(),$order->id,$order->coupon_created_by); |
||||
} |
||||
// coupon discount by restaurant |
||||
if($order->coupon_created_by == 'vendor') |
||||
{ |
||||
$restaurant_coupon_discount_subsidy = $order->coupon_discount_amount; |
||||
Helpers::expenseCreate($restaurant_coupon_discount_subsidy,'coupon_discount',now(),$order->id,$order->coupon_created_by,$order->restaurant->id); |
||||
} |
||||
|
||||
if($order->restaurant_discount_amount > 0 && $order->discount_on_product_by == 'vendor') |
||||
{ |
||||
if($restaurant->restaurant_model == 'subscription' && isset($rest_sub)){ |
||||
$restaurant_d_amount= $order->restaurant_discount_amount; |
||||
Helpers::expenseCreate($restaurant_d_amount,'discount_on_product',now(),$order->id,'vendor',$order->restaurant->id); |
||||
} else{ |
||||
$amount_admin = $comission?($order->restaurant_discount_amount/ 100) * $comission:0; |
||||
$restaurant_d_amount= $order->restaurant_discount_amount- $amount_admin; |
||||
Helpers::expenseCreate($restaurant_d_amount,'discount_on_product',now(),$order->id,'vendor',$order->restaurant->id); |
||||
Helpers::expenseCreate($amount_admin,'discount_on_product',now(),$order->id,'admin'); |
||||
} |
||||
} |
||||
|
||||
if($order->restaurant_discount_amount > 0 && $order->discount_on_product_by == 'admin') |
||||
{ |
||||
$restaurant_discount_amount=$order->restaurant_discount_amount; |
||||
Helpers::expenseCreate($restaurant_discount_amount,'discount_on_product',now(),$order->id,'admin'); |
||||
} |
||||
|
||||
|
||||
$order_amount = $order->order_amount - $order->delivery_charge - $order->total_tax_amount - $order->dm_tips + $order->coupon_discount_amount + $restaurant_discount_amount; |
||||
|
||||
if($restaurant->restaurant_model == 'subscription' && isset($rest_sub)){ |
||||
$comission_amount =0; |
||||
$subscription_mode= 1; |
||||
$commission_percentage= 0; |
||||
} |
||||
else{ |
||||
$comission_amount = $comission?($order_amount/ 100) * $comission:0; |
||||
$subscription_mode= 0; |
||||
$commission_percentage= $comission; |
||||
} |
||||
|
||||
if(($restaurant->restaurant_model == 'subscription' && isset($rest_sub) && $rest_sub->self_delivery == 1) || ($restaurant->restaurant_model != 'subscription' && $restaurant->self_delivery_system)){ |
||||
$comission_on_delivery =0; |
||||
$comission_on_actual_delivery_fee =0; |
||||
} |
||||
else{ |
||||
$delivery_charge_comission = BusinessSetting::where('key', 'delivery_charge_comission')->first(); |
||||
$delivery_charge_comission_percentage = $delivery_charge_comission ? $delivery_charge_comission->value : 0; |
||||
|
||||
$comission_on_delivery = $delivery_charge_comission_percentage * ( $order->original_delivery_charge / 100 ); |
||||
$comission_on_actual_delivery_fee = ($order->delivery_charge > 0) ? $comission_on_delivery : 0; |
||||
} |
||||
$restaurant_amount =$order_amount + $order->total_tax_amount - $comission_amount - $restaurant_coupon_discount_subsidy ; |
||||
try{ |
||||
OrderTransaction::insert([ |
||||
'vendor_id' =>$order->restaurant->vendor->id, |
||||
'delivery_man_id'=>$order->delivery_man_id, |
||||
'order_id' =>$order->id, |
||||
'order_amount'=>$order->order_amount, |
||||
'restaurant_amount'=>$restaurant_amount, |
||||
'admin_commission'=>$comission_amount - $admin_subsidy - $admin_coupon_discount_subsidy, |
||||
//add a new column. add the comission here |
||||
'delivery_charge'=>$order->delivery_charge - $comission_on_actual_delivery_fee,//minus here |
||||
'original_delivery_charge'=>$order->original_delivery_charge - $comission_on_delivery,//calculate the comission with this. minus here |
||||
'tax'=>$order->total_tax_amount, |
||||
'received_by'=> $received_by?$received_by:'admin', |
||||
'zone_id'=>$order->zone_id, |
||||
'status'=> $status, |
||||
'dm_tips'=> $order->dm_tips, |
||||
'created_at' => now(), |
||||
'updated_at' => now(), |
||||
'delivery_fee_comission'=>$comission_on_actual_delivery_fee, |
||||
'admin_expense'=>$admin_subsidy + $admin_coupon_discount_subsidy + $restaurant_discount_amount + $amount_admin, |
||||
'restaurant_expense'=>$restaurant_subsidy + $restaurant_coupon_discount_subsidy , |
||||
// for restaurant business model |
||||
'is_subscribed'=> $subscription_mode, |
||||
'commission_percentage'=> $commission_percentage, |
||||
'discount_amount_by_restaurant' => $restaurant_coupon_discount_subsidy + $restaurant_d_amount + $restaurant_subsidy, |
||||
// for subscription order |
||||
'is_subscription' => isset($order->subscription_id) ? $order->subscription_id : 0 , |
||||
]); |
||||
$adminWallet = AdminWallet::firstOrNew( |
||||
['admin_id' => Admin::where('role_id', 1)->first()->id] |
||||
); |
||||
$vendorWallet = RestaurantWallet::firstOrNew( |
||||
['vendor_id' => $order->restaurant->vendor->id] |
||||
); |
||||
if($order->delivery_man && |
||||
(($restaurant->restaurant_model == 'subscription' && isset($rest_sub) && $rest_sub->self_delivery == 0) || ($restaurant->restaurant_model != 'subscription' && $restaurant->self_delivery_system == 0)) |
||||
){ |
||||
$dmWallet = DeliveryManWallet::firstOrNew( |
||||
['delivery_man_id' => $order->delivery_man_id] |
||||
); |
||||
if (isset($order->delivery_man->earning) && $order->delivery_man->earning == 1) { |
||||
self::check_incentive($order->zone_id, $order->delivery_man_id, $order->delivery_man->todays_earning()->sum('original_delivery_charge'), $order->delivery_man->incentive); |
||||
|
||||
$dmWallet->total_earning = $dmWallet->total_earning + $order->dm_tips + $order->original_delivery_charge - $comission_on_delivery; |
||||
} else { |
||||
$adminWallet->total_commission_earning = $adminWallet->total_commission_earning + $order->dm_tips + $order->original_delivery_charge - $comission_on_delivery; |
||||
} |
||||
} |
||||
|
||||
$adminWallet->total_commission_earning = $adminWallet->total_commission_earning + $comission_amount + $comission_on_actual_delivery_fee - $admin_subsidy - $admin_coupon_discount_subsidy -$restaurant_discount_amount; |
||||
|
||||
if(($restaurant->restaurant_model == 'subscription' && isset($rest_sub) && $rest_sub->self_delivery == 1) || ($restaurant->restaurant_model != 'subscription' && $restaurant->self_delivery_system == 1)) |
||||
{ |
||||
$vendorWallet->total_earning = $vendorWallet->total_earning + $order->delivery_charge + $order->dm_tips; |
||||
} |
||||
else{ |
||||
$adminWallet->delivery_charge = $adminWallet->delivery_charge + $order->delivery_charge - $comission_on_actual_delivery_fee; |
||||
} |
||||
$vendorWallet->total_earning = $vendorWallet->total_earning + $restaurant_amount; |
||||
try |
||||
{ |
||||
DB::beginTransaction(); |
||||
if($received_by=='admin') |
||||
{ |
||||
$adminWallet->digital_received = $adminWallet->digital_received + $order->order_amount; |
||||
} |
||||
else if($received_by=='restaurant' && $order->payment_method == 'cash_on_delivery') |
||||
{ |
||||
$vendorWallet->collected_cash = $vendorWallet->collected_cash + $order->order_amount; |
||||
} |
||||
else if($received_by==false) |
||||
{ |
||||
$adminWallet->manual_received = $adminWallet->manual_received + $order->order_amount; |
||||
} |
||||
else if($received_by=='deliveryman' && $order->delivery_man->type == 'zone_wise' && $order->payment_method == 'cash_on_delivery') |
||||
{ |
||||
if(!isset($dmWallet)) { |
||||
$dmWallet = DeliveryManWallet::firstOrNew( |
||||
['delivery_man_id' => $order->delivery_man_id] |
||||
); |
||||
} |
||||
$dmWallet->collected_cash=$dmWallet->collected_cash+$order->order_amount; |
||||
} |
||||
if(isset($dmWallet)) { |
||||
$dmWallet->save(); |
||||
} |
||||
$vendorWallet->save(); |
||||
$adminWallet->save(); |
||||
DB::commit(); |
||||
|
||||
$ref_status = BusinessSetting::where('key','ref_earning_status')->first()->value; |
||||
if(isset($order->customer->ref_by) && $order->customer->order_count == 0 && $ref_status == 1){ |
||||
$ref_code_exchange_amt = BusinessSetting::where('key','ref_earning_exchange_rate')->first()->value; |
||||
$referar_user=User::where('id',$order->customer->ref_by)->first(); |
||||
$refer_wallet_transaction = CustomerLogic::create_wallet_transaction($referar_user->id, $ref_code_exchange_amt, 'referrer',$order->customer->phone); |
||||
try{ |
||||
if(config('mail.status')) { |
||||
Mail::to($referar_user->email)->send(new \App\Mail\AddFundToWallet($refer_wallet_transaction)); |
||||
} |
||||
} catch(\Exception $ex){ |
||||
info($ex->getMessage()); |
||||
} |
||||
} |
||||
|
||||
if($order->user_id) CustomerLogic::create_loyalty_point_transaction($order->user_id, $order->id, $order->order_amount, 'order_place'); |
||||
} |
||||
catch(\Exception $e) |
||||
{ |
||||
DB::rollBack(); |
||||
info($e); |
||||
return false; |
||||
} |
||||
} |
||||
catch(\Exception $e){ |
||||
info($e); |
||||
return false; |
||||
} |
||||
return true; |
||||
} |
||||
public static function refund_before_delivered($order){ |
||||
$adminWallet = AdminWallet::firstOrNew( |
||||
['admin_id' => Admin::where('role_id', 1)->first()->id] |
||||
); |
||||
if ($order->payment_method == 'cash_on_delivery') { |
||||
return false; |
||||
} |
||||
$adminWallet->digital_received = $adminWallet->digital_received - $order->order_amount; |
||||
$adminWallet->save(); |
||||
if ($order->payment_status == "paid" && BusinessSetting::where('key', 'wallet_add_refund')->first()->value == 1) { |
||||
CustomerLogic::create_wallet_transaction($order->user_id, $order->order_amount, 'order_refund', $order->id); |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
|
||||
public static function refund_order($order) |
||||
{ |
||||
$order_transaction = $order->transaction; |
||||
if($order_transaction == null || $order->restaurant == null) |
||||
{ |
||||
return false; |
||||
} |
||||
$received_by = $order_transaction->received_by; |
||||
|
||||
$adminWallet = AdminWallet::firstOrNew( |
||||
['admin_id' => Admin::where('role_id', 1)->first()->id] |
||||
); |
||||
|
||||
$vendorWallet = RestaurantWallet::firstOrNew( |
||||
['vendor_id' => $order->restaurant->vendor->id] |
||||
); |
||||
|
||||
$adminWallet->total_commission_earning = $adminWallet->total_commission_earning - $order_transaction->admin_commission; |
||||
|
||||
$vendorWallet->total_earning = $vendorWallet->total_earning - $order_transaction->restaurant_amount; |
||||
|
||||
$refund_amount = $order->order_amount; |
||||
|
||||
$status = 'refunded_with_delivery_charge'; |
||||
if($order->order_status == 'delivered' || $order->order_status == 'refund_requested'|| $order->order_status == 'refund_request_canceled') |
||||
{ |
||||
$refund_amount = $order->order_amount - $order->delivery_charge - $order->dm_tips; |
||||
$status = 'refunded_without_delivery_charge'; |
||||
} |
||||
else |
||||
{ |
||||
$adminWallet->delivery_charge = $adminWallet->delivery_charge - $order_transaction->delivery_charge; |
||||
} |
||||
try |
||||
{ |
||||
DB::beginTransaction(); |
||||
if($received_by=='admin') |
||||
{ |
||||
if($order->delivery_man_id && $order->payment_method != "cash_on_delivery") |
||||
{ |
||||
$adminWallet->digital_received = $adminWallet->digital_received - $refund_amount; |
||||
} |
||||
else |
||||
{ |
||||
$adminWallet->manual_received = $adminWallet->manual_received - $refund_amount; |
||||
} |
||||
|
||||
} |
||||
else if($received_by=='restaurant') |
||||
{ |
||||
$vendorWallet->collected_cash = $vendorWallet->collected_cash - $refund_amount; |
||||
} |
||||
|
||||
// DB::table('account_transactions')->insert([ |
||||
// 'from_type'=>'customer', |
||||
// 'from_id'=>$order->user_id, |
||||
// 'current_balance'=> 0, |
||||
// 'amount'=> $refund_amount, |
||||
// 'method'=>'CASH', |
||||
// 'created_at' => now(), |
||||
// 'updated_at' => now() |
||||
// ]); |
||||
|
||||
else if($received_by=='deliveryman') |
||||
{ |
||||
$dmWallet = DeliveryManWallet::firstOrNew( |
||||
['delivery_man_id' => $order->delivery_man_id] |
||||
); |
||||
$dmWallet->collected_cash=$dmWallet->collected_cash - $refund_amount; |
||||
$dmWallet->save(); |
||||
} |
||||
$order_transaction->status = $status; |
||||
$order_transaction->save(); |
||||
|
||||
$adminWallet->save(); |
||||
$vendorWallet->save(); |
||||
DB::commit(); |
||||
} |
||||
catch(\Exception $e) |
||||
{ |
||||
DB::rollBack(); |
||||
info($e); |
||||
return false; |
||||
} |
||||
return true; |
||||
|
||||
} |
||||
|
||||
public static function format_export_data($orders) |
||||
{ |
||||
$data = []; |
||||
foreach($orders as $key=>$order) |
||||
{ |
||||
|
||||
$data[]=[ |
||||
'#'=>$key+1, |
||||
translate('messages.order')=>$order['id'], |
||||
translate('messages.date')=>date('d M Y',strtotime($order['created_at'])), |
||||
translate('messages.customer')=>$order->customer?$order->customer['f_name'].' '.$order->customer['l_name']:translate('messages.invalid').' '.translate('messages.customer').' '.translate('messages.data'), |
||||
translate('messages.Restaurant')=>Str::limit($order->restaurant?$order->restaurant->name:translate('messages.Restaurant deleted!'),20,'...'), |
||||
translate('messages.payment').' '.translate('messages.status')=>$order->payment_status=='paid'?translate('messages.paid'):translate('messages.unpaid'), |
||||
translate('messages.total')=>\App\CentralLogics\Helpers::format_currency($order['order_amount']), |
||||
translate('messages.order').' '.translate('messages.status')=>translate('messages.'. $order['order_status']), |
||||
translate('messages.order').' '.translate('messages.type')=>translate('messages.'.$order['order_type']) |
||||
]; |
||||
} |
||||
return $data; |
||||
} |
||||
|
||||
public static function format_order_report_export_data($orders) |
||||
{ |
||||
$data = []; |
||||
foreach($orders as $key=>$order) |
||||
{ |
||||
|
||||
$data[]=[ |
||||
'#'=>$key+1, |
||||
translate('messages.order')=>$order['id'], |
||||
translate('messages.restaurant')=>$order->restaurant?$order->restaurant->name:translate('messages.invalid'), |
||||
translate('messages.customer_name')=>$order->customer?$order->customer['f_name'].' '.$order->customer['l_name']:translate('messages.invalid').' '.translate('messages.customer').' '.translate('messages.data'), |
||||
translate('Total product Amount')=>\App\CentralLogics\Helpers::format_currency($order['order_amount']-$order['dm_tips']-$order['total_tax_amount']-$order['delivery_charge']+$order['coupon_discount_amount'] + $order['restaurant_discount_amount']), |
||||
translate('product Discount')=>\App\CentralLogics\Helpers::format_currency($order->details->sum('discount_on_item')), |
||||
translate('Coupon Discount')=>\App\CentralLogics\Helpers::format_currency($order['coupon_discount_amount']), |
||||
translate('Discounted Amount')=>\App\CentralLogics\Helpers::format_currency($order['coupon_discount_amount'] + $order['restaurant_discount_amount']), |
||||
translate('messages.tax')=>\App\CentralLogics\Helpers::format_currency($order['total_tax_amount']), |
||||
translate('messages.delivery_charge')=>\App\CentralLogics\Helpers::format_currency($order['original_delivery_charge']), |
||||
translate('messages.order_amount')=>\App\CentralLogics\Helpers::format_currency($order['order_amount']), |
||||
translate('messages.amount_received_by')=>isset($order->transaction) ? $order->transaction->received_by : translate('messages.unpaid'), |
||||
translate('messages.payment_method')=>translate(str_replace('_', ' ', $order['payment_method'])), |
||||
translate('messages.order').' '.translate('messages.status')=>translate('messages.'. $order['order_status']), |
||||
translate('messages.order').' '.translate('messages.type')=>translate('messages.'.$order['order_type']), |
||||
]; |
||||
} |
||||
return $data; |
||||
} |
||||
|
||||
public static function check_incentive($zone_id, $delivery_man_id, $delivery_man_earning, $dm_incentive) |
||||
{ |
||||
$incentive = Incentive::where('zone_id', $zone_id)->where('earning', '<=', $delivery_man_earning)->orderBy('earning', 'desc')->first(); |
||||
|
||||
if ($dm_incentive) { |
||||
if ($incentive && $dm_incentive->earning != $incentive->earning){ |
||||
$dm_incentive->earning = $incentive ? $incentive->earning : $dm_incentive->earning; |
||||
$dm_incentive->incentive = $incentive ? $incentive->incentive : $dm_incentive->incentive; |
||||
} |
||||
} else { |
||||
$dm_incentive = new IncentiveLog(); |
||||
$dm_incentive->earning = $incentive ? $incentive->earning : 0; |
||||
$dm_incentive->incentive = $incentive ? $incentive->incentive : 0; |
||||
$dm_incentive->delivery_man_id = $delivery_man_id; |
||||
$dm_incentive->zone_id = $zone_id; |
||||
$dm_incentive->date = now(); |
||||
$dm_incentive->status = 'pending'; |
||||
} |
||||
// $min_pay = self::check_min_pay($delivery_man_id, $delivery_man_earning + $dm_incentive->incentive); |
||||
// $dm_incentive->min_pay_subsidy = $min_pay[0]; |
||||
// $dm_incentive->working_hours = $min_pay[1]; |
||||
$dm_incentive->today_earning = $delivery_man_earning; |
||||
$dm_incentive->save(); |
||||
// info(["incentive_created", $dm_incentive]); |
||||
// Helpers::expenseCreate($dm_incentive->incentive,'incentive',now(),$delivery_man_id); |
||||
return true; |
||||
} |
||||
|
||||
public static function create_subscription_log($id=null) |
||||
{ |
||||
$order = Order::find($id); |
||||
if(!isset($order) || !isset($order->subscription->schedule) || !isset($order->subscription->schedule_today) || isset($order->subscription_log ) || $order->restaurant->restaurant_model == 'unsubscribed'){ |
||||
return true; |
||||
} |
||||
|
||||
$day = $order->subscription->schedule_today->day ?? $order->subscription->schedule->day ?? 0; |
||||
$today = ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'][$day] ??'Sun'; |
||||
$nextdate = date('Y-m-d', strtotime('next ' . $today)); |
||||
|
||||
$time= $order->subscription->schedule_today->time ?? $order->subscription->schedule->time; |
||||
$schedule_at = $day != 0 ? $nextdate : now()->format('Y-m-d'); |
||||
$subscription_log = new SubscriptionLog(); |
||||
$subscription_log->subscription_id = $order->subscription_id; |
||||
$subscription_log->order_id = $order->id; |
||||
$subscription_log->order_status = 'pending'; |
||||
$subscription_log->schedule_at = $schedule_at.' '.$time; |
||||
$subscription_log->updated_at = now(); |
||||
$subscription_log->created_at = now(); |
||||
$order->subscription_log()->save($subscription_log); |
||||
$order->order_status = 'pending'; |
||||
$order->payment_status='unpaid'; |
||||
$order->schedule_at = $schedule_at.' '.$time ; |
||||
$order->save(); |
||||
|
||||
Helpers::send_order_notification($order); |
||||
|
||||
return true; |
||||
} |
||||
|
||||
public static function update_subscription_log(Order $order):void |
||||
{ |
||||
if(!isset($order->subscription_log) || !isset($order->subscription_id)){ |
||||
return ; |
||||
} |
||||
$schedule_today = $order->subscription_log; |
||||
$schedule_today->order_status = $order->order_status; |
||||
$schedule_today->delivery_man_id = $order->delivery_man_id; |
||||
if($order->order_status != 'pending')$schedule_today->{$order->order_status} = now(); |
||||
$schedule_today->save(); |
||||
|
||||
if($order->order_status == 'delivered'){ |
||||
$subscription = $order->subscription; |
||||
$subscription->billing_amount += $order->order_amount; |
||||
$subscription->paid_amount += $order->order_amount; |
||||
$subscription->save(); |
||||
|
||||
$order->delivery_man_id = null; |
||||
$order->save(); |
||||
} |
||||
|
||||
// if(in_array($order->order_status, ['delivered', 'canceled', 'failed']) && ($order->canceled == null)) |
||||
// { |
||||
// // $order->order_status = 'pending'; |
||||
// $order->delivery_man_id = null; |
||||
// $order->save(); |
||||
// } |
||||
|
||||
|
||||
return ; |
||||
} |
||||
|
||||
public static function check_subscription(User $user):void |
||||
{ |
||||
$subscriptions = Subscription::where('user_id', $user->id)->expired()->get(); |
||||
try{ |
||||
DB::beginTransaction(); |
||||
foreach($subscriptions as $subscription){ |
||||
if($subscription->paid_amount > $subscription->billing_amount){ |
||||
$extra = $subscription->paid_amount - $subscription->billing_amount; |
||||
CustomerLogic::create_wallet_transaction($user->id, $extra, 'add_fund', "Subscription, Id:{$subscription->id}"); |
||||
} |
||||
$subscription->status = 'expired'; |
||||
$subscription->save(); |
||||
} |
||||
DB::commit(); |
||||
}catch(Exception $ex){ |
||||
DB::rollBack(); |
||||
info($ex->getMessage()); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,319 @@ |
||||
<?php |
||||
|
||||
namespace App\CentralLogics; |
||||
|
||||
use App\Models\Food; |
||||
use App\Models\Review; |
||||
use Illuminate\Support\Facades\DB; |
||||
|
||||
class ProductLogic |
||||
{ |
||||
public static function get_product($id) |
||||
{ |
||||
return Food::active()->when(is_numeric($id),function ($qurey) use($id){ |
||||
$qurey-> where('id', $id); |
||||
}) |
||||
->when(!is_numeric($id),function ($qurey) use($id){ |
||||
$qurey-> where('slug', $id); |
||||
}) |
||||
->first(); |
||||
} |
||||
|
||||
public static function get_latest_products($limit, $offset, $restaurant_id, $category_id, $type='all') |
||||
{ |
||||
$paginator = Food::active()->type($type); |
||||
if($category_id != 0) |
||||
{ |
||||
$paginator = $paginator->whereHas('category',function($q)use($category_id){ |
||||
return $q->whereId($category_id)->orWhere('parent_id', $category_id); |
||||
}); |
||||
} |
||||
$paginator = $paginator->where('restaurant_id', $restaurant_id)->latest()->paginate($limit, ['*'], 'page', $offset); |
||||
|
||||
return [ |
||||
'total_size' => $paginator->total(), |
||||
'limit' => $limit, |
||||
'offset' => $offset, |
||||
'products' => $paginator->items() |
||||
]; |
||||
} |
||||
|
||||
public static function get_related_products($product_id) |
||||
{ |
||||
$product = Food::find($product_id); |
||||
return Food::active() |
||||
->whereHas('restaurant', function($query){ |
||||
$query->Weekday(); |
||||
}) |
||||
->where('category_ids', $product->category_ids) |
||||
->where('id', '!=', $product->id) |
||||
->limit(10) |
||||
->get(); |
||||
} |
||||
|
||||
public static function search_products($name, $zone_id, $limit = 10, $offset = 1) |
||||
{ |
||||
$key = explode(' ', $name); |
||||
$paginator = Food::active()->whereHas('restaurant', function($q)use($zone_id){ |
||||
$q->whereIn('zone_id', $zone_id)->Weekday(); |
||||
})->where(function ($q) use ($key) { |
||||
foreach ($key as $value) { |
||||
$q->orWhere('name', 'like', "%{$value}%"); |
||||
} |
||||
})->paginate($limit, ['*'], 'page', $offset); |
||||
|
||||
return [ |
||||
'total_size' => $paginator->total(), |
||||
'limit' => $limit, |
||||
'offset' => $offset, |
||||
'products' => $paginator->items() |
||||
]; |
||||
} |
||||
|
||||
public static function popular_products($zone_id, $limit = null, $offset = null, $type='all') |
||||
{ |
||||
if($limit != null && $offset != null) |
||||
{ |
||||
$paginator = Food::whereHas('restaurant', function($q)use($zone_id){ |
||||
$q->whereIn('zone_id', $zone_id)->Weekday(); |
||||
})->active()->has('reviews')->type($type)->popular()->paginate($limit, ['*'], 'page', $offset); |
||||
|
||||
return [ |
||||
'total_size' => $paginator->total(), |
||||
'limit' => $limit, |
||||
'offset' => $offset, |
||||
'products' => $paginator->items() |
||||
]; |
||||
} |
||||
$paginator = Food::active()->type($type)->whereHas('restaurant', function($q)use($zone_id){ |
||||
$q->whereIn('zone_id', $zone_id)->Weekday(); |
||||
})->has('reviews')->popular()->limit(50)->get(); |
||||
|
||||
return [ |
||||
'total_size' => $paginator->count(), |
||||
'limit' => $limit, |
||||
'offset' => $offset, |
||||
'products' => $paginator |
||||
]; |
||||
|
||||
} |
||||
|
||||
public static function most_reviewed_products($zone_id, $limit = null, $offset = null, $type='all') |
||||
{ |
||||
if($limit != null && $offset != null) |
||||
{ |
||||
$paginator = Food::whereHas('restaurant', function($q)use($zone_id){ |
||||
$q->whereIn('zone_id', $zone_id)->Weekday(); |
||||
})->has('reviews')->withCount('reviews')->active()->type($type) |
||||
->orderBy('reviews_count','desc') |
||||
->paginate($limit, ['*'], 'page', $offset); |
||||
|
||||
return [ |
||||
'total_size' => $paginator->total(), |
||||
'limit' => $limit, |
||||
'offset' => $offset, |
||||
'products' => $paginator->items() |
||||
]; |
||||
} |
||||
$paginator = Food::active()->type($type)->whereHas('restaurant', function($q)use($zone_id){ |
||||
$q->whereIn('zone_id', $zone_id)->Weekday(); |
||||
}) |
||||
->has('reviews') |
||||
->withCount('reviews') |
||||
->orderBy('reviews_count','desc') |
||||
->limit(50)->get(); |
||||
|
||||
return [ |
||||
'total_size' => $paginator->count(), |
||||
'limit' => $limit, |
||||
'offset' => $offset, |
||||
'products' => $paginator |
||||
]; |
||||
|
||||
} |
||||
|
||||
public static function get_product_review($id) |
||||
{ |
||||
$reviews = Review::where('product_id', $id)->get(); |
||||
return $reviews; |
||||
} |
||||
|
||||
public static function get_rating($reviews) |
||||
{ |
||||
$rating5 = 0; |
||||
$rating4 = 0; |
||||
$rating3 = 0; |
||||
$rating2 = 0; |
||||
$rating1 = 0; |
||||
foreach ($reviews as $key => $review) { |
||||
if ($review->rating == 5) { |
||||
$rating5 += 1; |
||||
} |
||||
if ($review->rating == 4) { |
||||
$rating4 += 1; |
||||
} |
||||
if ($review->rating == 3) { |
||||
$rating3 += 1; |
||||
} |
||||
if ($review->rating == 2) { |
||||
$rating2 += 1; |
||||
} |
||||
if ($review->rating == 1) { |
||||
$rating1 += 1; |
||||
} |
||||
} |
||||
return [$rating5, $rating4, $rating3, $rating2, $rating1]; |
||||
} |
||||
|
||||
public static function get_avg_rating($rating) |
||||
{ |
||||
$total_rating = 0; |
||||
$total_rating += $rating[1]; |
||||
$total_rating += $rating[2]*2; |
||||
$total_rating += $rating[3]*3; |
||||
$total_rating += $rating[4]*4; |
||||
$total_rating += $rating[5]*5; |
||||
|
||||
return $total_rating/array_sum($rating); |
||||
} |
||||
|
||||
public static function get_overall_rating($reviews) |
||||
{ |
||||
$totalRating = count($reviews); |
||||
$rating = 0; |
||||
foreach ($reviews as $key => $review) { |
||||
$rating += $review->rating; |
||||
} |
||||
if ($totalRating == 0) { |
||||
$overallRating = 0; |
||||
} else { |
||||
$overallRating = number_format($rating / $totalRating, 2); |
||||
} |
||||
|
||||
return [$overallRating, $totalRating]; |
||||
} |
||||
|
||||
public static function format_export_foods($foods) |
||||
{ |
||||
$storage = []; |
||||
foreach($foods as $item) |
||||
{ |
||||
$category_id = 0; |
||||
$sub_category_id = 0; |
||||
foreach(json_decode($item->category_ids, true) as $category) |
||||
{ |
||||
if($category['position']==1) |
||||
{ |
||||
$category_id = $category['id']; |
||||
} |
||||
else if($category['position']==2) |
||||
{ |
||||
$sub_category_id = $category['id']; |
||||
} |
||||
} |
||||
$storage[] = [ |
||||
'id'=>$item->id, |
||||
'name'=>$item->name, |
||||
'description'=>$item->description, |
||||
'image'=>$item->image, |
||||
'veg'=>$item->veg, |
||||
'category_id'=>$category_id, |
||||
'sub_category_id'=>$sub_category_id, |
||||
'restaurant_id'=>$item->restaurant_id, |
||||
'price'=>$item->price, |
||||
'discount'=>$item->discount, |
||||
'discount_type'=>$item->discount_type, |
||||
'available_time_starts'=>$item->available_time_starts, |
||||
'available_time_ends'=>$item->available_time_ends, |
||||
'variations'=>str_replace(['{','}','[',']'],['(',')','',''],$item->variations), |
||||
'add_ons'=>str_replace(['"','[',']'],'',$item->add_ons), |
||||
// 'attributes'=>str_replace(['"','[',']'],'',$item->attributes), |
||||
// 'choice_options'=>str_replace(['{','}'],['(',')'],substr($item->choice_options, 1, -1)), |
||||
]; |
||||
} |
||||
|
||||
return $storage; |
||||
} |
||||
|
||||
public static function update_food_ratings() |
||||
{ |
||||
try{ |
||||
$foods = Food::withOutGlobalScopes()->whereHas('reviews')->with('reviews')->get(); |
||||
foreach($foods as $key=>$food) |
||||
{ |
||||
$foods[$key]->avg_rating = $food->reviews->avg('rating'); |
||||
$foods[$key]->rating_count = $food->reviews->count(); |
||||
foreach($food->reviews as $review) |
||||
{ |
||||
$foods[$key]->rating = self::update_rating($foods[$key]->rating, $review->rating); |
||||
} |
||||
$foods[$key]->save(); |
||||
} |
||||
}catch(\Exception $e){ |
||||
info($e->getMessage()); |
||||
return false; |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
public static function update_rating($ratings, $product_rating) |
||||
{ |
||||
|
||||
$restaurant_ratings = [1=>0 , 2=>0, 3=>0, 4=>0, 5=>0]; |
||||
if(isset($ratings)) |
||||
{ |
||||
$restaurant_ratings = json_decode($ratings, true); |
||||
$restaurant_ratings[$product_rating] = $restaurant_ratings[$product_rating] + 1; |
||||
} |
||||
else |
||||
{ |
||||
$restaurant_ratings[$product_rating] = 1; |
||||
} |
||||
return json_encode($restaurant_ratings); |
||||
} |
||||
|
||||
|
||||
|
||||
public static function recommended_products($zone_id,$restaurant_id,$limit = null, $offset = null, $type='all') |
||||
{ |
||||
$data =[]; |
||||
if($limit != null && $offset != null) |
||||
{ |
||||
$paginator = Food::where('restaurant_id', $restaurant_id)->whereHas('restaurant', function($q)use($zone_id){ |
||||
$q->whereIn('zone_id', $zone_id)->Weekday(); |
||||
})->active()->type($type)->Recommended()->paginate($limit, ['*'], 'page', $offset); |
||||
$data = $paginator->items(); |
||||
} |
||||
else{ |
||||
$paginator = Food::where('restaurant_id', $restaurant_id)->active()->type($type)->whereHas('restaurant', function($q)use($zone_id){ |
||||
$q->whereIn('zone_id', $zone_id)->Weekday(); |
||||
})->Recommended()->limit(50)->get(); |
||||
$data =$paginator; |
||||
} |
||||
|
||||
return [ |
||||
'total_size' => $paginator->count(), |
||||
'limit' => $limit, |
||||
'offset' => $offset, |
||||
'products' => $data |
||||
]; |
||||
} |
||||
|
||||
|
||||
public static function format_export_addons($addons) |
||||
{ |
||||
$storage = []; |
||||
foreach($addons as $item) |
||||
{ |
||||
$storage[] = [ |
||||
'id'=>$item->id, |
||||
'name'=>$item->name, |
||||
'price'=>$item->price, |
||||
'restaurant_id'=>$item->restaurant_id, |
||||
]; |
||||
} |
||||
|
||||
return $storage; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,297 @@ |
||||
<?php |
||||
|
||||
namespace App\CentralLogics; |
||||
|
||||
use App\Models\Restaurant; |
||||
use App\Models\OrderTransaction; |
||||
|
||||
class RestaurantLogic |
||||
{ |
||||
public static function get_restaurants($zone_id, $filter, $limit = 10, $offset = 1, $type='all',$name= null,$longitude=0,$latitude=0,$cuisine='all') |
||||
{ |
||||
$paginator = Restaurant:: |
||||
withOpen($longitude,$latitude) |
||||
->with(['discount'=>function($q){ |
||||
return $q->validate(); |
||||
}])->whereIn('zone_id', $zone_id) |
||||
->when($filter=='delivery', function($q){ |
||||
return $q->delivery(); |
||||
}) |
||||
->when($filter=='take_away', function($q){ |
||||
return $q->takeaway(); |
||||
}) |
||||
->when($name, function($q)use($name){ |
||||
$key = explode(' ', $name); |
||||
$q->where(function($q)use($key){ |
||||
foreach ($key as $value){ |
||||
$q->orWhere('name', 'like', '%'.$value.'%'); |
||||
} |
||||
return $q; |
||||
}); |
||||
}) |
||||
->Active() |
||||
->type($type) |
||||
->cuisine($cuisine) |
||||
->orderBy('open', 'desc') |
||||
->orderBy('distance') |
||||
->paginate($limit, ['*'], 'page', $offset); |
||||
/*$paginator->count();*/ |
||||
return [ |
||||
'total_size' => $paginator->total(), |
||||
'limit' => $limit, |
||||
'offset' => $offset, |
||||
'restaurants' => $paginator->items() |
||||
]; |
||||
} |
||||
|
||||
public static function get_latest_restaurants($zone_id, $limit = 10, $offset = 1, $type='all',$longitude=0,$latitude=0) |
||||
{ |
||||
$paginator = Restaurant::withOpen($longitude,$latitude) |
||||
->with(['discount'=>function($q){ |
||||
return $q->validate(); |
||||
}])->whereIn('zone_id', $zone_id) |
||||
->Active() |
||||
->type($type) |
||||
->latest() |
||||
->limit(50) |
||||
->get(); |
||||
// ->paginate($limit, ['*'], 'page', $offset); |
||||
/*$paginator->count();*/ |
||||
return [ |
||||
'total_size' => $paginator->count(), |
||||
'limit' => $limit, |
||||
'offset' => $offset, |
||||
'restaurants' => $paginator |
||||
]; |
||||
} |
||||
|
||||
public static function get_popular_restaurants($zone_id, $limit = 10, $offset = 1, $type='all',$longitude=0,$latitude=0) |
||||
{ |
||||
$paginator = Restaurant::withOpen($longitude,$latitude) |
||||
->with(['discount'=>function($q){ |
||||
return $q->validate(); |
||||
}])->whereIn('zone_id', $zone_id) |
||||
->Active() |
||||
->type($type) |
||||
->withCount('orders') |
||||
->orderBy('open', 'desc') |
||||
->orderBy('orders_count', 'desc') |
||||
->limit(50) |
||||
->get(); |
||||
// ->paginate($limit, ['*'], 'page', $offset); |
||||
/*$paginator->count();*/ |
||||
return [ |
||||
'total_size' => $paginator->count(), |
||||
'limit' => $limit, |
||||
'offset' => $offset, |
||||
'restaurants' => $paginator |
||||
]; |
||||
} |
||||
|
||||
public static function get_restaurant_details($restaurant_id) |
||||
{ |
||||
return Restaurant::with(['discount'=>function($q){ |
||||
return $q->validate(); |
||||
}, 'campaigns', 'schedules','restaurant_sub'])->active() |
||||
->when(is_numeric($restaurant_id),function ($qurey) use($restaurant_id){ |
||||
$qurey-> where('id', $restaurant_id); |
||||
}) |
||||
->when(!is_numeric($restaurant_id),function ($qurey) use($restaurant_id){ |
||||
$qurey-> where('slug', $restaurant_id); |
||||
}) |
||||
->first(); |
||||
} |
||||
|
||||
public static function calculate_restaurant_rating($ratings) |
||||
{ |
||||
$total_submit = $ratings[0]+$ratings[1]+$ratings[2]+$ratings[3]+$ratings[4]; |
||||
$rating = ($ratings[0]*5+$ratings[1]*4+$ratings[2]*3+$ratings[3]*2+$ratings[4])/($total_submit?$total_submit:1); |
||||
return ['rating'=>$rating, 'total'=>$total_submit]; |
||||
} |
||||
|
||||
public static function update_restaurant_rating($ratings, $product_rating) |
||||
{ |
||||
$restaurant_ratings = [1=>0 , 2=>0, 3=>0, 4=>0, 5=>0]; |
||||
if($ratings) |
||||
{ |
||||
$restaurant_ratings[1] = $ratings[4]; |
||||
$restaurant_ratings[2] = $ratings[3]; |
||||
$restaurant_ratings[3] = $ratings[2]; |
||||
$restaurant_ratings[4] = $ratings[1]; |
||||
$restaurant_ratings[5] = $ratings[0]; |
||||
$restaurant_ratings[$product_rating] = $ratings[5-$product_rating] + 1; |
||||
} |
||||
else |
||||
{ |
||||
$restaurant_ratings[$product_rating] = 1; |
||||
} |
||||
return json_encode($restaurant_ratings); |
||||
} |
||||
|
||||
public static function search_restaurants($name, $zone_id, $category_id= null,$limit = 10, $offset = 1, $type='all',$longitude=0,$latitude=0) |
||||
{ |
||||
$key = explode(' ', $name); |
||||
$paginator = Restaurant::withOpen($longitude,$latitude)->with(['discount'=>function($q){ |
||||
return $q->validate(); |
||||
}])->whereIn('zone_id', $zone_id)->weekday()->where(function ($q) use ($key) { |
||||
foreach ($key as $value) { |
||||
$q->orWhere('name', 'like', "%{$value}%"); |
||||
} |
||||
}) |
||||
->when($category_id, function($query)use($category_id){ |
||||
$query->whereHas('foods.category', function($q)use($category_id){ |
||||
return $q->whereId($category_id)->orWhere('parent_id', $category_id); |
||||
}); |
||||
}) |
||||
->active()->type($type) |
||||
->orderBy('open', 'desc') |
||||
->orderBy('distance') |
||||
->paginate($limit, ['*'], 'page', $offset); |
||||
|
||||
return [ |
||||
'total_size' => $paginator->total(), |
||||
'limit' => $limit, |
||||
'offset' => $offset, |
||||
'restaurants' => $paginator->items() |
||||
]; |
||||
} |
||||
|
||||
public static function get_overall_rating($reviews) |
||||
{ |
||||
$totalRating = count($reviews); |
||||
$rating = 0; |
||||
foreach ($reviews as $key => $review) { |
||||
$rating += $review->rating; |
||||
} |
||||
if ($totalRating == 0) { |
||||
$overallRating = 0; |
||||
} else { |
||||
$overallRating = number_format($rating / $totalRating, 2); |
||||
} |
||||
|
||||
return [$overallRating, $totalRating]; |
||||
} |
||||
|
||||
public static function get_earning_data($vendor_id) |
||||
{ |
||||
$monthly_earning = OrderTransaction::whereMonth('created_at', date('m'))->NotRefunded()->where('vendor_id', $vendor_id)->sum('restaurant_amount'); |
||||
$weekly_earning = OrderTransaction::whereBetween('created_at', [now()->startOfWeek(), now()->endOfWeek()])->NotRefunded()->where('vendor_id', $vendor_id)->sum('restaurant_amount'); |
||||
$daily_earning = OrderTransaction::whereDate('created_at', now())->NotRefunded()->where('vendor_id', $vendor_id)->sum('restaurant_amount'); |
||||
|
||||
return['monthely_earning'=>(float)$monthly_earning, 'weekly_earning'=>(float)$weekly_earning, 'daily_earning'=>(float)$daily_earning]; |
||||
} |
||||
|
||||
public static function format_export_restaurants($restaurants) |
||||
{ |
||||
$storage = []; |
||||
foreach($restaurants as $item) |
||||
{ |
||||
$storage[] = [ |
||||
'id'=>$item->id, |
||||
'ownerFirstName'=>$item->f_name, |
||||
'ownerLastName'=>$item->l_name, |
||||
'restaurantName'=>$item->restaurants[0]->name, |
||||
'logo'=>$item->restaurants[0]->logo, |
||||
'phone'=>$item->phone, |
||||
'email'=>$item->email, |
||||
'latitude'=>$item->restaurants[0]->latitude, |
||||
'longitude'=>$item->restaurants[0]->longitude, |
||||
'zone_id'=>$item->restaurants[0]->zone_id, |
||||
'Address'=>$item->restaurants[0]->address ?? null, |
||||
// 'FooterText'=>$item->restaurants[0]->footer_text ?? null, |
||||
'MinimumOrderAmount'=>$item->restaurants[0]->minimum_order, |
||||
'Comission'=>$item->restaurants[0]->comission ?? 0, |
||||
'Tax'=>$item->restaurants[0]->tax ?? 0, |
||||
|
||||
'DeliveryTime'=>$item->restaurants[0]->delivery_time ?? '20-30', |
||||
'MinimumDeliveryFee'=>$item->restaurants[0]->minimum_shipping_charge ?? 0, |
||||
'PerKmDeliveryFee'=>$item->restaurants[0]->per_km_shipping_charge ?? 0, |
||||
'MaximumDeliveryFee'=>$item->restaurants[0]->maximum_shipping_charge ?? 0, |
||||
// 'order_count'=>$item->restaurants[0]->order_count, |
||||
// 'total_order'=>$item->restaurants[0]->total_order, |
||||
'RestaurantModel'=>$item->restaurants[0]->restaurant_model, |
||||
'ScheduleOrder'=> $item->restaurants[0]->schedule_order == 1 ? 'yes' : 'no', |
||||
'FreeDelivery'=> $item->restaurants[0]->free_delivery == 1 ? 'yes' : 'no', |
||||
'TakeAway'=> $item->restaurants[0]->take_away == 1 ? 'yes' : 'no', |
||||
'Delivery'=> $item->restaurants[0]->delivery == 1 ? 'yes' : 'no', |
||||
'Veg'=> $item->restaurants[0]->veg == 1 ? 'yes' : 'no', |
||||
'NonVeg'=> $item->restaurants[0]->non_veg == 1 ? 'yes' : 'no', |
||||
'Status'=> $item->restaurants[0]->status == 1 ? 'active' : 'inactive', |
||||
'FoodSection'=> $item->restaurants[0]->food_section == 1 ? 'active' : 'inactive', |
||||
'ReviewsSection'=> $item->restaurants[0]->reviews_section == 1 ? 'active' : 'inactive', |
||||
'SelfDeliverySystem'=> $item->restaurants[0]->self_delivery_system == 1 ? 'active' : 'inactive', |
||||
'PosSystem'=> $item->restaurants[0]->pos_system == 1 ? 'active' : 'inactive', |
||||
'RestaurantOpen'=> $item->restaurants[0]->active == 1 ? 'yes' : 'no', |
||||
// 'opening_time'=>$item->restaurants[0]->opening_time, |
||||
// 'off_day'=>$item->restaurants[0]->off_day, |
||||
// 'gst'=>$item->restaurants[0]->gst, |
||||
// 'closing_time'=>$item->restaurants[0]->closeing_time, |
||||
]; |
||||
} |
||||
|
||||
return $storage; |
||||
} |
||||
public static function format_restaurant_report_export_data($restaurants) |
||||
{ |
||||
$storage = []; |
||||
foreach($restaurants as $key => $restaurant) |
||||
{ |
||||
if($restaurant->count()<1) |
||||
{ |
||||
break; |
||||
} |
||||
if ($restaurant->reviews_count){ |
||||
$reviews_count = $restaurant->reviews_count; |
||||
} |
||||
else{ |
||||
$reviews_count = 1; |
||||
} |
||||
|
||||
$restaurant_rating = round($restaurant->reviews_sum_rating /$reviews_count,1); |
||||
$storage[] = [ |
||||
'#'=>$key+1, |
||||
translate('messages.restaurant') =>$restaurant->name, |
||||
translate('messages.total_food') =>$restaurant->foods_count ?? 0, |
||||
translate('messages.total_order') =>$restaurant->without_refund_total_orders_count ?? 0, |
||||
translate('messages.total_order').translate('messages.amount') =>$restaurant->transaction_sum_order_amount ?? 0, |
||||
translate('messages.total_discount_given') =>$restaurant->transaction_sum_restaurant_expense ?? 0, |
||||
translate('messages.total_admin_commission') =>$restaurant->transaction_sum_admin_commission ?? 0, |
||||
translate('messages.total_vat_tax') =>$restaurant->transaction_sum_tax ?? 0, |
||||
translate('messages.average_ratings') =>$restaurant_rating, |
||||
]; |
||||
} |
||||
|
||||
return $storage; |
||||
} |
||||
|
||||
public static function recently_viewed_restaurants_data($zone_id, $limit = 10, $offset = 1, $type='all',$longitude=0,$latitude=0) |
||||
{ |
||||
$user_id = null; |
||||
if(auth('api')->user() !== null){ |
||||
$user_id =auth('api')->user()->id; |
||||
} |
||||
|
||||
$paginator = Restaurant::whereHas('users',function ($query) use($user_id){ |
||||
$query->where('user_id',$user_id); |
||||
}) |
||||
->withOpen($longitude,$latitude) |
||||
->with(['discount'=>function($q){ |
||||
return $q->validate(); |
||||
}])->whereIn('zone_id', $zone_id) |
||||
->Active() |
||||
->type($type) |
||||
->withCount('orders') |
||||
->orderBy('orders_count', 'desc') |
||||
->orderBy('open', 'desc') |
||||
->limit(50) |
||||
->get(); |
||||
// ->paginate($limit, ['*'], 'page', $offset); |
||||
/*$paginator->count();*/ |
||||
return [ |
||||
'total_size' => $paginator->count(), |
||||
'limit' => $limit, |
||||
'offset' => $offset, |
||||
'restaurants' => $paginator |
||||
]; |
||||
} |
||||
} |
@ -0,0 +1,219 @@ |
||||
<?php |
||||
|
||||
namespace App\CentralLogics; |
||||
|
||||
use App\Models\BusinessSetting; |
||||
use Illuminate\Support\Facades\Config; |
||||
use Illuminate\Support\Facades\DB; |
||||
use Nexmo\Laravel\Facade\Nexmo; |
||||
use Twilio\Rest\Client; |
||||
|
||||
class SMS_module |
||||
{ |
||||
public static function send($receiver, $otp) |
||||
{ |
||||
$config = self::get_settings('twilio_sms'); |
||||
if (isset($config) && $config['status'] == 1) { |
||||
$response = self::twilio($receiver, $otp); |
||||
return $response; |
||||
} |
||||
|
||||
$config = self::get_settings('nexmo_sms'); |
||||
if (isset($config) && $config['status'] == 1) { |
||||
$response = self::nexmo($receiver, $otp); |
||||
return $response; |
||||
} |
||||
|
||||
$config = self::get_settings('2factor_sms'); |
||||
if (isset($config) && $config['status'] == 1) { |
||||
$response = self::two_factor($receiver, $otp); |
||||
return $response; |
||||
} |
||||
|
||||
$config = self::get_settings('msg91_sms'); |
||||
if (isset($config) && $config['status'] == 1) { |
||||
$response = self::msg_91($receiver, $otp); |
||||
return $response; |
||||
} |
||||
|
||||
return 'not_found'; |
||||
} |
||||
|
||||
public static function twilio($receiver, $otp) |
||||
{ |
||||
$config = self::get_settings('twilio_sms'); |
||||
$response = 'error'; |
||||
|
||||
if (isset($config) && $config['status'] == 1) { |
||||
$message = str_replace("#OTP#", $otp, $config['otp_template']); |
||||
$sid = $config['sid']; |
||||
$token = $config['token']; |
||||
try { |
||||
$twilio = new Client($sid, $token); |
||||
$twilio->messages |
||||
->create($receiver, // to |
||||
array( |
||||
"messagingServiceSid" => $config['messaging_service_id'], |
||||
"body" => $message |
||||
) |
||||
); |
||||
$response = 'success'; |
||||
} catch (\Exception $exception) { |
||||
$response = 'error'; |
||||
} |
||||
} elseif (empty($config)) { |
||||
DB::table('business_settings')->updateOrInsert(['key' => 'twilio_sms'], [ |
||||
'key' => 'twilio_sms', |
||||
'value' => json_encode([ |
||||
'status' => 0, |
||||
'sid' => '', |
||||
'token' => '', |
||||
'from' => '', |
||||
]), |
||||
'created_at' => now(), |
||||
'updated_at' => now(), |
||||
]); |
||||
} |
||||
return $response; |
||||
} |
||||
|
||||
public static function nexmo($receiver, $otp) |
||||
{ |
||||
$sms_nexmo = self::get_settings('nexmo_sms'); |
||||
$response = 'error'; |
||||
if (isset($sms_nexmo) && $sms_nexmo['status'] == 1) { |
||||
$message = str_replace("#OTP#", $otp, $sms_nexmo['otp_template']); |
||||
try { |
||||
$config = [ |
||||
'api_key' => $sms_nexmo['api_key'], |
||||
'api_secret' => $sms_nexmo['api_secret'], |
||||
'signature_secret' => '', |
||||
'private_key' => '', |
||||
'application_id' => '', |
||||
'app' => ['name' => '', 'version' => ''], |
||||
'http_client' => '' |
||||
]; |
||||
Config::set('nexmo', $config); |
||||
Nexmo::message()->send([ |
||||
'to' => $receiver, |
||||
'from' => $sms_nexmo['from'], |
||||
'text' => $message |
||||
]); |
||||
$response = 'success'; |
||||
} catch (\Exception $exception) { |
||||
$response = 'error'; |
||||
} |
||||
} elseif (empty($config)) { |
||||
DB::table('business_settings')->updateOrInsert(['key' => 'nexmo_sms'], [ |
||||
'key' => 'nexmo_sms', |
||||
'value' => json_encode([ |
||||
'status' => 0, |
||||
'api_key' => '', |
||||
'api_secret' => '', |
||||
'signature_secret' => '', |
||||
'private_key' => '', |
||||
'application_id' => '', |
||||
'from' => '', |
||||
]), |
||||
'created_at' => now(), |
||||
'updated_at' => now(), |
||||
]); |
||||
} |
||||
return $response; |
||||
} |
||||
|
||||
public static function two_factor($receiver, $otp) |
||||
{ |
||||
$config = self::get_settings('2factor_sms'); |
||||
$response = 'error'; |
||||
if (isset($config) && $config['status'] == 1) { |
||||
$api_key = $config['api_key']; |
||||
$curl = curl_init(); |
||||
curl_setopt_array($curl, array( |
||||
CURLOPT_URL => "https://2factor.in/API/V1/" . $api_key . "/SMS/" . $receiver . "/" . $otp . "", |
||||
CURLOPT_RETURNTRANSFER => true, |
||||
CURLOPT_ENCODING => "", |
||||
CURLOPT_MAXREDIRS => 10, |
||||
CURLOPT_TIMEOUT => 30, |
||||
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
||||
CURLOPT_CUSTOMREQUEST => "GET", |
||||
)); |
||||
$response = curl_exec($curl); |
||||
$err = curl_error($curl); |
||||
curl_close($curl); |
||||
|
||||
if (!$err) { |
||||
$response = 'success'; |
||||
} else { |
||||
$response = 'error'; |
||||
} |
||||
} elseif (empty($config)) { |
||||
DB::table('business_settings')->updateOrInsert(['key' => '2factor_sms'], [ |
||||
'key' => '2factor_sms', |
||||
'value' => json_encode([ |
||||
'status' => 0, |
||||
'api_key' => 'aabf4e9c-f55f-11eb-85d5-0200cd936042', |
||||
]), |
||||
'created_at' => now(), |
||||
'updated_at' => now(), |
||||
]); |
||||
} |
||||
return $response; |
||||
} |
||||
|
||||
public static function msg_91($receiver, $otp) |
||||
{ |
||||
$config = self::get_settings('msg91_sms'); |
||||
$response = 'error'; |
||||
if (isset($config) && $config['status'] == 1) { |
||||
$receiver = str_replace("+", "", $receiver); |
||||
$curl = curl_init(); |
||||
curl_setopt_array($curl, array( |
||||
CURLOPT_URL => "https://api.msg91.com/api/v5/otp?template_id=" . $config['template_id'] . "&mobile=" . $receiver . "&authkey=" . $config['authkey'] . "", |
||||
CURLOPT_RETURNTRANSFER => true, |
||||
CURLOPT_ENCODING => "", |
||||
CURLOPT_MAXREDIRS => 10, |
||||
CURLOPT_TIMEOUT => 30, |
||||
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
||||
CURLOPT_CUSTOMREQUEST => "GET", |
||||
CURLOPT_POSTFIELDS => "{\"OTP\":\"$otp\"}", |
||||
CURLOPT_HTTPHEADER => array( |
||||
"content-type: application/json" |
||||
), |
||||
)); |
||||
$response = curl_exec($curl); |
||||
$err = curl_error($curl); |
||||
curl_close($curl); |
||||
if (!$err) { |
||||
$response = 'success'; |
||||
} else { |
||||
$response = 'error'; |
||||
} |
||||
} elseif (empty($config)) { |
||||
DB::table('business_settings')->updateOrInsert(['key' => 'msg91_sms'], [ |
||||
'key' => 'msg91_sms', |
||||
'value' => json_encode([ |
||||
'status' => 0, |
||||
'template_id' => '', |
||||
'authkey' => '', |
||||
]), |
||||
'created_at' => now(), |
||||
'updated_at' => now(), |
||||
]); |
||||
} |
||||
return $response; |
||||
} |
||||
|
||||
public static function get_settings($name) |
||||
{ |
||||
$config = null; |
||||
$data = BusinessSetting::where(['key' => $name])->first(); |
||||
if (isset($data)) { |
||||
$config = json_decode($data['value'], true); |
||||
if (is_null($config)) { |
||||
$config = $data['value']; |
||||
} |
||||
} |
||||
return $config; |
||||
} |
||||
} |
@ -0,0 +1,50 @@ |
||||
<?php |
||||
|
||||
namespace App\Console\Commands; |
||||
|
||||
use Illuminate\Console\Command; |
||||
use Illuminate\Support\Facades\Artisan; |
||||
use Illuminate\Support\Facades\DB; |
||||
use Illuminate\Support\Facades\File; |
||||
use Madnest\Madzipper\Facades\Madzipper; |
||||
|
||||
class DatabaseRefresh extends Command |
||||
{ |
||||
/** |
||||
* The name and signature of the console command. |
||||
* |
||||
* @var string |
||||
*/ |
||||
protected $signature = 'database:refresh'; |
||||
|
||||
/** |
||||
* The console command description. |
||||
* |
||||
* @var string |
||||
*/ |
||||
protected $description = 'Refresh database after a certain time'; |
||||
|
||||
/** |
||||
* Create a new command instance. |
||||
* |
||||
* @return void |
||||
*/ |
||||
public function __construct() |
||||
{ |
||||
parent::__construct(); |
||||
} |
||||
|
||||
/** |
||||
* Execute the console command. |
||||
* |
||||
* @return int |
||||
*/ |
||||
public function handle() |
||||
{ |
||||
Artisan::call('db:wipe'); |
||||
$sql_path = base_path('installation/database.sql'); |
||||
DB::unprepared(file_get_contents($sql_path)); |
||||
File::deleteDirectory('storage/app/public'); |
||||
Madzipper::make('installation/public.zip')->extractTo('storage/app'); |
||||
} |
||||
} |
@ -0,0 +1,58 @@ |
||||
<?php |
||||
|
||||
namespace App\Console\Commands; |
||||
|
||||
use App\CentralLogics\Helpers; |
||||
use Illuminate\Console\Command; |
||||
use Illuminate\Support\Facades\Artisan; |
||||
use Illuminate\Support\Facades\Storage; |
||||
use Madnest\Madzipper\Facades\Madzipper; |
||||
|
||||
class InstallablePackage extends Command |
||||
{ |
||||
/** |
||||
* The name and signature of the console command. |
||||
* |
||||
* @var string |
||||
*/ |
||||
protected $signature = 'prepare:installable'; |
||||
|
||||
/** |
||||
* The console command description. |
||||
* |
||||
* @var string |
||||
*/ |
||||
protected $description = 'Create an installable package.'; |
||||
|
||||
/** |
||||
* Create a new command instance. |
||||
* |
||||
* @return void |
||||
*/ |
||||
public function __construct() |
||||
{ |
||||
parent::__construct(); |
||||
} |
||||
|
||||
/** |
||||
* Execute the console command. |
||||
* |
||||
* @return int |
||||
*/ |
||||
public function handle() |
||||
{ |
||||
/*Helpers::remove_dir('.idea');*/ |
||||
Artisan::call('debugbar:clear'); |
||||
Helpers::remove_dir('storage/app/public'); |
||||
Storage::disk('public')->makeDirectory('/'); |
||||
Madzipper::make('installation/backup/public.zip')->extractTo('storage/app'); |
||||
|
||||
$dot_env = base_path('.env'); |
||||
$new_env = base_path('.env.example'); |
||||
copy($new_env, $dot_env); |
||||
|
||||
$routes = base_path('app/Providers/RouteServiceProvider.php'); |
||||
$new_routes = base_path('installation/activate_install_routes.txt'); |
||||
copy($new_routes, $routes); |
||||
} |
||||
} |
@ -0,0 +1,47 @@ |
||||
<?php |
||||
|
||||
namespace App\Console\Commands; |
||||
|
||||
use Illuminate\Console\Command; |
||||
use Illuminate\Support\Facades\Artisan; |
||||
|
||||
class UpdatablePackage extends Command |
||||
{ |
||||
/** |
||||
* The name and signature of the console command. |
||||
* |
||||
* @var string |
||||
*/ |
||||
protected $signature = 'prepare:updatable'; |
||||
|
||||
/** |
||||
* The console command description. |
||||
* |
||||
* @var string |
||||
*/ |
||||
protected $description = 'Command description'; |
||||
|
||||
/** |
||||
* Create a new command instance. |
||||
* |
||||
* @return void |
||||
*/ |
||||
public function __construct() |
||||
{ |
||||
parent::__construct(); |
||||
} |
||||
|
||||
/** |
||||
* Execute the console command. |
||||
* |
||||
* @return int |
||||
*/ |
||||
public function handle() |
||||
{ |
||||
Artisan::call('debugbar:clear'); |
||||
$routes = base_path('app/Providers/RouteServiceProvider.php'); |
||||
$new_routes = base_path('installation/activate_update_routes.txt'); |
||||
copy($new_routes, $routes); |
||||
return 0; |
||||
} |
||||
} |
@ -0,0 +1,41 @@ |
||||
<?php |
||||
|
||||
namespace App\Console; |
||||
|
||||
use Illuminate\Console\Scheduling\Schedule; |
||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel; |
||||
|
||||
class Kernel extends ConsoleKernel |
||||
{ |
||||
/** |
||||
* The Artisan commands provided by your application. |
||||
* |
||||
* @var array |
||||
*/ |
||||
protected $commands = [ |
||||
// |
||||
]; |
||||
|
||||
/** |
||||
* Define the application's command schedule. |
||||
* |
||||
* @param \Illuminate\Console\Scheduling\Schedule $schedule |
||||
* @return void |
||||
*/ |
||||
protected function schedule(Schedule $schedule) |
||||
{ |
||||
// $schedule->command('inspire')->hourly(); |
||||
} |
||||
|
||||
/** |
||||
* Register the commands for the application. |
||||
* |
||||
* @return void |
||||
*/ |
||||
protected function commands() |
||||
{ |
||||
$this->load(__DIR__.'/Commands'); |
||||
|
||||
require base_path('routes/console.php'); |
||||
} |
||||
} |
@ -0,0 +1,41 @@ |
||||
<?php |
||||
|
||||
namespace App\Exceptions; |
||||
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; |
||||
use Throwable; |
||||
|
||||
class Handler extends ExceptionHandler |
||||
{ |
||||
/** |
||||
* A list of the exception types that are not reported. |
||||
* |
||||
* @var array |
||||
*/ |
||||
protected $dontReport = [ |
||||
// |
||||
]; |
||||
|
||||
/** |
||||
* A list of the inputs that are never flashed for validation exceptions. |
||||
* |
||||
* @var array |
||||
*/ |
||||
protected $dontFlash = [ |
||||
'current_password', |
||||
'password', |
||||
'password_confirmation', |
||||
]; |
||||
|
||||
/** |
||||
* Register the exception handling callbacks for the application. |
||||
* |
||||
* @return void |
||||
*/ |
||||
public function register() |
||||
{ |
||||
$this->reportable(function (Throwable $e) { |
||||
// |
||||
}); |
||||
} |
||||
} |
Binary file not shown.
@ -0,0 +1,180 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Admin; |
||||
|
||||
use App\Http\Controllers\Controller; |
||||
use Illuminate\Http\Request; |
||||
use App\Models\AccountTransaction; |
||||
use App\Models\Restaurant; |
||||
use App\Models\DeliveryMan; |
||||
use App\Models\AdminWallet; |
||||
use App\Models\Admin; |
||||
use Illuminate\Support\Facades\Validator; |
||||
use App\CentralLogics\Helpers; |
||||
use Brian2694\Toastr\Facades\Toastr; |
||||
use Illuminate\Support\Facades\DB; |
||||
use Rap2hpoutre\FastExcel\FastExcel; |
||||
|
||||
class AccountTransactionController extends Controller |
||||
{ |
||||
/** |
||||
* Display a listing of the resource. |
||||
* |
||||
* @return \Illuminate\Http\Response |
||||
*/ |
||||
public function index() |
||||
{ |
||||
$account_transaction = AccountTransaction::latest()->paginate(config('default_pagination')); |
||||
return view('admin-views.account.index', compact('account_transaction')); |
||||
} |
||||
|
||||
/** |
||||
* Show the form for creating a new resource. |
||||
* |
||||
* @return \Illuminate\Http\Response |
||||
*/ |
||||
public function create() |
||||
{ |
||||
// |
||||
} |
||||
|
||||
/** |
||||
* Store a newly created resource in storage. |
||||
* |
||||
* @param \Illuminate\Http\Request $request |
||||
* @return \Illuminate\Http\Response |
||||
*/ |
||||
public function store(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'type' => 'required|in:restaurant,deliveryman', |
||||
'method' => 'required', |
||||
'restaurant_id' => 'required_if:type,restaurant', |
||||
'deliveryman_id' => 'required_if:type,deliveryman', |
||||
'amount' => 'required|numeric', |
||||
]); |
||||
|
||||
if ($request['restaurant_id'] && $request['deliveryman_id']) { |
||||
$validator->getMessageBag()->add('from type', 'Can not select both deliveryman and restaurant'); |
||||
return response()->json(['errors' => Helpers::error_processor($validator)]); |
||||
} |
||||
|
||||
|
||||
if($request['type']=='restaurant' && $request['restaurant_id']) |
||||
{ |
||||
$restaurant = Restaurant::findOrFail($request['restaurant_id']); |
||||
$data = $restaurant->vendor; |
||||
$current_balance = $data->wallet?$data->wallet->collected_cash:0; |
||||
} |
||||
else if($request['type']=='deliveryman' && $request['deliveryman_id']) |
||||
{ |
||||
$data = DeliveryMan::findOrFail($request['deliveryman_id']); |
||||
|
||||
$current_balance = $data->wallet?$data->wallet->collected_cash:0; |
||||
} |
||||
|
||||
if ($current_balance < $request['amount']) { |
||||
$validator->getMessageBag()->add('amount', translate('messages.insufficient_balance')); |
||||
return response()->json(['errors' => Helpers::error_processor($validator)]); |
||||
} |
||||
|
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)]); |
||||
} |
||||
|
||||
$account_transaction = new AccountTransaction(); |
||||
$account_transaction->from_type = $request['type']; |
||||
$account_transaction->from_id = $data->id; |
||||
$account_transaction->method = $request['method']; |
||||
$account_transaction->ref = $request['ref']; |
||||
$account_transaction->amount = $request['amount']; |
||||
$account_transaction->current_balance = $current_balance; |
||||
|
||||
try |
||||
{ |
||||
DB::beginTransaction(); |
||||
$account_transaction->save(); |
||||
$data->wallet->decrement('collected_cash', $request['amount']); |
||||
AdminWallet::where('admin_id', Admin::where('role_id', 1)->first()->id)->increment('manual_received', $request['amount']); |
||||
DB::commit(); |
||||
} |
||||
catch(\Exception $e) |
||||
{ |
||||
DB::rollBack(); |
||||
return $e; |
||||
} |
||||
|
||||
return response()->json(200); |
||||
} |
||||
|
||||
/** |
||||
* Display the specified resource. |
||||
* |
||||
* @param int $id |
||||
* @return \Illuminate\Http\Response |
||||
*/ |
||||
public function show($id) |
||||
{ |
||||
$account_transaction=AccountTransaction::findOrFail($id); |
||||
return view('admin-views.account.view', compact('account_transaction')); |
||||
} |
||||
|
||||
/** |
||||
* Show the form for editing the specified resource. |
||||
* |
||||
* @param int $id |
||||
* @return \Illuminate\Http\Response |
||||
*/ |
||||
public function edit($id) |
||||
{ |
||||
// |
||||
} |
||||
|
||||
/** |
||||
* Update the specified resource in storage. |
||||
* |
||||
* @param \Illuminate\Http\Request $request |
||||
* @param int $id |
||||
* @return \Illuminate\Http\Response |
||||
*/ |
||||
public function update(Request $request, $id) |
||||
{ |
||||
// |
||||
} |
||||
|
||||
/** |
||||
* Remove the specified resource from storage. |
||||
* |
||||
* @param int $id |
||||
* @return \Illuminate\Http\Response |
||||
*/ |
||||
public function destroy($id) |
||||
{ |
||||
AccountTransaction::where('id', $id)->delete(); |
||||
Toastr::success(translate('messages.account_transaction_removed')); |
||||
return back(); |
||||
} |
||||
|
||||
public function export_account_transaction(Request $request){ |
||||
$account_transaction = AccountTransaction::latest()->get(); |
||||
if($request->type == 'excel'){ |
||||
return (new FastExcel(Helpers::export_account_transaction($account_transaction)))->download('Account_transactions.xlsx'); |
||||
}elseif($request->type == 'csv'){ |
||||
return (new FastExcel(Helpers::export_account_transaction($account_transaction)))->download('Account_transactions.csv'); |
||||
} |
||||
} |
||||
|
||||
public function search_account_transaction(Request $request){ |
||||
$key = explode(' ', $request['search']); |
||||
$account_transaction = AccountTransaction::where(function ($q) use ($key) { |
||||
foreach ($key as $value) { |
||||
$q->orWhere('ref', 'like', "%{$value}%"); |
||||
} |
||||
})->get(); |
||||
|
||||
return response()->json([ |
||||
'view'=>view('admin-views.account.partials._table', compact('account_transaction'))->render(), |
||||
'total'=>$account_transaction->count() |
||||
]); |
||||
} |
||||
} |
@ -0,0 +1,195 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Admin; |
||||
|
||||
use App\Http\Controllers\Controller; |
||||
use App\Models\AddOn; |
||||
use App\Models\Restaurant; |
||||
use App\Models\Translation; |
||||
use Brian2694\Toastr\Facades\Toastr; |
||||
use Illuminate\Http\Request; |
||||
use Rap2hpoutre\FastExcel\FastExcel; |
||||
use Illuminate\Support\Facades\DB; |
||||
use App\Scopes\RestaurantScope; |
||||
use App\CentralLogics\ProductLogic; |
||||
class AddOnController extends Controller |
||||
{ |
||||
public function index(Request $request) |
||||
{ |
||||
$restaurant_id = $request->query('restaurant_id', 'all'); |
||||
$addons = AddOn::withoutGlobalScope(RestaurantScope::class) |
||||
->when(is_numeric($restaurant_id), function($query)use($restaurant_id){ |
||||
return $query->where('restaurant_id', $restaurant_id); |
||||
}) |
||||
->orderBy('name')->paginate(config('default_pagination')); |
||||
$restaurant =$restaurant_id !='all'? Restaurant::findOrFail($restaurant_id):null; |
||||
return view('admin-views.addon.index', compact('addons', 'restaurant')); |
||||
} |
||||
|
||||
public function store(Request $request) |
||||
{ |
||||
$request->validate([ |
||||
'name.*' => 'max:191', |
||||
'name'=>'array|required', |
||||
'restaurant_id' => 'required', |
||||
'price' => 'required|numeric|between:0,999999999999.99', |
||||
], [ |
||||
'name.required' => translate('messages.Name is required!'), |
||||
'restaurant_id.required' => translate('messages.please_select_restaurant'), |
||||
]); |
||||
|
||||
$addon = new AddOn(); |
||||
$addon->name = $request->name[array_search('en', $request->lang)]; |
||||
$addon->price = $request->price; |
||||
$addon->restaurant_id = $request->restaurant_id; |
||||
$addon->save(); |
||||
|
||||
$data = []; |
||||
foreach($request->lang as $index=>$key) |
||||
{ |
||||
if($request->name[$index] && $key != 'en') |
||||
{ |
||||
array_push($data, Array( |
||||
'translationable_type' => 'App\Models\AddOn', |
||||
'translationable_id' => $addon->id, |
||||
'locale' => $key, |
||||
'key' => 'name', |
||||
'value' => $request->name[$index], |
||||
)); |
||||
} |
||||
} |
||||
if(count($data)) |
||||
{ |
||||
Translation::insert($data); |
||||
} |
||||
Toastr::success(translate('messages.addon_added_successfully')); |
||||
return back(); |
||||
} |
||||
|
||||
public function edit($id) |
||||
{ |
||||
$addon = AddOn::withoutGlobalScope(RestaurantScope::class)->withoutGlobalScope('translate')->findOrFail($id); |
||||
return view('admin-views.addon.edit', compact('addon')); |
||||
} |
||||
|
||||
public function update(Request $request, $id) |
||||
{ |
||||
$request->validate([ |
||||
'name' => 'required|max:191', |
||||
'restaurant_id' => 'required', |
||||
'price' => 'required|numeric|between:0,999999999999.99', |
||||
], [ |
||||
'name.required' => translate('messages.Name is required!'), |
||||
'restaurant_id.required' => translate('messages.please_select_restaurant'), |
||||
]); |
||||
|
||||
$addon = AddOn::withoutGlobalScope(RestaurantScope::class)->find($id); |
||||
$addon->name = $request->name[array_search('en', $request->lang)]; |
||||
$addon->price = $request->price; |
||||
$addon->restaurant_id = $request->restaurant_id; |
||||
$addon->save(); |
||||
|
||||
foreach($request->lang as $index=>$key) |
||||
{ |
||||
if($request->name[$index] && $key != 'en') |
||||
{ |
||||
Translation::updateOrInsert( |
||||
['translationable_type' => 'App\Models\AddOn', |
||||
'translationable_id' => $addon->id, |
||||
'locale' => $key, |
||||
'key' => 'name'], |
||||
['value' => $request->name[$index]] |
||||
); |
||||
} |
||||
} |
||||
|
||||
Toastr::success(translate('messages.addon_updated_successfully')); |
||||
return redirect(route('admin.addon.add-new')); |
||||
} |
||||
|
||||
public function delete(Request $request) |
||||
{ |
||||
$addon = AddOn::withoutGlobalScope(RestaurantScope::class)->find($request->id); |
||||
$addon->delete(); |
||||
Toastr::success(translate('messages.addon_deleted_successfully')); |
||||
return back(); |
||||
} |
||||
|
||||
public function status($addon, Request $request) |
||||
{ |
||||
$addon_data = AddOn::withoutGlobalScope(RestaurantScope::class)->find($addon); |
||||
$addon_data->status = $request->status; |
||||
$addon_data->save(); |
||||
Toastr::success(translate('messages.addon_status_updated')); |
||||
return back(); |
||||
} |
||||
|
||||
public function search(Request $request){ |
||||
$key = explode(' ', $request['search']); |
||||
$addons=AddOn::where(function ($q) use ($key) { |
||||
foreach ($key as $value) { |
||||
$q->orWhere('name', 'like', "%{$value}%"); |
||||
} |
||||
})->limit(50)->get(); |
||||
return response()->json([ |
||||
'view'=>view('admin-views.addon.partials._table',compact('addons'))->render() |
||||
]); |
||||
} |
||||
public function bulk_import_index() |
||||
{ |
||||
return view('admin-views.addon.bulk-import'); |
||||
} |
||||
|
||||
public function bulk_import_data(Request $request) |
||||
{ |
||||
try { |
||||
$collections = (new FastExcel)->import($request->file('products_file')); |
||||
} catch (\Exception $exception) { |
||||
Toastr::error(translate('messages.you_have_uploaded_a_wrong_format_file')); |
||||
return back(); |
||||
} |
||||
|
||||
$data = []; |
||||
foreach ($collections as $collection) { |
||||
if ($collection['name'] === "" && $collection['restaurant_id'] === "") { |
||||
Toastr::error(translate('messages.please_fill_all_required_fields')); |
||||
return back(); |
||||
} |
||||
array_push($data, [ |
||||
'name' => $collection['name'], |
||||
'price' => $collection['price'], |
||||
'restaurant_id' => $collection['restaurant_id'], |
||||
'created_at'=>now(), |
||||
'updated_at'=>now() |
||||
]); |
||||
} |
||||
DB::table('add_ons')->insert($data); |
||||
Toastr::success(translate('messages.addon_imported_successfully', ['count'=>count($data)])); |
||||
return back(); |
||||
} |
||||
|
||||
public function bulk_export_index() |
||||
{ |
||||
return view('admin-views.addon.bulk-export'); |
||||
} |
||||
|
||||
public function bulk_export_data(Request $request) |
||||
{ |
||||
$request->validate([ |
||||
'type'=>'required', |
||||
'start_id'=>'required_if:type,id_wise', |
||||
'end_id'=>'required_if:type,id_wise', |
||||
'from_date'=>'required_if:type,date_wise', |
||||
'to_date'=>'required_if:type,date_wise' |
||||
]); |
||||
$addons = AddOn::when($request['type']=='date_wise', function($query)use($request){ |
||||
$query->whereBetween('created_at', [$request['from_date'].' 00:00:00', $request['to_date'].' 23:59:59']); |
||||
}) |
||||
->when($request['type']=='id_wise', function($query)use($request){ |
||||
$query->whereBetween('id', [$request['start_id'], $request['end_id']]); |
||||
}) |
||||
->withoutGlobalScope(RestaurantScope::class)->get(); |
||||
return (new FastExcel(ProductLogic::format_export_addons($addons)))->download('Addons.xlsx'); |
||||
|
||||
} |
||||
} |
@ -0,0 +1,146 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Admin; |
||||
|
||||
use App\Http\Controllers\Controller; |
||||
use App\Models\Attribute; |
||||
use App\CentralLogics\Helpers; |
||||
use Brian2694\Toastr\Facades\Toastr; |
||||
use Illuminate\Http\Request; |
||||
use Rap2hpoutre\FastExcel\FastExcel; |
||||
use Illuminate\Support\Facades\DB; |
||||
|
||||
class AttributeController extends Controller |
||||
{ |
||||
function index() |
||||
{ |
||||
$attributes = Attribute::orderBy('name')->paginate(config('default_pagination')); |
||||
return view('admin-views.attribute.index', compact('attributes')); |
||||
} |
||||
|
||||
public function store(Request $request) |
||||
{ |
||||
$request->validate([ |
||||
'name' => 'required|unique:attributes|max:100', |
||||
], [ |
||||
'name.required' => translate('messages.Name is required!'), |
||||
]); |
||||
|
||||
$attribute = new Attribute; |
||||
$attribute->name = $request->name; |
||||
$attribute->save(); |
||||
|
||||
Toastr::success(translate('messages.attribute_added_successfully')); |
||||
return back(); |
||||
} |
||||
|
||||
public function edit($id) |
||||
{ |
||||
$attribute = Attribute::findOrFail($id); |
||||
return view('admin-views.attribute.edit', compact('attribute')); |
||||
} |
||||
|
||||
public function update(Request $request, $id) |
||||
{ |
||||
$request->validate([ |
||||
'name' => 'required|max:100|unique:attributes,name,'.$id, |
||||
], [ |
||||
'name.required' => translate('messages.Name is required!'), |
||||
]); |
||||
|
||||
$attribute = Attribute::findOrFail($id); |
||||
$attribute->name = $request->name; |
||||
$attribute->save(); |
||||
Toastr::success(translate('messages.attribute_updated_successfully')); |
||||
return back(); |
||||
} |
||||
|
||||
public function delete(Request $request) |
||||
{ |
||||
$attribute = Attribute::findOrFail($request->id); |
||||
$attribute->delete(); |
||||
Toastr::success(translate('messages.attribute_deleted_successfully')); |
||||
return back(); |
||||
} |
||||
|
||||
public function search(Request $request){ |
||||
$key = explode(' ', $request['search']); |
||||
$attributes=Attribute::where(function ($q) use ($key) { |
||||
foreach ($key as $value) { |
||||
$q->orWhere('name', 'like', "%{$value}%"); |
||||
} |
||||
})->limit(50)->get(); |
||||
return response()->json([ |
||||
'view'=>view('admin-views.attribute.partials._table',compact('attributes'))->render(), |
||||
'count'=>$attributes->count(), |
||||
]); |
||||
} |
||||
|
||||
public function bulk_import_index() |
||||
{ |
||||
return view('admin-views.attribute.bulk-import'); |
||||
} |
||||
|
||||
public function bulk_import_data(Request $request) |
||||
{ |
||||
try { |
||||
$collections = (new FastExcel)->import($request->file('products_file')); |
||||
} catch (\Exception $exception) { |
||||
Toastr::error(translate('messages.you_have_uploaded_a_wrong_format_file')); |
||||
return back(); |
||||
} |
||||
|
||||
$data = []; |
||||
$skip = ['youtube_video_url']; |
||||
foreach ($collections as $collection) { |
||||
if ($collection['name'] === "" ) { |
||||
Toastr::error(translate('messages.please_fill_all_required_fields')); |
||||
return back(); |
||||
} |
||||
|
||||
|
||||
array_push($data, [ |
||||
'name' => $collection['name'], |
||||
'created_at'=>now(), |
||||
'updated_at'=>now() |
||||
]); |
||||
} |
||||
DB::table('attributes')->insert($data); |
||||
Toastr::success(translate('messages.attribute_imported_successfully',['count'=>count($data)])); |
||||
return back(); |
||||
} |
||||
|
||||
public function bulk_export_index() |
||||
{ |
||||
return view('admin-views.attribute.bulk-export'); |
||||
} |
||||
|
||||
public function bulk_export_data(Request $request) |
||||
{ |
||||
$request->validate([ |
||||
'type'=>'required', |
||||
'start_id'=>'required_if:type,id_wise', |
||||
'end_id'=>'required_if:type,id_wise', |
||||
'from_date'=>'required_if:type,date_wise', |
||||
'to_date'=>'required_if:type,date_wise' |
||||
]); |
||||
$attributes = Attribute::when($request['type']=='date_wise', function($query)use($request){ |
||||
$query->whereBetween('created_at', [$request['from_date'].' 00:00:00', $request['to_date'].' 23:59:59']); |
||||
}) |
||||
->when($request['type']=='id_wise', function($query)use($request){ |
||||
$query->whereBetween('id', [$request['start_id'], $request['end_id']]); |
||||
}) |
||||
->get(); |
||||
return (new FastExcel($attributes))->download('Attributes.xlsx'); |
||||
} |
||||
|
||||
public function export_attributes($type){ |
||||
$collection = Attribute::all(); |
||||
|
||||
if($type == 'excel'){ |
||||
return (new FastExcel(Helpers::export_attributes($collection)))->download('Attributes.xlsx'); |
||||
}elseif($type == 'csv'){ |
||||
return (new FastExcel(Helpers::export_attributes($collection)))->download('Attributes.csv'); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,70 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Admin\Auth; |
||||
|
||||
use Illuminate\Http\Request; |
||||
use App\CentralLogics\Helpers; |
||||
use Gregwar\Captcha\CaptchaBuilder; |
||||
use App\Http\Controllers\Controller; |
||||
use Brian2694\Toastr\Facades\Toastr; |
||||
use Illuminate\Support\Facades\Http; |
||||
use Illuminate\Support\Facades\Session; |
||||
|
||||
class LoginController extends Controller |
||||
{ |
||||
public function __construct() |
||||
{ |
||||
$this->middleware('guest:admin', ['except' => 'logout']); |
||||
} |
||||
|
||||
public function login() |
||||
{ |
||||
$custome_recaptcha = new CaptchaBuilder; |
||||
$custome_recaptcha->build(); |
||||
Session::put('six_captcha', $custome_recaptcha->getPhrase()); |
||||
return view('admin-views.auth.login', compact('custome_recaptcha')); |
||||
} |
||||
|
||||
public function submit(Request $request) |
||||
{ |
||||
$request->validate([ |
||||
'email' => 'required|email', |
||||
'password' => 'required|min:6' |
||||
]); |
||||
|
||||
/* $recaptcha = Helpers::get_business_settings('recaptcha'); |
||||
if (isset($recaptcha) && $recaptcha['status'] == 1) { |
||||
$request->validate([ |
||||
'g-recaptcha-response' => [ |
||||
function ($attribute, $value, $fail) { |
||||
$secret_key = Helpers::get_business_settings('recaptcha')['secret_key']; |
||||
$response = $value; |
||||
$url = 'https://www.google.com/recaptcha/api/siteverify?secret=' . $secret_key . '&response=' . $response; |
||||
$response = Http::get($url); |
||||
$response = $response->json(); |
||||
if (!isset($response['success']) || !$response['success']) { |
||||
$fail(translate('messages.ReCAPTCHA Failed')); |
||||
} |
||||
}, |
||||
], |
||||
]); |
||||
} else if(session('six_captcha') != $request->custome_recaptcha) |
||||
{ |
||||
Toastr::error(translate('messages.ReCAPTCHA Failed')); |
||||
return back(); |
||||
} |
||||
*/ |
||||
if (auth('admin')->attempt(['email' => $request->email, 'password' => $request->password], $request->remember)) { |
||||
return redirect()->route('admin.dashboard'); |
||||
} |
||||
|
||||
return redirect()->back()->withInput($request->only('email', 'remember')) |
||||
->withErrors([translate('credentials_does_not_match')]); |
||||
} |
||||
|
||||
public function logout(Request $request) |
||||
{ |
||||
auth()->guard('admin')->logout(); |
||||
return redirect()->route('admin.auth.login'); |
||||
} |
||||
} |
@ -0,0 +1,129 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Admin; |
||||
|
||||
use App\Http\Controllers\Controller; |
||||
use Illuminate\Support\Facades\Validator; |
||||
use Illuminate\Http\Request; |
||||
use App\Models\Banner; |
||||
use App\Models\Restaurant; |
||||
use Brian2694\Toastr\Facades\Toastr; |
||||
use Carbon\Carbon; |
||||
use Illuminate\Support\Facades\Storage; |
||||
use App\CentralLogics\Helpers; |
||||
|
||||
class BannerController extends Controller |
||||
{ |
||||
function index() |
||||
{ |
||||
$banners = Banner::latest()->paginate(config('default_pagination')); |
||||
return view('admin-views.banner.index', compact('banners')); |
||||
} |
||||
|
||||
public function store(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'title' => 'required|max:191', |
||||
'image' => 'required|max:2048', |
||||
'banner_type' => 'required', |
||||
'zone_id' => 'required', |
||||
'restaurant_id' => 'required_if:banner_type,restaurant_wise', |
||||
'item_id' => 'required_if:banner_type,item_wise', |
||||
], [ |
||||
'zone_id.required' => translate('messages.select_a_zone'), |
||||
'restaurant_id.required_if'=> translate('messages.Restaurant is required when banner type is restaurant wise'), |
||||
'item_id.required_if'=> translate('messages.Food is required when banner type is food wise'), |
||||
]); |
||||
|
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)]); |
||||
} |
||||
|
||||
$banner = new Banner; |
||||
$banner->title = $request->title; |
||||
$banner->type = $request->banner_type; |
||||
$banner->zone_id = $request->zone_id; |
||||
$banner->image = Helpers::upload('banner/', 'png', $request->file('image')); |
||||
$banner->data = ($request->banner_type == 'restaurant_wise')?$request->restaurant_id:$request->item_id; |
||||
$banner->save(); |
||||
|
||||
return response()->json([], 200); |
||||
} |
||||
|
||||
public function edit(Banner $banner) |
||||
{ |
||||
return view('admin-views.banner.edit', compact('banner')); |
||||
} |
||||
|
||||
// public function view(Banner $banner) |
||||
// { |
||||
// $restaurant_ids = json_decode($banner->restaurant_ids); |
||||
// $restaurants = Restaurant::whereIn('id', $restaurant_ids)->paginate(10); |
||||
// return view('admin-views.banner.view', compact('banner', 'restaurants', 'restaurant_ids')); |
||||
// } |
||||
|
||||
public function status(Request $request) |
||||
{ |
||||
$banner = Banner::findOrFail($request->id); |
||||
$banner->status = $request->status; |
||||
$banner->save(); |
||||
Toastr::success(translate('messages.banner_status_updated')); |
||||
return back(); |
||||
} |
||||
|
||||
public function update(Request $request, Banner $banner) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'title' => 'required|max:191', |
||||
'banner_type' => 'required', |
||||
'zone_id' => 'required', |
||||
'image' => 'nullable|max:2048', |
||||
|
||||
'restaurant_id' => 'required_if:banner_type,restaurant_wise', |
||||
'item_id' => 'required_if:banner_type,item_wise', |
||||
], [ |
||||
'zone_id.required' => translate('messages.select_a_zone'), |
||||
'restaurant_id.required_if'=> translate('messages.Restaurant is required when banner type is restaurant wise'), |
||||
'item_id.required_if'=> translate('messages.Food is required when banner type is food wise'), |
||||
]); |
||||
|
||||
|
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)]); |
||||
} |
||||
|
||||
$banner->title = $request->title; |
||||
$banner->type = $request->banner_type; |
||||
$banner->zone_id = $request->zone_id; |
||||
$banner->image = $request->has('image') ? Helpers::update('banner/', $banner->image, 'png', $request->file('image')) : $banner->image; |
||||
$banner->data = $request->banner_type=='restaurant_wise'?$request->restaurant_id:$request->item_id; |
||||
$banner->save(); |
||||
|
||||
return response()->json([], 200); |
||||
// Toastr::success(translate('messages.banner_updated_successfully')); |
||||
// return redirect('admin/banner/add-new'); |
||||
} |
||||
|
||||
public function delete(Banner $banner) |
||||
{ |
||||
if (Storage::disk('public')->exists('banner/' . $banner['image'])) { |
||||
Storage::disk('public')->delete('banner/' . $banner['image']); |
||||
} |
||||
$banner->delete(); |
||||
Toastr::success(translate('messages.banner_deleted_successfully')); |
||||
return back(); |
||||
} |
||||
|
||||
public function search(Request $request){ |
||||
$key = explode(' ', $request['search']); |
||||
$banners=Banner::where(function ($q) use ($key) { |
||||
foreach ($key as $value) { |
||||
$q->orWhere('title', 'like', "%{$value}%"); |
||||
} |
||||
})->limit(50)->get(); |
||||
return response()->json([ |
||||
'view'=>view('admin-views.banner.partials._table',compact('banners'))->render(), |
||||
'count'=>$banners->count() |
||||
]); |
||||
} |
||||
} |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,565 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Admin; |
||||
|
||||
use Carbon\Carbon; |
||||
use App\Models\Campaign; |
||||
use App\Models\Restaurant; |
||||
use App\Models\Translation; |
||||
use Illuminate\Support\Str; |
||||
use App\Models\ItemCampaign; |
||||
use Illuminate\Http\Request; |
||||
use App\CentralLogics\Helpers; |
||||
use App\Http\Controllers\Controller; |
||||
use Brian2694\Toastr\Facades\Toastr; |
||||
use Illuminate\Support\Facades\Storage; |
||||
use Illuminate\Support\Facades\Validator; |
||||
|
||||
class CampaignController extends Controller |
||||
{ |
||||
function index($type) |
||||
{ |
||||
return view('admin-views.campaign.'.$type.'.index'); |
||||
} |
||||
|
||||
function list($type) |
||||
{ |
||||
if($type=='basic') |
||||
{ |
||||
$campaigns=Campaign::latest()->paginate(config('default_pagination')); |
||||
} |
||||
else{ |
||||
$campaigns=ItemCampaign::latest()->paginate(config('default_pagination')); |
||||
} |
||||
|
||||
return view('admin-views.campaign.'.$type.'.list', compact('campaigns')); |
||||
} |
||||
|
||||
public function storeBasic(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'title' => 'required|unique:campaigns|max:191', |
||||
'description'=>'max:1000', |
||||
'image' => 'required|max:2048', |
||||
|
||||
]); |
||||
|
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)]); |
||||
} |
||||
|
||||
$campaign = new Campaign; |
||||
$campaign->title = $request->title[array_search('en', $request->lang)]; |
||||
$campaign->description = $request->description[array_search('en', $request->lang)]; |
||||
$campaign->image = Helpers::upload('campaign/', 'png', $request->file('image')); |
||||
$campaign->start_date = $request->start_date; |
||||
$campaign->end_date = $request->end_date; |
||||
$campaign->start_time = $request->start_time; |
||||
$campaign->end_time = $request->end_time; |
||||
$campaign->save(); |
||||
|
||||
$data = []; |
||||
foreach ($request->lang as $index => $key) { |
||||
if ($request->title[$index] && $key != 'en') { |
||||
array_push($data, array( |
||||
'translationable_type' => 'App\Models\Campaign', |
||||
'translationable_id' => $campaign->id, |
||||
'locale' => $key, |
||||
'key' => 'title', |
||||
'value' => $request->title[$index], |
||||
)); |
||||
} |
||||
if ($request->description[$index] && $key != 'en') { |
||||
array_push($data, array( |
||||
'translationable_type' => 'App\Models\Campaign', |
||||
'translationable_id' => $campaign->id, |
||||
'locale' => $key, |
||||
'key' => 'description', |
||||
'value' => $request->description[$index], |
||||
)); |
||||
} |
||||
} |
||||
|
||||
Translation::insert($data); |
||||
|
||||
return response()->json([], 200); |
||||
} |
||||
|
||||
public function update(Request $request, Campaign $campaign) |
||||
{ |
||||
$validator = Validator::make($request->all(),[ |
||||
'title' => 'required|max:191', |
||||
'description' => 'max:1000', |
||||
'image' => 'nullable|max:2048', |
||||
|
||||
]); |
||||
|
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)]); |
||||
} |
||||
|
||||
$campaign->title = $request->title[array_search('en', $request->lang)]; |
||||
$campaign->description = $request->description[array_search('en', $request->lang)]; |
||||
$campaign->image = $request->has('image') ? Helpers::update('campaign/', $campaign->image, 'png', $request->file('image')) : $campaign->image;; |
||||
$campaign->start_date = $request->start_date; |
||||
$campaign->end_date = $request->end_date; |
||||
$campaign->start_time = $request->start_time; |
||||
$campaign->end_time = $request->end_time; |
||||
$campaign->save(); |
||||
|
||||
foreach ($request->lang as $index => $key) { |
||||
if ($request->title[$index] && $key != 'en') { |
||||
Translation::updateOrInsert( |
||||
['translationable_type' => 'App\Models\Campaign', |
||||
'translationable_id' => $campaign->id, |
||||
'locale' => $key, |
||||
'key' => 'title'], |
||||
['value' => $request->title[$index]] |
||||
); |
||||
} |
||||
if ($request->description[$index] && $key != 'en') { |
||||
Translation::updateOrInsert( |
||||
['translationable_type' => 'App\Models\Campaign', |
||||
'translationable_id' => $campaign->id, |
||||
'locale' => $key, |
||||
'key' => 'description'], |
||||
['value' => $request->description[$index]] |
||||
); |
||||
} |
||||
} |
||||
|
||||
return response()->json([], 200); |
||||
} |
||||
|
||||
public function storeItem(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'title' => 'required|max:191|unique:item_campaigns', |
||||
'image' => 'required|max:2048', |
||||
'category_id' => 'required', |
||||
'price' => 'required|numeric|between:0.01,999999999999.99', |
||||
'restaurant_id' => 'required', |
||||
'start_time' => 'required', |
||||
'end_time' => 'required', |
||||
'start_date' => 'required', |
||||
'start_date' => 'required', |
||||
'veg' => 'required', |
||||
'description'=>'max:1000' |
||||
], [ |
||||
'category_id.required' => translate('messages.select_category'), |
||||
]); |
||||
|
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)]); |
||||
} |
||||
|
||||
if ($request['discount_type'] == 'percent') { |
||||
$dis = ($request['price'] / 100) * $request['discount']; |
||||
} else { |
||||
$dis = $request['discount']; |
||||
} |
||||
|
||||
if ($request['price'] <= $dis) { |
||||
$validator->getMessageBag()->add('unit_price', translate('messages.discount_can_not_be_more_than_or_equal')); |
||||
} |
||||
|
||||
if ($request['price'] <= $dis || $validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)]); |
||||
} |
||||
|
||||
$campaign = new ItemCampaign; |
||||
|
||||
$category = []; |
||||
if ($request->category_id != null) { |
||||
array_push($category, [ |
||||
'id' => $request->category_id, |
||||
'position' => 1, |
||||
]); |
||||
} |
||||
if ($request->sub_category_id != null) { |
||||
array_push($category, [ |
||||
'id' => $request->sub_category_id, |
||||
'position' => 2, |
||||
]); |
||||
} |
||||
if ($request->sub_sub_category_id != null) { |
||||
array_push($category, [ |
||||
'id' => $request->sub_sub_category_id, |
||||
'position' => 3, |
||||
]); |
||||
} |
||||
|
||||
$campaign->category_ids = json_encode($category); |
||||
$choice_options = []; |
||||
if ($request->has('choice')) { |
||||
foreach ($request->choice_no as $key => $no) { |
||||
$str = 'choice_options_' . $no; |
||||
if ($request[$str][0] == null) { |
||||
$validator->getMessageBag()->add('name', translate('messages.attribute_choice_option_value_can_not_be_null')); |
||||
return response()->json(['errors' => Helpers::error_processor($validator)]); |
||||
} |
||||
$item['name'] = 'choice_' . $no; |
||||
$item['title'] = $request->choice[$key]; |
||||
$item['options'] = explode(',', implode('|', preg_replace('/\s+/', ' ', $request[$str]))); |
||||
array_push($choice_options, $item); |
||||
} |
||||
} |
||||
$campaign->choice_options = json_encode($choice_options); |
||||
$variations = []; |
||||
if(isset($request->options)) |
||||
{ |
||||
foreach(array_values($request->options) as $key=>$option) |
||||
{ |
||||
|
||||
$temp_variation['name']= $option['name']; |
||||
$temp_variation['type']= $option['type']; |
||||
$temp_variation['min']= $option['min'] ?? 0; |
||||
$temp_variation['max']= $option['max'] ?? 0; |
||||
if($option['min'] > 0 && $option['min'] > $option['max'] ){ |
||||
$validator->getMessageBag()->add('name', translate('messages.minimum_value_can_not_be_greater_then_maximum_value')); |
||||
return response()->json(['errors' => Helpers::error_processor($validator)]); |
||||
} |
||||
if(!isset($option['values'])){ |
||||
$validator->getMessageBag()->add('name', translate('messages.please_add_options_for').$option['name']); |
||||
return response()->json(['errors' => Helpers::error_processor($validator)]); |
||||
} |
||||
if($option['max'] > count($option['values']) ){ |
||||
$validator->getMessageBag()->add('name', translate('messages.please_add_more_options_or_change_the_max_value_for').$option['name']); |
||||
return response()->json(['errors' => Helpers::error_processor($validator)]); |
||||
} |
||||
$temp_variation['required']= $option['required']??'off'; |
||||
|
||||
$temp_value = []; |
||||
foreach(array_values($option['values']) as $value) |
||||
{ |
||||
if(isset($value['label'])){ |
||||
$temp_option['label'] = $value['label']; |
||||
} |
||||
$temp_option['optionPrice'] = $value['optionPrice']; |
||||
array_push($temp_value,$temp_option); |
||||
} |
||||
$temp_variation['values']= $temp_value; |
||||
array_push($variations,$temp_variation); |
||||
} |
||||
} |
||||
|
||||
$slug = Str::slug($request->title[array_search('en', $request->lang)]); |
||||
$campaign->slug = $campaign->slug? $campaign->slug :"{$slug}{$campaign->id}"; |
||||
|
||||
$campaign->admin_id = auth('admin')->id(); |
||||
$campaign->title = $request->title[array_search('en', $request->lang)]; |
||||
$campaign->description = $request->description[array_search('en', $request->lang)]; |
||||
$campaign->image = Helpers::upload('campaign/', 'png', $request->file('image')); |
||||
$campaign->start_date = $request->start_date; |
||||
$campaign->end_date = $request->end_date; |
||||
$campaign->start_time = $request->start_time; |
||||
$campaign->end_time = $request->end_time; |
||||
$campaign->variations = json_encode($variations); |
||||
$campaign->price = $request->price; |
||||
$campaign->discount = $request->discount_type == 'amount' ? $request->discount : $request->discount; |
||||
$campaign->discount_type = $request->discount_type; |
||||
$campaign->attributes = $request->has('attribute_id') ? json_encode($request->attribute_id) : json_encode([]); |
||||
$campaign->add_ons = $request->has('addon_ids') ? json_encode($request->addon_ids) : json_encode([]); |
||||
$campaign->restaurant_id = $request->restaurant_id; |
||||
$campaign->veg = $request->veg; |
||||
$campaign->save(); |
||||
|
||||
$data = []; |
||||
foreach ($request->lang as $index => $key) { |
||||
if ($request->title[$index] && $key != 'en') { |
||||
array_push($data, array( |
||||
'translationable_type' => 'App\Models\ItemCampaign', |
||||
'translationable_id' => $p->id, |
||||
'locale' => $key, |
||||
'key' => 'title', |
||||
'value' => $request->title[$index], |
||||
)); |
||||
} |
||||
if ($request->description[$index] && $key != 'en') { |
||||
array_push($data, array( |
||||
'translationable_type' => 'App\Models\ItemCampaign', |
||||
'translationable_id' => $p->id, |
||||
'locale' => $key, |
||||
'key' => 'description', |
||||
'value' => $request->description[$index], |
||||
)); |
||||
} |
||||
} |
||||
Translation::insert($data); |
||||
|
||||
return response()->json([], 200); |
||||
} |
||||
|
||||
public function updateItem(ItemCampaign $campaign, Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'title' => 'required|array', |
||||
'category_id' => 'required', |
||||
'price' => 'required|numeric|between:0.01,999999999999.99', |
||||
'restaurant_id' => 'required', |
||||
'veg' => 'required', |
||||
'image' => 'nullable|max:2048', |
||||
'description.*'=>'max:1000', |
||||
]); |
||||
|
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)]); |
||||
} |
||||
|
||||
if ($request['discount_type'] == 'percent') { |
||||
$dis = ($request['price'] / 100) * $request['discount']; |
||||
} else { |
||||
$dis = $request['discount']; |
||||
} |
||||
|
||||
if ($request['price'] <= $dis) { |
||||
$validator->getMessageBag()->add('unit_price', translate('messages.discount_can_not_be_more_than_or_equal')); |
||||
} |
||||
|
||||
if ($request['price'] <= $dis || $validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)]); |
||||
} |
||||
|
||||
$category = []; |
||||
if ($request->category_id != null) { |
||||
array_push($category, [ |
||||
'id' => $request->category_id, |
||||
'position' => 1, |
||||
]); |
||||
} |
||||
if ($request->sub_category_id != null) { |
||||
array_push($category, [ |
||||
'id' => $request->sub_category_id, |
||||
'position' => 2, |
||||
]); |
||||
} |
||||
if ($request->sub_sub_category_id != null) { |
||||
array_push($category, [ |
||||
'id' => $request->sub_sub_category_id, |
||||
'position' => 3, |
||||
]); |
||||
} |
||||
|
||||
$campaign->category_ids = json_encode($category); |
||||
$choice_options = []; |
||||
if ($request->has('choice')) { |
||||
foreach ($request->choice_no as $key => $no) { |
||||
$str = 'choice_options_' . $no; |
||||
if ($request[$str][0] == null) { |
||||
$validator->getMessageBag()->add('name', translate('messages.attribute_choice_option_value_can_not_be_null')); |
||||
return response()->json(['errors' => Helpers::error_processor($validator)]); |
||||
} |
||||
$item['name'] = 'choice_' . $no; |
||||
$item['title'] = $request->choice[$key]; |
||||
$item['options'] = explode(',', implode('|', preg_replace('/\s+/', ' ', $request[$str]))); |
||||
array_push($choice_options, $item); |
||||
} |
||||
} |
||||
|
||||
$campaign->choice_options = json_encode($choice_options); |
||||
$variations = []; |
||||
if(isset($request->options)) |
||||
{ |
||||
foreach(array_values($request->options) as $key=>$option) |
||||
{ |
||||
|
||||
$temp_variation['name']= $option['name']; |
||||
$temp_variation['type']= $option['type']; |
||||
$temp_variation['min']= $option['min'] ?? 0; |
||||
$temp_variation['max']= $option['max'] ?? 0; |
||||
if($option['min'] > 0 && $option['min'] > $option['max'] ){ |
||||
$validator->getMessageBag()->add('name', translate('messages.minimum_value_can_not_be_greater_then_maximum_value')); |
||||
return response()->json(['errors' => Helpers::error_processor($validator)]); |
||||
} |
||||
if(!isset($option['values'])){ |
||||
$validator->getMessageBag()->add('name', translate('messages.please_add_options_for').$option['name']); |
||||
return response()->json(['errors' => Helpers::error_processor($validator)]); |
||||
} |
||||
if($option['max'] > count($option['values']) ){ |
||||
$validator->getMessageBag()->add('name', translate('messages.please_add_more_options_or_change_the_max_value_for').$option['name']); |
||||
return response()->json(['errors' => Helpers::error_processor($validator)]); |
||||
} |
||||
$temp_variation['required']= $option['required']??'off'; |
||||
|
||||
$temp_value = []; |
||||
foreach(array_values($option['values']) as $value) |
||||
{ |
||||
if(isset($value['label'])){ |
||||
$temp_option['label'] = $value['label']; |
||||
} |
||||
$temp_option['optionPrice'] = $value['optionPrice']; |
||||
array_push($temp_value,$temp_option); |
||||
} |
||||
$temp_variation['values']= $temp_value; |
||||
array_push($variations,$temp_variation); |
||||
} |
||||
} |
||||
|
||||
$campaign->title = $request->title[array_search('en', $request->lang)]; |
||||
$campaign->description = $request->description[array_search('en', $request->lang)]; |
||||
$campaign->image = $request->has('image') ? Helpers::update('campaign/', $campaign->image, 'png', $request->file('image')) : $campaign->image; |
||||
$campaign->start_date = $request->start_date; |
||||
$campaign->end_date = $request->end_date; |
||||
$campaign->start_time = $request->start_time; |
||||
$campaign->end_time = $request->end_time; |
||||
$campaign->restaurant_id = $request->restaurant_id; |
||||
$campaign->variations = json_encode($variations); |
||||
$campaign->price = $request->price; |
||||
$campaign->discount = $request->discount_type == 'amount' ? $request->discount : $request->discount; |
||||
$campaign->discount_type = $request->discount_type; |
||||
$campaign->attributes = $request->has('attribute_id') ? json_encode($request->attribute_id) : json_encode([]); |
||||
$campaign->add_ons = $request->has('addon_ids') ? json_encode($request->addon_ids) : json_encode([]); |
||||
$campaign->veg = $request->veg; |
||||
$campaign->save(); |
||||
|
||||
foreach ($request->lang as $index => $key) { |
||||
if ($request->title[$index] && $key != 'en') { |
||||
Translation::updateOrInsert( |
||||
['translationable_type' => 'App\Models\ItemCampaign', |
||||
'translationable_id' => $campaign->id, |
||||
'locale' => $key, |
||||
'key' => 'title'], |
||||
['value' => $request->title[$index]] |
||||
); |
||||
} |
||||
if ($request->description[$index] && $key != 'en') { |
||||
Translation::updateOrInsert( |
||||
['translationable_type' => 'App\Models\ItemCampaign', |
||||
'translationable_id' => $campaign->id, |
||||
'locale' => $key, |
||||
'key' => 'description'], |
||||
['value' => $request->description[$index]] |
||||
); |
||||
} |
||||
} |
||||
|
||||
return response()->json([], 200); |
||||
} |
||||
|
||||
public function edit($type, $campaign) |
||||
{ |
||||
if($type=='basic') |
||||
{ |
||||
$campaign = Campaign::withoutGlobalScope('translate')->findOrFail($campaign); |
||||
} |
||||
else |
||||
{ |
||||
$campaign = ItemCampaign::withoutGlobalScope('translate')->findOrFail($campaign); |
||||
} |
||||
return view('admin-views.campaign.'.$type.'.edit', compact('campaign')); |
||||
} |
||||
|
||||
public function view(Request $request ,$type, $campaign) |
||||
{ |
||||
if($type=='basic') |
||||
{ |
||||
$campaign = Campaign::findOrFail($campaign); |
||||
$key = explode(' ', $request['search']); |
||||
|
||||
$restaurants = $campaign->restaurants() |
||||
->when(isset($key) ,function ($q) use ($key) { |
||||
foreach ($key as $value) { |
||||
$q->where('name', 'like', "%{$value}%"); |
||||
// ->orWhere('email', 'like', "%{$value}%"); |
||||
} |
||||
})->paginate(config('default_pagination')); |
||||
|
||||
$restaurant_ids = []; |
||||
foreach($campaign->restaurants as $restaurant) |
||||
{ |
||||
$restaurant_ids[] = $restaurant->id; |
||||
} |
||||
return view('admin-views.campaign.basic.view', compact('campaign', 'restaurants', 'restaurant_ids')); |
||||
} |
||||
else |
||||
{ |
||||
$campaign = ItemCampaign::findOrFail($campaign); |
||||
} |
||||
return view('admin-views.campaign.item.view', compact('campaign')); |
||||
|
||||
} |
||||
|
||||
public function status($type, $id, $status) |
||||
{ |
||||
if($type=='item') |
||||
{ |
||||
$campaign = ItemCampaign::findOrFail($id); |
||||
} |
||||
else{ |
||||
$campaign = Campaign::findOrFail($id); |
||||
} |
||||
$campaign->status = $status; |
||||
$campaign->save(); |
||||
Toastr::success(translate('messages.campaign_status_updated')); |
||||
return back(); |
||||
} |
||||
|
||||
public function delete(Campaign $campaign) |
||||
{ |
||||
if (Storage::disk('public')->exists('campaign/' . $campaign->image)) { |
||||
Storage::disk('public')->delete('campaign/' . $campaign->image); |
||||
} |
||||
$campaign->translations()->delete(); |
||||
$campaign->delete(); |
||||
Toastr::success(translate('messages.campaign_deleted_successfully')); |
||||
return back(); |
||||
} |
||||
public function delete_item(ItemCampaign $campaign) |
||||
{ |
||||
if (Storage::disk('public')->exists('campaign/' . $campaign->image)) { |
||||
Storage::disk('public')->delete('campaign/' . $campaign->image); |
||||
} |
||||
$campaign->translations()->delete(); |
||||
$campaign->delete(); |
||||
Toastr::success(translate('messages.campaign_deleted_successfully')); |
||||
return back(); |
||||
} |
||||
|
||||
public function remove_restaurant(Campaign $campaign, $restaurant) |
||||
{ |
||||
$campaign->restaurants()->detach($restaurant); |
||||
$campaign->save(); |
||||
Toastr::success(translate('messages.restaurant_remove_from_campaign')); |
||||
return back(); |
||||
} |
||||
public function addrestaurant(Request $request, Campaign $campaign) |
||||
{ |
||||
$campaign->restaurants()->attach($request->restaurant_id,['campaign_status' => 'confirmed']); |
||||
$campaign->save(); |
||||
Toastr::success(translate('messages.restaurant_added_to_campaign')); |
||||
return back(); |
||||
} |
||||
|
||||
public function restaurant_confirmation($campaign,$restaurant_id,$status) |
||||
{ |
||||
$campaign = Campaign::findOrFail($campaign); |
||||
$campaign->restaurants()->updateExistingPivot($restaurant_id,['campaign_status' => $status]); |
||||
$campaign->save(); |
||||
Toastr::success(translate('messages.restaurant_added_to_campaign')); |
||||
return back(); |
||||
} |
||||
|
||||
public function searchBasic(Request $request){ |
||||
$key = explode(' ', $request['search']); |
||||
$campaigns=Campaign::where(function ($q) use ($key) { |
||||
foreach ($key as $value) { |
||||
$q->orWhere('title', 'like', "%{$value}%"); |
||||
} |
||||
})->limit(50)->get(); |
||||
return response()->json([ |
||||
'view'=>view('admin-views.campaign.basic.partials._table',compact('campaigns'))->render(), |
||||
'count'=>$campaigns->count() |
||||
]); |
||||
} |
||||
public function searchItem(Request $request){ |
||||
$key = explode(' ', $request['search']); |
||||
$campaigns=ItemCampaign::where(function ($q) use ($key) { |
||||
foreach ($key as $value) { |
||||
$q->orWhere('title', 'like', "%{$value}%"); |
||||
} |
||||
})->limit(50)->get(); |
||||
return response()->json([ |
||||
'view'=>view('admin-views.campaign.item.partials._table',compact('campaigns'))->render() |
||||
]); |
||||
} |
||||
} |
@ -0,0 +1,259 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Admin; |
||||
|
||||
use App\Http\Controllers\Controller; |
||||
use App\Models\Category; |
||||
use Brian2694\Toastr\Facades\Toastr; |
||||
use Carbon\Carbon; |
||||
use Illuminate\Http\Request; |
||||
use Illuminate\Support\Facades\Storage; |
||||
use App\CentralLogics\Helpers; |
||||
use Rap2hpoutre\FastExcel\FastExcel; |
||||
use Illuminate\Support\Facades\DB; |
||||
use App\Models\Translation; |
||||
use Illuminate\Support\Str; |
||||
use App\CentralLogics\CategoryLogic; |
||||
|
||||
class CategoryController extends Controller |
||||
{ |
||||
function index() |
||||
{ |
||||
$categories=Category::where(['position'=>0])->latest()->paginate(config('default_pagination')); |
||||
return view('admin-views.category.index',compact('categories')); |
||||
} |
||||
|
||||
function sub_index() |
||||
{ |
||||
$categories=Category::with(['parent'])->where(['position'=>1])->latest()->paginate(config('default_pagination')); |
||||
return view('admin-views.category.sub-index',compact('categories')); |
||||
} |
||||
|
||||
function sub_sub_index() |
||||
{ |
||||
return view('admin-views.category.sub-sub-index'); |
||||
} |
||||
|
||||
function sub_category_index() |
||||
{ |
||||
return view('admin-views.category.index'); |
||||
} |
||||
|
||||
function sub_sub_category_index() |
||||
{ |
||||
return view('admin-views.category.index'); |
||||
} |
||||
|
||||
function store(Request $request) |
||||
{ |
||||
$request->validate([ |
||||
'name' => 'required|unique:categories|max:100', |
||||
'image' => 'nullable|max:2048', |
||||
|
||||
], [ |
||||
'name.required' => translate('messages.Name is required!'), |
||||
]); |
||||
|
||||
$category = new Category(); |
||||
$category->name = $request->name[array_search('en', $request->lang)]; |
||||
$category->image = $request->has('image') ? Helpers::upload('category/', 'png', $request->file('image')) : 'def.png'; |
||||
$category->parent_id = $request->parent_id == null ? 0 : $request->parent_id; |
||||
$category->position = $request->position; |
||||
$category->save(); |
||||
|
||||
$data = []; |
||||
foreach($request->lang as $index=>$key) |
||||
{ |
||||
if($request->name[$index] && $key != 'en') |
||||
{ |
||||
array_push($data, Array( |
||||
'translationable_type' => 'App\Models\Category', |
||||
'translationable_id' => $category->id, |
||||
'locale' => $key, |
||||
'key' => 'name', |
||||
'value' => $request->name[$index], |
||||
)); |
||||
} |
||||
} |
||||
if(count($data)) |
||||
{ |
||||
Translation::insert($data); |
||||
} |
||||
|
||||
Toastr::success(translate('messages.category_added_successfully')); |
||||
return back(); |
||||
} |
||||
|
||||
public function edit($id) |
||||
{ |
||||
$category = Category::withoutGlobalScope('translate')->findOrFail($id); |
||||
return view('admin-views.category.edit', compact('category')); |
||||
} |
||||
|
||||
public function status(Request $request) |
||||
{ |
||||
$category = Category::find($request->id); |
||||
$category->status = $request->status; |
||||
$category->save(); |
||||
Toastr::success(translate('messages.category_status_updated')); |
||||
return back(); |
||||
} |
||||
|
||||
public function update(Request $request, $id) |
||||
{ |
||||
$request->validate([ |
||||
'name' => 'required|max:100|unique:categories,name,'.$id, |
||||
'image' => 'nullable|max:2048', |
||||
|
||||
]); |
||||
$category = Category::find($id); |
||||
$slug = Str::slug($request->name[array_search('en', $request->lang)]); |
||||
$category->slug = $category->slug? $category->slug :"{$slug}{$category->id}"; |
||||
|
||||
$category->name = $request->name[array_search('en', $request->lang)]; |
||||
$category->image = $request->has('image') ? Helpers::update('category/', $category->image, 'png', $request->file('image')) : $category->image; |
||||
$category->save(); |
||||
foreach($request->lang as $index=>$key) |
||||
{ |
||||
if($request->name[$index] && $key != 'en') |
||||
{ |
||||
Translation::updateOrInsert( |
||||
['translationable_type' => 'App\Models\Category', |
||||
'translationable_id' => $category->id, |
||||
'locale' => $key, |
||||
'key' => 'name'], |
||||
['value' => $request->name[$index]] |
||||
); |
||||
} |
||||
} |
||||
Toastr::success(translate('messages.category_updated_successfully')); |
||||
return back(); |
||||
} |
||||
|
||||
public function delete(Request $request) |
||||
{ |
||||
$category = Category::findOrFail($request->id); |
||||
if ($category->childes->count()==0){ |
||||
$category->delete(); |
||||
Toastr::success('Category removed!'); |
||||
}else{ |
||||
Toastr::warning(translate('messages.remove_sub_categories_first')); |
||||
} |
||||
return back(); |
||||
} |
||||
|
||||
public function get_all(Request $request){ |
||||
$data = Category::where('name', 'like', '%'.$request->q.'%')->limit(8)->get([DB::raw('id, CONCAT(name, " (", if(position = 0, "'.translate('messages.main').'", "'.translate('messages.sub').'"),")") as text')]); |
||||
if(isset($request->all)) |
||||
{ |
||||
$data[]=(object)['id'=>'all', 'text'=>'All']; |
||||
} |
||||
return response()->json($data); |
||||
} |
||||
|
||||
public function update_priority(Category $category, Request $request) |
||||
{ |
||||
$priority = $request->priority??0; |
||||
$category->priority = $priority; |
||||
$category->save(); |
||||
Toastr::success(translate('messages.category_priority_updated successfully')); |
||||
return back(); |
||||
|
||||
} |
||||
|
||||
public function bulk_import_index() |
||||
{ |
||||
return view('admin-views.category.bulk-import'); |
||||
} |
||||
|
||||
public function bulk_import_data(Request $request) |
||||
{ |
||||
try { |
||||
$collections = (new FastExcel)->import($request->file('products_file')); |
||||
} catch (\Exception $exception) { |
||||
Toastr::error(translate('messages.you_have_uploaded_a_wrong_format_file')); |
||||
return back(); |
||||
} |
||||
|
||||
$data = []; |
||||
foreach ($collections as $collection) { |
||||
if ($collection['name'] === "") { |
||||
Toastr::error(translate('messages.please_fill_all_required_fields')); |
||||
return back(); |
||||
} |
||||
$parent_id = is_numeric($collection['parent_id'])?$collection['parent_id']:0; |
||||
array_push($data, [ |
||||
'name' => $collection['name'], |
||||
'image' => $collection['image'], |
||||
'parent_id' => $parent_id, |
||||
'position' => $collection['position'], |
||||
'priority' => $collection['priority'], |
||||
'status' => empty($collection['status'])?1:$collection['status'], |
||||
'created_at'=>now(), |
||||
'updated_at'=>now() |
||||
]); |
||||
} |
||||
DB::table('categories')->insert($data); |
||||
Toastr::success(translate('messages.category_imported_successfully', ['count'=>count($data)])); |
||||
return back(); |
||||
} |
||||
|
||||
public function bulk_export_index() |
||||
{ |
||||
return view('admin-views.category.bulk-export'); |
||||
} |
||||
|
||||
public function bulk_export_data(Request $request) |
||||
{ |
||||
$request->validate([ |
||||
'type'=>'required', |
||||
'start_id'=>'required_if:type,id_wise', |
||||
'end_id'=>'required_if:type,id_wise', |
||||
'from_date'=>'required_if:type,date_wise', |
||||
'to_date'=>'required_if:type,date_wise' |
||||
]); |
||||
$categories = Category::when($request['type']=='date_wise', function($query)use($request){ |
||||
$query->whereBetween('created_at', [$request['from_date'].' 00:00:00', $request['to_date'].' 23:59:59']); |
||||
}) |
||||
->when($request['type']=='id_wise', function($query)use($request){ |
||||
$query->whereBetween('id', [$request['start_id'], $request['end_id']]); |
||||
}) |
||||
->get(); |
||||
return (new FastExcel(CategoryLogic::format_export_category($categories)))->download('Categories.xlsx'); |
||||
} |
||||
|
||||
public function search(Request $request){ |
||||
$key = explode(' ', $request['search']); |
||||
$categories=Category:: |
||||
when($request->sub_category, function($query){ |
||||
return $query->where('position','1'); |
||||
}) |
||||
->where(function ($q) use ($key) { |
||||
foreach ($key as $value) { |
||||
$q->orWhere('name', 'like', "%{$value}%"); |
||||
} |
||||
})->limit(50)->get(); |
||||
|
||||
if($request->sub_category) |
||||
{ |
||||
return response()->json([ |
||||
'view'=>view('admin-views.category.partials._sub_category_table',compact('categories'))->render(), |
||||
'count'=>$categories->count() |
||||
]); |
||||
} |
||||
return response()->json([ |
||||
'view'=>view('admin-views.category.partials._table',compact('categories'))->render(), |
||||
'count'=>$categories->count() |
||||
]); |
||||
} |
||||
|
||||
public function export_categories($type){ |
||||
$collection = Category::where('position','0')->orderBy('id','desc')->get(); |
||||
|
||||
if($type == 'excel'){ |
||||
return (new FastExcel(Helpers::export_categories($collection)))->download('Categories.xlsx'); |
||||
}elseif($type == 'csv'){ |
||||
return (new FastExcel(Helpers::export_categories($collection)))->download('Categories.csv'); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,113 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Admin; |
||||
|
||||
use Illuminate\Http\Request; |
||||
use App\Models\ContactMessage; |
||||
use App\CentralLogics\Helpers; |
||||
use App\Http\Controllers\Controller; |
||||
use Brian2694\Toastr\Facades\Toastr; |
||||
use Illuminate\Support\Facades\Mail; |
||||
|
||||
class ContactMessages extends Controller |
||||
{ |
||||
// public function store(Request $request) |
||||
// { |
||||
// $request->validate([ |
||||
// 'mobile_number' => 'required', |
||||
// 'subject' => 'required', |
||||
// 'message' => 'required', |
||||
// ], [ |
||||
// 'mobile_number.required' => 'Mobile Number is Empty!', |
||||
// 'subject.required' => ' Subject is Empty!', |
||||
// 'message.required' => 'Message is Empty!', |
||||
|
||||
// ]); |
||||
// $contact = new ContactMessage(); |
||||
// $contact->name = $request->name; |
||||
// $contact->email = $request->email; |
||||
// $contact->mobile_number = $request->mobile_number; |
||||
// $contact->subject = $request->subject; |
||||
// $contact->message = $request->message; |
||||
// $contact->save(); |
||||
|
||||
// return response()->json(['success' => 'Your Message Send Successfully']); |
||||
// } |
||||
|
||||
public function list(Request $request) |
||||
{ |
||||
$query_param = []; |
||||
$search = $request['search']; |
||||
if ($request->has('search')) |
||||
{ |
||||
$key = explode(' ', $request['search']); |
||||
$contacts = ContactMessage::where(function ($q) use ($key) { |
||||
foreach ($key as $value) { |
||||
$q->orWhere('name', 'like', "%{$value}%") |
||||
->orWhere('email', 'like', "%{$value}%") |
||||
->orWhere('mobile_number', 'like', "%{$value}%"); |
||||
} |
||||
}); |
||||
$query_param = ['search' => $request['search']]; |
||||
}else{ |
||||
$contacts = new ContactMessage(); |
||||
} |
||||
$contacts = $contacts->latest()->paginate(config('default_pagination')); |
||||
return view('admin-views.contacts.list', compact('contacts','search')); |
||||
|
||||
} |
||||
|
||||
public function view($id) |
||||
{ |
||||
$contact = ContactMessage::findOrFail($id); |
||||
return view('admin-views.contacts.view', compact('contact')); |
||||
} |
||||
|
||||
// public function update(Request $request, $id) |
||||
// { |
||||
// $contact = ContactMessage::find($id); |
||||
// $contact->feedback = $request->feedback; |
||||
// $contact->seen = 1; |
||||
// $contact->update(); |
||||
// Toastr::success('Feedback Update successfully!'); |
||||
// return redirect()->route('admin.contact.list'); |
||||
// } |
||||
|
||||
public function destroy(Request $request) |
||||
{ |
||||
$contact = ContactMessage::find($request->id); |
||||
$contact->delete(); |
||||
Toastr::success('Message Delete successfully!'); |
||||
return redirect()->route('admin.contact.list'); |
||||
} |
||||
|
||||
public function send_mail(Request $request, $id) |
||||
{ |
||||
$contact = ContactMessage::findOrFail($id); |
||||
$data = array('body' => $request['mail_body'], |
||||
'name' => $contact->name |
||||
); |
||||
$business_name=Helpers::get_settings('business_name') ?? 'Stackfood'; |
||||
|
||||
try { |
||||
Mail::send('email-templates.customer-message', $data, function ($message) use ($contact,$business_name, $request) { |
||||
$message->to($contact['email'], $business_name) |
||||
->subject($request['subject']); |
||||
}); |
||||
|
||||
$contact->update([ |
||||
'reply' => json_encode([ |
||||
'subject' => $request['subject'], |
||||
'body' => $request['mail_body'] |
||||
]), |
||||
'seen'=>1, |
||||
]); |
||||
Toastr::success(translate('messages.Mail_sent_successfully')); |
||||
return back(); |
||||
} catch (\Throwable $th) { |
||||
Toastr::error(translate('messages.Something_went_wrong_please_check_your_mail_config')); |
||||
return back(); |
||||
} |
||||
|
||||
} |
||||
} |
@ -0,0 +1,174 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Admin; |
||||
|
||||
use App\Http\Controllers\Controller; |
||||
use App\CentralLogics\Helpers; |
||||
use App\Models\Conversation; |
||||
use App\Models\UserInfo; |
||||
use App\Models\Message; |
||||
use App\Models\User; |
||||
use App\Models\Admin; |
||||
use Carbon\Carbon; |
||||
use Illuminate\Http\Request; |
||||
use Illuminate\Support\Facades\DB; |
||||
use Illuminate\Support\Facades\Validator; |
||||
|
||||
class ConversationController extends Controller |
||||
{ |
||||
public function list(Request $request) |
||||
{ |
||||
$conversations = Conversation::with(['sender', 'receiver', 'last_message'])->WhereUserType('admin'); |
||||
if($request->query('key')) { |
||||
$key = explode(' ', $request->get('key')); |
||||
$conversations = $conversations->where(function($qu)use($key){ |
||||
$qu->whereHas('sender',function($query)use($key){ |
||||
foreach ($key as $value) { |
||||
$query->where('f_name', 'like', "%{$value}%")->orWhere('l_name', 'like', "%{$value}%")->orWhere('phone', 'like', "%{$value}%"); |
||||
} |
||||
}) |
||||
->orWhereHas('receiver',function($query1)use($key){ |
||||
foreach ($key as $value) { |
||||
$query1->where('f_name', 'like', "%{$value}%")->orWhere('l_name', 'like', "%{$value}%")->orWhere('phone', 'like', "%{$value}%"); |
||||
} |
||||
}); |
||||
}); |
||||
} |
||||
$conversations = $conversations->orderBy('last_message_time', 'DESC') |
||||
->paginate(8); |
||||
|
||||
if ($request->ajax()) { |
||||
$view = view('admin-views.messages.data',compact('conversations'))->render(); |
||||
return response()->json(['html'=>$view]); |
||||
} |
||||
|
||||
return view('admin-views.messages.index', compact('conversations')); |
||||
} |
||||
|
||||
public function view($conversation_id,$user_id) |
||||
{ |
||||
$conversation = Conversation::find($conversation_id); |
||||
$lastmessage = $conversation->last_message; |
||||
if($lastmessage && $lastmessage->sender_id == $user_id ) { |
||||
$conversation->unread_message_count = 0; |
||||
$conversation->save(); |
||||
} |
||||
Message::where(['conversation_id' => $conversation->id])->where('sender_id','!=',$user_id)->update(['is_seen' => 1]); |
||||
$convs = Message::where(['conversation_id' => $conversation_id])->get(); |
||||
$receiver = UserInfo::find($user_id); |
||||
// $user = User::find($receiver->user_id); |
||||
$user = $receiver; |
||||
return response()->json([ |
||||
'view' => view('admin-views.messages.partials._conversations', compact('convs', 'user', 'receiver'))->render() |
||||
]); |
||||
} |
||||
|
||||
public function store(Request $request, $user_id) |
||||
{ |
||||
|
||||
|
||||
if ($request->has('images')) { |
||||
$validator = Validator::make($request->all(), [ |
||||
'images.*' => 'max:2048', |
||||
]); |
||||
|
||||
if ($validator->fails()) { |
||||
$validator->getMessageBag()->add('images', 'Max Image Upload limit is 2mb'); |
||||
return response()->json(['errors' => Helpers::error_processor($validator)]); |
||||
} |
||||
$image_name=[]; |
||||
foreach($request->images as $key=>$img) |
||||
{ |
||||
$name = Helpers::upload('conversation/', 'png', $img); |
||||
array_push($image_name,$name); |
||||
} |
||||
} else { |
||||
$image_name = null; |
||||
$validator = Validator::make($request->all(), [ |
||||
'reply' => 'required', |
||||
]); |
||||
|
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)]); |
||||
} |
||||
} |
||||
|
||||
|
||||
$admin = Admin::find(auth('admin')->id()); |
||||
$sender = UserInfo::where('admin_id',$admin->id)->first(); |
||||
if(!$sender){ |
||||
$sender = new UserInfo(); |
||||
$sender->admin_id = $admin->id; |
||||
$sender->f_name = $admin->f_name; |
||||
$sender->l_name = $admin->l_name; |
||||
$sender->phone = $admin->phone; |
||||
$sender->email = $admin->email; |
||||
$sender->image = $admin->image; |
||||
$sender->save(); |
||||
} |
||||
|
||||
$user = User::find($user_id); |
||||
$fcm_token=$user->cm_firebase_token; |
||||
$receiver = UserInfo::where('user_id', $user->id)->first(); |
||||
$user = $receiver; |
||||
if(!$receiver){ |
||||
$receiver = new UserInfo(); |
||||
$receiver->user_id = $user->id; |
||||
$receiver->f_name = $user->f_name; |
||||
$receiver->l_name = $user->l_name; |
||||
$receiver->phone = $user->phone; |
||||
$receiver->email = $user->email; |
||||
$receiver->image = $user->image; |
||||
$receiver->save(); |
||||
} |
||||
|
||||
$conversation = Conversation::where(['sender_id' => $receiver->id, 'receiver_id' => 0])->orWhere(['sender_id' => 0, 'receiver_id' => $receiver->id])->first(); |
||||
|
||||
|
||||
if(!$conversation){ |
||||
$conversation = new Conversation; |
||||
$conversation->sender_id = 0; |
||||
$conversation->sender_type = 'admin'; |
||||
$conversation->receiver_id = $receiver->id; |
||||
$conversation->receiver_type = 'user'; |
||||
$conversation->last_message_time = Carbon::now()->toDateTimeString(); |
||||
$conversation->save(); |
||||
|
||||
$conversation= Conversation::find($conversation->id); |
||||
} |
||||
|
||||
$message = new Message(); |
||||
$message->conversation_id = $conversation->id; |
||||
$message->sender_id = $sender->id; |
||||
$message->message = $request->reply; |
||||
$message->file = $image_name?json_encode($image_name, JSON_UNESCAPED_SLASHES):null; |
||||
try { |
||||
if($message->save()) |
||||
$conversation->unread_message_count = $conversation->unread_message_count? $conversation->unread_message_count+1:1; |
||||
$conversation->last_message_id=$message->id; |
||||
$conversation->last_message_time = Carbon::now()->toDateTimeString(); |
||||
$conversation->save(); |
||||
{ |
||||
$data = [ |
||||
'title' =>translate('messages.message'), |
||||
'description' =>translate('messages.message_description'), |
||||
'order_id' => '', |
||||
'image' => '', |
||||
'message' => json_encode($message), |
||||
'type'=> 'message', |
||||
'conversation_id'=> $conversation->id, |
||||
'sender_type'=> 'admin' |
||||
]; |
||||
Helpers::send_push_notif_to_device($fcm_token, $data); |
||||
} |
||||
|
||||
} catch (\Exception $e) { |
||||
info($e); |
||||
} |
||||
|
||||
$convs = Message::where(['conversation_id' => $conversation->id])->get(); |
||||
return response()->json([ |
||||
'view' => view('admin-views.messages.partials._conversations', compact('convs', 'user', 'receiver'))->render() |
||||
]); |
||||
} |
||||
} |
@ -0,0 +1,153 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Admin; |
||||
|
||||
use App\Http\Controllers\Controller; |
||||
use App\Models\Coupon; |
||||
use Brian2694\Toastr\Facades\Toastr; |
||||
use Illuminate\Http\Request; |
||||
use Illuminate\Support\Facades\DB; |
||||
|
||||
class CouponController extends Controller |
||||
{ |
||||
public function add_new(Request $request) |
||||
{ |
||||
$key = explode(' ', $request['search']); |
||||
$coupons = Coupon::where('created_by','admin') |
||||
->when(isset($key), function($query)use($key){ |
||||
$query->where( function ($q) use ($key) { |
||||
foreach ($key as $value) { |
||||
$q->orWhere('title', 'like', "%{$value}%") |
||||
->orWhere('code', 'like', "%{$value}%"); |
||||
} |
||||
}); |
||||
}) |
||||
->latest()->paginate(config('default_pagination')); |
||||
return view('admin-views.coupon.index', compact('coupons')); |
||||
} |
||||
|
||||
public function store(Request $request) |
||||
{ |
||||
$request->validate([ |
||||
'code' => 'required|unique:coupons|max:100', |
||||
'title' => 'required|max:191', |
||||
'start_date' => 'required', |
||||
'expire_date' => 'required', |
||||
'discount' => 'required', |
||||
'coupon_type' => 'required|in:zone_wise,restaurant_wise,free_delivery,first_order,default', |
||||
'zone_ids' => 'required_if:coupon_type,zone_wise', |
||||
'restaurant_ids' => 'required_if:coupon_type,restaurant_wise' |
||||
]); |
||||
$data = ''; |
||||
$customer_id = $request->customer_ids ?? ['all']; |
||||
if($request->coupon_type == 'zone_wise') |
||||
{ |
||||
$data = $request->zone_ids; |
||||
} |
||||
else if($request->coupon_type == 'restaurant_wise') |
||||
{ |
||||
$data = $request->restaurant_ids; |
||||
} |
||||
|
||||
DB::table('coupons')->insert([ |
||||
'title' => $request->title, |
||||
'code' => $request->code, |
||||
'limit' => $request->coupon_type=='first_order'?1:$request->limit, |
||||
'coupon_type' => $request->coupon_type, |
||||
'start_date' => $request->start_date, |
||||
'expire_date' => $request->expire_date, |
||||
'min_purchase' => $request->min_purchase != null ? $request->min_purchase : 0, |
||||
'max_discount' => $request->max_discount != null ? $request->max_discount : 0, |
||||
'discount' => $request->discount_type == 'amount' ? $request->discount : $request['discount'], |
||||
'discount_type' => $request->discount_type??'', |
||||
'status' => 1, |
||||
'created_by' => 'admin', |
||||
'data' => json_encode($data), |
||||
'customer_id' => json_encode($customer_id), |
||||
'created_at' => now(), |
||||
'updated_at' => now() |
||||
]); |
||||
|
||||
Toastr::success(translate('messages.coupon_added_successfully')); |
||||
return back(); |
||||
} |
||||
|
||||
public function edit($id) |
||||
{ |
||||
$coupon = Coupon::where(['id' => $id])->first(); |
||||
// dd(json_decode($coupon->data)); |
||||
return view('admin-views.coupon.edit', compact('coupon')); |
||||
} |
||||
|
||||
public function update(Request $request, $id) |
||||
{ |
||||
$request->validate([ |
||||
'code' => 'required|max:100|unique:coupons,code,'.$id, |
||||
'title' => 'required|max:191', |
||||
'start_date' => 'required', |
||||
'expire_date' => 'required', |
||||
'discount' => 'required', |
||||
'zone_ids' => 'required_if:coupon_type,zone_wise', |
||||
'restaurant_ids' => 'required_if:coupon_type,restaurant_wise' |
||||
]); |
||||
$data = ''; |
||||
if($request->coupon_type == 'zone_wise') |
||||
{ |
||||
$data = $request->zone_ids; |
||||
} |
||||
else if($request->coupon_type == 'restaurant_wise') |
||||
{ |
||||
$data = $request->restaurant_ids; |
||||
} |
||||
$customer_id = $request->customer_ids ?? ['all']; |
||||
DB::table('coupons')->where(['id' => $id])->update([ |
||||
'title' => $request->title, |
||||
'code' => $request->code, |
||||
'limit' => $request->coupon_type=='first_order'?1:$request->limit, |
||||
'coupon_type' => $request->coupon_type, |
||||
'start_date' => $request->start_date, |
||||
'expire_date' => $request->expire_date, |
||||
'min_purchase' => $request->min_purchase != null ? $request->min_purchase : 0, |
||||
'max_discount' => $request->max_discount != null ? $request->max_discount : 0, |
||||
'discount' => $request->discount_type == 'amount' ? $request->discount : $request['discount'], |
||||
'discount_type' => $request->discount_type??'', |
||||
'data' => json_encode($data), |
||||
'customer_id' => json_encode($customer_id), |
||||
'updated_at' => now() |
||||
]); |
||||
|
||||
Toastr::success(translate('messages.coupon_updated_successfully')); |
||||
return redirect()->route('admin.coupon.add-new'); |
||||
} |
||||
|
||||
public function status(Request $request) |
||||
{ |
||||
$coupon = Coupon::find($request->id); |
||||
$coupon->status = $request->status; |
||||
$coupon->save(); |
||||
Toastr::success(translate('messages.coupon_status_updated')); |
||||
return back(); |
||||
} |
||||
|
||||
public function delete(Request $request) |
||||
{ |
||||
$coupon = Coupon::find($request->id); |
||||
$coupon->delete(); |
||||
Toastr::success(translate('messages.coupon_deleted_successfully')); |
||||
return back(); |
||||
} |
||||
|
||||
// public function search(Request $request){ |
||||
// $key = explode(' ', $request['search']); |
||||
// $coupons=Coupon::where(function ($q) use ($key) { |
||||
// foreach ($key as $value) { |
||||
// $q->orWhere('title', 'like', "%{$value}%") |
||||
// ->orWhere('code', 'like', "%{$value}%"); |
||||
// } |
||||
// })->where('created_by','admin')->limit(50)->get(); |
||||
// return response()->json([ |
||||
// 'view'=>view('admin-views.coupon.partials._table',compact('coupons'))->render(), |
||||
// 'count'=>$coupons->count() |
||||
// ]); |
||||
// } |
||||
} |
@ -0,0 +1,106 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Admin; |
||||
|
||||
use App\Models\Cuisine; |
||||
use Illuminate\Support\Str; |
||||
use Illuminate\Http\Request; |
||||
use App\CentralLogics\Helpers; |
||||
use App\Http\Controllers\Controller; |
||||
use Brian2694\Toastr\Facades\Toastr; |
||||
use Illuminate\Support\Facades\Storage; |
||||
|
||||
class CuisineController extends Controller |
||||
{ |
||||
/** |
||||
* Display a listing of the resource. |
||||
* |
||||
* @return \Illuminate\Http\Response |
||||
*/ |
||||
public function index(Request $request) |
||||
{ |
||||
|
||||
$key = explode(' ', $request['search']); |
||||
$cuisine = Cuisine::when(isset($key) ,function ($q) use ($key) { |
||||
foreach ($key as $value) { |
||||
$q->where('name', 'like', "%{$value}%"); |
||||
} |
||||
})->latest()->paginate(config('default_pagination')); |
||||
return view('admin-views.cuisine.index',compact('cuisine')); |
||||
} |
||||
|
||||
|
||||
|
||||
/** |
||||
* Store a newly created resource in storage. |
||||
* |
||||
* @param \Illuminate\Http\Request $request |
||||
* @return \Illuminate\Http\Response |
||||
*/ |
||||
public function store(Request $request) |
||||
{ |
||||
$request->validate([ |
||||
'name' => 'required|unique:cuisines|max:100', |
||||
'image' => 'nullable|max:2048', |
||||
], [ |
||||
'name.required' => translate('messages.Name is required!'), |
||||
]); |
||||
|
||||
$cuisine = new Cuisine(); |
||||
$cuisine->name = $request->name; |
||||
$cuisine->image = $request->has('image') ? Helpers::upload('cuisine/', 'png', $request->file('image')) : 'def.png'; |
||||
$cuisine->save(); |
||||
|
||||
Toastr::success(translate('messages.Cuisine_added_successfully')); |
||||
return back(); |
||||
} |
||||
|
||||
|
||||
public function update(Request $request) |
||||
{ |
||||
$request->validate([ |
||||
'name' => 'required|max:100|unique:cuisines,name,'.$request->id, |
||||
'image' => 'nullable|max:2048', |
||||
], [ |
||||
'name.required' => translate('messages.Name is required!'), |
||||
]); |
||||
$cuisine = Cuisine::find($request->id); |
||||
$cuisine->name = $request->name; |
||||
|
||||
$slug = Str::slug($request->name); |
||||
$cuisine->slug = $cuisine->slug? $cuisine->slug :"{$slug}-{$cuisine->id}"; |
||||
|
||||
$cuisine->image = $request->has('image') ? Helpers::update('cuisine/', $cuisine->image, 'png', $request->file('image')) : $cuisine->image; |
||||
$cuisine->save(); |
||||
|
||||
Toastr::success(translate('messages.Cuisine_updated_successfully')); |
||||
return back(); |
||||
} |
||||
|
||||
|
||||
public function status(Request $request) |
||||
{ |
||||
$cuisine = Cuisine::find($request->id); |
||||
$cuisine->status = $request->status; |
||||
$cuisine->save(); |
||||
Toastr::success(translate('messages.Cuisine_status_updated')); |
||||
return back(); |
||||
} |
||||
/** |
||||
* Remove the specified resource from storage. |
||||
* |
||||
* @param \App\Models\Cuisine $cuisine |
||||
* @return \Illuminate\Http\Response |
||||
*/ |
||||
public function destroy(Request $request) |
||||
{ |
||||
// dd(request()->all()); |
||||
$cuisine = Cuisine::findOrFail($request->id); |
||||
if (Storage::disk('public')->exists('cuisine/' . $cuisine['image'])) { |
||||
Storage::disk('public')->delete('cuisine/' . $cuisine['image']); |
||||
} |
||||
$cuisine->delete(); |
||||
Toastr::success('cuisine removed!'); |
||||
return back(); |
||||
} |
||||
} |
@ -0,0 +1,108 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Admin; |
||||
|
||||
use App\Http\Controllers\Controller; |
||||
use App\Models\AdminRole; |
||||
use Brian2694\Toastr\Facades\Toastr; |
||||
use Illuminate\Http\Request; |
||||
use Illuminate\Support\Facades\DB; |
||||
use Rap2hpoutre\FastExcel\FastExcel; |
||||
|
||||
class CustomRoleController extends Controller |
||||
{ |
||||
public function create() |
||||
{ |
||||
$rl=AdminRole::whereNotIn('id',[1])->latest()->paginate(config('default_pagination')); |
||||
return view('admin-views.custom-role.create',compact('rl')); |
||||
} |
||||
|
||||
public function store(Request $request) |
||||
{ |
||||
$request->validate([ |
||||
'name' => 'required|unique:admin_roles|max:191', |
||||
'modules'=>'required|array|min:1' |
||||
],[ |
||||
'name.required'=>translate('messages.Role name is required!'), |
||||
'modules.required'=>translate('messages.Please select atleast one module') |
||||
]); |
||||
DB::table('admin_roles')->insert([ |
||||
'name'=>$request->name, |
||||
'modules'=>json_encode($request['modules']), |
||||
'status'=>1, |
||||
'created_at'=>now(), |
||||
'updated_at'=>now() |
||||
]); |
||||
|
||||
Toastr::success(translate('messages.role_added_successfully')); |
||||
return back(); |
||||
} |
||||
|
||||
public function edit($id) |
||||
{ |
||||
if($id == 1) |
||||
{ |
||||
return view('errors.404'); |
||||
} |
||||
$role=AdminRole::where(['id'=>$id])->first(['id','name','modules']); |
||||
return view('admin-views.custom-role.edit',compact('role')); |
||||
} |
||||
|
||||
public function update(Request $request,$id) |
||||
{ |
||||
if($id == 1) |
||||
{ |
||||
return view('errors.404'); |
||||
} |
||||
$request->validate([ |
||||
'name' => 'required|max:191|unique:admin_roles,name,'.$id, |
||||
'modules'=>'required|array|min:1' |
||||
],[ |
||||
'name.required'=>translate('messages.Role name is required!'), |
||||
'modules.required'=>translate('messages.Please select atleast one module') |
||||
]); |
||||
|
||||
DB::table('admin_roles')->where(['id'=>$id])->update([ |
||||
'name'=>$request->name, |
||||
'modules'=>json_encode($request['modules']), |
||||
'status'=>1, |
||||
'updated_at'=>now() |
||||
]); |
||||
|
||||
Toastr::success(translate('messages.role_updated_successfully')); |
||||
return redirect()->route('admin.custom-role.create'); |
||||
} |
||||
public function distroy($id) |
||||
{ |
||||
if($id == 1) |
||||
{ |
||||
return view('errors.404'); |
||||
} |
||||
$role=AdminRole::where(['id'=>$id])->delete(); |
||||
Toastr::success(translate('messages.role_deleted_successfully')); |
||||
return back(); |
||||
} |
||||
|
||||
public function search(Request $request){ |
||||
$key = explode(' ', $request['search']); |
||||
$rl=AdminRole::where('id','!=','1') |
||||
->where(function ($q) use ($key) { |
||||
foreach ($key as $value) { |
||||
$q->orWhere('name', 'like', "%{$value}%"); |
||||
} |
||||
})->latest()->limit(50)->get(); |
||||
return response()->json([ |
||||
'view'=>view('admin-views.custom-role.partials._table',compact('rl'))->render(), |
||||
'count'=>$rl->count() |
||||
]); |
||||
} |
||||
|
||||
public function employee_role_export(Request $request){ |
||||
$withdraw_request = AdminRole::whereNotIn('id',[1])->get(); |
||||
if($request->type == 'excel'){ |
||||
return (new FastExcel($withdraw_request))->download('CustomRole.xlsx'); |
||||
}elseif($request->type == 'csv'){ |
||||
return (new FastExcel($withdraw_request))->download('CustomRole.csv'); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,209 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Admin; |
||||
|
||||
use App\Http\Controllers\Controller; |
||||
use App\Models\Order; |
||||
use App\Models\User; |
||||
use Brian2694\Toastr\Facades\Toastr; |
||||
use Illuminate\Http\Request; |
||||
use Illuminate\Support\Facades\DB; |
||||
use App\CentralLogics\Helpers; |
||||
use App\Models\BusinessSetting; |
||||
use App\Models\Newsletter; |
||||
|
||||
class CustomerController extends Controller |
||||
{ |
||||
public function customer_list(Request $request) |
||||
{ |
||||
$key = []; |
||||
if($request->search) |
||||
{ |
||||
$key = explode(' ', $request['search']); |
||||
} |
||||
$customers = User:: |
||||
when(count($key) > 0, function($query)use($key){ |
||||
foreach ($key as $value) { |
||||
$query->orWhere('f_name', 'like', "%{$value}%") |
||||
->orWhere('l_name', 'like', "%{$value}%") |
||||
->orWhere('email', 'like', "%{$value}%") |
||||
->orWhere('phone', 'like', "%{$value}%"); |
||||
}; |
||||
}) |
||||
->orderBy('order_count','desc')->paginate(config('default_pagination')); |
||||
return view('admin-views.customer.list', compact('customers')); |
||||
} |
||||
|
||||
public function status(User $customer, Request $request) |
||||
{ |
||||
$customer->status = $request->status; |
||||
$customer->save(); |
||||
|
||||
try |
||||
{ |
||||
if($request->status == 0) |
||||
{ $customer->tokens->each(function ($token, $key) { |
||||
$token->delete(); |
||||
}); |
||||
if(isset($customer->cm_firebase_token)) |
||||
{ |
||||
$data = [ |
||||
'title' => translate('messages.suspended'), |
||||
'description' => translate('messages.your_account_has_been_blocked'), |
||||
'order_id' => '', |
||||
'image' => '', |
||||
'type'=> 'block' |
||||
]; |
||||
Helpers::send_push_notif_to_device($customer->cm_firebase_token, $data); |
||||
|
||||
DB::table('user_notifications')->insert([ |
||||
'data'=> json_encode($data), |
||||
'user_id'=>$customer->id, |
||||
'created_at'=>now(), |
||||
'updated_at'=>now() |
||||
]); |
||||
} |
||||
|
||||
} |
||||
|
||||
} |
||||
catch (\Exception $e) { |
||||
Toastr::warning(translate('messages.push_notification_faild')); |
||||
} |
||||
|
||||
Toastr::success(translate('messages.customer').translate('messages.status_updated')); |
||||
return back(); |
||||
} |
||||
|
||||
public function search(Request $request){ |
||||
$key = explode(' ', $request['search']); |
||||
$customers=User::where(function ($q) use ($key) { |
||||
foreach ($key as $value) { |
||||
$q->orWhere('f_name', 'like', "%{$value}%") |
||||
->orWhere('l_name', 'like', "%{$value}%") |
||||
->orWhere('email', 'like', "%{$value}%") |
||||
->orWhere('phone', 'like', "%{$value}%"); |
||||
} |
||||
})->orderBy('order_count','desc')->limit(50)->get(); |
||||
return response()->json([ |
||||
'view'=>view('admin-views.customer.partials._table',compact('customers'))->render() |
||||
]); |
||||
} |
||||
public function order_search(Request $request){ |
||||
$key = explode(' ', $request['search']); |
||||
$customer = User::find($request->id); |
||||
|
||||
$orders=Order::where(['user_id' => $customer->id])->Notpos()-> |
||||
where(function ($q) use ($key) { |
||||
foreach ($key as $value) { |
||||
$q->Where('id', 'like', "%{$value}%"); |
||||
} |
||||
}) |
||||
->paginate(config('default_pagination')); |
||||
// ->limit(50)->get(); |
||||
$total=$orders->total(); |
||||
return response()->json([ |
||||
'view'=>view('admin-views.customer.partials._list_table',compact('customer', 'orders'))->render() ,'total' => $total |
||||
]); |
||||
} |
||||
|
||||
public function view($id) |
||||
{ |
||||
$customer = User::find($id); |
||||
if (isset($customer)) { |
||||
$orders = Order::latest()->where(['user_id' => $id])->Notpos()->paginate(config('default_pagination')); |
||||
return view('admin-views.customer.customer-view', compact('customer', 'orders')); |
||||
} |
||||
Toastr::error(translate('messages.customer_not_found')); |
||||
return back(); |
||||
} |
||||
|
||||
public function get_customers(Request $request){ |
||||
$key = explode(' ', $request['q']); |
||||
$data = User:: |
||||
where(function ($q) use ($key) { |
||||
foreach ($key as $value) { |
||||
$q->orWhere('f_name', 'like', "%{$value}%") |
||||
->orWhere('l_name', 'like', "%{$value}%") |
||||
->orWhere('phone', 'like', "%{$value}%"); |
||||
} |
||||
}) |
||||
->limit(8) |
||||
->get([DB::raw('id, CONCAT(f_name, " ", l_name, " (", phone ,")") as text')]); |
||||
if($request->all) $data[]=(object)['id'=>false, 'text'=>translate('messages.all')]; |
||||
|
||||
|
||||
return response()->json($data); |
||||
} |
||||
|
||||
public function settings() |
||||
{ |
||||
$data = BusinessSetting::where('key','like','wallet_%') |
||||
->orWhere('key','like','loyalty_%') |
||||
->orWhere('key','like','ref_earning_%') |
||||
->orWhere('key','like','ref_earning_%')->get(); |
||||
$data = array_column($data->toArray(), 'value','key'); |
||||
//dd($data); |
||||
return view('admin-views.customer.settings', compact('data')); |
||||
} |
||||
|
||||
public function update_settings(Request $request) |
||||
{ |
||||
|
||||
if (env('APP_MODE') == 'demo') { |
||||
Toastr::info(translate('messages.update_option_is_disable_for_demo')); |
||||
return back(); |
||||
} |
||||
|
||||
$request->validate([ |
||||
'add_fund_bonus'=>'nullable|numeric|max:100|min:0', |
||||
'loyalty_point_exchange_rate'=>'nullable|numeric', |
||||
'ref_earning_exchange_rate'=>'nullable|numeric', |
||||
]); |
||||
BusinessSetting::updateOrInsert(['key' => 'wallet_status'], [ |
||||
'value' => $request['customer_wallet']??0 |
||||
]); |
||||
BusinessSetting::updateOrInsert(['key' => 'loyalty_point_status'], [ |
||||
'value' => $request['customer_loyalty_point']??0 |
||||
]); |
||||
BusinessSetting::updateOrInsert(['key' => 'ref_earning_status'], [ |
||||
'value' => $request['ref_earning_status'] ?? 0 |
||||
]); |
||||
BusinessSetting::updateOrInsert(['key' => 'wallet_add_refund'], [ |
||||
'value' => $request['refund_to_wallet']??0 |
||||
]); |
||||
BusinessSetting::updateOrInsert(['key' => 'loyalty_point_exchange_rate'], [ |
||||
'value' => $request['loyalty_point_exchange_rate'] ?? 0 |
||||
]); |
||||
BusinessSetting::updateOrInsert(['key' => 'ref_earning_exchange_rate'], [ |
||||
'value' => $request['ref_earning_exchange_rate'] ?? 0 |
||||
]); |
||||
BusinessSetting::updateOrInsert(['key' => 'loyalty_point_item_purchase_point'], [ |
||||
'value' => $request['item_purchase_point']??0 |
||||
]); |
||||
BusinessSetting::updateOrInsert(['key' => 'loyalty_point_minimum_point'], [ |
||||
'value' => $request['minimun_transfer_point']??0 |
||||
]); |
||||
|
||||
Toastr::success(translate('messages.customer_settings_updated_successfully')); |
||||
return back(); |
||||
} |
||||
|
||||
public function subscribedCustomers() |
||||
{ |
||||
$subscribers = Newsletter::orderBy('id', 'desc')->paginate(config('default_pagination')); |
||||
return view('admin-views.customer.subscriber.list', compact('subscribers')); |
||||
} |
||||
public function subscriberMailSearch(Request $request) |
||||
{ |
||||
$key = explode(' ', $request['search']); |
||||
$customers = Newsletter::where(function ($q) use ($key) { |
||||
foreach ($key as $value) { |
||||
$q->orWhere('email', 'like', "%". $value."%"); |
||||
} |
||||
})->orderBy('id', 'desc')->get(); |
||||
return response()->json([ |
||||
'view' => view('admin-views.customer.partials._subscriber-email-table', compact('customers'))->render() |
||||
]); |
||||
} |
||||
} |
@ -0,0 +1,89 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Admin; |
||||
|
||||
use App\CentralLogics\CustomerLogic; |
||||
use App\CentralLogics\Helpers; |
||||
use App\Http\Controllers\Controller; |
||||
use App\Models\BusinessSetting; |
||||
use App\Models\WalletTransaction; |
||||
use Illuminate\Http\Request; |
||||
use Illuminate\Support\Facades\Validator; |
||||
use Brian2694\Toastr\Facades\Toastr; |
||||
use Illuminate\Support\Facades\Mail; |
||||
|
||||
class CustomerWalletController extends Controller |
||||
{ |
||||
public function add_fund_view() |
||||
{ |
||||
if(BusinessSetting::where('key','wallet_status')->first()->value != 1) |
||||
{ |
||||
Toastr::error(translate('messages.customer_wallet_disable_warning_admin')); |
||||
return back(); |
||||
} |
||||
return view('admin-views.customer.wallet.add_fund'); |
||||
} |
||||
|
||||
public function add_fund(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'customer_id'=>'exists:users,id', |
||||
'amount'=>'numeric|min:.01', |
||||
]); |
||||
|
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)]); |
||||
} |
||||
|
||||
$wallet_transaction = CustomerLogic::create_wallet_transaction($request->customer_id, $request->amount, 'add_fund_by_admin',$request->referance); |
||||
|
||||
if($wallet_transaction) |
||||
{ |
||||
try{ |
||||
if(config('mail.status')) { |
||||
Mail::to($wallet_transaction->user->email)->send(new \App\Mail\AddFundToWallet($wallet_transaction)); |
||||
} |
||||
}catch(\Exception $ex) |
||||
{ |
||||
info($ex); |
||||
} |
||||
|
||||
return response()->json([], 200); |
||||
} |
||||
|
||||
return response()->json(['errors'=>[ |
||||
'message'=>translate('messages.failed_to_create_transaction') |
||||
]], 200); |
||||
} |
||||
|
||||
public function report(Request $request) |
||||
{ |
||||
$data = WalletTransaction::selectRaw('sum(credit) as total_credit, sum(debit) as total_debit') |
||||
->when(($request->from && $request->to),function($query)use($request){ |
||||
$query->whereBetween('created_at', [$request->from.' 00:00:00', $request->to.' 23:59:59']); |
||||
}) |
||||
->when($request->transaction_type, function($query)use($request){ |
||||
$query->where('transaction_type',$request->transaction_type); |
||||
}) |
||||
->when($request->customer_id, function($query)use($request){ |
||||
$query->where('user_id',$request->customer_id); |
||||
}) |
||||
->get(); |
||||
|
||||
$transactions = WalletTransaction:: |
||||
when(($request->from && $request->to),function($query)use($request){ |
||||
$query->whereBetween('created_at', [$request->from.' 00:00:00', $request->to.' 23:59:59']); |
||||
}) |
||||
->when($request->transaction_type, function($query)use($request){ |
||||
$query->where('transaction_type',$request->transaction_type); |
||||
}) |
||||
->when($request->customer_id, function($query)use($request){ |
||||
$query->where('user_id',$request->customer_id); |
||||
}) |
||||
->whereNull('delivery_man_id') |
||||
->latest() |
||||
->paginate(config('default_pagination')); |
||||
|
||||
return view('admin-views.customer.wallet.report', compact('data','transactions')); |
||||
} |
||||
} |
@ -0,0 +1,313 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Admin; |
||||
|
||||
use App\Http\Controllers\Controller; |
||||
use App\Models\DeliveryMan; |
||||
use App\Models\Food; |
||||
use App\Models\Order; |
||||
use App\Models\Restaurant; |
||||
use App\Models\User; |
||||
use App\Models\Wishlist; |
||||
use App\Models\OrderTransaction; |
||||
use App\Models\SubscriptionTransaction; |
||||
use Carbon\Carbon; |
||||
use Illuminate\Http\Request; |
||||
use Illuminate\Support\Facades\DB; |
||||
|
||||
class DashboardController extends Controller |
||||
{ |
||||
public function dashboard(Request $request) |
||||
{ |
||||
$params = [ |
||||
'zone_id' => $request['zone_id'] ?? 'all', |
||||
'statistics_type' => $request['statistics_type'] ?? 'overall', |
||||
'user_overview' => $request['user_overview'] ?? 'overall', |
||||
'business_overview' => $request['business_overview'] ?? 'overall', |
||||
]; |
||||
session()->put('dash_params', $params); |
||||
$data = self::dashboard_data(); |
||||
$total_sell = $data['total_sell']; |
||||
$total_subs = $data['total_subs']; |
||||
$commission = $data['commission']; |
||||
return view('admin-views.dashboard', compact('data', 'total_sell','total_subs' ,'commission', 'params')); |
||||
} |
||||
|
||||
public function order(Request $request) |
||||
{ |
||||
$params = session('dash_params'); |
||||
foreach ($params as $key => $value) { |
||||
if ($key == 'statistics_type') { |
||||
$params['statistics_type'] = $request['statistics_type']; |
||||
} |
||||
} |
||||
session()->put('dash_params', $params); |
||||
|
||||
if ($params['zone_id'] != 'all') { |
||||
$restaurant_ids = Restaurant::where(['zone_id' => $params['zone_id']])->pluck('id')->toArray(); |
||||
} else { |
||||
$restaurant_ids = Restaurant::pluck('id')->toArray(); |
||||
} |
||||
$data = self::order_stats_calc($params['zone_id']); |
||||
return response()->json([ |
||||
'view' => view('admin-views.partials._dashboard-order-stats', compact('data'))->render(), |
||||
'order_stats_top' => view('admin-views.partials._order-statics', compact('data'))->render() |
||||
], 200); |
||||
} |
||||
|
||||
public function zone(Request $request) |
||||
{ |
||||
$params = session('dash_params'); |
||||
foreach ($params as $key => $value) { |
||||
if ($key == 'zone_id') { |
||||
$params['zone_id'] = $request['zone_id']; |
||||
} |
||||
} |
||||
session()->put('dash_params', $params); |
||||
|
||||
$data = self::dashboard_data(); |
||||
$total_subs = $data['total_subs']; |
||||
$total_sell = $data['total_sell']; |
||||
$commission = $data['commission']; |
||||
$popular = $data['popular']; |
||||
$top_deliveryman = $data['top_deliveryman']; |
||||
$top_rated_foods = $data['top_rated_foods']; |
||||
$top_restaurants = $data['top_restaurants']; |
||||
$top_sell = $data['top_sell']; |
||||
|
||||
return response()->json([ |
||||
'popular_restaurants' => view('admin-views.partials._popular-restaurants', compact('popular'))->render(), |
||||
'top_deliveryman' => view('admin-views.partials._top-deliveryman', compact('top_deliveryman'))->render(), |
||||
'top_rated_foods' => view('admin-views.partials._top-rated-foods', compact('top_rated_foods'))->render(), |
||||
'top_restaurants' => view('admin-views.partials._top-restaurants', compact('top_restaurants'))->render(), |
||||
'top_selling_foods' => view('admin-views.partials._top-selling-foods', compact('top_sell'))->render(), |
||||
|
||||
'order_stats' => view('admin-views.partials._dashboard-order-stats', compact('data'))->render(), |
||||
'stat_zone' => view('admin-views.partials._zone-change', compact('data'))->render(), |
||||
'order_stats_top' => view('admin-views.partials._order-statics', compact('data'))->render(), |
||||
'user_overview' => view('admin-views.partials._user-overview-chart', compact('data'))->render(), |
||||
'monthly_graph' => view('admin-views.partials._monthly-earning-graph', compact('total_sell','total_subs', 'commission'))->render(), |
||||
], 200); |
||||
} |
||||
|
||||
public function user_overview(Request $request) |
||||
{ |
||||
$params = session('dash_params'); |
||||
foreach ($params as $key => $value) { |
||||
if ($key == 'user_overview') { |
||||
$params['user_overview'] = $request['user_overview']; |
||||
} |
||||
} |
||||
session()->put('dash_params', $params); |
||||
|
||||
$data = self::user_overview_calc($params['zone_id']); |
||||
|
||||
return response()->json([ |
||||
'view' => view('admin-views.partials._user-overview-chart', compact('data'))->render() |
||||
], 200); |
||||
} |
||||
|
||||
public function order_stats_calc($zone_id) |
||||
{ |
||||
$params = session('dash_params'); |
||||
|
||||
|
||||
if ($params['statistics_type'] == 'today') { |
||||
$searching_for_dm = Order::SearchingForDeliveryman()->whereDate('created_at', Carbon::now()); |
||||
$accepted_by_dm = Order::AccepteByDeliveryman()->whereDate('accepted', Carbon::now()); |
||||
$preparing_in_rs = Order::Preparing()->whereDate('processing', Carbon::now()); |
||||
$picked_up = Order::FoodOnTheWay()->whereDate('picked_up', Carbon::now()); |
||||
$delivered = Order::Delivered()->whereDate('delivered', Carbon::now()); |
||||
$canceled = Order::where(['order_status' => 'canceled'])->whereDate('canceled', Carbon::now()); |
||||
$refund_requested = Order::where(['order_status' => 'refund_requested'])->whereDate('refund_requested', Carbon::now()); |
||||
$refunded = Order::where(['order_status' => 'refunded'])->whereDate('refunded', Carbon::now()); |
||||
} else { |
||||
$searching_for_dm = Order::SearchingForDeliveryman(); |
||||
$accepted_by_dm = Order::AccepteByDeliveryman(); |
||||
$preparing_in_rs = Order::Preparing(); |
||||
$picked_up = Order::FoodOnTheWay(); |
||||
$delivered = Order::Delivered(); |
||||
$canceled = Order::Canceled(); |
||||
$refund_requested = Order::failed(); |
||||
$refunded = Order::Refunded(); |
||||
} |
||||
|
||||
if(is_numeric($zone_id)) |
||||
{ |
||||
$searching_for_dm = $searching_for_dm->Notpos()->OrderScheduledIn(30)->where('zone_id', $zone_id)->count(); |
||||
$accepted_by_dm = $accepted_by_dm->Notpos()->where('zone_id', $zone_id)->count(); |
||||
$preparing_in_rs = $preparing_in_rs->Notpos()->where('zone_id', $zone_id)->count(); |
||||
$picked_up = $picked_up->Notpos()->where('zone_id', $zone_id)->count(); |
||||
$delivered = $delivered->Notpos()->where('zone_id', $zone_id)->count(); |
||||
$canceled = $canceled->Notpos()->where('zone_id', $zone_id)->count(); |
||||
$refund_requested = $refund_requested->Notpos()->where('zone_id', $zone_id)->count(); |
||||
$refunded = $refunded->Notpos()->where('zone_id', $zone_id)->count(); |
||||
} |
||||
else |
||||
{ |
||||
$searching_for_dm = $searching_for_dm->Notpos()->OrderScheduledIn(30)->count(); |
||||
$accepted_by_dm = $accepted_by_dm->Notpos()->count(); |
||||
$preparing_in_rs = $preparing_in_rs->Notpos()->count(); |
||||
$picked_up = $picked_up->Notpos()->count(); |
||||
$delivered = $delivered->Notpos()->count(); |
||||
$canceled = $canceled->Notpos()->count(); |
||||
$refund_requested = $refund_requested->Notpos()->count(); |
||||
$refunded = $refunded->Notpos()->count(); |
||||
} |
||||
|
||||
|
||||
$data = [ |
||||
'searching_for_dm' => $searching_for_dm, |
||||
'accepted_by_dm' => $accepted_by_dm, |
||||
'preparing_in_rs' => $preparing_in_rs, |
||||
'picked_up' => $picked_up, |
||||
'delivered' => $delivered, |
||||
'canceled' => $canceled, |
||||
'refund_requested' => $refund_requested, |
||||
'refunded' => $refunded |
||||
]; |
||||
|
||||
|
||||
return $data; |
||||
|
||||
|
||||
} |
||||
|
||||
public function user_overview_calc($zone_id) |
||||
{ |
||||
$params = session('dash_params'); |
||||
//zone |
||||
if(is_numeric($zone_id)) |
||||
{ |
||||
$customer = User::where('zone_id', $zone_id); |
||||
$restaurants = Restaurant::where(['zone_id' => $zone_id]); |
||||
$delivery_man = DeliveryMan::where('zone_id', $zone_id)->Zonewise(); |
||||
} |
||||
else |
||||
{ |
||||
$customer = User::whereNotNull('id'); |
||||
$restaurants = Restaurant::whereNotNull('id'); |
||||
$delivery_man = DeliveryMan::Zonewise(); |
||||
} |
||||
//user overview |
||||
if ($params['user_overview'] == 'overall') { |
||||
$customer = $customer->count(); |
||||
$restaurants = $restaurants->count(); |
||||
$delivery_man = $delivery_man->count(); |
||||
} else { |
||||
$customer = $customer->whereMonth('created_at', date('m')) |
||||
->whereYear('created_at', date('Y'))->count(); |
||||
$restaurants = $restaurants->whereMonth('created_at', date('m')) |
||||
->whereYear('created_at', date('Y'))->count(); |
||||
$delivery_man = $delivery_man->whereMonth('created_at', date('m')) |
||||
->whereYear('created_at', date('Y'))->count(); |
||||
} |
||||
$data = [ |
||||
'customer' => $customer, |
||||
'restaurants' => $restaurants, |
||||
'delivery_man' => $delivery_man |
||||
]; |
||||
return $data; |
||||
} |
||||
|
||||
|
||||
public function dashboard_data() |
||||
{ |
||||
$params = session('dash_params'); |
||||
$data_os = self::order_stats_calc($params['zone_id']); |
||||
$data_uo = self::user_overview_calc($params['zone_id']); |
||||
|
||||
$popular = Wishlist::with(['restaurant']) |
||||
->whereHas('restaurant') |
||||
->when(is_numeric($params['zone_id']), function($q)use($params){ |
||||
return $q->whereHas('restaurant', function($query)use($params){ |
||||
return $query->where('zone_id', $params['zone_id']); |
||||
}); |
||||
}) |
||||
->select('restaurant_id', DB::raw('COUNT(restaurant_id) as count'))->groupBy('restaurant_id')->orderBy('count', 'DESC')->limit(6)->get(); |
||||
$top_sell = Food::withoutGlobalScopes() |
||||
->when(is_numeric($params['zone_id']),function($q)use($params){ |
||||
return $q->whereHas('restaurant', function($query)use($params){ |
||||
return $query->where('zone_id', $params['zone_id']); |
||||
}); |
||||
}) |
||||
->orderBy("order_count", 'desc') |
||||
->take(6) |
||||
->get(); |
||||
$top_rated_foods = Food::withoutGlobalScopes() |
||||
->when(is_numeric($params['zone_id']),function($q)use($params){ |
||||
return $q->whereHas('restaurant', function($query)use($params){ |
||||
return $query->where('zone_id', $params['zone_id']); |
||||
}); |
||||
}) |
||||
->orderBy('rating_count','desc') |
||||
->take(6) |
||||
->get(); |
||||
|
||||
$top_deliveryman = DeliveryMan:: |
||||
when(is_numeric($params['zone_id']), function($q)use($params){ |
||||
return $q->where('zone_id', $params['zone_id']); |
||||
}) |
||||
->where('type','zone_wise') |
||||
->orderBy("order_count", 'desc') |
||||
->take(6) |
||||
->get(); |
||||
|
||||
$top_restaurants = Restaurant:: |
||||
when(is_numeric($params['zone_id']), function($q)use($params){ |
||||
return $q->where('zone_id', $params['zone_id']); |
||||
}) |
||||
->orderBy("order_count", 'desc') |
||||
->take(6) |
||||
->get(); |
||||
|
||||
$total_sell = []; |
||||
$commission = []; |
||||
$total_subs= []; |
||||
for ($i = 1; $i <= 12; $i++) { |
||||
$total_sell[$i] = OrderTransaction::NotRefunded() |
||||
->when(is_numeric($params['zone_id']), function($q)use($params){ |
||||
return $q->where('zone_id', $params['zone_id']); |
||||
}) |
||||
->whereMonth('created_at', $i)->whereYear('created_at', now()->format('Y')) |
||||
->sum('order_amount'); |
||||
|
||||
|
||||
$total_subs[$i] = SubscriptionTransaction:: |
||||
// ->when(is_numeric($params['zone_id']), function($q)use($params){ |
||||
// return $q->where('zone_id', $params['zone_id']); |
||||
// }) |
||||
whereMonth('created_at', $i)->whereYear('created_at', now()->format('Y')) |
||||
->sum('paid_amount'); |
||||
|
||||
|
||||
|
||||
$commission[$i] = OrderTransaction::NotRefunded() |
||||
->when(is_numeric($params['zone_id']), function($q)use($params){ |
||||
return $q->where('zone_id', $params['zone_id']); |
||||
}) |
||||
->whereMonth('created_at', $i)->whereYear('created_at', now()->format('Y')) |
||||
// ->sum('admin_commission'); |
||||
->sum(DB::raw('admin_commission + admin_expense - delivery_fee_comission')); |
||||
|
||||
$commission[$i] += OrderTransaction::NotRefunded() |
||||
->when(is_numeric($params['zone_id']), function($q)use($params){ |
||||
return $q->where('zone_id', $params['zone_id']); |
||||
}) |
||||
->whereMonth('created_at', $i)->whereYear('created_at', now()->format('Y')) |
||||
->sum('delivery_fee_comission'); |
||||
} |
||||
|
||||
$dash_data = array_merge($data_os, $data_uo); |
||||
$dash_data['popular'] = $popular; |
||||
$dash_data['top_sell'] = $top_sell; |
||||
$dash_data['top_rated_foods'] = $top_rated_foods; |
||||
$dash_data['top_deliveryman'] = $top_deliveryman; |
||||
$dash_data['top_restaurants'] = $top_restaurants; |
||||
$dash_data['total_sell'] = $total_sell; |
||||
$dash_data['total_subs'] = $total_subs; |
||||
$dash_data['commission'] = $commission; |
||||
|
||||
return $dash_data; |
||||
} |
||||
} |
@ -0,0 +1,59 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Admin; |
||||
|
||||
use App\Http\Controllers\Controller; |
||||
use Illuminate\Http\Request; |
||||
use Illuminate\Support\Facades\DB; |
||||
use Brian2694\Toastr\Facades\Toastr; |
||||
|
||||
|
||||
class DatabaseSettingController extends Controller |
||||
{ |
||||
public function db_index() |
||||
{ |
||||
|
||||
$tables = DB::connection()->getDoctrineSchemaManager()->listTableNames(); |
||||
$filter_tables = array( |
||||
'admin_roles', 'admins', 'business_settings', 'colors', 'currencies', |
||||
'failed_jobs', 'migrations', 'oauth_access_tokens', 'oauth_auth_codes', |
||||
'oauth_clients', 'oauth_personal_access_clients', 'oauth_refresh_tokens', |
||||
'password_resets', 'personal_access_tokens', 'phone_or_email_verifications', |
||||
'social_medias', 'soft_credentials', 'users','email_verifications', |
||||
'phone_verifications','phone_verifications','restaurant_zone','mail_configs', |
||||
'translations','vendor_employees' |
||||
); |
||||
$tables = array_values(array_diff($tables, $filter_tables)); |
||||
$filter_tables = array_diff($tables, $filter_tables); |
||||
$rows = []; |
||||
foreach ($filter_tables as $table) { |
||||
$count = DB::table($table)->count(); |
||||
array_push($rows, $count); |
||||
} |
||||
|
||||
return view('admin-views.business-settings.db-index', compact('tables', 'rows')); |
||||
} |
||||
public function clean_db(Request $request) |
||||
{ |
||||
$tables = (array)$request->tables; |
||||
|
||||
if (count($tables) == 0) { |
||||
Toastr::error(translate('No Table Updated')); |
||||
return back(); |
||||
} |
||||
|
||||
try { |
||||
DB::transaction(function () use ($tables) { |
||||
foreach ($tables as $table) { |
||||
DB::table($table)->delete(); |
||||
} |
||||
}); |
||||
} catch (\Exception $exception) { |
||||
Toastr::error(translate('Failed to update!')); |
||||
return back(); |
||||
} |
||||
|
||||
Toastr::success(translate('messages.updated_successfully')); |
||||
return back(); |
||||
} |
||||
} |
@ -0,0 +1,590 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Admin; |
||||
|
||||
use App\Models\Zone; |
||||
use App\Models\Message; |
||||
use App\Models\DMReview; |
||||
use App\Models\UserInfo; |
||||
use App\Models\DeliveryMan; |
||||
use App\Models\Conversation; |
||||
use App\Models\IncentiveLog; |
||||
use Illuminate\Http\Request; |
||||
use App\CentralLogics\Helpers; |
||||
use App\Models\DeliveryManWallet; |
||||
use App\Models\WalletTransaction; |
||||
use Illuminate\Support\Facades\DB; |
||||
use App\Http\Controllers\Controller; |
||||
use Brian2694\Toastr\Facades\Toastr; |
||||
use Illuminate\Support\Facades\Mail; |
||||
use Rap2hpoutre\FastExcel\FastExcel; |
||||
use Illuminate\Support\Facades\Storage; |
||||
use Illuminate\Support\Facades\Validator; |
||||
|
||||
|
||||
class DeliveryManController extends Controller |
||||
{ |
||||
public function index() |
||||
{ |
||||
|
||||
return view('admin-views.delivery-man.index'); |
||||
} |
||||
|
||||
public function list(Request $request) |
||||
{ |
||||
$zone_id = $request->query('zone_id', 'all'); |
||||
$delivery_men = DeliveryMan::when(is_numeric($zone_id), function($query) use($zone_id){ |
||||
return $query->where('zone_id', $zone_id); |
||||
})->with('zone')->where('type','zone_wise')->latest()->where('application_status','approved')->paginate(config('default_pagination')); |
||||
$zone = is_numeric($zone_id)?Zone::findOrFail($zone_id):null; |
||||
return view('admin-views.delivery-man.list', compact('delivery_men', 'zone')); |
||||
} |
||||
|
||||
public function search(Request $request){ |
||||
$key = explode(' ', $request['search']); |
||||
$delivery_men=DeliveryMan::where(function ($q) use ($key) { |
||||
foreach ($key as $value) { |
||||
$q->orWhere('f_name', 'like', "%{$value}%") |
||||
->orWhere('l_name', 'like', "%{$value}%") |
||||
->orWhere('email', 'like', "%{$value}%") |
||||
->orWhere('phone', 'like', "%{$value}%") |
||||
->orWhere('identity_number', 'like', "%{$value}%"); |
||||
} |
||||
})->where('type','zone_wise')->where('application_status','approved')->get(); |
||||
return response()->json([ |
||||
'view'=>view('admin-views.delivery-man.partials._table',compact('delivery_men'))->render(), |
||||
'count'=>$delivery_men->count() |
||||
]); |
||||
} |
||||
|
||||
public function reviews_list(){ |
||||
$reviews=DMReview::with(['delivery_man','customer'])->whereHas('delivery_man',function($query){ |
||||
$query->where('type','zone_wise'); |
||||
})->latest()->paginate(config('default_pagination')); |
||||
return view('admin-views.delivery-man.reviews-list',compact('reviews')); |
||||
} |
||||
|
||||
public function preview(Request $request, $id, $tab='info') |
||||
{ |
||||
$dm = DeliveryMan::with(['reviews'])->where('type','zone_wise')->where(['id' => $id])->first(); |
||||
if($tab == 'info') |
||||
{ |
||||
$reviews=DMReview::where(['delivery_man_id'=>$id])->latest()->paginate(config('default_pagination')); |
||||
return view('admin-views.delivery-man.view.info', compact('dm', 'reviews')); |
||||
} |
||||
else if($tab == 'transaction') |
||||
{ |
||||
$date = $request->query('date'); |
||||
return view('admin-views.delivery-man.view.transaction', compact('dm', 'date')); |
||||
} |
||||
else if($tab == 'timelog') |
||||
{ |
||||
$from = $request->query('from', null); |
||||
$to = $request->query('to', null); |
||||
$timelogs = $dm->time_logs()->when($from && $to, function($query)use($from, $to){ |
||||
$query->whereBetween('date', [$from, $to]); |
||||
})->paginate(config('default_pagination')); |
||||
return view('admin-views.delivery-man.view.timelog', compact('dm', 'timelogs')); |
||||
} |
||||
else if($tab == 'conversation') |
||||
{ |
||||
$user = UserInfo::where(['deliveryman_id' => $id])->first(); |
||||
if($user){ |
||||
$conversations = Conversation::with(['sender', 'receiver', 'last_message'])->WhereUser($user->id)->paginate(8); |
||||
}else{ |
||||
$conversations = []; |
||||
} |
||||
|
||||
return view('admin-views.delivery-man.view.conversations', compact('conversations','dm')); |
||||
} |
||||
} |
||||
|
||||
public function store(Request $request) |
||||
{ |
||||
$request->validate([ |
||||
'f_name' => 'required|max:100', |
||||
'l_name' => 'nullable|max:100', |
||||
'identity_number' => 'required|max:30', |
||||
'email' => 'required|unique:delivery_men', |
||||
'phone' => 'required|regex:/^([0-9\s\-\+\(\)]*)$/|min:10|max:20|unique:delivery_men', |
||||
'zone_id' => 'required', |
||||
'earning' => 'required', |
||||
'password'=>'required|min:6', |
||||
'vehicle_id' => 'required', |
||||
'image' => 'nullable|max:2048', |
||||
'identity_image.*' => 'nullable|max:2048', |
||||
|
||||
], [ |
||||
'f_name.required' => translate('messages.first_name_is_required'), |
||||
'zone_id.required' => translate('messages.select_a_zone'), |
||||
'vehicle_id.required' => translate('messages.select_a_vehicle'), |
||||
'earning.required' => translate('messages.select_dm_type') |
||||
]); |
||||
|
||||
if ($request->has('image')) { |
||||
$image_name = Helpers::upload('delivery-man/', 'png', $request->file('image')); |
||||
} else { |
||||
$image_name = 'def.png'; |
||||
} |
||||
|
||||
$id_img_names = []; |
||||
if (!empty($request->file('identity_image'))) { |
||||
foreach ($request->identity_image as $img) { |
||||
$identity_image = Helpers::upload('delivery-man/', 'png', $img); |
||||
array_push($id_img_names, $identity_image); |
||||
} |
||||
$identity_image = json_encode($id_img_names); |
||||
} else { |
||||
$identity_image = json_encode([]); |
||||
} |
||||
|
||||
$dm = New DeliveryMan(); |
||||
$dm->f_name = $request->f_name; |
||||
$dm->l_name = $request->l_name; |
||||
$dm->email = $request->email; |
||||
$dm->phone = $request->phone; |
||||
$dm->identity_number = $request->identity_number; |
||||
$dm->identity_type = $request->identity_type; |
||||
$dm->zone_id = $request->zone_id; |
||||
$dm->vehicle_id = $request->vehicle_id; |
||||
$dm->identity_image = $identity_image; |
||||
$dm->image = $image_name; |
||||
$dm->active = 0; |
||||
$dm->earning = $request->earning; |
||||
$dm->password = bcrypt($request->password); |
||||
$dm->save(); |
||||
|
||||
Toastr::success(translate('messages.deliveryman_added_successfully')); |
||||
return redirect('admin/delivery-man/list'); |
||||
} |
||||
|
||||
public function edit($id) |
||||
{ |
||||
$delivery_man = DeliveryMan::find($id); |
||||
return view('admin-views.delivery-man.edit', compact('delivery_man')); |
||||
} |
||||
|
||||
public function status(Request $request) |
||||
{ |
||||
$delivery_man = DeliveryMan::find($request->id); |
||||
$delivery_man->status = $request->status; |
||||
|
||||
try |
||||
{ |
||||
if($request->status == 0) |
||||
{ $delivery_man->auth_token = null; |
||||
if(isset($delivery_man->fcm_token)) |
||||
{ |
||||
$data = [ |
||||
'title' => translate('messages.suspended'), |
||||
'description' => translate('messages.your_account_has_been_suspended'), |
||||
'order_id' => '', |
||||
'image' => '', |
||||
'type'=> 'block' |
||||
]; |
||||
Helpers::send_push_notif_to_device($delivery_man->fcm_token, $data); |
||||
|
||||
DB::table('user_notifications')->insert([ |
||||
'data'=> json_encode($data), |
||||
'delivery_man_id'=>$delivery_man->id, |
||||
'created_at'=>now(), |
||||
'updated_at'=>now() |
||||
]); |
||||
} |
||||
|
||||
} |
||||
|
||||
} |
||||
catch (\Exception $e) { |
||||
Toastr::warning(translate('messages.push_notification_faild')); |
||||
} |
||||
|
||||
$delivery_man->save(); |
||||
|
||||
Toastr::success(translate('messages.deliveryman_status_updated')); |
||||
return back(); |
||||
} |
||||
|
||||
public function reviews_status(Request $request) |
||||
{ |
||||
$review = DMReview::find($request->id); |
||||
$review->status = $request->status; |
||||
$review->save(); |
||||
Toastr::success(translate('messages.review_visibility_updated')); |
||||
return back(); |
||||
} |
||||
|
||||
public function earning(Request $request) |
||||
{ |
||||
$delivery_man = DeliveryMan::find($request->id); |
||||
$delivery_man->earning = $request->status; |
||||
|
||||
$delivery_man->save(); |
||||
|
||||
Toastr::success(translate('messages.deliveryman_type_updated')); |
||||
return back(); |
||||
} |
||||
|
||||
public function update_application(Request $request) |
||||
{ |
||||
$delivery_man = DeliveryMan::findOrFail($request->id); |
||||
$delivery_man->application_status = $request->status; |
||||
if($request->status == 'approved') $delivery_man->status = 1; |
||||
$delivery_man->save(); |
||||
|
||||
try{ |
||||
if( config('mail.status')) { |
||||
Mail::to($request['email'])->send(new \App\Mail\SelfRegistration($request->status, $delivery_man->f_name.' '.$delivery_man->l_name)); |
||||
} |
||||
|
||||
}catch(\Exception $ex){ |
||||
info($ex); |
||||
} |
||||
|
||||
|
||||
Toastr::success(translate('messages.application_status_updated_successfully')); |
||||
return back(); |
||||
} |
||||
|
||||
public function update(Request $request, $id) |
||||
{ |
||||
$request->validate([ |
||||
'f_name' => 'required|max:100', |
||||
'l_name' => 'nullable|max:100', |
||||
'identity_number' => 'required|max:30', |
||||
'email' => 'required|unique:delivery_men,email,'.$id, |
||||
'phone' => 'required|regex:/^([0-9\s\-\+\(\)]*)$/|min:10|unique:delivery_men,phone,'.$id, |
||||
'vehicle_id' => 'required', |
||||
'earning' => 'required', |
||||
'password' => 'nullable|min:6', |
||||
'image' => 'nullable|max:2048', |
||||
'identity_image.*' => 'nullable|max:2048', |
||||
], [ |
||||
'f_name.required' => translate('messages.first_name_is_required'), |
||||
'earning.required' => translate('messages.select_dm_type'), |
||||
'vehicle_id.required' => translate('messages.select_a_vehicle'), |
||||
|
||||
]); |
||||
|
||||
$delivery_man = DeliveryMan::find($id); |
||||
|
||||
if ($request->has('image')) { |
||||
$image_name = Helpers::update('delivery-man/', $delivery_man->image, 'png', $request->file('image')); |
||||
} else { |
||||
$image_name = $delivery_man['image']; |
||||
} |
||||
|
||||
if ($request->has('identity_image')){ |
||||
foreach (json_decode($delivery_man['identity_image'], true) as $img) { |
||||
if (Storage::disk('public')->exists('delivery-man/' . $img)) { |
||||
Storage::disk('public')->delete('delivery-man/' . $img); |
||||
} |
||||
} |
||||
$img_keeper = []; |
||||
foreach ($request->identity_image as $img) { |
||||
$identity_image = Helpers::upload('delivery-man/', 'png', $img); |
||||
array_push($img_keeper, $identity_image); |
||||
} |
||||
$identity_image = json_encode($img_keeper); |
||||
} else { |
||||
$identity_image = $delivery_man['identity_image']; |
||||
} |
||||
|
||||
$delivery_man->vehicle_id = $request->vehicle_id; |
||||
|
||||
$delivery_man->f_name = $request->f_name; |
||||
$delivery_man->l_name = $request->l_name; |
||||
$delivery_man->email = $request->email; |
||||
$delivery_man->phone = $request->phone; |
||||
$delivery_man->identity_number = $request->identity_number; |
||||
$delivery_man->identity_type = $request->identity_type; |
||||
$delivery_man->zone_id = $request->zone_id; |
||||
$delivery_man->identity_image = $identity_image; |
||||
$delivery_man->image = $image_name; |
||||
$delivery_man->earning = $request->earning; |
||||
$delivery_man->password = strlen($request->password)>1?bcrypt($request->password):$delivery_man['password']; |
||||
$delivery_man->save(); |
||||
Toastr::success(translate('messages.deliveryman_updated_successfully')); |
||||
return redirect('admin/delivery-man/list'); |
||||
} |
||||
|
||||
public function delete(Request $request) |
||||
{ |
||||
$delivery_man = DeliveryMan::find($request->id); |
||||
if (Storage::disk('public')->exists('delivery-man/' . $delivery_man['image'])) { |
||||
Storage::disk('public')->delete('delivery-man/' . $delivery_man['image']); |
||||
} |
||||
|
||||
foreach (json_decode($delivery_man['identity_image'], true) as $img) { |
||||
if (Storage::disk('public')->exists('delivery-man/' . $img)) { |
||||
Storage::disk('public')->delete('delivery-man/' . $img); |
||||
} |
||||
} |
||||
if($delivery_man->userinfo){ |
||||
|
||||
$delivery_man->userinfo->delete(); |
||||
} |
||||
$delivery_man->delete(); |
||||
Toastr::success(translate('messages.deliveryman_deleted_successfully')); |
||||
return back(); |
||||
} |
||||
|
||||
public function get_deliverymen(Request $request){ |
||||
$key = explode(' ', $request->q); |
||||
$zone_ids = isset($request->zone_ids)?(count($request->zone_ids)>0?$request->zone_ids:[]):0; |
||||
$data=DeliveryMan::when($zone_ids, function($query) use($zone_ids){ |
||||
return $query->whereIn('zone_id', $zone_ids); |
||||
}) |
||||
->when($request->earning, function($query){ |
||||
return $query->earning(); |
||||
}) |
||||
->where(function ($q) use ($key) { |
||||
foreach ($key as $value) { |
||||
$q->orWhere('f_name', 'like', "%{$value}%") |
||||
->orWhere('l_name', 'like', "%{$value}%") |
||||
->orWhere('email', 'like', "%{$value}%") |
||||
->orWhere('phone', 'like', "%{$value}%") |
||||
->orWhere('identity_number', 'like', "%{$value}%"); |
||||
} |
||||
})->active()->limit(8)->get(['id',DB::raw('CONCAT(f_name, " ", l_name) as text')]); |
||||
return response()->json($data); |
||||
} |
||||
|
||||
public function get_account_data(DeliveryMan $deliveryman) |
||||
{ |
||||
$wallet = $deliveryman->wallet; |
||||
$cash_in_hand = 0; |
||||
$balance = 0; |
||||
|
||||
if($wallet) |
||||
{ |
||||
$cash_in_hand = $wallet->collected_cash; |
||||
$balance = round($wallet->total_earning - $wallet->total_withdrawn - $wallet->pending_withdraw, config('round_up_to_digit')); |
||||
} |
||||
return response()->json(['cash_in_hand'=>$cash_in_hand, 'earning_balance'=>$balance], 200); |
||||
|
||||
} |
||||
|
||||
public function get_conversation_list(Request $request) |
||||
{ |
||||
$user = UserInfo::where(['deliveryman_id' => $request->user_id])->first(); |
||||
$dm = DeliveryMan::find($request->user_id); |
||||
if($user){ |
||||
$conversations = Conversation::with(['sender', 'receiver', 'last_message'])->WhereUser($user->id); |
||||
if($request->query('key')) { |
||||
$key = explode(' ', $request->get('key')); |
||||
$conversations = $conversations->where(function($qu)use($key){ |
||||
$qu->where(function($q)use($key){ |
||||
$q->where('sender_type','!=', 'delivery_man')->whereHas('sender',function($query)use($key){ |
||||
foreach ($key as $value) { |
||||
$query->where('f_name', 'like', "%{$value}%")->orWhere('l_name', 'like', "%{$value}%")->orWhere('phone', 'like', "%{$value}%"); |
||||
} |
||||
}); |
||||
})->orWhere(function($q)use($key){ |
||||
$q->where('receiver_type','!=', 'delivery_man')->whereHas('receiver',function($query)use($key){ |
||||
foreach ($key as $value) { |
||||
$query->where('f_name', 'like', "%{$value}%")->orWhere('l_name', 'like', "%{$value}%")->orWhere('phone', 'like', "%{$value}%"); |
||||
} |
||||
}); |
||||
}); |
||||
}); |
||||
} |
||||
$conversations = $conversations->WhereUserType('delivery_man')->paginate(8); |
||||
}else{ |
||||
$conversations = []; |
||||
} |
||||
|
||||
$view = view('admin-views.delivery-man.partials._conversation_list',compact('conversations','dm'))->render(); |
||||
return response()->json(['html'=>$view]); |
||||
|
||||
} |
||||
|
||||
public function conversation_view($conversation_id,$user_id) |
||||
{ |
||||
$convs = Message::where(['conversation_id' => $conversation_id])->get(); |
||||
$conversation = Conversation::find($conversation_id); |
||||
$receiver = UserInfo::find($conversation->receiver_id); |
||||
$sender = UserInfo::find($conversation->sender_id); |
||||
$user = UserInfo::find($user_id); |
||||
return response()->json([ |
||||
'view' => view('admin-views.delivery-man.partials._conversations', compact('convs', 'user', 'receiver'))->render() |
||||
]); |
||||
} |
||||
public function dm_list_export(Request $request){ |
||||
|
||||
$withdraw_request = DeliveryMan::where('type','zone_wise')->orderBy('id','desc')->get(); |
||||
if ($request->type == 'excel') { |
||||
return (new FastExcel(Helpers::export_d_man($withdraw_request)))->download('deliveryman_list.xlsx'); |
||||
} elseif ($request->type == 'csv') { |
||||
return (new FastExcel(Helpers::export_d_man($withdraw_request)))->download('deliveryman_list.csv'); |
||||
} |
||||
} |
||||
|
||||
|
||||
public function pending(Request $request) |
||||
{ |
||||
$key = explode(' ', $request['search']); |
||||
$zone_id = $request->query('zone_id', 'all'); |
||||
$delivery_men = DeliveryMan::when(is_numeric($zone_id), function($query) use($zone_id){ |
||||
return $query->where('zone_id', $zone_id); |
||||
}) |
||||
->when(isset($key),function($query)use($key){ |
||||
$query->where(function($q)use($key){ |
||||
foreach ($key as $value) { |
||||
$q->orWhere('f_name', 'like', "%{$value}%") |
||||
->orWhere('l_name', 'like', "%{$value}%") |
||||
->orWhere('email', 'like', "%{$value}%") |
||||
->orWhere('phone', 'like', "%{$value}%") |
||||
->orWhere('identity_number', 'like', "%{$value}%"); |
||||
} |
||||
}); |
||||
}) |
||||
->with('zone')->where('type','zone_wise')->where('application_status', 'pending')->latest()->paginate(config('default_pagination')); |
||||
$zone = is_numeric($zone_id)?Zone::findOrFail($zone_id):null; |
||||
return view('admin-views.delivery-man.pending_list', compact('delivery_men', 'zone')); |
||||
|
||||
|
||||
} |
||||
public function denied(Request $request) |
||||
{ |
||||
$key = explode(' ', $request['search']); |
||||
$zone_id = $request->query('zone_id', 'all'); |
||||
$delivery_men = DeliveryMan::when(is_numeric($zone_id), function($query) use($zone_id){ |
||||
return $query->where('zone_id', $zone_id); |
||||
}) |
||||
->when(isset($key),function($query)use($key){ |
||||
$query->where(function($q)use($key){ |
||||
foreach ($key as $value) { |
||||
$q->orWhere('f_name', 'like', "%{$value}%") |
||||
->orWhere('l_name', 'like', "%{$value}%") |
||||
->orWhere('email', 'like', "%{$value}%") |
||||
->orWhere('phone', 'like', "%{$value}%") |
||||
->orWhere('identity_number', 'like', "%{$value}%"); |
||||
} |
||||
}); |
||||
}) |
||||
->with('zone')->where('type','zone_wise')->where('application_status', 'denied')->latest()->paginate(config('default_pagination')); |
||||
$zone = is_numeric($zone_id)?Zone::findOrFail($zone_id):null; |
||||
return view('admin-views.delivery-man.denied', compact('delivery_men', 'zone')); |
||||
} |
||||
|
||||
public function get_incentives(Request $request) |
||||
{ |
||||
$incentives = IncentiveLog::when($request->search, function ($query) use ($request) { |
||||
$key = explode(' ', $request->search); |
||||
$query->whereHas('deliveryman', function ($query) use ($key) { |
||||
$query->where(function ($q) use ($key) { |
||||
foreach ($key as $value) { |
||||
$q->orWhere('f_name', 'like', "%{$value}%"); |
||||
$q->orWhere('l_name', 'like', "%{$value}%"); |
||||
$q->orWhere('phone', 'like', "%{$value}%"); |
||||
$q->orWhere('email', 'like', "%{$value}%"); |
||||
} |
||||
}); |
||||
}); |
||||
}) |
||||
->where('status', '!=', 'pending') |
||||
->latest()->paginate(config('default_pagination')); |
||||
return view('admin-views.delivery-man.incentive', compact('incentives')); |
||||
} |
||||
public function pending_incentives(Request $request) |
||||
{ |
||||
$incentives = IncentiveLog:: |
||||
when($request->search, function ($query) use ($request) { |
||||
$key = explode(' ', $request->search); |
||||
$query->whereHas('deliveryman', function ($query) use ($key) { |
||||
$query->where(function ($q) use ($key) { |
||||
foreach ($key as $value) { |
||||
$q->orWhere('f_name', 'like', "%{$value}%"); |
||||
$q->orWhere('l_name', 'like', "%{$value}%"); |
||||
$q->orWhere('phone', 'like', "%{$value}%"); |
||||
$q->orWhere('email', 'like', "%{$value}%"); |
||||
} |
||||
}); |
||||
}); |
||||
}) |
||||
->whereStatus('pending') |
||||
->latest()->paginate(config('default_pagination')); |
||||
return view('admin-views.delivery-man.incentive', compact('incentives')); |
||||
} |
||||
|
||||
public function update_incentive_status(Request $request) |
||||
{ |
||||
$request->validate([ |
||||
'status' => 'required|in:denied', |
||||
'id' => 'required' |
||||
]); |
||||
|
||||
$incentive = IncentiveLog::findOrFail($request->id); |
||||
|
||||
if ($incentive->status == "pending") { |
||||
$incentive->status = $request->status; |
||||
$incentive->save(); |
||||
Toastr::success(translate('messages.incentive_denied')); |
||||
return back(); |
||||
} |
||||
|
||||
} |
||||
|
||||
public function update_all_incentive_status(Request $request) |
||||
{ |
||||
$request->validate([ |
||||
'incentive_id' => 'required' |
||||
]); |
||||
$incentives = IncentiveLog::whereIn('id', $request->incentive_id)->get(); |
||||
foreach ($incentives as $incentive) { |
||||
Helpers::dm_wallet_transaction($incentive->delivery_man_id, $incentive->incentive, null, 'incentive'); |
||||
$incentive->status = "approved"; |
||||
// $incentive->subsidy = $request->incentive[$incentive->id]; |
||||
$incentive->save(); |
||||
} |
||||
Toastr::success(translate('messages.succesfully_approved_incentive')); |
||||
return back(); |
||||
} |
||||
|
||||
public function get_bonus(Request $request) |
||||
{ |
||||
$data = WalletTransaction::where('transaction_type', 'dm_admin_bonus') |
||||
->when($request->search, function ($query) use ($request) { |
||||
$query->where(function($query) use ($request) { |
||||
$key = explode(' ', $request->search); |
||||
$query->where(function ($q) use ($key) { |
||||
foreach ($key as $value) { |
||||
$q->Where('transaction_id', 'like', "%{$value}%"); |
||||
} |
||||
}) |
||||
->orWhereHas('delivery_man', function ($query) use ($key) { |
||||
$query->where(function ($q) use ($key) { |
||||
foreach ($key as $value) { |
||||
$q->orWhere('f_name', 'like', "%{$value}%"); |
||||
$q->orWhere('l_name', 'like', "%{$value}%"); |
||||
$q->orWhere('phone', 'like', "%{$value}%"); |
||||
$q->orWhere('email', 'like', "%{$value}%"); |
||||
} |
||||
}); |
||||
}); |
||||
}); |
||||
}) |
||||
|
||||
->paginate(config('default_pagination')); |
||||
return view('admin-views.delivery-man.bonus', compact('data')); |
||||
} |
||||
|
||||
public function add_bonus(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'delivery_man_id'=>'exists:delivery_men,id', |
||||
'amount'=>'numeric|min:.01', |
||||
]); |
||||
|
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)]); |
||||
} |
||||
|
||||
if(Helpers::dm_wallet_transaction($request->delivery_man_id, $request->amount, $request->referance)){ |
||||
return response()->json(['message'=>trans('messages.bonus_added_successfully')], 200); |
||||
} |
||||
return response()->json(['errors' => [['code'=>'transaction-failed', 'message'=>translate('messages.faield_to_create_transaction')]]]); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,167 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Admin; |
||||
|
||||
use App\CentralLogics\Helpers; |
||||
use App\Http\Controllers\Controller; |
||||
use App\Models\Admin; |
||||
use App\Models\AdminRole; |
||||
use Brian2694\Toastr\Facades\Toastr; |
||||
use Illuminate\Http\Request; |
||||
use Illuminate\Support\Facades\DB; |
||||
use Rap2hpoutre\FastExcel\FastExcel; |
||||
|
||||
class EmployeeController extends Controller |
||||
{ |
||||
|
||||
public function add_new() |
||||
{ |
||||
$rls = AdminRole::whereNotIn('id', [1])->get(); |
||||
return view('admin-views.employee.add-new', compact('rls')); |
||||
} |
||||
|
||||
public function store(Request $request) |
||||
{ |
||||
$request->validate([ |
||||
'f_name' => 'required', |
||||
'l_name' => 'nullable|max:100', |
||||
'role_id' => 'required', |
||||
'image' => 'required|max:2048', |
||||
'email' => 'required|unique:admins', |
||||
'phone' => 'required|regex:/^([0-9\s\-\+\(\)]*)$/|min:10|max:20|unique:admins', |
||||
'password' =>'required|min:6' |
||||
]); |
||||
|
||||
if ($request->role_id == 1) { |
||||
Toastr::warning(translate('messages.access_denied')); |
||||
return back(); |
||||
} |
||||
|
||||
DB::table('admins')->insert([ |
||||
'f_name' => $request->f_name, |
||||
'l_name' => $request->l_name, |
||||
'phone' => $request->phone, |
||||
'zone_id' => $request->zone_id, |
||||
'email' => $request->email, |
||||
'role_id' => $request->role_id, |
||||
'password' => bcrypt($request->password), |
||||
'image' => Helpers::upload('admin/', 'png', $request->file('image')), |
||||
'created_at' => now(), |
||||
'updated_at' => now(), |
||||
]); |
||||
|
||||
Toastr::success(translate('messages.employee_added_successfully')); |
||||
return redirect()->route('admin.employee.list'); |
||||
} |
||||
|
||||
function list() |
||||
{ |
||||
$em = Admin::zone()->with(['role'])->where('role_id', '!=','1')->latest()->paginate(config('default_pagination')); |
||||
return view('admin-views.employee.list', compact('em')); |
||||
} |
||||
|
||||
public function edit($id) |
||||
{ |
||||
$e = Admin::zone()->where('role_id', '!=','1')->where(['id' => $id])->first(); |
||||
if (auth('admin')->id() == $e['id']){ |
||||
Toastr::error(translate('messages.You_can_not_edit_your_own_info')); |
||||
return redirect()->route('admin.employee.list'); |
||||
} |
||||
$rls = AdminRole::whereNotIn('id', [1])->get(); |
||||
return view('admin-views.employee.edit', compact('rls', 'e')); |
||||
} |
||||
|
||||
public function update(Request $request, $id) |
||||
{ |
||||
$request->validate([ |
||||
'f_name' => 'required|max:100', |
||||
'l_name' => 'nullable|max:100', |
||||
'role_id' => 'required', |
||||
'email' => 'required|unique:admins,email,'.$id, |
||||
'phone' => 'required|regex:/^([0-9\s\-\+\(\)]*)$/|min:10|max:20|unique:admins,phone,'.$id, |
||||
'password' => 'nullable|min:6', |
||||
'image' => 'nullable|max:2048', |
||||
], [ |
||||
'f_name.required' => translate('messages.first_name_is_required'), |
||||
]); |
||||
|
||||
|
||||
if ($request->role_id == 1) { |
||||
Toastr::warning(translate('messages.access_denied')); |
||||
return back(); |
||||
} |
||||
|
||||
$e = Admin::where('role_id','!=',1)->findOrFail($id); |
||||
if (auth('admin')->id() == $e['id']){ |
||||
Toastr::error(translate('messages.You_can_not_edit_your_own_info')); |
||||
return redirect()->route('admin.employee.list'); |
||||
} |
||||
|
||||
if ($request['password'] == null) { |
||||
$pass = $e['password']; |
||||
} else { |
||||
if (strlen($request['password']) < 6) { |
||||
Toastr::warning(translate('messages.password_length_warning',['length'=>'6'])); |
||||
return back(); |
||||
} |
||||
$pass = bcrypt($request['password']); |
||||
} |
||||
|
||||
if ($request->has('image')) { |
||||
$e['image'] = Helpers::update('admin/', $e->image, 'png', $request->file('image')); |
||||
} |
||||
|
||||
DB::table('admins')->where(['id' => $id])->update([ |
||||
'f_name' => $request->f_name, |
||||
'l_name' => $request->l_name, |
||||
'phone' => $request->phone, |
||||
'zone_id' => $request->zone_id, |
||||
'email' => $request->email, |
||||
'role_id' => $request->role_id, |
||||
'password' => $pass, |
||||
'image' => $e['image'], |
||||
'updated_at' => now(), |
||||
]); |
||||
|
||||
Toastr::success(translate('messages.employee_updated_successfully')); |
||||
return redirect()->route('admin.employee.list'); |
||||
} |
||||
|
||||
public function distroy($id) |
||||
{ |
||||
$role=Admin::zone()->where('role_id', '!=','1')->where(['id'=>$id])->first(); |
||||
if (auth('admin')->id() == $role['id']){ |
||||
Toastr::error(translate('messages.You_can_not_edit_your_own_info')); |
||||
return redirect()->route('admin.employee.list'); |
||||
} |
||||
$role->delete(); |
||||
Toastr::info(translate('messages.employee_deleted_successfully')); |
||||
return back(); |
||||
} |
||||
|
||||
public function search(Request $request){ |
||||
$key = explode(' ', $request['search']); |
||||
$employees=Admin::zone()->where('role_id', '!=','1') |
||||
->where(function ($q) use ($key) { |
||||
foreach ($key as $value) { |
||||
$q->orWhere('f_name', 'like', "%{$value}%"); |
||||
$q->orWhere('l_name', 'like', "%{$value}%"); |
||||
$q->orWhere('phone', 'like', "%{$value}%"); |
||||
$q->orWhere('email', 'like', "%{$value}%"); |
||||
} |
||||
})->limit(50)->get(); |
||||
return response()->json([ |
||||
'view'=>view('admin-views.employee.partials._table',compact('employees'))->render(), |
||||
'count'=>$employees->count() |
||||
]); |
||||
} |
||||
|
||||
public function employee_list_export(Request $request){ |
||||
$withdraw_request = Admin::zone()->with(['role'])->where('role_id', '!=','1')->get(); |
||||
if($request->type == 'excel'){ |
||||
return (new FastExcel($withdraw_request))->download('Employee.xlsx'); |
||||
}elseif($request->type == 'csv'){ |
||||
return (new FastExcel($withdraw_request))->download('Employee.csv'); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,103 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Admin; |
||||
|
||||
use App\Http\Controllers\Controller; |
||||
use Illuminate\Http\Request; |
||||
use Illuminate\Http\File; |
||||
use Illuminate\Support\Facades\Storage; |
||||
use App\CentralLogics\FileManagerLogic; |
||||
use App\CentralLogics\Helpers; |
||||
use Brian2694\Toastr\Facades\Toastr; |
||||
use Madnest\Madzipper\Facades\Madzipper; |
||||
|
||||
class FileManagerController extends Controller |
||||
{ |
||||
/** |
||||
* Display a listing of the resource. |
||||
* |
||||
* @return \Illuminate\Http\Response |
||||
*/ |
||||
public function index($folder_path = "cHVibGlj") |
||||
{ |
||||
$file = Storage::files(base64_decode($folder_path)); |
||||
$directories = Storage::directories(base64_decode($folder_path)); |
||||
|
||||
$folders = FileManagerLogic::format_file_and_folders($directories, 'folder'); |
||||
$files = FileManagerLogic::format_file_and_folders($file, 'file'); |
||||
// dd($files); |
||||
$data = array_merge($folders, $files); |
||||
return view('admin-views.file-manager.index', compact('data', 'folder_path')); |
||||
} |
||||
|
||||
|
||||
public function upload(Request $request) |
||||
{ |
||||
if (env('APP_MODE') == 'demo') { |
||||
Toastr::info(translate('messages.upload_option_is_disable_for_demo')); |
||||
return back(); |
||||
} |
||||
$request->validate([ |
||||
'images' => 'required_without:file', |
||||
'file' => 'required_without:images', |
||||
'path' => 'required', |
||||
]); |
||||
if ($request->hasfile('images')) { |
||||
$images = $request->file('images'); |
||||
|
||||
foreach($images as $image) { |
||||
$name = $image->getClientOriginalName(); |
||||
Storage::disk('local')->put($request->path.'/'. $name, file_get_contents($image)); |
||||
} |
||||
} |
||||
if ($request->hasfile('file')) { |
||||
$file = $request->file('file'); |
||||
$name = $file->getClientOriginalName(); |
||||
|
||||
Madzipper::make($file)->extractTo('storage/app/'.$request->path); |
||||
// Storage::disk('local')->put($request->path.'/'. $name, file_get_contents($file)); |
||||
|
||||
} |
||||
Toastr::success(translate('messages.image_uploaded_successfully')); |
||||
return back()->with('success', translate('messages.image_uploaded_successfully')); |
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
public function download($file_name) |
||||
{ |
||||
return Storage::download(base64_decode($file_name)); |
||||
} |
||||
|
||||
/** |
||||
* Show the form for editing the specified resource. |
||||
* |
||||
* @param int $id |
||||
* @return \Illuminate\Http\Response |
||||
*/ |
||||
public function edit($id) |
||||
{ |
||||
// |
||||
} |
||||
|
||||
/** |
||||
* Update the specified resource in storage. |
||||
* |
||||
* @param \Illuminate\Http\Request $request |
||||
* @param int $id |
||||
* @return \Illuminate\Http\Response |
||||
*/ |
||||
public function update(Request $request, $id) |
||||
{ |
||||
// |
||||
} |
||||
|
||||
|
||||
public function destroy($file_path) |
||||
{ |
||||
Storage::disk('local')->delete(base64_decode($file_path)); |
||||
Toastr::success(translate('messages.image_deleted_successfully')); |
||||
return back()->with('success', translate('messages.image_deleted_successfully')); |
||||
} |
||||
} |
@ -0,0 +1,722 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Admin; |
||||
|
||||
use Carbon\Carbon; |
||||
use App\Models\Tag; |
||||
use App\Models\Food; |
||||
use App\Models\Review; |
||||
use App\Models\Category; |
||||
use App\Models\Restaurant; |
||||
use App\Models\Translation; |
||||
use Illuminate\Support\Str; |
||||
use App\Models\ItemCampaign; |
||||
use Illuminate\Http\Request; |
||||
use App\CentralLogics\Helpers; |
||||
use App\Scopes\RestaurantScope; |
||||
use Illuminate\Support\Facades\DB; |
||||
use App\CentralLogics\ProductLogic; |
||||
use App\Http\Controllers\Controller; |
||||
use Brian2694\Toastr\Facades\Toastr; |
||||
use Rap2hpoutre\FastExcel\FastExcel; |
||||
use Illuminate\Support\Facades\Storage; |
||||
use Illuminate\Support\Facades\Validator; |
||||
|
||||
class FoodController extends Controller |
||||
{ |
||||
public function index() |
||||
{ |
||||
$categories = Category::where(['position' => 0])->get(); |
||||
return view('admin-views.product.index', compact('categories')); |
||||
} |
||||
|
||||
public function store(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'name.0' => 'required', |
||||
'name.*' => 'max:191', |
||||
'category_id' => 'required', |
||||
//'image' => 'required', |
||||
'image' => 'nullable|max:2048', |
||||
'price' => 'required|numeric|between:.01,999999999999.99', |
||||
'discount' => 'required|numeric|min:0', |
||||
'restaurant_id' => 'required', |
||||
'description.*' => 'max:1000', |
||||
'veg'=>'required' |
||||
], [ |
||||
'description.*.max' => translate('messages.description_length_warning'), |
||||
'name.0.required' => translate('messages.item_name_required'), |
||||
'category_id.required' => translate('messages.category_required'), |
||||
'veg.required'=>translate('messages.item_type_is_required') |
||||
]); |
||||
|
||||
if ($request['discount_type'] == 'percent') { |
||||
$dis = ($request['price'] / 100) * $request['discount']; |
||||
} else { |
||||
$dis = $request['discount']; |
||||
} |
||||
|
||||
if ($request['price'] <= $dis) { |
||||
$validator->getMessageBag()->add('unit_price', translate('messages.discount_can_not_be_more_than_or_equal')); |
||||
} |
||||
|
||||
if ($request['price'] <= $dis || $validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)]); |
||||
} |
||||
$tag_ids = []; |
||||
if ($request->tags != null) { |
||||
$tags = explode(",", $request->tags); |
||||
} |
||||
if(isset($tags)){ |
||||
foreach ($tags as $key => $value) { |
||||
$tag = Tag::firstOrNew( |
||||
['tag' => $value] |
||||
); |
||||
$tag->save(); |
||||
array_push($tag_ids,$tag->id); |
||||
} |
||||
} |
||||
$food = new Food; |
||||
$food->name = $request->name[array_search('en', $request->lang)]; |
||||
|
||||
$category = []; |
||||
if ($request->category_id != null) { |
||||
array_push($category, [ |
||||
'id' => $request->category_id, |
||||
'position' => 1, |
||||
]); |
||||
} |
||||
if ($request->sub_category_id != null) { |
||||
array_push($category, [ |
||||
'id' => $request->sub_category_id, |
||||
'position' => 2, |
||||
]); |
||||
} |
||||
if ($request->sub_sub_category_id != null) { |
||||
array_push($category, [ |
||||
'id' => $request->sub_sub_category_id, |
||||
'position' => 3, |
||||
]); |
||||
} |
||||
|
||||
$food->category_ids = json_encode($category); |
||||
$food->category_id = $request->sub_category_id?$request->sub_category_id:$request->category_id; |
||||
$food->description = $request->description[array_search('en', $request->lang)]; |
||||
|
||||
$choice_options = []; |
||||
if ($request->has('choice')) { |
||||
foreach ($request->choice_no as $key => $no) { |
||||
$str = 'choice_options_' . $no; |
||||
if ($request[$str][0] == null) { |
||||
$validator->getMessageBag()->add('name', translate('messages.attribute_choice_option_value_can_not_be_null')); |
||||
return response()->json(['errors' => Helpers::error_processor($validator)]); |
||||
} |
||||
$item['name'] = 'choice_' . $no; |
||||
$item['title'] = $request->choice[$key]; |
||||
$item['options'] = explode(',', implode('|', preg_replace('/\s+/', ' ', $request[$str]))); |
||||
array_push($choice_options, $item); |
||||
} |
||||
} |
||||
$food->choice_options = json_encode($choice_options); |
||||
|
||||
$variations = []; |
||||
if(isset($request->options)) |
||||
{ |
||||
foreach(array_values($request->options) as $key=>$option) |
||||
{ |
||||
|
||||
$temp_variation['name']= $option['name']; |
||||
$temp_variation['type']= $option['type']; |
||||
$temp_variation['min']= $option['min'] ?? 0; |
||||
$temp_variation['max']= $option['max'] ?? 0; |
||||
$temp_variation['required']= $option['required']??'off'; |
||||
if($option['min'] > 0 && $option['min'] > $option['max'] ){ |
||||
$validator->getMessageBag()->add('name', translate('messages.minimum_value_can_not_be_greater_then_maximum_value')); |
||||
return response()->json(['errors' => Helpers::error_processor($validator)]); |
||||
} |
||||
if(!isset($option['values'])){ |
||||
$validator->getMessageBag()->add('name', translate('messages.please_add_options_for').$option['name']); |
||||
return response()->json(['errors' => Helpers::error_processor($validator)]); |
||||
} |
||||
if($option['max'] > count($option['values']) ){ |
||||
$validator->getMessageBag()->add('name', translate('messages.please_add_more_options_or_change_the_max_value_for').$option['name']); |
||||
return response()->json(['errors' => Helpers::error_processor($validator)]); |
||||
} |
||||
$temp_value = []; |
||||
|
||||
foreach(array_values($option['values']) as $value) |
||||
{ |
||||
if(isset($value['label'])){ |
||||
$temp_option['label'] = $value['label']; |
||||
} |
||||
$temp_option['optionPrice'] = $value['optionPrice']; |
||||
array_push($temp_value,$temp_option); |
||||
} |
||||
$temp_variation['values']= $temp_value; |
||||
array_push($variations,$temp_variation); |
||||
} |
||||
} |
||||
|
||||
//combinations end |
||||
$food->variations = json_encode($variations); |
||||
$food->price = $request->price; |
||||
$food->image = Helpers::upload('product/', 'png', $request->file('image')); |
||||
$food->available_time_starts = $request->available_time_starts; |
||||
$food->available_time_ends = $request->available_time_ends; |
||||
$food->discount = $request->discount_type == 'amount' ? $request->discount : $request->discount; |
||||
$food->discount_type = $request->discount_type; |
||||
|
||||
$food->attributes = $request->has('attribute_id') ? json_encode($request->attribute_id) : json_encode([]); |
||||
$food->add_ons = $request->has('addon_ids') ? json_encode($request->addon_ids) : json_encode([]); |
||||
$food->restaurant_id = $request->restaurant_id; |
||||
$food->veg = $request->veg; |
||||
$food->save(); |
||||
$food->tags()->sync($tag_ids); |
||||
|
||||
$data = []; |
||||
foreach ($request->lang as $index => $key) { |
||||
if ($request->name[$index] && $key != 'en') { |
||||
array_push($data, array( |
||||
'translationable_type' => 'App\Models\Food', |
||||
'translationable_id' => $food->id, |
||||
'locale' => $key, |
||||
'key' => 'name', |
||||
'value' => $request->name[$index], |
||||
)); |
||||
} |
||||
if ($request->description[$index] && $key != 'en') { |
||||
array_push($data, array( |
||||
'translationable_type' => 'App\Models\Food', |
||||
'translationable_id' => $food->id, |
||||
'locale' => $key, |
||||
'key' => 'description', |
||||
'value' => $request->description[$index], |
||||
)); |
||||
} |
||||
} |
||||
Translation::insert($data); |
||||
|
||||
return response()->json([], 200); |
||||
} |
||||
|
||||
public function view($id) |
||||
{ |
||||
$product = Food::withoutGlobalScope(RestaurantScope::class)->findOrFail($id); |
||||
$reviews=Review::where(['food_id'=>$id])->latest()->paginate(config('default_pagination')); |
||||
return view('admin-views.product.view', compact('product','reviews')); |
||||
} |
||||
|
||||
public function edit($id) |
||||
{ |
||||
$product = Food::withoutGlobalScope(RestaurantScope::class)->withoutGlobalScope('translate')->findOrFail($id); |
||||
// dd($product->toArray()); |
||||
if(!$product) |
||||
{ |
||||
Toastr::error(translate('messages.food').' '.translate('messages.not_found')); |
||||
return back(); |
||||
} |
||||
$product_category = json_decode($product->category_ids); |
||||
$categories = Category::where(['parent_id' => 0])->get(); |
||||
return view('admin-views.product.edit', compact('product', 'product_category', 'categories')); |
||||
} |
||||
|
||||
public function status(Request $request) |
||||
{ |
||||
$product = Food::withoutGlobalScope(RestaurantScope::class)->findOrFail($request->id); |
||||
$product->status = $request->status; |
||||
$product->save(); |
||||
Toastr::success(translate('messages.food_status_updated')); |
||||
return back(); |
||||
} |
||||
|
||||
public function update(Request $request, $id) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'name' => 'array', |
||||
'name.0' => 'required', |
||||
'name.*' => 'max:191', |
||||
'category_id' => 'required', |
||||
'price' => 'required|numeric|between:.01,999999999999.99', |
||||
'restaurant_id' => 'required', |
||||
'veg' => 'required', |
||||
'description' => 'array', |
||||
'description.*' => 'max:1000', |
||||
'discount' => 'required|numeric|min:0', |
||||
'image' => 'nullable|max:2048', |
||||
], [ |
||||
'description.*.max' => translate('messages.description_length_warning'), |
||||
'name.0.required' => translate('messages.item_name_required'), |
||||
'category_id.required' => translate('messages.category_required'), |
||||
'veg.required'=>translate('messages.item_type_is_required'), |
||||
]); |
||||
|
||||
if ($request['discount_type'] == 'percent') { |
||||
$dis = ($request['price'] / 100) * $request['discount']; |
||||
} else { |
||||
$dis = $request['discount']; |
||||
} |
||||
|
||||
if ($request['price'] <= $dis) { |
||||
$validator->getMessageBag()->add('unit_price', translate('messages.discount_can_not_be_more_than_or_equal')); |
||||
} |
||||
|
||||
if ($request['price'] <= $dis || $validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)]); |
||||
} |
||||
|
||||
|
||||
$tag_ids = []; |
||||
if ($request->tags != null) { |
||||
$tags = explode(",", $request->tags); |
||||
} |
||||
if(isset($tags)){ |
||||
foreach ($tags as $key => $value) { |
||||
$tag = Tag::firstOrNew( |
||||
['tag' => $value] |
||||
); |
||||
$tag->save(); |
||||
array_push($tag_ids,$tag->id); |
||||
} |
||||
} |
||||
|
||||
$p = Food::withoutGlobalScope(RestaurantScope::class)->find($id); |
||||
|
||||
$p->name = $request->name[array_search('en', $request->lang)]; |
||||
|
||||
$category = []; |
||||
if ($request->category_id != null) { |
||||
array_push($category, [ |
||||
'id' => $request->category_id, |
||||
'position' => 1, |
||||
]); |
||||
} |
||||
if ($request->sub_category_id != null) { |
||||
array_push($category, [ |
||||
'id' => $request->sub_category_id, |
||||
'position' => 2, |
||||
]); |
||||
} |
||||
if ($request->sub_sub_category_id != null) { |
||||
array_push($category, [ |
||||
'id' => $request->sub_sub_category_id, |
||||
'position' => 3, |
||||
]); |
||||
} |
||||
|
||||
$p->category_id = $request->sub_category_id?$request->sub_category_id:$request->category_id; |
||||
$p->category_ids = json_encode($category); |
||||
$p->description = $request->description[array_search('en', $request->lang)]; |
||||
|
||||
$choice_options = []; |
||||
if ($request->has('choice')) { |
||||
foreach ($request->choice_no as $key => $no) { |
||||
$str = 'choice_options_' . $no; |
||||
if ($request[$str][0] == null) { |
||||
$validator->getMessageBag()->add('name', translate('messages.attribute_choice_option_value_can_not_be_null')); |
||||
return response()->json(['errors' => Helpers::error_processor($validator)]); |
||||
} |
||||
$item['name'] = 'choice_' . $no; |
||||
$item['title'] = $request->choice[$key]; |
||||
$item['options'] = explode(',', implode('|', preg_replace('/\s+/', ' ', $request[$str]))); |
||||
array_push($choice_options, $item); |
||||
} |
||||
} |
||||
$p->choice_options = json_encode($choice_options); |
||||
|
||||
|
||||
|
||||
$variations = []; |
||||
if(isset($request->options)) |
||||
{ |
||||
foreach(array_values($request->options) as $key=>$option) |
||||
{ |
||||
$temp_variation['name']= $option['name']; |
||||
$temp_variation['type']= $option['type']; |
||||
$temp_variation['min']= $option['min'] ?? 0; |
||||
$temp_variation['max']= $option['max'] ?? 0; |
||||
if($option['min'] > 0 && $option['min'] > $option['max'] ){ |
||||
$validator->getMessageBag()->add('name', translate('messages.minimum_value_can_not_be_greater_then_maximum_value')); |
||||
return response()->json(['errors' => Helpers::error_processor($validator)]); |
||||
} |
||||
if(!isset($option['values'])){ |
||||
$validator->getMessageBag()->add('name', translate('messages.please_add_options_for').$option['name']); |
||||
return response()->json(['errors' => Helpers::error_processor($validator)]); |
||||
} |
||||
if($option['max'] > count($option['values']) ){ |
||||
$validator->getMessageBag()->add('name', translate('messages.please_add_more_options_or_change_the_max_value_for').$option['name']); |
||||
return response()->json(['errors' => Helpers::error_processor($validator)]); |
||||
} |
||||
$temp_variation['required']= $option['required']??'off'; |
||||
$temp_value = []; |
||||
foreach(array_values($option['values']) as $value) |
||||
{ |
||||
if(isset($value['label'])){ |
||||
$temp_option['label'] = $value['label']; |
||||
} |
||||
$temp_option['optionPrice'] = $value['optionPrice']; |
||||
array_push($temp_value,$temp_option); |
||||
} |
||||
$temp_variation['values']= $temp_value; |
||||
array_push($variations,$temp_variation); |
||||
} |
||||
} |
||||
|
||||
|
||||
$slug = Str::slug($request->name[array_search('en', $request->lang)]); |
||||
$p->slug = $p->slug? $p->slug :"{$slug}{$p->id}"; |
||||
//combinations end |
||||
$p->variations = json_encode($variations); |
||||
$p->price = $request->price; |
||||
$p->image = $request->has('image') ? Helpers::update('product/', $p->image, 'png', $request->file('image')) : $p->image; |
||||
$p->available_time_starts = $request->available_time_starts; |
||||
$p->available_time_ends = $request->available_time_ends; |
||||
|
||||
$p->discount = $request->discount_type == 'amount' ? $request->discount : $request->discount; |
||||
$p->discount_type = $request->discount_type; |
||||
|
||||
$p->attributes = $request->has('attribute_id') ? json_encode($request->attribute_id) : json_encode([]); |
||||
$p->add_ons = $request->has('addon_ids') ? json_encode($request->addon_ids) : json_encode([]); |
||||
$p->restaurant_id = $request->restaurant_id; |
||||
$p->veg = $request->veg; |
||||
$p->save(); |
||||
$p->tags()->sync($tag_ids); |
||||
|
||||
foreach ($request->lang as $index => $key) { |
||||
if ($request->name[$index] && $key != 'en') { |
||||
Translation::updateOrInsert( |
||||
['translationable_type' => 'App\Models\Food', |
||||
'translationable_id' => $p->id, |
||||
'locale' => $key, |
||||
'key' => 'name'], |
||||
['value' => $request->name[$index]] |
||||
); |
||||
} |
||||
if ($request->description[$index] && $key != 'en') { |
||||
Translation::updateOrInsert( |
||||
['translationable_type' => 'App\Models\Food', |
||||
'translationable_id' => $p->id, |
||||
'locale' => $key, |
||||
'key' => 'description'], |
||||
['value' => $request->description[$index]] |
||||
); |
||||
} |
||||
} |
||||
|
||||
return response()->json([], 200); |
||||
} |
||||
|
||||
public function delete(Request $request) |
||||
{ |
||||
$product = Food::withoutGlobalScope(RestaurantScope::class)->withoutGlobalScope('translate')->find($request->id); |
||||
|
||||
if($product->image) |
||||
{ |
||||
if (Storage::disk('public')->exists('product/' . $product['image'])) { |
||||
Storage::disk('public')->delete('product/' . $product['image']); |
||||
} |
||||
} |
||||
$product->translations()->delete(); |
||||
$product->delete(); |
||||
Toastr::success(translate('messages.product_deleted_successfully')); |
||||
return back(); |
||||
} |
||||
|
||||
public function variant_combination(Request $request) |
||||
{ |
||||
$options = []; |
||||
$price = $request->price; |
||||
$product_name = $request->name; |
||||
|
||||
if ($request->has('choice_no')) { |
||||
foreach ($request->choice_no as $key => $no) { |
||||
$name = 'choice_options_' . $no; |
||||
$my_str = implode('', $request[$name]); |
||||
array_push($options, explode(',', $my_str)); |
||||
} |
||||
} |
||||
|
||||
$result = [[]]; |
||||
foreach ($options as $property => $property_values) { |
||||
$tmp = []; |
||||
foreach ($result as $result_item) { |
||||
foreach ($property_values as $property_value) { |
||||
$tmp[] = array_merge($result_item, [$property => $property_value]); |
||||
} |
||||
} |
||||
$result = $tmp; |
||||
} |
||||
$combinations = $result; |
||||
return response()->json([ |
||||
'view' => view('admin-views.product.partials._variant-combinations', compact('combinations', 'price', 'product_name'))->render(), |
||||
]); |
||||
} |
||||
|
||||
public function variant_price(Request $request) |
||||
{ |
||||
if($request->item_type=='food') |
||||
{ |
||||
$product = Food::withoutGlobalScope(RestaurantScope::class)->find($request->id); |
||||
} |
||||
else |
||||
{ |
||||
$product = ItemCampaign::find($request->id); |
||||
} |
||||
// $product = Food::withoutGlobalScope(RestaurantScope::class)->find($request->id); |
||||
$str = ''; |
||||
$quantity = 0; |
||||
$price = 0; |
||||
$addon_price = 0; |
||||
|
||||
foreach (json_decode($product->choice_options) as $key => $choice) { |
||||
if ($str != null) { |
||||
$str .= '-' . str_replace(' ', '', $request[$choice->name]); |
||||
} else { |
||||
$str .= str_replace(' ', '', $request[$choice->name]); |
||||
} |
||||
} |
||||
|
||||
if($request['addon_id']) |
||||
{ |
||||
foreach($request['addon_id'] as $id) |
||||
{ |
||||
$addon_price+= $request['addon-price'.$id]*$request['addon-quantity'.$id]; |
||||
} |
||||
} |
||||
|
||||
if ($str != null) { |
||||
$count = count(json_decode($product->variations)); |
||||
for ($i = 0; $i < $count; $i++) { |
||||
if (json_decode($product->variations)[$i]->type == $str) { |
||||
$price = json_decode($product->variations)[$i]->price - Helpers::product_discount_calculate($product, json_decode($product->variations)[$i]->price,$product->restaurant); |
||||
} |
||||
} |
||||
} else { |
||||
$price = $product->price - Helpers::product_discount_calculate($product, $product->price,$product->restaurant); |
||||
} |
||||
|
||||
return array('price' => Helpers::format_currency(($price * $request->quantity)+$addon_price)); |
||||
} |
||||
public function get_categories(Request $request) |
||||
{ |
||||
$cat = Category::where(['parent_id' => $request->parent_id])->get(); |
||||
$res = '<option value="' . 0 . '" disabled selected>---'.translate('messages.Select').'---</option>'; |
||||
foreach ($cat as $row) { |
||||
if ($row->id == $request->sub_category) { |
||||
$res .= '<option value="' . $row->id . '" selected >' . $row->name . '</option>'; |
||||
} else { |
||||
$res .= '<option value="' . $row->id . '">' . $row->name . '</option>'; |
||||
} |
||||
} |
||||
return response()->json([ |
||||
'options' => $res, |
||||
]); |
||||
} |
||||
|
||||
public function get_foods(Request $request) |
||||
{ |
||||
$foods = Food::withoutGlobalScope(RestaurantScope::class)->with('restaurant')->whereHas('restaurant', function($query)use($request){ |
||||
$query->where('zone_id', $request->zone_id); |
||||
})->get(); |
||||
$res = ''; |
||||
if(count($foods)>0 && !$request->data) |
||||
{ |
||||
$res = '<option value="' . 0 . '" disabled selected>---'.translate('messages.Select').'---</option>'; |
||||
} |
||||
|
||||
foreach ($foods as $row) { |
||||
$res .= '<option value="'.$row->id.'" '; |
||||
if($request->data) |
||||
{ |
||||
$res .= in_array($row->id, $request->data)?'selected ':''; |
||||
} |
||||
$res .= '>'.$row->name.' ('.$row->restaurant->name.')'. '</option>'; |
||||
} |
||||
return response()->json([ |
||||
'options' => $res, |
||||
]); |
||||
} |
||||
|
||||
public function list(Request $request) |
||||
{ |
||||
$restaurant_id = $request->query('restaurant_id', 'all'); |
||||
$category_id = $request->query('category_id', 'all'); |
||||
$type = $request->query('type', 'all'); |
||||
$foods = Food::withoutGlobalScope(RestaurantScope::class) |
||||
->when(is_numeric($restaurant_id), function($query)use($restaurant_id){ |
||||
return $query->where('restaurant_id', $restaurant_id); |
||||
}) |
||||
->when(is_numeric($category_id), function($query)use($category_id){ |
||||
return $query->whereHas('category',function($q)use($category_id){ |
||||
return $q->whereId($category_id)->orWhere('parent_id', $category_id); |
||||
}); |
||||
}) |
||||
->type($type) |
||||
->latest()->paginate(config('default_pagination')); |
||||
$restaurant =$restaurant_id !='all'? Restaurant::findOrFail($restaurant_id):null; |
||||
$category =$category_id !='all'? Category::findOrFail($category_id):null; |
||||
return view('admin-views.product.list', compact('foods','restaurant','category', 'type')); |
||||
} |
||||
|
||||
public function search(Request $request){ |
||||
$key = explode(' ', $request['search']); |
||||
if($request->has('restaurant_id')){ |
||||
|
||||
$foods = Food::withoutGlobalScope(RestaurantScope::class) |
||||
->where('restaurant_id', $request->restaurant_id) |
||||
->where(function($q) use($key){ |
||||
foreach ($key as $value) { |
||||
$q->where('name', 'like', "%{$value}%"); |
||||
|
||||
} |
||||
})->limit(50)->get(); |
||||
return response()->json(['count'=>count($foods), |
||||
'view'=>view('admin-views.product.partials._table',compact('foods'))->render() |
||||
]); |
||||
|
||||
} |
||||
$foods=Food::withoutGlobalScope(RestaurantScope::class)->where(function ($q) use ($key) { |
||||
foreach ($key as $value) { |
||||
$q->where('name', 'like', "%{$value}%"); |
||||
} |
||||
})->limit(50)->get(); |
||||
return response()->json(['count'=>count($foods), |
||||
'view'=>view('admin-views.product.partials._table',compact('foods'))->render() |
||||
]); |
||||
} |
||||
public function search_vendor(Request $request){ |
||||
$key = explode(' ', $request['search']); |
||||
if($request->has('restaurant_id')){ |
||||
|
||||
$foods = Food::withoutGlobalScope(RestaurantScope::class) |
||||
->where('restaurant_id', $request->restaurant_id) |
||||
->where(function($q) use($key){ |
||||
foreach ($key as $value) { |
||||
$q->where('name', 'like', "%{$value}%"); |
||||
|
||||
} |
||||
})->limit(50)->get(); |
||||
return response()->json(['count'=>count($foods), |
||||
'view'=>view('admin-views.vendor.view.partials._product',compact('foods'))->render() |
||||
]); |
||||
|
||||
} |
||||
$foods=Food::withoutGlobalScope(RestaurantScope::class)->where(function ($q) use ($key) { |
||||
foreach ($key as $value) { |
||||
$q->where('name', 'like', "%{$value}%"); |
||||
} |
||||
})->limit(50)->get(); |
||||
return response()->json(['count'=>count($foods), |
||||
'view'=>view('admin-views.vendor.view.partials._product',compact('foods'))->render() |
||||
]); |
||||
} |
||||
|
||||
public function review_list(Request $request) |
||||
{ |
||||
$reviews = Review::with(['customer','food'=> function ($q) { |
||||
$q->withoutGlobalScope(RestaurantScope::class); |
||||
}])->latest()->paginate(config('default_pagination')); |
||||
return view('admin-views.product.reviews-list', compact('reviews')); |
||||
} |
||||
|
||||
public function reviews_status(Request $request) |
||||
{ |
||||
$review = Review::find($request->id); |
||||
$review->status = $request->status; |
||||
$review->save(); |
||||
Toastr::success(translate('messages.review_visibility_updated')); |
||||
return back(); |
||||
} |
||||
|
||||
public function bulk_import_index() |
||||
{ |
||||
return view('admin-views.product.bulk-import'); |
||||
} |
||||
|
||||
public function bulk_import_data(Request $request) |
||||
{ |
||||
try { |
||||
$collections = (new FastExcel)->import($request->file('products_file')); |
||||
} catch (\Exception $exception) { |
||||
Toastr::error(translate('messages.you_have_uploaded_a_wrong_format_file')); |
||||
return back(); |
||||
} |
||||
|
||||
$data = []; |
||||
$skip = ['youtube_video_url']; |
||||
foreach ($collections as $collection) { |
||||
if ($collection['name'] === "" || $collection['category_id'] === "" || $collection['sub_category_id'] === "" || $collection['price'] === "" || empty($collection['available_time_starts']) === "" || empty($collection['available_time_ends']) || $collection['restaurant_id'] === "") { |
||||
Toastr::error(translate('messages.please_fill_all_required_fields')); |
||||
return back(); |
||||
} |
||||
|
||||
|
||||
array_push($data, [ |
||||
'name' => $collection['name'], |
||||
'category_id' => $collection['sub_category_id']?$collection['sub_category_id']:$collection['category_id'], |
||||
'category_ids' => json_encode([['id' => $collection['category_id'], 'position' => 0], ['id' => $collection['sub_category_id'], 'position' => 1]]), |
||||
'veg' => $collection['veg']??0, //$request->item_type; |
||||
'price' => $collection['price'], |
||||
'discount' => $collection['discount'], |
||||
'discount_type' => $collection['discount_type'], |
||||
'description' => $collection['description'], |
||||
'available_time_starts' => $collection['available_time_starts'], |
||||
'available_time_ends' => $collection['available_time_ends'], |
||||
'image' => $collection['image'], |
||||
'restaurant_id' => $collection['restaurant_id'], |
||||
'add_ons' => json_encode([]), |
||||
// 'attributes' => json_encode([]), |
||||
// 'choice_options' => json_encode([]), |
||||
'variations' => json_encode([]), |
||||
'created_at'=>now(), |
||||
'updated_at'=>now() |
||||
]); |
||||
} |
||||
try |
||||
{ |
||||
DB::beginTransaction(); |
||||
DB::table('food')->insert($data); |
||||
DB::commit(); |
||||
}catch(\Exception $e){ |
||||
DB::rollBack(); |
||||
Toastr::error(translate('messages.failed_to_import_data')); |
||||
return back(); |
||||
} |
||||
|
||||
Toastr::success(translate('messages.product_imported_successfully', ['count'=>count($data)])); |
||||
return back(); |
||||
} |
||||
|
||||
public function bulk_export_index() |
||||
{ |
||||
return view('admin-views.product.bulk-export'); |
||||
} |
||||
|
||||
public function bulk_export_data(Request $request) |
||||
{ |
||||
$request->validate([ |
||||
'type'=>'required', |
||||
'start_id'=>'required_if:type,id_wise', |
||||
'end_id'=>'required_if:type,id_wise', |
||||
'from_date'=>'required_if:type,date_wise', |
||||
'to_date'=>'required_if:type,date_wise' |
||||
]); |
||||
$products = Food::when($request['type']=='date_wise', function($query)use($request){ |
||||
$query->whereBetween('created_at', [$request['from_date'].' 00:00:00', $request['to_date'].' 23:59:59']); |
||||
}) |
||||
->when($request['type']=='id_wise', function($query)use($request){ |
||||
$query->whereBetween('id', [$request['start_id'], $request['end_id']]); |
||||
}) |
||||
->withoutGlobalScope(RestaurantScope::class)->get(); |
||||
return (new FastExcel(ProductLogic::format_export_foods($products)))->download('Foods.xlsx'); |
||||
} |
||||
|
||||
public function restaurant_food_export($type, $restaurant_id){ |
||||
$food = Food::with('category')->where('restaurant_id', $restaurant_id)->get(); |
||||
//dd($food[0]->category); |
||||
if($type == 'excel'){ |
||||
return (new FastExcel(Helpers::export_restaurant_food($food)))->download('Foods.xlsx'); |
||||
}elseif($type == 'csv'){ |
||||
return (new FastExcel(Helpers::export_restaurant_food($food)))->download('Foods.csv'); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,323 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Admin; |
||||
|
||||
use App\CentralLogics\Helpers; |
||||
use App\Http\Controllers\Controller; |
||||
use App\Models\BusinessSetting; |
||||
use Brian2694\Toastr\Facades\Toastr; |
||||
use Illuminate\Http\Request; |
||||
use Illuminate\Support\Facades\DB; |
||||
use Illuminate\Support\Facades\File; |
||||
use RecursiveDirectoryIterator; |
||||
use RecursiveIteratorIterator; |
||||
use Illuminate\Pagination\Paginator; |
||||
use Illuminate\Support\Collection; |
||||
use Illuminate\Pagination\LengthAwarePaginator; |
||||
|
||||
class LanguageController extends Controller |
||||
{ |
||||
public function index() |
||||
{ $language = BusinessSetting::where('key', 'system_language')->exists(); |
||||
if(!$language){ |
||||
Helpers::insert_business_settings_key('system_language','[{"id":1,"direction":"ltr","code":"en","status":1,"default":true}]'); |
||||
} |
||||
return view('admin-views.business-settings.language.index'); |
||||
} |
||||
|
||||
public function store(Request $request) |
||||
{ |
||||
$language = BusinessSetting::where('key', 'system_language')->first(); |
||||
$lang_array = []; |
||||
$codes = []; |
||||
foreach (json_decode($language['value'], true) as $key => $data) { |
||||
if ($data['code'] != $request['code']) { |
||||
if (!array_key_exists('default', $data)) { |
||||
$default = array('default' => ($data['code'] == 'en') ? true : false); |
||||
$data = array_merge($data, $default); |
||||
} |
||||
array_push($lang_array, $data); |
||||
array_push($codes, $data['code']); |
||||
} |
||||
} |
||||
array_push($codes, $request['code']); |
||||
|
||||
if (!file_exists(base_path('resources/lang/' . $request['code']))) { |
||||
mkdir(base_path('resources/lang/' . $request['code']), 0777, true); |
||||
} |
||||
|
||||
$lang_file = fopen(base_path('resources/lang/' . $request['code'] . '/' . 'messages.php'), "w") or die("Unable to open file!"); |
||||
$read = file_get_contents(base_path('resources/lang/en/messages.php')); |
||||
fwrite($lang_file, $read); |
||||
|
||||
$lang_array[] = [ |
||||
'id' => count(json_decode($language['value'], true)) + 1, |
||||
|
||||
'code' => $request['code'], |
||||
'direction' => $request['direction'], |
||||
'status' => 0, |
||||
'default' => false, |
||||
]; |
||||
|
||||
BusinessSetting::updateOrInsert(['key' => 'system_language'], [ |
||||
'value' => $lang_array |
||||
]); |
||||
|
||||
DB::table('business_settings')->updateOrInsert(['key' => 'language'], [ |
||||
'value' => json_encode($codes), |
||||
]); |
||||
|
||||
Toastr::success('Language Added!'); |
||||
return back(); |
||||
} |
||||
|
||||
public function update_status(Request $request) |
||||
{ |
||||
$language = BusinessSetting::where('key', 'system_language')->first(); |
||||
$lang_array = []; |
||||
foreach (json_decode($language['value'], true) as $key => $data) { |
||||
|
||||
if ($data['code'] == $request['code']) { |
||||
if( array_key_exists('default', $data) && $data['default'] == true ){ |
||||
return response()->json(['error' => 403]); |
||||
} |
||||
$lang = [ |
||||
'id' => $data['id'], |
||||
'direction' => $data['direction'] ?? 'ltr', |
||||
'code' => $data['code'], |
||||
'status' => $data['status'] == 1 ? 0 : 1, |
||||
'default' => (array_key_exists('default', $data) ? $data['default'] : (($data['code'] == 'en') ? true : false)), |
||||
]; |
||||
$lang_array[] = $lang; |
||||
} else { |
||||
$lang = [ |
||||
'id' => $data['id'], |
||||
'direction' => $data['direction'] ?? 'ltr', |
||||
'code' => $data['code'], |
||||
'status' => $data['status'], |
||||
'default' => (array_key_exists('default', $data) ? $data['default'] : (($data['code'] == 'en') ? true : false)), |
||||
]; |
||||
$lang_array[] = $lang; |
||||
} |
||||
} |
||||
$businessSetting = BusinessSetting::where('key', 'system_language')->update([ |
||||
'value' => $lang_array |
||||
]); |
||||
return $businessSetting; |
||||
} |
||||
|
||||
public function update_default_status(Request $request) |
||||
{ |
||||
$language = BusinessSetting::where('key', 'system_language')->first(); |
||||
$lang_array = []; |
||||
foreach (json_decode($language['value'], true) as $key => $data) { |
||||
if ($data['code'] == $request['code']) { |
||||
$lang = [ |
||||
'id' => $data['id'], |
||||
|
||||
'direction' => $data['direction'] ?? 'ltr', |
||||
'code' => $data['code'], |
||||
'status' => 1, |
||||
'default' => true, |
||||
]; |
||||
$lang_array[] = $lang; |
||||
} else { |
||||
$lang = [ |
||||
'id' => $data['id'], |
||||
|
||||
'direction' => $data['direction'] ?? 'ltr', |
||||
'code' => $data['code'], |
||||
'status' => $data['status'], |
||||
'default' => false, |
||||
]; |
||||
$lang_array[] = $lang; |
||||
} |
||||
} |
||||
BusinessSetting::where('key', 'system_language')->update([ |
||||
'value' => $lang_array |
||||
]); |
||||
|
||||
Toastr::success('Default Language Changed!'); |
||||
return back(); |
||||
} |
||||
|
||||
public function update(Request $request) |
||||
{ |
||||
$language = BusinessSetting::where('key', 'system_language')->first(); |
||||
$lang_array = []; |
||||
foreach (json_decode($language['value'], true) as $key => $data) { |
||||
if ($data['code'] == $request['code']) { |
||||
$lang = [ |
||||
'id' => $data['id'], |
||||
|
||||
'direction' => $request['direction'] ?? 'ltr', |
||||
'code' => $data['code'], |
||||
'status' => $data['status'], |
||||
'default' => (array_key_exists('default', $data) ? $data['default'] : (($data['code'] == 'en') ? true : false)), |
||||
]; |
||||
$lang_array[] = $lang; |
||||
} else { |
||||
$lang = [ |
||||
'id' => $data['id'], |
||||
'direction' => $data['direction'] ?? 'ltr', |
||||
'code' => $data['code'], |
||||
'status' => $data['status'], |
||||
'default' => (array_key_exists('default', $data) ? $data['default'] : (($data['code'] == 'en') ? true : false)), |
||||
]; |
||||
$lang_array[] = $lang; |
||||
} |
||||
} |
||||
BusinessSetting::where('key', 'system_language')->update([ |
||||
'value' => $lang_array |
||||
]); |
||||
Toastr::success('Language updated!'); |
||||
return back(); |
||||
} |
||||
|
||||
public function convertArrayToCollection($lang, $items, $perPage = null, $page = null, $options = []) |
||||
{ |
||||
$page = $page ?: (Paginator::resolveCurrentPage() ?: 1); |
||||
$items = $items instanceof Collection ? $items : Collection::make($items); |
||||
$options = [ |
||||
"path" => route('admin.language.translate',[$lang]), |
||||
"pageName" => "page" |
||||
]; |
||||
return new LengthAwarePaginator($items->forPage($page, $perPage), $items->count(), $perPage, $page, $options); |
||||
} |
||||
|
||||
public function translate($lang) |
||||
{ |
||||
$full_data = include(base_path('resources/lang/' . $lang . '/messages.php')); |
||||
ksort($full_data); |
||||
$full_data = $this->convertArrayToCollection($lang,$full_data,config('default_pagination')); |
||||
return view('admin-views.business-settings.language.translate', compact('lang', 'full_data')); |
||||
} |
||||
|
||||
public function translate_key_remove(Request $request, $lang) |
||||
{ |
||||
$full_data = include(base_path('resources/lang/' . $lang . '/messages.php')); |
||||
unset($full_data[$request['key']]); |
||||
$str = "<?php return " . var_export($full_data, true) . ";";
|
||||
file_put_contents(base_path('resources/lang/' . $lang . '/messages.php'), $str); |
||||
} |
||||
|
||||
public function translate_submit(Request $request, $lang) |
||||
{ |
||||
$full_data = include(base_path('resources/lang/' . $lang . '/messages.php')); |
||||
$data_filtered = []; |
||||
foreach ($full_data as $key => $data) { |
||||
$data_filtered[Helpers::remove_invalid_charcaters($key)] = $data; |
||||
} |
||||
$data_filtered[$request['key']] = $request['value']; |
||||
$str = "<?php return " . var_export($data_filtered, true) . ";";
|
||||
file_put_contents(base_path('resources/lang/' . $lang . '/messages.php'), $str); |
||||
} |
||||
|
||||
public function auto_translate(Request $request, $lang): \Illuminate\Http\JsonResponse |
||||
{ |
||||
$lang_code = Helpers::getLanguageCode($lang); |
||||
$full_data = include(base_path('resources/lang/' . $lang . '/messages.php')); |
||||
$data_filtered = []; |
||||
|
||||
foreach ($full_data as $key => $data) { |
||||
$data_filtered[Helpers::remove_invalid_charcaters($key)] = $data; |
||||
} |
||||
|
||||
$translated = Helpers::auto_translator($request['key'], 'en', $lang_code); |
||||
$data_filtered[$request['key']] = $translated; |
||||
|
||||
$str = "<?php return " . var_export($data_filtered, true) . ";";
|
||||
file_put_contents(base_path('resources/lang/' . $lang . '/messages.php'), $str); |
||||
|
||||
return response()->json([ |
||||
'translated_data' => $translated |
||||
]); |
||||
} |
||||
|
||||
public function delete($lang) |
||||
{ |
||||
$language = BusinessSetting::where('key', 'system_language')->first(); |
||||
|
||||
$del_default = false; |
||||
foreach (json_decode($language['value'], true) as $key => $data) { |
||||
if ($data['code'] == $lang && array_key_exists('default', $data) && $data['default'] == true) { |
||||
$del_default = true; |
||||
} |
||||
} |
||||
|
||||
$lang_array = []; |
||||
foreach (json_decode($language['value'], true) as $key => $data) { |
||||
if ($data['code'] != $lang) { |
||||
$lang_data = [ |
||||
'id' => $data['id'], |
||||
|
||||
'direction' => $data['direction'] ?? 'ltr', |
||||
'code' => $data['code'], |
||||
'status' => ($del_default == true && $data['code'] == 'en') ? 1 : $data['status'], |
||||
'default' => ($del_default == true && $data['code'] == 'en') ? true : (array_key_exists('default', $data) ? $data['default'] : (($data['code'] == 'en') ? true : false)), |
||||
]; |
||||
array_push($lang_array, $lang_data); |
||||
} |
||||
} |
||||
|
||||
BusinessSetting::where('key', 'system_language')->update([ |
||||
'value' => $lang_array |
||||
]); |
||||
|
||||
$dir = base_path('resources/lang/' . $lang); |
||||
if (File::isDirectory($dir)) { |
||||
$it = new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS); |
||||
$files = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST); |
||||
foreach ($files as $file) { |
||||
if ($file->isDir()) { |
||||
rmdir($file->getRealPath()); |
||||
} else { |
||||
unlink($file->getRealPath()); |
||||
} |
||||
} |
||||
rmdir($dir); |
||||
} |
||||
|
||||
|
||||
$languages = array(); |
||||
$language = BusinessSetting::where('key', 'language')->first(); |
||||
foreach (json_decode($language['value'], true) as $key => $data) { |
||||
if ($data != $lang) { |
||||
array_push($languages, $data); |
||||
} |
||||
} |
||||
if (in_array('en', $languages)) { |
||||
unset($languages[array_search('en', $languages)]); |
||||
} |
||||
array_unshift($languages, 'en'); |
||||
|
||||
DB::table('business_settings')->updateOrInsert(['key' => 'language'], [ |
||||
'value' => json_encode($languages), |
||||
]); |
||||
|
||||
Toastr::success('Removed Successfully!'); |
||||
return back(); |
||||
} |
||||
|
||||
public function lang($local) |
||||
{ |
||||
$direction = BusinessSetting::where('key', 'site_direction')->first(); |
||||
$direction = $direction->value ?? 'ltr'; |
||||
$language = BusinessSetting::where('key', 'system_language')->first(); |
||||
foreach (json_decode($language['value'], true) as $key => $data) { |
||||
if ($data['code'] == $local) { |
||||
$direction = isset($data['direction']) ? $data['direction'] : 'ltr'; |
||||
} |
||||
} |
||||
session()->forget('language_settings'); |
||||
Helpers::language_load(); |
||||
session()->put('local', $local); |
||||
session()->put('site_direction', $direction); |
||||
|
||||
|
||||
// DB::table('business_settings')->updateOrInsert(['key' => 'site_direction'], [ |
||||
// 'value' => $direction |
||||
// ]); |
||||
return redirect()->back(); |
||||
} |
||||
} |
@ -0,0 +1,40 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Admin; |
||||
|
||||
use App\Http\Controllers\Controller; |
||||
use App\Models\LoyaltyPointTransaction; |
||||
use Illuminate\Http\Request; |
||||
|
||||
class LoyaltyPointController extends Controller |
||||
{ |
||||
public function report(Request $request) |
||||
{ |
||||
$data = LoyaltyPointTransaction::selectRaw('sum(credit) as total_credit, sum(debit) as total_debit') |
||||
->when(($request->from && $request->to),function($query)use($request){ |
||||
$query->whereBetween('created_at', [$request->from.' 00:00:00', $request->to.' 23:59:59']); |
||||
}) |
||||
->when($request->transaction_type, function($query)use($request){ |
||||
$query->where('transaction_type',$request->transaction_type); |
||||
}) |
||||
->when($request->customer_id, function($query)use($request){ |
||||
$query->where('user_id',$request->customer_id); |
||||
}) |
||||
->get(); |
||||
|
||||
$transactions = LoyaltyPointTransaction:: |
||||
when(($request->from && $request->to),function($query)use($request){ |
||||
$query->whereBetween('created_at', [$request->from.' 00:00:00', $request->to.' 23:59:59']); |
||||
}) |
||||
->when($request->transaction_type, function($query)use($request){ |
||||
$query->where('transaction_type',$request->transaction_type); |
||||
}) |
||||
->when($request->customer_id, function($query)use($request){ |
||||
$query->where('user_id',$request->customer_id); |
||||
}) |
||||
->latest() |
||||
->paginate(config('default_pagination')); |
||||
|
||||
return view('admin-views.customer.loyalty-point.report', compact('data','transactions')); |
||||
} |
||||
} |
@ -0,0 +1,179 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Admin; |
||||
|
||||
use App\CentralLogics\Helpers; |
||||
use App\Http\Controllers\Controller; |
||||
use App\Models\Notification; |
||||
use Brian2694\Toastr\Facades\Toastr; |
||||
use Illuminate\Http\Request; |
||||
use Illuminate\Support\Facades\Storage; |
||||
use Illuminate\Support\Facades\Validator; |
||||
use Rap2hpoutre\FastExcel\Facades\FastExcel; |
||||
use Rap2hpoutre\FastExcel\FastExcel as FastExcelFastExcel; |
||||
|
||||
class NotificationController extends Controller |
||||
{ |
||||
function index() |
||||
{ |
||||
$notifications = Notification::latest()->paginate(config('default_pagination')); |
||||
return view('admin-views.notification.index', compact('notifications')); |
||||
} |
||||
|
||||
public function store(Request $request) |
||||
{ |
||||
if (env('APP_MODE') == 'demo') { |
||||
return response()->json(['errors' => Helpers::error_formater('feature-disable', 'This option is disabled for demo!')]); |
||||
} |
||||
$validator = Validator::make($request->all(), [ |
||||
'notification_title' => 'required|max:191', |
||||
'description' => 'required|max:1000', |
||||
'tergat' => 'required', |
||||
'zone'=>'required' |
||||
], [ |
||||
'notification_title.required' => 'Title is required!', |
||||
]); |
||||
|
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)]); |
||||
} |
||||
|
||||
if ($request->has('image')) { |
||||
$image_name = Helpers::upload('notification/', 'png', $request->file('image')); |
||||
} else { |
||||
$image_name = null; |
||||
} |
||||
|
||||
$notification = new Notification; |
||||
$notification->title = $request->notification_title; |
||||
$notification->description = $request->description; |
||||
$notification->image = $image_name; |
||||
$notification->tergat= $request->tergat; |
||||
$notification->status = 1; |
||||
$notification->zone_id = $request->zone=='all'?null:$request->zone; |
||||
$notification->save(); |
||||
|
||||
$topic_all_zone=[ |
||||
'customer'=>'all_zone_customer', |
||||
'deliveryman'=>'all_zone_delivery_man', |
||||
'restaurant'=>'all_zone_restaurant', |
||||
]; |
||||
|
||||
$topic_zone_wise=[ |
||||
'customer'=>'zone_'.$request->zone.'_customer', |
||||
'deliveryman'=>'zone_'.$request->zone.'_delivery_man', |
||||
'restaurant'=>'zone_'.$request->zone.'_restaurant', |
||||
]; |
||||
$topic = $request->zone == 'all'?$topic_all_zone[$request->tergat]:$topic_zone_wise[$request->tergat]; |
||||
|
||||
if($request->has('image')) |
||||
{ |
||||
$notification->image = url('/').'/storage/app/public/notification/'.$image_name; |
||||
} |
||||
|
||||
try { |
||||
Helpers::send_push_notif_to_topic($notification, $topic, 'general'); |
||||
} catch (\Exception $e) { |
||||
Toastr::warning(translate('messages.push_notification_faild')); |
||||
} |
||||
|
||||
return response()->json([], 200); |
||||
} |
||||
|
||||
public function edit($id) |
||||
{ |
||||
$notification = Notification::findOrFail($id); |
||||
return view('admin-views.notification.edit', compact('notification')); |
||||
} |
||||
|
||||
public function update(Request $request, $id) |
||||
{ |
||||
if (env('APP_MODE') == 'demo') { |
||||
Toastr::info(translate('messages.update_option_is_disable_for_demo')); |
||||
return back(); |
||||
} |
||||
$request->validate([ |
||||
'notification_title' => 'required|max:191', |
||||
'description' => 'required|max:1000', |
||||
'tergat' => 'required', |
||||
]); |
||||
|
||||
$notification = Notification::findOrFail($id); |
||||
|
||||
if ($request->has('image')) { |
||||
$image_name = Helpers::update('notification/', $notification->image, 'png', $request->file('image')); |
||||
} else { |
||||
$image_name = $notification['image']; |
||||
} |
||||
|
||||
$notification->title = $request->notification_title; |
||||
$notification->description = $request->description; |
||||
$notification->image = $image_name; |
||||
$notification->tergat= $request->tergat; |
||||
$notification->zone_id = $request->zone=='all'?null:$request->zone; |
||||
$notification->updated_at = now(); |
||||
$notification->save(); |
||||
|
||||
$topic_all_zone=[ |
||||
'customer'=>'all_zone_customer', |
||||
'deliveryman'=>'all_zone_delivery_man', |
||||
'restaurant'=>'all_zone_restaurant', |
||||
]; |
||||
|
||||
$topic_zone_wise=[ |
||||
'customer'=>'zone_'.$request->zone.'_customer', |
||||
'deliveryman'=>'zone_'.$request->zone.'_delivery_man', |
||||
'restaurant'=>'zone_'.$request->zone.'_restaurant', |
||||
]; |
||||
$topic = $request->zone == 'all'?$topic_all_zone[$request->tergat]:$topic_zone_wise[$request->tergat]; |
||||
|
||||
if($request->has('image')) |
||||
{ |
||||
$notification->image = url('/').'/storage/app/public/notification/'.$image_name; |
||||
} |
||||
|
||||
try { |
||||
Helpers::send_push_notif_to_topic($notification, $topic, 'general'); |
||||
} catch (\Exception $e) { |
||||
Toastr::warning(translate('messages.push_notification_faild')); |
||||
} |
||||
Toastr::success(translate('messages.notification').' '.translate('messages.updated_successfully')); |
||||
return back(); |
||||
} |
||||
|
||||
public function status(Request $request) |
||||
{ |
||||
$notification = Notification::findOrFail($request->id); |
||||
$notification->status = $request->status; |
||||
$notification->save(); |
||||
Toastr::success(translate('messages.notification_status_updated')); |
||||
return back(); |
||||
} |
||||
|
||||
public function delete(Request $request) |
||||
{ |
||||
$notification = Notification::findOrFail($request->id); |
||||
if (Storage::disk('public')->exists('notification/' . $notification['image'])) { |
||||
Storage::disk('public')->delete('notification/' . $notification['image']); |
||||
} |
||||
$notification->delete(); |
||||
Toastr::success(translate('messages.notification_deleted_successfully')); |
||||
return back(); |
||||
} |
||||
|
||||
public function export(Request $request){ |
||||
$notifications = Notification::with('zone')->get(); |
||||
//dd($notifications); |
||||
|
||||
$data = Helpers::push_notification_export_data($notifications); |
||||
|
||||
/* foreach($notifications as $notification){ |
||||
echo $notification; |
||||
} */ |
||||
if($request->type == 'excel'){ |
||||
return (new FastExcelFastExcel($data))->download('Notifications.xlsx'); |
||||
}elseif($request->type == 'csv'){ |
||||
return (new FastExcelFastExcel($data))->download('Notifications.csv'); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,63 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Admin; |
||||
|
||||
use Illuminate\Http\Request; |
||||
use App\Models\OrderCancelReason; |
||||
use App\Http\Controllers\Controller; |
||||
use Brian2694\Toastr\Facades\Toastr; |
||||
|
||||
class OrderCancelReasonController extends Controller |
||||
{ |
||||
public function index() |
||||
{ |
||||
$reasons = OrderCancelReason::latest()->paginate(config('default_pagination')); |
||||
return view('admin-views.order.cancelation-reason', compact('reasons')); |
||||
} |
||||
public function store(Request $request) |
||||
{ |
||||
$request->validate([ |
||||
'reason'=>'required|max:255', |
||||
'user_type' =>'required|max:50', |
||||
]); |
||||
$cancelReason = new OrderCancelReason(); |
||||
$cancelReason->reason = $request->reason; |
||||
$cancelReason->user_type=$request->user_type; |
||||
$cancelReason->created_at = now(); |
||||
$cancelReason->updated_at = now(); |
||||
$cancelReason->save(); |
||||
|
||||
Toastr::success(translate('messages.order_cancellation_reason_added_successfully')); |
||||
return back(); |
||||
} |
||||
public function destroy($cancelReason) |
||||
{ |
||||
$cancelReason = OrderCancelReason::findOrFail($cancelReason); |
||||
$cancelReason->delete(); |
||||
Toastr::success(translate('messages.order_cancellation_reason_deleted_successfully')); |
||||
return back(); |
||||
} |
||||
|
||||
public function status(Request $request) |
||||
{ |
||||
$cancelReason = OrderCancelReason::findOrFail($request->id); |
||||
$cancelReason->status = $request->status; |
||||
$cancelReason->save(); |
||||
Toastr::success(translate('messages.status_updated')); |
||||
return back(); |
||||
} |
||||
public function update(Request $request) |
||||
{ |
||||
$request->validate([ |
||||
'reason' => 'required|max:255', |
||||
'user_type' =>'required|max:50', |
||||
]); |
||||
$cancelReason = OrderCancelReason::findOrFail($request->reason_id); |
||||
$cancelReason->reason = $request->reason; |
||||
$cancelReason->user_type=$request->user_type; |
||||
$cancelReason->save(); |
||||
|
||||
Toastr::success(translate('order_cancellation_reason_updated_successfully')); |
||||
return back(); |
||||
} |
||||
} |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,128 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Admin; |
||||
|
||||
use Exception; |
||||
use App\Models\Order; |
||||
use App\Models\Subscription; |
||||
use Illuminate\Http\Request; |
||||
use Illuminate\Support\Carbon; |
||||
use App\Models\BusinessSetting; |
||||
use App\Models\OrderCancelReason; |
||||
use App\Models\SubscriptionPause; |
||||
use Illuminate\Support\Facades\DB; |
||||
use App\Http\Controllers\Controller; |
||||
use Brian2694\Toastr\Facades\Toastr; |
||||
|
||||
class OrderSubscriptionController extends Controller |
||||
{ |
||||
public function index(Request $request) |
||||
{ |
||||
$order_subs= BusinessSetting::where('key', 'order_subscription')->first(); |
||||
$cash_on_delivery= BusinessSetting::where('key', 'cash_on_delivery')->first(); |
||||
// $subs_o= Order::whereNotNull('subscription_id')->count(); |
||||
|
||||
// if (!isset($order_subs) || ($order_subs->value != 1 && $cash_on_delivery->value != 1) ) { |
||||
// Toastr::error(translate('messages.You_must_turn_on_Order_subscription_form_the_Business_settings_and_also_Cash_on_delivery_must_be_Enabled')); |
||||
// return back(); |
||||
// } |
||||
$key = explode(' ', $request['search']); |
||||
$subscriptions = Subscription::with(['customer', 'restaurant', 'order.details']) |
||||
->when(isset($request['search']), function ($query) use($key){ |
||||
$query->whereHas('order',function ($qu) use ($key){ |
||||
foreach ($key as $value) { |
||||
$qu->Where('id', 'like', "%{$value}%"); |
||||
} |
||||
}); |
||||
})->orderBy('created_at', 'desc') |
||||
->paginate(config('default_pagination')); |
||||
return view('admin-views.order-subscription.index', compact('subscriptions')); |
||||
} |
||||
public function show(Request $request, Subscription $subscription) |
||||
{ |
||||
$tab = $request->query('tab', 'info'); |
||||
return view('admin-views.order-subscription.view', compact('subscription', 'tab')); |
||||
} |
||||
public function edit(Subscription $subscription) |
||||
{ |
||||
return response()->json($subscription); |
||||
} |
||||
public function update(Request $request, Subscription $subscription) |
||||
{ |
||||
$request->validate([ |
||||
'status' => 'required|in:active,paused,canceled', |
||||
'start_date' => 'required_if:status,paused|date|after_or_equal:today', |
||||
'end_date' => 'required_if:status,paused|date|after_or_equal:start_date' |
||||
]); |
||||
|
||||
DB::beginTransaction(); |
||||
try{ |
||||
if($request->status == 'paused'){ |
||||
if($subscription->pause()->checkDate($request->start_date, $request->end_date)->count()) |
||||
{ |
||||
Toastr::error(translate('messages.subscription_pause_log_overlap_warning')); |
||||
return back(); |
||||
} |
||||
$subscription->pause()->updateOrInsert(['from'=>$request->start_date, 'subscription_id'=>$subscription->id],['to'=>$request->end_date]); |
||||
} |
||||
|
||||
elseif ($request->status == 'canceled' && isset($subscription->order)) { |
||||
|
||||
$subscription->order()->update([ |
||||
'order_status' => $request->status, |
||||
'canceled' => now(), |
||||
'cancellation_note' => $request->note ?? null, |
||||
'cancellation_reason' => $request->reason ?? null, |
||||
'canceled_by' => 'admin', |
||||
]); |
||||
if($subscription->log){ |
||||
$subscription->log()->update([ |
||||
'order_status' => $request->status, |
||||
'canceled' => now(), |
||||
]); |
||||
} |
||||
$subscription->status = $request->status; |
||||
} |
||||
elseif ($request->status == 'active' && isset($subscription->order)) { |
||||
|
||||
$subscription->order()->update([ |
||||
'order_status' => 'pending', |
||||
'canceled' => null, |
||||
'pending' => now(), |
||||
]); |
||||
$subscription->status = $request->status; |
||||
} |
||||
|
||||
|
||||
|
||||
else { |
||||
$subscription->status = $request->status; |
||||
} |
||||
$subscription->save(); |
||||
DB::commit(); |
||||
Toastr::success(translate('messages.subscription_updated_successfully')); |
||||
return back(); |
||||
}catch(Exception $ex){ |
||||
DB::rollBack(); |
||||
info($ex); |
||||
Toastr::error($ex->getMessage()); |
||||
return back(); |
||||
} |
||||
|
||||
Toastr::error(translate('messages.failed_updated_subscription')); |
||||
return back(); |
||||
} |
||||
public function pause_log_delete($id){ |
||||
$sub=SubscriptionPause::where('id',$id)->first(); |
||||
$current_date = date('Y-m-d'); |
||||
|
||||
$from = Carbon::parse($sub->from); |
||||
if($sub && $from->gt($current_date) ){ |
||||
$sub->delete(); |
||||
Toastr::success(translate('messages.pause_log_deleted_successfully')); |
||||
return back(); |
||||
} |
||||
Toastr::error(translate('messages.you_can_not_delete_this_time_log')); |
||||
return back(); |
||||
} |
||||
} |
@ -0,0 +1,630 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Admin; |
||||
|
||||
use Carbon\Carbon; |
||||
use App\Models\Food; |
||||
use App\Models\User; |
||||
use App\Models\Zone; |
||||
use App\Models\Order; |
||||
use App\Models\Vehicle; |
||||
use App\Models\Category; |
||||
use App\Models\Restaurant; |
||||
use App\Models\OrderDetail; |
||||
use Illuminate\Http\Request; |
||||
use App\CentralLogics\Helpers; |
||||
use App\Models\BusinessSetting; |
||||
use App\Scopes\RestaurantScope; |
||||
use Illuminate\Support\Facades\DB; |
||||
use App\CentralLogics\CustomerLogic; |
||||
use App\Http\Controllers\Controller; |
||||
use Brian2694\Toastr\Facades\Toastr; |
||||
use Illuminate\Support\Facades\Mail; |
||||
use Illuminate\Support\Facades\Validator; |
||||
|
||||
class POSController extends Controller |
||||
{ |
||||
public function index(Request $request) |
||||
{ |
||||
$time = Carbon::now()->toTimeString(); |
||||
$zone_id = $request->query('zone_id', null); |
||||
$restaurant_id = $request->query('restaurant_id', null); |
||||
$zone = is_numeric($zone_id) ? Zone::findOrFail($zone_id) : null; |
||||
$restaurant_data = Restaurant::active()->with('restaurant_sub')->where('zone_id', $zone_id)->find($restaurant_id); |
||||
$category = $request->query('category_id', 0); |
||||
$categories = Category::active()->get(); |
||||
$keyword = $request->query('keyword', false); |
||||
$key = explode(' ', $keyword); |
||||
|
||||
if ($request->session()->has('cart')) { |
||||
$cart = $request->session()->get('cart', collect([])); |
||||
if (!isset($cart['restaurant_id']) || $cart['restaurant_id'] != $restaurant_id) { |
||||
session()->forget('cart'); |
||||
session()->forget('address'); |
||||
} |
||||
} |
||||
|
||||
$products = Food::withoutGlobalScope(RestaurantScope::class)->active()->when($category, function ($query) use ($category) { |
||||
$query->whereHas('category', function ($q) use ($category) { |
||||
return $q->whereId($category)->orWhere('parent_id', $category); |
||||
}); |
||||
}) |
||||
->where(['restaurant_id' => $restaurant_id]) |
||||
->when(isset($zone), function ($query) use ($zone) { |
||||
return $query->whereIn('restaurant_id', $zone->restaurants->pluck('id')); |
||||
}) |
||||
->when($keyword, function ($query) use ($key) { |
||||
return $query->where(function ($q) use ($key) { |
||||
foreach ($key as $value) { |
||||
$q->orWhere('name', 'like', "%{$value}%"); |
||||
} |
||||
}); |
||||
})->available($time) |
||||
->latest()->paginate(10); |
||||
|
||||
return view('admin-views.pos.index', compact('categories', 'products', 'category', 'keyword', 'restaurant_data', 'zone')); |
||||
} |
||||
|
||||
public function quick_view(Request $request) |
||||
{ |
||||
$product = Food::withoutGlobalScope(RestaurantScope::class)->with('restaurant')->findOrFail($request->product_id); |
||||
return response()->json([ |
||||
'success' => 1, |
||||
'view' => view('admin-views.pos._quick-view-data', compact('product'))->render(), |
||||
]); |
||||
} |
||||
|
||||
|
||||
public function quick_view_card_item(Request $request) |
||||
{ |
||||
$product = Food::withoutGlobalScope(RestaurantScope::class)->findOrFail($request->product_id); |
||||
//dd($product); |
||||
$item_key = $request->item_key; |
||||
$cart_item = session()->get('cart')[$item_key]; |
||||
|
||||
return response()->json([ |
||||
'success' => 1, |
||||
'view' => view('admin-views.pos._quick-view-cart-item', compact('product', 'cart_item', 'item_key'))->render(), |
||||
]); |
||||
} |
||||
|
||||
public function variant_price(Request $request) |
||||
{ |
||||
$product = Food::withoutGlobalScope(RestaurantScope::class)->with('restaurant')->where(['id' => $request->id])->first(); |
||||
$price = $product->price; |
||||
$addon_price = 0; |
||||
|
||||
if ($request['addon_id']) { |
||||
foreach ($request['addon_id'] as $id) { |
||||
$addon_price += $request['addon-price' . $id] * $request['addon-quantity' . $id]; |
||||
} |
||||
} |
||||
$product_variations = json_decode($product->variations, true); |
||||
if ($request->variations && count($product_variations)) { |
||||
|
||||
$price_total = $price + Helpers::variation_price($product_variations, $request->variations); |
||||
$price= $price_total - Helpers::product_discount_calculate($product, $price_total, $product->restaurant); |
||||
} else { |
||||
$price = $product->price - Helpers::product_discount_calculate($product, $product->price, $product->restaurant); |
||||
} |
||||
return array('price' => Helpers::format_currency(($price * $request->quantity) + $addon_price)); |
||||
} |
||||
|
||||
public function addToCart(Request $request) |
||||
{ |
||||
$product = Food::with('restaurant')->withoutGlobalScope(RestaurantScope::class)->where(['id' => $request->id])->first(); |
||||
$data = array(); |
||||
$data['id'] = $product->id; |
||||
$str = ''; |
||||
$variations = []; |
||||
$price = 0; |
||||
$addon_price = 0; |
||||
$variation_price=0; |
||||
|
||||
$product_variations = json_decode($product->variations, true); |
||||
if ($request->variations && count($product_variations)) { |
||||
foreach($request->variations as $key=> $value ){ |
||||
|
||||
if($value['required'] == 'on' && isset($value['values']) == false){ |
||||
return response()->json([ |
||||
'data' => 'variation_error', |
||||
'message' => translate('Please select items from') . ' ' . $value['name'], |
||||
]); |
||||
} |
||||
if(isset($value['values']) && $value['min'] != 0 && $value['min'] > count($value['values']['label'])){ |
||||
return response()->json([ |
||||
'data' => 'variation_error', |
||||
'message' => translate('Please select minimum ').$value['min'].translate(' For ').$value['name'].'.', |
||||
]); |
||||
} |
||||
if(isset($value['values']) && $value['max'] != 0 && $value['max'] < count($value['values']['label'])){ |
||||
return response()->json([ |
||||
'data' => 'variation_error', |
||||
'message' => translate('Please select maximum ').$value['max'].translate(' For ').$value['name'].'.', |
||||
]); |
||||
} |
||||
} |
||||
$variation_data = Helpers::get_varient($product_variations, $request->variations); |
||||
$variation_price = $variation_data['price']; |
||||
$variations = $request->variations; |
||||
} |
||||
$data['variations'] = $variations; |
||||
$data['variant'] = $str; |
||||
|
||||
$price = $product->price + $variation_price; |
||||
$data['variation_price'] = $variation_price; |
||||
$data['quantity'] = $request['quantity']; |
||||
$data['price'] = $price; |
||||
$data['name'] = $product->name; |
||||
$data['discount'] = Helpers::product_discount_calculate($product, $price, $product->restaurant); |
||||
$data['image'] = $product->image; |
||||
$data['add_ons'] = []; |
||||
$data['add_on_qtys'] = []; |
||||
|
||||
if ($request['addon_id']) { |
||||
foreach ($request['addon_id'] as $id) { |
||||
$addon_price += $request['addon-price' . $id] * $request['addon-quantity' . $id]; |
||||
$data['add_on_qtys'][] = $request['addon-quantity' . $id]; |
||||
} |
||||
$data['add_ons'] = $request['addon_id']; |
||||
} |
||||
|
||||
$data['addon_price'] = $addon_price; |
||||
|
||||
if ($request->session()->has('cart')) { |
||||
$cart = $request->session()->get('cart', collect([])); |
||||
if (isset($request->cart_item_key)) { |
||||
$cart[$request->cart_item_key] = $data; |
||||
$data = 2; |
||||
} else { |
||||
$cart->push($data); |
||||
} |
||||
} else { |
||||
$cart = collect([$data,'restaurant_id'=>$product->restaurant_id]); |
||||
$request->session()->put('cart', $cart); |
||||
} |
||||
|
||||
return response()->json([ |
||||
'data' => $data |
||||
]); |
||||
} |
||||
|
||||
public function addDeliveryInfo(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(),[ |
||||
'contact_person_name' => 'required', |
||||
'contact_person_number' => 'required', |
||||
'floor' => 'required', |
||||
'road' => 'required', |
||||
'house' => 'required', |
||||
'delivery_fee' => 'required', |
||||
'longitude' => 'required', |
||||
'latitude' => 'required', |
||||
]); |
||||
|
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)]); |
||||
} |
||||
|
||||
$address = [ |
||||
'contact_person_name' => $request->contact_person_name, |
||||
'contact_person_number' => $request->contact_person_number, |
||||
'address_type' => 'delivery', |
||||
'address' => $request->address, |
||||
'floor' => $request->floor, |
||||
'road' => $request->road, |
||||
'house' => $request->house, |
||||
'delivery_fee' => $request->delivery_fee, |
||||
'distance' => $request->distance, |
||||
'longitude' => (string)$request->longitude, |
||||
'latitude' => (string)$request->latitude, |
||||
]; |
||||
|
||||
$request->session()->put('address', $address); |
||||
|
||||
return response()->json([ |
||||
'data' => $address, |
||||
'view' => view('admin-views.pos._address', compact('address'))->render(), |
||||
]); |
||||
} |
||||
|
||||
public function cart_items(Request $request) |
||||
{ |
||||
$restaurant_data = Restaurant::find($request->restaurant_id); |
||||
return view('admin-views.pos._cart', compact('restaurant_data')); |
||||
} |
||||
|
||||
//removes from Cart |
||||
public function removeFromCart(Request $request) |
||||
{ |
||||
if ($request->session()->has('cart')) { |
||||
$cart = $request->session()->get('cart', collect([])); |
||||
$cart->forget($request->key); |
||||
$request->session()->put('cart', $cart); |
||||
} |
||||
|
||||
return response()->json([], 200); |
||||
} |
||||
|
||||
//updated the quantity for a cart item |
||||
public function updateQuantity(Request $request) |
||||
{ |
||||
$cart = $request->session()->get('cart', collect([])); |
||||
$cart = $cart->map(function ($object, $key) use ($request) { |
||||
if ($key == $request->key) { |
||||
$object['quantity'] = $request->quantity; |
||||
} |
||||
return $object; |
||||
}); |
||||
$request->session()->put('cart', $cart); |
||||
return response()->json([], 200); |
||||
} |
||||
|
||||
//empty Cart |
||||
public function emptyCart(Request $request) |
||||
{ |
||||
session()->forget('cart'); |
||||
session()->forget('address'); |
||||
return response()->json([], 200); |
||||
} |
||||
|
||||
public function update_tax(Request $request) |
||||
{ |
||||
$cart = $request->session()->get('cart', collect([])); |
||||
$cart['tax'] = $request->tax; |
||||
$request->session()->put('cart', $cart); |
||||
return back(); |
||||
} |
||||
|
||||
public function update_paid(Request $request) |
||||
{ |
||||
$cart = $request->session()->get('cart', collect([])); |
||||
$cart['paid'] = $request->paid; |
||||
$request->session()->put('cart', $cart); |
||||
return back(); |
||||
} |
||||
|
||||
public function update_discount(Request $request) |
||||
{ |
||||
$cart = $request->session()->get('cart', collect([])); |
||||
$cart['discount'] = $request->discount; |
||||
$cart['discount_type'] = $request->type; |
||||
$request->session()->put('cart', $cart); |
||||
return back(); |
||||
} |
||||
|
||||
public function get_customers(Request $request) |
||||
{ |
||||
$key = explode(' ', $request['q']); |
||||
$data = User::where(function ($q) use ($key) { |
||||
foreach ($key as $value) { |
||||
$q->orWhere('f_name', 'like', "%{$value}%") |
||||
->orWhere('l_name', 'like', "%{$value}%") |
||||
->orWhere('phone', 'like', "%{$value}%"); |
||||
} |
||||
}) |
||||
->limit(8) |
||||
->get([DB::raw('id, CONCAT(f_name, " ", l_name, " (", phone ,")") as text')]); |
||||
|
||||
return response()->json($data); |
||||
} |
||||
|
||||
public function place_order(Request $request) |
||||
{ |
||||
if(!$request->user_id){ |
||||
Toastr::error(translate('messages.no_customer_selected')); |
||||
return back(); |
||||
} |
||||
if(!$request->type){ |
||||
Toastr::error(translate('No payment method selected')); |
||||
return back(); |
||||
} |
||||
if ($request->session()->has('cart')) { |
||||
if (count($request->session()->get('cart')) < 2) { |
||||
Toastr::error(translate('messages.cart_empty_warning')); |
||||
return back(); |
||||
} |
||||
} else { |
||||
Toastr::error(translate('messages.cart_empty_warning')); |
||||
return back(); |
||||
} |
||||
if ($request->session()->has('address')) { |
||||
$address = $request->session()->get('address'); |
||||
}else { |
||||
if(!isset($address['delivery_fee'])){ |
||||
Toastr::error(translate('messages.please_select_a_valid_delivery_location_on_the_map')); |
||||
return back(); |
||||
} |
||||
Toastr::error(translate('messages.delivery_information_warning')); |
||||
return back(); |
||||
} |
||||
if($request->type == 'wallet' && Helpers::get_business_settings('wallet_status', false) != 1) |
||||
{ |
||||
Toastr::error(translate('messages.customer_wallet_disable_warning')); |
||||
} |
||||
$restaurant = Restaurant::find($request->restaurant_id); |
||||
if(!$restaurant){ |
||||
Toastr::error(translate('messages.Sorry_the_restaurant_is_not_available')); |
||||
return back(); |
||||
} |
||||
|
||||
$rest_sub=$restaurant->restaurant_sub; |
||||
if ( $restaurant->restaurant_model == 'subscription' && isset($rest_sub)) { |
||||
if($rest_sub->max_order != "unlimited" && $rest_sub->max_order <= 0){ |
||||
Toastr::error(translate('messages.The_restaurant_has_reached_the_maximum_number_of_orders')); |
||||
return back(); |
||||
} |
||||
} elseif($restaurant->restaurant_model == 'unsubscribed'){ |
||||
Toastr::error(translate('messages.The_restaurant_is_not_subscribed_or_subscription_has_expired')); |
||||
return back(); |
||||
} |
||||
|
||||
$cart = $request->session()->get('cart'); |
||||
$total_addon_price = 0; |
||||
$product_price = 0; |
||||
$restaurant_discount_amount = 0; |
||||
|
||||
$order_details = []; |
||||
$order = new Order(); |
||||
$order->id = 100000 + Order::all()->count() + 1; |
||||
if (Order::find($order->id)) { |
||||
$order->id = Order::latest()->first()->id + 1; |
||||
} |
||||
$order->distance = isset($address) ? $address['distance'] : 0; |
||||
$order->payment_status = $request->type == 'wallet'?'paid':'unpaid'; |
||||
$order->order_status = $request->type == 'wallet'?'confirmed':'pending'; |
||||
$order->order_type = 'delivery'; |
||||
$order->restaurant_id = $restaurant->id; |
||||
$order->user_id = $request->user_id; |
||||
$order->delivery_charge = isset($address)?$address['delivery_fee']:0; |
||||
$order->original_delivery_charge = isset($address)?$address['delivery_fee']:0; |
||||
$order->delivery_address = isset($address)?json_encode($address):null; |
||||
$order->checked = 1; |
||||
$order->schedule_at = now(); |
||||
$order->created_at = now(); |
||||
$order->updated_at = now(); |
||||
$order->otp = rand(1000, 9999); |
||||
foreach ($cart as $c) { |
||||
if (is_array($c)) { |
||||
$product = Food::withoutGlobalScope(RestaurantScope::class)->with('restaurant')->find($c['id']); |
||||
// dd($product->variations); |
||||
if ($product) { |
||||
$price = $c['price']; |
||||
$product->tax = $product->restaurant->tax; |
||||
$product = Helpers::product_data_formatting($product); |
||||
$addon_data = Helpers::calculate_addon_price(\App\Models\AddOn::withOutGlobalScope(App\Scopes\RestaurantScope::class)->whereIn('id', $c['add_ons'])->get(), $c['add_on_qtys']); |
||||
|
||||
$variation_data = Helpers::get_varient($product->variations, $c['variations']); |
||||
$variations = $variation_data['variations']; |
||||
$or_d = [ |
||||
'food_id' => $c['id'], |
||||
'item_campaign_id' => null, |
||||
'food_details' => json_encode($product), |
||||
'quantity' => $c['quantity'], |
||||
'price' => $price, |
||||
'tax_amount' => Helpers::tax_calculate($product, $price), |
||||
'discount_on_food' => Helpers::product_discount_calculate($product, $price, $product->restaurant), |
||||
'discount_type' => 'discount_on_product', |
||||
// 'variant' => json_encode($c['variant']), |
||||
'variation' => json_encode($variations), |
||||
// 'variation' => json_encode(count($c['variations']) ? $c['variations'] : []), |
||||
'add_ons' => json_encode($addon_data['addons']), |
||||
'total_add_on_price' => $addon_data['total_add_on_price'], |
||||
'created_at' => now(), |
||||
'updated_at' => now() |
||||
]; |
||||
$total_addon_price += $or_d['total_add_on_price']; |
||||
$product_price += $price * $or_d['quantity']; |
||||
$restaurant_discount_amount += $or_d['discount_on_food'] * $or_d['quantity']; |
||||
$order_details[] = $or_d; |
||||
} |
||||
} |
||||
} |
||||
|
||||
|
||||
$order->discount_on_product_by = 'vendor'; |
||||
$restaurant_discount = Helpers::get_restaurant_discount($restaurant); |
||||
if(isset($restaurant_discount)){ |
||||
$order->discount_on_product_by = 'admin'; |
||||
} |
||||
|
||||
if (isset($cart['discount'])) { |
||||
$restaurant_discount_amount += $cart['discount_type'] == 'percent' && $cart['discount'] > 0 ? ((($product_price + $total_addon_price - $restaurant_discount_amount) * $cart['discount']) / 100) : $cart['discount']; |
||||
} |
||||
|
||||
$total_price = $product_price + $total_addon_price - $restaurant_discount_amount; |
||||
$tax = isset($cart['tax']) ? $cart['tax'] : $restaurant->tax; |
||||
// $total_tax_amount = ($tax > 0) ? (($total_price * $tax) / 100) : 0; |
||||
|
||||
|
||||
$order->tax_status = 'excluded'; |
||||
|
||||
$tax_included =BusinessSetting::where(['key'=>'tax_included'])->first() ? BusinessSetting::where(['key'=>'tax_included'])->first()->value : 0; |
||||
if ($tax_included == 1){ |
||||
$order->tax_status = 'included'; |
||||
} |
||||
|
||||
$total_tax_amount=Helpers::product_tax($total_price,$tax,$order->tax_status =='included'); |
||||
$tax_a=$order->tax_status =='included'?0:$total_tax_amount; |
||||
|
||||
try { |
||||
$order->restaurant_discount_amount = $restaurant_discount_amount; |
||||
$order->total_tax_amount = $total_tax_amount; |
||||
|
||||
// $tax_a=$total_tax_amount; |
||||
// $order->tax_status = 'excluded' ; |
||||
// $tax_included =BusinessSetting::where(['key'=>'tax_included'])->first() ? BusinessSetting::where(['key'=>'tax_included'])->first()->value : 0; |
||||
// if ($tax_included == 1){ |
||||
// $tax_a=0; |
||||
// $order->tax_status = 'included'; |
||||
// } |
||||
|
||||
$order->order_amount = $total_price + $tax_a + $order->delivery_charge; |
||||
|
||||
|
||||
$order->payment_method = $request->type == 'wallet'?'wallet':'cash_on_delivery'; |
||||
$order->adjusment = $order->order_amount; |
||||
|
||||
$max_cod_order_amount = BusinessSetting::where('key', 'max_cod_order_amount')->first(); |
||||
$max_cod_order_amount_value= $max_cod_order_amount ? $max_cod_order_amount->value : 0; |
||||
if( $max_cod_order_amount_value > 0 && $order->payment_method == 'cash_on_delivery' && $order->order_amount > $max_cod_order_amount_value){ |
||||
Toastr::error(translate('messages.You can not Order more then ').$max_cod_order_amount_value .Helpers::currency_symbol().' '. translate('messages.on COD order.') ); |
||||
return back(); |
||||
} |
||||
|
||||
if($request->type == 'wallet'){ |
||||
if($request->user_id){ |
||||
|
||||
$customer = User::find($request->user_id); |
||||
if($customer->wallet_balance < $order->order_amount){ |
||||
Toastr::error(translate('messages.insufficient_wallet_balance')); |
||||
return back(); |
||||
}else{ |
||||
CustomerLogic::create_wallet_transaction($order->user_id, $order->order_amount, 'order_place', $order->id); |
||||
} |
||||
}else{ |
||||
Toastr::error(translate('messages.no_customer_selected')); |
||||
return back(); |
||||
} |
||||
}; |
||||
|
||||
|
||||
|
||||
|
||||
$order->save(); |
||||
foreach ($order_details as $key => $item) { |
||||
$order_details[$key]['order_id'] = $order->id; |
||||
} |
||||
OrderDetail::insert($order_details); |
||||
session()->forget('cart'); |
||||
session()->forget('address'); |
||||
session(['last_order' => $order->id]); |
||||
|
||||
if ($restaurant->restaurant_model == 'subscription' && isset($rest_sub)) { |
||||
if ($rest_sub->max_order != "unlimited" && $rest_sub->max_order > 0 ) { |
||||
$rest_sub->decrement('max_order' , 1); |
||||
// if ( $rest_sub->max_order <= 0 ){ |
||||
// $restaurant->update(['status' => 0]); |
||||
// } |
||||
} |
||||
} |
||||
Toastr::success(translate('messages.order_placed_successfully')); |
||||
return back(); |
||||
} catch (\Exception $e) { |
||||
info($e); |
||||
} |
||||
Toastr::warning(translate('messages.failed_to_place_order')); |
||||
return back(); |
||||
} |
||||
|
||||
public function order_list() |
||||
{ |
||||
$orders = Order::with(['customer']) |
||||
->where('order_type', 'pos') |
||||
->latest() |
||||
->paginate(config('default_pagination')); |
||||
//dd($orders); |
||||
return view('admin-views.pos.order.list', compact('orders')); |
||||
} |
||||
|
||||
public function search(Request $request) |
||||
{ |
||||
$key = explode(' ', $request['search']); |
||||
$orders = Order::where(function ($q) use ($key) { |
||||
foreach ($key as $value) { |
||||
$q->orWhere('id', 'like', "%{$value}%") |
||||
->orWhere('order_status', 'like', "%{$value}%") |
||||
->orWhere('transaction_reference', 'like', "%{$value}%"); |
||||
} |
||||
})->pos()->limit(100)->get(); |
||||
return response()->json([ |
||||
'view' => view('admin-views.pos.order.partials._table', compact('orders'))->render() |
||||
]); |
||||
} |
||||
|
||||
public function order_details($id) |
||||
{ |
||||
$order = Order::with(['details', 'restaurant' => function ($query) { |
||||
return $query->withCount('orders'); |
||||
}, 'customer' => function ($query) { |
||||
return $query->withCount('orders'); |
||||
}, 'details.food' => function ($query) { |
||||
return $query->withoutGlobalScope(RestaurantScope::class); |
||||
}])->where(['id' => $id])->first(); |
||||
//dd($order); |
||||
if (isset($order)) { |
||||
return view('admin-views.pos.order.order-view', compact('order')); |
||||
} else { |
||||
Toastr::info('No more orders!'); |
||||
return back(); |
||||
} |
||||
} |
||||
|
||||
public function generate_invoice($id) |
||||
{ |
||||
$order = Order::with(['details', 'restaurant' => function ($query) { |
||||
return $query->withCount('orders'); |
||||
}, 'customer' => function ($query) { |
||||
return $query->withCount('orders'); |
||||
}, 'details.food' => function ($query) { |
||||
return $query->withoutGlobalScope(RestaurantScope::class); |
||||
}])->where('id', $id)->first(); |
||||
return response()->json([ |
||||
'success' => 1, |
||||
'view' => view('admin-views.pos.order.invoice', compact('order'))->render(), |
||||
]); |
||||
} |
||||
public function customer_store(Request $request) |
||||
{ |
||||
$request->validate([ |
||||
'f_name' => 'required', |
||||
'l_name' => 'required', |
||||
'email' => 'required|email|unique:users', |
||||
'phone' => 'required|unique:users', |
||||
]); |
||||
User::create([ |
||||
'f_name' => $request['f_name'], |
||||
'l_name' => $request['l_name'], |
||||
'email' => $request['email'], |
||||
'phone' => $request['phone'], |
||||
'password' => bcrypt('password') |
||||
]); |
||||
try { |
||||
if (config('mail.status')) { |
||||
Mail::to($request->email)->send(new \App\Mail\CustomerRegistration($request->f_name . ' ' . $request->l_name,true)); |
||||
} |
||||
} catch (\Exception $ex) { |
||||
info($ex); |
||||
} |
||||
Toastr::success(translate('customer_added_successfully')); |
||||
return back(); |
||||
} |
||||
|
||||
|
||||
public function extra_charge(Request $request) |
||||
{ |
||||
$distance_data = $request->distancMileResult ?? 1; |
||||
$self_delivery_status = $request->self_delivery_status; |
||||
|
||||
// $data= Vehicle::where('starting_coverage_area','<=' , $distance )->where('maximum_coverage_area','>=', $distance)->first(); |
||||
// if(!$data){ |
||||
// $data= Vehicle::where('maximum_coverage_area','>=', $distance)->first(); |
||||
// if(!$data){ |
||||
// $data= Vehicle::orderBy('maximum_coverage_area','DESC')->first(); |
||||
// } |
||||
// } |
||||
if($self_delivery_status != 1){ |
||||
$data = Vehicle::active()-> |
||||
where(function ($query) use ($distance_data) { |
||||
$query->where('starting_coverage_area', '<=', $distance_data)->where('maximum_coverage_area', '>=', $distance_data) |
||||
->orWhere(function ($query) use ($distance_data) { |
||||
$query->where('starting_coverage_area', '>=', $distance_data); |
||||
}); |
||||
}) |
||||
->orderBy('starting_coverage_area')->first(); |
||||
} |
||||
|
||||
$extra_charges = (float) (isset($data) ? $data->extra_charges : 0); |
||||
return response()->json($extra_charges,200); |
||||
} |
||||
} |
@ -0,0 +1,162 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Admin; |
||||
|
||||
use App\Models\DeliveryMan; |
||||
use Illuminate\Http\Request; |
||||
use App\CentralLogics\Helpers; |
||||
use App\Models\ProvideDMEarning; |
||||
use App\Models\AccountTransaction; |
||||
use Illuminate\Support\Facades\DB; |
||||
use App\Http\Controllers\Controller; |
||||
use Rap2hpoutre\FastExcel\FastExcel; |
||||
use Illuminate\Support\Facades\Validator; |
||||
use Brian2694\Toastr\Facades\Toastr; |
||||
|
||||
class ProvideDMEarningController extends Controller |
||||
{ |
||||
/** |
||||
* Display a listing of the resource. |
||||
* |
||||
* @return \Illuminate\Http\Response |
||||
*/ |
||||
public function index() |
||||
{ |
||||
$provide_dm_earning = ProvideDMEarning::latest()->paginate(config('default_pagination')); |
||||
return view('admin-views.deliveryman-earning-provide.index', compact('provide_dm_earning')); |
||||
} |
||||
|
||||
/** |
||||
* Show the form for creating a new resource. |
||||
* |
||||
* @return \Illuminate\Http\Response |
||||
*/ |
||||
public function create() |
||||
{ |
||||
// |
||||
} |
||||
|
||||
/** |
||||
* Store a newly created resource in storage. |
||||
* |
||||
* @param \Illuminate\Http\Request $request |
||||
* @return \Illuminate\Http\Response |
||||
*/ |
||||
public function store(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'deliveryman_id' => 'required', |
||||
'method'=>'max:191', |
||||
'ref'=>'max:191', |
||||
'amount' => 'required|numeric|between:0.01,999999999999.99', |
||||
]); |
||||
|
||||
|
||||
$dm = DeliveryMan::findOrFail($request['deliveryman_id']); |
||||
|
||||
$current_balance = $dm->wallet?$dm->wallet->total_earning - $dm->wallet->total_withdrawn:0; |
||||
|
||||
if ($current_balance < $request['amount']) { |
||||
$validator->getMessageBag()->add('amount', 'Insufficient balance!'); |
||||
return response()->json(['errors' => Helpers::error_processor($validator)]); |
||||
} |
||||
|
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)]); |
||||
} |
||||
|
||||
$provide_dm_earning = new ProvideDMEarning(); |
||||
|
||||
$provide_dm_earning->delivery_man_id = $dm->id; |
||||
$provide_dm_earning->method = $request['method']; |
||||
$provide_dm_earning->ref = $request['ref']; |
||||
$provide_dm_earning->amount = $request['amount']; |
||||
|
||||
try |
||||
{ |
||||
DB::beginTransaction(); |
||||
$provide_dm_earning->save(); |
||||
$dm->wallet->increment('total_withdrawn', $request['amount']); |
||||
DB::commit(); |
||||
} |
||||
catch(\Exception $e) |
||||
{ |
||||
DB::rollBack(); |
||||
return response()->json(['error'=>$e],200); |
||||
} |
||||
|
||||
return response()->json(200); |
||||
} |
||||
|
||||
/** |
||||
* Display the specified resource. |
||||
* |
||||
* @param int $id |
||||
* @return \Illuminate\Http\Response |
||||
*/ |
||||
public function show($id) |
||||
{ |
||||
$account_transaction=AccountTransaction::findOrFail($id); |
||||
return view('admin-views.account.view', compact('account_transaction')); |
||||
} |
||||
|
||||
/** |
||||
* Show the form for editing the specified resource. |
||||
* |
||||
* @param int $id |
||||
* @return \Illuminate\Http\Response |
||||
*/ |
||||
public function edit($id) |
||||
{ |
||||
// |
||||
} |
||||
|
||||
/** |
||||
* Update the specified resource in storage. |
||||
* |
||||
* @param \Illuminate\Http\Request $request |
||||
* @param int $id |
||||
* @return \Illuminate\Http\Response |
||||
*/ |
||||
public function update(Request $request, $id) |
||||
{ |
||||
// |
||||
} |
||||
|
||||
/** |
||||
* Remove the specified resource from storage. |
||||
* |
||||
* @param int $id |
||||
* @return \Illuminate\Http\Response |
||||
*/ |
||||
public function destroy($id) |
||||
{ |
||||
DeliveryMan::where('id', $id)->delete(); |
||||
Toastr::success(translate('messages.provided_dm_earnings_removed')); |
||||
return back(); |
||||
} |
||||
|
||||
|
||||
public function dm_earning_list_export(Request $request){ |
||||
$withdraw_request = ProvideDMEarning::latest()->get(); |
||||
if($request->type == 'excel'){ |
||||
return (new FastExcel(Helpers::dm_earning_list_export($withdraw_request)))->download('ProvideDMEarning.xlsx'); |
||||
}elseif($request->type == 'csv'){ |
||||
return (new FastExcel(Helpers::dm_earning_list_export($withdraw_request)))->download('ProvideDMEarning.csv'); |
||||
} |
||||
} |
||||
|
||||
public function search_deliveryman_earning(Request $request){ |
||||
$key = explode(' ', $request['search']); |
||||
$provide_dm_earning = ProvideDMEarning::with('delivery_man')->whereHas('delivery_man',function($query)use($key){ |
||||
foreach ($key as $value) { |
||||
$query->where('f_name', 'like', "%{$value}%")->orWhere('l_name', 'like', "%{$value}%"); |
||||
} |
||||
})->get(); |
||||
|
||||
return response()->json([ |
||||
'view'=>view('admin-views.deliveryman-earning-provide.partials._table', compact('provide_dm_earning'))->render(), |
||||
'total'=>$provide_dm_earning->count() |
||||
]); |
||||
} |
||||
} |
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,29 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Admin; |
||||
|
||||
use App\Http\Controllers\Controller; |
||||
use App\Models\Food; |
||||
use App\Models\Review; |
||||
use Illuminate\Http\Request; |
||||
|
||||
class ReviewsController extends Controller |
||||
{ |
||||
public function list(){ |
||||
$reviews=Review::with(['food','customer'])->latest()->paginate(config('default_pagination')); |
||||
return view('admin-views.reviews.list',compact('reviews')); |
||||
} |
||||
|
||||
public function search(Request $request){ |
||||
$key = explode(' ', $request['search']); |
||||
$foods=Food::where(function ($q) use ($key) { |
||||
foreach ($key as $value) { |
||||
$q->orWhere('name', 'like', "%{$value}%"); |
||||
} |
||||
})->pluck('id')->toArray(); |
||||
$reviews=Review::whereIn('food_id',$foods)->get(); |
||||
return response()->json([ |
||||
'view'=>view('admin-views.reviews.partials._table',compact('reviews'))->render() |
||||
]); |
||||
} |
||||
} |
@ -0,0 +1,136 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Admin; |
||||
|
||||
use App\CentralLogics\Helpers; |
||||
use App\Http\Controllers\Controller; |
||||
use App\Models\BusinessSetting; |
||||
use Illuminate\Http\Request; |
||||
use Illuminate\Support\Facades\DB; |
||||
|
||||
class SMSModuleController extends Controller |
||||
{ |
||||
public function sms_index() |
||||
{ |
||||
return view('admin-views.business-settings.sms-index'); |
||||
} |
||||
|
||||
public function sms_update(Request $request, $module) |
||||
{ |
||||
if ($module == 'twilio_sms') { |
||||
DB::table('business_settings')->updateOrInsert(['key' => 'twilio_sms'], [ |
||||
'key' => 'twilio_sms', |
||||
'value' => json_encode([ |
||||
'status' => $request['status'], |
||||
'sid' => $request['sid'], |
||||
'messaging_service_id' => $request['messaging_service_id'], |
||||
'token' => $request['token'], |
||||
'from' => $request['from'], |
||||
'otp_template' => $request['otp_template'], |
||||
]), |
||||
'created_at' => now(), |
||||
'updated_at' => now(), |
||||
]); |
||||
} elseif ($module == 'nexmo_sms') { |
||||
DB::table('business_settings')->updateOrInsert(['key' => 'nexmo_sms'], [ |
||||
'key' => 'nexmo_sms', |
||||
'value' => json_encode([ |
||||
'status' => $request['status'], |
||||
'api_key' => $request['api_key'], |
||||
'api_secret' => $request['api_secret'], |
||||
'signature_secret' => '', |
||||
'private_key' => '', |
||||
'application_id' => '', |
||||
'from' => $request['from'], |
||||
'otp_template' => $request['otp_template'] |
||||
]), |
||||
'created_at' => now(), |
||||
'updated_at' => now(), |
||||
]); |
||||
} elseif ($module == '2factor_sms') { |
||||
DB::table('business_settings')->updateOrInsert(['key' => '2factor_sms'], [ |
||||
'key' => '2factor_sms', |
||||
'value' => json_encode([ |
||||
'status' => $request['status'], |
||||
'api_key' => $request['api_key'], |
||||
]), |
||||
'created_at' => now(), |
||||
'updated_at' => now(), |
||||
]); |
||||
} elseif ($module == 'msg91_sms') { |
||||
DB::table('business_settings')->updateOrInsert(['key' => 'msg91_sms'], [ |
||||
'key' => 'msg91_sms', |
||||
'value' => json_encode([ |
||||
'status' => $request['status'], |
||||
'template_id' => $request['template_id'], |
||||
'authkey' => $request['authkey'], |
||||
]), |
||||
'created_at' => now(), |
||||
'updated_at' => now(), |
||||
]); |
||||
} |
||||
|
||||
if ($request['status'] == 1) { |
||||
if ($module != 'twilio_sms') { |
||||
$config = Helpers::get_business_settings('twilio_sms'); |
||||
DB::table('business_settings')->updateOrInsert(['key' => 'twilio_sms'], [ |
||||
'key' => 'twilio_sms', |
||||
'value' => json_encode([ |
||||
'status' => 0, |
||||
'sid' => $config['sid'], |
||||
'token' => $config['token'], |
||||
'from' => $config['from'], |
||||
'otp_template' => $config['otp_template'], |
||||
]), |
||||
'created_at' => now(), |
||||
'updated_at' => now(), |
||||
]); |
||||
} |
||||
if ($module != 'nexmo_sms') { |
||||
$config = Helpers::get_business_settings('nexmo_sms'); |
||||
DB::table('business_settings')->updateOrInsert(['key' => 'nexmo_sms'], [ |
||||
'key' => 'nexmo_sms', |
||||
'value' => json_encode([ |
||||
'status' => 0, |
||||
'api_key' => $config['api_key'], |
||||
'api_secret' => $config['api_secret'], |
||||
'signature_secret' => '', |
||||
'private_key' => '', |
||||
'application_id' => '', |
||||
'from' => $config['from'], |
||||
'otp_template' => $config['otp_template'] |
||||
]), |
||||
'created_at' => now(), |
||||
'updated_at' => now(), |
||||
]); |
||||
} |
||||
if ($module != '2factor_sms') { |
||||
$config = Helpers::get_business_settings('2factor_sms'); |
||||
DB::table('business_settings')->updateOrInsert(['key' => '2factor_sms'], [ |
||||
'key' => '2factor_sms', |
||||
'value' => json_encode([ |
||||
'status' => 0, |
||||
'api_key' => $config['api_key'], |
||||
]), |
||||
'created_at' => now(), |
||||
'updated_at' => now(), |
||||
]); |
||||
} |
||||
if ($module != 'msg91_sms') { |
||||
$config = Helpers::get_business_settings('msg91_sms'); |
||||
DB::table('business_settings')->updateOrInsert(['key' => 'msg91_sms'], [ |
||||
'key' => 'msg91_sms', |
||||
'value' => json_encode([ |
||||
'status' => 0, |
||||
'template_id' => $config['template_id'], |
||||
'authkey' => $config['authkey'], |
||||
]), |
||||
'created_at' => now(), |
||||
'updated_at' => now(), |
||||
]); |
||||
} |
||||
} |
||||
|
||||
return back(); |
||||
} |
||||
} |
@ -0,0 +1,117 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Admin; |
||||
|
||||
use App\Http\Controllers\Controller; |
||||
use Illuminate\Http\Request; |
||||
use App\Models\Shift; |
||||
use Brian2694\Toastr\Facades\Toastr; |
||||
|
||||
class ShiftController extends Controller |
||||
{ |
||||
public function list() |
||||
{ |
||||
$shifts= Shift::latest()->paginate(25); |
||||
$total=$shifts->total(); |
||||
// dd($shifts); |
||||
return view('admin-views.shift.list',[ |
||||
'shifts'=>$shifts, |
||||
'total'=>$total, |
||||
]); |
||||
} |
||||
public function store(Request $request) |
||||
{ |
||||
$request->validate([ |
||||
'start_time'=>'required|date_format:H:i', |
||||
'end_time'=>'required|date_format:H:i|after:start_time', |
||||
'name'=>'required|max:191', |
||||
],[ |
||||
'end_time.after'=>translate('messages.End time must be after the start time') |
||||
]); |
||||
|
||||
$temp = Shift::where(function ($q) use ($request) { |
||||
return $q->where(function ($query) use ($request) { |
||||
return $query->where('start_time', '<=', $request->start_time)->where('end_time', '>=', $request->start_time); |
||||
})->orWhere(function ($query) use ($request) { |
||||
return $query->where('start_time', '<=', $request->end_time)->where('end_time', '>=', $request->end_time); |
||||
}); |
||||
}) |
||||
->first(); |
||||
|
||||
if (isset($temp)) { |
||||
return response()->json(['errors' => [ |
||||
['code' => 'overlaped', 'message' => translate('messages.Shift_overlaped')] |
||||
]]); |
||||
} |
||||
$shift = new Shift(); |
||||
$shift->name = $request->name; |
||||
$shift->start_time = $request->start_time; |
||||
$shift->end_time = $request->end_time; |
||||
$shift->save(); |
||||
|
||||
Toastr::success(translate('messages.shift_added_successfully')); |
||||
return response()->json(['success'=>true]); |
||||
|
||||
} |
||||
public function status(Request $request) |
||||
{ |
||||
$shift = Shift::findOrFail($request->id); |
||||
$shift->status = $request->status; |
||||
$shift->save(); |
||||
Toastr::success(translate('messages.shift_status_updated')); |
||||
return back(); |
||||
} |
||||
public function update(Request $request ) |
||||
{ |
||||
// dd($request->all()); |
||||
$id=$request->id; |
||||
$request->validate([ |
||||
'start_time'=>'required', |
||||
'end_time'=>'required|after:start_time', |
||||
'name'=>'required|max:191', |
||||
],[ |
||||
'end_time.after'=>translate('messages.End time must be after the start time') |
||||
]); |
||||
$temp = Shift::where('id' ,'!=', $id)->where(function ($q) use ($request) { |
||||
return $q->where(function ($query) use ($request) { |
||||
return $query->where('start_time', '<=', $request->start_time)->where('end_time', '>=', $request->start_time); |
||||
})->orWhere(function ($query) use ($request) { |
||||
return $query->where('start_time', '<=', $request->end_time)->where('end_time', '>=', $request->end_time); |
||||
}); |
||||
}) |
||||
->first(); |
||||
|
||||
if (isset($temp)) { |
||||
return response()->json(['errors' => [ |
||||
['code' => 'overlaped', 'message' => translate('messages.Shift_overlaped')] |
||||
]]); |
||||
} |
||||
Shift::find($id)->update([ |
||||
'name' => $request->name, |
||||
'start_time' => $request->start_time, |
||||
'end_time' => $request->end_time, |
||||
]); |
||||
|
||||
Toastr::success(translate('messages.shift_updated_successfully')); |
||||
return response()->json(['success'=>true]); |
||||
} |
||||
public function destroy(Shift $shift) |
||||
{ |
||||
$shift->delete(); |
||||
Toastr::success(translate('messages.shift_deleted_successfully')); |
||||
return back(); |
||||
} |
||||
public function search(Request $request){ |
||||
$key = explode(' ', $request['search']); |
||||
$shifts=Shift::where(function ($q) use ($key) { |
||||
foreach ($key as $value) { |
||||
$q->orWhere('name', 'like', "%{$value}%"); |
||||
} |
||||
}) |
||||
->latest()->paginate(50); |
||||
return response()->json([ |
||||
'view'=>view('admin-views.shift.partials._table',compact('shifts'))->render(), |
||||
'total'=>$shifts->count() |
||||
]); |
||||
} |
||||
} |
@ -0,0 +1,126 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Admin; |
||||
|
||||
use App\Http\Controllers\Controller; |
||||
use App\Models\SocialMedia; |
||||
use Illuminate\Http\Request; |
||||
|
||||
class SocialMediaController extends Controller |
||||
{ |
||||
/** |
||||
* Display a listing of the resource. |
||||
* |
||||
* @return \Illuminate\Http\Response |
||||
*/ |
||||
public function index() |
||||
{ |
||||
return view('admin-views.business-settings.social-media'); |
||||
} |
||||
|
||||
/** |
||||
* Show the form for creating a new resource. |
||||
* |
||||
* @return \Illuminate\Http\Response |
||||
*/ |
||||
public function create() |
||||
{ |
||||
// |
||||
} |
||||
|
||||
/** |
||||
* Store a newly created resource in storage. |
||||
* |
||||
* @param \Illuminate\Http\Request $request |
||||
* @return \Illuminate\Http\Response |
||||
*/ |
||||
public function store(Request $request) |
||||
{ |
||||
try { |
||||
SocialMedia::updateOrInsert([ |
||||
'name' => $request->get('name'), |
||||
], [ |
||||
'name' => $request->get('name'), |
||||
'link' => $request->get('link'), |
||||
]); |
||||
|
||||
return response()->json([ |
||||
'success' => 1, |
||||
]); |
||||
|
||||
} catch (\Exception $exception) { |
||||
return response()->json([ |
||||
'error' => 1, |
||||
]); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Display the specified resource. |
||||
* |
||||
* @param \App\Models\SocialMedia $socialMedia |
||||
* @return \Illuminate\Http\Response |
||||
*/ |
||||
public function show($socialMedia) |
||||
{ |
||||
$data = SocialMedia::where('id', $socialMedia)->first(); |
||||
return response()->json($data); |
||||
} |
||||
|
||||
/** |
||||
* Show the form for editing the specified resource. |
||||
* |
||||
* @param \App\Models\SocialMedia $socialMedia |
||||
* @return \Illuminate\Http\Response |
||||
*/ |
||||
public function edit(SocialMedia $socialMedia) |
||||
{ |
||||
return response()->json($socialMedia); |
||||
} |
||||
|
||||
/** |
||||
* Update the specified resource in storage. |
||||
* |
||||
* @param \Illuminate\Http\Request $request |
||||
* @param \App\Models\SocialMedia $socialMedia |
||||
* @return \Illuminate\Http\Response |
||||
*/ |
||||
public function update(Request $request, $socialMedia) |
||||
{ |
||||
$social_media = SocialMedia::find($socialMedia); |
||||
$social_media->name = $request->name; |
||||
$social_media->link = $request->link; |
||||
$social_media->save(); |
||||
return response()->json(); |
||||
} |
||||
|
||||
/** |
||||
* Remove the specified resource from storage. |
||||
* |
||||
* @param \App\Models\SocialMedia $socialMedia |
||||
* @return \Illuminate\Http\Response |
||||
*/ |
||||
public function destroy(SocialMedia $socialMedia) |
||||
{ |
||||
// |
||||
} |
||||
|
||||
public function fetch(Request $request) |
||||
{ |
||||
if ($request->ajax()) { |
||||
$data = SocialMedia::orderBy('id', 'desc')->get(); |
||||
return response()->json($data); |
||||
} |
||||
} |
||||
|
||||
public function social_media_status_update(Request $request) |
||||
{ |
||||
SocialMedia::where(['id' => $request['id']])->update([ |
||||
'status' => $request['status'], |
||||
]); |
||||
return response()->json([ |
||||
'success' => 1, |
||||
], 200); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,480 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Admin; |
||||
|
||||
use App\Models\Zone; |
||||
use App\Models\Restaurant; |
||||
use Illuminate\Http\Request; |
||||
use App\CentralLogics\Helpers; |
||||
use Illuminate\Support\Carbon; |
||||
use App\Models\RestaurantWallet; |
||||
use App\Models\SubscriptionPackage; |
||||
use App\Http\Controllers\Controller; |
||||
use App\Models\BusinessSetting; |
||||
use Brian2694\Toastr\Facades\Toastr; |
||||
use App\Models\RestaurantSubscription; |
||||
use App\Models\SubscriptionTransaction; |
||||
|
||||
class SubscriptionController extends Controller |
||||
{ |
||||
public function package_list() |
||||
{ |
||||
$packages = SubscriptionPackage::withCount('transactions') |
||||
->latest() |
||||
->paginate(config('default_pagination')); |
||||
// $expire_soon = RestaurantSubscription::where('status', 1)->whereDate('expiry_date', '<=', Carbon::today()->addDays('10'))->count(); |
||||
// $rest= RestaurantSubscription::get(); |
||||
// $active= $rest->where('status',1)->count(); |
||||
// $suspended= $rest->where('status',0)->count(); |
||||
// $total_sub=SubscriptionTransaction::count(); |
||||
$total=$packages->total(); |
||||
return view('admin-views.subscription.index', [ |
||||
'packages' => $packages, |
||||
'total' => $total, |
||||
// 'expire_soon' => $expire_soon, |
||||
// 'active' => $active, |
||||
// 'suspended' => $suspended, |
||||
// 'total_sub' => $total_sub, |
||||
]); |
||||
} |
||||
|
||||
public function create() |
||||
{ |
||||
return view('admin-views.subscription.create'); |
||||
} |
||||
|
||||
public function edit($id) |
||||
{ |
||||
$package = SubscriptionPackage::findOrFail($id); |
||||
return view('admin-views.subscription.edit', compact('package')); |
||||
} |
||||
|
||||
public function store(Request $request) |
||||
{ |
||||
$request->validate([ |
||||
'package_name' => 'required|max:191|unique:subscription_packages', |
||||
'package_price' => 'required|numeric|between:0,999999999999.99', |
||||
'package_validity' => 'required|integer|between:0,999999999', |
||||
'max_order' => 'nullable|integer|between:0,999999999', |
||||
'max_product' => 'nullable|integer|between:0,999999999', |
||||
|
||||
'pos_system' => 'nullable|boolean', |
||||
'mobile_app' => 'nullable|boolean', |
||||
'self_delivery' => 'nullable|boolean', |
||||
'chat' => 'nullable|boolean', |
||||
'review' => 'nullable|boolean', |
||||
|
||||
], [ |
||||
'price.required' => translate('Must enter Price for the Package'), |
||||
'package_name.required' => translate('Name of the Package is required'), |
||||
'validity.required' => translate('Must enter a validity period for the Package in days'), |
||||
]); |
||||
|
||||
|
||||
SubscriptionPackage::create([ |
||||
'package_name' => $request->package_name, |
||||
'price' => $request->package_price, |
||||
'validity' => $request->package_validity, |
||||
'max_order' => $request->max_order ?? 'unlimited', |
||||
'max_product' => $request->max_product ?? 'unlimited', |
||||
'pos' => $request->pos_system ?? 0, |
||||
'mobile_app' => $request->mobile_app ?? 0, |
||||
'self_delivery' => $request->self_delivery ?? 0, |
||||
'chat' => $request->chat ?? 0, |
||||
'review' => $request->review ?? 0, |
||||
'colour' => $request->colour, |
||||
'text' => $request->text, |
||||
]); |
||||
Toastr::success(translate('Subscription Plan Added Successfully')); |
||||
return redirect()->route('admin.subscription.package_list'); |
||||
} |
||||
|
||||
|
||||
public function update(Request $request) |
||||
{ |
||||
|
||||
$request->validate([ |
||||
'package_name' => 'required|max:191|unique:subscription_packages,package_name,' . $request->id, |
||||
'package_price' => 'required|numeric|between:0,999999999999.99', |
||||
'package_validity' => 'required|integer|between:0,999999999', |
||||
'max_order' => 'nullable|integer|between:0,999999999', |
||||
'max_product' => 'nullable|integer|between:0,999999999', |
||||
|
||||
'pos_system' => 'nullable|boolean', |
||||
'mobile_app' => 'nullable|boolean', |
||||
'self_delivery' => 'nullable|boolean', |
||||
'chat' => 'nullable|boolean', |
||||
'review' => 'nullable|boolean', |
||||
|
||||
], [ |
||||
'price.required' => translate('Must enter Price for the Package'), |
||||
'package_name.required' => translate('Name of the Package is required'), |
||||
'validity.required' => translate('Must enter a validity period for the Package in days'), |
||||
]); |
||||
|
||||
SubscriptionPackage::findOrfail($request->id)->update([ |
||||
'package_name' => $request->package_name, |
||||
'price' => $request->package_price, |
||||
'validity' => $request->package_validity, |
||||
'max_order' => $request->max_order ?? 'unlimited', |
||||
'max_product' => $request->max_product ?? 'unlimited', |
||||
'pos' => $request->pos_system ?? 0, |
||||
'mobile_app' => $request->mobile_app ?? 0, |
||||
'self_delivery' => $request->self_delivery ?? 0, |
||||
'chat' => $request->chat ?? 0, |
||||
'review' => $request->review ?? 0, |
||||
'colour' => $request->colour, |
||||
'text' => $request->text, |
||||
]); |
||||
|
||||
|
||||
Toastr::success(translate('Subscription Plan Updated Successfully')); |
||||
return redirect()->route('admin.subscription.package_list'); |
||||
} |
||||
|
||||
public function details($id) |
||||
{ |
||||
|
||||
$package = SubscriptionPackage::withCount('transactions')->findOrFail($id); |
||||
$expire_soon = RestaurantSubscription::where('status', 1)->where('package_id',$package->id)->whereDate('expiry_date', '<=', Carbon::today()->addDays('7'))->count(); |
||||
$RestaurantSubscription=RestaurantSubscription::where('package_id',$package->id)->get(); |
||||
$active= $RestaurantSubscription->where('status',1)->count(); |
||||
$deactive= $RestaurantSubscription->where('status',0)->count(); |
||||
$total_renewed= $RestaurantSubscription->sum('total_package_renewed'); |
||||
$total_on_package=$RestaurantSubscription->count(); |
||||
$on_trail=SubscriptionTransaction::where('package_id',$package->id)->where('payment_method','free_trial')->count(); |
||||
|
||||
$this_month_active= RestaurantSubscription::where('package_id',$package->id)->where('status',1)->whereMonth('created_at', Carbon::now()->month)->count(); |
||||
$this_month_deactive= RestaurantSubscription::where('package_id',$package->id)->where('status',0)->whereMonth('created_at', Carbon::now()->month)->count(); |
||||
$this_month_total_renewed= RestaurantSubscription::where('package_id',$package->id)->whereMonth('created_at', Carbon::now()->month)->sum('total_package_renewed'); |
||||
$this_month_total_sub= SubscriptionTransaction::where('package_id',$package->id)->whereMonth('created_at', Carbon::now()->month)->count(); |
||||
$this_month_total_on_package= RestaurantSubscription::where('package_id',$package->id)->whereMonth('created_at', Carbon::now()->month)->count(); |
||||
$his_month_on_trail=SubscriptionTransaction::where('package_id',$package->id)->where('payment_method','free_trial')->whereMonth('created_at', Carbon::now()->month)->count(); |
||||
|
||||
|
||||
|
||||
$this_year_active= RestaurantSubscription::where('package_id',$package->id)->where('status',1)->whereYear('created_at', Carbon::now()->year)->count(); |
||||
$this_year_deactive= RestaurantSubscription::where('package_id',$package->id)->where('status',0)->whereYear('created_at', Carbon::now()->year)->count(); |
||||
$this_year_total_renewed= RestaurantSubscription::where('package_id',$package->id)->whereYear('created_at', Carbon::now()->year)->sum('total_package_renewed'); |
||||
$this_year_total_sub= SubscriptionTransaction::where('package_id',$package->id)->whereYear('created_at', Carbon::now()->year)->count(); |
||||
$this_year_total_on_package= RestaurantSubscription::where('package_id',$package->id)->whereYear('created_at', Carbon::now()->year)->count(); |
||||
$his_year_on_trail=SubscriptionTransaction::where('package_id',$package->id)->where('payment_method','free_trial')->whereMonth('created_at', Carbon::now()->year)->count(); |
||||
|
||||
$this_month = SubscriptionTransaction::where('package_id', $id)->whereMonth('created_at', Carbon::now()->month)->sum('paid_amount'); |
||||
$transcation_sum = SubscriptionTransaction::where('package_id', $id)->sum('paid_amount'); |
||||
|
||||
$transcation_sum_month = SubscriptionTransaction::where('package_id', $id)->whereMonth('created_at', Carbon::now()->month)->sum('paid_amount'); |
||||
$transcation_sum_year = SubscriptionTransaction::where('package_id', $id)->whereYear('created_at', Carbon::now()->year)->sum('paid_amount'); |
||||
$transcation_sum = SubscriptionTransaction::where('package_id', $id)->sum('paid_amount'); |
||||
return view('admin-views.subscription.view', compact([ |
||||
'package', |
||||
'active', |
||||
'transcation_sum', |
||||
'deactive', |
||||
'this_month', |
||||
'total_renewed', |
||||
'expire_soon', |
||||
'this_month_active', |
||||
'this_month_deactive', |
||||
'this_month_total_renewed', |
||||
'this_month_total_sub', |
||||
'this_year_active', |
||||
'this_year_deactive', |
||||
'this_year_total_renewed', |
||||
'this_year_total_sub', |
||||
'transcation_sum_month', |
||||
'transcation_sum_year', |
||||
'total_on_package', |
||||
'this_month_total_on_package', |
||||
'this_year_total_on_package', |
||||
'on_trail', |
||||
'his_month_on_trail', |
||||
'his_year_on_trail', |
||||
])); |
||||
} |
||||
|
||||
|
||||
public function transcation_list(Request $request, $id){ |
||||
$filter = $request->query('filter', 'all'); |
||||
$transcations = SubscriptionTransaction::withoutGlobalScope(RestaurantScope::class)->where('package_id',$id) |
||||
->when($filter == 'month', function ($query) { |
||||
return $query->whereMonth('created_at', Carbon::now()->month); |
||||
}) |
||||
->when($filter == 'year', function ($query) { |
||||
return $query->whereYear('created_at', Carbon::now()->year); |
||||
}) |
||||
->latest()->paginate(config('default_pagination')); |
||||
$total = $transcations->total(); |
||||
return view('admin-views.subscription.subscription-transaction',[ |
||||
'transcations' => $transcations, |
||||
'filter' => $filter, |
||||
'total' => $total, |
||||
'package_id' => $id, |
||||
]); |
||||
} |
||||
|
||||
public function trans_search_by_date(Request $request){ |
||||
$from=$request->start_date; |
||||
$to= $request->end_date; |
||||
$id=$request->package_id; |
||||
$filter = 'all'; |
||||
$transcations=SubscriptionTransaction::where('package_id',$id) |
||||
->whereBetween('created_at', ["{$from}", "{$to} 23:59:59"]) |
||||
->latest()->paginate(config('default_pagination')); |
||||
$total = $transcations->total(); |
||||
return view('admin-views.subscription.subscription-transaction',[ |
||||
'transcations' => $transcations, |
||||
'filter' => $filter, |
||||
'total' => $total, |
||||
'package_id' => $id, |
||||
'from' => $from, |
||||
'to' => $to, |
||||
]); |
||||
} |
||||
|
||||
public function transcation_search(Request $request) |
||||
{ |
||||
$key = explode(' ', $request['search']); |
||||
$transcations = SubscriptionTransaction::where(function ($q) use ($key) { |
||||
foreach ($key as $value) { |
||||
$q->orWhere('id', 'like', "%{$value}%") |
||||
->orWhere('paid_amount', 'like', "%{$value}%") |
||||
->orWhere('reference', 'like', "%{$value}%") |
||||
->orWheredate('created_at', 'like', "%{$value}%"); |
||||
} |
||||
}) |
||||
->with('restaurant') |
||||
->latest()->paginate(config('default_pagination')); |
||||
$total = $transcations->count(); |
||||
return response()->json([ |
||||
'view' => view('admin-views.subscription.partials._subs_transcation', compact('transcations'))->render(),'total' => $total |
||||
]); |
||||
} |
||||
|
||||
|
||||
|
||||
public function search(Request $request) |
||||
{ |
||||
$key = explode(' ', $request['search']); |
||||
$packages = SubscriptionPackage::where(function ($q) use ($key) { |
||||
foreach ($key as $value) { |
||||
$q->orWhere('package_name', 'like', "%{$value}%") |
||||
->orWhere('price', 'like', "%{$value}%") |
||||
->orWhere('validity', 'like', "%{$value}%"); |
||||
} |
||||
})->latest()->paginate(config('default_pagination')); |
||||
$total=$packages->total(); |
||||
return response()->json([ |
||||
'view' => view('admin-views.subscription.partials._table', compact('packages'))->render(),'total' => $total |
||||
]); |
||||
} |
||||
|
||||
|
||||
public function subscription_search(Request $request){ |
||||
$key = explode(' ', $request['search']); |
||||
$restaurants = RestaurantSubscription::with('restaurant')->whereHas('restaurant',function($query)use($key){ |
||||
foreach ($key as $value) { |
||||
$query->where('name', 'like', "%{$value}%")->orWhere('email', 'like', "%{$value}%"); |
||||
} |
||||
})->latest()->paginate(config('default_pagination')); |
||||
$total=$restaurants->total(); |
||||
return response()->json([ |
||||
'view' => view('admin-views.subscription.partials._subs_table', compact('restaurants'))->render(),'total' => $total |
||||
]); |
||||
} |
||||
|
||||
public function status(SubscriptionPackage $package, Request $request) |
||||
{ |
||||
$package->status = $request->status; |
||||
$package->save(); |
||||
Toastr::success(translate('messages.Package') . translate('messages.status_updated')); |
||||
return back(); |
||||
} |
||||
|
||||
|
||||
|
||||
public function subscription_list(Request $request) |
||||
{ |
||||
$zone_id = $request->query('zone_id', 'all'); |
||||
$type = $request->query('type', 'all'); |
||||
$restaurants = Restaurant::whereHas('restaurant_sub_update_application', function($query)use($type){ |
||||
$query->when($type == 'subscribed', function ($query) { |
||||
return $query->where('status', 1); |
||||
}) |
||||
->when($type == 'unsubscribed', function ($query) { |
||||
return $query->where('status', 0); |
||||
}) |
||||
->when($type == 'expire_soon', function ($query) { |
||||
return $query->where('status', 1)->whereDate('expiry_date', '<=', Carbon::today()->addDays('10')); |
||||
}); |
||||
}) |
||||
->when($request->query('key'),function($query)use($request){ |
||||
$query->where(function($query)use($request){ |
||||
$key = explode(' ', $request->query('key')); |
||||
foreach ($key as $value) { |
||||
$query->orWhere('name', 'like', "%{$value}%")->orWhere('email', 'like', "%{$value}%"); |
||||
} |
||||
}); |
||||
}) |
||||
->when(is_numeric($request->zone_id), function ($query) use ($request) { |
||||
return $query->where('zone_id', $request->zone_id); |
||||
}) |
||||
->latest()->paginate(config('default_pagination')); |
||||
|
||||
$zone = is_numeric($zone_id) ? Zone::findOrFail($zone_id) : null; |
||||
$transcations=SubscriptionTransaction::get(); |
||||
$sub_transcations = $transcations->count(); |
||||
$total_earning = $transcations->sum('paid_amount'); |
||||
$this_month = SubscriptionTransaction::whereMonth('created_at', Carbon::now()->month)->sum('paid_amount'); |
||||
|
||||
$restaurant_subscription=RestaurantSubscription::get(); |
||||
$total_restaurant = $restaurant_subscription->groupBy('restaurant_id')->count(); |
||||
$total_active_subscription = $restaurant_subscription->where('status', 1)->groupBy('restaurant_id')->count(); |
||||
$total_inactive_subscription = $restaurant_subscription->where('status', 0)->groupBy('restaurant_id')->count(); |
||||
$expire_soon = RestaurantSubscription::where('status', 1)->groupBy('restaurant_id')->whereDate('expiry_date', '<=', Carbon::today()->addDays('10'))->count(); |
||||
|
||||
return view('admin-views.subscription.list', compact( |
||||
'restaurants', |
||||
'zone', |
||||
'type', |
||||
'sub_transcations', |
||||
'expire_soon', |
||||
'this_month', |
||||
'total_earning', |
||||
'total_active_subscription', |
||||
'total_inactive_subscription', |
||||
'total_restaurant' |
||||
)); |
||||
} |
||||
|
||||
|
||||
public function package_renew_change_update(Request $request){ |
||||
$package = SubscriptionPackage::findOrFail($request->package_id); |
||||
$discount = $request->discount ?? 0; |
||||
$restaurant=Restaurant::findOrFail($request->restaurant_id); |
||||
$restaurant_id=$restaurant->id; |
||||
$total_parice =$package->price - (($package->price*$discount)/100); |
||||
$reference= $request->reference ?? null; |
||||
if($request->button == 'renew'){ |
||||
$type = 'renew'; |
||||
}else{ |
||||
$type = null; |
||||
} |
||||
if ($request->payment_type == 'wallet') { |
||||
$wallet = RestaurantWallet::where('vendor_id',$restaurant->vendor_id)->first(); |
||||
if ( $wallet->balance >= $total_parice) { |
||||
$payment_method= 'wallet'; |
||||
$status= Helpers::subscription_plan_chosen($restaurant_id ,$package->id, $payment_method ,$reference ,$discount,$type); |
||||
|
||||
if($status === 'downgrade_error'){ |
||||
Toastr::error(translate('messages.You_can_not_downgraded_to_this_package_please_choose_a_package_with_higher_upload_limits') ); |
||||
return back(); |
||||
} |
||||
$wallet->total_withdrawn= $wallet->total_withdrawn +$total_parice; |
||||
$wallet->save(); |
||||
} |
||||
else{ |
||||
Toastr::error('Insufficient Balance'); |
||||
return back(); |
||||
} |
||||
} |
||||
elseif ($request->payment_type == 'pay_now') { |
||||
// dd('pay_now'); |
||||
$payment_method= 'manual_payment_admin'; |
||||
$status= Helpers::subscription_plan_chosen($restaurant_id ,$package->id, $payment_method ,$reference ,$discount,$type); |
||||
if($status === 'downgrade_error'){ |
||||
Toastr::error(translate('messages.You_can_not_downgraded_to_this_package_please_choose_a_package_with_higher_upload_limits') ); |
||||
return back(); |
||||
} |
||||
|
||||
} |
||||
Toastr::success(translate('messages.subscription_successful') ); |
||||
return back(); |
||||
} |
||||
|
||||
|
||||
public function package_selected(Request $request,$id,$rest_id){ |
||||
$restaurant_id = $rest_id; |
||||
$rest_subscription= RestaurantSubscription::where('restaurant_id', $restaurant_id)->with(['package'])->latest()->first(); |
||||
$package = SubscriptionPackage::where('status',1)->where('id',$id)->first(); |
||||
return response()->json([ |
||||
'view' => view('admin-views.subscription.partials._package_selected', compact('rest_subscription','package','restaurant_id'))->render() |
||||
]); |
||||
} |
||||
|
||||
public function package_cancel(Request $request){ |
||||
// RestaurantSubscription::where('restaurant_id', $request->id)->update([ |
||||
// 'status' => 0 |
||||
// ]); |
||||
|
||||
$restaurant = Restaurant::where('id', $request->id)->first(); |
||||
$restaurant->update([ |
||||
'status' => 0, |
||||
'self_delivery_system' => 1, |
||||
'reviews_section' => 1, |
||||
'free_delivery' => 0, |
||||
'pos_system' => 1, |
||||
'restaurant_model' => 'unsubscribed', |
||||
]); |
||||
$restaurant->coupon()->where('created_by','vendor')->where('coupon_type','free_delivery')->delete(); |
||||
$restaurant->restaurant_subs()->update(['status' => 0]); |
||||
Toastr::success(translate('Subscription Canceled') ); |
||||
return back(); |
||||
} |
||||
|
||||
public function invoice($id){ |
||||
$subscription_transaction= SubscriptionTransaction::findOrFail($id); |
||||
$restaurant= Restaurant::findOrFail($subscription_transaction->restaurant_id); |
||||
|
||||
return view('admin-views.subscription.subs_transcation_invoice', compact( |
||||
'restaurant', |
||||
'subscription_transaction', |
||||
)); |
||||
} |
||||
public function settings(){ |
||||
// $free_trial_period= BusinessSetting::where('key', 'free_trial_period')->first(); |
||||
// return view('admin-views.subscription.settings',['free_trial_period'=>$free_trial_period]); |
||||
|
||||
$free_trial_period = BusinessSetting::where(['key' => 'free_trial_period'])->first(); |
||||
if ($free_trial_period == false) { |
||||
|
||||
$values= [ |
||||
'data' => '', |
||||
'status' => 0, |
||||
]; |
||||
Helpers::insert_business_settings_key('free_trial_period', json_encode($values) ); |
||||
} |
||||
$free_trial_period = json_decode(BusinessSetting::where(['key' => 'free_trial_period'])->first()->value,true); |
||||
return view('admin-views.subscription.settings',['free_trial_period'=>$free_trial_period]); |
||||
|
||||
|
||||
} |
||||
public function settings_update(Request $request){ |
||||
$data = json_decode(BusinessSetting::where(['key' => 'free_trial_period'])->first()->value,true); |
||||
$values= [ |
||||
'data' => $request->free_trial_period, |
||||
'status' => $data['status'], |
||||
]; |
||||
BusinessSetting::where(['key' => 'free_trial_period'])->update([ |
||||
'value' => $values, |
||||
]); |
||||
Toastr::success(translate('messages.free_trial_period_updated') ); |
||||
return back(); |
||||
} |
||||
|
||||
|
||||
|
||||
public function settings_update_status($status){ |
||||
$data = json_decode(BusinessSetting::where(['key' => 'free_trial_period'])->first()->value,true); |
||||
$values= [ |
||||
'data' => $data['data'], |
||||
'status' => $status, |
||||
]; |
||||
BusinessSetting::where(['key' => 'free_trial_period'])->update([ |
||||
'value' => $values, |
||||
]); |
||||
return response()->json(['status'=>"changed"]); |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,110 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Admin; |
||||
|
||||
use App\Http\Controllers\Controller; |
||||
use App\Models\Admin; |
||||
use App\Models\BusinessSetting; |
||||
use Brian2694\Toastr\Facades\Toastr; |
||||
use Illuminate\Http\Request; |
||||
use Illuminate\Support\Carbon; |
||||
use Illuminate\Support\Facades\DB; |
||||
use Illuminate\Support\Facades\Storage; |
||||
use App\CentralLogics\Helpers; |
||||
|
||||
|
||||
class SystemController extends Controller |
||||
{ |
||||
|
||||
public function restaurant_data() |
||||
{ |
||||
$new_order = DB::table('orders')->where(['checked' => 0])->count(); |
||||
return response()->json([ |
||||
'success' => 1, |
||||
'data' => ['new_order' => $new_order] |
||||
]); |
||||
} |
||||
|
||||
public function settings() |
||||
{ |
||||
return view('admin-views.settings'); |
||||
} |
||||
|
||||
public function settings_update(Request $request) |
||||
{ |
||||
$request->validate([ |
||||
'f_name' => 'required', |
||||
'l_name' => 'required', |
||||
'email' => 'required|unique:admins,email,'.auth('admin')->id(), |
||||
'phone' => 'required|regex:/^([0-9\s\-\+\(\)]*)$/|min:10|unique:admins,phone,'.auth('admin')->id(), |
||||
], [ |
||||
'f_name.required' => translate('messages.first_name_is_required'), |
||||
'l_name.required' => translate('messages.Last name is required!'), |
||||
]); |
||||
|
||||
$admin = Admin::find(auth('admin')->id()); |
||||
|
||||
if ($request->has('image')) { |
||||
$image_name =Helpers::update('admin/', $admin->image, 'png', $request->file('image')); |
||||
} else { |
||||
$image_name = $admin['image']; |
||||
} |
||||
|
||||
|
||||
$admin->f_name = $request->f_name; |
||||
$admin->l_name = $request->l_name; |
||||
$admin->email = $request->email; |
||||
$admin->phone = $request->phone; |
||||
$admin->image = $image_name; |
||||
$admin->save(); |
||||
Toastr::success(translate('messages.admin_updated_successfully')); |
||||
return back(); |
||||
} |
||||
|
||||
public function settings_password_update(Request $request) |
||||
{ |
||||
$request->validate([ |
||||
'password' => 'required|same:confirm_password', |
||||
'confirm_password' => 'required', |
||||
]); |
||||
|
||||
$admin = Admin::find(auth('admin')->id()); |
||||
$admin->password = bcrypt($request['password']); |
||||
$admin->save(); |
||||
Toastr::success(translate('messages.admin_password_updated_successfully')); |
||||
return back(); |
||||
} |
||||
|
||||
public function maintenance_mode() |
||||
{ |
||||
$maintenance_mode = BusinessSetting::where('key', 'maintenance_mode')->first(); |
||||
if (isset($maintenance_mode) == false) { |
||||
DB::table('business_settings')->insert([ |
||||
'key' => 'maintenance_mode', |
||||
'value' => 1, |
||||
'created_at' => now(), |
||||
'updated_at' => now(), |
||||
]); |
||||
} else { |
||||
DB::table('business_settings')->where(['key' => 'maintenance_mode'])->update([ |
||||
'key' => 'maintenance_mode', |
||||
'value' => $maintenance_mode->value == 1 ? 0 : 1, |
||||
'updated_at' => now(), |
||||
]); |
||||
} |
||||
|
||||
if (isset($maintenance_mode) && $maintenance_mode->value){ |
||||
return response()->json(['message'=>'Maintenance is off.']); |
||||
} |
||||
return response()->json(['message'=>'Maintenance is on.']); |
||||
} |
||||
|
||||
public function update_fcm_token(Request $request){ |
||||
$admin = $request->user(); |
||||
$admin->firebase_token = $request->token; |
||||
$admin->save(); |
||||
|
||||
return response()->json([]); |
||||
|
||||
} |
||||
} |
@ -0,0 +1,190 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Admin; |
||||
use App\Models\Vehicle; |
||||
use Illuminate\Http\Request; |
||||
use App\Http\Controllers\Controller; |
||||
use Brian2694\Toastr\Facades\Toastr; |
||||
use App\CentralLogics\Helpers; |
||||
use App\Models\DeliveryMan; |
||||
use Illuminate\Support\Facades\Validator; |
||||
class VehicleController extends Controller |
||||
{ |
||||
/** |
||||
* Display a listing of the resource. |
||||
* |
||||
* @return \Illuminate\Http\Response |
||||
*/ |
||||
public function list(Request $request) |
||||
{ |
||||
$key = explode(' ', $request['search']); |
||||
$vehicles = Vehicle::when(isset($key) ,function ($q) use ($key) { |
||||
foreach ($key as $value) { |
||||
$q->where('type', 'like', "%{$value}%"); |
||||
} |
||||
})->latest()->paginate(config('default_pagination')); |
||||
return view('admin-views.vehicle.list', compact('vehicles') ); |
||||
} |
||||
|
||||
/** |
||||
* Show the form for creating a new resource. |
||||
* |
||||
* @return \Illuminate\Http\Response |
||||
*/ |
||||
public function create() |
||||
{ |
||||
return view('admin-views.vehicle.index'); |
||||
} |
||||
|
||||
/** |
||||
* Store a newly created resource in storage. |
||||
* |
||||
* @param \Illuminate\Http\Request $request |
||||
* @return \Illuminate\Http\Response |
||||
*/ |
||||
public function store(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'type' => 'required|string|max:254|unique:vehicles', |
||||
'extra_charges' => 'required|numeric|between:0,999999999999.99', |
||||
'starting_coverage_area' => 'required|numeric|between:0,999999999999.99', |
||||
'maximum_coverage_area' => 'required|numeric|between:.01,999999999999.99|gt:starting_coverage_area', |
||||
]); |
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)]); |
||||
} |
||||
|
||||
$starting_coverage_area= $request->starting_coverage_area; |
||||
$maximum_coverage_area= $request->maximum_coverage_area; |
||||
|
||||
$temp = Vehicle::where(function ($query) use ($starting_coverage_area) { |
||||
$query->where('starting_coverage_area', '<=', $starting_coverage_area)->where('maximum_coverage_area', '>=', $starting_coverage_area); |
||||
})->orWhere(function ($query) use ($maximum_coverage_area) { |
||||
$query->where('starting_coverage_area', '<=', $maximum_coverage_area)->where('maximum_coverage_area', '>=', $maximum_coverage_area); |
||||
})->orWhere(function ($query) use ($starting_coverage_area,$maximum_coverage_area) { |
||||
$query->where('starting_coverage_area', '>=', $starting_coverage_area)->where('maximum_coverage_area', '<=', $maximum_coverage_area); |
||||
}) |
||||
->first(); |
||||
|
||||
if (isset($temp)) { |
||||
return response()->json(['errors' => [ |
||||
['code' => 'Vehicle_overlaped', 'message' => translate('messages.Coverage_area_overlapped')] |
||||
]]); |
||||
} |
||||
|
||||
|
||||
$vehicle = new Vehicle(); |
||||
$vehicle->type = $request->type; |
||||
$vehicle->status = 1; |
||||
$vehicle->extra_charges = $request->extra_charges; |
||||
$vehicle->starting_coverage_area = $request->starting_coverage_area; |
||||
$vehicle->maximum_coverage_area = $request->maximum_coverage_area; |
||||
$vehicle->save(); |
||||
|
||||
return response()->json(['success' => translate('messages.Vehicle_created')]); |
||||
} |
||||
|
||||
/** |
||||
* Display the specified resource. |
||||
* |
||||
* @param \App\Models\Vehicle $vehicle |
||||
* @return \Illuminate\Http\Response |
||||
*/ |
||||
public function view(Vehicle $vehicle, Request $request) |
||||
{ |
||||
$key = explode(' ', $request['search']); |
||||
$delivery_men = DeliveryMan::when(isset($key),function($query)use($key){ |
||||
$query->where(function($query)use($key){ |
||||
foreach ($key as $value) { |
||||
$query->orWhere('f_name', 'like', "%{$value}%")->orWhere('l_name', 'like', "%{$value}%"); |
||||
} |
||||
}); |
||||
}) |
||||
->with('vehicle') |
||||
->where('vehicle_id',$vehicle->id) |
||||
->latest()->paginate(config('default_pagination')); |
||||
return view('admin-views.vehicle.view', compact('vehicle','delivery_men') ); |
||||
} |
||||
|
||||
|
||||
|
||||
public function status($id, $status) |
||||
{ |
||||
$Vehicle = Vehicle::findOrFail($id); |
||||
$Vehicle->status = $status; |
||||
$Vehicle->save(); |
||||
Toastr::success(translate('messages.Vehicle_status_updated')); |
||||
return back(); |
||||
} |
||||
/** |
||||
* Show the form for editing the specified resource. |
||||
* |
||||
* @param \App\Models\Vehicle $vehicle |
||||
* @return \Illuminate\Http\Response |
||||
*/ |
||||
public function edit(Vehicle $vehicle) |
||||
{ |
||||
return view('admin-views.vehicle.edit', compact('vehicle') ); |
||||
} |
||||
|
||||
/** |
||||
* Update the specified resource in storage. |
||||
* |
||||
* @param \Illuminate\Http\Request $request |
||||
* @param \App\Models\Vehicle $vehicle |
||||
* @return \Illuminate\Http\Response |
||||
*/ |
||||
public function update(Request $request, Vehicle $vehicle) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'type' => 'required|string|max:254|unique:vehicles,type,'.$vehicle->id, |
||||
'extra_charges' => 'required|numeric|between:0,999999999999.99', |
||||
'starting_coverage_area' => 'required|numeric|between:0,999999999999.99', |
||||
'maximum_coverage_area' => 'required|numeric|between:.01,999999999999.99|gt:starting_coverage_area', |
||||
]); |
||||
|
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)]); |
||||
} |
||||
$starting_coverage_area= $request->starting_coverage_area; |
||||
$maximum_coverage_area= $request->maximum_coverage_area; |
||||
|
||||
$temp = Vehicle::where('id' ,'!=', $vehicle->id)->where(function ($q) use ($starting_coverage_area,$maximum_coverage_area ){ |
||||
$q->where(function ($query) use ($starting_coverage_area) { |
||||
$query->where('starting_coverage_area', '<=', $starting_coverage_area)->where('maximum_coverage_area', '>=', $starting_coverage_area); |
||||
})->orWhere(function ($query) use ($maximum_coverage_area) { |
||||
$query->where('starting_coverage_area', '<=', $maximum_coverage_area)->where('maximum_coverage_area', '>=', $maximum_coverage_area); |
||||
})->orWhere(function ($query) use ($starting_coverage_area, $maximum_coverage_area) { |
||||
$query->where('starting_coverage_area', '>=', $starting_coverage_area)->where('maximum_coverage_area', '<=', $maximum_coverage_area); |
||||
}); |
||||
}) |
||||
->first(); |
||||
if (isset($temp)) { |
||||
return response()->json(['errors' => [ |
||||
['code' => 'Vehicle_overlaped', 'message' => translate('messages.Coverage_area_overlapped')] |
||||
]]); |
||||
} |
||||
|
||||
$vehicle->type = $request->type; |
||||
$vehicle->extra_charges = $request->extra_charges; |
||||
$vehicle->starting_coverage_area = $request->starting_coverage_area; |
||||
$vehicle->maximum_coverage_area = $request->maximum_coverage_area; |
||||
$vehicle->save(); |
||||
|
||||
return response()->json(['success' => translate('messages.Vehicle_updated')]); |
||||
} |
||||
|
||||
/** |
||||
* Remove the specified resource from storage. |
||||
* |
||||
* @param \App\Models\Vehicle $vehicle |
||||
* @return \Illuminate\Http\Response |
||||
*/ |
||||
public function destroy(Request $request) |
||||
{ |
||||
$vehicle = Vehicle::findOrFail($request->vehicle); |
||||
$vehicle->delete(); |
||||
Toastr::success(translate('messages.vehicle') . ' ' . translate('messages.removed')); |
||||
return back(); |
||||
} |
||||
} |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,24 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Admin; |
||||
|
||||
use App\Http\Controllers\Controller; |
||||
use App\Models\User; |
||||
use App\Models\VisitorLog; |
||||
use Illuminate\Http\Request; |
||||
|
||||
class VisitorLogController extends Controller |
||||
{ |
||||
public function index(Request $request) |
||||
{ |
||||
abort(404); |
||||
$customer=User::where('id',$request->customer_id)->select(['id','f_name','l_name'])->first(); |
||||
$logs = VisitorLog::with('users:id,f_name,l_name','visitor_log:id,name') |
||||
->when(isset($request->customer_id), function ($q) use($request){ |
||||
$q->where('user_id',$request->customer_id); |
||||
}) |
||||
->latest() |
||||
->paginate(config('default_pagination')); |
||||
return view('admin-views.visitor-log.index', compact('logs','customer')); |
||||
} |
||||
} |
@ -0,0 +1,168 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Admin; |
||||
|
||||
|
||||
use Illuminate\Http\Request; |
||||
use App\Models\WithdrawalMethod; |
||||
use App\Http\Controllers\Controller; |
||||
use Brian2694\Toastr\Facades\Toastr; |
||||
// use App\CentralLogics\Helpers; |
||||
|
||||
class WithdrawalMethodController extends Controller |
||||
{ |
||||
protected WithdrawalMethod $withdrawal_method; |
||||
|
||||
public function __construct(WithdrawalMethod $withdrawal_method) |
||||
{ |
||||
$this->withdrawal_method = $withdrawal_method; |
||||
} |
||||
|
||||
public function list(Request $request) |
||||
{ |
||||
$search = $request->search; |
||||
$withdrawal_methods = $this->withdrawal_method |
||||
->when($request->has('search'), function ($query) use ($request) { |
||||
$keys = explode(' ', $request['search']); |
||||
return $query->where(function ($query) use ($keys) { |
||||
foreach ($keys as $key) { |
||||
$query->where('method_name', 'LIKE', '%' . $key . '%'); |
||||
} |
||||
}); |
||||
}) |
||||
->latest() |
||||
->paginate(config('default_pagination')); |
||||
|
||||
return view('admin-views.withdraw-method.withdraw-methods-list', compact('withdrawal_methods', 'search')); |
||||
} |
||||
|
||||
public function create(Request $request) |
||||
{ |
||||
return view('admin-views.withdraw-method.withdraw-methods-create'); |
||||
} |
||||
|
||||
public function store(Request $request) |
||||
{ |
||||
$request->validate([ |
||||
'method_name' => 'required', |
||||
'field_type' => 'required|array', |
||||
'field_name' => 'required|array', |
||||
'placeholder_text' => 'required|array', |
||||
// 'is_required' => '', |
||||
// 'is_default' => 'nullable|in:0,1 ', |
||||
]); |
||||
|
||||
$method_fields = []; |
||||
foreach ($request->field_name as $key => $field_name) { |
||||
$method_fields[] = [ |
||||
'input_type' => $request->field_type[$key], |
||||
'input_name' => strtolower(str_replace(' ', "_", $request->field_name[$key])), |
||||
'placeholder' => $request->placeholder_text[$key], |
||||
'is_required' => isset($request['is_required']) && isset($request['is_required'][$key]) ? 1 : 0, |
||||
]; |
||||
} |
||||
|
||||
$data_count = $this->withdrawal_method->get()->count(); |
||||
|
||||
$withdrawal_method_object = $this->withdrawal_method->updateOrCreate( |
||||
['method_name' => $request->method_name], |
||||
[ |
||||
'method_fields' => $method_fields, |
||||
'is_default' => ($request->has('is_default') && $request->is_default || $data_count == 0) == '1' ? 1 : 0, |
||||
] |
||||
); |
||||
|
||||
if ($request->has('is_default') && $request->is_default == '1') { |
||||
$this->withdrawal_method->where('id', '!=', $withdrawal_method_object->id)->update(['is_default' => 0]); |
||||
} |
||||
|
||||
Toastr::success('Withdrawal method added successfully'); |
||||
return redirect()->route('admin.business-settings.withdraw-method.list'); |
||||
} |
||||
|
||||
public function edit($id) |
||||
{ |
||||
$withdrawal_method = $this->withdrawal_method->find($id); |
||||
return View('admin-views.withdraw-method.withdraw-methods-edit', compact('withdrawal_method')); |
||||
} |
||||
|
||||
public function update(Request $request) |
||||
{ |
||||
// dd($request->all()); |
||||
$request->validate([ |
||||
'method_name' => 'required', |
||||
'field_type' => 'required|array', |
||||
'field_name' => 'required|array', |
||||
'placeholder_text' => 'required|array', |
||||
// 'is_required' => '', |
||||
// 'is_default' => 'nullable|in:1,0 ', |
||||
]); |
||||
$withdrawal_method = $this->withdrawal_method->find($request['id']); |
||||
|
||||
if(!isset($withdrawal_method)) { |
||||
Toastr::error('Withdrawal method not found!'); |
||||
return back(); |
||||
} |
||||
|
||||
$method_fields = []; |
||||
foreach ($request->field_name as $key=>$field_name) { |
||||
$method_fields[] = [ |
||||
'input_type' => $request->field_type[$key], |
||||
'input_name' => strtolower(str_replace(' ', "_", $request->field_name[$key])), |
||||
'placeholder' => $request->placeholder_text[$key], |
||||
'is_required' => isset($request['is_required']) && isset($request['is_required'][$key]) ? 1 : 0, |
||||
]; |
||||
} |
||||
|
||||
$withdrawal_method->method_name = $request->method_name; |
||||
$withdrawal_method->method_fields = $method_fields; |
||||
$withdrawal_method->is_default = $request->has('is_default') && $request->is_default == '1' ? 1 : 0; |
||||
$withdrawal_method->save(); |
||||
|
||||
if ($request->has('is_default') && $request->is_default == '1') { |
||||
$this->withdrawal_method->where('id', '!=', $withdrawal_method->id)->update(['is_default' => 0]); |
||||
} |
||||
|
||||
Toastr::success('Withdrawal method update successfully'); |
||||
return redirect()->route('admin.business-settings.withdraw-method.list'); |
||||
|
||||
} |
||||
|
||||
public function status_update(Request $request) |
||||
{ |
||||
$id = $request->id; |
||||
$success = 1; |
||||
$withdrawal_method = $this->withdrawal_method->where('id', $id)->first(); |
||||
$withdrawal_method->is_active = ($withdrawal_method['is_active'] == 0 || $withdrawal_method['is_active'] == null) ? 1 : 0; |
||||
$withdrawal_method->save(); |
||||
|
||||
return response()->json([ |
||||
'success' => $success, |
||||
], 200); |
||||
} |
||||
|
||||
public function default_status_update(Request $request) |
||||
{ |
||||
$id = $request->id; |
||||
$withdrawal_method = $this->withdrawal_method->where('id', $id)->first(); |
||||
$success = 1; |
||||
if ($withdrawal_method->is_default == 1) { |
||||
$success = 0; |
||||
} |
||||
|
||||
$this->withdrawal_method->where('id', '!=', $id)->update(['is_default' => $withdrawal_method->is_default]); |
||||
$this->withdrawal_method->where('id', $id)->update(['is_default' => !$withdrawal_method->is_default]); |
||||
|
||||
return response()->json([ |
||||
'success' => $success, |
||||
], 200); |
||||
} |
||||
|
||||
public function delete($id) |
||||
{ |
||||
$this->withdrawal_method->where('id', $id)->delete(); |
||||
|
||||
Toastr::success('Withdraw method removed successfully!'); |
||||
return back(); |
||||
} |
||||
} |
@ -0,0 +1,254 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Admin; |
||||
|
||||
use App\Models\Zone; |
||||
use App\Models\Incentive; |
||||
use Illuminate\Http\Request; |
||||
use App\CentralLogics\Helpers; |
||||
use App\Http\Controllers\Controller; |
||||
use Brian2694\Toastr\Facades\Toastr; |
||||
use Rap2hpoutre\FastExcel\FastExcel; |
||||
use Grimzy\LaravelMysqlSpatial\Types\Point; |
||||
use Grimzy\LaravelMysqlSpatial\Types\Polygon; |
||||
use Grimzy\LaravelMysqlSpatial\Types\LineString; |
||||
|
||||
class ZoneController extends Controller |
||||
{ |
||||
public function index() |
||||
{ |
||||
$zones = Zone::withCount(['restaurants','deliverymen'])->latest()->paginate(config('default_pagination')); |
||||
return view('admin-views.zone.index', compact('zones')); |
||||
} |
||||
|
||||
public function store(Request $request) |
||||
{ |
||||
$request->validate([ |
||||
'name' => 'required|unique:zones|max:191', |
||||
'coordinates' => 'required', |
||||
'per_km_delivery_charge'=>'required|numeric|between:1,999999999999.99', |
||||
'minimum_delivery_charge'=>'required|numeric|between:1,999999999999.99', |
||||
'maximum_shipping_charge' => 'nullable|numeric|between:0,999999999999.99|gt:minimum_delivery_charge', |
||||
'max_cod_order_amount' => 'nullable|numeric|between:0,999999999999.99', |
||||
]); |
||||
// if( $request['maximum_shipping_charge'] > 0 && $request['maximum_shipping_charge'] <= $request['minimum_delivery_charge']){ |
||||
// Toastr::error(translate('messages.maximum_shipping_charge_must_be_greater_than_minimum_shipping_charge')); |
||||
// return back(); |
||||
// } |
||||
$value = $request->coordinates; |
||||
foreach(explode('),(',trim($value,'()')) as $index=>$single_array){ |
||||
if($index == 0) |
||||
{ |
||||
$lastcord = explode(',',$single_array); |
||||
} |
||||
$coords = explode(',',$single_array); |
||||
$polygon[] = new Point($coords[0], $coords[1]); |
||||
} |
||||
$zone_id=Zone::all()->count() + 1; |
||||
$polygon[] = new Point($lastcord[0], $lastcord[1]); |
||||
$zone = new Zone(); |
||||
$zone->name = $request->name; |
||||
$zone->coordinates = new Polygon([new LineString($polygon)]); |
||||
$zone->restaurant_wise_topic = 'zone_'.$zone_id.'_restaurant'; |
||||
$zone->customer_wise_topic = 'zone_'.$zone_id.'_customer'; |
||||
$zone->deliveryman_wise_topic = 'zone_'.$zone_id.'_delivery_man'; |
||||
$zone->per_km_shipping_charge = $request->per_km_delivery_charge ?? null; |
||||
$zone->minimum_shipping_charge = $request->minimum_delivery_charge ?? null; |
||||
$zone->maximum_shipping_charge = $request->maximum_shipping_charge ?? null ; |
||||
$zone->max_cod_order_amount = $request->max_cod_order_amount ?? null; |
||||
$zone->save(); |
||||
|
||||
Toastr::success(translate('messages.zone_added_successfully')); |
||||
return back(); |
||||
} |
||||
|
||||
public function edit($id) |
||||
{ |
||||
if(env('APP_MODE')=='demo' && $id == 1) |
||||
{ |
||||
Toastr::warning(translate('messages.you_can_not_edit_this_zone_please_add_a_new_zone_to_edit')); |
||||
return back(); |
||||
} |
||||
$zone=Zone::selectRaw("*,ST_AsText(ST_Centroid(`coordinates`)) as center")->findOrFail($id); |
||||
return view('admin-views.zone.edit', compact('zone')); |
||||
} |
||||
public function zone_settings($id) |
||||
{ |
||||
if(env('APP_MODE')=='demo' && $id == 1) |
||||
{ |
||||
Toastr::warning(translate('messages.you_can_not_edit_this_zone_please_add_a_new_zone_to_edit')); |
||||
return back(); |
||||
} |
||||
$zone=Zone::with('incentives')->selectRaw("*,ST_AsText(ST_Centroid(`coordinates`)) as center")->findOrFail($id); |
||||
return view('admin-views.zone.settings', compact('zone')); |
||||
} |
||||
|
||||
public function update(Request $request, $id) |
||||
{ |
||||
$request->validate([ |
||||
'name' => 'required|max:191|unique:zones,name,'.$id, |
||||
'coordinates' => 'required', |
||||
]); |
||||
|
||||
$value = $request->coordinates; |
||||
foreach(explode('),(',trim($value,'()')) as $index=>$single_array){ |
||||
if($index == 0) |
||||
{ |
||||
$lastcord = explode(',',$single_array); |
||||
} |
||||
$coords = explode(',',$single_array); |
||||
$polygon[] = new Point($coords[0], $coords[1]); |
||||
} |
||||
$polygon[] = new Point($lastcord[0], $lastcord[1]); |
||||
$zone=Zone::findOrFail($id); |
||||
$zone->name = $request->name; |
||||
$zone->coordinates = new Polygon([new LineString($polygon)]); |
||||
$zone->restaurant_wise_topic = 'zone_'.$id.'_restaurant'; |
||||
$zone->customer_wise_topic = 'zone_'.$id.'_customer'; |
||||
$zone->deliveryman_wise_topic = 'zone_'.$id.'_delivery_man'; |
||||
$zone->save(); |
||||
Toastr::success(translate('messages.zone_updated_successfully')); |
||||
return redirect()->route('admin.zone.home'); |
||||
} |
||||
|
||||
public function zone_settings_update(Request $request, $id){ |
||||
$request->validate([ |
||||
'per_km_delivery_charge'=>'required|numeric|between:1,999999999999.99', |
||||
'minimum_delivery_charge'=>'required|numeric|between:1,999999999999.99', |
||||
'maximum_shipping_charge' => 'nullable|numeric|between:0,999999999999.99|gt:minimum_delivery_charge', |
||||
'max_cod_order_amount' => 'nullable|numeric|between:0,999999999999.99', |
||||
'increased_delivery_fee' => 'nullable|numeric|between:0.01,9999.99|required_if:increased_delivery_fee_status,1', |
||||
], [ |
||||
'increased_delivery_fee.required_if' => translate('messages.increased_delivery_fee_is_required') |
||||
]); |
||||
// if( $request['maximum_shipping_charge'] > 0 && $request['maximum_shipping_charge'] <= $request['minimum_delivery_charge']){ |
||||
// Toastr::error(translate('messages.maximum_shipping_charge_must_be_greater_than_minimum_shipping_charge')); |
||||
// return back(); |
||||
// } |
||||
|
||||
$zone=Zone::findOrFail($id); |
||||
$zone->restaurant_wise_topic = 'zone_'.$id.'_restaurant'; |
||||
$zone->customer_wise_topic = 'zone_'.$id.'_customer'; |
||||
$zone->deliveryman_wise_topic = 'zone_'.$id.'_delivery_man'; |
||||
$zone->per_km_shipping_charge = $request->per_km_delivery_charge; |
||||
$zone->minimum_shipping_charge = $request->minimum_delivery_charge; |
||||
$zone->maximum_shipping_charge = $request->maximum_shipping_charge ?? null; |
||||
$zone->max_cod_order_amount = $request->max_cod_order_amount ?? null; |
||||
$zone->increased_delivery_fee = $request->increased_delivery_fee ?? 0; |
||||
$zone->increased_delivery_fee_status = $request->increased_delivery_fee_status ?? 0; |
||||
$zone->increase_delivery_charge_message = $request->increase_delivery_charge_message ?? null; |
||||
$zone->save(); |
||||
Toastr::success(translate('messages.zone_settings_updated_successfully')); |
||||
// return redirect()->route('admin.zone.home'); |
||||
return back(); |
||||
} |
||||
|
||||
public function destroy(Zone $zone) |
||||
{ |
||||
if(env('APP_MODE')=='demo' && $zone->id == 1) |
||||
{ |
||||
Toastr::warning(translate('messages.you_can_not_delete_this_zone_please_add_a_new_zone_to_delete')); |
||||
return back(); |
||||
} |
||||
$zone->delete(); |
||||
Toastr::success(translate('messages.zone_deleted_successfully')); |
||||
return back(); |
||||
} |
||||
|
||||
public function status(Request $request) |
||||
{ |
||||
if(env('APP_MODE')=='demo' && $request->id == 1) |
||||
{ |
||||
Toastr::warning('Sorry!You can not inactive this zone!'); |
||||
return back(); |
||||
} |
||||
$zone = Zone::findOrFail($request->id); |
||||
$zone->status = $request->status; |
||||
$zone->save(); |
||||
Toastr::success(translate('messages.zone_status_updated')); |
||||
return back(); |
||||
} |
||||
|
||||
public function search(Request $request){ |
||||
$key = explode(' ', $request['search']); |
||||
$zones=Zone::withCount(['restaurants','deliverymen'])->where(function ($q) use ($key) { |
||||
foreach ($key as $value) { |
||||
$q->orWhere('name', 'like', "%{$value}%"); |
||||
} |
||||
})->limit(50)->get(); |
||||
return response()->json([ |
||||
'view'=>view('admin-views.zone.partials._table',compact('zones'))->render(), |
||||
'total'=>$zones->count() |
||||
]); |
||||
} |
||||
|
||||
public function get_coordinates($id){ |
||||
$zone=Zone::withoutGlobalScopes()->selectRaw("*,ST_AsText(ST_Centroid(`coordinates`)) as center")->findOrFail($id); |
||||
$data = Helpers::format_coordiantes($zone->coordinates[0]); |
||||
$center = (object)['lat'=>(float)trim(explode(' ',$zone->center)[1], 'POINT()'), 'lng'=>(float)trim(explode(' ',$zone->center)[0], 'POINT()')]; |
||||
return response()->json(['coordinates'=>$data, 'center'=>$center]); |
||||
} |
||||
|
||||
public function zone_filter($id) |
||||
{ |
||||
if($id == 'all') |
||||
{ |
||||
if(session()->has('zone_id')){ |
||||
session()->forget('zone_id'); |
||||
} |
||||
} |
||||
else{ |
||||
session()->put('zone_id', $id); |
||||
} |
||||
|
||||
return back(); |
||||
} |
||||
|
||||
public function get_all_zone_cordinates($id = 0) |
||||
{ |
||||
$zones = Zone::where('id', '<>', $id)->active()->get(); |
||||
$data = []; |
||||
foreach($zones as $zone) |
||||
{ |
||||
$data[] = Helpers::format_coordiantes($zone->coordinates[0]); |
||||
} |
||||
return response()->json($data,200); |
||||
} |
||||
|
||||
public function export_zones(Request $request, $type){ |
||||
|
||||
|
||||
$zones = Zone::with('restaurants', 'deliverymen')->get(); |
||||
if($type == 'excel'){ |
||||
return (new FastExcel(Helpers::export_zones($zones)))->download('Zones.xlsx'); |
||||
}elseif($type == 'csv'){ |
||||
return (new FastExcel(Helpers::export_zones($zones)))->download('Zones.csv'); |
||||
} |
||||
} |
||||
|
||||
public function store_incentive(Request $request, $zone_id) |
||||
{ |
||||
$request->validate([ |
||||
'earning' => 'required|unique:incentives|numeric|between:1,999999999999.99', |
||||
'incentive' => 'required|numeric|between:1,999999999999.99' |
||||
],[ |
||||
'earning.unique' => translate('This_earning_amount_already_exists') |
||||
]); |
||||
|
||||
$incentive = new Incentive(); |
||||
$incentive->earning = $request->earning; |
||||
$incentive->incentive = $request->incentive; |
||||
$incentive->zone_id = $zone_id; |
||||
$incentive->save(); |
||||
Toastr::success(translate('messages.incentive_inserted_successfully')); |
||||
return back(); |
||||
} |
||||
|
||||
public function destroy_incentive(Request $request, $id) |
||||
{ |
||||
$incentive = Incentive::findOrFail($id); |
||||
$incentive->delete(); |
||||
Toastr::success(translate('messages.incentive_deleted_successfully')); |
||||
return back(); |
||||
} |
||||
} |
@ -0,0 +1,444 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Api\V1\Auth; |
||||
|
||||
use App\Models\User; |
||||
use Carbon\CarbonInterval; |
||||
use Illuminate\Http\Request; |
||||
use App\CentralLogics\Helpers; |
||||
use Illuminate\Support\Carbon; |
||||
use App\Mail\EmailVerification; |
||||
use App\Models\BusinessSetting; |
||||
use App\CentralLogics\SMS_module; |
||||
use App\Models\WalletTransaction; |
||||
use App\Models\EmailVerifications; |
||||
use App\Models\PhoneVerifications; |
||||
use Illuminate\Support\Facades\DB; |
||||
use App\CentralLogics\CustomerLogic; |
||||
use App\Http\Controllers\Controller; |
||||
use Illuminate\Support\Facades\Mail; |
||||
use Illuminate\Support\Facades\Validator; |
||||
|
||||
class CustomerAuthController extends Controller |
||||
{ |
||||
public function verify_phone(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'phone' => 'required|min:11|max:14', |
||||
'otp'=>'required', |
||||
]); |
||||
|
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)], 403); |
||||
} |
||||
$user = User::where('phone', $request->phone)->first(); |
||||
if($user) |
||||
{ |
||||
if($user->is_phone_verified) |
||||
{ |
||||
return response()->json([ |
||||
'message' => translate('messages.phone_number_is_already_varified') |
||||
], 200); |
||||
|
||||
} |
||||
|
||||
if(env('APP_MODE')=='demo') |
||||
{ |
||||
if($request['otp']=="1234") |
||||
{ |
||||
$user->is_phone_verified = 1; |
||||
$user->save(); |
||||
|
||||
return response()->json([ |
||||
'message' => translate('messages.phone_number_varified_successfully'), |
||||
'otp' => 'inactive' |
||||
], 200); |
||||
} |
||||
return response()->json([ |
||||
'message' => translate('messages.phone_number_and_otp_not_matched') |
||||
], 404); |
||||
} |
||||
|
||||
$data = DB::table('phone_verifications')->where([ |
||||
'phone' => $request['phone'], |
||||
'token' => $request['otp'], |
||||
])->first(); |
||||
|
||||
if($data) |
||||
{ |
||||
DB::table('phone_verifications')->where([ |
||||
'phone' => $request['phone'], |
||||
'token' => $request['otp'], |
||||
])->delete(); |
||||
|
||||
$user->is_phone_verified = 1; |
||||
$user->save(); |
||||
return response()->json([ |
||||
'message' => translate('messages.phone_number_varified_successfully'), |
||||
'otp' => 'inactive' |
||||
], 200); |
||||
} |
||||
else{ |
||||
// $otp_hit = BusinessSetting::where('key', 'max_otp_hit')->first(); |
||||
// $max_otp_hit =isset($otp_hit) ? $otp_hit->value : 5 ; |
||||
$max_otp_hit = 5; |
||||
|
||||
// $otp_hit_time = BusinessSetting::where('key', 'max_otp_hit_time')->first(); |
||||
// $max_otp_hit_time =isset($otp_hit_time) ? $otp_hit_time->value : 30 ; |
||||
|
||||
$max_otp_hit_time = 60; // seconds |
||||
$temp_block_time = 600; // seconds |
||||
|
||||
$verification_data= DB::table('phone_verifications')->where('phone', $request['phone'])->first(); |
||||
|
||||
if(isset($verification_data)){ |
||||
|
||||
|
||||
// if($verification_data->is_blocked == 1){ |
||||
// $errors = []; |
||||
// array_push($errors, ['code' => 'otp', 'message' => translate('messages.your_account_is_blocked')]); |
||||
// return response()->json(['errors' => $errors ], 403); |
||||
// } |
||||
|
||||
|
||||
|
||||
if(isset($verification_data->temp_block_time ) && Carbon::parse($verification_data->temp_block_time)->DiffInSeconds() <= $temp_block_time){ |
||||
$time= $temp_block_time - Carbon::parse($verification_data->temp_block_time)->DiffInSeconds(); |
||||
|
||||
$errors = []; |
||||
array_push($errors, ['code' => 'otp_block_time', |
||||
'message' => translate('messages.please_try_again_after_').CarbonInterval::seconds($time)->cascade()->forHumans() |
||||
]); |
||||
return response()->json([ |
||||
'errors' => $errors |
||||
], 405); |
||||
} |
||||
|
||||
if($verification_data->is_temp_blocked == 1 && Carbon::parse($verification_data->updated_at)->DiffInSeconds() >= $max_otp_hit_time){ |
||||
DB::table('phone_verifications')->updateOrInsert(['phone' => $request['phone']], |
||||
[ |
||||
'otp_hit_count' => 0, |
||||
'is_temp_blocked' => 0, |
||||
'temp_block_time' => null, |
||||
'created_at' => now(), |
||||
'updated_at' => now(), |
||||
]); |
||||
} |
||||
|
||||
// if($verification_data->is_temp_blocked == 1 && Carbon::parse($verification_data->updated_at)->DiffInSeconds() < $max_otp_hit_time){ |
||||
// $errors = []; |
||||
// array_push($errors, ['code' => 'otp', 'message' => translate('messages.please_try_again_after_').$time.' '.translate('messages.seconds') ]); |
||||
// return response()->json([ |
||||
// 'errors' => $errors |
||||
// ], 405); |
||||
// } |
||||
|
||||
if($verification_data->otp_hit_count >= $max_otp_hit && Carbon::parse($verification_data->updated_at)->DiffInSeconds() < $max_otp_hit_time && $verification_data->is_temp_blocked == 0){ |
||||
|
||||
DB::table('phone_verifications')->updateOrInsert(['phone' => $request['phone']], |
||||
[ |
||||
'is_temp_blocked' => 1, |
||||
'temp_block_time' => now(), |
||||
'created_at' => now(), |
||||
'updated_at' => now(), |
||||
]); |
||||
$errors = []; |
||||
array_push($errors, ['code' => 'otp_temp_blocked', 'message' => translate('messages.Too_many_attemps') ]); |
||||
return response()->json([ |
||||
'errors' => $errors |
||||
], 405); |
||||
} |
||||
|
||||
|
||||
// if($verification_data->otp_hit_count >= $max_otp_hit && Carbon::parse($verification_data->updated_at)->DiffInSeconds() < $max_otp_hit_time){ |
||||
|
||||
// DB::table('phone_verifications')->updateOrInsert(['phone' => $request['phone']], |
||||
// [ |
||||
// // 'is_temp_blocked' => 1, |
||||
// 'created_at' => now(), |
||||
// 'updated_at' => now(), |
||||
// ]); |
||||
// // $errors = []; |
||||
// array_push($errors, ['code' => 'otp_warning', 'message' =>translate('messages.Too_many_attemps') ]); |
||||
// return response()->json([ |
||||
// 'errors' => $errors |
||||
// ], 405); |
||||
// } |
||||
} |
||||
|
||||
|
||||
DB::table('phone_verifications')->updateOrInsert(['phone' => $request['phone']], |
||||
[ |
||||
'otp_hit_count' => DB::raw('otp_hit_count + 1'), |
||||
'updated_at' => now(), |
||||
'temp_block_time' => null, |
||||
]); |
||||
|
||||
return response()->json([ |
||||
'message' => translate('messages.phone_number_and_otp_not_matched') |
||||
], 404); |
||||
} |
||||
} |
||||
return response()->json([ |
||||
'message' => translate('messages.not_found') |
||||
], 404); |
||||
|
||||
} |
||||
|
||||
public function check_email(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'email' => 'required|unique:users' |
||||
]); |
||||
|
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)], 403); |
||||
} |
||||
|
||||
|
||||
if (BusinessSetting::where(['key'=>'email_verification'])->first()->value){ |
||||
$token = rand(1000, 9999); |
||||
DB::table('email_verifications')->insert([ |
||||
'email' => $request['email'], |
||||
'token' => $token, |
||||
'created_at' => now(), |
||||
'updated_at' => now(), |
||||
]); |
||||
try{ |
||||
if(config('mail.status')) { |
||||
Mail::to($request['email'])->send(new EmailVerification($token)); |
||||
} |
||||
|
||||
}catch(\Exception $ex){ |
||||
info($ex); |
||||
} |
||||
|
||||
|
||||
return response()->json([ |
||||
'message' => 'Email is ready to register', |
||||
'token' => 'active' |
||||
], 200); |
||||
}else{ |
||||
return response()->json([ |
||||
'message' => 'Email is ready to register', |
||||
'token' => 'inactive' |
||||
], 200); |
||||
} |
||||
} |
||||
|
||||
public function verify_email(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'email' => 'required' |
||||
]); |
||||
|
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)], 403); |
||||
} |
||||
|
||||
$verify = EmailVerifications::where(['email' => $request['email'], 'token' => $request['token']])->first(); |
||||
|
||||
if (isset($verify)) { |
||||
$verify->delete(); |
||||
return response()->json([ |
||||
'message' => translate('messages.token_varified'), |
||||
], 200); |
||||
} |
||||
|
||||
$errors = []; |
||||
array_push($errors, ['code' => 'token', 'message' => translate('messages.token_not_found')]); |
||||
return response()->json(['errors' => $errors ] |
||||
, 404); |
||||
} |
||||
|
||||
public function register(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'f_name' => 'required', |
||||
'l_name' => 'required', |
||||
'email' => 'required|unique:users', |
||||
'phone' => 'required|unique:users', |
||||
'password' => 'required|min:6', |
||||
], [ |
||||
'f_name.required' => 'The first name field is required.', |
||||
'l_name.required' => 'The last name field is required.', |
||||
]); |
||||
|
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)], 403); |
||||
} |
||||
$ref_by= null ; |
||||
$customer_verification = BusinessSetting::where('key','customer_verification')->first()->value; |
||||
//Save point to refeer |
||||
if($request->ref_code) { |
||||
$ref_status = BusinessSetting::where('key','ref_earning_status')->first()->value; |
||||
if ($ref_status != '1') { |
||||
return response()->json(['errors'=>Helpers::error_formater('ref_code', translate('messages.referer_disable'))], 403); |
||||
} |
||||
|
||||
$referar_user = User::where('ref_code', '=', $request->ref_code)->first(); |
||||
if (!$referar_user || !$referar_user->status) { |
||||
return response()->json(['errors'=>Helpers::error_formater('ref_code',translate('messages.referer_code_not_found'))], 405); |
||||
} |
||||
|
||||
if(WalletTransaction::where('reference', $request->phone)->first()) { |
||||
return response()->json(['errors'=>Helpers::error_formater('phone',translate('Referrer code already used'))], 203); |
||||
} |
||||
|
||||
// $ref_code_exchange_amt = BusinessSetting::where('key','ref_earning_exchange_rate')->first()->value; |
||||
|
||||
// $refer_wallet_transaction = CustomerLogic::create_wallet_transaction($referar_user->id, $ref_code_exchange_amt, 'referrer',$request->phone); |
||||
//dd($refer_wallet_transaction); |
||||
// try{ |
||||
// if(config('mail.status')) { |
||||
// Mail::to($referar_user->email)->send(new \App\Mail\AddFundToWallet($refer_wallet_transaction)); |
||||
// } |
||||
// }catch(\Exception $ex) |
||||
// { |
||||
// info($ex->getMessage()); |
||||
// } |
||||
|
||||
$ref_by= $referar_user->id; |
||||
} |
||||
|
||||
$user = User::create([ |
||||
'f_name' => $request->f_name, |
||||
'l_name' => $request->l_name, |
||||
'email' => $request->email, |
||||
'phone' => $request->phone, |
||||
'ref_by' => $ref_by, |
||||
'password' => bcrypt($request->password), |
||||
]); |
||||
$user->ref_code = Helpers::generate_referer_code($user); |
||||
$user->save(); |
||||
|
||||
$token = $user->createToken('RestaurantCustomerAuth')->accessToken; |
||||
|
||||
if($customer_verification && env('APP_MODE') !='demo') |
||||
{ |
||||
|
||||
// $interval_time = BusinessSetting::where('key', 'otp_interval_time')->first(); |
||||
// $otp_interval_time= isset($interval_time) ? $interval_time->value : 20; |
||||
$otp_interval_time= 60; //seconds |
||||
$verification_data= DB::table('phone_verifications')->where('phone', $request['phone'])->first(); |
||||
|
||||
if(isset($verification_data) && Carbon::parse($verification_data->updated_at)->DiffInSeconds() < $otp_interval_time){ |
||||
$time= $otp_interval_time - Carbon::parse($verification_data->updated_at)->DiffInSeconds(); |
||||
$errors = []; |
||||
array_push($errors, ['code' => 'otp', 'message' => translate('messages.please_try_again_after_').$time.' '.translate('messages.seconds')]); |
||||
return response()->json([ |
||||
'errors' => $errors |
||||
], 405); |
||||
} |
||||
|
||||
$otp = rand(1000, 9999); |
||||
DB::table('phone_verifications')->updateOrInsert(['phone' => $request['phone']], |
||||
[ |
||||
'token' => $otp, |
||||
'otp_hit_count' => 0, |
||||
'created_at' => now(), |
||||
'updated_at' => now(), |
||||
]); |
||||
// Mail::to($request['email'])->send(new EmailVerification($otp)); |
||||
$response = SMS_module::send($request['phone'],$otp); |
||||
if($response != 'success') |
||||
{ |
||||
$errors = []; |
||||
array_push($errors, ['code' => 'otp', 'message' => translate('messages.faield_to_send_sms')]); |
||||
return response()->json([ |
||||
'errors' => $errors |
||||
], 405); |
||||
} |
||||
} |
||||
try |
||||
{ |
||||
Mail::to($request->email)->send(new \App\Mail\CustomerRegistration($request->f_name.' '.$request->l_name)); |
||||
} |
||||
catch(\Exception $ex) |
||||
{ |
||||
info($ex); |
||||
} |
||||
|
||||
return response()->json(['token' => $token,'is_phone_verified' => 0, 'phone_verify_end_url'=>"api/v1/auth/verify-phone" ], 200); |
||||
} |
||||
|
||||
public function login(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'phone' => 'required', |
||||
'password' => 'required|min:6' |
||||
]); |
||||
|
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)], 403); |
||||
} |
||||
$data = [ |
||||
'phone' => $request->phone, |
||||
'password' => $request->password |
||||
]; |
||||
|
||||
$customer_verification = BusinessSetting::where('key','customer_verification')->first()->value; |
||||
//dd($customer_verification); |
||||
if (auth()->attempt($data)) { |
||||
$token = auth()->user()->createToken('RestaurantCustomerAuth')->accessToken; |
||||
if(!auth()->user()->status) |
||||
{ |
||||
$errors = []; |
||||
array_push($errors, ['code' => 'auth-003', 'message' => translate('messages.your_account_is_blocked')]); |
||||
return response()->json([ |
||||
'errors' => $errors |
||||
], 403); |
||||
} |
||||
if($customer_verification && !auth()->user()->is_phone_verified && env('APP_MODE') != 'demo') |
||||
{ |
||||
|
||||
// $interval_time = BusinessSetting::where('key', 'otp_interval_time')->first(); |
||||
// $otp_interval_time= isset($interval_time) ? $interval_time->value : 60; |
||||
$otp_interval_time= 60; //seconds |
||||
|
||||
$verification_data= DB::table('phone_verifications')->where('phone', $request['phone'])->first(); |
||||
|
||||
if(isset($verification_data) && Carbon::parse($verification_data->updated_at)->DiffInSeconds() < $otp_interval_time){ |
||||
|
||||
$time= $otp_interval_time - Carbon::parse($verification_data->updated_at)->DiffInSeconds(); |
||||
$errors = []; |
||||
array_push($errors, ['code' => 'otp', 'message' => translate('messages.please_try_again_after_').$time.' '.translate('messages.seconds')]); |
||||
return response()->json([ |
||||
'errors' => $errors |
||||
], 405); |
||||
} |
||||
|
||||
$otp = rand(1000, 9999); |
||||
DB::table('phone_verifications')->updateOrInsert(['phone' => $request['phone']], |
||||
[ |
||||
'token' => $otp, |
||||
'otp_hit_count' => 0, |
||||
'created_at' => now(), |
||||
'updated_at' => now(), |
||||
]); |
||||
$response = SMS_module::send($request['phone'],$otp); |
||||
// $response = 'qq'; |
||||
if($response != 'success') |
||||
{ |
||||
$errors = []; |
||||
array_push($errors, ['code' => 'otp', 'message' => translate('messages.faield_to_send_sms')]); |
||||
return response()->json([ |
||||
'errors' => $errors |
||||
], 405); |
||||
} |
||||
} |
||||
$user = auth()->user(); |
||||
if($user->ref_code == null && isset($user->id)){ |
||||
$ref_code = Helpers::generate_referer_code($user); |
||||
DB::table('users')->where('phone', $user->phone)->update(['ref_code' => $ref_code]); |
||||
} |
||||
return response()->json(['token' => $token, 'is_phone_verified'=>auth()->user()->is_phone_verified], 200); |
||||
} else { |
||||
$errors = []; |
||||
array_push($errors, ['code' => 'auth-001', 'message' => translate('messages.Unauthorized')]); |
||||
return response()->json([ |
||||
'errors' => $errors |
||||
], 401); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,211 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Api\V1\Auth; |
||||
|
||||
use Carbon\CarbonInterval; |
||||
use App\Models\DeliveryMan; |
||||
use Illuminate\Http\Request; |
||||
use App\CentralLogics\Helpers; |
||||
use Illuminate\Support\Carbon; |
||||
use App\Models\BusinessSetting; |
||||
use App\CentralLogics\SMS_module; |
||||
use Illuminate\Support\Facades\DB; |
||||
use App\Http\Controllers\Controller; |
||||
use Illuminate\Support\Facades\Validator; |
||||
|
||||
class DMPasswordResetController extends Controller |
||||
{ |
||||
public function reset_password_request(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'phone' => 'required', |
||||
]); |
||||
|
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)], 403); |
||||
} |
||||
|
||||
$deliveryman = DeliveryMan::Where(['phone' => $request['phone']])->first(); |
||||
|
||||
if (isset($deliveryman)) { |
||||
if(env('APP_MODE') =='demo') |
||||
{ |
||||
return response()->json(['message' => translate('messages.otp_sent_successfull')], 200); |
||||
} |
||||
|
||||
// $interval_time = BusinessSetting::where('key', 'otp_interval_time')->first(); |
||||
// $otp_interval_time= isset($interval_time) ? $interval_time->value : 20; |
||||
$otp_interval_time= 60; //seconds |
||||
$verification_data= DB::table('password_resets')->where('email', $deliveryman['email'])->first(); |
||||
if(isset($verification_data) && Carbon::parse($verification_data->created_at)->DiffInSeconds() < $otp_interval_time){ |
||||
$time= $otp_interval_time - Carbon::parse($verification_data->created_at)->DiffInSeconds(); |
||||
$errors = []; |
||||
array_push($errors, ['code' => 'otp', 'message' => translate('messages.please_try_again_after_').$time.' '.translate('messages.seconds')]); |
||||
return response()->json([ |
||||
'errors' => $errors |
||||
], 405); |
||||
} |
||||
|
||||
$token = rand(1000,9999); |
||||
DB::table('password_resets')->updateOrInsert(['email' => $deliveryman['email']], |
||||
[ |
||||
'token' => $token, |
||||
'created_at' => now(), |
||||
]); |
||||
$response = SMS_module::send($request['phone'],$token); |
||||
if($response == 'success') |
||||
{ |
||||
return response()->json(['message' => translate('messages.otp_sent_successfull')], 200); |
||||
} |
||||
else |
||||
{ |
||||
$errors = []; |
||||
array_push($errors, ['code' => 'otp', 'message' => translate('messages.failed_to_send_sms')]); |
||||
return response()->json([ |
||||
'errors' => $errors |
||||
], 405); |
||||
} |
||||
} |
||||
$errors = []; |
||||
array_push($errors, ['code' => 'not-found', 'message' => 'Phone number not found!']); |
||||
return response()->json(['errors' => $errors], 404); |
||||
} |
||||
|
||||
public function verify_token(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'phone' => 'required|regex:/^([0-9\s\-\+\(\)]*)$/|min:10', |
||||
'reset_token'=> 'required' |
||||
]); |
||||
|
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)], 403); |
||||
} |
||||
$user=DeliveryMan::where('phone', $request->phone)->first(); |
||||
if (!isset($user)) { |
||||
$errors = []; |
||||
array_push($errors, ['code' => 'not-found', 'message' => 'Phone number not found!']); |
||||
return response()->json(['errors' => $errors |
||||
], 404); |
||||
} |
||||
if(env('APP_MODE')=='demo') |
||||
{ |
||||
if($request['reset_token'] == '1234') |
||||
{ |
||||
return response()->json(['message'=>"Token found, you can proceed"], 200); |
||||
} |
||||
$errors = []; |
||||
array_push($errors, ['code' => 'reset_token', 'message' => 'Invalid token.']); |
||||
return response()->json(['errors' => $errors |
||||
], 400); |
||||
} |
||||
$data = DB::table('password_resets')->where(['token' => $request['reset_token'],'email'=>$user->email])->first(); |
||||
if (isset($data)) { |
||||
return response()->json(['message'=>"Token found, you can proceed"], 200); |
||||
} else{ |
||||
// $otp_hit = BusinessSetting::where('key', 'max_otp_hit')->first(); |
||||
// $max_otp_hit =isset($otp_hit) ? $otp_hit->value : 5 ; |
||||
$max_otp_hit = 5; |
||||
// $otp_hit_time = BusinessSetting::where('key', 'max_otp_hit_time')->first(); |
||||
// $max_otp_hit_time = isset($otp_hit_time) ? $otp_hit_time->value : 30 ; |
||||
$max_otp_hit_time = 60; // seconds |
||||
$temp_block_time = 600; // seconds |
||||
$verification_data= DB::table('password_resets')->where('email', $user->email)->first(); |
||||
|
||||
if(isset($verification_data)){ |
||||
$time= $temp_block_time - Carbon::parse($verification_data->temp_block_time)->DiffInSeconds(); |
||||
|
||||
if(isset($verification_data->temp_block_time ) && Carbon::parse($verification_data->temp_block_time)->DiffInSeconds() <= $temp_block_time){ |
||||
$time= $temp_block_time - Carbon::parse($verification_data->temp_block_time)->DiffInSeconds(); |
||||
|
||||
$errors = []; |
||||
array_push($errors, ['code' => 'otp_block_time', 'message' => translate('messages.please_try_again_after_').CarbonInterval::seconds($time)->cascade()->forHumans() |
||||
]); |
||||
return response()->json([ |
||||
'errors' => $errors |
||||
], 405); |
||||
} |
||||
|
||||
if($verification_data->is_temp_blocked == 1 && Carbon::parse($verification_data->created_at)->DiffInSeconds() >= $max_otp_hit_time){ |
||||
DB::table('password_resets')->updateOrInsert(['email' => $user->email], |
||||
[ |
||||
'otp_hit_count' => 0, |
||||
'is_temp_blocked' => 0, |
||||
'temp_block_time' => null, |
||||
'created_at' => now(), |
||||
]); |
||||
} |
||||
|
||||
if($verification_data->otp_hit_count >= $max_otp_hit && Carbon::parse($verification_data->created_at)->DiffInSeconds() < $max_otp_hit_time && $verification_data->is_temp_blocked == 0){ |
||||
|
||||
DB::table('password_resets')->updateOrInsert(['email' => $user->email], [ |
||||
'is_temp_blocked' => 1, |
||||
'temp_block_time' => now(), |
||||
'created_at' => now(), |
||||
]); |
||||
$errors = []; |
||||
array_push($errors, ['code' => 'otp_temp_blocked', 'message' => translate('messages.Too_many_attemps') ]); |
||||
return response()->json([ |
||||
'errors' => $errors |
||||
], 405); |
||||
} |
||||
} |
||||
|
||||
DB::table('password_resets')->updateOrInsert(['email' => $user->email], |
||||
[ |
||||
'otp_hit_count' => DB::raw('otp_hit_count + 1'), |
||||
'created_at' => now(), |
||||
'temp_block_time' => null, |
||||
]); |
||||
} |
||||
|
||||
$errors = []; |
||||
array_push($errors, ['code' => 'reset_token', 'message' => 'Invalid token.']); |
||||
return response()->json(['errors' => $errors |
||||
], 400); |
||||
} |
||||
|
||||
public function reset_password_submit(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'phone' => 'required|regex:/^([0-9\s\-\+\(\)]*)$/|min:10', |
||||
'reset_token'=> 'required', |
||||
'password'=> 'required|min:6', |
||||
'confirm_password'=> 'required|same:password', |
||||
]); |
||||
|
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)], 403); |
||||
} |
||||
if(env('APP_MODE')=='demo') |
||||
{ |
||||
if($request['reset_token']=="1234") |
||||
{ |
||||
DB::table('delivery_men')->where(['phone' => $request['phone']])->update([ |
||||
'password' => bcrypt($request['confirm_password']) |
||||
]); |
||||
return response()->json(['message' => 'Password changed successfully.'], 200); |
||||
} |
||||
$errors = []; |
||||
array_push($errors, ['code' => 'invalid', 'message' => 'Invalid token.']); |
||||
return response()->json(['errors' => $errors], 400); |
||||
} |
||||
$data = DB::table('password_resets')->where(['token' => $request['reset_token']])->first(); |
||||
if (isset($data)) { |
||||
if ($request['password'] == $request['confirm_password']) { |
||||
DB::table('delivery_men')->where(['email' => $data->email])->update([ |
||||
'password' => bcrypt($request['confirm_password']) |
||||
]); |
||||
DB::table('password_resets')->where(['token' => $request['reset_token']])->delete(); |
||||
return response()->json(['message' => 'Password changed successfully.'], 200); |
||||
} |
||||
$errors = []; |
||||
array_push($errors, ['code' => 'mismatch', 'message' => 'Password did,t match!']); |
||||
return response()->json(['errors' => $errors], 401); |
||||
} |
||||
|
||||
$errors = []; |
||||
array_push($errors, ['code' => 'invalid', 'message' => 'Invalid token.']); |
||||
return response()->json(['errors' => $errors], 400); |
||||
} |
||||
} |
@ -0,0 +1,132 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Api\V1\Auth; |
||||
|
||||
use App\CentralLogics\Helpers; |
||||
use App\Http\Controllers\Controller; |
||||
use App\Models\DeliveryMan; |
||||
use Illuminate\Http\Request; |
||||
use Illuminate\Support\Facades\Validator; |
||||
use Illuminate\Support\Str; |
||||
|
||||
class DeliveryManLoginController extends Controller |
||||
{ |
||||
public function login(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'phone' => 'required|exists:delivery_men,phone', |
||||
'password' => 'required|min:6' |
||||
]); |
||||
|
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)], 403); |
||||
} |
||||
|
||||
$data = [ |
||||
'phone' => $request->phone, |
||||
'password' => $request->password |
||||
]; |
||||
|
||||
if (auth('delivery_men')->attempt($data)) { |
||||
$token = Str::random(120); |
||||
|
||||
if(auth('delivery_men')->user()->application_status != 'approved') |
||||
{ |
||||
return response()->json([ |
||||
'errors' => [ |
||||
['code' => 'auth-003', 'message' => translate('messages.your_application_is_not_approved_yet')] |
||||
] |
||||
], 401); |
||||
} |
||||
else if(!auth('delivery_men')->user()->status) |
||||
{ |
||||
$errors = []; |
||||
array_push($errors, ['code' => 'auth-003', 'message' => translate('messages.your_account_has_been_suspended')]); |
||||
return response()->json([ |
||||
'errors' => $errors |
||||
], 401); |
||||
} |
||||
|
||||
$delivery_man = DeliveryMan::where(['phone' => $request['phone']])->first(); |
||||
$delivery_man->auth_token = $token; |
||||
$delivery_man->save(); |
||||
|
||||
if(isset($delivery_man->zone)){ |
||||
if($delivery_man->vehicle_id){ |
||||
|
||||
$topic = 'delivery_man_'.$delivery_man->zone->id.'_'.$delivery_man->vehicle_id; |
||||
}else{ |
||||
$topic = $delivery_man->type=='zone_wise'?$delivery_man->zone->deliveryman_wise_topic:'restaurant_dm_'.$delivery_man->restaurant_id; |
||||
} |
||||
} |
||||
return response()->json(['token' => $token, 'topic'=> isset($topic)?$topic:'No_topic_found'], 200); |
||||
} else { |
||||
$errors = []; |
||||
array_push($errors, ['code' => 'auth-001', 'message' => 'Unauthorized.']); |
||||
return response()->json([ |
||||
'errors' => $errors |
||||
], 401); |
||||
} |
||||
} |
||||
|
||||
public function store(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'f_name' => 'required', |
||||
'identity_type' => 'required|in:passport,driving_license,nid', |
||||
'identity_number' => 'required', |
||||
'email' => 'required|unique:delivery_men', |
||||
'phone' => 'required|regex:/^([0-9\s\-\+\(\)]*)$/|min:10|unique:delivery_men', |
||||
'password'=>'required|min:6', |
||||
'zone_id' => 'required', |
||||
'vehicle_id' => 'required', |
||||
'earning' => 'required|in:0,1', |
||||
'image' => 'nullable|max:2048', |
||||
'identity_image.*' => 'nullable|max:2048', |
||||
], [ |
||||
'f_name.required' => translate('messages.first_name_is_required'), |
||||
'zone_id.required' => translate('messages.select_a_zone'), |
||||
'earning.required' => translate('messages.select_dm_type') |
||||
]); |
||||
|
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)],403); |
||||
} |
||||
|
||||
if ($request->has('image')) { |
||||
$image_name = Helpers::upload('delivery-man/', 'png', $request->file('image')); |
||||
} else { |
||||
$image_name = 'def.png'; |
||||
} |
||||
|
||||
$id_img_names = []; |
||||
if (!empty($request->file('identity_image'))) { |
||||
foreach ($request->identity_image as $img) { |
||||
$identity_image = Helpers::upload('delivery-man/', 'png', $img); |
||||
array_push($id_img_names, $identity_image); |
||||
} |
||||
$identity_image = json_encode($id_img_names); |
||||
} else { |
||||
$identity_image = json_encode([]); |
||||
} |
||||
|
||||
$dm = New DeliveryMan(); |
||||
$dm->f_name = $request->f_name; |
||||
$dm->l_name = $request->l_name; |
||||
$dm->email = $request->email; |
||||
$dm->phone = $request->phone; |
||||
$dm->identity_number = $request->identity_number; |
||||
$dm->identity_type = $request->identity_type; |
||||
$dm->identity_image = $identity_image; |
||||
$dm->image = $image_name; |
||||
$dm->active = 0; |
||||
$dm->zone_id = $request->zone_id; |
||||
$dm->vehicle_id = $request->vehicle_id; |
||||
$dm->earning = $request->earning; |
||||
$dm->password = bcrypt($request->password); |
||||
$dm->application_status= 'pending'; |
||||
$dm->save(); |
||||
|
||||
return response()->json(['message' => translate('messages.deliveryman_added_successfully')], 200); |
||||
} |
||||
} |
@ -0,0 +1,218 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Api\V1\Auth; |
||||
|
||||
use App\Models\User; |
||||
use Carbon\CarbonInterval; |
||||
use Illuminate\Http\Request; |
||||
use App\CentralLogics\Helpers; |
||||
use Illuminate\Support\Carbon; |
||||
use App\Models\BusinessSetting; |
||||
use App\CentralLogics\SMS_module; |
||||
use Illuminate\Support\Facades\DB; |
||||
use App\Http\Controllers\Controller; |
||||
use Illuminate\Support\Facades\Validator; |
||||
|
||||
class PasswordResetController extends Controller |
||||
{ |
||||
public function reset_password_request(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'phone' => 'required', |
||||
]); |
||||
|
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)], 403); |
||||
} |
||||
|
||||
$customer = User::Where(['phone' => $request['phone']])->first(); |
||||
|
||||
if (isset($customer)) { |
||||
if(env('APP_MODE')=='demo') |
||||
{ |
||||
return response()->json(['message' => translate('messages.otp_sent_successfull')], 200); |
||||
} |
||||
|
||||
|
||||
// $interval_time = BusinessSetting::where('key', 'otp_interval_time')->first(); |
||||
// $otp_interval_time= isset($interval_time) ? $interval_time->value : 20; |
||||
$otp_interval_time= 60; //seconds |
||||
$password_verification_data= DB::table('password_resets')->where('email', $customer['email'])->first(); |
||||
if(isset($password_verification_data) && Carbon::parse($password_verification_data->created_at)->DiffInSeconds() < $otp_interval_time){ |
||||
$time= $otp_interval_time - Carbon::parse($password_verification_data->created_at)->DiffInSeconds(); |
||||
$errors = []; |
||||
array_push($errors, ['code' => 'otp', 'message' => translate('messages.please_try_again_after_').$time.' '.translate('messages.seconds')]); |
||||
return response()->json([ |
||||
'errors' => $errors |
||||
], 405); |
||||
} |
||||
|
||||
|
||||
|
||||
$token = rand(1000,9999); |
||||
DB::table('password_resets')->updateOrInsert(['email' => $customer['email']], |
||||
[ |
||||
'token' => $token, |
||||
'created_at' => now(), |
||||
]); |
||||
// Mail::to($customer['email'])->send(new \App\Mail\PasswordResetMail($token, $customer->f_name)); |
||||
// return response()->json(['message' => 'Email sent successfully.'], 200); |
||||
$response = SMS_module::send($request['phone'],$token); |
||||
if($response == 'success') |
||||
{ |
||||
return response()->json(['message' => translate('messages.otp_sent_successfull')], 200); |
||||
} |
||||
else |
||||
{ |
||||
return response()->json([ |
||||
'errors' => [ |
||||
['code' => 'otp', 'message' => translate('messages.failed_to_send_sms')] |
||||
]], 405); |
||||
} |
||||
} |
||||
return response()->json(['errors' => [ |
||||
['code' => 'not-found', 'message' => 'Phone number not found!'] |
||||
]], 404); |
||||
} |
||||
|
||||
public function verify_token(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'phone' => 'required|regex:/^([0-9\s\-\+\(\)]*)$/|min:10', |
||||
'reset_token'=> 'required' |
||||
]); |
||||
|
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)], 403); |
||||
} |
||||
$user=User::where('phone', $request->phone)->first(); |
||||
if (!isset($user)) { |
||||
return response()->json(['errors' => [ |
||||
['code' => 'not-found', 'message' => 'Phone number not found!'] |
||||
]], 404); |
||||
} |
||||
|
||||
if(env('APP_MODE')=='demo') |
||||
{ |
||||
if($request['reset_token']=="1234") |
||||
{ |
||||
return response()->json(['message'=>"OTP found, you can proceed"], 200); |
||||
} |
||||
return response()->json(['errors' => [ |
||||
['code' => 'invalid', 'message' => 'Invalid OTP.'] |
||||
]], 400); |
||||
} |
||||
|
||||
$data = DB::table('password_resets')->where(['token' => $request['reset_token'],'email'=>$user->email])->first(); |
||||
if (isset($data)) { |
||||
return response()->json(['message'=>"OTP found, you can proceed"], 200); |
||||
} else{ |
||||
// $otp_hit = BusinessSetting::where('key', 'max_otp_hit')->first(); |
||||
// $max_otp_hit =isset($otp_hit) ? $otp_hit->value : 5 ; |
||||
$max_otp_hit = 5; |
||||
// $otp_hit_time = BusinessSetting::where('key', 'max_otp_hit_time')->first(); |
||||
// $max_otp_hit_time = isset($otp_hit_time) ? $otp_hit_time->value : 30 ; |
||||
$max_otp_hit_time = 60; // seconds |
||||
$temp_block_time = 600; // seconds |
||||
$verification_data= DB::table('password_resets')->where('email', $user->email)->first(); |
||||
|
||||
if(isset($verification_data)){ |
||||
$time= $temp_block_time - Carbon::parse($verification_data->temp_block_time)->DiffInSeconds(); |
||||
|
||||
if(isset($verification_data->temp_block_time ) && Carbon::parse($verification_data->temp_block_time)->DiffInSeconds() <= $temp_block_time){ |
||||
$time= $temp_block_time - Carbon::parse($verification_data->temp_block_time)->DiffInSeconds(); |
||||
|
||||
$errors = []; |
||||
array_push($errors, ['code' => 'otp_block_time', 'message' => translate('messages.please_try_again_after_').CarbonInterval::seconds($time)->cascade()->forHumans() |
||||
]); |
||||
return response()->json([ |
||||
'errors' => $errors |
||||
], 405); |
||||
} |
||||
|
||||
if($verification_data->is_temp_blocked == 1 && Carbon::parse($verification_data->created_at)->DiffInSeconds() >= $max_otp_hit_time){ |
||||
DB::table('password_resets')->updateOrInsert(['email' => $user->email], |
||||
[ |
||||
'otp_hit_count' => 0, |
||||
'is_temp_blocked' => 0, |
||||
'temp_block_time' => null, |
||||
'created_at' => now(), |
||||
]); |
||||
} |
||||
|
||||
if($verification_data->otp_hit_count >= $max_otp_hit && Carbon::parse($verification_data->created_at)->DiffInSeconds() < $max_otp_hit_time && $verification_data->is_temp_blocked == 0){ |
||||
|
||||
DB::table('password_resets')->updateOrInsert(['email' => $user->email], |
||||
[ |
||||
'is_temp_blocked' => 1, |
||||
'temp_block_time' => now(), |
||||
'created_at' => now(), |
||||
]); |
||||
$errors = []; |
||||
array_push($errors, ['code' => 'otp_temp_blocked', 'message' => translate('messages.Too_many_attemps') ]); |
||||
return response()->json([ |
||||
'errors' => $errors |
||||
], 405); |
||||
} |
||||
} |
||||
|
||||
|
||||
DB::table('password_resets')->updateOrInsert(['email' => $user->email], |
||||
[ |
||||
'otp_hit_count' => DB::raw('otp_hit_count + 1'), |
||||
'created_at' => now(), |
||||
'temp_block_time' => null, |
||||
]); |
||||
} |
||||
|
||||
return response()->json(['errors' => [ |
||||
['code' => 'invalid', 'message' => 'Invalid OTP.'] |
||||
]], 400); |
||||
} |
||||
|
||||
public function reset_password_submit(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'phone' => 'required|regex:/^([0-9\s\-\+\(\)]*)$/|min:10|exists:users,phone', |
||||
'reset_token'=> 'required', |
||||
'password'=> 'required|min:6', |
||||
'confirm_password'=> 'required|same:password', |
||||
]); |
||||
|
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)], 403); |
||||
} |
||||
|
||||
if(env('APP_MODE')=='demo') |
||||
{ |
||||
if($request['reset_token']=="1234") |
||||
{ |
||||
DB::table('users')->where(['phone' => $request['phone']])->update([ |
||||
'password' => bcrypt($request['confirm_password']) |
||||
]); |
||||
return response()->json(['message' => 'Password changed successfully.'], 200); |
||||
} |
||||
return response()->json([ |
||||
'message' => 'Phone number and otp not matched!' |
||||
], 404); |
||||
} |
||||
|
||||
|
||||
$data = DB::table('password_resets')->where(['token' => $request['reset_token']])->first(); |
||||
if (isset($data)) { |
||||
if ($request['password'] == $request['confirm_password']) { |
||||
DB::table('users')->where(['email' => $data->email])->update([ |
||||
'password' => bcrypt($request['confirm_password']) |
||||
]); |
||||
DB::table('password_resets')->where(['token' => $request['reset_token']])->delete(); |
||||
return response()->json(['message' => 'Password changed successfully.'], 200); |
||||
} |
||||
return response()->json(['errors' => [ |
||||
['code' => 'mismatch', 'message' => 'Password did,t match!'] |
||||
]], 401); |
||||
} |
||||
return response()->json(['errors' => [ |
||||
['code' => 'invalid', 'message' => translate('messages.invalid_otp')] |
||||
]], 400); |
||||
} |
||||
} |
@ -0,0 +1,484 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\api\v1\auth; |
||||
|
||||
use App\CentralLogics\CustomerLogic; |
||||
use Carbon\CarbonInterval; |
||||
use App\CentralLogics\Helpers; |
||||
use App\Http\Controllers\Controller; |
||||
use App\Models\User; |
||||
use GuzzleHttp\Client; |
||||
use Illuminate\Http\Request; |
||||
use Illuminate\Support\Facades\Validator; |
||||
use App\CentralLogics\SMS_module; |
||||
use App\Models\BusinessSetting; |
||||
use Illuminate\Support\Carbon; |
||||
use App\Models\WalletTransaction; |
||||
use Illuminate\Support\Facades\Mail; |
||||
use Illuminate\Support\Facades\DB; |
||||
use Firebase\JWT\JWT; |
||||
use Illuminate\Support\Facades\Http; |
||||
|
||||
class SocialAuthController extends Controller |
||||
{ |
||||
public function social_register(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'token' => 'required', |
||||
'unique_id' => 'required', |
||||
'email' => 'required_if:medium,google,facebook|unique:users,email', |
||||
'phone' => 'required|unique:users,phone', |
||||
'medium' => 'required|in:google,facebook,apple', |
||||
]); |
||||
|
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)], 403); |
||||
} |
||||
|
||||
$client = new Client(); |
||||
$token = $request['token']; |
||||
$email = $request['email']; |
||||
$unique_id = $request['unique_id']; |
||||
try { |
||||
if ($request['medium'] == 'google') { |
||||
$res = $client->request('GET', 'https://www.googleapis.com/oauth2/v3/tokeninfo?id_token=' . $token); |
||||
$data = json_decode($res->getBody()->getContents(), true); |
||||
} elseif ($request['medium'] == 'facebook') { |
||||
$res = $client->request('GET', 'https://graph.facebook.com/' . $unique_id . '?access_token=' . $token . '&&fields=name,email'); |
||||
$data = json_decode($res->getBody()->getContents(), true); |
||||
} elseif ($request['medium'] == 'apple') { |
||||
$user = User::where('temp_token', $unique_id)->first(); |
||||
$data = [ |
||||
'email' => $user->email |
||||
]; |
||||
} |
||||
} catch (\Exception $e) { |
||||
return response()->json(['error' => 'wrong credential.','message'=>$e->getMessage()],403); |
||||
} |
||||
if($request['medium'] == 'apple'){ |
||||
$fast_name = implode('@', explode('@', $data['email'], -1)); |
||||
$last_name = ''; |
||||
|
||||
$user = User::where('email', $data['email'])->where('phone', $request->phone)->where('temp_token', $unique_id)->first(); |
||||
if (!isset($user)) { |
||||
//Check Exists Ref Code |
||||
$check_duplicate_ref = WalletTransaction::where('reference', $request->phone)->first(); |
||||
|
||||
//Check Exists Ref Code Condition |
||||
if ($check_duplicate_ref) { |
||||
return response()->json(['errors'=>['code'=>'ref_code','message'=>'Referral code already used']]); |
||||
} else { |
||||
$user = User::where('email', $data['email'])->where('temp_token', $unique_id)->first(); |
||||
$user->phone = $request->phone; |
||||
$user->password = bcrypt($request->phone); |
||||
|
||||
$user->ref_code = Helpers::generate_referer_code(); |
||||
$user->save(); |
||||
|
||||
//Save point to refeer |
||||
if ($request->ref_code) { |
||||
$checkRefCode = $request->ref_code; |
||||
$referar_user = User::where('ref_code', '=', $checkRefCode)->first(); |
||||
$ref_status = BusinessSetting::where('key', 'ref_earning_status')->first()->value; |
||||
if ($ref_status != '1') { |
||||
$errors = []; |
||||
array_push($errors, ['code' => 'ref_code', 'message' => translate('messages.referer_disable')]); |
||||
return response()->json([ |
||||
'errors' => $errors |
||||
], 405); |
||||
} |
||||
|
||||
if (!$referar_user) { |
||||
$errors = []; |
||||
array_push($errors, ['code' => 'ref_code', 'message' => translate('messages.referer_code_not_found')]); |
||||
return response()->json([ |
||||
'errors' => $errors |
||||
], 405); |
||||
} |
||||
|
||||
$user->ref_by =$referar_user->id; |
||||
$user->save(); |
||||
|
||||
// $ref_code_exchange_amt = BusinessSetting::where('key', 'ref_earning_exchange_rate')->first()->value; |
||||
|
||||
// $refer_wallet_transaction = CustomerLogic::create_wallet_transaction($referar_user->id, $ref_code_exchange_amt, 'referrer', $user->phone); |
||||
|
||||
// try { |
||||
// if (config('mail.status')) { |
||||
// Mail::to($referar_user->email)->send(new \App\Mail\AddFundToWallet($refer_wallet_transaction)); |
||||
// } |
||||
// } catch (\Exception $ex) { |
||||
// info($ex); |
||||
// } |
||||
} |
||||
} |
||||
} else { |
||||
return response()->json([ |
||||
'errors' => [ |
||||
['code' => 'auth-004', 'message' => translate('messages.email_already_exists')] |
||||
] |
||||
], 403); |
||||
} |
||||
|
||||
$data = [ |
||||
'phone' => $user->phone, |
||||
'password' => $user->phone |
||||
]; |
||||
$customer_verification = BusinessSetting::where('key','customer_verification')->first()->value; |
||||
if (auth()->attempt($data)) { |
||||
$token = auth()->user()->createToken('RestaurantCustomerAuth')->accessToken; |
||||
if(!auth()->user()->status) |
||||
{ |
||||
$errors = []; |
||||
array_push($errors, ['code' => 'auth-003', 'message' => translate('messages.your_account_is_blocked')]); |
||||
return response()->json([ |
||||
'errors' => $errors |
||||
], 403); |
||||
} |
||||
if($customer_verification && !auth()->user()->is_phone_verified && env('APP_MODE') != 'demo') |
||||
{ |
||||
// $interval_time = BusinessSetting::where('key', 'otp_interval_time')->first(); |
||||
// $otp_interval_time= isset($interval_time) ? $interval_time->value : 20; |
||||
$otp_interval_time= 60; //seconds |
||||
$phone_verification_data= DB::table('phone_verifications')->where('phone', $request['phone'])->first(); |
||||
if(isset($phone_verification_data) && Carbon::parse($phone_verification_data->updated_at)->DiffInSeconds() < $otp_interval_time){ |
||||
$time= $otp_interval_time - Carbon::parse($phone_verification_data->updated_at)->DiffInSeconds(); |
||||
$errors = []; |
||||
array_push($errors, ['code' => 'otp', 'message' => translate('messages.please_try_again_after_').$time.' '.translate('messages.seconds')]); |
||||
return response()->json([ |
||||
'errors' => $errors |
||||
], 405); |
||||
} |
||||
|
||||
$otp = rand(1000, 9999); |
||||
DB::table('phone_verifications')->updateOrInsert(['phone' => $request['phone']], |
||||
[ |
||||
'token' => $otp, |
||||
'created_at' => now(), |
||||
'updated_at' => now(), |
||||
]); |
||||
$response = SMS_module::send($request['phone'],$otp); |
||||
if($response != 'success') |
||||
{ |
||||
|
||||
$errors = []; |
||||
array_push($errors, ['code' => 'otp', 'message' => translate('messages.faield_to_send_sms')]); |
||||
return response()->json([ |
||||
'errors' => $errors |
||||
], 403); |
||||
} |
||||
} |
||||
return response()->json(['token' => $token, 'is_phone_verified'=>auth()->user()->is_phone_verified], 200); |
||||
} else { |
||||
$errors = []; |
||||
array_push($errors, ['code' => 'auth-001', 'message' => 'Unauthorized.']); |
||||
return response()->json([ |
||||
'errors' => $errors |
||||
], 401); |
||||
} |
||||
} |
||||
if ($request['medium'] != 'apple' && strcmp($email, $data['email']) === 0) { |
||||
$name = explode(' ', $data['name']); |
||||
if (count($name) > 1) { |
||||
$fast_name = implode(" ", array_slice($name, 0, -1)); |
||||
$last_name = end($name); |
||||
} else { |
||||
$fast_name = implode(" ", $name); |
||||
$last_name = ''; |
||||
} |
||||
$user = User::where('email', $email)->first(); |
||||
if (isset($user) == false) { |
||||
//Check Exists Ref Code |
||||
$check_duplicate_ref = WalletTransaction::where('reference', $request->phone)->first(); |
||||
|
||||
//Check Exists Ref Code Condition |
||||
if ($check_duplicate_ref) { |
||||
return response()->json(['errors'=>['code'=>'ref_code','message'=>'Referral code already used']]); |
||||
} else { |
||||
if(!isset($data['id']) && !isset($data['kid'])){ |
||||
return response()->json(['error' => 'wrong credential.'],403); |
||||
} |
||||
$pk = isset($data['id'])?$data['id']:$data['kid']; |
||||
$user = User::create([ |
||||
'f_name' => $fast_name, |
||||
'l_name' => $last_name, |
||||
'email' => $email, |
||||
'phone' => $request->phone, |
||||
'password' => bcrypt($pk), |
||||
'login_medium' => $request['medium'], |
||||
'social_id' => $pk, |
||||
]); |
||||
|
||||
$user->ref_code = Helpers::generate_referer_code(); |
||||
$user->save(); |
||||
|
||||
//Save point to refeer |
||||
if ($request->ref_code) { |
||||
$checkRefCode = $request->ref_code; |
||||
$referar_user = User::where('ref_code', '=', $checkRefCode)->first(); |
||||
$ref_status = BusinessSetting::where('key', 'ref_earning_status')->first()->value; |
||||
if ($ref_status != '1') { |
||||
$errors = []; |
||||
array_push($errors, ['code' => 'ref_code', 'message' => translate('messages.referer_disable')]); |
||||
return response()->json([ |
||||
'errors' => $errors |
||||
], 405); |
||||
} |
||||
|
||||
if (!$referar_user) { |
||||
$errors = []; |
||||
array_push($errors, ['code' => 'ref_code', 'message' => translate('messages.referer_code_not_found')]); |
||||
return response()->json([ |
||||
'errors' => $errors |
||||
], 405); |
||||
} |
||||
|
||||
$user->ref_by =$referar_user->id; |
||||
$user->save(); |
||||
|
||||
// $ref_code_exchange_amt = BusinessSetting::where('key', 'ref_earning_exchange_rate')->first()->value; |
||||
|
||||
// $refer_wallet_transaction = CustomerLogic::create_wallet_transaction($referar_user->id, $ref_code_exchange_amt, 'referrer', $user->phone); |
||||
|
||||
// try { |
||||
// if (config('mail.status')) { |
||||
// Mail::to($referar_user->email)->send(new \App\Mail\AddFundToWallet($refer_wallet_transaction)); |
||||
// } |
||||
// } catch (\Exception $ex) { |
||||
// info($ex); |
||||
// } |
||||
} |
||||
} |
||||
} else { |
||||
return response()->json([ |
||||
'errors' => [ |
||||
['code' => 'auth-004', 'message' => translate('messages.email_already_exists')] |
||||
] |
||||
], 403); |
||||
} |
||||
|
||||
$data = [ |
||||
'phone' => $user->phone, |
||||
'password' => $user->social_id |
||||
]; |
||||
$customer_verification = BusinessSetting::where('key','customer_verification')->first()->value; |
||||
if (auth()->loginUsingId($user->id)) { |
||||
$token = auth()->user()->createToken('RestaurantCustomerAuth')->accessToken; |
||||
if(!auth()->user()->status) |
||||
{ |
||||
$errors = []; |
||||
array_push($errors, ['code' => 'auth-003', 'message' => translate('messages.your_account_is_blocked')]); |
||||
return response()->json([ |
||||
'errors' => $errors |
||||
], 403); |
||||
} |
||||
if($customer_verification && !auth()->user()->is_phone_verified && env('APP_MODE') != 'demo') |
||||
{ |
||||
// $interval_time = BusinessSetting::where('key', 'otp_interval_time')->first(); |
||||
// $otp_interval_time= isset($interval_time) ? $interval_time->value : 20; |
||||
$otp_interval_time= 60; //seconds |
||||
$phone_verification_data= DB::table('phone_verifications')->where('phone', $request['phone'])->first(); |
||||
if(isset($phone_verification_data) && Carbon::parse($phone_verification_data->updated_at)->DiffInSeconds() < $otp_interval_time){ |
||||
$time= $otp_interval_time - Carbon::parse($phone_verification_data->updated_at)->DiffInSeconds(); |
||||
$errors = []; |
||||
array_push($errors, ['code' => 'otp', 'message' => translate('messages.please_try_again_after_').$time.' '.translate('messages.seconds')]); |
||||
return response()->json([ |
||||
'errors' => $errors |
||||
], 405); |
||||
} |
||||
|
||||
$otp = rand(1000, 9999); |
||||
DB::table('phone_verifications')->updateOrInsert(['phone' => $request['phone']], |
||||
[ |
||||
'token' => $otp, |
||||
'created_at' => now(), |
||||
'updated_at' => now(), |
||||
]); |
||||
$response = SMS_module::send($request['phone'],$otp); |
||||
if($response != 'success') |
||||
{ |
||||
|
||||
$errors = []; |
||||
array_push($errors, ['code' => 'otp', 'message' => translate('messages.faield_to_send_sms')]); |
||||
return response()->json([ |
||||
'errors' => $errors |
||||
], 403); |
||||
} |
||||
} |
||||
return response()->json(['token' => $token, 'is_phone_verified'=>auth()->user()->is_phone_verified], 200); |
||||
} else { |
||||
$errors = []; |
||||
array_push($errors, ['code' => 'auth-001', 'message' => 'Unauthorized.']); |
||||
return response()->json([ |
||||
'errors' => $errors |
||||
], 401); |
||||
} |
||||
|
||||
|
||||
} |
||||
|
||||
return response()->json(['error' => translate('messages.email_does_not_match')]); |
||||
} |
||||
|
||||
|
||||
public function social_login(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'token' => 'required', |
||||
'unique_id' => 'required', |
||||
'email' => 'required_if:medium,google,facebook', |
||||
'medium' => 'required|in:google,facebook,apple', |
||||
]); |
||||
|
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)], 403); |
||||
} |
||||
|
||||
$client = new Client(); |
||||
$token = $request['token']; |
||||
$email = $request['email']; |
||||
$unique_id = $request['unique_id']; |
||||
try { |
||||
if ($request['medium'] == 'google') { |
||||
$res = $client->request('GET', 'https://www.googleapis.com/oauth2/v3/tokeninfo?id_token=' . $token); |
||||
$data = json_decode($res->getBody()->getContents(), true); |
||||
} elseif ($request['medium'] == 'facebook') { |
||||
$res = $client->request('GET', 'https://graph.facebook.com/' . $unique_id . '?access_token=' . $token . '&&fields=name,email'); |
||||
$data = json_decode($res->getBody()->getContents(), true); |
||||
} elseif ($request['medium'] == 'apple') { |
||||
$apple_login=\App\Models\BusinessSetting::where(['key'=>'apple_login'])->first(); |
||||
if($apple_login){ |
||||
$apple_login = json_decode($apple_login->value)[0]; |
||||
} |
||||
$teamId = $apple_login->team_id; |
||||
$keyId = $apple_login->key_id; |
||||
$sub = $apple_login->client_id; |
||||
$aud = 'https://appleid.apple.com'; |
||||
$iat = strtotime('now'); |
||||
$exp = strtotime('+60days'); |
||||
$keyContent = file_get_contents('storage/app/public/apple-login/'.$apple_login->service_file); |
||||
|
||||
$token = JWT::encode([ |
||||
'iss' => $teamId, |
||||
'iat' => $iat, |
||||
'exp' => $exp, |
||||
'aud' => $aud, |
||||
'sub' => $sub, |
||||
], $keyContent, 'ES256', $keyId); |
||||
$redirect_uri = $apple_login->redirect_url??'www.example.com/apple-callback'; |
||||
$res = Http::asForm()->post('https://appleid.apple.com/auth/token', [ |
||||
'grant_type' => 'authorization_code', |
||||
'code' => $unique_id, |
||||
'redirect_uri' => $redirect_uri, |
||||
'client_id' => $sub, |
||||
'client_secret' => $token, |
||||
]); |
||||
|
||||
|
||||
$claims = explode('.', $res['id_token'])[1]; |
||||
$data = json_decode(base64_decode($claims),true); |
||||
} |
||||
} catch (\Exception $e) { |
||||
return response()->json(['error' => 'wrong credential.','message'=>$e->getMessage()],403); |
||||
} |
||||
if(!isset($claims)){ |
||||
|
||||
if (strcmp($email, $data['email']) != 0 || (!isset($data['id']) && !isset($data['kid']))) { |
||||
return response()->json(['error' => translate('messages.email_does_not_match')],403); |
||||
} |
||||
} |
||||
|
||||
$user = User::where('email', $data['email'])->first(); |
||||
|
||||
if($request['medium'] == 'apple'){ |
||||
try { |
||||
if(isset($user) == false ) |
||||
{ |
||||
$user = new User(); |
||||
} |
||||
$user->f_name = implode('@', explode('@', $data['email'], -1)); |
||||
$user->l_name = ''; |
||||
$user->email = $data['email']; |
||||
$user->login_medium = $request['medium']; |
||||
$user->temp_token = $unique_id; |
||||
$user->save(); |
||||
} catch (\Throwable $e) { |
||||
return response()->json(['error' => 'wrong credential.','message'=>$e->getMessage()],403); |
||||
} |
||||
} |
||||
|
||||
if(isset($user) == false ) |
||||
{ |
||||
return response()->json(['token' => null, 'is_phone_verified'=>0], 200); |
||||
} |
||||
|
||||
if($request['medium'] == 'apple' && $user->phone == null) |
||||
{ |
||||
return response()->json(['token' => null, 'is_phone_verified'=>0], 200); |
||||
} |
||||
|
||||
$customer_verification = BusinessSetting::where('key','customer_verification')->first()->value; |
||||
if (auth()->loginUsingId($user->id)) { |
||||
$token = auth()->user()->createToken('RestaurantCustomerAuth')->accessToken; |
||||
if(!auth()->user()->status) |
||||
{ |
||||
$errors = []; |
||||
array_push($errors, ['code' => 'auth-003', 'message' => translate('messages.your_account_is_blocked')]); |
||||
return response()->json([ |
||||
'errors' => $errors |
||||
], 403); |
||||
} |
||||
if($customer_verification && !auth()->user()->is_phone_verified && env('APP_MODE') != 'demo') |
||||
{ |
||||
// $interval_time = BusinessSetting::where('key', 'otp_interval_time')->first(); |
||||
// $otp_interval_time= isset($interval_time) ? $interval_time->value : 20; |
||||
$otp_interval_time= 60; //seconds |
||||
$phone_verification_data= DB::table('phone_verifications')->where('phone', $request['phone'])->first(); |
||||
if(isset($phone_verification_data) && Carbon::parse($phone_verification_data->updated_at)->DiffInSeconds() < $otp_interval_time){ |
||||
$time= $otp_interval_time - Carbon::parse($phone_verification_data->updated_at)->DiffInSeconds(); |
||||
$errors = []; |
||||
array_push($errors, ['code' => 'otp', 'message' => translate('messages.please_try_again_after_').$time.' '.translate('messages.seconds')]); |
||||
return response()->json([ |
||||
'errors' => $errors |
||||
], 405); |
||||
} |
||||
$otp = rand(1000, 9999); |
||||
DB::table('phone_verifications')->updateOrInsert(['phone' => $user->phone], |
||||
[ |
||||
'token' => $otp, |
||||
'otp_hit_count' => 0, |
||||
'created_at' => now(), |
||||
'updated_at' => now(), |
||||
]); |
||||
$response = SMS_module::send($user->phone,$otp); |
||||
if($response != 'success') |
||||
{ |
||||
|
||||
$errors = []; |
||||
array_push($errors, ['code' => 'otp', 'message' => translate('messages.faield_to_send_sms')]); |
||||
return response()->json([ |
||||
'errors' => $errors |
||||
], 403); |
||||
} |
||||
} |
||||
if($user->ref_code == null && isset($user->id)){ |
||||
$ref_code = Helpers::generate_referer_code($user); |
||||
DB::table('users')->where('phone', $user->phone)->update(['ref_code' => $ref_code]); |
||||
} |
||||
return response()->json(['token' => $token, 'is_phone_verified'=>auth()->user()->is_phone_verified, 'phone'=>$user->phone, 'res'=>$res], 200); |
||||
} else { |
||||
$errors = []; |
||||
array_push($errors, ['code' => 'auth-001', 'message' => 'Unauthorized.']); |
||||
return response()->json([ |
||||
'errors' => $errors |
||||
], 401); |
||||
} |
||||
|
||||
return response()->json([ |
||||
'errors'=>[ |
||||
['code'=>'not-found','message' => translate('messages.user_not_found')] |
||||
] |
||||
], 404); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,64 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Api\V1\Auth; |
||||
|
||||
use App\CentralLogics\Helpers; |
||||
use App\Http\Controllers\Controller; |
||||
use App\Models\Restaurant; |
||||
use App\Models\RestaurantWallet; |
||||
use App\Models\SubscriptionPackage; |
||||
use Illuminate\Http\Request; |
||||
|
||||
class SubscriptionController extends Controller |
||||
{ |
||||
public function package_renew_change_update_api(Request $request){ |
||||
$package = SubscriptionPackage::findOrFail($request->package_id); |
||||
$discount = $request->discount ?? 0; |
||||
$restaurant=Restaurant::findOrFail($request->restaurant_id); |
||||
$restaurant_id=$restaurant->id; |
||||
$total_parice =$package->price - (($package->price*$discount)/100); |
||||
$reference= $request->reference ?? null; |
||||
$type = $request->type; |
||||
|
||||
if ($request->payment_type == 'wallet') { |
||||
$wallet = RestaurantWallet::where('vendor_id',$restaurant->vendor_id)->first(); |
||||
if ( $wallet->balance >= $total_parice) { |
||||
$payment_method= 'wallet'; |
||||
$status= Helpers::subscription_plan_chosen($restaurant_id ,$package->id, $payment_method ,$reference ,$discount,$type); |
||||
|
||||
if($status === 'downgrade_error'){ |
||||
return response()->json([ |
||||
'errors' => ['message' => translate('messages.You_can_not_downgraded_to_this_package_please_choose_a_package_with_higher_upload_limits')] |
||||
], 403); |
||||
// Toastr::error(translate('messages.You_can_not_downgraded_to_this_package_please_choose_a_package_with_higher_upload_limits') ); |
||||
// return back(); |
||||
} |
||||
$wallet->total_withdrawn= $wallet->total_withdrawn +$total_parice; |
||||
$wallet->save(); |
||||
} |
||||
else{ |
||||
return response()->json([ |
||||
'errors' => ['message' => translate('messages.Insufficient Balance')] |
||||
], 403); |
||||
// Toastr::error('Insufficient Balance'); |
||||
// return back(); |
||||
} |
||||
} |
||||
elseif ($request->payment_type == 'pay_now') { |
||||
// dd('pay_now'); |
||||
$payment_method= 'manual_payment_admin'; |
||||
$status= Helpers::subscription_plan_chosen($restaurant_id ,$package->id, $payment_method ,$reference ,$discount,$type); |
||||
if($status === 'downgrade_error'){ |
||||
return response()->json([ |
||||
'errors' => ['message' => translate('messages.You_can_not_downgraded_to_this_package_please_choose_a_package_with_higher_upload_limits')] |
||||
], 403); |
||||
// Toastr::error(translate('messages.You_can_not_downgraded_to_this_package_please_choose_a_package_with_higher_upload_limits') ); |
||||
// return back(); |
||||
} |
||||
|
||||
} |
||||
return response()->json(['message' => translate('messages.subscription_successful')], 200); |
||||
// Toastr::success(translate('messages.subscription_successful') ); |
||||
// return back(); |
||||
} |
||||
} |
@ -0,0 +1,260 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Api\V1\Auth; |
||||
|
||||
use App\Models\Zone; |
||||
use App\Models\Vendor; |
||||
use App\Models\Restaurant; |
||||
use Illuminate\Support\Str; |
||||
use Illuminate\Http\Request; |
||||
use App\CentralLogics\Helpers; |
||||
use App\Models\BusinessSetting; |
||||
use App\Models\SubscriptionPackage; |
||||
use App\Http\Controllers\Controller; |
||||
use Illuminate\Support\Facades\Mail; |
||||
use App\Models\SubscriptionTransaction; |
||||
use Illuminate\Support\Facades\Validator; |
||||
use Grimzy\LaravelMysqlSpatial\Types\Point; |
||||
|
||||
class VendorLoginController extends Controller |
||||
{ |
||||
public function login(Request $request) |
||||
{ |
||||
|
||||
$validator = Validator::make($request->all(), [ |
||||
'email' => 'required', |
||||
'password' => 'required|min:6' |
||||
]); |
||||
|
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)], 403); |
||||
} |
||||
|
||||
$data = [ |
||||
'email' => $request->email, |
||||
'password' => $request->password |
||||
]; |
||||
|
||||
if (auth('vendor')->attempt($data)) { |
||||
$token = $this->genarate_token($request['email']); |
||||
$vendor = Vendor::where(['email' => $request['email']])->first(); |
||||
if($vendor->restaurants[0]->status == 0 && $vendor->status == 0) |
||||
// if(!$vendor->restaurants[0]->status) |
||||
{ |
||||
|
||||
return response()->json([ |
||||
'errors' => [ |
||||
['code' => 'auth-002', 'message' => translate('messages.inactive_vendor_warning')] |
||||
] |
||||
], 403); |
||||
} |
||||
|
||||
$restaurant=$vendor->restaurants[0]; |
||||
if( $restaurant->restaurant_model == 'none') |
||||
{ |
||||
return response()->json([ |
||||
'subscribed' => [ |
||||
'restaurant_id' => $vendor->restaurants[0]->id, 'type' => 'new_join' |
||||
] |
||||
], 200); |
||||
} |
||||
|
||||
if ( $restaurant->restaurant_model == 'subscription' ) { |
||||
$rest_sub = $restaurant->restaurant_sub; |
||||
if (isset($rest_sub)) { |
||||
if ($rest_sub->mobile_app == 0 ) { |
||||
return response()->json([ |
||||
'errors' => [ |
||||
['code'=>'no_mobile_app', 'message'=>translate('Your Subscription Plan is not Active for Mobile App')] |
||||
] |
||||
], 401); |
||||
} |
||||
} |
||||
} |
||||
if( $restaurant->restaurant_model == 'unsubscribed' && isset($restaurant->restaurant_sub_update_application)){ |
||||
$vendor->auth_token = $token; |
||||
$vendor->save(); |
||||
|
||||
if($restaurant->restaurant_sub_update_application->max_product== 'unlimited' ){ |
||||
$max_product_uploads= -1; |
||||
} |
||||
else{ |
||||
$max_product_uploads= $restaurant->restaurant_sub_update_application->max_product - $restaurant->foods()->count(); |
||||
if($max_product_uploads > 0){ |
||||
$max_product_uploads ?? 0; |
||||
}elseif($max_product_uploads < 0) { |
||||
$max_product_uploads = 0; |
||||
} |
||||
} |
||||
|
||||
$data['subscription_other_data'] = [ |
||||
'total_bill'=> (float) SubscriptionTransaction::where('restaurant_id', $restaurant->id)->where('package_id', $restaurant->restaurant_sub_update_application->package->id)->sum('paid_amount'), |
||||
'max_product_uploads' => (int) $max_product_uploads, |
||||
]; |
||||
|
||||
return response()->json(['token' => $token, 'zone_wise_topic'=> $vendor->restaurants[0]->zone->restaurant_wise_topic, |
||||
'subscription' => $restaurant->restaurant_sub_update_application, |
||||
'subscription_other_data' => $data['subscription_other_data'], |
||||
'balance' =>$vendor->wallet?(float)$vendor->wallet->balance:0, |
||||
'restaurant_id' =>(int) $restaurant->id, |
||||
'package' => $restaurant->restaurant_sub_update_application->package |
||||
], 426); |
||||
} |
||||
|
||||
if($restaurant->restaurant_model == 'unsubscribed' && !isset($restaurant->restaurant_sub_update_application)){ |
||||
return response()->json([ |
||||
'subscribed' => [ |
||||
'restaurant_id' => $vendor->restaurants[0]->id, 'type' => 'new_join' |
||||
] |
||||
], 200); |
||||
} |
||||
|
||||
$vendor->auth_token = $token; |
||||
$vendor->save(); |
||||
return response()->json(['token' => $token, 'zone_wise_topic'=> $vendor->restaurants[0]->zone->restaurant_wise_topic], 200); |
||||
} else { |
||||
$errors = []; |
||||
array_push($errors, ['code' => 'auth-001', 'message' => 'Unauthorized.']); |
||||
return response()->json([ |
||||
'errors' => $errors |
||||
], 401); |
||||
} |
||||
} |
||||
|
||||
private function genarate_token($email) |
||||
{ |
||||
$token = Str::random(120); |
||||
$is_available = Vendor::where('auth_token', $token)->where('email', '!=', $email)->count(); |
||||
if($is_available) |
||||
{ |
||||
$this->genarate_token($email); |
||||
} |
||||
return $token; |
||||
} |
||||
|
||||
|
||||
public function register(Request $request) |
||||
{ |
||||
$status = BusinessSetting::where('key', 'toggle_restaurant_registration')->first(); |
||||
if(!isset($status) || $status->value == '0') |
||||
{ |
||||
return response()->json(['errors' => Helpers::error_formater('self-registration', translate('messages.restaurant_self_registration_disabled'))]); |
||||
} |
||||
|
||||
$validator = Validator::make($request->all(), [ |
||||
'fName' => 'required', |
||||
'restaurant_name' => 'required', |
||||
'restaurant_address' => 'required', |
||||
'lat' => 'required|numeric|min:-90|max:90', |
||||
'lng' => 'required|numeric|min:-180|max:180', |
||||
'email' => 'required|email|unique:vendors', |
||||
'phone' => 'required|regex:/^([0-9\s\-\+\(\)]*)$/|min:10|unique:vendors', |
||||
'min_delivery_time' => 'required|regex:/^([0-9]{2})$/|min:2|max:2', |
||||
'max_delivery_time' => 'required|regex:/^([0-9]{2})$/|min:2|max:2', |
||||
'password' => 'required|min:6', |
||||
'zone_id' => 'required', |
||||
// 'cuisine_ids' => 'required', |
||||
'logo' => 'required', |
||||
'vat' => 'required', |
||||
]); |
||||
|
||||
if($request->zone_id) |
||||
{ |
||||
$point = new Point($request->lat, $request->lng); |
||||
$zone = Zone::contains('coordinates', $point)->where('id', $request->zone_id)->first(); |
||||
if(!$zone){ |
||||
$validator->getMessageBag()->add('latitude', translate('messages.coordinates_out_of_zone')); |
||||
} |
||||
} |
||||
|
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)], 403); |
||||
} |
||||
|
||||
$vendor = new Vendor(); |
||||
$vendor->f_name = $request->fName; |
||||
$vendor->l_name = $request->lName; |
||||
$vendor->email = $request->email; |
||||
$vendor->phone = $request->phone; |
||||
$vendor->password = bcrypt($request->password); |
||||
$vendor->status = null; |
||||
$vendor->save(); |
||||
|
||||
$restaurant = new Restaurant; |
||||
$restaurant->name = $request->restaurant_name; |
||||
$restaurant->phone = $request->phone; |
||||
$restaurant->email = $request->email; |
||||
$restaurant->logo = Helpers::upload('restaurant/', 'png', $request->file('logo')); |
||||
$restaurant->cover_photo = Helpers::upload('restaurant/cover/', 'png', $request->file('cover_photo')); |
||||
$restaurant->address = $request->restaurant_address; |
||||
$restaurant->latitude = $request->lat; |
||||
$restaurant->longitude = $request->lng; |
||||
$restaurant->vendor_id = $vendor->id; |
||||
$restaurant->zone_id = $request->zone_id; |
||||
$restaurant->tax = $request->vat; |
||||
$restaurant->delivery_time = $request->min_delivery_time .'-'. $request->max_delivery_time; |
||||
$restaurant->status = 0; |
||||
$restaurant->restaurant_model = 'none'; |
||||
$restaurant->save(); |
||||
|
||||
$cuisine_ids = []; |
||||
$cuisine_ids = json_decode($request->cuisine_ids, true); |
||||
$restaurant->cuisine()->sync($cuisine_ids); |
||||
try{ |
||||
if(config('mail.status')){ |
||||
Mail::to($request['email'])->send(new \App\Mail\SelfRegistration('pending', $vendor->f_name.' '.$vendor->l_name)); |
||||
} |
||||
}catch(\Exception $ex){ |
||||
info($ex); |
||||
} |
||||
|
||||
return response()->json([ |
||||
'restaurant_id'=> $restaurant->id, |
||||
'message'=>translate('messages.application_placed_successfully')],200); |
||||
} |
||||
|
||||
public function package_view(){ |
||||
$packages= SubscriptionPackage::where('status',1)->get(); |
||||
return response()->json(['packages'=> $packages], 200); |
||||
} |
||||
|
||||
public function business_plan(Request $request){ |
||||
$restaurant=Restaurant::findOrFail($request->restaurant_id); |
||||
|
||||
if($request->business_plan == 'subscription' && $request->package_id != null ) { |
||||
$restaurant_id=$restaurant->id; |
||||
$package_id=$request->package_id; |
||||
$payment_method=$request->payment_method ?? 'free_trial'; |
||||
$reference=$request->reference ?? null; |
||||
$discount=$request->discount ?? 0; |
||||
$restaurant=Restaurant::findOrFail($restaurant_id); |
||||
$type=$request->type ?? 'new_join'; |
||||
if($request->payment == 'free_trial' ){ |
||||
Helpers::subscription_plan_chosen($restaurant_id ,$package_id, $payment_method ,$reference ,$discount,$type); |
||||
} |
||||
elseif($request->payment == 'paying_now'){ |
||||
// dd('paying_now'); |
||||
Helpers::subscription_plan_chosen($restaurant_id ,$package_id, $payment_method ,$reference ,$discount,$type); |
||||
} |
||||
$data=[ |
||||
'restaurant_model' => 'subscription', |
||||
'logo'=> $restaurant->logo, |
||||
'message' => translate('messages.application_placed_successfully') |
||||
]; |
||||
return response()->json($data,200); |
||||
} |
||||
|
||||
elseif($request->business_plan == 'commission' ){ |
||||
$restaurant->restaurant_model = 'commission'; |
||||
$restaurant->save(); |
||||
|
||||
$data=['restaurant_model' => 'commission', |
||||
'logo'=> $restaurant->logo, |
||||
'message' => translate('messages.application_placed_successfully') |
||||
]; |
||||
return response()->json($data,200); |
||||
} |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,178 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Api\V1\Auth; |
||||
|
||||
use App\Models\Vendor; |
||||
use Illuminate\Http\Request; |
||||
use App\CentralLogics\Helpers; |
||||
use Illuminate\Support\Carbon; |
||||
use App\Models\BusinessSetting; |
||||
use Illuminate\Support\Facades\DB; |
||||
use App\Http\Controllers\Controller; |
||||
use Illuminate\Support\Facades\Mail; |
||||
use Illuminate\Support\Facades\Validator; |
||||
|
||||
class VendorPasswordResetController extends Controller |
||||
{ |
||||
public function reset_password_request(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'email' => 'required', |
||||
]); |
||||
|
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)], 403); |
||||
} |
||||
|
||||
$vendor = Vendor::Where(['email' => $request['email']])->first(); |
||||
|
||||
if (isset($vendor)) { |
||||
$token = rand(1000,9999); |
||||
DB::table('password_resets')->updateOrInsert(['email' => $vendor['email']], |
||||
[ |
||||
'token' => $token, |
||||
'created_at' => now(), |
||||
]); |
||||
try{ |
||||
if (config('mail.status')) { |
||||
Mail::to($vendor['email'])->send(new \App\Mail\PasswordResetMail($token, $vendor->f_name)); |
||||
} |
||||
|
||||
}catch(\Exception $ex){ |
||||
info($ex); |
||||
} |
||||
|
||||
return response()->json(['message' => 'Email sent successfully.'], 200); |
||||
} |
||||
return response()->json(['errors' => [ |
||||
['code' => 'not-found', 'message' => 'Email not found!'] |
||||
]], 404); |
||||
} |
||||
|
||||
public function verify_token(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'email' => 'required|exists:vendors,email', |
||||
'reset_token'=> 'required' |
||||
]); |
||||
|
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)], 403); |
||||
} |
||||
|
||||
$data = DB::table('password_resets')->where(['token' => $request['reset_token'],'email'=>$request->email])->first(); |
||||
if (isset($data) || (env('APP_MODE') == 'demo' && $request['reset_token'] == '1234' )) { |
||||
return response()->json(['message'=> translate("OTP found, you can proceed")], 200); |
||||
} else{ |
||||
// $otp_hit = BusinessSetting::where('key', 'max_otp_hit')->first(); |
||||
// $max_otp_hit =isset($otp_hit) ? $otp_hit->value : 5 ; |
||||
$max_otp_hit = 5; |
||||
// $otp_hit_time = BusinessSetting::where('key', 'max_otp_hit_time')->first(); |
||||
// $max_otp_hit_time = isset($otp_hit_time) ? $otp_hit_time->value : 30 ; |
||||
$max_otp_hit_time = 60; // seconds |
||||
$temp_block_time = 600; // seconds |
||||
$verification_data= DB::table('password_resets')->where('email', $request->email)->first(); |
||||
|
||||
|
||||
if(isset($verification_data)){ |
||||
$time= $temp_block_time - Carbon::parse($verification_data->temp_block_time)->DiffInSeconds(); |
||||
|
||||
if(isset($verification_data->temp_block_time ) && Carbon::parse($verification_data->temp_block_time)->DiffInSeconds() <= $temp_block_time){ |
||||
$time= $temp_block_time - Carbon::parse($verification_data->temp_block_time)->DiffInSeconds(); |
||||
|
||||
$errors = []; |
||||
array_push($errors, ['code' => 'otp_block_time', 'message' => translate('messages.please_try_again_after_').CarbonInterval::seconds($time)->cascade()->forHumans() |
||||
]); |
||||
return response()->json([ |
||||
'errors' => $errors |
||||
], 405); |
||||
} |
||||
|
||||
if($verification_data->is_temp_blocked == 1 && Carbon::parse($verification_data->created_at)->DiffInSeconds() >= $max_otp_hit_time){ |
||||
DB::table('password_resets')->updateOrInsert(['email' => $request->email], |
||||
[ |
||||
'otp_hit_count' => 0, |
||||
'is_temp_blocked' => 0, |
||||
'temp_block_time' => null, |
||||
'created_at' => now(), |
||||
]); |
||||
} |
||||
|
||||
if($verification_data->otp_hit_count >= $max_otp_hit && Carbon::parse($verification_data->created_at)->DiffInSeconds() < $max_otp_hit_time && $verification_data->is_temp_blocked == 0){ |
||||
|
||||
DB::table('password_resets')->updateOrInsert(['email' => $request->email], |
||||
[ |
||||
'is_temp_blocked' => 1, |
||||
'temp_block_time' => now(), |
||||
'created_at' => now(), |
||||
]); |
||||
$errors = []; |
||||
array_push($errors, ['code' => 'otp_temp_blocked', 'message' => translate('messages.Too_many_attemps') ]); |
||||
return response()->json([ |
||||
'errors' => $errors |
||||
], 405); |
||||
} |
||||
} |
||||
DB::table('password_resets')->updateOrInsert(['email' => $request->email], |
||||
[ |
||||
'otp_hit_count' => DB::raw('otp_hit_count + 1'), |
||||
'created_at' => now(), |
||||
'temp_block_time' => null, |
||||
]); |
||||
} |
||||
|
||||
return response()->json(['errors' => [ |
||||
['code' => 'reset_token', 'message' => 'Invalid OTP.'] |
||||
]], 400); |
||||
} |
||||
|
||||
public function reset_password_submit(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'email' => 'required|exists:vendors,email', |
||||
'reset_token'=> 'required', |
||||
'password'=> 'required|min:6', |
||||
'confirm_password'=> 'required|same:password', |
||||
]); |
||||
|
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)], 403); |
||||
} |
||||
|
||||
if(env('APP_MODE') == 'demo') { |
||||
if ($request['reset_token'] != '1234') { |
||||
return response()->json(['errors' => [ |
||||
['code' => 'invalid', 'message' => translate('messages.invalid_otp')] |
||||
]], 400); |
||||
} |
||||
if ($request['password'] == $request['confirm_password']) { |
||||
DB::table('vendors')->where(['email' => $request->email])->update([ |
||||
'password' => bcrypt($request['confirm_password']) |
||||
]); |
||||
DB::table('password_resets')->where(['token' => $request['reset_token']])->delete(); |
||||
return response()->json(['message' => translate('Password changed successfully.')], 200); |
||||
} |
||||
return response()->json(['errors' => [ |
||||
['code' => 'mismatch', 'message' => translate('messages.password_mismatch')] |
||||
]], 401); |
||||
} |
||||
|
||||
|
||||
$data = DB::table('password_resets')->where(['email'=>$request['email'],'token' => $request['reset_token']])->first(); |
||||
if (isset($data)) { |
||||
if ($request['password'] == $request['confirm_password']) { |
||||
DB::table('vendors')->where(['email' => $data->email])->update([ |
||||
'password' => bcrypt($request['confirm_password']) |
||||
]); |
||||
DB::table('password_resets')->where(['token' => $request['reset_token']])->delete(); |
||||
return response()->json(['message' => translate('Password changed successfully.')], 200); |
||||
} |
||||
return response()->json(['errors' => [ |
||||
['code' => 'mismatch', 'message' => translate('messages.password_mismatch')] |
||||
]], 401); |
||||
} |
||||
return response()->json(['errors' => [ |
||||
['code' => 'invalid', 'message' => translate('messages.invalid_otp')] |
||||
]], 400); |
||||
} |
||||
} |
@ -0,0 +1,37 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Api\V1; |
||||
|
||||
use App\Models\Campaign; |
||||
use App\CentralLogics\BannerLogic; |
||||
use App\CentralLogics\Helpers; |
||||
use App\Http\Controllers\Controller; |
||||
use Illuminate\Http\Request; |
||||
|
||||
class BannerController extends Controller |
||||
{ |
||||
public function get_banners(Request $request) |
||||
{ |
||||
if (!$request->hasHeader('zoneId')) { |
||||
$errors = []; |
||||
array_push($errors, ['code' => 'zoneId', 'message' => translate('messages.zone_id_required')]); |
||||
return response()->json([ |
||||
'errors' => $errors |
||||
], 403); |
||||
} |
||||
$longitude= $request->header('longitude'); |
||||
$latitude= $request->header('latitude'); |
||||
$zone_id= json_decode($request->header('zoneId'), true); |
||||
$banners = BannerLogic::get_banners($zone_id); |
||||
$campaigns = Campaign::whereHas('restaurants', function($query)use($zone_id){ |
||||
$query->whereIn('zone_id', $zone_id); |
||||
})->with('restaurants',function($query)use($zone_id,$longitude,$latitude){ |
||||
return $query->WithOpen($longitude,$latitude)->whereIn('zone_id', $zone_id); |
||||
})->running()->active()->get(); |
||||
try { |
||||
return response()->json(['campaigns'=>Helpers::basic_campaign_data_formatting($campaigns, true),'banners'=>$banners], 200); |
||||
} catch (\Exception $e) { |
||||
return response()->json([], 200); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,95 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Api\V1; |
||||
|
||||
use App\Http\Controllers\Controller; |
||||
use App\Models\Campaign; |
||||
use App\Models\ItemCampaign; |
||||
use Illuminate\Http\Request; |
||||
use App\CentralLogics\Helpers; |
||||
use Illuminate\Support\Facades\Validator; |
||||
|
||||
class CampaignController extends Controller |
||||
{ |
||||
public function get_basic_campaigns(Request $request){ |
||||
if (!$request->hasHeader('zoneId')) { |
||||
$errors = []; |
||||
array_push($errors, ['code' => 'zoneId', 'message' => translate('messages.zone_id_required')]); |
||||
return response()->json([ |
||||
'errors' => $errors |
||||
], 200); |
||||
} |
||||
$longitude= $request->header('longitude'); |
||||
$latitude= $request->header('latitude'); |
||||
$zone_id= json_decode($request->header('zoneId'), true); |
||||
try { |
||||
$campaigns = Campaign::whereHas('restaurants', function($query)use($zone_id){ |
||||
$query->whereIn('zone_id', $zone_id); |
||||
}) |
||||
->with('restaurants',function($query)use($zone_id,$longitude,$latitude){ |
||||
return $query->WithOpen($longitude,$latitude)->whereIn('zone_id', $zone_id)->wherePivot('campaign_status', 'confirmed')->active(); |
||||
}) |
||||
->running()->active()->get(); |
||||
$campaigns=Helpers::basic_campaign_data_formatting($campaigns, true); |
||||
return response()->json($campaigns, 200); |
||||
} catch (\Exception $e) { |
||||
return response()->json([$e], 200); |
||||
} |
||||
} |
||||
public function basic_campaign_details(Request $request){ |
||||
if (!$request->hasHeader('zoneId')) { |
||||
$errors = []; |
||||
array_push($errors, ['code' => 'zoneId', 'message' => translate('messages.zone_id_required')]); |
||||
return response()->json([ |
||||
'errors' => $errors |
||||
], 200); |
||||
} |
||||
$zone_id= json_decode($request->header('zoneId'), true); |
||||
|
||||
$validator = Validator::make($request->all(), [ |
||||
'basic_campaign_id' => 'required', |
||||
]); |
||||
|
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)], 403); |
||||
} |
||||
try { |
||||
$longitude= $request->header('longitude'); |
||||
$latitude= $request->header('latitude'); |
||||
$campaign = Campaign::with(['restaurants'=>function($q)use($zone_id){ |
||||
$q->whereIn('zone_id', $zone_id); |
||||
}]) |
||||
->with('restaurants',function($query)use($zone_id,$longitude,$latitude){ |
||||
return $query->WithOpen($longitude,$latitude)->whereIn('zone_id', $zone_id)->wherePivot('campaign_status', 'confirmed')->active(); |
||||
}) |
||||
->running()->active()->whereId($request->basic_campaign_id)->first(); |
||||
|
||||
$campaign=Helpers::basic_campaign_data_formatting($campaign, false); |
||||
|
||||
$campaign['restaurants'] = Helpers::restaurant_data_formatting($campaign['restaurants'], true); |
||||
|
||||
return response()->json($campaign, 200); |
||||
} catch (\Exception $e) { |
||||
return response()->json([], 200); |
||||
} |
||||
} |
||||
public function get_item_campaigns(Request $request){ |
||||
if (!$request->hasHeader('zoneId')) { |
||||
$errors = []; |
||||
array_push($errors, ['code' => 'zoneId', 'message' => translate('messages.zone_id_required')]); |
||||
return response()->json([ |
||||
'errors' => $errors |
||||
], 200); |
||||
} |
||||
$zone_id= json_decode($request->header('zoneId'), true); |
||||
try { |
||||
$campaigns = ItemCampaign::active()->whereHas('restaurant', function($query)use($zone_id){ |
||||
$query->whereIn('zone_id', $zone_id); |
||||
})->running()->active()->get(); |
||||
$campaigns= Helpers::product_data_formatting($campaigns, true, false, app()->getLocale()); |
||||
return response()->json($campaigns, 200); |
||||
} catch (\Exception $e) { |
||||
return response()->json([], 200); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,132 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Api\V1; |
||||
|
||||
use App\CentralLogics\CategoryLogic; |
||||
use App\CentralLogics\Helpers; |
||||
use App\Http\Controllers\Controller; |
||||
use App\Models\Category; |
||||
use Illuminate\Http\Request; |
||||
use Illuminate\Support\Facades\Validator; |
||||
|
||||
class CategoryController extends Controller |
||||
{ |
||||
public function get_categories(Request $request) |
||||
{ |
||||
try { |
||||
$name= $request->query('name'); |
||||
$categories = Category::withCount('products')->with(['childes' => function($query) { |
||||
$query->withCount('products'); |
||||
}]) |
||||
->where(['position'=>0,'status'=>1]) |
||||
|
||||
->when($name, function($q)use($name){ |
||||
$key = explode(' ', $name); |
||||
$q->where(function($q)use($key){ |
||||
foreach ($key as $value){ |
||||
$q->orWhere('name', 'like', '%'.$value.'%')->orWhere('slug', 'like', '%'.$value.'%'); |
||||
} |
||||
return $q; |
||||
}); |
||||
}) |
||||
->orderBy('priority','desc')->get(); |
||||
return response()->json(Helpers::category_data_formatting($categories, true), 200); |
||||
} catch (\Exception $e) { |
||||
return response()->json([$e->getMessage()], 200); |
||||
} |
||||
} |
||||
|
||||
public function get_childes($id) |
||||
{ |
||||
try { |
||||
$categories = Category::when(is_numeric($id),function ($qurey) use($id){ |
||||
$qurey->where(['parent_id' => $id,'status'=>1]); |
||||
}) |
||||
->when(!is_numeric($id),function ($qurey) use($id){ |
||||
$qurey->where(['slug' => $id,'status'=>1]); |
||||
}) |
||||
->orderBy('priority','desc')->get(); |
||||
return response()->json(Helpers::category_data_formatting($categories, true), 200); |
||||
} catch (\Exception $e) { |
||||
return response()->json([], 200); |
||||
} |
||||
} |
||||
|
||||
public function get_products($id, Request $request) |
||||
{ |
||||
if (!$request->hasHeader('zoneId')) { |
||||
$errors = []; |
||||
array_push($errors, ['code' => 'zoneId', 'message' => translate('messages.zone_id_required')]); |
||||
return response()->json([ |
||||
'errors' => $errors |
||||
], 403); |
||||
} |
||||
$validator = Validator::make($request->all(), [ |
||||
'limit' => 'required', |
||||
'offset' => 'required', |
||||
]); |
||||
|
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)], 403); |
||||
} |
||||
|
||||
$zone_id= json_decode($request->header('zoneId'), true); |
||||
|
||||
$type = $request->query('type', 'all'); |
||||
|
||||
$data = CategoryLogic::products($id, $zone_id, $request['limit'], $request['offset'], $type); |
||||
$data['products'] = Helpers::product_data_formatting($data['products'] , true, false, app()->getLocale()); |
||||
|
||||
if(auth('api')->user() !== null){ |
||||
$customer_id =auth('api')->user()->id; |
||||
Helpers::visitor_log('category',$customer_id,$id,false); |
||||
} |
||||
|
||||
return response()->json($data, 200); |
||||
} |
||||
|
||||
|
||||
public function get_restaurants($id, Request $request) |
||||
{ |
||||
if (!$request->hasHeader('zoneId')) { |
||||
$errors = []; |
||||
array_push($errors, ['code' => 'zoneId', 'message' => translate('messages.zone_id_required')]); |
||||
return response()->json([ |
||||
'errors' => $errors |
||||
], 403); |
||||
} |
||||
$validator = Validator::make($request->all(), [ |
||||
'limit' => 'required', |
||||
'offset' => 'required', |
||||
]); |
||||
|
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)], 403); |
||||
} |
||||
|
||||
$zone_id= json_decode($request->header('zoneId'), true); |
||||
|
||||
$type = $request->query('type', 'all'); |
||||
|
||||
$data = CategoryLogic::restaurants($id, $zone_id, $request['limit'], $request['offset'], $type); |
||||
$data['restaurants'] = Helpers::restaurant_data_formatting($data['restaurants'] , true); |
||||
|
||||
// if(auth('api')->user() !== null){ |
||||
// $customer_id =auth('api')->user()->id; |
||||
// Helpers::visitor_log('category',$customer_id,$id,false); |
||||
// } |
||||
|
||||
return response()->json($data, 200); |
||||
} |
||||
|
||||
|
||||
|
||||
public function get_all_products($id,Request $request) |
||||
{ |
||||
try { |
||||
return response()->json(Helpers::product_data_formatting(CategoryLogic::all_products($id), true, false, app()->getLocale()), 200); |
||||
} catch (\Exception $e) { |
||||
return response()->json([], 200); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,321 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Api\V1; |
||||
|
||||
use App\Models\Zone; |
||||
use App\Models\Vehicle; |
||||
use App\Models\Currency; |
||||
use App\Models\SocialMedia; |
||||
use Illuminate\Http\Request; |
||||
use App\CentralLogics\Helpers; |
||||
use App\Models\BusinessSetting; |
||||
use App\Http\Controllers\Controller; |
||||
use App\Models\Restaurant; |
||||
use Illuminate\Support\Facades\Http; |
||||
use Illuminate\Support\Facades\Validator; |
||||
use Grimzy\LaravelMysqlSpatial\Types\Point; |
||||
|
||||
class ConfigController extends Controller |
||||
{ |
||||
private $map_api_key; |
||||
|
||||
function __construct() |
||||
{ |
||||
$map_api_key_server = BusinessSetting::where(['key' => 'map_api_key_server'])->first(); |
||||
$map_api_key_server = $map_api_key_server ? $map_api_key_server->value : null; |
||||
$this->map_api_key = $map_api_key_server; |
||||
} |
||||
|
||||
public function configuration() |
||||
{ |
||||
$key = [ |
||||
'cash_on_delivery', 'digital_payment', 'default_location', 'free_delivery_over', 'business_name', 'logo', 'address', 'phone', 'email_address', 'country', 'currency_symbol_position', 'app_minimum_version_android', |
||||
'app_url_android', 'app_minimum_version_ios', 'app_url_ios', 'customer_verification', 'order_delivery_verification', 'terms_and_conditions', 'privacy_policy', 'about_us', 'maintenance_mode', 'popular_food', 'popular_restaurant', 'new_restaurant', 'most_reviewed_foods', 'show_dm_earning', 'canceled_by_deliveryman', 'canceled_by_restaurant', 'timeformat', 'toggle_veg_non_veg', 'toggle_dm_registration', 'toggle_restaurant_registration', 'schedule_order_slot_duration', |
||||
'loyalty_point_exchange_rate', 'loyalty_point_item_purchase_point', 'loyalty_point_status', 'loyalty_point_minimum_point', 'wallet_status', 'schedule_order', 'dm_tips_status', 'ref_earning_status', 'ref_earning_exchange_rate', 'theme','business_model','admin_commission','footer_text' ,'icon','refund_active_status', |
||||
'refund_policy','shipping_policy','cancellation_policy','free_trial_period','app_minimum_version_android_restaurant', |
||||
'app_url_android_restaurant','app_minimum_version_ios_restaurant','app_url_ios_restaurant','app_minimum_version_android_deliveryman','tax_included','order_subscription', |
||||
'app_url_android_deliveryman', |
||||
]; |
||||
$social_login = []; |
||||
$social_login_data=Helpers::get_business_settings('social_login') ?? []; |
||||
foreach ($social_login_data as $social) { |
||||
$config = [ |
||||
'login_medium' => $social['login_medium'], |
||||
'status' => (boolean)$social['status'] |
||||
]; |
||||
array_push($social_login, $config); |
||||
} |
||||
|
||||
$settings = array_column(BusinessSetting::whereIn('key', $key)->get()->toArray(), 'value', 'key'); |
||||
$currency_symbol = Currency::where(['currency_code' => Helpers::currency_code()])->first()->currency_symbol; |
||||
$cod = json_decode($settings['cash_on_delivery'], true); |
||||
$business_plan = isset($settings['business_model']) ? json_decode($settings['business_model'], true) : [ |
||||
'commission' => 1, |
||||
'subscription' => 0, |
||||
]; |
||||
|
||||
$digital_payment = json_decode($settings['digital_payment'], true); |
||||
|
||||
$default_location = isset($settings['default_location']) ? json_decode($settings['default_location'], true) : 0; |
||||
$free_delivery_over = $settings['free_delivery_over']; |
||||
$free_delivery_over = $free_delivery_over ? (float)$free_delivery_over : $free_delivery_over; |
||||
$languages = Helpers::get_business_settings('language'); |
||||
$lang_array = []; |
||||
foreach ($languages as $language) { |
||||
array_push($lang_array, [ |
||||
'key' => $language, |
||||
'value' => Helpers::get_language_name($language) |
||||
]); |
||||
} |
||||
|
||||
|
||||
$apple_login = []; |
||||
$apples = Helpers::get_business_settings('apple_login'); |
||||
if(isset($apples)){ |
||||
foreach (Helpers::get_business_settings('apple_login') as $apple) { |
||||
$config = [ |
||||
'login_medium' => $apple['login_medium'], |
||||
'status' => (boolean)$apple['status'], |
||||
'client_id' => $apple['client_id'] |
||||
]; |
||||
array_push($apple_login, $config); |
||||
} |
||||
} |
||||
|
||||
return response()->json([ |
||||
'business_name' => $settings['business_name'], |
||||
'logo' => $settings['logo'], |
||||
'address' => $settings['address'], |
||||
'phone' => $settings['phone'], |
||||
'email' => $settings['email_address'], |
||||
'base_urls' => [ |
||||
'product_image_url' => asset('storage/app/public/product'), |
||||
'customer_image_url' => asset('storage/app/public/profile'), |
||||
'banner_image_url' => asset('storage/app/public/banner'), |
||||
'category_image_url' => asset('storage/app/public/category'), |
||||
'cuisine_image_url' => asset('storage/app/public/cuisine'), |
||||
'review_image_url' => asset('storage/app/public/review'), |
||||
'notification_image_url' => asset('storage/app/public/notification'), |
||||
'restaurant_image_url' => asset('storage/app/public/restaurant'), |
||||
'vendor_image_url' => asset('storage/app/public/vendor'), |
||||
'restaurant_cover_photo_url' => asset('storage/app/public/restaurant/cover'), |
||||
'delivery_man_image_url' => asset('storage/app/public/delivery-man'), |
||||
'chat_image_url' => asset('storage/app/public/conversation'), |
||||
'campaign_image_url' => asset('storage/app/public/campaign'), |
||||
'business_logo_url' => asset('storage/app/public/business'), |
||||
'react_landing_page_images' => asset('storage/app/public/react_landing') , |
||||
'react_landing_page_feature_images' => asset('storage/app/public/react_landing/feature') , |
||||
'refund_image_url' => asset('storage/app/public/refund'), |
||||
], |
||||
'country' => $settings['country'], |
||||
'default_location' => ['lat' => $default_location ? $default_location['lat'] : '23.757989', 'lng' => $default_location ? $default_location['lng'] : '90.360587'], |
||||
'currency_symbol' => $currency_symbol, |
||||
'currency_symbol_direction' => $settings['currency_symbol_position'], |
||||
'app_minimum_version_android' => (float)$settings['app_minimum_version_android'], |
||||
'app_url_android' => $settings['app_url_android'], |
||||
'app_minimum_version_ios' => (float)$settings['app_minimum_version_ios'], |
||||
'app_url_ios' => $settings['app_url_ios'], |
||||
'customer_verification' => (bool)$settings['customer_verification'], |
||||
'schedule_order' => (bool)$settings['schedule_order'], |
||||
'order_delivery_verification' => (bool)$settings['order_delivery_verification'], |
||||
'cash_on_delivery' => (bool)($cod['status'] == 1 ? true : false), |
||||
'digital_payment' => (bool)($digital_payment['status'] == 1 ? true : false), |
||||
'terms_and_conditions' => $settings['terms_and_conditions'], |
||||
'privacy_policy' => $settings['privacy_policy'], |
||||
'about_us' => $settings['about_us'], |
||||
'free_delivery_over' => $free_delivery_over, |
||||
'demo' => (bool)(env('APP_MODE') == 'demo' ? true : false), |
||||
'maintenance_mode' => (bool)Helpers::get_business_settings('maintenance_mode') ?? 0, |
||||
'order_confirmation_model' => config('order_confirmation_model'), |
||||
'popular_food' => (float)$settings['popular_food'], |
||||
'popular_restaurant' => (float)$settings['popular_restaurant'], |
||||
'new_restaurant' => (float)$settings['new_restaurant'], |
||||
'most_reviewed_foods' => (float)$settings['most_reviewed_foods'], |
||||
'show_dm_earning' => (bool)$settings['show_dm_earning'], |
||||
'canceled_by_deliveryman' => (bool)$settings['canceled_by_deliveryman'], |
||||
'canceled_by_restaurant' => (bool)$settings['canceled_by_restaurant'], |
||||
'timeformat' => (string)$settings['timeformat'], |
||||
'language' => $lang_array, |
||||
'toggle_veg_non_veg' => (bool)$settings['toggle_veg_non_veg'], |
||||
'toggle_dm_registration' => (bool)$settings['toggle_dm_registration'], |
||||
'toggle_restaurant_registration' => (bool)$settings['toggle_restaurant_registration'], |
||||
'schedule_order_slot_duration' => (int)$settings['schedule_order_slot_duration'], |
||||
'digit_after_decimal_point' => (int)config('round_up_to_digit'), |
||||
'loyalty_point_exchange_rate' => (int)(isset($settings['loyalty_point_item_purchase_point']) ? $settings['loyalty_point_exchange_rate'] : 0), |
||||
'loyalty_point_item_purchase_point' => (float)(isset($settings['loyalty_point_item_purchase_point']) ? $settings['loyalty_point_item_purchase_point'] : 0.0), |
||||
'loyalty_point_status' => (int)(isset($settings['loyalty_point_status']) ? $settings['loyalty_point_status'] : 0), |
||||
'minimum_point_to_transfer' => (int)(isset($settings['loyalty_point_minimum_point']) ? $settings['loyalty_point_minimum_point'] : 0), |
||||
'customer_wallet_status' => (int)(isset($settings['wallet_status']) ? $settings['wallet_status'] : 0), |
||||
'ref_earning_status' => (int)(isset($settings['ref_earning_status']) ? $settings['ref_earning_status'] : 0), |
||||
'ref_earning_exchange_rate' => (double)(isset($settings['ref_earning_exchange_rate']) ? $settings['ref_earning_exchange_rate'] : 0), |
||||
'dm_tips_status' => (int)(isset($settings['dm_tips_status']) ? $settings['dm_tips_status'] : 0), |
||||
'theme' => (int)$settings['theme'], |
||||
'social_media'=>SocialMedia::active()->get()->toArray(), |
||||
'social_login' => $social_login, |
||||
'business_plan' => $business_plan, |
||||
'admin_commission' => (float)(isset($settings['admin_commission']) ? $settings['admin_commission'] : 0), |
||||
'footer_text' => $settings['footer_text'], |
||||
'fav_icon' => $settings['icon'], |
||||
'refund_active_status' => (bool)(isset($settings['refund_active_status']) ? $settings['refund_active_status'] : 0), |
||||
'refund_policy_status' => (int)(isset($settings['refund_policy']) ? json_decode($settings['refund_policy'], true)['status'] : 0), |
||||
'refund_policy_data' =>(isset($settings['refund_policy']) ? json_decode($settings['refund_policy'], true)['data'] : null), |
||||
'cancellation_policy_status' => (int)(isset($settings['cancellation_policy']) ? json_decode($settings['cancellation_policy'], true)['status'] : 0), |
||||
'cancellation_policy_data' => (isset($settings['cancellation_policy']) ? json_decode($settings['cancellation_policy'], true)['data'] : null), |
||||
'shipping_policy_status' => (int)(isset($settings['shipping_policy']) ? json_decode($settings['shipping_policy'], true)['status'] : 0), |
||||
'shipping_policy_data' => (isset($settings['shipping_policy']) ? json_decode($settings['shipping_policy'], true)['data'] : null), |
||||
'free_trial_period_status' => (int)(isset($settings['free_trial_period']) ? json_decode($settings['free_trial_period'], true)['status'] : 0), |
||||
'free_trial_period_data' => (int)(isset($settings['free_trial_period']) ? json_decode($settings['free_trial_period'], true)['data'] : 0), |
||||
|
||||
'app_minimum_version_android_restaurant' => (float)(isset($settings['app_minimum_version_android_restaurant']) ? $settings['app_minimum_version_android_restaurant'] : 0), |
||||
'app_url_android_restaurant' => (isset($settings['app_url_android_restaurant']) ? $settings['app_url_android_restaurant'] : null), |
||||
'app_minimum_version_ios_restaurant' => (float)(isset($settings['app_minimum_version_ios_restaurant']) ? $settings['app_minimum_version_ios_restaurant'] : 0), |
||||
'app_url_ios_restaurant' => (isset($settings['app_url_ios_restaurant']) ? $settings['app_url_ios_restaurant'] : null), |
||||
'app_minimum_version_android_deliveryman' => (float)(isset($settings['app_minimum_version_android_deliveryman']) ? $settings['app_minimum_version_android_deliveryman'] : 0), |
||||
'app_url_android_deliveryman' => (isset($settings['app_url_android_deliveryman']) ? $settings['app_url_android_deliveryman'] : null), |
||||
'tax_included' => (int)(isset($settings['tax_included']) ? $settings['tax_included'] : 0), |
||||
'apple_login' => $apple_login, |
||||
'order_subscription' => (int)(isset($settings['order_subscription']) ? $settings['order_subscription'] : 0), |
||||
]); |
||||
} |
||||
|
||||
public function get_zone(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'lat' => 'required', |
||||
'lng' => 'required', |
||||
]); |
||||
|
||||
if ($validator->errors()->count() > 0) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)], 403); |
||||
} |
||||
$point = new Point($request->lat, $request->lng); |
||||
$zones = Zone::contains('coordinates', $point)->latest()->get(['id', 'status', 'minimum_shipping_charge', |
||||
'increased_delivery_fee','increased_delivery_fee_status','increase_delivery_charge_message','per_km_shipping_charge','max_cod_order_amount','maximum_shipping_charge']); |
||||
if (count($zones) < 1) { |
||||
return response()->json([ |
||||
'errors' => [ |
||||
['code' => 'coordinates', 'message' => translate('messages.service_not_available_in_this_area')] |
||||
] |
||||
], 404); |
||||
} |
||||
$data = array_filter($zones->toArray(), function ($zone) { |
||||
if ($zone['status'] == 1) { |
||||
return $zone; |
||||
} |
||||
}); |
||||
|
||||
if (count($data) > 0) { |
||||
return response()->json(['zone_id' => json_encode(array_column($data, 'id')), 'zone_data'=>array_values($data)], 200); |
||||
} |
||||
|
||||
return response()->json([ |
||||
'errors' => [ |
||||
['code' => 'coordinates', 'message' => translate('messages.we_are_temporarily_unavailable_in_this_area')] |
||||
] |
||||
], 403); |
||||
} |
||||
|
||||
public function place_api_autocomplete(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'search_text' => 'required', |
||||
]); |
||||
|
||||
if ($validator->errors()->count() > 0) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)], 403); |
||||
} |
||||
$response = Http::get('https://maps.googleapis.com/maps/api/place/autocomplete/json?input=' . $request['search_text'] . '&key=' . $this->map_api_key); |
||||
return $response->json(); |
||||
} |
||||
|
||||
|
||||
public function distance_api(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'origin_lat' => 'required', |
||||
'origin_lng' => 'required', |
||||
'destination_lat' => 'required', |
||||
'destination_lng' => 'required', |
||||
]); |
||||
|
||||
if ($validator->errors()->count() > 0) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)], 403); |
||||
} |
||||
$response = Http::get('https://maps.googleapis.com/maps/api/distancematrix/json?origins=' . $request['origin_lat'] . ',' . $request['origin_lng'] . '&destinations=' . $request['destination_lat'] . ',' . $request['destination_lng'] . '&key=' . $this->map_api_key . '&mode=walking'); |
||||
return $response->json(); |
||||
} |
||||
|
||||
|
||||
public function place_api_details(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'placeid' => 'required', |
||||
]); |
||||
|
||||
if ($validator->errors()->count() > 0) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)], 403); |
||||
} |
||||
$response = Http::get('https://maps.googleapis.com/maps/api/place/details/json?placeid=' . $request['placeid'] . '&key=' . $this->map_api_key); |
||||
return $response->json(); |
||||
} |
||||
|
||||
public function geocode_api(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'lat' => 'required', |
||||
'lng' => 'required', |
||||
]); |
||||
|
||||
if ($validator->errors()->count() > 0) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)], 403); |
||||
} |
||||
$response = Http::get('https://maps.googleapis.com/maps/api/geocode/json?latlng=' . $request->lat . ',' . $request->lng . '&key=' . $this->map_api_key); |
||||
return $response->json(); |
||||
} |
||||
|
||||
public function landing_page(){ |
||||
$key =['react_header_banner','banner_section_full','banner_section_half' ,'footer_logo','app_section_image', |
||||
'react_feature' ,'discount_banner','landing_page_links']; |
||||
$settings = array_column(BusinessSetting::whereIn('key', $key)->get()->toArray(), 'value', 'key'); |
||||
return response()->json( |
||||
[ |
||||
'react_header_banner'=>(isset($settings['react_header_banner']) ) ? $settings['react_header_banner'] : null , |
||||
'app_section_image'=> (isset($settings['app_section_image'])) ? $settings['app_section_image'] : null, |
||||
'footer_logo'=> (isset($settings['footer_logo'])) ? $settings['footer_logo'] : null, |
||||
'banner_section_full'=> (isset($settings['banner_section_full']) ) ? json_decode($settings['banner_section_full'], true) : null , |
||||
'banner_section_half'=>(isset($settings['banner_section_half']) ) ? json_decode($settings['banner_section_half'], true) : [], |
||||
'react_feature'=> (isset($settings['react_feature'])) ? json_decode($settings['react_feature'], true) : [], |
||||
'discount_banner'=> (isset($settings['discount_banner'])) ? json_decode($settings['discount_banner'], true) : null, |
||||
'landing_page_links'=> (isset($settings['landing_page_links'])) ? json_decode($settings['landing_page_links'], true) : null, |
||||
]); |
||||
} |
||||
|
||||
|
||||
public function extra_charge(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'distance' => 'required', |
||||
]); |
||||
if ($validator->errors()->count() > 0) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)], 403); |
||||
} |
||||
$distance_data = $request->distance ?? 0; |
||||
$data = Vehicle::active()-> |
||||
where(function ($query) use ($distance_data) { |
||||
$query->where('starting_coverage_area', '<=', $distance_data)->where('maximum_coverage_area', '>=', $distance_data) |
||||
->orWhere(function ($query) use ($distance_data) { |
||||
$query->where('starting_coverage_area', '>=', $distance_data); |
||||
}); |
||||
}) |
||||
->orderBy('starting_coverage_area')->first(); |
||||
$extra_charges = (float) (isset($data) ? $data->extra_charges : 0); |
||||
return response()->json($extra_charges,200); |
||||
} |
||||
|
||||
public function get_vehicles(Request $request){ |
||||
$data = Vehicle::active()->get(['id','type']); |
||||
return response()->json($data, 200); |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,794 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Api\V1; |
||||
|
||||
use App\CentralLogics\Helpers; |
||||
use App\Http\Controllers\Controller; |
||||
use App\Models\Conversation; |
||||
use App\Models\DeliveryMan; |
||||
use App\Models\UserInfo; |
||||
use App\Models\Message; |
||||
use App\Models\Order; |
||||
use App\Models\Vendor; |
||||
use App\Models\User; |
||||
use Carbon\Carbon; |
||||
use Illuminate\Http\Request; |
||||
use Illuminate\Support\Facades\Storage; |
||||
use Illuminate\Support\Facades\Validator; |
||||
|
||||
class ConversationController extends Controller |
||||
{ |
||||
public function messages_store(Request $request) |
||||
{ |
||||
// info(['New message request',$request->all()]); |
||||
|
||||
if ($request->has('image')) { |
||||
|
||||
|
||||
$validator = Validator::make($request->all(), [ |
||||
'image.*' => 'max:2048', |
||||
]); |
||||
|
||||
if ($validator->fails()) { |
||||
$validator->getMessageBag()->add('image', 'Max Image Upload limit is 2mb'); |
||||
return response()->json(['errors' => Helpers::error_processor($validator)],403); |
||||
} |
||||
|
||||
$image_name=[]; |
||||
foreach($request->file('image') as $key=>$img) |
||||
{ |
||||
|
||||
$name = Helpers::upload('conversation/', 'png', $img); |
||||
array_push($image_name,$name); |
||||
} |
||||
} else { |
||||
$image_name = null; |
||||
} |
||||
|
||||
$limit = $request['limit']??10; |
||||
$offset = $request['offset']??1; |
||||
$fcm_token_web = null; |
||||
|
||||
$sender = UserInfo::where('user_id', $request->user()->id)->first(); |
||||
if(!$sender){ |
||||
$sender = new UserInfo(); |
||||
$sender->user_id = $request->user()->id; |
||||
$sender->f_name = $request->user()->f_name; |
||||
$sender->l_name = $request->user()->l_name; |
||||
$sender->phone = $request->user()->phone; |
||||
$sender->email = $request->user()->email; |
||||
$sender->image = $request->user()->image; |
||||
$sender->save(); |
||||
} |
||||
|
||||
if($request->conversation_id){ |
||||
$conversation = Conversation::find($request->conversation_id); |
||||
|
||||
if($conversation->sender_id == $sender->id){ |
||||
$receiver_id = $conversation->receiver_id; |
||||
$receiver = UserInfo::find($receiver_id); |
||||
if($receiver->vendor_id){ |
||||
$vendor = Vendor::find($receiver->vendor_id); |
||||
$fcm_token=$vendor->firebase_token; |
||||
$fcm_token_web=$vendor->fcm_token_web; |
||||
}elseif($receiver->deliveryman_id){ |
||||
$delivery_man = DeliveryMan::find($receiver->deliveryman_id); |
||||
$fcm_token=$delivery_man->fcm_token; |
||||
}elseif($receiver->admin_id){ |
||||
$receiver_id = 0; |
||||
} |
||||
}else{ |
||||
$receiver_id =$conversation->sender_id; |
||||
$receiver = UserInfo::find($receiver_id); |
||||
if($receiver->vendor_id){ |
||||
$vendor = Vendor::find($receiver->vendor_id); |
||||
$fcm_token=$vendor->firebase_token; |
||||
$fcm_token_web=$vendor->fcm_token_web; |
||||
}elseif($receiver->deliveryman_id){ |
||||
$delivery_man = DeliveryMan::find($receiver->deliveryman_id); |
||||
$fcm_token=$delivery_man->fcm_token; |
||||
}elseif($receiver->admin_id){ |
||||
$receiver_id = 0; |
||||
} |
||||
} |
||||
}else{ |
||||
if($request->receiver_type == 'admin'){ |
||||
$receiver_id = 0; |
||||
}else if($request->receiver_type == 'vendor'){ |
||||
$receiver = UserInfo::where('vendor_id',$request->receiver_id)->first(); |
||||
$vendor = Vendor::find($request->receiver_id); |
||||
if(!$receiver){ |
||||
$receiver = new UserInfo(); |
||||
$receiver->vendor_id = $vendor->id; |
||||
$receiver->f_name = $vendor->restaurants[0]->name; |
||||
$receiver->l_name = ''; |
||||
$receiver->phone = $vendor->phone; |
||||
$receiver->email = $vendor->email; |
||||
$receiver->image = $vendor->restaurants[0]->logo; |
||||
$receiver->save(); |
||||
} |
||||
|
||||
$receiver_id = $receiver->id; |
||||
$fcm_token=$vendor->firebase_token; |
||||
$fcm_token_web=$vendor->fcm_token_web; |
||||
|
||||
}else if($request->receiver_type == 'delivery_man'){ |
||||
$receiver = UserInfo::where('deliveryman_id',$request->receiver_id)->first(); |
||||
$delivery_man = DeliveryMan::find($request->receiver_id); |
||||
|
||||
if(!$receiver){ |
||||
$receiver = new UserInfo(); |
||||
$receiver->deliveryman_id = $delivery_man->id; |
||||
$receiver->f_name = $delivery_man->f_name; |
||||
$receiver->l_name = $delivery_man->l_name; |
||||
$receiver->phone = $delivery_man->phone; |
||||
$receiver->email = $delivery_man->email; |
||||
$receiver->image = $delivery_man->image; |
||||
$receiver->save(); |
||||
} |
||||
|
||||
$receiver_id = $receiver->id; |
||||
$fcm_token=$delivery_man->fcm_token; |
||||
} |
||||
|
||||
$conversation = Conversation::WhereConversation($sender->id,$receiver_id)->first(); |
||||
} |
||||
|
||||
if(!$conversation){ |
||||
$conversation = new Conversation; |
||||
$conversation->sender_id = $sender->id; |
||||
$conversation->sender_type = 'customer'; |
||||
$conversation->receiver_id = $receiver_id; |
||||
$conversation->receiver_type = $request->receiver_type; |
||||
$conversation->unread_message_count = 0; |
||||
$conversation->last_message_time = Carbon::now()->toDateTimeString(); |
||||
$conversation->save(); |
||||
$conversation= Conversation::find($conversation->id); |
||||
} |
||||
|
||||
$message = new Message(); |
||||
$message->conversation_id = $conversation->id; |
||||
$message->sender_id = $sender->id; |
||||
$message->message = $request->message; |
||||
$message->file = $image_name?json_encode($image_name, JSON_UNESCAPED_SLASHES):null; |
||||
try { |
||||
if($message->save()) |
||||
$conversation->unread_message_count = $conversation->unread_message_count? $conversation->unread_message_count+1:1; |
||||
$conversation->last_message_id=$message->id; |
||||
$conversation->last_message_time = Carbon::now()->toDateTimeString(); |
||||
$conversation->save(); |
||||
{ |
||||
if($request->receiver_type == 'admin' || $receiver_id == 0){ |
||||
$data = [ |
||||
'title' =>translate('messages.message'), |
||||
'description' =>translate('messages.message_description'), |
||||
'order_id' => '', |
||||
'image' => '', |
||||
'message' => json_encode($message) , |
||||
'type'=> 'message' |
||||
]; |
||||
Helpers::send_push_notif_to_topic($data,'admin_message','message'); |
||||
}else if($request->receiver_type == 'vendor' || $request->receiver_type == 'delivery_man'){ |
||||
$data = [ |
||||
'title' =>translate('messages.message'), |
||||
'description' =>translate('messages.message_description'), |
||||
'order_id' => '', |
||||
'image' => '', |
||||
'message' => json_encode($message) , |
||||
'type'=> 'message', |
||||
'conversation_id'=> $conversation->id, |
||||
'sender_type'=> 'user' |
||||
]; |
||||
Helpers::send_push_notif_to_device($fcm_token, $data); |
||||
if($fcm_token_web){ |
||||
Helpers::send_push_notif_to_device($fcm_token_web, $data); |
||||
} |
||||
|
||||
} |
||||
} |
||||
|
||||
} catch (\Exception $e) { |
||||
info($e); |
||||
} |
||||
|
||||
$messages = Message::where(['conversation_id' => $conversation->id])->latest()->paginate($limit, ['*'], 'page', $offset); |
||||
|
||||
$conv = Conversation::with('sender','receiver','last_message')->find($conversation->id); |
||||
|
||||
if($conv->sender_type == 'vendor' && $conversation->sender){ |
||||
$vd = Vendor::find($conv->sender->vendor_id); |
||||
$order = Order::where('user_id',$request->user()->id)->where('restaurant_id', $vd->restaurants[0]->id)->whereIn('order_status', ['pending','accepted','confirmed','processing','handover','picked_up'])->count(); |
||||
}else if($conv->receiver_type == 'vendor' && $conversation->receiver){ |
||||
$vd = Vendor::find($conv->receiver->vendor_id); |
||||
$order = Order::where('user_id',$request->user()->id)->where('restaurant_id', $vd->restaurants[0]->id)->whereIn('order_status', ['pending','accepted','confirmed','processing','handover','picked_up'])->count(); |
||||
}else if($conv->sender_type == 'delivery_man' && $conversation->sender){ |
||||
$user2 = DeliveryMan::find($conv->sender->deliveryman_id); |
||||
$order = Order::where('user_id',$request->user()->id)->where('delivery_man_id', $user2->id)->whereIn('order_status', ['pending','accepted','confirmed','processing','handover','picked_up'])->count(); |
||||
}else if($conv->receiver_type == 'delivery_man' && $conversation->receiver){ |
||||
$user2 = DeliveryMan::find($conv->receiver->deliveryman_id); |
||||
$order = Order::where('user_id',$request->user()->id)->where('delivery_man_id', $user2->id)->whereIn('order_status', ['pending','accepted','confirmed','processing','handover','picked_up'])->count(); |
||||
} |
||||
else{ |
||||
$order=1; |
||||
} |
||||
|
||||
|
||||
$data = [ |
||||
'total_size' => intval($messages->total()), |
||||
'limit' => intval($limit), |
||||
'offset' => intval($offset), |
||||
'status' => ($order>0)?true:false, |
||||
'message' => 'successfully sent!', |
||||
'messages' => $messages->items(), |
||||
'conversation' => $conv, |
||||
]; |
||||
return response()->json($data, 200); |
||||
} |
||||
|
||||
public function chat_image(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'image' => 'required|max:2048' |
||||
|
||||
]); |
||||
|
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)], 403); |
||||
} |
||||
|
||||
if ($request->has('image')) { |
||||
$image_name = Helpers::upload('conversation/', 'png', $request->file('image')); |
||||
} else { |
||||
$image_name = 'def.png'; |
||||
} |
||||
|
||||
$url = asset('storage/app/public/conversation') . '/' . $image_name; |
||||
|
||||
return response()->json(['image_url' => $url], 200); |
||||
} |
||||
|
||||
|
||||
public function conversations(Request $request) |
||||
{ |
||||
$limit = $request['limit']??10; |
||||
$offset = $request['offset']??1; |
||||
|
||||
$sender = UserInfo::where('user_id', $request->user()->id)->first(); |
||||
if(!$sender){ |
||||
$sender = new UserInfo(); |
||||
$sender->user_id = $request->user()->id; |
||||
$sender->f_name = $request->user()->f_name; |
||||
$sender->l_name = $request->user()->l_name; |
||||
$sender->phone = $request->user()->phone; |
||||
$sender->email = $request->user()->email; |
||||
$sender->image = $request->user()->image; |
||||
$sender->save(); |
||||
} |
||||
|
||||
$conversations = Conversation::with('sender','receiver','last_message')->where(['sender_id' => $sender->id])->orWhere(['receiver_id' => $sender->id])->orderBy('last_message_time', 'DESC')->paginate($limit, ['*'], 'page', $offset); |
||||
|
||||
$data = [ |
||||
'total_size' => intval($conversations->total()), |
||||
'limit' => intval($limit), |
||||
'offset' => intval($offset), |
||||
'conversations' => $conversations->items() |
||||
]; |
||||
return response()->json($data, 200); |
||||
} |
||||
|
||||
public function get_searched_conversations(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'name' => 'required' |
||||
]); |
||||
|
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)], 403); |
||||
} |
||||
|
||||
$key = explode(' ', $request['name']); |
||||
|
||||
$limit = $request['limit']??10; |
||||
$offset = $request['offset']??1; |
||||
|
||||
$sender = UserInfo::where('user_id', $request->user()->id)->first(); |
||||
if(!$sender){ |
||||
$sender = new UserInfo(); |
||||
$sender->user_id = $request->user()->id; |
||||
$sender->f_name = $request->user()->f_name; |
||||
$sender->l_name = $request->user()->l_name; |
||||
$sender->phone = $request->user()->phone; |
||||
$sender->email = $request->user()->email; |
||||
$sender->image = $request->user()->image; |
||||
$sender->save(); |
||||
} |
||||
|
||||
$conversations = Conversation::with('sender','receiver','last_message')->WhereUser($sender->id)->where(function($qu)use($key){ |
||||
$qu->whereHas('sender',function($query)use($key){ |
||||
foreach ($key as $value) { |
||||
$query->where('f_name', 'like', "%{$value}%")->orWhere('l_name', 'like', "%{$value}%"); |
||||
} |
||||
}) |
||||
->orWhereHas('receiver',function($query1)use($key){ |
||||
foreach ($key as $value) { |
||||
$query1->where('f_name', 'like', "%{$value}%")->orWhere('l_name', 'like', "%{$value}%"); |
||||
} |
||||
}); |
||||
}); |
||||
|
||||
$conversations = $conversations->orderBy('last_message_time', 'DESC')->paginate($limit, ['*'], 'page', $offset); |
||||
|
||||
$data = [ |
||||
'total_size' => intval($conversations->total()), |
||||
'limit' => intval($limit), |
||||
'offset' => intval($offset), |
||||
'conversations' => $conversations->items() |
||||
]; |
||||
return response()->json($data, 200); |
||||
} |
||||
|
||||
public function messages(Request $request) |
||||
{ |
||||
$limit = $request['limit']??10; |
||||
$offset = $request['offset']??1; |
||||
|
||||
$user = UserInfo::where('user_id', $request->user()->id)->first(); |
||||
if(!$user){ |
||||
$user = new UserInfo(); |
||||
$user->user_id = $request->user()->id; |
||||
$user->f_name = $request->user()->f_name; |
||||
$user->l_name = $request->user()->l_name; |
||||
$user->phone = $request->user()->phone; |
||||
$user->email = $request->user()->email; |
||||
$user->image = $request->user()->image; |
||||
$user->save(); |
||||
} |
||||
|
||||
$conversation = null; |
||||
if($request->conversation_id){ |
||||
$conversation = Conversation::with(['sender','receiver','last_message'])->find($request->conversation_id); |
||||
}else if($request->has('admin_id')){ |
||||
$conversation = Conversation::with(['sender','receiver','last_message'])->WhereConversation($user->id,0)->first(); |
||||
$order=0; |
||||
}else if($request->vendor_id){ |
||||
$vendor = UserInfo::where('vendor_id', $request->vendor_id)->first(); |
||||
if(!$vendor){ |
||||
$vd = Vendor::find($request->vendor_id); |
||||
$vendor = new UserInfo(); |
||||
$vendor->vendor_id = $vd->id; |
||||
$vendor->f_name = $vd->restaurants[0]->name; |
||||
$vendor->l_name = ''; |
||||
$vendor->phone = $vd->phone; |
||||
$vendor->email = $vd->email; |
||||
$vendor->image = $vd->restaurants[0]->logo; |
||||
$vendor->save(); |
||||
} |
||||
$conversation = Conversation::with(['sender','receiver','last_message'])->WhereConversation($user->id,$vendor->id)->first(); |
||||
}else if($request->delivery_man_id){ |
||||
$dm = UserInfo::where('deliveryman_id', $request->delivery_man_id)->first(); |
||||
if(!$dm){ |
||||
$user2 = DeliveryMan::find($request->delivery_man_id); |
||||
$dm = new UserInfo(); |
||||
$dm->deliveryman_id = $user2->id; |
||||
$dm->f_name = $user2->f_name; |
||||
$dm->l_name = $user2->l_name; |
||||
$dm->phone = $user2->phone; |
||||
$dm->email = $user2->email; |
||||
$dm->image = $user2->image; |
||||
$dm->save(); |
||||
} |
||||
$conversation = Conversation::with(['sender','receiver','last_message'])->WhereConversation($user->id,$dm->id)->first(); |
||||
} |
||||
|
||||
if(isset($conversation)){ |
||||
if($conversation->sender_type == 'vendor' && $conversation->sender){ |
||||
$vd = Vendor::find($conversation->sender->vendor_id); |
||||
$order = Order::where('user_id',$user->user_id)->where('restaurant_id', $vd->restaurants[0]->id)->whereIn('order_status', ['pending','accepted','confirmed','processing','handover','picked_up'])->count(); |
||||
}else if($conversation->receiver_type == 'vendor' && $conversation->receiver){ |
||||
$vd = Vendor::find($conversation->receiver->vendor_id); |
||||
$order = Order::where('user_id',$user->user_id)->where('restaurant_id', $vd->restaurants[0]->id)->whereIn('order_status', ['pending','accepted','confirmed','processing','handover','picked_up'])->count(); |
||||
}else if($conversation->sender_type == 'delivery_man' && $conversation->sender){ |
||||
$user2 = DeliveryMan::find($conversation->sender->deliveryman_id); |
||||
$order = Order::where('user_id',$user->user_id)->where('delivery_man_id', $user2->id)->whereIn('order_status', ['pending','accepted','confirmed','processing','handover','picked_up'])->count(); |
||||
}else if($conversation->receiver_type == 'delivery_man' && $conversation->receiver){ |
||||
$user2 = DeliveryMan::find($conversation->receiver->deliveryman_id); |
||||
$order = Order::where('user_id',$user->user_id)->where('delivery_man_id', $user2->id)->whereIn('order_status', ['pending','accepted','confirmed','processing','handover','picked_up'])->count(); |
||||
} |
||||
else{ |
||||
$order=1; |
||||
} |
||||
|
||||
$lastmessage = $conversation->last_message; |
||||
if($lastmessage && $lastmessage->sender_id != $user->id ) { |
||||
$conversation->unread_message_count = 0; |
||||
$conversation->save(); |
||||
} |
||||
Message::where(['conversation_id' => $conversation->id])->where('sender_id','!=',$user->id)->update(['is_seen' => 1]); |
||||
$messages = Message::where(['conversation_id' => $conversation->id])->latest()->paginate($limit, ['*'], 'page', $offset); |
||||
}else{ |
||||
$messages =[]; |
||||
$order=0; |
||||
} |
||||
|
||||
|
||||
$data = [ |
||||
'total_size' => $messages? intval($messages->total()):0, |
||||
'limit' => intval($limit), |
||||
'offset' => intval($offset), |
||||
'status' => ($order > 0)?true:false, |
||||
'messages' => $messages? $messages->items():[], |
||||
'conversation' => $conversation |
||||
]; |
||||
return response()->json($data, 200); |
||||
} |
||||
|
||||
public function dm_messages_store(Request $request) |
||||
{ |
||||
|
||||
if ($request->has('image')) { |
||||
|
||||
$validator = Validator::make($request->all(), [ |
||||
'image.*' => 'max:2048', |
||||
]); |
||||
|
||||
if ($validator->fails()) { |
||||
$validator->getMessageBag()->add('image', 'Max Image Upload limit is 2mb'); |
||||
return response()->json(['errors' => Helpers::error_processor($validator)],403); |
||||
} |
||||
|
||||
$image_name=[]; |
||||
foreach($request->file('image') as $key=>$img) |
||||
{ |
||||
|
||||
$name = Helpers::upload('conversation/', 'png', $img); |
||||
array_push($image_name,$name); |
||||
} |
||||
} else { |
||||
$image_name = null; |
||||
} |
||||
|
||||
$limit = $request['limit']??10; |
||||
$offset = $request['offset']??1; |
||||
$fcm_token_web = null; |
||||
$dm = DeliveryMan::where(['auth_token' => $request['token']])->first(); |
||||
|
||||
$sender = UserInfo::where('deliveryman_id', $dm->id)->first(); |
||||
if(!$sender){ |
||||
$sender = new UserInfo(); |
||||
$sender->deliveryman_id = $dm->id; |
||||
$sender->f_name = $dm->f_name; |
||||
$sender->l_name = $dm->l_name; |
||||
$sender->phone = $dm->phone; |
||||
$sender->email = $dm->email; |
||||
$sender->image = $dm->image; |
||||
$sender->save(); |
||||
} |
||||
|
||||
if($request->conversation_id){ |
||||
$conversation = Conversation::find($request->conversation_id); |
||||
|
||||
if($conversation->sender_id == $sender->id){ |
||||
$receiver_id = $conversation->receiver_id; |
||||
$receiver = UserInfo::find($receiver_id); |
||||
if($receiver->vendor_id){ |
||||
$vendor = Vendor::find($receiver->vendor_id); |
||||
$fcm_token=$vendor->firebase_token; |
||||
$fcm_token_web = "restaurant_panel_{$vendor->restaurants[0]->id}_message"; |
||||
}elseif($receiver->user_id){ |
||||
$user = User::find($receiver->user_id); |
||||
$fcm_token=$user->cm_firebase_token; |
||||
} |
||||
}else{ |
||||
$receiver_id =$conversation->sender_id; |
||||
$receiver = UserInfo::find($receiver_id); |
||||
if($receiver->vendor_id){ |
||||
$vendor = Vendor::find($receiver->vendor_id); |
||||
$fcm_token=$vendor->firebase_token; |
||||
$fcm_token_web="restaurant_panel_{$vendor->restaurants[0]->id}_message"; |
||||
}elseif($receiver->user_id){ |
||||
$user = User::find($receiver->user_id); |
||||
$fcm_token=$user->cm_firebase_token; |
||||
} |
||||
} |
||||
}else{ |
||||
if($request->receiver_type == 'vendor'){ |
||||
$receiver = UserInfo::where('vendor_id',$request->receiver_id)->first(); |
||||
$vendor = Vendor::find($request->receiver_id); |
||||
|
||||
if(!$receiver){ |
||||
$receiver = new UserInfo(); |
||||
$receiver->vendor_id = $vendor->id; |
||||
$receiver->f_name = $vendor->restaurants[0]->name; |
||||
$receiver->l_name = ''; |
||||
$receiver->phone = $vendor->phone; |
||||
$receiver->email = $vendor->email; |
||||
$receiver->image = $vendor->restaurants[0]->logo; |
||||
$receiver->save(); |
||||
} |
||||
$receiver_id = $receiver->id; |
||||
$fcm_token=$vendor->firebase_token; |
||||
$fcm_token_web="restaurant_panel_{$vendor->restaurants[0]->id}_message"; |
||||
}else if($request->receiver_type == 'customer'){ |
||||
$receiver = UserInfo::where('user_id',$request->receiver_id)->first(); |
||||
$user = User::find($request->receiver_id); |
||||
// dd($user); |
||||
|
||||
if(!$receiver){ |
||||
$receiver = new UserInfo(); |
||||
$receiver->user_id = $user->id; |
||||
$receiver->f_name = $user->f_name; |
||||
$receiver->l_name = $user->l_name; |
||||
$receiver->phone = $user->phone; |
||||
$receiver->email = $user->email; |
||||
$receiver->image = $user->image; |
||||
$receiver->save(); |
||||
} |
||||
$receiver_id = $receiver->id; |
||||
$fcm_token=$user->cm_firebase_token; |
||||
} |
||||
} |
||||
|
||||
$conversation = Conversation::WhereConversation($sender->id,$receiver_id)->first(); |
||||
|
||||
if(!$conversation){ |
||||
$conversation = new Conversation; |
||||
$conversation->sender_id = $sender->id; |
||||
$conversation->sender_type = 'delivery_man'; |
||||
$conversation->receiver_id = $receiver->id; |
||||
$conversation->receiver_type = $request->receiver_type; |
||||
$conversation->unread_message_count = 0; |
||||
$conversation->last_message_time = Carbon::now()->toDateTimeString(); |
||||
$conversation->save(); |
||||
$conversation= Conversation::find($conversation->id); |
||||
} |
||||
|
||||
|
||||
$message = new Message(); |
||||
$message->conversation_id = $conversation->id; |
||||
$message->sender_id = $sender->id; |
||||
$message->message = $request->message; |
||||
$message->file = $image_name?json_encode($image_name, JSON_UNESCAPED_SLASHES):null; |
||||
try { |
||||
if($message->save()) |
||||
$conversation->unread_message_count = $conversation->unread_message_count? $conversation->unread_message_count+1:1; |
||||
$conversation->last_message_id=$message->id; |
||||
$conversation->last_message_time = Carbon::now()->toDateTimeString(); |
||||
$conversation->save(); |
||||
{ |
||||
$data = [ |
||||
'title' =>translate('messages.message'), |
||||
'description' =>translate('messages.message_description'), |
||||
'order_id' => '', |
||||
'image' => '', |
||||
'message' => json_encode($message) , |
||||
'type'=> 'message', |
||||
'conversation_id'=> $conversation->id, |
||||
'sender_type'=> 'delivery_man' |
||||
]; |
||||
Helpers::send_push_notif_to_device($fcm_token, $data); |
||||
if($fcm_token_web){ |
||||
Helpers::send_push_notif_to_topic($data, $fcm_token_web, 'message'); |
||||
} |
||||
} |
||||
|
||||
} catch (\Exception $e) { |
||||
info($e); |
||||
} |
||||
|
||||
$messages = Message::where(['conversation_id' => $conversation->id])->latest()->paginate($limit, ['*'], 'page', $offset); |
||||
|
||||
$conv = Conversation::with('sender','receiver','last_message')->find($conversation->id); |
||||
|
||||
if($conv->sender_type == 'vendor' && $conversation->sender){ |
||||
$vd = Vendor::find($conv->sender->vendor_id); |
||||
$order = Order::where('delivery_man_id',$dm->id)->where('restaurant_id', $vd->restaurants[0]->id)->whereIn('order_status', ['pending','accepted','confirmed','processing','handover','picked_up'])->count(); |
||||
}else if($conv->receiver_type == 'vendor' && $conversation->receiver){ |
||||
$vd = Vendor::find($conv->receiver->vendor_id); |
||||
$order = Order::where('delivery_man_id',$dm->id)->where('restaurant_id', $vd->restaurants[0]->id)->whereIn('order_status', ['pending','accepted','confirmed','processing','handover','picked_up'])->count(); |
||||
}else if($conv->sender_type == 'customer' && $conversation->sender){ |
||||
$user = User::find($conv->sender->user_id); |
||||
$order = Order::where('delivery_man_id',$dm->id)->where('user_id', $user->id)->whereIn('order_status', ['pending','accepted','confirmed','processing','handover','picked_up'])->count(); |
||||
}else if($conv->receiver_type == 'customer' && $conversation->receiver){ |
||||
$user = User::find($conv->receiver->user_id); |
||||
$order = Order::where('delivery_man_id',$dm->id)->where('user_id', $user->id)->whereIn('order_status', ['pending','accepted','confirmed','processing','handover','picked_up'])->count(); |
||||
} |
||||
else{ |
||||
$order=0; |
||||
} |
||||
|
||||
|
||||
$data = [ |
||||
'total_size' => intval($messages->total()), |
||||
'limit' => intval($limit), |
||||
'offset' => intval($offset), |
||||
'status' => ($order>0)?true:false, |
||||
'message' => 'successfully sent!', |
||||
'messages' => $messages->items(), |
||||
'conversation' => $conv, |
||||
]; |
||||
return response()->json($data, 200); |
||||
} |
||||
|
||||
public function dm_conversations(Request $request) |
||||
{ |
||||
$limit = $request['limit']??10; |
||||
$offset = $request['offset']??1; |
||||
|
||||
$delivery_man = DeliveryMan::where(['auth_token' => $request['token']])->first(); |
||||
|
||||
$sender = UserInfo::where('deliveryman_id', $delivery_man->id)->first(); |
||||
if(!$sender){ |
||||
$sender = new UserInfo(); |
||||
$sender->deliveryman_id = $delivery_man->id; |
||||
$sender->f_name = $delivery_man->f_name; |
||||
$sender->l_name = $delivery_man->l_name; |
||||
$sender->phone = $delivery_man->phone; |
||||
$sender->email = $delivery_man->email; |
||||
$sender->image = $delivery_man->image; |
||||
$sender->save(); |
||||
} |
||||
|
||||
|
||||
$conversations = Conversation::with('sender','receiver','last_message')->where(['sender_id' => $sender->id])->orWhere(['receiver_id' => $sender->id])->orderBy('last_message_time', 'DESC')->paginate($limit, ['*'], 'page', $offset); |
||||
|
||||
|
||||
$data = [ |
||||
'total_size' => intval($conversations->total()), |
||||
'limit' => intval($limit), |
||||
'offset' => intval($offset), |
||||
'conversation' => $conversations->items() |
||||
]; |
||||
|
||||
return response()->json($data, 200); |
||||
} |
||||
|
||||
public function dm_search_conversations(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'name' => 'required' |
||||
]); |
||||
|
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)], 403); |
||||
} |
||||
|
||||
$key = explode(' ', $request['name']); |
||||
|
||||
$limit = $request['limit']??10; |
||||
$offset = $request['offset']??1; |
||||
|
||||
$delivery_man = DeliveryMan::where(['auth_token' => $request['token']])->first(); |
||||
|
||||
$sender = UserInfo::where('deliveryman_id', $delivery_man->id)->first(); |
||||
if(!$sender){ |
||||
$sender = new UserInfo(); |
||||
$sender->deliveryman_id = $delivery_man->id; |
||||
$sender->f_name = $delivery_man->f_name; |
||||
$sender->l_name = $delivery_man->l_name; |
||||
$sender->phone = $delivery_man->phone; |
||||
$sender->email = $delivery_man->email; |
||||
$sender->image = $delivery_man->image; |
||||
$sender->save(); |
||||
} |
||||
|
||||
$conversations = Conversation::with('sender','receiver','last_message')->WhereUser($sender->id)->where(function($qu)use($key){ |
||||
$qu->whereHas('sender',function($query)use($key){ |
||||
foreach ($key as $value) { |
||||
$query->where('f_name', 'like', "%{$value}%")->orWhere('l_name', 'like', "%{$value}%"); |
||||
} |
||||
}) |
||||
->orWhereHas('receiver',function($query1)use($key){ |
||||
foreach ($key as $value) { |
||||
$query1->where('f_name', 'like', "%{$value}%")->orWhere('l_name', 'like', "%{$value}%"); |
||||
} |
||||
}); |
||||
}); |
||||
|
||||
$conversations = $conversations->orderBy('last_message_time', 'DESC')->paginate($limit, ['*'], 'page', $offset); |
||||
|
||||
$data = [ |
||||
'total_size' => intval($conversations->total()), |
||||
'limit' => intval($limit), |
||||
'offset' => intval($offset), |
||||
'conversation' => $conversations->items() |
||||
]; |
||||
return response()->json($data, 200); |
||||
} |
||||
|
||||
|
||||
public function dm_messages(Request $request) |
||||
{ |
||||
$limit = $request['limit']??10; |
||||
$offset = $request['offset']??1; |
||||
|
||||
$dm = DeliveryMan::where(['auth_token' => $request['token']])->first(); |
||||
$delivery_man = UserInfo::where('deliveryman_id',$dm->id)->first(); |
||||
|
||||
if(!$delivery_man){ |
||||
$delivery_man = new UserInfo(); |
||||
$delivery_man->deliveryman_id = $dm->id; |
||||
$delivery_man->f_name = $dm->f_name; |
||||
$delivery_man->l_name = $dm->l_name; |
||||
$delivery_man->phone = $dm->phone; |
||||
$delivery_man->email = $dm->email; |
||||
$delivery_man->image = $dm->image; |
||||
$delivery_man->save(); |
||||
} |
||||
|
||||
if($request->conversation_id){ |
||||
$conversation = Conversation::with(['sender','receiver','last_message'])->find($request->conversation_id); |
||||
}else if($request->vendor_id){ |
||||
$vendor = UserInfo::where('vendor_id', $request->vendor_id)->first(); |
||||
if(!$vendor){ |
||||
$user = Vendor::find($request->vendor_id); |
||||
$vendor = new UserInfo(); |
||||
$vendor->vendor_id = $user->id; |
||||
$vendor->f_name = $user->restaurants[0]->name; |
||||
$vendor->l_name = ''; |
||||
$vendor->phone = $user->phone; |
||||
$vendor->email = $user->email; |
||||
$vendor->image = $user->image; |
||||
$vendor->save(); |
||||
} |
||||
$conversation = Conversation::with(['sender','receiver','last_message'])->WhereConversation($delivery_man->id,$vendor->id)->first(); |
||||
|
||||
}else if($request->user_id){ |
||||
$user = UserInfo::where('user_id', $request->user_id)->first(); |
||||
if(!$user){ |
||||
$customer = User::find($request->user_id); |
||||
$user = new UserInfo(); |
||||
$user->user_id = $customer->id; |
||||
$user->f_name = $customer->f_name; |
||||
$user->l_name = $customer->l_name; |
||||
$user->phone = $customer->phone; |
||||
$user->email = $customer->email; |
||||
$user->image = $customer->image; |
||||
$user->save(); |
||||
} |
||||
$conversation = Conversation::with(['sender','receiver','last_message'])->WhereConversation($delivery_man->id,$user->id)->first(); |
||||
} |
||||
|
||||
if($conversation){ |
||||
|
||||
if($conversation->sender_type == 'vendor' && $conversation->sender){ |
||||
$vd = Vendor::find($conversation->sender->vendor_id); |
||||
$order = Order::where('delivery_man_id',$dm->id)->where('restaurant_id', $vd->restaurants[0]->id)->whereIn('order_status', ['pending','accepted','confirmed','processing','handover','picked_up'])->count(); |
||||
}else if($conversation->receiver_type == 'vendor' && $conversation->receiver){ |
||||
$vd = Vendor::find($conversation->receiver->vendor_id); |
||||
$order = Order::where('delivery_man_id',$dm->id)->where('restaurant_id', $vd->restaurants[0]->id)->whereIn('order_status', ['pending','accepted','confirmed','processing','handover','picked_up'])->count(); |
||||
}else if($conversation->sender_type == 'customer' && $conversation->sender){ |
||||
$user = User::find($conversation->sender->user_id); |
||||
$order = Order::where('delivery_man_id',$dm->id)->where('user_id', $user->id)->whereIn('order_status', ['pending','accepted','confirmed','processing','handover','picked_up'])->count(); |
||||
}else if($conversation->receiver_type == 'customer' && $conversation->receiver){ |
||||
$user = User::find($conversation->receiver->user_id); |
||||
$order = Order::where('delivery_man_id',$dm->id)->where('user_id', $user->id)->whereIn('order_status', ['pending','accepted','confirmed','processing','handover','picked_up'])->count(); |
||||
} |
||||
else{ |
||||
$order=0; |
||||
} |
||||
|
||||
|
||||
$lastmessage = $conversation->last_message; |
||||
if($lastmessage && $lastmessage->sender_id != $delivery_man->id ) { |
||||
$conversation->unread_message_count = 0; |
||||
$conversation->save(); |
||||
} |
||||
|
||||
Message::where(['conversation_id' => $conversation->id])->where('sender_id','!=',$delivery_man->id)->update(['is_seen' => 1]); |
||||
$messages = Message::where(['conversation_id' => $conversation->id])->latest()->paginate($limit, ['*'], 'page', $offset); |
||||
}else{ |
||||
$messages =[]; |
||||
$order=0; |
||||
} |
||||
|
||||
$data = [ |
||||
'total_size' => $messages? intval($messages->total()):0, |
||||
'limit' => intval($limit), |
||||
'offset' => intval($offset), |
||||
'status' => ($order>0)?true:false, |
||||
'messages' => $messages? $messages->items():[], |
||||
'conversation' => $conversation |
||||
]; |
||||
return response()->json($data, 200); |
||||
} |
||||
} |
@ -0,0 +1,118 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Api\V1; |
||||
|
||||
use App\Models\Order; |
||||
use App\Models\Coupon; |
||||
use App\Models\Restaurant; |
||||
use Illuminate\Http\Request; |
||||
use App\CentralLogics\Helpers; |
||||
use App\CentralLogics\CouponLogic; |
||||
use App\Http\Controllers\Controller; |
||||
use Illuminate\Support\Facades\Auth; |
||||
use Illuminate\Support\Facades\Validator; |
||||
|
||||
class CouponController extends Controller |
||||
{ |
||||
public function list(Request $request) |
||||
{ |
||||
if (!$request->hasHeader('zoneId')) { |
||||
$errors = []; |
||||
array_push($errors, ['code' => 'zoneId', 'message' => translate('messages.zone_id_required')]); |
||||
return response()->json([ |
||||
'errors' => $errors |
||||
], 403); |
||||
} |
||||
$customer_id=Auth::user()->id; |
||||
$zone_id= json_decode($request->header('zoneId'), true); |
||||
$data = []; |
||||
$coupons = Coupon::with('restaurant:id,name')->active()->whereDate('expire_date', '>=', date('Y-m-d'))->whereDate('start_date', '<=', date('Y-m-d'))->get(); |
||||
foreach($coupons as $key=>$coupon) |
||||
{ |
||||
if($coupon->coupon_type == 'restaurant_wise') |
||||
{ |
||||
$temp = Restaurant::active()->whereIn('zone_id', $zone_id)->whereIn('id', json_decode($coupon->data, true))->first(); |
||||
if($temp && (in_array("all", json_decode($coupon->customer_id, true)) || in_array($customer_id,json_decode($coupon->customer_id, true)))) |
||||
{ |
||||
$coupon->data = $temp->name; |
||||
$data[] = $coupon; |
||||
} |
||||
} |
||||
else if($coupon->coupon_type == 'zone_wise') |
||||
{ |
||||
foreach($zone_id as $z_id) { |
||||
if(in_array($z_id, json_decode($coupon->data,true))) |
||||
{ |
||||
$data[] = $coupon; |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
else{ |
||||
if((in_array("all", json_decode($coupon->customer_id, true)) || in_array($customer_id,json_decode($coupon->customer_id, true))) ){ |
||||
$data[] = $coupon; |
||||
} |
||||
} |
||||
} |
||||
return response()->json($data, 200); |
||||
} |
||||
|
||||
|
||||
|
||||
public function apply(Request $request) |
||||
{ |
||||
|
||||
$validator = Validator::make($request->all(), [ |
||||
'code' => 'required', |
||||
'restaurant_id' => 'required', |
||||
]); |
||||
|
||||
if ($validator->errors()->count()>0) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)], 403); |
||||
} |
||||
|
||||
try { |
||||
$coupon = Coupon::active()->where(['code' => $request['code']])->first(); |
||||
if (isset($coupon)) { |
||||
$staus = CouponLogic::is_valide($coupon, $request->user()->id ,$request['restaurant_id']); |
||||
|
||||
switch ($staus) { |
||||
case 200: |
||||
return response()->json($coupon, 200); |
||||
case 406: |
||||
return response()->json([ |
||||
'errors' => [ |
||||
['code' => 'coupon', 'message' => translate('messages.coupon_usage_limit_over')] |
||||
] |
||||
], 406); |
||||
case 407: |
||||
return response()->json([ |
||||
'errors' => [ |
||||
['code' => 'coupon', 'message' => translate('messages.coupon_expire')] |
||||
] |
||||
], 407); |
||||
case 408: |
||||
return response()->json([ |
||||
'errors' => [ |
||||
['code' => 'coupon', 'message' => translate('messages.You_are_not_eligible_for_this_coupon')] |
||||
] |
||||
], 403); |
||||
default: |
||||
return response()->json([ |
||||
'errors' => [ |
||||
['code' => 'coupon', 'message' => translate('messages.not_found')] |
||||
] |
||||
], 404); |
||||
} |
||||
} else { |
||||
return response()->json([ |
||||
'errors' => [ |
||||
['code' => 'coupon', 'message' => translate('messages.not_found')] |
||||
] |
||||
], 404); |
||||
} |
||||
} catch (\Exception $e) { |
||||
return response()->json(['errors' => $e], 403); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,57 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Api\V1; |
||||
|
||||
use App\Models\Cuisine; |
||||
use App\Models\Restaurant; |
||||
use Illuminate\Http\Request; |
||||
use App\CentralLogics\Helpers; |
||||
use App\Http\Controllers\Controller; |
||||
use Illuminate\Support\Facades\Validator; |
||||
|
||||
class CuisineConbtroller extends Controller |
||||
{ |
||||
public function get_all_cuisines() |
||||
{ |
||||
$Cuisines = Cuisine::where('status',1)->get(); |
||||
return response()->json( ['Cuisines' => $Cuisines], 200); |
||||
} |
||||
public function get_restaurants(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'cuisine_id' => 'required', |
||||
'limit' => 'required', |
||||
'offset' => 'required', |
||||
]); |
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)], 203); |
||||
} |
||||
$longitude= $request->header('longitude'); |
||||
$latitude= $request->header('latitude'); |
||||
|
||||
if (!$request->hasHeader('zoneId')) { |
||||
$errors = []; |
||||
array_push($errors, ['code' => 'zoneId', 'message' => translate('messages.zone_id_required')]); |
||||
return response()->json([ |
||||
'errors' => $errors |
||||
], 403); |
||||
} |
||||
$zone_id= json_decode($request->header('zoneId'), true); |
||||
$limit = $request->query('limit', 1); |
||||
$offset = $request->query('offset', 1); |
||||
|
||||
$restaurants=Restaurant::whereIn('zone_id',$zone_id)->cuisine($request->cuisine_id)->WithOpen($longitude,$latitude) |
||||
->paginate($limit, ['*'], 'page', $offset); |
||||
|
||||
$restaurants_data = Helpers::restaurant_data_formatting($restaurants->items(), true); |
||||
|
||||
$data = [ |
||||
'total_size' => $restaurants->total(), |
||||
'limit' => $limit, |
||||
'offset' => $offset, |
||||
'restaurants' => $restaurants_data, |
||||
]; |
||||
return response()->json($data, 200); |
||||
|
||||
} |
||||
} |
@ -0,0 +1,325 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Api\V1; |
||||
|
||||
use App\CentralLogics\Helpers; |
||||
use App\Http\Controllers\Controller; |
||||
use App\Models\CustomerAddress; |
||||
use App\Models\Order; |
||||
use App\Models\Food; |
||||
use App\Models\OrderDetail; |
||||
use App\Models\User; |
||||
use App\Models\UserInfo; |
||||
use Illuminate\Http\Request; |
||||
use Illuminate\Support\Facades\DB; |
||||
use Illuminate\Support\Facades\Validator; |
||||
use App\Models\Zone; |
||||
use Grimzy\LaravelMysqlSpatial\Types\Point; |
||||
class CustomerController extends Controller |
||||
{ |
||||
public function address_list(Request $request) |
||||
{ |
||||
$limit = $request['limit']??10; |
||||
$offset = $request['offset']??1; |
||||
|
||||
$addresses = CustomerAddress::where('user_id', $request->user()->id)->latest()->paginate($limit, ['*'], 'page', $offset); |
||||
|
||||
$data = [ |
||||
'total_size' => $addresses->total(), |
||||
'limit' => $limit, |
||||
'offset' => $offset, |
||||
'addresses' => Helpers::address_data_formatting($addresses->items()) |
||||
]; |
||||
return response()->json($data, 200); |
||||
} |
||||
|
||||
public function add_new_address(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'contact_person_name' => 'required', |
||||
'address_type' => 'required', |
||||
'contact_person_number' => 'required', |
||||
'address' => 'required', |
||||
'longitude' => 'required', |
||||
'latitude' => 'required', |
||||
]); |
||||
|
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)], 403); |
||||
} |
||||
|
||||
$point = new Point($request->latitude,$request->longitude); |
||||
$zone = Zone::contains('coordinates', $point)->get(['id']); |
||||
if(count($zone) == 0) |
||||
{ |
||||
$errors = []; |
||||
array_push($errors, ['code' => 'coordinates', 'message' => translate('messages.service_not_available_in_this_area')]); |
||||
return response()->json([ |
||||
'errors' => $errors |
||||
], 403); |
||||
} |
||||
|
||||
$address = [ |
||||
'user_id' => $request->user()->id, |
||||
'contact_person_name' => $request->contact_person_name, |
||||
'contact_person_number' => $request->contact_person_number, |
||||
'address_type' => $request->address_type, |
||||
'address' => $request->address, |
||||
'floor' => $request->floor, |
||||
'road' => $request->road, |
||||
'house' => $request->house, |
||||
'longitude' => $request->longitude, |
||||
'latitude' => $request->latitude, |
||||
'zone_id' => $zone[0]->id, |
||||
'created_at' => now(), |
||||
'updated_at' => now() |
||||
]; |
||||
DB::table('customer_addresses')->insert($address); |
||||
return response()->json(['message' => translate('messages.successfully_added'),'zone_ids'=>array_column($zone->toArray(), 'id')], 200); |
||||
} |
||||
|
||||
public function update_address(Request $request,$id) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'contact_person_name' => 'required', |
||||
'address_type' => 'required', |
||||
'contact_person_number' => 'required', |
||||
'address' => 'required', |
||||
'longitude' => 'required', |
||||
'latitude' => 'required', |
||||
]); |
||||
|
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)], 403); |
||||
} |
||||
$point = new Point($request->latitude,$request->longitude); |
||||
$zone = Zone::contains('coordinates', $point)->first(); |
||||
if(!$zone) |
||||
{ |
||||
$errors = []; |
||||
array_push($errors, ['code' => 'coordinates', 'message' => translate('messages.service_not_available_in_this_area')]); |
||||
return response()->json([ |
||||
'errors' => $errors |
||||
], 403); |
||||
} |
||||
$address = [ |
||||
'user_id' => $request->user()->id, |
||||
'contact_person_name' => $request->contact_person_name, |
||||
'contact_person_number' => $request->contact_person_number, |
||||
'address_type' => $request->address_type, |
||||
'address' => $request->address, |
||||
'floor' => $request->floor, |
||||
'road' => $request->road, |
||||
'house' => $request->house, |
||||
'longitude' => $request->longitude, |
||||
'latitude' => $request->latitude, |
||||
'zone_id' => $zone->id, |
||||
'created_at' => now(), |
||||
'updated_at' => now() |
||||
]; |
||||
DB::table('customer_addresses')->where('id',$id)->update($address); |
||||
return response()->json(['message' => translate('messages.updated_successfully'),'zone_id'=>$zone->id], 200); |
||||
} |
||||
|
||||
public function delete_address(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'address_id' => 'required' |
||||
]); |
||||
|
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)], 403); |
||||
} |
||||
|
||||
if (DB::table('customer_addresses')->where(['id' => $request['address_id'], 'user_id' => $request->user()->id])->first()) { |
||||
DB::table('customer_addresses')->where(['id' => $request['address_id'], 'user_id' => $request->user()->id])->delete(); |
||||
return response()->json(['message' => translate('messages.successfully_removed')], 200); |
||||
} |
||||
return response()->json(['message' => translate('messages.not_found')], 404); |
||||
} |
||||
|
||||
public function get_order_list(Request $request) |
||||
{ |
||||
$orders = Order::with('restaurant')->where(['user_id' => $request->user()->id])->get(); |
||||
return response()->json($orders, 200); |
||||
} |
||||
|
||||
public function get_order_details(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'order_id' => 'required' |
||||
]); |
||||
|
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)], 403); |
||||
} |
||||
|
||||
$details = OrderDetail::where(['order_id' => $request['order_id']])->get(); |
||||
foreach ($details as $det) { |
||||
$det['product_details'] = json_decode($det['product_details'], true); |
||||
} |
||||
|
||||
return response()->json($details, 200); |
||||
} |
||||
|
||||
public function info(Request $request) |
||||
{ |
||||
$data = $request->user(); |
||||
$data['userinfo'] = $data->userinfo; |
||||
$data['order_count'] =(integer)$request->user()->orders->count(); |
||||
$data['member_since_days'] =(integer)$request->user()->created_at->diffInDays(); |
||||
unset($data['orders']); |
||||
return response()->json($data, 200); |
||||
} |
||||
|
||||
public function update_profile(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'f_name' => 'required', |
||||
'l_name' => 'required', |
||||
'email' => 'required|unique:users,email,'.$request->user()->id, |
||||
'image' => 'nullable|max:2048', |
||||
|
||||
], [ |
||||
'f_name.required' => 'First name is required!', |
||||
'l_name.required' => 'Last name is required!', |
||||
]); |
||||
|
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)], 403); |
||||
} |
||||
|
||||
$image = $request->file('image'); |
||||
|
||||
if ($request->has('image')) { |
||||
$imageName = Helpers::update('profile/', $request->user()->image, 'png', $request->file('image')); |
||||
} else { |
||||
$imageName = $request->user()->image; |
||||
} |
||||
|
||||
if ($request['password'] != null && strlen($request['password']) > 5) { |
||||
$pass = bcrypt($request['password']); |
||||
} else { |
||||
$pass = $request->user()->password; |
||||
} |
||||
|
||||
$userDetails = [ |
||||
'f_name' => $request->f_name, |
||||
'l_name' => $request->l_name, |
||||
'email' => $request->email, |
||||
'image' => $imageName, |
||||
'password' => $pass, |
||||
'updated_at' => now() |
||||
]; |
||||
|
||||
User::where(['id' => $request->user()->id])->update($userDetails); |
||||
if($request->user()->userinfo) { |
||||
UserInfo::where(['user_id' => $request->user()->id])->update([ |
||||
'f_name' => $request->f_name, |
||||
'l_name' => $request->l_name, |
||||
'email' => $request->email, |
||||
'image' => $imageName |
||||
]); |
||||
} |
||||
|
||||
|
||||
return response()->json(['message' => translate('messages.successfully_updated')], 200); |
||||
} |
||||
public function update_interest(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'interest' => 'required|array', |
||||
]); |
||||
|
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)], 403); |
||||
} |
||||
|
||||
$userDetails = [ |
||||
'interest' => json_encode($request->interest), |
||||
]; |
||||
|
||||
User::where(['id' => $request->user()->id])->update($userDetails); |
||||
|
||||
return response()->json(['message' => translate('messages.interest_updated_successfully')], 200); |
||||
} |
||||
|
||||
public function update_cm_firebase_token(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'cm_firebase_token' => 'required', |
||||
]); |
||||
|
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)], 403); |
||||
} |
||||
|
||||
DB::table('users')->where('id',$request->user()->id)->update([ |
||||
'cm_firebase_token'=>$request['cm_firebase_token'] |
||||
]); |
||||
|
||||
return response()->json(['message' => translate('messages.updated_successfully')], 200); |
||||
} |
||||
|
||||
public function get_suggested_food(Request $request) |
||||
{ |
||||
if (!$request->hasHeader('zoneId')) { |
||||
$errors = []; |
||||
array_push($errors, ['code' => 'zoneId', 'message' => 'Zone id is required!']); |
||||
return response()->json([ |
||||
'errors' => $errors |
||||
], 403); |
||||
} |
||||
|
||||
|
||||
$zone_id= json_decode($request->header('zoneId'), true); |
||||
|
||||
$interest = $request->user()->interest; |
||||
$interest = isset($interest) ? json_decode($interest):null; |
||||
// return response()->json($interest, 200); |
||||
|
||||
$products = Food::active()->whereHas('restaurant', function($q)use($zone_id){ |
||||
$q->whereIn('zone_id', $zone_id); |
||||
}) |
||||
->when(isset($interest), function($q)use($interest){ |
||||
return $q->whereIn('category_id',$interest); |
||||
}) |
||||
->when($interest == null, function($q){ |
||||
return $q->popular(); |
||||
})->limit(5)->get(); |
||||
$products = Helpers::product_data_formatting($products, true, false, app()->getLocale()); |
||||
return response()->json($products, 200); |
||||
} |
||||
|
||||
public function update_zone(Request $request) |
||||
{ |
||||
if (!$request->hasHeader('zoneId') && is_numeric($request->header('zoneId'))) { |
||||
$errors = []; |
||||
array_push($errors, ['code' => 'zoneId', 'message' => translate('messages.zone_id_required')]); |
||||
return response()->json([ |
||||
'errors' => $errors |
||||
], 403); |
||||
} |
||||
|
||||
$customer = $request->user(); |
||||
$customer->zone_id = (integer)json_decode($request->header('zoneId'), true)[0]; |
||||
$customer->save(); |
||||
return response()->json([], 200); |
||||
} |
||||
|
||||
public function remove_account(Request $request) |
||||
{ |
||||
$user = $request->user(); |
||||
|
||||
if(Order::where('user_id', $user->id)->whereIn('order_status', ['pending','accepted','confirmed','processing','handover','picked_up'])->count()) |
||||
{ |
||||
return response()->json(['errors'=>[['code'=>'on-going', 'message'=>translate('messages.user_account_delete_warning')]]],403); |
||||
} |
||||
$request->user()->token()->revoke(); |
||||
if($user->userinfo){ |
||||
$user->userinfo->delete(); |
||||
} |
||||
$user->delete(); |
||||
return response()->json([]); |
||||
} |
||||
} |
@ -0,0 +1,101 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Api\V1; |
||||
|
||||
use App\CentralLogics\Helpers; |
||||
use App\Http\Controllers\Controller; |
||||
use App\Models\DeliveryMan; |
||||
use App\Models\DMReview; |
||||
use Illuminate\Http\Request; |
||||
use Illuminate\Support\Facades\Storage; |
||||
use Illuminate\Support\Facades\Validator; |
||||
|
||||
class DeliveryManReviewController extends Controller |
||||
{ |
||||
public function get_reviews($id) |
||||
{ |
||||
$reviews = DMReview::with(['customer', 'delivery_man'])->where(['delivery_man_id' => $id])->active()->get(); |
||||
|
||||
$storage = []; |
||||
foreach ($reviews as $item) { |
||||
$item['attachment'] = json_decode($item['attachment']); |
||||
array_push($storage, $item); |
||||
} |
||||
|
||||
return response()->json($storage, 200); |
||||
} |
||||
|
||||
public function get_rating($id) |
||||
{ |
||||
try { |
||||
$totalReviews = DMReview::where(['delivery_man_id' => $id])->get(); |
||||
$rating = 0; |
||||
foreach ($totalReviews as $key => $review) { |
||||
$rating += $review->rating; |
||||
} |
||||
|
||||
if ($rating == 0) { |
||||
$overallRating = 0; |
||||
} else { |
||||
$overallRating = number_format($rating / $totalReviews->count(), 2); |
||||
} |
||||
|
||||
return response()->json(floatval($overallRating), 200); |
||||
} catch (\Exception $e) { |
||||
return response()->json(['errors' => $e], 403); |
||||
} |
||||
} |
||||
|
||||
public function submit_review(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'delivery_man_id' => 'required', |
||||
'order_id' => 'required', |
||||
'comment' => 'required', |
||||
'rating' => 'required|numeric|max:5', |
||||
'attachment.*' => 'nullable|max:2048', |
||||
]); |
||||
|
||||
$dm = DeliveryMan::find($request->delivery_man_id); |
||||
if (isset($dm) == false) { |
||||
$validator->errors()->add('delivery_man_id', translate('messages.not_found')); |
||||
} |
||||
|
||||
if ($validator->errors()->count() > 0) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)], 403); |
||||
} |
||||
|
||||
$multi_review = DMReview::where(['delivery_man_id' => $request->delivery_man_id, 'user_id' => $request->user()->id, 'order_id'=>$request->order_id])->first(); |
||||
if (isset($multi_review)) { |
||||
return response()->json([ |
||||
'errors' => [ |
||||
['code'=>'review','message'=> translate('messages.already_submitted')] |
||||
] |
||||
], 403); |
||||
} |
||||
|
||||
|
||||
$image_array = []; |
||||
if (!empty($request->file('attachment'))) { |
||||
foreach ($request->file('attachment') as $image) { |
||||
if ($image != null) { |
||||
if (!Storage::disk('public')->exists('review')) { |
||||
Storage::disk('public')->makeDirectory('review'); |
||||
} |
||||
array_push($image_array, Storage::disk('public')->put('review', $image)); |
||||
} |
||||
} |
||||
} |
||||
|
||||
$review = new DMReview(); |
||||
$review->user_id = $request->user()->id; |
||||
$review->delivery_man_id = $request->delivery_man_id; |
||||
$review->order_id = $request->order_id; |
||||
$review->comment = $request->comment; |
||||
$review->rating = $request->rating; |
||||
$review->attachment = json_encode($image_array); |
||||
$review->save(); |
||||
|
||||
return response()->json(['message' => translate('messages.review_submited_successfully')], 200); |
||||
} |
||||
} |
@ -0,0 +1,645 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Api\V1; |
||||
|
||||
ini_set('memory_limit', '-1'); |
||||
|
||||
use App\Models\Order; |
||||
use App\Models\Vehicle; |
||||
use App\Models\Shift; |
||||
use App\Models\DeliveryMan; |
||||
use App\Models\Notification; |
||||
use Illuminate\Http\Request; |
||||
use App\CentralLogics\Helpers; |
||||
use App\Models\BusinessSetting; |
||||
use App\Models\DeliveryHistory; |
||||
use App\Models\UserNotification; |
||||
use App\CentralLogics\OrderLogic; |
||||
use App\Models\DeliveryManWallet; |
||||
use Illuminate\Support\Facades\DB; |
||||
use App\Http\Controllers\Controller; |
||||
use Illuminate\Support\Facades\Config; |
||||
use Illuminate\Support\Facades\Storage; |
||||
use Illuminate\Support\Facades\Validator; |
||||
|
||||
// Carbon::setWeekStartsAt(Carbon::SUNDAY); |
||||
// Carbon::setWeekEndsAt(Carbon::SATURDAY); |
||||
|
||||
|
||||
class DeliverymanController extends Controller |
||||
{ |
||||
|
||||
public function get_profile(Request $request) |
||||
{ |
||||
$dm = DeliveryMan::with(['rating','userinfo','dm_shift'])->where(['auth_token' => $request['token']])->first(); |
||||
$dm['avg_rating'] = (double)(!empty($dm->rating[0])?$dm->rating[0]->average:0); |
||||
$dm['rating_count'] = (double)(!empty($dm->rating[0])?$dm->rating[0]->rating_count:0); |
||||
$dm['order_count'] =(integer)$dm->orders->count(); |
||||
$dm['todays_order_count'] =(integer)$dm->todaysorders->count(); |
||||
$dm['this_week_order_count'] =(integer)$dm->this_week_orders->count(); |
||||
$dm['member_since_days'] =(integer)$dm->created_at->diffInDays(); |
||||
$dm['cash_in_hands'] =$dm->wallet?$dm->wallet->collected_cash:0; |
||||
$dm['balance'] =$dm->wallet?$dm->wallet->total_earning - $dm->wallet->total_withdrawn:0; |
||||
$dm['todays_earning'] =(float)($dm->todays_earning()->sum('original_delivery_charge') + $dm->todays_earning()->sum('dm_tips')); |
||||
$dm['this_week_earning'] =(float)($dm->this_week_earning()->sum('original_delivery_charge') + $dm->this_week_earning()->sum('dm_tips')); |
||||
$dm['this_month_earning'] =(float)($dm->this_month_earning()->sum('original_delivery_charge') + $dm->this_month_earning()->sum('dm_tips')); |
||||
$dm['total_incentive_earning']= (float) ($dm->incentives()->where('status','approved')->sum('incentive')); |
||||
$dm['incentive_list']=$dm->zone ? $dm->zone->incentives : []; |
||||
$dm['shift_name']=$dm->dm_shift ? $dm->dm_shift->name : null; |
||||
$dm['shift_start_time']=$dm->dm_shift ? $dm->dm_shift->start_time : null; |
||||
$dm['shift_end_time']=$dm->dm_shift ? $dm->dm_shift->end_time : null; |
||||
unset($dm['dm_shift']); |
||||
unset($dm['zone']); |
||||
unset($dm['orders']); |
||||
unset($dm['rating']); |
||||
unset($dm['todaysorders']); |
||||
unset($dm['this_week_orders']); |
||||
unset($dm['wallet']); |
||||
return response()->json($dm, 200); |
||||
} |
||||
|
||||
public function update_profile(Request $request) |
||||
{ |
||||
$dm = DeliveryMan::with(['rating'])->where(['auth_token' => $request['token']])->first(); |
||||
$validator = Validator::make($request->all(), [ |
||||
'f_name' => 'required', |
||||
'l_name' => 'required', |
||||
'email' => 'required|unique:delivery_men,email,'.$dm->id, |
||||
'password'=>'nullable|min:6', |
||||
'image' => 'nullable|max:2048', |
||||
], [ |
||||
'f_name.required' => 'First name is required!', |
||||
'l_name.required' => 'Last name is required!', |
||||
]); |
||||
|
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)], 403); |
||||
} |
||||
|
||||
$image = $request->file('image'); |
||||
|
||||
if ($request->has('image')) { |
||||
$imageName = Helpers::update('delivery-man/', $dm->image, 'png', $request->file('image')); |
||||
} else { |
||||
$imageName = $dm->image; |
||||
} |
||||
|
||||
if ($request['password'] != null && strlen($request['password']) > 5) { |
||||
$pass = bcrypt($request['password']); |
||||
} else { |
||||
$pass = $dm->password; |
||||
} |
||||
|
||||
$dm->vehicle_id = $request->vehicle_id ?? $dm->vehicle_id ?? null; |
||||
|
||||
$dm->f_name = $request->f_name; |
||||
$dm->l_name = $request->l_name; |
||||
$dm->email = $request->email; |
||||
$dm->image = $imageName; |
||||
$dm->password = $pass; |
||||
$dm->updated_at = now(); |
||||
$dm->save(); |
||||
|
||||
if($dm->userinfo) { |
||||
$userinfo = $dm->userinfo; |
||||
$userinfo->f_name = $request->f_name; |
||||
$userinfo->l_name = $request->l_name; |
||||
$userinfo->email = $request->email; |
||||
$userinfo->image = $imageName; |
||||
$userinfo->save(); |
||||
} |
||||
return response()->json(['message' => 'successfully updated!'], 200); |
||||
} |
||||
|
||||
public function activeStatus(Request $request) |
||||
{ |
||||
$shift_id =$request->shift_id ?? Null; |
||||
$dm = DeliveryMan::with(['rating'])->where(['auth_token' => $request['token']])->first(); |
||||
$dm->active = $dm->active?0:1; |
||||
$dm->shift_id =$shift_id; |
||||
$dm->save(); |
||||
Helpers::set_time_log($dm->id, date('Y-m-d') , ($dm->active ? now() : null), ($dm->active ? null : now()) , $shift_id); |
||||
return response()->json(['message' => translate('messages.active_status_updated')], 200); |
||||
} |
||||
|
||||
public function get_current_orders(Request $request) |
||||
{ |
||||
$dm = DeliveryMan::where(['auth_token' => $request['token']])->first(); |
||||
$orders = Order::with(['customer', 'restaurant']) |
||||
->whereIn('order_status', ['accepted','confirmed','pending', 'processing', 'picked_up', 'handover']) |
||||
->where(['delivery_man_id' => $dm['id']]) |
||||
->orderBy('accepted') |
||||
->orderBy('schedule_at', 'desc') |
||||
->Notpos() |
||||
->get(); |
||||
$orders= Helpers::order_data_formatting($orders, true); |
||||
return response()->json($orders, 200); |
||||
} |
||||
|
||||
public function get_latest_orders(Request $request) |
||||
{ |
||||
$dm = DeliveryMan::where(['auth_token' => $request['token']])->first(); |
||||
|
||||
$orders = Order::with(['customer', 'restaurant']); |
||||
|
||||
if($dm->type == 'zone_wise') |
||||
{ |
||||
$orders = $orders |
||||
->whereHas('restaurant', function($q) use($dm){ |
||||
$q->where('restaurant_model','subscription')->where('zone_id', $dm->zone_id)->whereHas('restaurant_sub', function($q1){ |
||||
$q1->where('self_delivery', 0); |
||||
}); |
||||
}) |
||||
->orWhereHas('restaurant', function($qu) use($dm) { |
||||
$qu->where('restaurant_model','commission')->where('zone_id', $dm->zone_id)->where('self_delivery_system', 0); |
||||
}); |
||||
} |
||||
else |
||||
{ |
||||
$orders = $orders->where('restaurant_id', $dm->restaurant_id); |
||||
} |
||||
|
||||
if(config('order_confirmation_model') == 'deliveryman' && $dm->type == 'zone_wise') |
||||
{ |
||||
$orders = $orders->whereIn('order_status', ['pending', 'confirmed','processing','handover']); |
||||
} |
||||
else |
||||
{ |
||||
$orders = $orders->where(function($query){ |
||||
$query->where(function($query){ |
||||
$query->where('order_status', 'pending')->whereNotNull('subscription_id'); |
||||
})->orWhereIn('order_status', ['confirmed','processing','handover']); |
||||
}); |
||||
} |
||||
|
||||
if(isset($dm->vehicle_id )){ |
||||
$orders = $orders->where('vehicle_id',$dm->vehicle_id); |
||||
} |
||||
// else{ |
||||
// $orders = $orders->whereNull('vehicle_id'); |
||||
// } |
||||
$orders = $orders->delivery() |
||||
->OrderScheduledIn(30) |
||||
// ->hasSubscriptionToday() |
||||
->whereNull('delivery_man_id') |
||||
->orderBy('schedule_at', 'desc') |
||||
->Notpos() |
||||
->get(); |
||||
$orders= Helpers::order_data_formatting($orders, true); |
||||
return response()->json($orders, 200); |
||||
} |
||||
|
||||
public function accept_order(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'order_id' => 'required|exists:orders,id', |
||||
]); |
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)], 403); |
||||
} |
||||
$dm=DeliveryMan::where(['auth_token' => $request['token']])->first(); |
||||
$order = Order::where('id', $request['order_id']) |
||||
// ->whereIn('order_status', ['pending', 'confirmed']) |
||||
->whereNull('delivery_man_id') |
||||
->Notpos() |
||||
->first(); |
||||
if(!$order) |
||||
{ |
||||
return response()->json([ |
||||
'errors' => [ |
||||
['code' => 'order', 'message' => translate('messages.can_not_accept')] |
||||
] |
||||
], 404); |
||||
} |
||||
if($dm->current_orders >= config('dm_maximum_orders')) |
||||
{ |
||||
return response()->json([ |
||||
'errors'=>[ |
||||
['code' => 'dm_maximum_order_exceed', 'message'=> translate('messages.dm_maximum_order_exceed_warning')] |
||||
] |
||||
], 405); |
||||
} |
||||
|
||||
$cash_in_hand = isset($dm->wallet) ? $dm->wallet->collected_cash : 0; |
||||
|
||||
$dm_max_cash=BusinessSetting::where('key','dm_max_cash_in_hand')->first(); |
||||
|
||||
$value= $dm_max_cash ? $dm_max_cash->value : 0; |
||||
|
||||
if($order->payment_method == "cash_on_delivery" && (($cash_in_hand+$order->order_amount) >= $value)){ |
||||
return response()->json(['errors' => Helpers::error_formater('dm_max_cash_in_hand',translate('delivery man max cash in hand exceeds'))], 203); |
||||
} |
||||
|
||||
$order->order_status = in_array($order->order_status, ['pending', 'confirmed'])?'accepted':$order->order_status; |
||||
$order->delivery_man_id = $dm->id; |
||||
$order->accepted = now(); |
||||
$order->save(); |
||||
|
||||
$dm->current_orders = $dm->current_orders+1; |
||||
$dm->save(); |
||||
|
||||
$dm->increment('assigned_order_count'); |
||||
|
||||
$fcm_token=$order->customer->cm_firebase_token; |
||||
|
||||
$value = Helpers::order_status_update_message('accepted'); |
||||
OrderLogic::update_subscription_log($order); |
||||
try { |
||||
if($value) |
||||
{ |
||||
$data = [ |
||||
'title' =>translate('messages.order_push_title'), |
||||
'description' => $value, |
||||
'order_id' => $order['id'], |
||||
'image' => '', |
||||
'type'=> 'order_status' |
||||
]; |
||||
Helpers::send_push_notif_to_device($fcm_token, $data); |
||||
} |
||||
|
||||
} catch (\Exception $e) { |
||||
|
||||
} |
||||
|
||||
return response()->json(['message' => 'Order accepted successfully'], 200); |
||||
|
||||
} |
||||
|
||||
public function record_location_data(Request $request) |
||||
{ |
||||
$dm = DeliveryMan::where(['auth_token' => $request['token']])->first(); |
||||
DB::table('delivery_histories')->insert([ |
||||
'delivery_man_id' => $dm['id'], |
||||
'longitude' => $request['longitude'], |
||||
'latitude' => $request['latitude'], |
||||
'time' => now(), |
||||
'location' => $request['location'], |
||||
'created_at' => now(), |
||||
'updated_at' => now() |
||||
]); |
||||
return response()->json(['message' => 'location recorded'], 200); |
||||
} |
||||
|
||||
public function get_order_history(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'order_id' => 'required' |
||||
]); |
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)], 403); |
||||
} |
||||
$dm = DeliveryMan::where(['auth_token' => $request['token']])->first(); |
||||
|
||||
$history = DeliveryHistory::where(['order_id' => $request['order_id'], 'delivery_man_id' => $dm['id']])->get(); |
||||
return response()->json($history, 200); |
||||
} |
||||
|
||||
public function update_order_status(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'order_id' => 'required', |
||||
'status' => 'required|in:confirmed,canceled,picked_up,delivered', |
||||
'reason' =>'required_if:status,canceled', |
||||
]); |
||||
|
||||
$validator->sometimes('otp', 'required', function ($request) { |
||||
return (Config::get('order_delivery_verification')==1 && $request['status']=='delivered'); |
||||
}); |
||||
|
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)], 403); |
||||
} |
||||
$dm = DeliveryMan::where(['auth_token' => $request['token']])->first(); |
||||
$order = Order::where('id', $request['order_id'])->first(); |
||||
if(!isset($order)){ |
||||
return response()->json([ |
||||
'errors' => [ |
||||
['code' => 'order-not-found', 'message' => translate('messages.order_not_found')] |
||||
] |
||||
], 403); |
||||
} |
||||
|
||||
if($request['status'] =="confirmed" && config('order_confirmation_model') == 'restaurant') |
||||
{ |
||||
return response()->json([ |
||||
'errors' => [ |
||||
['code' => 'order-confirmation-model', 'message' => translate('messages.order_confirmation_warning')] |
||||
] |
||||
], 403); |
||||
} |
||||
|
||||
if($request['status'] == 'canceled' && !config('canceled_by_deliveryman')) |
||||
{ |
||||
return response()->json([ |
||||
'errors' => [ |
||||
['code' => 'status', 'message' => translate('messages.you_can_not_cancel_a_order')] |
||||
] |
||||
], 403); |
||||
} |
||||
|
||||
if(isset($order->confirmed ) && $request['status'] == 'canceled') |
||||
{ |
||||
return response()->json([ |
||||
'errors' => [ |
||||
['code' => 'delivery-man', 'message' => translate('messages.order_can_not_cancle_after_confirm')] |
||||
] |
||||
], 403); |
||||
} |
||||
|
||||
if(Config::get('order_delivery_verification')==1 && $request['status']=='delivered' && $order->otp != $request['otp']) |
||||
{ |
||||
return response()->json([ |
||||
'errors' => [ |
||||
['code' => 'otp', 'message' => 'Not matched'] |
||||
] |
||||
], 406); |
||||
} |
||||
if ($request->status == 'delivered' || isset($order->subscription_id)) |
||||
{ |
||||
if($order->transaction == null) |
||||
{ |
||||
$reveived_by = $order->payment_method == 'cash_on_delivery'?($dm->type != 'zone_wise'?'restaurant':'deliveryman'):'admin'; |
||||
|
||||
if(OrderLogic::create_transaction($order,$reveived_by, null)) |
||||
{ |
||||
$order->payment_status = 'paid'; |
||||
} |
||||
else |
||||
{ |
||||
return response()->json([ |
||||
'errors' => [ |
||||
['code' => 'error', 'message' => translate('messages.faield_to_create_order_transaction')] |
||||
] |
||||
], 406); |
||||
} |
||||
} |
||||
if($order->transaction) |
||||
{ |
||||
$order->transaction->update(['delivery_man_id'=>$dm->id]); |
||||
} |
||||
|
||||
$order->details->each(function($item, $key){ |
||||
if($item->food) |
||||
{ |
||||
$item->food->increment('order_count'); |
||||
} |
||||
}); |
||||
$order->customer ? $order->customer->increment('order_count') : ''; |
||||
|
||||
$dm->current_orders = $dm->current_orders>1?$dm->current_orders-1:0; |
||||
$dm->save(); |
||||
|
||||
$dm->increment('order_count'); |
||||
$order->restaurant->increment('order_count'); |
||||
|
||||
} |
||||
else if($request->status == 'canceled') |
||||
{ |
||||
if($order->delivery_man) |
||||
{ |
||||
$dm = $order->delivery_man; |
||||
$dm->current_orders = $dm->current_orders>1?$dm->current_orders-1:0; |
||||
$dm->save(); |
||||
} |
||||
|
||||
|
||||
if(!isset($order->confirmed) && isset($order->subscription_id)){ |
||||
$order->subscription()->update(['status' => 'canceled']); |
||||
if($order->subscription->log){ |
||||
$order->subscription->log()->update([ |
||||
'order_status' => $request->status, |
||||
'canceled' => now(), |
||||
]); |
||||
} |
||||
} |
||||
|
||||
$order->cancellation_reason = $request->reason; |
||||
$order->canceled_by = 'deliveryman'; |
||||
} |
||||
|
||||
if($request->status == 'confirmed' && $order->delivery_man_id == null){ |
||||
$order->delivery_man_id = $dm->id; |
||||
} |
||||
// dd($request['status']); |
||||
$order->order_status = $request['status']; |
||||
$order[$request['status']] = now(); |
||||
$order->save(); |
||||
try { |
||||
Helpers::send_order_notification($order); |
||||
} catch (\Exception $th) { |
||||
info($th); |
||||
} |
||||
|
||||
OrderLogic::update_subscription_log($order); |
||||
return response()->json(['message' => 'Status updated'], 200); |
||||
} |
||||
|
||||
public function get_order_details(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'order_id' => 'required' |
||||
]); |
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)], 403); |
||||
} |
||||
// OrderLogic::create_subscription_log($request->order_id); |
||||
$dm = DeliveryMan::where(['auth_token' => $request['token']])->first(); |
||||
$order = Order::with(['details'])->where('id',$request['order_id'])->where(function($query) use($dm){ |
||||
$query->whereNull('delivery_man_id') |
||||
->orWhere('delivery_man_id', $dm['id']); |
||||
})->Notpos()->first(); |
||||
if(!$order) |
||||
{ |
||||
return response()->json([ |
||||
'errors' => [ |
||||
['code' => 'order', 'message' => translate('messages.not_found')] |
||||
] |
||||
], 404); |
||||
} |
||||
$details = Helpers::order_details_data_formatting($order->details); |
||||
return response()->json($details, 200); |
||||
} |
||||
|
||||
public function get_order(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'order_id' => 'required' |
||||
]); |
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)], 403); |
||||
} |
||||
$dm = DeliveryMan::where(['auth_token' => $request['token']])->first(); |
||||
|
||||
$order = Order::with(['customer', 'restaurant','details'])->where(['delivery_man_id' => $dm['id'], 'id' => $request['order_id']])->Notpos()->first(); |
||||
if(!$order) |
||||
{ |
||||
return response()->json([ |
||||
'errors' => [ |
||||
['code' => 'order', 'message' => translate('messages.not_found')] |
||||
] |
||||
], 204); |
||||
} |
||||
return response()->json(Helpers::order_data_formatting($order), 200); |
||||
} |
||||
|
||||
public function get_all_orders(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'limit' => 'required', |
||||
'offset' => 'required', |
||||
]); |
||||
|
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)], 403); |
||||
} |
||||
|
||||
$dm = DeliveryMan::where(['auth_token' => $request['token']])->first(); |
||||
|
||||
$paginator = Order::with(['customer', 'restaurant']) |
||||
->where(['delivery_man_id' => $dm['id']]) |
||||
->whereIn('order_status', ['delivered','canceled','refund_requested','refunded','refund_request_canceled','failed']) |
||||
->HasSubscriptionInStatus(['delivered','canceled','refund_requested','refunded','refund_request_canceled','failed']) |
||||
->orderBy('schedule_at', 'desc') |
||||
->Notpos() |
||||
->paginate($request['limit'], ['*'], 'page', $request['offset']); |
||||
$orders= Helpers::order_data_formatting($paginator->items(), true); |
||||
$data = [ |
||||
'total_size' => $paginator->total(), |
||||
'limit' => $request['limit'], |
||||
'offset' => $request['offset'], |
||||
'orders' => $orders |
||||
]; |
||||
return response()->json($data, 200); |
||||
} |
||||
|
||||
public function get_last_location(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'order_id' => 'required' |
||||
]); |
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)], 403); |
||||
} |
||||
|
||||
$last_data = DeliveryHistory::whereHas('delivery_man.orders', function($query) use($request){ |
||||
return $query->where('id',$request->order_id); |
||||
})->latest()->first(); |
||||
return response()->json($last_data, 200); |
||||
} |
||||
|
||||
public function order_payment_status_update(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'order_id' => 'required', |
||||
'status' => 'required|in:paid' |
||||
]); |
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)], 403); |
||||
} |
||||
|
||||
$dm = DeliveryMan::where(['auth_token' => $request['token']])->first(); |
||||
|
||||
if (Order::where(['delivery_man_id' => $dm['id'], 'id' => $request['order_id']])->Notpos()->first()) { |
||||
Order::where(['delivery_man_id' => $dm['id'], 'id' => $request['order_id']])->update([ |
||||
'payment_status' => $request['status'] |
||||
]); |
||||
return response()->json(['message' => 'Payment status updated'], 200); |
||||
} |
||||
return response()->json([ |
||||
'errors' => [ |
||||
['code' => 'order', 'message' => 'not found!'] |
||||
] |
||||
], 404); |
||||
} |
||||
|
||||
public function update_fcm_token(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'fcm_token' => 'required' |
||||
]); |
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)], 403); |
||||
} |
||||
$dm = DeliveryMan::where(['auth_token' => $request['token']])->first(); |
||||
|
||||
DeliveryMan::where(['id' => $dm['id']])->update([ |
||||
'fcm_token' => $request['fcm_token'] |
||||
]); |
||||
|
||||
return response()->json(['message'=>'successfully updated!'], 200); |
||||
} |
||||
|
||||
public function get_notifications(Request $request){ |
||||
|
||||
$dm = DeliveryMan::where(['auth_token' => $request['token']])->first(); |
||||
|
||||
$notifications = Notification::active()->where(function($q) use($dm){ |
||||
$q->whereNull('zone_id')->orWhere('zone_id', $dm->zone_id); |
||||
})->where('tergat', 'deliveryman')->where('created_at', '>=', \Carbon\Carbon::today()->subDays(7))->get(); |
||||
|
||||
$user_notifications = UserNotification::where('delivery_man_id', $dm->id)->where('created_at', '>=', \Carbon\Carbon::today()->subDays(7))->get(); |
||||
|
||||
$notifications->append('data'); |
||||
|
||||
$notifications = $notifications->merge($user_notifications); |
||||
try { |
||||
return response()->json($notifications, 200); |
||||
} catch (\Exception $e) { |
||||
return response()->json([], 200); |
||||
} |
||||
} |
||||
|
||||
public function remove_account(Request $request) |
||||
{ |
||||
$dm = DeliveryMan::where(['auth_token' => $request['token']])->first(); |
||||
|
||||
if(Order::where('delivery_man_id', $dm->id)->whereIn('order_status', ['pending','accepted','confirmed','processing','handover','picked_up'])->count()) |
||||
{ |
||||
return response()->json(['errors'=>[['code'=>'on-going', 'message'=>translate('messages.user_account_delete_warning')]]],203); |
||||
} |
||||
|
||||
if($dm->wallet && $dm->wallet->collected_cash > 0) |
||||
{ |
||||
return response()->json(['errors'=>[['code'=>'on-going', 'message'=>translate('messages.user_account_wallet_delete_warning')]]],203); |
||||
} |
||||
|
||||
if (Storage::disk('public')->exists('delivery-man/' . $dm['image'])) { |
||||
Storage::disk('public')->delete('delivery-man/' . $dm['image']); |
||||
} |
||||
|
||||
foreach (json_decode($dm['identity_image'], true) as $img) { |
||||
if (Storage::disk('public')->exists('delivery-man/' . $img)) { |
||||
Storage::disk('public')->delete('delivery-man/' . $img); |
||||
} |
||||
} |
||||
if($dm->userinfo){ |
||||
$dm->userinfo->delete(); |
||||
} |
||||
|
||||
$dm->delete(); |
||||
return response()->json([]); |
||||
} |
||||
|
||||
|
||||
|
||||
public function dm_shift(Request $request){ |
||||
$shift= Shift::where('status',1) |
||||
->latest() |
||||
->get(); |
||||
return response()->json($shift, 200); |
||||
} |
||||
// public function assign_vehicle(Request $request){ |
||||
// $validator = Validator::make($request->all(), [ |
||||
// 'vehicle_id' => 'required', |
||||
// ]); |
||||
// if ($validator->fails()) { |
||||
// return response()->json(['errors' => Helpers::error_processor($validator)], 403); |
||||
// } |
||||
|
||||
// $dm = DeliveryMan::where(['auth_token' => $request['token']])->first(); |
||||
// $dm->vehicle_id = $request['vehicle_id']; |
||||
// $dm->save(); |
||||
// return response()->json(['message'=>'successfully updated!'], 200); |
||||
// } |
||||
|
||||
} |
@ -0,0 +1,67 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Api\V1; |
||||
|
||||
use App\CentralLogics\CustomerLogic; |
||||
use App\CentralLogics\Helpers; |
||||
use App\Http\Controllers\Controller; |
||||
use App\Models\BusinessSetting; |
||||
use App\Models\LoyaltyPointTransaction; |
||||
use Illuminate\Support\Facades\Validator; |
||||
use Illuminate\Http\Request; |
||||
use Illuminate\Support\Facades\Mail; |
||||
|
||||
class LoyaltyPointController extends Controller |
||||
{ |
||||
public function point_transfer(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'point' => 'required|integer|min:1' |
||||
]); |
||||
|
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)], 403); |
||||
} |
||||
|
||||
if($request->user()->loyalty_point <= 0 || $request->user()->loyalty_point < (int)BusinessSetting::where('key','loyalty_point_minimum_point')->first()->value || $request->point > $request->user()->loyalty_point) { |
||||
return response()->json(['errors' => [ ['code' => 'point', 'message' => trans('messages.insufficient_point')]]], 203); |
||||
} |
||||
|
||||
try |
||||
{ |
||||
$wallet_transaction = CustomerLogic::create_wallet_transaction($request->user()->id,$request->point,'loyalty_point',$request->reference); |
||||
CustomerLogic::create_loyalty_point_transaction($request->user()->id, $wallet_transaction->transaction_id, $request->point, 'point_to_wallet'); |
||||
if(config('mail.status')) { |
||||
Mail::to($request->user()->email)->send(new \App\Mail\AddFundToWallet($wallet_transaction)); |
||||
} |
||||
|
||||
return response()->json(['message' => translate('messages.point_to_wallet_transfer_successfully')], 200); |
||||
}catch(\Exception $ex){ |
||||
info($ex); |
||||
} |
||||
|
||||
return response()->json(['errors' => [ ['code' => 'customer_wallet', 'message' => translate('messages.failed_to_transfer')]]], 203); |
||||
} |
||||
|
||||
public function transactions(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'limit' => 'required', |
||||
'offset' => 'required', |
||||
]); |
||||
|
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)], 403); |
||||
} |
||||
|
||||
$paginator = LoyaltyPointTransaction::where('user_id', $request->user()->id)->latest()->paginate($request->limit, ['*'], 'page', $request->offset); |
||||
|
||||
$data = [ |
||||
'total_size' => $paginator->total(), |
||||
'limit' => $request->limit, |
||||
'offset' => $request->offset, |
||||
'data' => $paginator->items() |
||||
]; |
||||
return response()->json($data, 200); |
||||
} |
||||
} |
@ -0,0 +1,31 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Api\V1; |
||||
|
||||
use App\CentralLogics\Helpers; |
||||
use App\Http\Controllers\Controller; |
||||
use App\Models\Newsletter; |
||||
use Illuminate\Http\Request; |
||||
use Illuminate\Support\Facades\Validator; |
||||
|
||||
class NewsletterController extends Controller |
||||
{ |
||||
// Save newsLetterSubscribe email |
||||
public function index(Request $request) |
||||
{ |
||||
$validator = Validator::make($request->all(), [ |
||||
'email'=>'required|email|unique:newsletters,email', |
||||
]); |
||||
|
||||
if ($validator->fails()) { |
||||
return response()->json(['errors' => Helpers::error_processor($validator)], 403); |
||||
} |
||||
|
||||
Newsletter::create(['email'=>$request->email]); |
||||
|
||||
return response()->json(['message'=>translate('messages.subscription_successful')],200); |
||||
|
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,38 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Api\V1; |
||||
|
||||
use App\Http\Controllers\Controller; |
||||
use App\Models\Notification; |
||||
use App\Models\UserNotification; |
||||
use Illuminate\Http\Request; |
||||
use App\CentralLogics\Helpers; |
||||
|
||||
class NotificationController extends Controller |
||||
{ |
||||
public function get_notifications(Request $request){ |
||||
|
||||
if (!$request->hasHeader('zoneId')) { |
||||
$errors = []; |
||||
array_push($errors, ['code' => 'zoneId', 'message' => 'Zone id is required!']); |
||||
return response()->json([ |
||||
'errors' => $errors |
||||
], 403); |
||||
} |
||||
$zone_id= json_decode($request->header('zoneId'), true); |
||||
try { |
||||
$notifications = Notification::active()->where('tergat', 'customer')->where(function($q)use($zone_id){ |
||||
$q->whereNull('zone_id')->orWhereIn('zone_id', $zone_id); |
||||
})->where('created_at', '>=', \Carbon\Carbon::today()->subDays(15))->get(); |
||||
$notifications->append('data'); |
||||
|
||||
$user_notifications = UserNotification::where('user_id', $request->user()->id)->where('created_at', '>=', \Carbon\Carbon::today()->subDays(15))->get(); |
||||
$notifications = $notifications->merge($user_notifications); |
||||
return response()->json($notifications, 200); |
||||
} catch (\Exception $e) { |
||||
info(['Notification api issue_____',$e->getMessage()]); |
||||
return response()->json([], 200); |
||||
} |
||||
} |
||||
|
||||
} |
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue