/
home
/
old_henza
/
server
/
app
/
Http
/
Controllers
/
Adm
/
File Upload :
llllll
Current File: /home/old_henza/server/app/Http/Controllers/Adm/AdminController.php
<?php namespace App\Http\Controllers\Adm; use App\DB\Te\TableEngine; use App\Http\Controllers\api\CustomerController; use App\Http\Controllers\Controller; use App\Jobs\PromotionAfterCreate; use App\Jobs\SendSmsAfterCreate; use App\Models\Major\Cash; use App\Models\Category; use App\Models\Collect; use App\Models\ConfigStatic; use App\Models\Customer; use App\Models\Major\Promotion; use App\Models\Major\PromotionItem; use App\Models\Notify; use App\Models\Order; use App\Models\OrderActivity; use App\Models\OrderItem; use App\Models\Permission; use App\Models\Product; use App\Models\ProductBrand; use App\Models\ProductImage; use App\Models\ProductTags; use App\Models\ProductVariant; use App\Models\RequestFashion; use App\Models\SingleCustomer; use App\Models\SingleCustomerOrders; use App\Models\SingleCustomerTransaction; use App\Models\Sms; use App\Models\TransactionOrder; use App\Models\User; use App\Models\Utility; use App\Models\WebServiceGold; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Log; use Carbon\Carbon; use Psy\Util\Json; use Ramsey\Collection\Collection; use Illuminate\Database\Eloquent\Builder; use Rooyesh\Wallet\interfaces\TransactionInterface; use Rooyesh\Wallet\interfaces\WalletInterface; class AdminController extends Controller { /** * AdminController constructor. */ public function __construct() { $this->middleware('auth', ['except' => ['generateReportOrder', 'createCustomer', 'login','generateReportDocument']]); } public function login(Request $request) { $this->validate($request, ['phone' => 'required', 'password' => 'required']); $user = User::where('mobile', $request->phone)->firstOrFail(); if (!Hash::check($request->password, $user->password)) { abort(422); } if ($user->api_token == null) { $user->api_token = \Illuminate\Support\Str::random(60); } if (isset($request->token_mobile)){ $user->token_mobile = $request->token_mobile; } $user->save(); $per = Permission::whereUt($user->ut)->get(); $user->roles = $per; return new JsonResponse($user); } /* public function getOrders(Request $request) { $records = Order::with(['items', 'customer','activity']) ->orderBy('id', 'DESC'); TableEngine::create($records,$request->all()) ->initSearch(['customer.name','customer.mobile']) ->select([ '*', Order::$SELECT_STS_STR, Order::$SELECT_TYPE_STR, Order::$SELECT_CAJ, ])->export($records); return response()->json($records); }*/ public function getProducts(Request $request) { $goldPrice = WebServiceGold::getPriceGold18Ayar(); ProductVariant::$goldPrice = $goldPrice; $count1 = 0; $count2 = 0; $count3 = 0; if (!is_null($request->search)){ $count1 = Product::where('show_type',1)->where('title','like','%'.$request->search.'%')->count(); $count2 = Product::where('show_type',2)->where('title','like','%'.$request->search.'%')->count(); $count3 = Product::where('show_type',3)->where('title','like','%'.$request->search.'%')->count(); } $records = Product::query(); if (!is_null(auth()->user()->branch_id)){ $records->where('branch_id',auth()->user()->branch_id); } $records->with(['promotion','thumb', 'variantsAll', 'tmobile', 'brand', 'category.collection', 'tags', 'file']); // if ($request->has('search')){ // $records->whereRaw('lower(`title`) like ?', ['%' . strtolower(trim($request->text)) . '%']); // } TableEngine::create($records, $request->all()) ->initSearch(['id', 'product_code', 'title', 'brand.title', 'category.collection.title']) ->select([ '*', Product::$SELECT_SHOW_TYPE_STR ])->export($records); $records['query']['gold_price'] = $goldPrice; $records['query']['count1'] = $count1; $records['query']['count2'] = $count2; $records['query']['count3'] = $count3; return response()->json($records); } public function queryCategory(Request $request) { $cat = Category::with(['image'])->select(['id', 'title' , Category::$SELECT_TYPE_STR]); /* if ($request->has('text_search') && !empty(trim($request->text_search))) { $cat->where('title', 'LIKE', '%' . $request->text_search . '%'); } $cat->limit(10);*/ return response()->json($cat->get()); } public function getCustomer(Request $request) { //old method /* $search='%'.( $request->search ?? '%').'%'; $records = Customer::select(array_merge(Customer::selectWithjDate(), [Customer::$SELECT_STS_STR, Customer::$SELECT_TYPE_STR])) ->with(['reagent', 'cash', 'order']) ->orderBy('id', 'DESC') ->where('type',2) ->Where(function ($q) use ($search){ $q ->Where('name','like',$search) ->orWhere('mobile','like',$search); }); $c = clone $records; return response()->json([ 'rows' => $records->limit($request->limit)->offset($request->limit * ($request->page - 1))->get(), 'query' => [ 'total' => $c->count(), 'limit' => $request->limit, 'page' => $request->page ] ]);*/ //new method $records = Customer::with(['reagent', 'cash', 'order', 'city']) ->where('type', 2); TableEngine::create($records, $request->all()) ->initSearch(['name', 'mobile']) ->select([ '*', Customer::$SELECT_CAJ, Customer::$SELECT_UAJ, Customer::$SELECT_STS_STR, Customer::$SELECT_TYPE_STR ])->export($records); $count = Customer::where('type', 2)->where('active',-1)->count(); $records['query']['count'] = $count; return response()->json($records); } public function getReagent(Request $request) { $records = Customer::with(['reagent', 'cash', 'order.items' , 'city']) ->orderBy('id', 'DESC') ->where('type', 1); TableEngine::create($records, $request->all()) ->initSearch(['name', 'mobile']) ->select([ '*', // Customer::selectWithjDate(), Customer::$SELECT_CAJ, Customer::$SELECT_UAJ, Customer::$SELECT_STS_STR, Customer::$SELECT_TYPE_STR, ])->export($records); $count = Customer::where('type', 1)->where('active',-1)->count(); $records['query']['count'] = $count; return response()->json($records); } public function getSingleCustomer(Request $request) { $records = SingleCustomer::with(['branch']); if (!is_null(auth()->user()->branch_id)){ $records->where('branch_id',auth()->user()->branch_id); } TableEngine::create($records, $request->all()) ->initSearch(['name']) ->select([ '*', ])->export($records); return response()->json($records); } public function createCustomer(Request $request) { //Log::info($request->all()); $customer = null; $request['mobile'] = Utility::faTOen($request['mobile']); $input = $request->all(); if (isset($request->from_reagent)) { $this->validate($request, [ 'mobile' => 'required|unique:customers', 'reagent' => 'required' ]); $reagent = Customer::where('mobile', $request['reagent'])->firstOrFail(); $input['reagent_id'] = $reagent->id; $input['name'] = $input['fname'] . ' ' . $input['lname']; $input['sts'] = 1; $input['type'] = 2; $input['city_id'] = $input['city_id'] ?? null; $input['mobile'] = Utility::faTOen($request['mobile']); $input['remain'] = 0; $input['grams_sell'] = 0; $input['rial_remain'] = 0; $input['count_login'] = 0; $input['gram_level'] = 100; $input['percent'] = 3; $input['active'] = 1; $customer = Customer::create($input); } else { $input['name'] = $input['fname'] . ' ' . $input['lname']; $input['city_id'] = $input['city_id'] ?? null; if ($input['id']) { $customer = Customer::findOrFail($input['id']); $input['mobile'] = $customer->mobile; $customer->update($input); } else { $this->validate($request, [ 'mobile' => 'required|unique:customers' ]); if ($request->has('reagent_id')) { $input['type'] = 2; } else { $input['type'] = 1; } $input['sts'] = 1; $input['city_id'] = $input['city_id'] ?? null; $input['remain'] = 0; $input['mobile'] = Utility::faTOen($request['mobile']); $input['grams_sell'] = 0; $input['count_login'] = 0; $input['rial_remain'] = 0; $customer = Customer::create($input); $customer->save(); } //$customer->password = $input['password']; //Sms::Send($customer->mobile , 'ثبت نام شما در هنزا با موفقیت انجام شد. رمز عبور شما :'.$input['password'].' می باشد.'); //.'رمز عبور : '.$input['password']."\n" } if (!isset($input['id'])) { Sms::Send($customer->mobile, 'هنزا گلد' . "\n" . 'جناب آقای ' . $input['fname'] . ' ' . $input['lname'] . "\n" . 'نام کاربری : ' . $input['mobile'] . "\n" // . 'لینک دانلود اپلیکشن اندروید: ' . "\n" // . 'https://henzagold.com/download/henza.apk' . "\n" // . "لینک جهت اپلیکشن آی او اس " . "\n" // . "https://henzagold.com/app"); . "لینک pwa " . "\n" . "https://app.henzagold.com"); $promotion = Promotion::find(17); if ($promotion && $promotion->is_active == true) { PromotionItem::create([ 'promotion_id' => 17, 'item_id' => $customer->id, ]); } SendSmsAfterCreate::dispatch($customer->mobile,'هنزا گلد' . "\n".'1') ->onConnection('database') ->delay(now()->addMonth()->subDays(3)); PromotionAfterCreate::dispatch($customer->id) ->onConnection('database') ->delay(now()->addMonth()); } return response()->json(true); } public function queryCustomer(Request $request) { $search = ($request->text_search != null) ? $request->text_search : '%'; $records = Customer::select(['id', 'name as title'])->where('name', 'LIKE', '%' . $search . '%'); return response()->json($records->get()); } public function queryReagent(Request $request) { //->where('name', 'LIKE', '%' . $request->text_search . '%'); $search = ($request->text_search != null) ? $request->text_search : '%'; $records = Customer::select(['id', 'name as title']) ->whereNull('reagent_id') ->Where('name', 'like', '%' . $search . '%'); return response()->json($records->get()); } public function customerToggleSts(Request $request) { Customer::findOrFail($request->id)->update(['sts' => $request->sts == 1 ? -1 : 1]); return response()->json(true); } public function customerToggleActive(Request $request) { $customer = Customer::findOrFail($request->id); $active = $customer->active; $customer->update([ 'active' => $customer->active == 1 ? -1 : 1, 'api_token' => null ]); if ($active == -1){ Sms::Send($customer->mobile, $customer->name.' عزیز '."\n". 'حساب كاربري شما در اپليكيشن هنزا فعال شد.'."\n". 'هم اكنون مي توانيد محصولات جديد را بررسي و ثبت سفارش كنيد.'."\n". 'با مراجعه به لینک زیر می توانید وارد پروفایل کاربری خود شوید.'."\n". 'https://henzagold.com/oapi/login'."\n". 'هنزا، راهكارهاي نوين تامين محصولات' ); } return response()->json(true); } /*public function setConfiremdDoc(Request $request) { $this->validate($request, [ 'id' => 'required' ]); $cash = Cash::findOrFail($request->id); $cash->update(['confirmed'=>1]); //$cash->save(); $customer=Customer::findOrFail($cash->customer_id); //Log::info("customer ".$customer_id); //$customer->decrement('remain',$cash->value); CustomerController::updateRemain($customer->id); Sms::Send($customer->mobile, 'هنزا گلد'."\n".'سند مالی شما توسط مدیر سیستم تایید شد.'); Notify::store($customer->token_mobile,'هنزاگلد','سند مالی شما توسط مدیر سیستم تایید شد.'); Notify::create([ 'title' => 'تاییدیه سند مالی', 'customer_id' => $cash->customer_id, 'note' => "سند مالی شما توسط مدیر سیستم تایید شد.", 'read' => false, 'value' => 1, 'type' => 1, ]); return response()->json(true); }*/ /*public function setGramForFinDoc(Request $request) { $this->validate($request, [ 'id' => 'required', 'gram'=>'required' ]); $cash = Cash::findOrFail($request->id); $cash->update(['confirmed'=>1]); $cash->update(['value'=>$request->gram]); CustomerController::updateRemain($cash->customer_id); //$customer=Customer::findOrFail($cash->customer_id); //$customer->decrement('remain',$request->gram); //$customer=Customer::findOrFail($cash->customer_id); //Sms::Send($customer->mobile, 'هنزا گلد'."\n".'سند مالی شما توسط مدیر سیستم تایید شد.'); Notify::create([ 'title' => 'تاییدیه سند مالی', 'customer_id' => $cash->customer_id, 'note' => "سند مالی شما توسط مدیر سیستم تایید شد.", 'read' => false, 'value' => 1, 'type' => 1, ]); //return response()->json(true); }*/ /*public function readSMS(Request $request) { $this->validate($request, [ 'FROM' => 'required', 'TO' => 'required', 'TEXT' => 'required' ]); //Log::info($request->all()); return response()->json(true); }*/ public function confiremOrder(Request $request) { $this->validate($request, [ 'cId' => 'required',//customer Id 'oId' => 'required',//Order Id ]); $customer = Customer::findOrFail($request->cId); Sms::Send($customer->mobile, 'هنزا گلد' . "\n" . 'سفارش شما با شماره سند ' . $request->oId . 'تایید شد.'); Notify::store($customer->token_mobile, 'هنزاگلد', 'سفارش شما با شماره سند ' . $request->oId . 'تایید شد.'); $order = Order::findOrFail($request->oId); //$customer->decrement('remain',$order->input); $order->confirmed = 1; $order->save(); //Log::info($request->all()); return response()->json(true); } public function getAnalytics() { $omdeAnalytics = []; $omdeAnalytics['customerCount'] = Customer::where('created_at', '>=', Carbon::now()->subDays(30))->count(); $omdeAnalytics['allgram'] = Utility::round(Order::where('created_at', '>=', Carbon::now()->subDays(30))->sum('w')); $omdeAnalytics['ordercount'] = Order::where('created_at', '>=', Carbon::now()->subDays(30))->count(); $omdeAnalytics['lastOrder'] = Order::select(array_merge(Order::selectWithjDate(), [Order::$SELECT_STS_STR]))->with(['customer', 'parent'])->orderBy('created_at', 'desc') ->take(5) ->get() ->toArray(); //[Order::$SELECT_STS_STR,Order::selectWithjDate()] $omdeAnalytics['sumLastOrderMonth'] = Utility::round(Order::where('created_at', '>=', Carbon::now()->subDays(30))->sum('w')); $omdeAnalytics['sumLastOrder2Month'] = Utility::round(Order::whereBetween('created_at', [Carbon::now()->subDays(60), Carbon::now()->subDays(30)])->sum('w')); $omdeAnalytics['sumLastOrder3Month'] = Utility::round(Order::whereBetween('created_at', [Carbon::now()->subDays(90), Carbon::now()->subDays(60)])->sum('w')); $omdeAnalytics['openOrder'] = Customer::sum('open_order'); //$omdeAnalytics['reagent']=Order::where('created_at','>=',Carbon::now()->subDays(30))->select(DB::raw('sum(w) as totalsell'),'reagent_id')->with(['parent'])->whereNotNull('reagent_id')->groupBy('reagent_id')->get()->toArray(); //$omdeAnalytics['reagent']= Order::where('created_at','>=',Carbon::now()->subDays(30))->select(DB::raw('sum(w) as totalsell'),'reagent_id')->with(['parent'])->whereNotNull('reagent_id')->groupBy('reagent_id')->get()->toArray(); $omdeAnalytics['reagent'] = Customer::whereNull('reagent_id')->with(['children' => function ($q) { return $q->select('reagent_id', DB::raw('sum(w) as totalsell'))->groupBy('reagent_id'); }])->get()->toArray(); //$omdeAnalytics['reagent']=Customer::whereNull('reagent_id').with(['parent']); return response()->json($omdeAnalytics); } public function getAnalyticsTak() { $analytics = []; //$omdeAnalytics['customerCount']=Customer::where('created_at','>=',Carbon::now()->subDays(30))->count(); //$omdeAnalytics['allgram']=Utility::round(Order::where('created_at','>=',Carbon::now()->subDays(30))->sum('w')); //$omdeAnalytics['ordercount']=Order::where('created_at','>=',Carbon::now()->subDays(30))->count(); $analytics['lastOrder'] = SingleCustomerOrders::select(array_merge(Order::selectWithjDate(), [Order::$SELECT_STS_STR]))->with(['customer'])->orderBy('created_at', 'desc') ->take(5) ->get() ->toArray(); //[Order::$SELECT_STS_STR,Order::selectWithjDate()] //$omdeAnalytics['sumLastOrderMonth']=Utility::round(Order::where('created_at','>=',Carbon::now()->subDays(30))->sum('w')); //$omdeAnalytics['sumLastOrder2Month']=Utility::round(Order::whereBetween('created_at',[Carbon::now()->subDays(60),Carbon::now()->subDays(30)])->sum('w')); //$omdeAnalytics['sumLastOrder3Month']=Utility::round(Order::whereBetween('created_at',[Carbon::now()->subDays(90),Carbon::now()->subDays(60)])->sum('w')); //$omdeAnalytics['openOrder']=Customer::sum('open_order'); //$omdeAnalytics['reagent']=Order::where('created_at','>=',Carbon::now()->subDays(30))->select(DB::raw('sum(w) as totalsell'),'reagent_id')->with(['parent'])->whereNotNull('reagent_id')->groupBy('reagent_id')->get()->toArray(); //$omdeAnalytics['reagent']= Order::where('created_at','>=',Carbon::now()->subDays(30))->select(DB::raw('sum(w) as totalsell'),'reagent_id')->with(['parent'])->whereNotNull('reagent_id')->groupBy('reagent_id')->get()->toArray(); /*$omdeAnalytics['reagent']=Customer::whereNull('reagent_id')->with(['children'=>function($q){ return $q->select('reagent_id',DB::raw('sum(w) as totalsell'))->groupBy('reagent_id'); }])->get()->toArray();*/ //$omdeAnalytics['reagent']=Customer::whereNull('reagent_id').with(['parent']); return response()->json($analytics); } /* public function setFinDoc(Request $request) { $this->validate($request,[ 'customer_id' => 'required', 'price' => 'required', 'value'=>'required' ]); $input=$request->all(); $input['type']=4; $input['title']='ثبت سند پولی'; $input['confirmed']=1; Cash::create($input); //Customer::findOrFail($input->customer_id)->decrement('remain',$input->value); CustomerController::updateRemain($input['customer_id']); return response()->json(true); }*/ public function addProduct(Request $request) { $this->validate($request, [ 'cats' => 'required|array', 'title' => 'required' ]); $input = $request->all(); $productId = $input['id'] ?? null; if ($productId) { /* update Product */ $product = Product::findOrFail($productId); $product->title = $input['title']; $product->body_html = $input['body_html'] ?? null; $product->desk_note = $input['desk_note'] ?? null; $product->product_code = $input['product_code'] ?? null; $product->indicator_id_id = $input['indicator_id'] ?? null; //$product->indicator_id_id=$input['indicator_id'] ?? $product->indicator_id_id; $product->mobile_pic_id = $input['mobile_pic'] ?? null; $product->brand_id = $input['brand_id'] ?? null; $product->show_type = $input['show_type'] ?? null; $product->delivery_type = $input['delivery_type'] ?? null; $product->file_id = $input['file_id'] ?? null;; $product->message_long_delivery = $input['message_long_delivery'] ?? null; $product->save(); ProductImage::where('product_id', $product->id)->forceDelete(); // $input['gallery'] = $input['images']; foreach ($input['gallery'] ?? [] as $item) { ProductImage::create([ 'image_id' => $item, 'product_id' => $product->id ]); } foreach ($input['images'] ?? [] as $item) { ProductImage::create([ 'image_id' => $item, 'w' => 'mobile', 'product_id' => $product->id ]); } foreach ($input['tags'] ?? [] as $item) { if (!isset($item['id'])) { ProductTags::create([ 'const_id' => $item['const_id'], 'product_id' => $product->id ]); } if (isset($item['remove']) && isset($item['id'])) { ProductTags::destroy($item['id']); } } $collect = Collect::where('product_id_id', $productId)->first(); Category::reloadCategory($input['cats'] , $product->id); $collect->save(); } else { /* ADD New Product */ $product = Product::create([ 'title' => $input['title'], 'body_html' => $input['body_html'] ?? null, 'desk_note' => $input['desk_note'] ?? null, 'product_code' => $input['product_code'], 'indicator_id_id' => $input['indicator_id'] ?? null, 'mobile_pic_id' => $input['mobile_pic'] ?? null, 'number_of_purchase' => 0, 'file_id' => $input['file_id'] ?? null, 'is_active' => 1, 'brand_id' => $input['brand_id'], 'show_type' => $input['show_type'], 'delivery_type' => $input['delivery_type'], 'message_long_delivery' => $input['message_long_delivery'] ?? null, ]); foreach ($input['gallery'] ?? [] as $item) { ProductImage::create([ 'image_id' => $item, 'product_id' => $product->id ]); } foreach ($input['images'] ?? [] as $item) { ProductImage::create([ 'image_id' => $item, 'w' => 'mobile', 'product_id' => $product->id ]); } foreach ($input['tags'] ?? [] as $item) { if (!isset($item['id'])) { ProductTags::create([ 'const_id' => $item['const_id'], 'product_id' => $product->id ]); } if (isset($item['remove']) && isset($item['id'])) { ProductTags::destroy($item['id']); } } Category::reloadCategory($input['cats'] , $product->id); //Add Varaints /*foreach ($request->variants as $item) { ProductVariant::create([ 'title'=>$item['title'], 'grams'=>$item['grams'], 'percentage_pay'=>$item['percentage_pay'], 'qty'=>$item['qty'], 'product_id_id'=>$product->id ]); }*/ } return response()->json(true); } public function addVariant(Request $request) { $input = $request->all(); //$input['product_id_id']=$request->product_id; //dd($input); if (isset($request->id)) { ProductVariant::where('id', $request->id) ->update($input); } else { ProductVariant::create($input); } return response()->json(true); } public function getVariant(Request $request) { $this->validate($request, [ 'id' => 'required', ]); $variant = ProductVariant::findOrFail($request->id); return response()->json($variant); } public function getVariants(Request $request) { $this->validate($request, [ 'id' => 'required', ]); $variant = ProductVariant::where('product_id_id', $request->id)->get(); return response()->json($variant); } public function getConfigStatics() { $static = ConfigStatic::all(); return response()->json($static); } public function getProduct($id) { $product = Product::with(['collect', 'image', 'gallery','images', 'tmobile', 'file', 'tags'])->findOrFail($id); return response()->json($product); } public function deleteProduct($id) { Product::safeDelete($id); return response()->json(true); } public function getCustomerById($id) { $customer = Customer::with(['image'])->select(['*',Customer::$SELECT_BRJ])->findOrFail($id); return response()->json($customer); } public function getCategory(Request $request) { $records = Category::with(['parent' , 'image', 'icon']); TableEngine::create($records, $request->all()) ->initSearch(['title']) ->select(['*' , Category::$SELECT_TYPE_STR]) ->export($records); return response()->json($records); } public function AddCategory(Request $request) { $this->validate($request, [ 'title' => 'required', ]); if ($request->id) { $category = Category::findorFail($request->id); $category->update($request->all()); } else { Category::create($request->all()); } return response()->json(true); } public function getOneCategory(Request $request) { $category = Category::with(['image' , 'icon'])->findorFail($request->id)->toArray(); $body = Category::findorFail($request->id)->body; $category['body'] = $body; return response()->json($category); } public function deleteCategory(Request $request) { /* $this->validate($request,[ 'id' => 'required', ]);*/ $category = Category::findorFail($request->id); $category->delete(); return response()->json(true); } public function getSingleOrders(Request $request) { $records = SingleCustomerOrders::with(['items', 'customer', 'activity','user','branch']); if (!is_null(auth()->user()->branch_id)){ $records->where('branch_id',auth()->user()->branch_id); } TableEngine::create($records, $request->all()) ->initSearch(['customer.name']) ->select([ '*',SingleCustomerOrders::$SELECT_CAJ ])->export($records); return response()->json($records); } public function changePercent(Request $request) { Log::info('change percent'); Log::info($request->all()); //return true; $this->validate($request, [ 'percentage_pay' => 'required', ]); $variants = ProductVariant::query(); if ($request->brand_id != null) { $variants->whereHas('product', function (Builder $query) use ($request) { $query->where('brand_id', $request->brand_id); }); } if ($request->category_id != null) { $variants->whereHas('product', function (Builder $query) use ($request) { $query->whereHas('collect', function (Builder $q) use ($request) { $q->where('collection_id_id', $request->category_id); }); }); } $result = $variants->update(['percentage_pay' => $request->percentage_pay]); return response()->json($result); } public function countProductForPercent(Request $request){ $variants = ProductVariant::query(); if ($request->brand_id != null) { $variants->whereHas('product', function (Builder $query) use ($request) { $query->where('brand_id', $request->brand_id); }); } if ($request->category_id != null) { $variants->whereHas('product', function (Builder $query) use ($request) { $query->whereHas('collect', function (Builder $q) use ($request) { $q->where('collection_id_id', $request->category_id); }); }); } return response()->json($variants->count()); } public function generateReportOrder(Request $request) { $order = Order::with(['items', 'customer', 'parent'])->select(['*', Order::$SELECT_UAJ, Order::$SELECT_CAJ, Order::$SELECT_STS_STR, Order::$SELECT_COLOR, Order::$SELECT_IMG])->findOrFail($request->order_id); $pdf = \niklasravnsborg\LaravelPdf\Facades\Pdf::loadView('pdf', ['order' => $order]); $file_name = 'report_' . $order->id . '.pdf'; if (!\Illuminate\Support\Facades\File::exists(public_path('storage/pdf'))) { \Illuminate\Support\Facades\File::makeDirectory(public_path('storage/pdf')); } $pdf->save(public_path('storage/pdf' . '/' . $file_name)); return response()->download(public_path('storage/pdf' . '/' . $file_name)); } public function orderStsSingle(Request $request) { $this->validate($request, [ 'id' => 'required' ]); $percent = ConfigStatic::where('key','percent')->first(); $oa = SingleCustomer\OrderActivity::findOrFail($request->id); $oa->proceed = !$request->has('remove'); $oa->note = $request->note; $oa->save(); $customer=SingleCustomer::findOrFail($oa->customer_id); $order = SingleCustomerOrders::findOrFail($oa->order_id); $transaction_order = TransactionOrder::where('order_id',$order->id)->where('customer_id',$order->user_id_id)->first(); $value = $transaction_order->total_weight * ($percent->val/100); if (!$request->has('remove')) { if ($oa->title == SingleCustomerOrders::$STS[1]) { $order->update(['sts' => 1]); //$customer->increment('remain',$order->w); } //ارسال پیامک تایید مدیر سیستم else if ($oa->title == SingleCustomerOrders::$STS[2]) { $order->update(['sts' => 2]); // $this->chargeWalletAfterOrder($order->user_id_id,$order->id); Sms::Send($customer->phone, 'هنزا گلد'."\n".'تایید سفارش '.$oa->order_id.' توسط مدیر سیستم'); Sms::Send($customer->phone, 'هنزا گلد' ."\n" .'با نهایی کردن سفارش و پرداخت مبلغ کل' .$value .'گرم طلا به کیف پول شما اضافه خواهد شد.' ); //Notify::store($customer->token_mobile,'هنزاگلد','تایید سفارش '.$oa->order_id.' توسط مدیر سیستم'); } else if ($oa->title == SingleCustomerOrders::$STS[3]) { $order->update(['sts' => 3]); } //ارسال پیامک به کیفی مربوطه بعد از اماده سازی else if ($oa->title == SingleCustomerOrders::$STS[4]) { $order->update(['sts' => 4]); /*if(!($reagent==null)) { Sms::Send($reagent->mobile, 'همکار گرامی'."\n".'سفارش آقای '.$customer->fname.' '.$customer->lname.' به شماره '.$oa->order_id.' در دفتر مرکزی آماده تحویل می باشد.'); Notify::store($reagent->token_mobile,'هنزاگلد','همکار گرامی'."\n".'سفارش آقای '.$customer->fname.' '.$customer->lname.' به شماره '.$oa->order_id.' در دفتر مرکزی آماده تحویل می باشد.'); }*/ } //ارسال پیامک به مشتری بعد از تحویل به کیفی else if ($oa->title == SingleCustomerOrders::$STS[5]) { $order->update(['sts' => 5]); // Sms::Send($customer->mobile, 'هنزا گلد'."\n".'سفارش شما با شماره سند '.$oa->order_id.' آماده و تحویل مسئول فروش شده است'); //Notify::store($customer->token_mobile,'هنزاگلد','سفارش شما با شماره سند '.$oa->order_id.' آماده و تحویل مسئول فروش شده است'); } //ارسال پیامک تحویل محصول با موفقیت به مشتری else if ($oa->title == SingleCustomerOrders::$STS[6]) { $order->update(['sts' => 6]); //Sms::Send($customer->mobile, 'هنزا گلد'."\n".'از خریدتان ممنونیم.از شما خواهشمندیم تا نظر خود را درباره خدمات هنزا گلد با ما در میان بگذارید.سپاس فراوان'); //Notify::store($customer->token_mobile,'هنزاگلد','از خریدتان ممنونیم.از شما خواهشمندیم تا نظر خود را درباره خدمات هنزا گلد با ما در میان بگذارید.سپاس فراوان'); // $this->chargeWalletAfterOrder($order->user_id_id,$order->price); $this->chargeWalletAfterOrder($order->user_id_id,$order->id); // Sms::Send($customer->phone, 'هنزا گلد'."\n".' سفارش '.$oa->order_id.' در حالت ارسال قرار گرفت.'); Sms::Send($customer->phone, 'هنزا گلد' ."\n" .$value .'گرم طلا به کیف پول شما اضافه شد و در سفارش بعدی قابل استفاده است.'."\n" .'اعتبار این موجودی 6 ماهه می باشد.'."\n" .'در ضمن شما میتوانید موجودی کیف پول خود را از طريق لينک زير مشاهده نماييد.'."\n" .'https://henzagold.com/customer/dashboard' ); } } else { // if ($oa->title == SingleCustomerOrders::$STS[1]) { // //$order->update(['sts'=>0]); // //$customer->decrement('remain',$order->w); // } else if ($oa->title == SingleCustomerOrders::$STS[2]) { // $order->update(['sts' => 1]); // } else if ($oa->title == SingleCustomerOrders::$STS[3]) { // $order->update(['sts' => 2]); // } else if ($oa->title == SingleCustomerOrders::$STS[4]) { // $order->update(['sts' => 3]); // } else if ($oa->title == SingleCustomerOrders::$STS[5]) { // $order->update(['sts' => 4]); // } else if ($oa->title == SingleCustomerOrders::$STS[6]) { // $order->update(['sts' => 5]); // } if ($oa->sts > 1) { $order->update(['sts' => $oa->sts -1]); } } return response()->json(true); } // public function chargeWalletAfterOrder($customer_id,$value){ public function chargeWalletAfterOrder($customer_id,$order_id){ $customer = SingleCustomer::findOrFail($customer_id); $transaction_order = TransactionOrder::where('order_id',$order_id)->where('customer_id',$customer_id)->first(); // $percent = ($value * $customer->percent)/100; // $wallet_interface = new WalletInterface($customer_id, 1); // new TransactionInterface($wallet_interface, $_inp = [ // "value" => $percent, // 'expire_at'=>now()->addYear(), // ], 2, true); $percent = ConfigStatic::where('key','percent')->first(); $expire = ConfigStatic::where('key','expire')->first(); if (!is_null($percent) && !is_null($expire) && !is_null($transaction_order)){ $value = $transaction_order->total_weight * ($percent->val/100); $wallet_interface = new WalletInterface($customer_id, 1); $transaction = new TransactionInterface($wallet_interface, $_inp = [ "value" => $value, 'order_id'=>$order_id, 'expire_at'=>now()->addDay($expire->val), ], 1, true,$meta = [ 'order_id'=>$order_id, 'total_weight'=>$transaction_order->total_weight, 'percent'=>$percent->val, 'order_date'=>$transaction_order->created_at ]); } $transaction_order->payment = 1; $transaction_order->save(); // Sms::Send($customer->phone, $customer->fname.' '.$customer->lname.' عزیز میزان '.$value.' طلا بابت آخرین خرید به کیف پول شما اضافه شد.هنزاگلد ' ); } public function getHavaleList(Request $request) { return response()->json(config('havaleh')); } public function changeAll(Request $request) { Log::info('change percent with product table'); Log::info($request->all()); if (isset($request->percentage_pay) && $request->percentage_pay != null) { $variants = ProductVariant::whereIn('product_id_id', $request->products_id); $variants->update(['percentage_pay' => $request->percentage_pay]); } return response()->json(true); //return response()->json($result); /*if($request->brand_id!=null) { $variants->whereHas('product',function (Builder $query) use ($request) { $query->where('brand_id',$request->brand_id); }); } if($request->category_id!=null) { $variants->whereHas('product',function (Builder $query) use ($request) { $query->whereHas('collect',function (Builder $q) use ($request) { $q->where('collection_id_id',$request->category_id); }); }); } $result= $variants->update(['percentage_pay'=>$request->percentage_pay]);*/ } public function generateReportDocument(Request $request){ $cash=Cash::with(['customer.reagent'])->select(['*',Cash::$SELECT_CAJ])->findOrFail($request->doc_id); $pdf = \niklasravnsborg\LaravelPdf\Facades\Pdf::loadView('doc_pdf', ['cash' => $cash]); $file_name = 'doc_' . $cash->id . '.pdf'; if (!\Illuminate\Support\Facades\File::exists(public_path('storage/pdf'))) { \Illuminate\Support\Facades\File::makeDirectory(public_path('storage/pdf')); } $pdf->save(public_path('storage/pdf' . '/' . $file_name)); return response()->download(public_path('storage/pdf/'. $file_name)); } public function getListFashion(Request $request){ $fashion = RequestFashion::query(); TableEngine::create($fashion, $request->all()) ->initSearch(['name', 'mobile']) ->select([ '*' ])->export($fashion); return response()->json($fashion); } }
Copyright ©2k19 -
Hexid
|
Tex7ure