/
home
/
old_henza
/
server
/
app
/
Http
/
Controllers
/
File Upload :
llllll
Current File: /home/old_henza/server/app/Http/Controllers/Controller.php
<?php namespace App\Http\Controllers; use App\Models\ConfigStatic; use App\Models\PromotionProduct; use App\Models\SingleCustomer; use App\Models\SingleCustomer\OrderActivity; use App\Models\SingleCustomer\PromotionUsed; use App\Models\SingleCustomerOrderItems; use App\Models\SingleCustomerOrders; use App\Models\Sms; use App\Models\TransactionOrder; use App\Models\WebServiceGold; use Illuminate\Foundation\Auth\Access\AuthorizesRequests; use Illuminate\Foundation\Bus\DispatchesJobs; use Illuminate\Foundation\Validation\ValidatesRequests; use Illuminate\Routing\Controller as BaseController; use Illuminate\Support\Facades\Auth; use Rooyesh\Wallet\interfaces\TransactionInterface; use App\Http\Controllers\Adm\AdminController as AdminCo; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; class Controller extends BaseController { use AuthorizesRequests, DispatchesJobs, ValidatesRequests; public function addLimit($table,$list){ if (!isset($list['page'])){ $list['page'] = 0; } if (!isset($list['limit']) || is_null($list['limit'])){ $list['limit'] = 10; } if ($list['limit']>50){ $list['limit'] = 50; } $list['count'] = $table->count(); $list['rows'] = $table->offset( $list['page']*$list['limit']) ->limit($list['limit']) ->get(); $list['page'] = (int)$list['page']; $list['limit'] = (int)$list['limit']; return $list; } public function convert($string) { $persian = ['ی']; $arabic = ['ي']; $output= str_replace($arabic, $persian, $string); return $output; } /** * for create order * create transaction order * @param $customer_id * @param $order * @param $type */ public function createTransactionOrder($customer_id, $order, $type){ $tr = TransactionOrder::create([ 'customer_id'=>$customer_id, 'order_id'=>$order->id, 'total_price'=>$order->total_price, 'transaction_type'=>$type, 'total_weight'=>$order->total_weight, 'order_date'=>$order->created_at ]); return $tr; } /** * for create order * create single order activity * @param $order_id * @param $customer_id * @return void */ public function createSingleOrderActivity($order_id, $customer_id){ foreach (SingleCustomerOrders::$STS as $key => $item) { \App\Models\SingleCustomer\OrderActivity::create([ 'order_id' => $order_id, 'customer_id' => $customer_id, 'title' => $item, 'note'=> '' , 'key'=>$key, 'proceed' => $key==1 ? 1 : 0 , ]); } } /** * for create order * create single customer order * @param $data * @param $customer_id * @param $user_id * @return mixed */ public function createSingleCustomerOrders($data, $customer_id, $user_id = null, $branch_id=null){ $order = SingleCustomerOrders::create([ 'app'=>$data['app'], 'shipping_address'=>$data['shipping_address'], 'total_price'=>$data['total_price'], 'user_id_id'=>$customer_id, 'sts'=>$data['sts'], 'total_discount'=>$data['total_discount'], 'price'=>$data['price'], 'total_weight'=>$data['total_weight'], 'reagent_id'=>$user_id, 'type'=>$data['type'] ?? null, 'gold_price_original'=>WebServiceGold::getPriceGold18Ayar(), 'use_wallet'=>$data['use_wallet'] ?? 0, 'payment_after_wallet'=>$data['price'], 'branch_id'=>$branch_id ]); return $order; } /** * for create order * create single customer order item * @param $title * @param $item * @param $order_id * @return mixed */ public function createSingleCustomerOrderItems($title, $item, $order_id, $customer_id, $branch_id = null){ $order_item =SingleCustomerOrderItems::create([ 'title' => $title, 'price' => $item['price'] ?? 0, 'qty' => $item['qty'] ?? 0, 'product_id' => $item['product_id'] ?? 0, 'variant_id' => $item['variant_id'] ?? 0, 'order_id' => $order_id, 'grams'=>$item['grams'] ?? 0 , 'rial_pay'=>$item['rial_pay'] ?? 0, 'variant_title'=>$item['variant_title'], 'is_preorder'=> $item['is_preorder'], 'total_discount'=> $item['total_discount'], 'total_price'=> $item['total_price'], 'gold_price_in_formula'=>($item['total_price'] / $item['qty']) / $item['grams'], 'branch_id'=>$branch_id ]); if (!is_null($item['promotion_id'])){ $this->createPromotionForOrder($item,$order_item,$order_id,$customer_id); } return $order_item; } /** * for create order * create promotion for order * @param $item * @param $order_item * @param $order_id * @param $customer_id * @return mixed */ public function createPromotionForOrder($item, $order_item, $order_id, $customer_id){ $promotion = PromotionProduct::findOrFail($item['promotion_id']); $order_item->promotion_id = $promotion->promotion_id; $order_item->promotion_item_id = $promotion->promotion_item_id; $order_item->save(); PromotionUsed::create([ 'customer_id'=>$customer_id, 'promotion_id'=>$promotion->promotion_id, 'promotion_item_id'=>$promotion->promotion_item_id, 'order_id'=> $order_id, 'order_item_id'=>$order_item->id, 'promotion_product_id'=>$promotion->id ]); return $promotion; } public function afterCreateOrder($customer_id, $order, $type, $sts = 1){ //ثبت وضعیت های سفارش $this->createSingleOrderActivity($order->id ,$customer_id); $cu = SingleCustomer::findOrFail($customer_id); if ($sts != 1){ OrderActivity::where('order_id',$order->id) ->where('key',$sts) ->update(['proceed'=>1]); } //ثبت در جدول transaction_order $tr = $this->createTransactionOrder($customer_id, $order, $type); if ($sts == 1) { Sms::Send($cu->phone, 'هنزا گلد' . "\n" . $cu->fname . ' ' . $cu->lname . ' گرامی ' . "\n" . 'با تشکر از اعتماد شما به هنزا' . "\n" . 'سفارش شما به شماره ' . $order->id . ' ثبت و در حال پردازش است.' . "\n" . 'لطفا منتظر تماس کارشناسان فروش ما باشید.' . "\n" . 'در ضمن شما میتوانید وضعیت سفارش خود را از طريق لينک زير پیگیری نماييد.' . "\n" . 'https://henzagold.com/customer/my-orders' ); } if ($sts == 6){ $percent = ConfigStatic::where('key','percent')->first(); $value = $tr->total_weight * ($percent->val/100); (new AdminCo())->chargeWalletAfterOrder($order->user_id_id,$order->id); // Sms::Send($cu->phone, 'هنزا گلد'."\n".' سفارش '.$order->id.' در حالت ارسال قرار گرفت.'); Sms::Send($cu->phone, 'هنزا گلد' ."\n" .$value .'گرم طلا به کیف پول شما اضافه شد و در سفارش بعدی قابل استفاده است.'."\n" .'اعتبار این موجودی 6 ماهه می باشد.'."\n" .'در ضمن شما میتوانید موجودی کیف پول خود را از طريق لينک زير مشاهده نماييد.'."\n" .'https://henzagold.com/customer/dashboard' ); } } public function createTransactionInterface($wallet_interface,$value,$type,$deposit,$order){ $transaction = new TransactionInterface($wallet_interface, $_inp = [ "value" => $value, "note"=>"for buy", 'order_id'=>$order->id, ], $type, $deposit,$meta = [ 'order_id'=>$order->id, 'total_weight'=>$order->total_weight, 'order_date'=>$order->created_at ]); } public function checkCustomer($customer_id_auth, $customer_id_store){ if ($customer_id_auth != $customer_id_store){ throw new AccessDeniedHttpException('شما دسترسی ندارید'); } } }
Copyright ©2k19 -
Hexid
|
Tex7ure