|
|
@@ -0,0 +1,133 @@
|
|
|
+<?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 20210519
|
|
|
+ public static function addBalance($shop, $amount, $order, $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;
|
|
|
+ $capitalType = $order->capitalType;
|
|
|
+ $change = [
|
|
|
+ 'relateId' => $id,
|
|
|
+ 'capitalType' => $capitalType,
|
|
|
+ 'amount' => $order->actPrice,
|
|
|
+ 'balance' => $currentAmount,
|
|
|
+ 'txBalance' => $currentTxBalance,
|
|
|
+ 'io' => 1,
|
|
|
+ 'payWay' => $order->payWay,
|
|
|
+ 'event' => "商家 {$shop->merchantName} {$shop->shopName} 充值(订单:{$order->orderSn})",
|
|
|
+ 'sjId' => $order->sjId,
|
|
|
+ 'shopId' => $order->shopId,
|
|
|
+ 'tx' => $tx,
|
|
|
+ ];
|
|
|
+ PtYeChangeClass::addChange($change, true);
|
|
|
+ }
|
|
|
+
|
|
|
+ //零售平台余额对象 shish 20210519
|
|
|
+ public static function getHdBalance()
|
|
|
+ {
|
|
|
+ $hd = dict::getDict('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('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('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('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;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|