NASER fix some issues
This commit is contained in:
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
@@ -0,0 +1,80 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use App\Models\Product;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
use App\Http\Controllers\Site\ReportController ;
|
||||||
|
|
||||||
|
// مدل محصول خود را ایمپورت کنید
|
||||||
|
|
||||||
|
class UpdateProductStatus extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* نام دستور که در زمانبندی استفاده میشود
|
||||||
|
*/
|
||||||
|
protected $signature = 'product:update-status';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* توضیحات دستور
|
||||||
|
*/
|
||||||
|
protected $description = 'Updates product prices and auto closes/opens products';
|
||||||
|
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
// منطق توابع خود را اینجا بیاورید
|
||||||
|
// اگر توابع در کلاس دیگری هستند، آن کلاس را صدا بزنید یا کد را اینجا کپی کنید
|
||||||
|
|
||||||
|
$this->info('Starting update...');
|
||||||
|
// \Illuminate\Support\Facades\Log::info("handle at: " . now());
|
||||||
|
|
||||||
|
// 1. Get Price Logic
|
||||||
|
|
||||||
|
$RPrices =Http::timeout(40)->get('http://212.23.201.173:8381/price_list', [])->json();
|
||||||
|
|
||||||
|
try{
|
||||||
|
$cooper =Http::timeout(40)->get('https://www.livedata.ir/main/static/p.json', [])->json();
|
||||||
|
if(isset($cooper['s_301006']) && isset($cooper['s_200103'])){
|
||||||
|
$CP = (($cooper['s_301006']/1000000)*$cooper['s_200103'])*10;
|
||||||
|
// Cnt::where('key', 'cu_price')
|
||||||
|
}
|
||||||
|
}catch (\Exception $e){}
|
||||||
|
$products = Product::with([])->whereNotNull('reading_method')->get();
|
||||||
|
$current_time = now()->format('H:i:s');
|
||||||
|
|
||||||
|
foreach ($products as $product) {
|
||||||
|
foreach ($RPrices as $RPrice) {
|
||||||
|
$show = ($current_time >= $product->auto_open_at && $current_time <= $product->auto_close_at);
|
||||||
|
|
||||||
|
if ($product->reading_method == $RPrice['name']) {
|
||||||
|
$p = Product::where('id', $product->id)->update([
|
||||||
|
'price' => $RPrice['price'],
|
||||||
|
'price_profit' => $RPrice['profit'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
if($product->bubble== 1){
|
||||||
|
$ReportController = new ReportController();
|
||||||
|
$liquidGold= $ReportController->lastPrice();
|
||||||
|
$p = Product::find($product->id);
|
||||||
|
|
||||||
|
$p->amount = $RPrice['price'] / $liquidGold['price'];
|
||||||
|
$p->show = $show;
|
||||||
|
$p->save();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if($product->reading_method == 'مس' && $CP){
|
||||||
|
$p = Product::where('id', $product->id)->update([
|
||||||
|
'price' => $CP,
|
||||||
|
'show' => $show,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 2. Auto Close/Open Logic
|
||||||
|
// $this->auto_close_open(); -> کد داخل این تابع را اینجا قرار دهید
|
||||||
|
// \Illuminate\Support\Facades\Log::info("handle end at: " . now());
|
||||||
|
|
||||||
|
$this->info('Product statuses updated successfully.');
|
||||||
|
}
|
||||||
|
}
|
||||||
Executable → Regular
+14
@@ -20,6 +20,20 @@ class Kernel extends ConsoleKernel
|
|||||||
protected function schedule(Schedule $schedule)
|
protected function schedule(Schedule $schedule)
|
||||||
{
|
{
|
||||||
// $schedule->command('inspire')->hourly();
|
// $schedule->command('inspire')->hourly();
|
||||||
|
$schedule->call(function () {
|
||||||
|
// حلقه برای اجرای 6 بار در یک دقیقه (هر 10 ثانیه)
|
||||||
|
for ($i = 0; $i < 6; $i++) {
|
||||||
|
// \Illuminate\Support\Facades\Log::info("Update process ran at: " . now());
|
||||||
|
|
||||||
|
// فراخوانی کامند ما
|
||||||
|
\Illuminate\Support\Facades\Artisan::call('product:update-status');
|
||||||
|
|
||||||
|
// 10 ثانیه صبر کن (به جز دور آخر که نیاز نیست اسکریپت باز بماند)
|
||||||
|
if ($i < 5) {
|
||||||
|
sleep(10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})->everyMinute()->name('update_products_every_20s')->withoutOverlapping();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
@@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Admin;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Models\File;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
|
||||||
|
class FileController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* make directory in Public Storage By Date
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function createDir()
|
||||||
|
{
|
||||||
|
$now = Verta();
|
||||||
|
$path = preg_replace('/-/', '/', $now->formatDate());
|
||||||
|
if (!Storage::exists($path)) {
|
||||||
|
Storage::makeDirectory($path);
|
||||||
|
Storage::makeDirectory($path . '/' . 'thumb');
|
||||||
|
}
|
||||||
|
return $path;
|
||||||
|
}
|
||||||
|
public function store(Request $request)
|
||||||
|
{
|
||||||
|
// Store FIle in Public Storage By Date
|
||||||
|
// Date Sample is : <Year>/<Month>/<Day> of today
|
||||||
|
|
||||||
|
$data = $request->all();
|
||||||
|
$path = $this->createDir();
|
||||||
|
$data['original_name'] = $request->file('file')->getClientOriginalName();
|
||||||
|
$data['ext'] = $request->file('file')->getClientOriginalExtension();
|
||||||
|
if (!isset($data['title']) || is_null($data['title'])) {
|
||||||
|
$data['title'] = $data['original_name'];
|
||||||
|
}
|
||||||
|
$file_name_src = md5(time() . $data['original_name']);
|
||||||
|
$file_name = $file_name_src . '.' . $data['ext'];
|
||||||
|
$file = $request->file('file');
|
||||||
|
$data['has_thumb'] = false;
|
||||||
|
$data['size'] = $file->getSize();
|
||||||
|
$file->move(public_path('storage/' . $path . '/'), $file_name);
|
||||||
|
$data['src'] = 'storage/' . $path . '/' . $file_name;
|
||||||
|
// $data['size'] = $file->getSize();
|
||||||
|
$data['user_id'] = auth()->id();
|
||||||
|
$data['sts'] = 1;
|
||||||
|
$file_create = File::create($data);
|
||||||
|
return response()->json($file_create);
|
||||||
|
}
|
||||||
|
}
|
||||||
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
+17
-2
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Admin;
|
|||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Http\Controllers\SuperController;
|
use App\Http\Controllers\SuperController;
|
||||||
|
use App\Models\Cnt;
|
||||||
use App\Models\Product;
|
use App\Models\Product;
|
||||||
use App\DB\Te\TableEngine;
|
use App\DB\Te\TableEngine;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
@@ -116,8 +117,8 @@ class ProductController extends SuperController
|
|||||||
|
|
||||||
public function listProduct()
|
public function listProduct()
|
||||||
{
|
{
|
||||||
$this->getPrice();
|
// $this->getPrice();
|
||||||
$this->auto_close_open();
|
// $this->auto_close_open();
|
||||||
$product = Product::with([])->where('active', 1)->get();
|
$product = Product::with([])->where('active', 1)->get();
|
||||||
return response()->json($product);
|
return response()->json($product);
|
||||||
}
|
}
|
||||||
@@ -126,8 +127,17 @@ class ProductController extends SuperController
|
|||||||
{
|
{
|
||||||
// $RPrices = Http::get('https://pricing.liman.gold/pricingApi', [])->json();
|
// $RPrices = Http::get('https://pricing.liman.gold/pricingApi', [])->json();
|
||||||
// $RPrices = Http::get('https://pricing.liman.gold/pricingApi', [])->json();
|
// $RPrices = Http::get('https://pricing.liman.gold/pricingApi', [])->json();
|
||||||
|
|
||||||
$RPrices =Http::timeout(40)->get('http://212.23.201.173:8381/price_list', [])->json();
|
$RPrices =Http::timeout(40)->get('http://212.23.201.173:8381/price_list', [])->json();
|
||||||
|
|
||||||
|
try{
|
||||||
|
$cooper =Http::timeout(40)->get('https://www.livedata.ir/main/static/p.json', [])->json();
|
||||||
|
if(isset($cooper['s_301006']) && isset($cooper['s_200103'])){
|
||||||
|
$CP = (($cooper['s_301006']/1000000)*$cooper['s_200103'])*10;
|
||||||
|
// Cnt::where('key', 'cu_price')
|
||||||
|
}
|
||||||
|
}catch (\Exception $e){}
|
||||||
|
|
||||||
$products = Product::with([])->whereNotNull('reading_method')->get();
|
$products = Product::with([])->whereNotNull('reading_method')->get();
|
||||||
foreach ($products as $product) {
|
foreach ($products as $product) {
|
||||||
foreach ($RPrices as $RPrice) {
|
foreach ($RPrices as $RPrice) {
|
||||||
@@ -146,6 +156,11 @@ class ProductController extends SuperController
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if($product->reading_method == 'مس' && $CP){
|
||||||
|
$p = Product::where('id', $product->id)->update([
|
||||||
|
'price' => $CP,
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return response()->json(true);
|
return response()->json(true);
|
||||||
|
|||||||
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
+2
-2
@@ -83,8 +83,8 @@ class AuthController extends Controller
|
|||||||
$user->token_sms = $rand;
|
$user->token_sms = $rand;
|
||||||
$user->save();
|
$user->save();
|
||||||
|
|
||||||
// $this->SendMessage($mobile, 'رمز عبور یکبار مصرف شما جهت ورود به اپلیکشن ' . $this->Config('name_fa') . ' ' . $rand . ' می باشد' . PHP_EOL . "@$subDomain" . " #" . $rand,true ,"sms");
|
// $this->SendMessage($mobile, 'رمز عبور یکبار مصرف شما جهت ورود به اپلیکشن ' . $this->Config('name_fa') . ' ' . $rand . ' می باشد' . PHP_EOL . "@$subDomain" . " #" . $r and,true ,"sms");
|
||||||
$this->SendMessage($mobile, 'رمز عبور یکبار مصرف شما جهت ورود به اپلیکشن ' . $this->Config('name_fa') . ' ' . $rand . ' می باشد' . PHP_EOL . "@samin.gold" . " #" . $rand,true ,"sms");
|
$this->SendMessage($mobile, 'رمز عبور یکبار مصرف شما جهت ورود به اپلیکشن ' . $this->Config('name_fa') . ' ' . $rand . ' می باشد' . PHP_EOL . "@goldsun.zaarbox.ir" . " #" . $rand,true ,"sms");
|
||||||
|
|
||||||
return $user->id;
|
return $user->id;
|
||||||
}
|
}
|
||||||
|
|||||||
Executable → Regular
+1
-1
@@ -72,7 +72,7 @@ class Controller extends BaseController
|
|||||||
|
|
||||||
"sms" => [
|
"sms" => [
|
||||||
'user_name' => 'ysms1362',
|
'user_name' => 'ysms1362',
|
||||||
'password' => '1234@Abcgh',
|
'password' => 'tL4w0PfNy2()',
|
||||||
'sender' => '3000164545',
|
'sender' => '3000164545',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|||||||
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
@@ -0,0 +1,91 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Site;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Http\Controllers\SuperController;
|
||||||
|
use App\Models\OfferCode;
|
||||||
|
use App\Models\Product;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class OfferCodesController extends SuperController
|
||||||
|
{
|
||||||
|
public function __construct(Request $request)
|
||||||
|
{
|
||||||
|
$model = OfferCode::class;
|
||||||
|
$this->with=[];
|
||||||
|
$select = ['*'];
|
||||||
|
$search=['name'];
|
||||||
|
$request->request->add(['customer_id'=>auth('customer')->id()]);
|
||||||
|
$query = OfferCode::with($this->with)->where('customer_id',auth('customer')->id());
|
||||||
|
parent::__construct($model, $this->with/*, $select, null,$query,$search*/);
|
||||||
|
}
|
||||||
|
public function store(Request $request)
|
||||||
|
{
|
||||||
|
$data = $request->all();
|
||||||
|
if (OfferCode::where('code',$data['code'])->first())
|
||||||
|
{
|
||||||
|
return response()->json(['message' => 'این کد تخفیف از قبل ثبت شده'], 422);
|
||||||
|
}
|
||||||
|
$user = OfferCode::create($data);
|
||||||
|
return $this->resultCreate($user->id);
|
||||||
|
}
|
||||||
|
public function check_code(Request $request)
|
||||||
|
{
|
||||||
|
$data = $request->all();
|
||||||
|
|
||||||
|
// Check if the code is provided
|
||||||
|
if (!isset($data['code'])) {
|
||||||
|
return response()->json(['message' => 'کد تخفیف اجباریه'], 422);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find the offer code, or return error if not found
|
||||||
|
if (!$OfferCode = OfferCode::where('code', $data['code'])->first()) {
|
||||||
|
return response()->json(['message' => 'کد تخفیف پیدا نشد'], 422);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if items are provided
|
||||||
|
if (!isset($data['items']) || !is_array($data['items'])) {
|
||||||
|
return response()->json(['message' => 'لیست محصولات اجباری است'], 422);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Retrieve products and apply discount
|
||||||
|
$select = ['*',
|
||||||
|
// Product::$SELECT_CAJ,
|
||||||
|
// Product::$SELECT_GENDER_STR,
|
||||||
|
];
|
||||||
|
$items = Product::with([
|
||||||
|
// 'collection',
|
||||||
|
'file',
|
||||||
|
// 'gallery.file',
|
||||||
|
// 'brand.image'
|
||||||
|
])->select($select)->whereIn('id',$data['items'])->get();
|
||||||
|
$i=0;
|
||||||
|
foreach ($items as $i => $row) {
|
||||||
|
// Apply percentage or fixed discount
|
||||||
|
if (!empty($OfferCode->discount_percent)) {
|
||||||
|
// Apply percentage discount
|
||||||
|
$newPrice = $row->price - ($row->price * $OfferCode->discount_percent / 100);
|
||||||
|
} else {
|
||||||
|
// Apply fixed price discount
|
||||||
|
$newPrice = $row->price - $OfferCode->discount_price;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure the discounted price doesn't go below zero
|
||||||
|
$newPrice = max(0, $newPrice);
|
||||||
|
|
||||||
|
// Update the price_with_discount field
|
||||||
|
$row->price_with_discount = $newPrice;
|
||||||
|
|
||||||
|
// Convert model to an array and assign the discounted values
|
||||||
|
$response[$i] = $row->toArray();
|
||||||
|
$response[$i]['price_with_discount'] = $newPrice;
|
||||||
|
$response[$i]['discount'] = $row->price - $newPrice;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Return the updated items with the discount applied
|
||||||
|
return response()->json($response);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
|
||||||
|
class File extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
use Selector;
|
||||||
|
protected $fillable = [
|
||||||
|
'original_name',
|
||||||
|
'title',
|
||||||
|
'ext',
|
||||||
|
'src',
|
||||||
|
'size',
|
||||||
|
'user_id',
|
||||||
|
'type',
|
||||||
|
'has_thumb',
|
||||||
|
'url',
|
||||||
|
];
|
||||||
|
protected $casts = [
|
||||||
|
"has_thumb"=>"boolean"
|
||||||
|
];
|
||||||
|
public function getSrcAttribute(){
|
||||||
|
return 'https://bazarsaat.com/kernel/'.$this->attributes['src'];
|
||||||
|
// return url($this->attributes['src']);
|
||||||
|
}
|
||||||
|
}
|
||||||
Executable → Regular
Executable → Regular
Executable → Regular
@@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
|
||||||
|
class OfferCode extends Model
|
||||||
|
{
|
||||||
|
use HasFactory,Selector,SoftDeletes;
|
||||||
|
protected $table='offer_codes';
|
||||||
|
protected $fillable=[
|
||||||
|
'code',
|
||||||
|
'title',
|
||||||
|
'description',
|
||||||
|
'start_at',
|
||||||
|
'end_at',
|
||||||
|
'type',
|
||||||
|
'discount_percent',
|
||||||
|
'discount_price',
|
||||||
|
'is_active',
|
||||||
|
'use_only',
|
||||||
|
'use_count'
|
||||||
|
];
|
||||||
|
static $TYPES = [
|
||||||
|
1=>"محصول",
|
||||||
|
2=>"دسته بندی",
|
||||||
|
3=>"مشتری",
|
||||||
|
4=>"برند",
|
||||||
|
5=>""
|
||||||
|
];
|
||||||
|
static $TYPE_CUSTOMER = [
|
||||||
|
1=>"تکی",
|
||||||
|
2=>"عمده",
|
||||||
|
];
|
||||||
|
protected $casts=[
|
||||||
|
'is_active' => 'boolean',
|
||||||
|
];
|
||||||
|
// public static function safeDelete($promotionID){
|
||||||
|
// Promotion::findOrFail($promotionID)->delete();
|
||||||
|
// PromotionItem::where('promotion_id',$promotionID)->delete();
|
||||||
|
// PromotionProduct::where('promotion_id',$promotionID)->delete();
|
||||||
|
// return true;
|
||||||
|
// }
|
||||||
|
|
||||||
|
}
|
||||||
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
+1
-1
@@ -70,7 +70,7 @@ class Product extends Model
|
|||||||
return $this->hasOne(Wallet::class)->where('owner',auth()->user()->id);
|
return $this->hasOne(Wallet::class)->where('owner',auth()->user()->id);
|
||||||
}
|
}
|
||||||
public function file(){
|
public function file(){
|
||||||
return $this->belongsTo(File::class);
|
return $this->belongsTo(File::class, 'original_image_id');
|
||||||
}
|
}
|
||||||
public function price(){
|
public function price(){
|
||||||
return $this->hasOne(Price::class)->orderBy('id','desc');
|
return $this->hasOne(Price::class)->orderBy('id','desc');
|
||||||
|
|||||||
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user