| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293 |
- <?php
- namespace biz\pt\classes;
- use biz\base\classes\BaseClass;
- use common\components\dict;
- use common\components\util;
- class PtAssetClass extends BaseClass
- {
- public static $baseFile = '\biz\pt\models\PtAsset';
- //客户下单增加商家余额 shish 20210520
- public static function customKdAddBalance($shop, $amount, $order, $capitalType, $tx)
- {
- $ptStyle = $shop->ptStyle;
- if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
- $asset = self::getHdBalance();
- } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
- $asset = self::getGhsBalance();
- } else {
- util::fail('没有找到平台');
- }
- $currentAmount = bcadd($asset->amount, $amount, 2);
- $asset->amount = $currentAmount;
- $asset->save();
- if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
- $txAsset = self::getHdTxBalance();
- } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
- $txAsset = self::getGhsTxBalance();
- } else {
- util::fail('没有找到平台');
- }
- $currentTxBalance = $txAsset->amount;
- $currentTxBalance = bcadd($currentTxBalance, $amount, 2);
- $txAsset->amount = $currentTxBalance;
- $txAsset->save();
- $id = $order->id;
- $event = "【{$shop->merchantName} {$shop->shopName}】的客户下单购买 {$amount}元 订单号:{$order->orderSn}";
- $change = [
- 'relateId' => $id,
- 'capitalType' => $capitalType,
- 'amount' => $amount,
- 'balance' => $currentAmount,
- 'txBalance' => $currentTxBalance,
- 'io' => 1,
- 'payWay' => $order->payWay,
- 'event' => $event,
- 'sjId' => $order->sjId,
- 'shopId' => $order->shopId,
- 'tx' => $tx,
- 'ptStyle' => $ptStyle,
- 'shopName' => $shop->shopName,
- 'sjName' => $shop->merchantName,
- ];
- PtYeChangeClass::addChange($change, true);
- }
- //客户使用优惠券增加余额 shish 20210601
- public static function customKdUseCouponAddBalance($shop, $order, $capitalType, $tx)
- {
- $amount = $order->discountAmount;
- $ptStyle = $shop->ptStyle;
- if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
- $asset = self::getHdBalance();
- } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
- $asset = self::getGhsBalance();
- } else {
- util::fail('没有找到平台');
- }
- $currentAmount = bcadd($asset->amount, $amount, 2);
- $asset->amount = $currentAmount;
- $asset->save();
- if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
- $txAsset = self::getHdTxBalance();
- } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
- $txAsset = self::getGhsTxBalance();
- } else {
- util::fail('没有找到平台');
- }
- $currentTxBalance = $txAsset->amount;
- $currentTxBalance = bcadd($currentTxBalance, $amount, 2);
- $txAsset->amount = $currentTxBalance;
- $txAsset->save();
- $id = $order->id;
- $event = "【{$shop->merchantName} {$shop->shopName}】的客户下单(使用平台优惠券{$amount}元) 订单号:{$order->orderSn}";
- $change = [
- 'relateId' => $id,
- 'capitalType' => $capitalType,
- 'amount' => $amount,
- 'balance' => $currentAmount,
- 'txBalance' => $currentTxBalance,
- 'io' => 1,
- 'payWay' => $order->payWay,
- 'event' => $event,
- 'sjId' => $order->sjId,
- 'shopId' => $order->shopId,
- 'tx' => $tx,
- 'ptStyle' => $ptStyle,
- 'shopName' => $shop->shopName,
- 'sjName' => $shop->merchantName,
- ];
- PtYeChangeClass::addChange($change, true);
- }
- //平台余额增加 shish 20210519
- public static function rechargeAddBalance($shop, $amount, $order, $capitalType, $tx)
- {
- $ptStyle = $shop->ptStyle;
- if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
- $asset = self::getHdBalance();
- } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
- $asset = self::getGhsBalance();
- } else {
- util::fail('没有找到平台');
- }
- $currentAmount = bcadd($asset->amount, $amount, 2);
- $asset->amount = $currentAmount;
- $asset->save();
- if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
- $txAsset = self::getHdTxBalance();
- } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
- $txAsset = self::getGhsTxBalance();
- } else {
- util::fail('没有找到平台');
- }
- $currentTxBalance = $txAsset->amount;
- if ($tx == dict::getDict('yeTx', 'can')) {
- $currentTxBalance = bcadd($currentTxBalance, $amount, 2);
- $txAsset->amount = $currentTxBalance;
- $txAsset->save();
- }
- $id = $order->id;
- $event = "【{$shop->merchantName} {$shop->shopName}】 充值{$amount}元 订单号:{$order->orderSn}";
- if ($order->shopAdminId == 0) {
- $event = "系统为【{$shop->merchantName} {$shop->shopName}】 充值{$amount}元 订单号:{$order->orderSn}";
- }
- $change = [
- 'relateId' => $id,
- 'capitalType' => $capitalType,
- 'amount' => $amount,
- 'balance' => $currentAmount,
- 'txBalance' => $currentTxBalance,
- 'io' => 1,
- 'payWay' => $order->payWay,
- 'event' => $event,
- 'sjId' => $order->sjId,
- 'shopId' => $order->shopId,
- 'tx' => $tx,
- 'ptStyle' => $ptStyle,
- 'shopName' => $shop->shopName,
- 'sjName' => $shop->merchantName,
- ];
- PtYeChangeClass::addChange($change, true);
- }
- //平台余额增加 shish 20210519
- public static function reduceBalance($shop, $amount, $order, $capitalType, $tx)
- {
- $ptStyle = $shop->ptStyle;
- if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
- $asset = self::getHdBalance();
- } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
- $asset = self::getGhsBalance();
- } else {
- util::fail('没有找到平台');
- }
- if (bccomp($amount, $asset->amount, 2) == 1) {
- util::fail('平台余额不足');
- }
- $currentAmount = bcsub($asset->amount, $amount, 2);
- $asset->amount = $currentAmount;
- $asset->save();
- if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
- $txAsset = self::getHdTxBalance();
- } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
- $txAsset = self::getGhsTxBalance();
- } else {
- util::fail('没有找到平台');
- }
- $currentTxBalance = $txAsset->amount;
- if ($tx == dict::getDict('yeTx', 'can')) {
- if (!empty($currentTxBalance)) {
- $reduceTxBalance = $currentTxBalance > $amount ? $amount : $currentTxBalance;
- $currentTxBalance = bcsub($currentTxBalance, $reduceTxBalance, 2);
- $txAsset->amount = $currentTxBalance;
- $txAsset->save();
- }
- }
- $id = $order->id;
- $change = [
- 'relateId' => $id,
- 'capitalType' => $capitalType,
- 'amount' => $amount,
- 'balance' => $currentAmount,
- 'txBalance' => $currentTxBalance,
- 'io' => 0,
- 'payWay' => $order->payWay,
- 'event' => "【{$shop->merchantName} {$shop->shopName}】 {$amount}元 订单号:{$order->orderSn}",
- 'sjId' => $order->sjId,
- 'shopId' => $order->shopId,
- 'tx' => $tx,
- 'ptStyle' => $ptStyle,
- 'shopName' => $shop->shopName,
- 'sjName' => $shop->merchantName,
- ];
- PtYeChangeClass::addChange($change, true);
- }
- //零售平台余额对象 shish 20210519
- public static function getHdBalance()
- {
- $hd = dict::getDict('ptAsset', 'hdBalance');
- $id = $hd['id'];
- $name = $hd['name'];
- $asset = self::getLockById($id);
- if (empty($asset)) {
- $data = ['id' => $id, 'name' => $name, 'amount' => 0.00];
- self::add($data);
- $asset = self::getLockById($id);
- if (empty($asset)) {
- util::fail('没有找到零售平台余额,请先创建');
- }
- }
- return $asset;
- }
- //供应商平台余额对象 shish 20210519
- public static function getGhsBalance()
- {
- $ghs = dict::getDict('ptAsset', 'ghsBalance');
- $id = $ghs['id'];
- $name = $ghs['name'];
- $asset = self::getLockById($id);
- if (empty($asset)) {
- $data = ['id' => $id, 'name' => $name, 'amount' => 0.00];
- self::add($data);
- $asset = self::getLockById($id);
- if (empty($asset)) {
- util::fail('没有找到供应商平台余额,请先创建');
- }
- }
- return $asset;
- }
- //零售平台余额对象 shish 20210519
- public static function getHdTxBalance()
- {
- $txHd = dict::getDict('ptAsset', 'hdTxBalance');
- $id = $txHd['id'];
- $name = $txHd['name'];
- $asset = self::getLockById($id);
- if (empty($asset)) {
- $data = ['id' => $id, 'name' => $name, 'amount' => 0.00];
- self::add($data);
- $asset = self::getLockById($id);
- if (empty($asset)) {
- util::fail('没有找到零售平台可提现余额,请先创建');
- }
- }
- return $asset;
- }
- //供应商平台余额对象 shish 20210519
- public static function getGhsTxBalance()
- {
- $txGhs = dict::getDict('ptAsset', 'ghsTxBalance');
- $id = $txGhs['id'];
- $name = $txGhs['name'];
- $asset = self::getLockById($id);
- if (empty($asset)) {
- $data = ['id' => $id, 'name' => $name, 'amount' => 0.00];
- self::add($data);
- $asset = self::getLockById($id);
- if (empty($asset)) {
- util::fail('没有找到供应商平台可提现余额,请先创建');
- }
- }
- return $asset;
- }
- }
|