PtAssetClass.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  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 20240508
  56. public static function customRechargeAddBalance($shop, $order, $capitalType, $tx)
  57. {
  58. $amount = $order->amount ?? 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 || $shop->shopName != '首店') {
  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 ?? 0,
  100. 'shopId' => $order->shopId ?? 0,
  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 20210729
  111. public static function customClearAddBalance($shop, $order, $capitalType, $tx)
  112. {
  113. $amount = $order->actPrice ?? 0;
  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. if ($tx == dict::getDict('yeTx', 'can')) {
  134. $currentTxBalance = bcadd($currentTxBalance, $amount, 2);
  135. $txAsset->amount = $currentTxBalance;
  136. $txAsset->save();
  137. }
  138. $sjName = $shop->merchantName ?? '';
  139. if (isset($shop->default) == false || $shop->default != 1 || $shop->shopName != '首店') {
  140. $sjName .= ' ' . $shop->shopName;
  141. }
  142. $id = $order->id;
  143. $event = "客户结帐给商家-{$sjName}(单号:{$order->orderSn})";
  144. $mainId = $shop->mainId ?? 0;
  145. $change = [
  146. 'relateId' => $id,
  147. 'capitalType' => $capitalType,
  148. 'amount' => $amount,
  149. 'balance' => $currentAmount,
  150. 'txBalance' => $currentTxBalance,
  151. 'io' => 1,
  152. 'payWay' => $order->payWay,
  153. 'event' => $event,
  154. 'sjId' => $order->sjId,
  155. 'shopId' => $order->shopId,
  156. 'mainId' => $order->mainId ?? 0,
  157. 'tx' => $tx,
  158. 'ptStyle' => $ptStyle,
  159. 'shopName' => $shop->shopName,
  160. 'sjName' => $shop->merchantName,
  161. 'mainId' => $mainId,
  162. ];
  163. PtYeChangeClass::addChange($change, true);
  164. }
  165. //客户使用优惠券增加余额 ssh 20210601
  166. public static function customKdUseCouponAddBalance($shop, $order, $capitalType, $tx)
  167. {
  168. $amount = $order->discountAmount;
  169. $ptStyle = $shop->ptStyle;
  170. if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
  171. $asset = self::getHdBalance();
  172. } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
  173. $asset = self::getGhsBalance();
  174. } else {
  175. util::fail('没有找到平台');
  176. }
  177. $currentAmount = bcadd($asset->amount, $amount, 2);
  178. $asset->amount = $currentAmount;
  179. $asset->save();
  180. if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
  181. $txAsset = self::getHdTxBalance();
  182. } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
  183. $txAsset = self::getGhsTxBalance();
  184. } else {
  185. util::fail('没有找到平台');
  186. }
  187. $currentTxBalance = $txAsset->amount;
  188. $currentTxBalance = bcadd($currentTxBalance, $amount, 2);
  189. $txAsset->amount = $currentTxBalance;
  190. $txAsset->save();
  191. $id = $order->id;
  192. $mainId = $shop->mainId ?? 0;
  193. $event = "【{$shop->merchantName} {$shop->shopName}】的客户下单(使用平台优惠券{$amount}元) 订单号:{$order->orderSn}";
  194. $change = [
  195. 'relateId' => $id,
  196. 'capitalType' => $capitalType,
  197. 'amount' => $amount,
  198. 'balance' => $currentAmount,
  199. 'txBalance' => $currentTxBalance,
  200. 'io' => 1,
  201. 'payWay' => $order->payWay,
  202. 'event' => $event,
  203. 'mainId' => $mainId,
  204. 'tx' => $tx,
  205. 'ptStyle' => $ptStyle,
  206. 'shopName' => $shop->shopName,
  207. 'sjName' => $shop->merchantName,
  208. ];
  209. PtYeChangeClass::addChange($change, true);
  210. }
  211. //平台余额增加 ssh 20210519
  212. public static function rechargeAddBalance($shop, $amount, $order, $capitalType, $tx)
  213. {
  214. $ptStyle = $shop->ptStyle;
  215. if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
  216. $asset = self::getHdBalance();
  217. } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
  218. $asset = self::getGhsBalance();
  219. } else {
  220. util::fail('没有找到平台');
  221. }
  222. $currentAmount = bcadd($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. $currentTxBalance = bcadd($currentTxBalance, $amount, 2);
  235. $txAsset->amount = $currentTxBalance;
  236. $txAsset->save();
  237. }
  238. $id = $order->id;
  239. $mainId = $shop->mainId ?? 0;
  240. $event = "【{$shop->merchantName} {$shop->shopName}】 充值{$amount}元 订单号:{$order->orderSn}";
  241. if ($order->shopAdminId == 0) {
  242. $event = "系统为【{$shop->merchantName} {$shop->shopName}】 充值{$amount}元 订单号:{$order->orderSn}";
  243. }
  244. $change = [
  245. 'relateId' => $id,
  246. 'capitalType' => $capitalType,
  247. 'amount' => $amount,
  248. 'balance' => $currentAmount,
  249. 'txBalance' => $currentTxBalance,
  250. 'io' => 1,
  251. 'payWay' => $order->payWay,
  252. 'event' => $event,
  253. 'sjId' => $order->sjId,
  254. 'shopId' => $order->shopId,
  255. 'mainId' => $mainId,
  256. 'tx' => $tx,
  257. 'ptStyle' => $ptStyle,
  258. 'shopName' => $shop->shopName,
  259. 'sjName' => $shop->merchantName,
  260. ];
  261. PtYeChangeClass::addChange($change, true);
  262. }
  263. //平台余额减少 ssh 20210519
  264. public static function reduceBalance($shop, $amount, $order, $capitalType, $tx)
  265. {
  266. $ptStyle = $shop->ptStyle;
  267. if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
  268. $asset = self::getHdBalance();
  269. } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
  270. $asset = self::getGhsBalance();
  271. } else {
  272. util::fail('没有找到平台');
  273. }
  274. if (bccomp($amount, $asset->amount, 2) == 1) {
  275. //util::fail('平台余额不足哦');
  276. }
  277. $currentAmount = bcsub($asset->amount, $amount, 2);
  278. $asset->amount = $currentAmount;
  279. $asset->save();
  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. $currentTxBalance = $txAsset->amount;
  288. if ($tx == dict::getDict('yeTx', 'can')) {
  289. if (!empty($currentTxBalance)) {
  290. $reduceTxBalance = $currentTxBalance > $amount ? $amount : $currentTxBalance;
  291. $currentTxBalance = bcsub($currentTxBalance, $reduceTxBalance, 2);
  292. $txAsset->amount = $currentTxBalance;
  293. $txAsset->save();
  294. }
  295. }
  296. $id = $order->id;
  297. $change = [
  298. 'relateId' => $id,
  299. 'capitalType' => $capitalType,
  300. 'amount' => $amount,
  301. 'balance' => $currentAmount,
  302. 'txBalance' => $currentTxBalance,
  303. 'io' => 0,
  304. 'payWay' => $order->payWay,
  305. 'event' => "【{$shop->merchantName} {$shop->shopName}】 {$amount}元 订单号:{$order->orderSn}",
  306. 'sjId' => $order->sjId,
  307. 'shopId' => $order->shopId,
  308. 'mainId' => $order->mainId ?? 0,
  309. 'tx' => $tx,
  310. 'ptStyle' => $ptStyle,
  311. 'shopName' => $shop->shopName,
  312. 'sjName' => $shop->merchantName,
  313. ];
  314. PtYeChangeClass::addChange($change, true);
  315. }
  316. //供货商预订被多付了退款减少余额 ssh 20220324
  317. public static function ghsBookOrderRefundReduceBalance($shop, $refund, $refundPrice)
  318. {
  319. $ptStyle = $shop->ptStyle;
  320. $asset = null;
  321. if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
  322. $asset = self::getHdBalance();
  323. } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
  324. $asset = self::getGhsBalance();
  325. } else {
  326. util::fail('没有找到平台');
  327. }
  328. if (bccomp($refundPrice, $asset->amount, 2) == 1) {
  329. //util::fail('平台余额不足!');
  330. }
  331. $currentAmount = bcsub($asset->amount, $refundPrice, 2);
  332. $asset->amount = $currentAmount;
  333. $asset->save();
  334. $txAsset = null;
  335. if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
  336. $txAsset = self::getHdTxBalance();
  337. } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
  338. $txAsset = self::getGhsTxBalance();
  339. } else {
  340. util::fail('没有找到平台');
  341. }
  342. $tx = dict::getDict('yeTx', 'can');
  343. $currentTxBalance = $txAsset->amount;
  344. if (!empty($currentTxBalance)) {
  345. $reduceTxBalance = $currentTxBalance > $refundPrice ? $refundPrice : $currentTxBalance;
  346. $currentTxBalance = bcsub($currentTxBalance, $reduceTxBalance, 2);
  347. $txAsset->amount = $currentTxBalance;
  348. $txAsset->save();
  349. }
  350. $merchantName = $shop->merchantName ?? '';
  351. if ($shop->default != 1 || $shop->shopName != '首店') {
  352. $shopName = $shop->shopName ?? '';
  353. $merchantName = $merchantName . '-' . $shopName;
  354. }
  355. $event = "{$merchantName} 预订单被多付退还(退款单 {$refund->orderSn} 订单{$refund->relateOrderSn})";
  356. $relateOrderSn = $refund->relateOrderSn ?? '';
  357. if (!empty($relateOrderSn)) {
  358. $relateOrder = OrderClass::getByCondition(['orderSn' => $relateOrderSn], true);
  359. $customName = $relateOrder->customName ?? '';
  360. if (!empty($customName)) {
  361. $event = "{$merchantName} 的预订单被{$customName}多付退还(退款单 {$refund->orderSn} 订单{$refund->relateOrderSn})";
  362. }
  363. }
  364. $id = $refund->id;
  365. $currentType = dict::getDict('capitalType', 'ghsBookRefund');
  366. $change = [
  367. 'relateId' => $id,
  368. 'capitalType' => $currentType,
  369. 'amount' => $refundPrice,
  370. 'balance' => $currentAmount,
  371. 'txBalance' => $currentTxBalance,
  372. 'io' => 0,
  373. 'payWay' => 0,
  374. 'event' => $event,
  375. 'sjId' => $shop->sjId,
  376. 'shopId' => $shop->id,
  377. 'mainId' => $shop->mainId,
  378. 'tx' => $tx,
  379. 'ptStyle' => $ptStyle,
  380. 'shopName' => $shop->shopName,
  381. 'sjName' => $shop->merchantName,
  382. ];
  383. PtYeChangeClass::addChange($change, true);
  384. }
  385. public static function hdSaleRefundReduceBalance($shop, $refund, $refundPrice)
  386. {
  387. $ptStyle = $shop->ptStyle;
  388. $asset = null;
  389. if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
  390. $asset = self::getHdBalance();
  391. } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
  392. $asset = self::getGhsBalance();
  393. } else {
  394. util::fail('没有找到平台');
  395. }
  396. if (bccomp($refundPrice, $asset->amount, 2) == 1) {
  397. //util::fail('平台余额不足呢');
  398. }
  399. $currentAmount = bcsub($asset->amount, $refundPrice, 2);
  400. $asset->amount = $currentAmount;
  401. $asset->save();
  402. $txAsset = null;
  403. if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
  404. $txAsset = self::getHdTxBalance();
  405. } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
  406. $txAsset = self::getGhsTxBalance();
  407. } else {
  408. util::fail('没有找到平台');
  409. }
  410. $tx = dict::getDict('yeTx', 'can');
  411. $currentTxBalance = $txAsset->amount;
  412. if (!empty($currentTxBalance)) {
  413. $reduceTxBalance = $currentTxBalance > $refundPrice ? $refundPrice : $currentTxBalance;
  414. $currentTxBalance = bcsub($currentTxBalance, $reduceTxBalance, 2);
  415. $txAsset->amount = $currentTxBalance;
  416. $txAsset->save();
  417. }
  418. $id = $refund->id;
  419. $currentType = dict::getDict('capitalType', 'hdOrderRefund');
  420. $change = [
  421. 'relateId' => $id,
  422. 'capitalType' => $currentType,
  423. 'amount' => $refundPrice,
  424. 'balance' => $currentAmount,
  425. 'txBalance' => $currentTxBalance,
  426. 'io' => 0,
  427. 'payWay' => 0,
  428. 'event' => "【{$shop->merchantName} {$shop->shopName}】的销售单发起退款",
  429. 'sjId' => $shop->sjId,
  430. 'shopId' => $shop->id,
  431. 'mainId' => $shop->mainId,
  432. 'tx' => $tx,
  433. 'ptStyle' => $ptStyle,
  434. 'shopName' => $shop->shopName,
  435. 'sjName' => $shop->merchantName,
  436. ];
  437. PtYeChangeClass::addChange($change, true);
  438. }
  439. public static function saleRefundReduceBalance($shop, $refund, $refundPrice)
  440. {
  441. $ptStyle = $shop->ptStyle;
  442. $asset = null;
  443. if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
  444. $asset = self::getHdBalance();
  445. } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
  446. $asset = self::getGhsBalance();
  447. } else {
  448. util::fail('没有找到平台');
  449. }
  450. if (bccomp($refundPrice, $asset->amount, 2) == 1) {
  451. //util::fail('平台余额不足哈');
  452. }
  453. $currentAmount = bcsub($asset->amount, $refundPrice, 2);
  454. $asset->amount = $currentAmount;
  455. $asset->save();
  456. $txAsset = null;
  457. if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
  458. $txAsset = self::getHdTxBalance();
  459. } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
  460. $txAsset = self::getGhsTxBalance();
  461. } else {
  462. util::fail('没有找到平台');
  463. }
  464. $tx = dict::getDict('yeTx', 'can');
  465. $currentTxBalance = $txAsset->amount;
  466. if (!empty($currentTxBalance)) {
  467. $reduceTxBalance = $currentTxBalance > $refundPrice ? $refundPrice : $currentTxBalance;
  468. $currentTxBalance = bcsub($currentTxBalance, $reduceTxBalance, 2);
  469. $txAsset->amount = $currentTxBalance;
  470. $txAsset->save();
  471. }
  472. $id = $refund->id;
  473. $currentType = dict::getDict('capitalType', 'saleRefund');
  474. $change = [
  475. 'relateId' => $id,
  476. 'capitalType' => $currentType,
  477. 'amount' => $refundPrice,
  478. 'balance' => $currentAmount,
  479. 'txBalance' => $currentTxBalance,
  480. 'io' => 0,
  481. 'payWay' => 0,
  482. 'event' => "【{$shop->merchantName} {$shop->shopName}】 的销售单发起退款",
  483. 'sjId' => $shop->sjId,
  484. 'shopId' => $shop->id,
  485. 'mainId' => $shop->mainId,
  486. 'tx' => $tx,
  487. 'ptStyle' => $ptStyle,
  488. 'shopName' => $shop->shopName,
  489. 'sjName' => $shop->merchantName,
  490. ];
  491. PtYeChangeClass::addChange($change, true);
  492. }
  493. //零售平台余额对象 ssh 20210519
  494. public static function getHdBalance()
  495. {
  496. $hd = dict::getDict('ptAsset', 'hdBalance');
  497. $id = $hd['id'];
  498. $name = $hd['name'];
  499. $asset = self::getLockById($id);
  500. if (empty($asset)) {
  501. $data = ['id' => $id, 'name' => $name, 'amount' => 0.00];
  502. self::add($data);
  503. $asset = self::getLockById($id);
  504. if (empty($asset)) {
  505. util::fail('没有找到零售平台余额,请先创建');
  506. }
  507. }
  508. return $asset;
  509. }
  510. //供货商平台余额对象 ssh 20210519
  511. public static function getGhsBalance()
  512. {
  513. $ghs = dict::getDict('ptAsset', 'ghsBalance');
  514. $id = $ghs['id'];
  515. $name = $ghs['name'];
  516. $asset = self::getLockById($id);
  517. if (empty($asset)) {
  518. $data = ['id' => $id, 'name' => $name, 'amount' => 0.00];
  519. self::add($data);
  520. $asset = self::getLockById($id);
  521. if (empty($asset)) {
  522. util::fail('没有找到供货商平台余额,请先创建');
  523. }
  524. }
  525. return $asset;
  526. }
  527. //零售平台余额对象 ssh 20210519
  528. public static function getHdTxBalance()
  529. {
  530. $txHd = dict::getDict('ptAsset', 'hdTxBalance');
  531. $id = $txHd['id'];
  532. $name = $txHd['name'];
  533. $asset = self::getLockById($id);
  534. if (empty($asset)) {
  535. $data = ['id' => $id, 'name' => $name, 'amount' => 0.00];
  536. self::add($data);
  537. $asset = self::getLockById($id);
  538. if (empty($asset)) {
  539. util::fail('没有找到零售平台可提现余额,请先创建');
  540. }
  541. }
  542. return $asset;
  543. }
  544. //供货商平台余额对象 ssh 20210519
  545. public static function getGhsTxBalance()
  546. {
  547. $txGhs = dict::getDict('ptAsset', 'ghsTxBalance');
  548. $id = $txGhs['id'];
  549. $name = $txGhs['name'];
  550. $asset = self::getLockById($id);
  551. if (empty($asset)) {
  552. $data = ['id' => $id, 'name' => $name, 'amount' => 0.00];
  553. self::add($data);
  554. $asset = self::getLockById($id);
  555. if (empty($asset)) {
  556. util::fail('没有找到供货商平台可提现余额,请先创建');
  557. }
  558. }
  559. return $asset;
  560. }
  561. //零售采购退款
  562. public static function cgRefundAddBalance($shop, $refundPrice, $cgRefund, $currentType, $tx)
  563. {
  564. $ptStyle = $shop->ptStyle;
  565. $asset = null;
  566. if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
  567. $asset = PtAssetClass::getHdBalance();
  568. } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
  569. $asset = PtAssetClass::getGhsBalance();
  570. } else {
  571. util::fail('没有找到平台');
  572. }
  573. $currentPtBalance = bcadd($asset->amount, $refundPrice, 2);
  574. $asset->amount = $currentPtBalance;
  575. $asset->save();
  576. $txAsset = null;
  577. if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
  578. $txAsset = PtAssetClass::getHdTxBalance();
  579. } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
  580. $txAsset = PtAssetClass::getGhsTxBalance();
  581. } else {
  582. util::fail('没有找到平台');
  583. }
  584. $currentPtTxBalance = $txAsset->amount;
  585. $id = $cgRefund->id;
  586. $sjId = $shop->sjId;
  587. $shopId = $shop->id;
  588. $mainId = $shop->mainId ?? 0;
  589. $change = [
  590. 'relateId' => $id,
  591. 'capitalType' => $currentType,
  592. 'amount' => $refundPrice,
  593. 'balance' => $currentPtBalance,
  594. 'txBalance' => $currentPtTxBalance,
  595. 'io' => 1,
  596. 'payWay' => 0,
  597. 'event' => "【{$shop->merchantName} {$shop->shopName}】的采购被退款",
  598. 'sjId' => $sjId,
  599. 'shopId' => $shopId,
  600. 'mainId' => $mainId,
  601. 'tx' => $tx,
  602. 'ptStyle' => $ptStyle,
  603. 'shopName' => $shop->shopName,
  604. 'sjName' => $shop->merchantName,
  605. ];
  606. PtYeChangeClass::addChange($change, true);
  607. }
  608. }