PtAssetClass.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  1. <?php
  2. namespace biz\pt\classes;
  3. use biz\base\classes\BaseClass;
  4. use bizGhs\order\classes\OrderClass;
  5. use common\components\dict;
  6. use common\components\util;
  7. class PtAssetClass extends BaseClass
  8. {
  9. public static $baseFile = '\biz\pt\models\PtAsset';
  10. //客户下单增加商家余额 ssh 20210520
  11. public static function customKdAddBalance($shop, $amount, $order, $capitalType, $tx)
  12. {
  13. $ptStyle = $shop->ptStyle;
  14. if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
  15. $asset = self::getHdBalance();
  16. } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
  17. $asset = self::getGhsBalance();
  18. } else {
  19. util::fail('没有找到平台');
  20. }
  21. $currentAmount = bcadd($asset->amount, $amount, 2);
  22. $asset->amount = $currentAmount;
  23. $asset->save();
  24. if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
  25. $txAsset = self::getHdTxBalance();
  26. } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
  27. $txAsset = self::getGhsTxBalance();
  28. } else {
  29. util::fail('没有找到平台');
  30. }
  31. $currentTxBalance = $txAsset->amount;
  32. $currentTxBalance = bcadd($currentTxBalance, $amount, 2);
  33. $txAsset->amount = $currentTxBalance;
  34. $txAsset->save();
  35. $id = $order->id;
  36. $mainId = $shop->mainId ?? 0;
  37. $event = "【{$shop->merchantName} {$shop->shopName}】的客户下单购买 {$amount}元 订单号:{$order->orderSn}";
  38. $change = [
  39. 'relateId' => $id,
  40. 'capitalType' => $capitalType,
  41. 'amount' => $amount,
  42. 'balance' => $currentAmount,
  43. 'txBalance' => $currentTxBalance,
  44. 'io' => 1,
  45. 'payWay' => $order->payWay,
  46. 'event' => $event,
  47. 'mainId' => $mainId,
  48. 'tx' => $tx,
  49. 'ptStyle' => $ptStyle,
  50. 'shopName' => $shop->shopName,
  51. 'sjName' => $shop->merchantName,
  52. ];
  53. PtYeChangeClass::addChange($change, true);
  54. }
  55. //客户结帐增加加余额 ssh 20210729
  56. public static function customClearAddBalance($shop, $order, $capitalType, $tx)
  57. {
  58. $amount = $order->actPrice ?? 0;
  59. $ptStyle = $shop->ptStyle;
  60. if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
  61. $asset = self::getHdBalance();
  62. } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
  63. $asset = self::getGhsBalance();
  64. } else {
  65. util::fail('没有找到平台');
  66. }
  67. $currentAmount = bcadd($asset->amount, $amount, 2);
  68. $asset->amount = $currentAmount;
  69. $asset->save();
  70. if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
  71. $txAsset = self::getHdTxBalance();
  72. } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
  73. $txAsset = self::getGhsTxBalance();
  74. } else {
  75. util::fail('没有找到平台');
  76. }
  77. $currentTxBalance = $txAsset->amount;
  78. if ($tx == dict::getDict('yeTx', 'can')) {
  79. $currentTxBalance = bcadd($currentTxBalance, $amount, 2);
  80. $txAsset->amount = $currentTxBalance;
  81. $txAsset->save();
  82. }
  83. $sjName = $shop->merchantName ?? '';
  84. if (isset($shop->default) == false || $shop->default != 1) {
  85. $sjName .= ' ' . $shop->shopName;
  86. }
  87. $id = $order->id;
  88. $event = "客户结帐给商家-{$sjName}(单号:{$order->orderSn})";
  89. $mainId = $shop->mainId ?? 0;
  90. $change = [
  91. 'relateId' => $id,
  92. 'capitalType' => $capitalType,
  93. 'amount' => $amount,
  94. 'balance' => $currentAmount,
  95. 'txBalance' => $currentTxBalance,
  96. 'io' => 1,
  97. 'payWay' => $order->payWay,
  98. 'event' => $event,
  99. 'sjId' => $order->sjId,
  100. 'shopId' => $order->shopId,
  101. 'mainId' => $order->mainId ?? 0,
  102. 'tx' => $tx,
  103. 'ptStyle' => $ptStyle,
  104. 'shopName' => $shop->shopName,
  105. 'sjName' => $shop->merchantName,
  106. 'mainId' => $mainId,
  107. ];
  108. PtYeChangeClass::addChange($change, true);
  109. }
  110. //客户使用优惠券增加余额 ssh 20210601
  111. public static function customKdUseCouponAddBalance($shop, $order, $capitalType, $tx)
  112. {
  113. $amount = $order->discountAmount;
  114. $ptStyle = $shop->ptStyle;
  115. if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
  116. $asset = self::getHdBalance();
  117. } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
  118. $asset = self::getGhsBalance();
  119. } else {
  120. util::fail('没有找到平台');
  121. }
  122. $currentAmount = bcadd($asset->amount, $amount, 2);
  123. $asset->amount = $currentAmount;
  124. $asset->save();
  125. if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
  126. $txAsset = self::getHdTxBalance();
  127. } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
  128. $txAsset = self::getGhsTxBalance();
  129. } else {
  130. util::fail('没有找到平台');
  131. }
  132. $currentTxBalance = $txAsset->amount;
  133. $currentTxBalance = bcadd($currentTxBalance, $amount, 2);
  134. $txAsset->amount = $currentTxBalance;
  135. $txAsset->save();
  136. $id = $order->id;
  137. $mainId = $shop->mainId ?? 0;
  138. $event = "【{$shop->merchantName} {$shop->shopName}】的客户下单(使用平台优惠券{$amount}元) 订单号:{$order->orderSn}";
  139. $change = [
  140. 'relateId' => $id,
  141. 'capitalType' => $capitalType,
  142. 'amount' => $amount,
  143. 'balance' => $currentAmount,
  144. 'txBalance' => $currentTxBalance,
  145. 'io' => 1,
  146. 'payWay' => $order->payWay,
  147. 'event' => $event,
  148. 'mainId' => $mainId,
  149. 'tx' => $tx,
  150. 'ptStyle' => $ptStyle,
  151. 'shopName' => $shop->shopName,
  152. 'sjName' => $shop->merchantName,
  153. ];
  154. PtYeChangeClass::addChange($change, true);
  155. }
  156. //平台余额增加 ssh 20210519
  157. public static function rechargeAddBalance($shop, $amount, $order, $capitalType, $tx)
  158. {
  159. $ptStyle = $shop->ptStyle;
  160. if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
  161. $asset = self::getHdBalance();
  162. } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
  163. $asset = self::getGhsBalance();
  164. } else {
  165. util::fail('没有找到平台');
  166. }
  167. $currentAmount = bcadd($asset->amount, $amount, 2);
  168. $asset->amount = $currentAmount;
  169. $asset->save();
  170. if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
  171. $txAsset = self::getHdTxBalance();
  172. } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
  173. $txAsset = self::getGhsTxBalance();
  174. } else {
  175. util::fail('没有找到平台');
  176. }
  177. $currentTxBalance = $txAsset->amount;
  178. if ($tx == dict::getDict('yeTx', 'can')) {
  179. $currentTxBalance = bcadd($currentTxBalance, $amount, 2);
  180. $txAsset->amount = $currentTxBalance;
  181. $txAsset->save();
  182. }
  183. $id = $order->id;
  184. $mainId = $shop->mainId ?? 0;
  185. $event = "【{$shop->merchantName} {$shop->shopName}】 充值{$amount}元 订单号:{$order->orderSn}";
  186. if ($order->shopAdminId == 0) {
  187. $event = "系统为【{$shop->merchantName} {$shop->shopName}】 充值{$amount}元 订单号:{$order->orderSn}";
  188. }
  189. $change = [
  190. 'relateId' => $id,
  191. 'capitalType' => $capitalType,
  192. 'amount' => $amount,
  193. 'balance' => $currentAmount,
  194. 'txBalance' => $currentTxBalance,
  195. 'io' => 1,
  196. 'payWay' => $order->payWay,
  197. 'event' => $event,
  198. 'sjId' => $order->sjId,
  199. 'shopId' => $order->shopId,
  200. 'mainId' => $mainId,
  201. 'tx' => $tx,
  202. 'ptStyle' => $ptStyle,
  203. 'shopName' => $shop->shopName,
  204. 'sjName' => $shop->merchantName,
  205. ];
  206. PtYeChangeClass::addChange($change, true);
  207. }
  208. //平台余额减少 ssh 20210519
  209. public static function reduceBalance($shop, $amount, $order, $capitalType, $tx)
  210. {
  211. $ptStyle = $shop->ptStyle;
  212. if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
  213. $asset = self::getHdBalance();
  214. } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
  215. $asset = self::getGhsBalance();
  216. } else {
  217. util::fail('没有找到平台');
  218. }
  219. if (bccomp($amount, $asset->amount, 2) == 1) {
  220. //util::fail('平台余额不足哦');
  221. }
  222. $currentAmount = bcsub($asset->amount, $amount, 2);
  223. $asset->amount = $currentAmount;
  224. $asset->save();
  225. if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
  226. $txAsset = self::getHdTxBalance();
  227. } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
  228. $txAsset = self::getGhsTxBalance();
  229. } else {
  230. util::fail('没有找到平台');
  231. }
  232. $currentTxBalance = $txAsset->amount;
  233. if ($tx == dict::getDict('yeTx', 'can')) {
  234. if (!empty($currentTxBalance)) {
  235. $reduceTxBalance = $currentTxBalance > $amount ? $amount : $currentTxBalance;
  236. $currentTxBalance = bcsub($currentTxBalance, $reduceTxBalance, 2);
  237. $txAsset->amount = $currentTxBalance;
  238. $txAsset->save();
  239. }
  240. }
  241. $id = $order->id;
  242. $change = [
  243. 'relateId' => $id,
  244. 'capitalType' => $capitalType,
  245. 'amount' => $amount,
  246. 'balance' => $currentAmount,
  247. 'txBalance' => $currentTxBalance,
  248. 'io' => 0,
  249. 'payWay' => $order->payWay,
  250. 'event' => "【{$shop->merchantName} {$shop->shopName}】 {$amount}元 订单号:{$order->orderSn}",
  251. 'sjId' => $order->sjId,
  252. 'shopId' => $order->shopId,
  253. 'mainId' => $order->mainId ?? 0,
  254. 'tx' => $tx,
  255. 'ptStyle' => $ptStyle,
  256. 'shopName' => $shop->shopName,
  257. 'sjName' => $shop->merchantName,
  258. ];
  259. PtYeChangeClass::addChange($change, true);
  260. }
  261. //供应商预订被多付了退款减少余额 ssh 20220324
  262. public static function ghsBookOrderRefundReduceBalance($shop, $refund, $refundPrice)
  263. {
  264. $ptStyle = $shop->ptStyle;
  265. $asset = null;
  266. if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
  267. $asset = self::getHdBalance();
  268. } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
  269. $asset = self::getGhsBalance();
  270. } else {
  271. util::fail('没有找到平台');
  272. }
  273. if (bccomp($refundPrice, $asset->amount, 2) == 1) {
  274. //util::fail('平台余额不足!');
  275. }
  276. $currentAmount = bcsub($asset->amount, $refundPrice, 2);
  277. $asset->amount = $currentAmount;
  278. $asset->save();
  279. $txAsset = null;
  280. if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
  281. $txAsset = self::getHdTxBalance();
  282. } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
  283. $txAsset = self::getGhsTxBalance();
  284. } else {
  285. util::fail('没有找到平台');
  286. }
  287. $tx = dict::getDict('yeTx', 'can');
  288. $currentTxBalance = $txAsset->amount;
  289. if (!empty($currentTxBalance)) {
  290. $reduceTxBalance = $currentTxBalance > $refundPrice ? $refundPrice : $currentTxBalance;
  291. $currentTxBalance = bcsub($currentTxBalance, $reduceTxBalance, 2);
  292. $txAsset->amount = $currentTxBalance;
  293. $txAsset->save();
  294. }
  295. $merchantName = $shop->merchantName ?? '';
  296. if ($shop->default != 1) {
  297. $shopName = $shop->shopName ?? '';
  298. $merchantName = $merchantName . '-' . $shopName;
  299. }
  300. $event = "{$merchantName} 预订单被多付退还(退款单 {$refund->orderSn} 订单{$refund->relateOrderSn})";
  301. $relateOrderSn = $refund->relateOrderSn ?? '';
  302. if (!empty($relateOrderSn)) {
  303. $relateOrder = OrderClass::getByCondition(['orderSn' => $relateOrderSn], true);
  304. $customName = $relateOrder->customName ?? '';
  305. if (!empty($customName)) {
  306. $event = "{$merchantName} 的预订单被{$customName}多付退还(退款单 {$refund->orderSn} 订单{$refund->relateOrderSn})";
  307. }
  308. }
  309. $id = $refund->id;
  310. $currentType = dict::getDict('capitalType', 'ghsBookRefund');
  311. $change = [
  312. 'relateId' => $id,
  313. 'capitalType' => $currentType,
  314. 'amount' => $refundPrice,
  315. 'balance' => $currentAmount,
  316. 'txBalance' => $currentTxBalance,
  317. 'io' => 0,
  318. 'payWay' => 0,
  319. 'event' => $event,
  320. 'sjId' => $shop->sjId,
  321. 'shopId' => $shop->id,
  322. 'mainId' => $shop->mainId,
  323. 'tx' => $tx,
  324. 'ptStyle' => $ptStyle,
  325. 'shopName' => $shop->shopName,
  326. 'sjName' => $shop->merchantName,
  327. ];
  328. PtYeChangeClass::addChange($change, true);
  329. }
  330. public static function hdSaleRefundReduceBalance($shop, $refund, $refundPrice)
  331. {
  332. $ptStyle = $shop->ptStyle;
  333. $asset = null;
  334. if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
  335. $asset = self::getHdBalance();
  336. } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
  337. $asset = self::getGhsBalance();
  338. } else {
  339. util::fail('没有找到平台');
  340. }
  341. if (bccomp($refundPrice, $asset->amount, 2) == 1) {
  342. //util::fail('平台余额不足呢');
  343. }
  344. $currentAmount = bcsub($asset->amount, $refundPrice, 2);
  345. $asset->amount = $currentAmount;
  346. $asset->save();
  347. $txAsset = null;
  348. if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
  349. $txAsset = self::getHdTxBalance();
  350. } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
  351. $txAsset = self::getGhsTxBalance();
  352. } else {
  353. util::fail('没有找到平台');
  354. }
  355. $tx = dict::getDict('yeTx', 'can');
  356. $currentTxBalance = $txAsset->amount;
  357. if (!empty($currentTxBalance)) {
  358. $reduceTxBalance = $currentTxBalance > $refundPrice ? $refundPrice : $currentTxBalance;
  359. $currentTxBalance = bcsub($currentTxBalance, $reduceTxBalance, 2);
  360. $txAsset->amount = $currentTxBalance;
  361. $txAsset->save();
  362. }
  363. $id = $refund->id;
  364. $currentType = dict::getDict('capitalType', 'hdOrderRefund');
  365. $change = [
  366. 'relateId' => $id,
  367. 'capitalType' => $currentType,
  368. 'amount' => $refundPrice,
  369. 'balance' => $currentAmount,
  370. 'txBalance' => $currentTxBalance,
  371. 'io' => 0,
  372. 'payWay' => 0,
  373. 'event' => "【{$shop->merchantName} {$shop->shopName}】的销售单发起退款",
  374. 'sjId' => $shop->sjId,
  375. 'shopId' => $shop->id,
  376. 'mainId' => $shop->mainId,
  377. 'tx' => $tx,
  378. 'ptStyle' => $ptStyle,
  379. 'shopName' => $shop->shopName,
  380. 'sjName' => $shop->merchantName,
  381. ];
  382. PtYeChangeClass::addChange($change, true);
  383. }
  384. public static function saleRefundReduceBalance($shop, $refund, $refundPrice)
  385. {
  386. $ptStyle = $shop->ptStyle;
  387. $asset = null;
  388. if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
  389. $asset = self::getHdBalance();
  390. } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
  391. $asset = self::getGhsBalance();
  392. } else {
  393. util::fail('没有找到平台');
  394. }
  395. if (bccomp($refundPrice, $asset->amount, 2) == 1) {
  396. //util::fail('平台余额不足哈');
  397. }
  398. $currentAmount = bcsub($asset->amount, $refundPrice, 2);
  399. $asset->amount = $currentAmount;
  400. $asset->save();
  401. $txAsset = null;
  402. if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
  403. $txAsset = self::getHdTxBalance();
  404. } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
  405. $txAsset = self::getGhsTxBalance();
  406. } else {
  407. util::fail('没有找到平台');
  408. }
  409. $tx = dict::getDict('yeTx', 'can');
  410. $currentTxBalance = $txAsset->amount;
  411. if (!empty($currentTxBalance)) {
  412. $reduceTxBalance = $currentTxBalance > $refundPrice ? $refundPrice : $currentTxBalance;
  413. $currentTxBalance = bcsub($currentTxBalance, $reduceTxBalance, 2);
  414. $txAsset->amount = $currentTxBalance;
  415. $txAsset->save();
  416. }
  417. $id = $refund->id;
  418. $currentType = dict::getDict('capitalType', 'saleRefund');
  419. $change = [
  420. 'relateId' => $id,
  421. 'capitalType' => $currentType,
  422. 'amount' => $refundPrice,
  423. 'balance' => $currentAmount,
  424. 'txBalance' => $currentTxBalance,
  425. 'io' => 0,
  426. 'payWay' => 0,
  427. 'event' => "【{$shop->merchantName} {$shop->shopName}】 的销售单发起退款",
  428. 'sjId' => $shop->sjId,
  429. 'shopId' => $shop->id,
  430. 'mainId' => $shop->mainId,
  431. 'tx' => $tx,
  432. 'ptStyle' => $ptStyle,
  433. 'shopName' => $shop->shopName,
  434. 'sjName' => $shop->merchantName,
  435. ];
  436. PtYeChangeClass::addChange($change, true);
  437. }
  438. //零售平台余额对象 ssh 20210519
  439. public static function getHdBalance()
  440. {
  441. $hd = dict::getDict('ptAsset', 'hdBalance');
  442. $id = $hd['id'];
  443. $name = $hd['name'];
  444. $asset = self::getLockById($id);
  445. if (empty($asset)) {
  446. $data = ['id' => $id, 'name' => $name, 'amount' => 0.00];
  447. self::add($data);
  448. $asset = self::getLockById($id);
  449. if (empty($asset)) {
  450. util::fail('没有找到零售平台余额,请先创建');
  451. }
  452. }
  453. return $asset;
  454. }
  455. //供应商平台余额对象 ssh 20210519
  456. public static function getGhsBalance()
  457. {
  458. $ghs = dict::getDict('ptAsset', 'ghsBalance');
  459. $id = $ghs['id'];
  460. $name = $ghs['name'];
  461. $asset = self::getLockById($id);
  462. if (empty($asset)) {
  463. $data = ['id' => $id, 'name' => $name, 'amount' => 0.00];
  464. self::add($data);
  465. $asset = self::getLockById($id);
  466. if (empty($asset)) {
  467. util::fail('没有找到供应商平台余额,请先创建');
  468. }
  469. }
  470. return $asset;
  471. }
  472. //零售平台余额对象 ssh 20210519
  473. public static function getHdTxBalance()
  474. {
  475. $txHd = dict::getDict('ptAsset', 'hdTxBalance');
  476. $id = $txHd['id'];
  477. $name = $txHd['name'];
  478. $asset = self::getLockById($id);
  479. if (empty($asset)) {
  480. $data = ['id' => $id, 'name' => $name, 'amount' => 0.00];
  481. self::add($data);
  482. $asset = self::getLockById($id);
  483. if (empty($asset)) {
  484. util::fail('没有找到零售平台可提现余额,请先创建');
  485. }
  486. }
  487. return $asset;
  488. }
  489. //供应商平台余额对象 ssh 20210519
  490. public static function getGhsTxBalance()
  491. {
  492. $txGhs = dict::getDict('ptAsset', 'ghsTxBalance');
  493. $id = $txGhs['id'];
  494. $name = $txGhs['name'];
  495. $asset = self::getLockById($id);
  496. if (empty($asset)) {
  497. $data = ['id' => $id, 'name' => $name, 'amount' => 0.00];
  498. self::add($data);
  499. $asset = self::getLockById($id);
  500. if (empty($asset)) {
  501. util::fail('没有找到供应商平台可提现余额,请先创建');
  502. }
  503. }
  504. return $asset;
  505. }
  506. //零售采购退款
  507. public static function cgRefundAddBalance($shop, $refundPrice, $cgRefund, $currentType, $tx)
  508. {
  509. $ptStyle = $shop->ptStyle;
  510. $asset = null;
  511. if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
  512. $asset = PtAssetClass::getHdBalance();
  513. } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
  514. $asset = PtAssetClass::getGhsBalance();
  515. } else {
  516. util::fail('没有找到平台');
  517. }
  518. $currentPtBalance = bcadd($asset->amount, $refundPrice, 2);
  519. $asset->amount = $currentPtBalance;
  520. $asset->save();
  521. $txAsset = null;
  522. if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
  523. $txAsset = PtAssetClass::getHdTxBalance();
  524. } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
  525. $txAsset = PtAssetClass::getGhsTxBalance();
  526. } else {
  527. util::fail('没有找到平台');
  528. }
  529. $currentPtTxBalance = $txAsset->amount;
  530. $id = $cgRefund->id;
  531. $sjId = $shop->sjId;
  532. $shopId = $shop->id;
  533. $mainId = $shop->mainId ?? 0;
  534. $change = [
  535. 'relateId' => $id,
  536. 'capitalType' => $currentType,
  537. 'amount' => $refundPrice,
  538. 'balance' => $currentPtBalance,
  539. 'txBalance' => $currentPtTxBalance,
  540. 'io' => 1,
  541. 'payWay' => 0,
  542. 'event' => "【{$shop->merchantName} {$shop->shopName}】的采购被退款",
  543. 'sjId' => $sjId,
  544. 'shopId' => $shopId,
  545. 'mainId' => $mainId,
  546. 'tx' => $tx,
  547. 'ptStyle' => $ptStyle,
  548. 'shopName' => $shop->shopName,
  549. 'sjName' => $shop->merchantName,
  550. ];
  551. PtYeChangeClass::addChange($change, true);
  552. }
  553. }