Find this useful? Enter your email to receive occasional updates for securing PHP code.
Signing you up...
Thank you for signing up!
PHP Decode
<?php /** * The file was created by Assimon. * * @author assimon<[email protected]> * ..
Decoded Output download
<?php
/**
* The file was created by Assimon.
*
* @author assimon<[email protected]>
* @copyright assimon<[email protected]>
* @link http://utf8.hk/
*/
namespace App\Service;
use App\Exceptions\RuleValidationException;
use App\Jobs\ApiHook;
use App\Jobs\MailSend;
use App\Jobs\OrderExpired;
use App\Jobs\ServerJiang;
use App\Jobs\TelegramPush;
use App\Jobs\BarkPush;
use App\Jobs\WorkWeiXinPush;
use App\Models\BaseModel;
use App\Models\Coupon;
use App\Models\Goods;
use App\Models\Order;
use Carbon\Carbon;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
/**
*
*
* Class OrderProcessService
* @package App\Service
* @author: Assimon
* @email: [email protected]
* @blog: https://utf8.hk
* Date: 2021/5/30
*/
class OrderProcessService
{
const PENDING_CACHE_KEY = 'PENDING_ORDERS_LIST';
/**
*
* @var \App\Service\CouponService
*/
private $couponService;
/**
*
* @var \App\Service\OrderService
*/
private $orderService;
/**
*
* @var \App\Service\CarmisService
*/
private $carmisService;
/**
*
* @var \App\Service\EmailtplService
*/
private $emailtplService;
/**
* .
* @var \App\Service\GoodsService
*/
private $goodsService;
/**
*
* @var Goods
*/
private $goods;
/**
*
* @var Coupon;
*/
private $coupon;
/**
*
* @var string
*/
private $otherIpt;
/**
*
* @var int
*/
private $buyAmount;
/**
*
* @var string
*/
private $email;
/**
*
* @var string
*/
private $searchPwd;
/**
* id
* @var string
*/
private $buyIP;
/**
*
* @var int
*/
private $payID;
public function __construct()
{
$this->couponService = app('Service\CouponService');
$this->orderService = app('Service\OrderService');
$this->carmisService = app('Service\CarmisService');
$this->emailtplService = app('Service\EmailtplService');
$this->goodsService = app('Service\GoodsService');
}
/**
*
* @param int $payID
*/
public function setPayID(int $payID): void
{
$this->payID = $payID;
}
/**
* ip
* @param mixed $buyIP
*/
public function setBuyIP($buyIP): void
{
$this->buyIP = $buyIP;
}
/**
*
* @param mixed $searchPwd
*/
public function setSearchPwd($searchPwd): void
{
$this->searchPwd = $searchPwd;
}
/**
*
* @param mixed $buyAmount
*/
public function setBuyAmount($buyAmount): void
{
$this->buyAmount = $buyAmount;
}
/**
*
* @param mixed $email
*/
public function setEmail($email): void
{
$this->email = $email;
}
/**
*
*
* @param Goods $goods
*
* @author assimon<[email protected]>
* @copyright assimon<[email protected]>
* @link http://utf8.hk/
*/
public function setGoods(Goods $goods)
{
$this->goods = $goods;
}
/**
* .
*
* @param ?Coupon $coupon
*
* @author assimon<[email protected]>
* @copyright assimon<[email protected]>
* @link http://utf8.hk/
*/
public function setCoupon(?Coupon $coupon)
{
$this->coupon = $coupon;
}
/**
* .
*
* @param ?string $otherIpt
*
* @author assimon<[email protected]>
* @copyright assimon<[email protected]>
* @link http://utf8.hk/
*/
public function setOtherIpt(?string $otherIpt)
{
$this->otherIpt = $otherIpt;
}
/**
*
*
* @return float
*
* @author assimon<[email protected]>
* @copyright assimon<[email protected]>
* @link http://utf8.hk/
*/
private function calculateTheCouponPrice(): float
{
$couponPrice = 0;
//
if ($this->coupon) {
$couponPrice = $this->coupon->discount;
}
return $couponPrice;
}
/**
*
* @return float
*
* @author assimon<[email protected]>
* @copyright assimon<[email protected]>
* @link http://utf8.hk/
*/
private function calculateTheWholesalePrice(): float
{
$wholesalePrice = 0; //
$wholesaleTotalPrice = 0; //
if ($this->goods->wholesale_price_cnf) {
$formatWholesalePrice = format_wholesale_price($this->goods->wholesale_price_cnf);
foreach ($formatWholesalePrice as $item) {
if ($this->buyAmount >= $item['number']) {
$wholesalePrice = $item['price'];
}
}
}
if ($wholesalePrice > 0 ) {
$totalPrice = $this->calculateTheTotalPrice(); //
$newTotalPrice = bcmul($wholesalePrice, $this->buyAmount, 2); //
$wholesaleTotalPrice = bcsub($totalPrice, $newTotalPrice, 2); //
}
return $wholesaleTotalPrice;
}
/**
*
* @return float
*
* @author assimon<[email protected]>
* @copyright assimon<[email protected]>
* @link http://utf8.hk/
*/
private function calculateTheTotalPrice(): float
{
$price = $this->goods->actual_price;
return bcmul($price, $this->buyAmount, 2);
}
/**
*
*
* @param float $totalPrice
* @param float $couponPrice
* @param float $wholesalePrice
* @return float
*
* @author assimon<[email protected]>
* @copyright assimon<[email protected]>
* @link http://utf8.hk/
*/
private function calculateTheActualPrice(float $totalPrice, float $couponPrice, float $wholesalePrice): float
{
$actualPrice = bcsub($totalPrice, $couponPrice, 2);
$actualPrice = bcsub($actualPrice, $wholesalePrice, 2);
if ($actualPrice <= 0) {
$actualPrice = 0;
}
return $actualPrice;
}
/**
* .
* @return Order
* @throws RuleValidationException
*
* @author assimon<[email protected]>
* @copyright assimon<[email protected]>
* @link http://utf8.hk/
*/
public function createOrder(): Order
{
try {
$order = new Order();
//
$order->order_sn = strtoupper(Str::random(16));
//
$order->goods_id = $this->goods->id;
//
$order->title = $this->goods->gd_name . ' x ' . $this->buyAmount;
//
$order->type = $this->goods->type;
//
$order->search_pwd = $this->searchPwd;
//
$order->email = $this->email;
// .
$order->pay_id = $this->payID;
//
$order->goods_price = $this->goods->actual_price;
//
$order->buy_amount = $this->buyAmount;
//
$order->info = $this->otherIpt;
// ip
$order->buy_ip = $this->buyIP;
//
$order->coupon_discount_price = $this->calculateTheCouponPrice();
if ($this->coupon) {
$order->coupon_id = $this->coupon->id;
}
//
$order->wholesale_discount_price = $this->calculateTheWholesalePrice();
//
$order->total_price = $this->calculateTheTotalPrice();
//
$order->actual_price = $this->calculateTheActualPrice(
$this->calculateTheTotalPrice(),
$this->calculateTheCouponPrice(),
$this->calculateTheWholesalePrice()
);
//
$order->save();
//
if ($this->coupon) {
//
$this->couponService->used($this->coupon->coupon);
// -1
$this->couponService->retDecr($this->coupon->coupon);
}
// x
$expiredOrderDate = dujiaoka_config_get('order_expire_time', 5);
OrderExpired::dispatch($order->order_sn)->delay(Carbon::now()->addMinutes($expiredOrderDate));
return $order;
} catch (\Exception $exception) {
throw new RuleValidationException($exception->getMessage());
}
}
/**
*
*
* @param string $orderSN
* @param float $actualPrice
* @param string $tradeNo
* @return Order
*
* @author assimon<[email protected]>
* @copyright assimon<[email protected]>
* @link http://utf8.hk/
*/
public function completedOrder(string $orderSN, float $actualPrice, string $tradeNo = '')
{
DB::beginTransaction();
try {
//
$order = $this->orderService->detailOrderSN($orderSN);
if (!$order) {
throw new \Exception(__('dujiaoka.prompt.order_does_not_exist'));
}
//
if ($order->status == Order::STATUS_COMPLETED) {
throw new \Exception(__('dujiaoka.prompt.order_status_completed'));
}
$bccomp = bccomp($order->actual_price, $actualPrice, 2);
//
if ($bccomp != 0) {
throw new \Exception(__('dujiaoka.prompt.order_inconsistent_amounts'));
}
$order->actual_price = $actualPrice;
$order->trade_no = $tradeNo;
//
//
if ($order->type == Order::AUTOMATIC_DELIVERY) {
$completedOrder = $this->processAuto($order);
} else {
$completedOrder = $this->processManual($order);
}
//
$this->goodsService->salesVolumeIncr($order->goods_id, $order->buy_amount);
DB::commit();
// server
if (dujiaoka_config_get('is_open_server_jiang', 0) == BaseModel::STATUS_OPEN) {
ServerJiang::dispatch($order);
}
// TG
if (dujiaoka_config_get('is_open_telegram_push', 0) == BaseModel::STATUS_OPEN) {
TelegramPush::dispatch($order);
}
// Bark
if (dujiaoka_config_get('is_open_bark_push', 0) == BaseModel::STATUS_OPEN) {
BarkPush::dispatch($order);
}
// Bot
if (dujiaoka_config_get('is_open_qywxbot_push', 0) == BaseModel::STATUS_OPEN) {
WorkWeiXinPush::dispatch($order);
}
//
ApiHook::dispatch($order);
return $completedOrder;
} catch (\Exception $exception) {
DB::rollBack();
throw new RuleValidationException($exception->getMessage());
}
}
/**
* .
*
* @param Order $order
* @return Order
*
* @author assimon<[email protected]>
* @copyright assimon<[email protected]>
* @link http://utf8.hk/
*/
public function processManual(Order $order)
{
//
$order->status = Order::STATUS_PENDING;
//
$order->save();
//
$this->goodsService->inStockDecr($order->goods_id, $order->buy_amount);
//
$mailData = [
'created_at' => $order->create_at,
'product_name' => $order->goods->gd_name,
'webname' => dujiaoka_config_get('text_logo', ''),
'weburl' => config('app.url') ?? 'http://dujiaoka.com',
'ord_info' => str_replace(PHP_EOL, '<br/>', $order->info),
'ord_title' => $order->title,
'order_id' => $order->order_sn,
'buy_amount' => $order->buy_amount,
'ord_price' => $order->actual_price,
'created_at' => $order->created_at,
];
$tpl = $this->emailtplService->detailByToken('manual_send_manage_mail');
$mailBody = replace_mail_tpl($tpl, $mailData);
$manageMail = dujiaoka_config_get('manage_email', '');
//
MailSend::dispatch($manageMail, $mailBody['tpl_name'], $mailBody['tpl_content']);
return $order;
}
/**
* .
*
* @param Order $order
* @return Order
*
* @author assimon<[email protected]>
* @copyright assimon<[email protected]>
* @link http://utf8.hk/
*/
public function processAuto(Order $order): Order
{
//
$carmis = $this->carmisService->withGoodsByAmountAndStatusUnsold($order->goods_id, $order->buy_amount);
//
if (count($carmis) != $order->buy_amount) {
$order->info = __('dujiaoka.prompt.order_carmis_insufficient_quantity_available');
$order->status = Order::STATUS_ABNORMAL;
$order->save();
return $order;
}
$carmisInfo = array_column($carmis, 'carmi');
$ids = array_column($carmis, 'id');
$order->info = implode(PHP_EOL, $carmisInfo);
$order->status = Order::STATUS_COMPLETED;
$order->save();
//
$this->carmisService->soldByIDS($ids);
//
$mailData = [
'created_at' => $order->create_at,
'product_name' => $order->goods->gd_name,
'webname' => dujiaoka_config_get('text_logo', ''),
'weburl' => config('app.url') ?? 'http://dujiaoka.com',
'ord_info' => implode('<br/>', $carmisInfo),
'ord_title' => $order->title,
'order_id' => $order->order_sn,
'buy_amount' => $order->buy_amount,
'ord_price' => $order->actual_price,
];
$tpl = $this->emailtplService->detailByToken('card_send_user_email');
$mailBody = replace_mail_tpl($tpl, $mailData);
//
MailSend::dispatch($order->email, $mailBody['tpl_name'], $mailBody['tpl_content']);
return $order;
}
}
?>
Did this file decode correctly?
Original Code
<?php
/**
* The file was created by Assimon.
*
* @author assimon<[email protected]>
* @copyright assimon<[email protected]>
* @link http://utf8.hk/
*/
namespace App\Service;
use App\Exceptions\RuleValidationException;
use App\Jobs\ApiHook;
use App\Jobs\MailSend;
use App\Jobs\OrderExpired;
use App\Jobs\ServerJiang;
use App\Jobs\TelegramPush;
use App\Jobs\BarkPush;
use App\Jobs\WorkWeiXinPush;
use App\Models\BaseModel;
use App\Models\Coupon;
use App\Models\Goods;
use App\Models\Order;
use Carbon\Carbon;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
/**
*
*
* Class OrderProcessService
* @package App\Service
* @author: Assimon
* @email: [email protected]
* @blog: https://utf8.hk
* Date: 2021/5/30
*/
class OrderProcessService
{
const PENDING_CACHE_KEY = 'PENDING_ORDERS_LIST';
/**
*
* @var \App\Service\CouponService
*/
private $couponService;
/**
*
* @var \App\Service\OrderService
*/
private $orderService;
/**
*
* @var \App\Service\CarmisService
*/
private $carmisService;
/**
*
* @var \App\Service\EmailtplService
*/
private $emailtplService;
/**
* .
* @var \App\Service\GoodsService
*/
private $goodsService;
/**
*
* @var Goods
*/
private $goods;
/**
*
* @var Coupon;
*/
private $coupon;
/**
*
* @var string
*/
private $otherIpt;
/**
*
* @var int
*/
private $buyAmount;
/**
*
* @var string
*/
private $email;
/**
*
* @var string
*/
private $searchPwd;
/**
* id
* @var string
*/
private $buyIP;
/**
*
* @var int
*/
private $payID;
public function __construct()
{
$this->couponService = app('Service\CouponService');
$this->orderService = app('Service\OrderService');
$this->carmisService = app('Service\CarmisService');
$this->emailtplService = app('Service\EmailtplService');
$this->goodsService = app('Service\GoodsService');
}
/**
*
* @param int $payID
*/
public function setPayID(int $payID): void
{
$this->payID = $payID;
}
/**
* ip
* @param mixed $buyIP
*/
public function setBuyIP($buyIP): void
{
$this->buyIP = $buyIP;
}
/**
*
* @param mixed $searchPwd
*/
public function setSearchPwd($searchPwd): void
{
$this->searchPwd = $searchPwd;
}
/**
*
* @param mixed $buyAmount
*/
public function setBuyAmount($buyAmount): void
{
$this->buyAmount = $buyAmount;
}
/**
*
* @param mixed $email
*/
public function setEmail($email): void
{
$this->email = $email;
}
/**
*
*
* @param Goods $goods
*
* @author assimon<[email protected]>
* @copyright assimon<[email protected]>
* @link http://utf8.hk/
*/
public function setGoods(Goods $goods)
{
$this->goods = $goods;
}
/**
* .
*
* @param ?Coupon $coupon
*
* @author assimon<[email protected]>
* @copyright assimon<[email protected]>
* @link http://utf8.hk/
*/
public function setCoupon(?Coupon $coupon)
{
$this->coupon = $coupon;
}
/**
* .
*
* @param ?string $otherIpt
*
* @author assimon<[email protected]>
* @copyright assimon<[email protected]>
* @link http://utf8.hk/
*/
public function setOtherIpt(?string $otherIpt)
{
$this->otherIpt = $otherIpt;
}
/**
*
*
* @return float
*
* @author assimon<[email protected]>
* @copyright assimon<[email protected]>
* @link http://utf8.hk/
*/
private function calculateTheCouponPrice(): float
{
$couponPrice = 0;
//
if ($this->coupon) {
$couponPrice = $this->coupon->discount;
}
return $couponPrice;
}
/**
*
* @return float
*
* @author assimon<[email protected]>
* @copyright assimon<[email protected]>
* @link http://utf8.hk/
*/
private function calculateTheWholesalePrice(): float
{
$wholesalePrice = 0; //
$wholesaleTotalPrice = 0; //
if ($this->goods->wholesale_price_cnf) {
$formatWholesalePrice = format_wholesale_price($this->goods->wholesale_price_cnf);
foreach ($formatWholesalePrice as $item) {
if ($this->buyAmount >= $item['number']) {
$wholesalePrice = $item['price'];
}
}
}
if ($wholesalePrice > 0 ) {
$totalPrice = $this->calculateTheTotalPrice(); //
$newTotalPrice = bcmul($wholesalePrice, $this->buyAmount, 2); //
$wholesaleTotalPrice = bcsub($totalPrice, $newTotalPrice, 2); //
}
return $wholesaleTotalPrice;
}
/**
*
* @return float
*
* @author assimon<[email protected]>
* @copyright assimon<[email protected]>
* @link http://utf8.hk/
*/
private function calculateTheTotalPrice(): float
{
$price = $this->goods->actual_price;
return bcmul($price, $this->buyAmount, 2);
}
/**
*
*
* @param float $totalPrice
* @param float $couponPrice
* @param float $wholesalePrice
* @return float
*
* @author assimon<[email protected]>
* @copyright assimon<[email protected]>
* @link http://utf8.hk/
*/
private function calculateTheActualPrice(float $totalPrice, float $couponPrice, float $wholesalePrice): float
{
$actualPrice = bcsub($totalPrice, $couponPrice, 2);
$actualPrice = bcsub($actualPrice, $wholesalePrice, 2);
if ($actualPrice <= 0) {
$actualPrice = 0;
}
return $actualPrice;
}
/**
* .
* @return Order
* @throws RuleValidationException
*
* @author assimon<[email protected]>
* @copyright assimon<[email protected]>
* @link http://utf8.hk/
*/
public function createOrder(): Order
{
try {
$order = new Order();
//
$order->order_sn = strtoupper(Str::random(16));
//
$order->goods_id = $this->goods->id;
//
$order->title = $this->goods->gd_name . ' x ' . $this->buyAmount;
//
$order->type = $this->goods->type;
//
$order->search_pwd = $this->searchPwd;
//
$order->email = $this->email;
// .
$order->pay_id = $this->payID;
//
$order->goods_price = $this->goods->actual_price;
//
$order->buy_amount = $this->buyAmount;
//
$order->info = $this->otherIpt;
// ip
$order->buy_ip = $this->buyIP;
//
$order->coupon_discount_price = $this->calculateTheCouponPrice();
if ($this->coupon) {
$order->coupon_id = $this->coupon->id;
}
//
$order->wholesale_discount_price = $this->calculateTheWholesalePrice();
//
$order->total_price = $this->calculateTheTotalPrice();
//
$order->actual_price = $this->calculateTheActualPrice(
$this->calculateTheTotalPrice(),
$this->calculateTheCouponPrice(),
$this->calculateTheWholesalePrice()
);
//
$order->save();
//
if ($this->coupon) {
//
$this->couponService->used($this->coupon->coupon);
// -1
$this->couponService->retDecr($this->coupon->coupon);
}
// x
$expiredOrderDate = dujiaoka_config_get('order_expire_time', 5);
OrderExpired::dispatch($order->order_sn)->delay(Carbon::now()->addMinutes($expiredOrderDate));
return $order;
} catch (\Exception $exception) {
throw new RuleValidationException($exception->getMessage());
}
}
/**
*
*
* @param string $orderSN
* @param float $actualPrice
* @param string $tradeNo
* @return Order
*
* @author assimon<[email protected]>
* @copyright assimon<[email protected]>
* @link http://utf8.hk/
*/
public function completedOrder(string $orderSN, float $actualPrice, string $tradeNo = '')
{
DB::beginTransaction();
try {
//
$order = $this->orderService->detailOrderSN($orderSN);
if (!$order) {
throw new \Exception(__('dujiaoka.prompt.order_does_not_exist'));
}
//
if ($order->status == Order::STATUS_COMPLETED) {
throw new \Exception(__('dujiaoka.prompt.order_status_completed'));
}
$bccomp = bccomp($order->actual_price, $actualPrice, 2);
//
if ($bccomp != 0) {
throw new \Exception(__('dujiaoka.prompt.order_inconsistent_amounts'));
}
$order->actual_price = $actualPrice;
$order->trade_no = $tradeNo;
//
//
if ($order->type == Order::AUTOMATIC_DELIVERY) {
$completedOrder = $this->processAuto($order);
} else {
$completedOrder = $this->processManual($order);
}
//
$this->goodsService->salesVolumeIncr($order->goods_id, $order->buy_amount);
DB::commit();
// server
if (dujiaoka_config_get('is_open_server_jiang', 0) == BaseModel::STATUS_OPEN) {
ServerJiang::dispatch($order);
}
// TG
if (dujiaoka_config_get('is_open_telegram_push', 0) == BaseModel::STATUS_OPEN) {
TelegramPush::dispatch($order);
}
// Bark
if (dujiaoka_config_get('is_open_bark_push', 0) == BaseModel::STATUS_OPEN) {
BarkPush::dispatch($order);
}
// Bot
if (dujiaoka_config_get('is_open_qywxbot_push', 0) == BaseModel::STATUS_OPEN) {
WorkWeiXinPush::dispatch($order);
}
//
ApiHook::dispatch($order);
return $completedOrder;
} catch (\Exception $exception) {
DB::rollBack();
throw new RuleValidationException($exception->getMessage());
}
}
/**
* .
*
* @param Order $order
* @return Order
*
* @author assimon<[email protected]>
* @copyright assimon<[email protected]>
* @link http://utf8.hk/
*/
public function processManual(Order $order)
{
//
$order->status = Order::STATUS_PENDING;
//
$order->save();
//
$this->goodsService->inStockDecr($order->goods_id, $order->buy_amount);
//
$mailData = [
'created_at' => $order->create_at,
'product_name' => $order->goods->gd_name,
'webname' => dujiaoka_config_get('text_logo', ''),
'weburl' => config('app.url') ?? 'http://dujiaoka.com',
'ord_info' => str_replace(PHP_EOL, '<br/>', $order->info),
'ord_title' => $order->title,
'order_id' => $order->order_sn,
'buy_amount' => $order->buy_amount,
'ord_price' => $order->actual_price,
'created_at' => $order->created_at,
];
$tpl = $this->emailtplService->detailByToken('manual_send_manage_mail');
$mailBody = replace_mail_tpl($tpl, $mailData);
$manageMail = dujiaoka_config_get('manage_email', '');
//
MailSend::dispatch($manageMail, $mailBody['tpl_name'], $mailBody['tpl_content']);
return $order;
}
/**
* .
*
* @param Order $order
* @return Order
*
* @author assimon<[email protected]>
* @copyright assimon<[email protected]>
* @link http://utf8.hk/
*/
public function processAuto(Order $order): Order
{
//
$carmis = $this->carmisService->withGoodsByAmountAndStatusUnsold($order->goods_id, $order->buy_amount);
//
if (count($carmis) != $order->buy_amount) {
$order->info = __('dujiaoka.prompt.order_carmis_insufficient_quantity_available');
$order->status = Order::STATUS_ABNORMAL;
$order->save();
return $order;
}
$carmisInfo = array_column($carmis, 'carmi');
$ids = array_column($carmis, 'id');
$order->info = implode(PHP_EOL, $carmisInfo);
$order->status = Order::STATUS_COMPLETED;
$order->save();
//
$this->carmisService->soldByIDS($ids);
//
$mailData = [
'created_at' => $order->create_at,
'product_name' => $order->goods->gd_name,
'webname' => dujiaoka_config_get('text_logo', ''),
'weburl' => config('app.url') ?? 'http://dujiaoka.com',
'ord_info' => implode('<br/>', $carmisInfo),
'ord_title' => $order->title,
'order_id' => $order->order_sn,
'buy_amount' => $order->buy_amount,
'ord_price' => $order->actual_price,
];
$tpl = $this->emailtplService->detailByToken('card_send_user_email');
$mailBody = replace_mail_tpl($tpl, $mailData);
//
MailSend::dispatch($order->email, $mailBody['tpl_name'], $mailBody['tpl_content']);
return $order;
}
}
Function Calls
| None |
Stats
| MD5 | 75010cbaa0c70bd6b830464a48833339 |
| Eval Count | 0 |
| Decode Time | 102 ms |