PtAssetClass.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. <?php
  2. namespace biz\pt\classes;
  3. use biz\base\classes\BaseClass;
  4. use common\components\dict;
  5. use common\components\util;
  6. class PtAssetClass extends BaseClass
  7. {
  8. public static $baseFile = '\biz\pt\models\PtAsset';
  9. //客户下单增加商家余额 shish 20210520
  10. public static function customKdAddBalance($shop, $amount, $order, $capitalType, $tx)
  11. {
  12. $ptStyle = $shop->ptStyle;
  13. if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
  14. $asset = self::getHdBalance();
  15. } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
  16. $asset = self::getGhsBalance();
  17. } else {
  18. util::fail('没有找到平台');
  19. }
  20. $currentAmount = bcadd($asset->amount, $amount, 2);
  21. $asset->amount = $currentAmount;
  22. $asset->save();
  23. if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
  24. $txAsset = self::getHdTxBalance();
  25. } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
  26. $txAsset = self::getGhsTxBalance();
  27. } else {
  28. util::fail('没有找到平台');
  29. }
  30. $currentTxBalance = $txAsset->amount;
  31. $currentTxBalance = bcadd($currentTxBalance, $amount, 2);
  32. $txAsset->amount = $currentTxBalance;
  33. $txAsset->save();
  34. $id = $order->id;
  35. $event = "【{$shop->merchantName} {$shop->shopName}】的客户下单购买 {$amount}元 订单号:{$order->orderSn}";
  36. $change = [
  37. 'relateId' => $id,
  38. 'capitalType' => $capitalType,
  39. 'amount' => $amount,
  40. 'balance' => $currentAmount,
  41. 'txBalance' => $currentTxBalance,
  42. 'io' => 1,
  43. 'payWay' => $order->payWay,
  44. 'event' => $event,
  45. 'sjId' => $order->sjId,
  46. 'shopId' => $order->shopId,
  47. 'tx' => $tx,
  48. 'ptStyle' => $ptStyle,
  49. 'shopName' => $shop->shopName,
  50. 'sjName' => $shop->merchantName,
  51. ];
  52. PtYeChangeClass::addChange($change, true);
  53. }
  54. //客户使用优惠券增加余额 shish 20210601
  55. public static function customKdUseCouponAddBalance($shop, $order, $capitalType, $tx)
  56. {
  57. $amount = $order->discountAmount;
  58. $ptStyle = $shop->ptStyle;
  59. if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
  60. $asset = self::getHdBalance();
  61. } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
  62. $asset = self::getGhsBalance();
  63. } else {
  64. util::fail('没有找到平台');
  65. }
  66. $currentAmount = bcadd($asset->amount, $amount, 2);
  67. $asset->amount = $currentAmount;
  68. $asset->save();
  69. if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
  70. $txAsset = self::getHdTxBalance();
  71. } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
  72. $txAsset = self::getGhsTxBalance();
  73. } else {
  74. util::fail('没有找到平台');
  75. }
  76. $currentTxBalance = $txAsset->amount;
  77. $currentTxBalance = bcadd($currentTxBalance, $amount, 2);
  78. $txAsset->amount = $currentTxBalance;
  79. $txAsset->save();
  80. $id = $order->id;
  81. $event = "【{$shop->merchantName} {$shop->shopName}】的客户下单(使用平台优惠券{$amount}元) 订单号:{$order->orderSn}";
  82. $change = [
  83. 'relateId' => $id,
  84. 'capitalType' => $capitalType,
  85. 'amount' => $amount,
  86. 'balance' => $currentAmount,
  87. 'txBalance' => $currentTxBalance,
  88. 'io' => 1,
  89. 'payWay' => $order->payWay,
  90. 'event' => $event,
  91. 'sjId' => $order->sjId,
  92. 'shopId' => $order->shopId,
  93. 'tx' => $tx,
  94. 'ptStyle' => $ptStyle,
  95. 'shopName' => $shop->shopName,
  96. 'sjName' => $shop->merchantName,
  97. ];
  98. PtYeChangeClass::addChange($change, true);
  99. }
  100. //平台余额增加 shish 20210519
  101. public static function rechargeAddBalance($shop, $amount, $order, $capitalType, $tx)
  102. {
  103. $ptStyle = $shop->ptStyle;
  104. if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
  105. $asset = self::getHdBalance();
  106. } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
  107. $asset = self::getGhsBalance();
  108. } else {
  109. util::fail('没有找到平台');
  110. }
  111. $currentAmount = bcadd($asset->amount, $amount, 2);
  112. $asset->amount = $currentAmount;
  113. $asset->save();
  114. if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
  115. $txAsset = self::getHdTxBalance();
  116. } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
  117. $txAsset = self::getGhsTxBalance();
  118. } else {
  119. util::fail('没有找到平台');
  120. }
  121. $currentTxBalance = $txAsset->amount;
  122. if ($tx == dict::getDict('yeTx', 'can')) {
  123. $currentTxBalance = bcadd($currentTxBalance, $amount, 2);
  124. $txAsset->amount = $currentTxBalance;
  125. $txAsset->save();
  126. }
  127. $id = $order->id;
  128. $event = "【{$shop->merchantName} {$shop->shopName}】 充值{$amount}元 订单号:{$order->orderSn}";
  129. if ($order->shopAdminId == 0) {
  130. $event = "系统为【{$shop->merchantName} {$shop->shopName}】 充值{$amount}元 订单号:{$order->orderSn}";
  131. }
  132. $change = [
  133. 'relateId' => $id,
  134. 'capitalType' => $capitalType,
  135. 'amount' => $amount,
  136. 'balance' => $currentAmount,
  137. 'txBalance' => $currentTxBalance,
  138. 'io' => 1,
  139. 'payWay' => $order->payWay,
  140. 'event' => $event,
  141. 'sjId' => $order->sjId,
  142. 'shopId' => $order->shopId,
  143. 'tx' => $tx,
  144. 'ptStyle' => $ptStyle,
  145. 'shopName' => $shop->shopName,
  146. 'sjName' => $shop->merchantName,
  147. ];
  148. PtYeChangeClass::addChange($change, true);
  149. }
  150. //平台余额增加 shish 20210519
  151. public static function reduceBalance($shop, $amount, $order, $capitalType, $tx)
  152. {
  153. $ptStyle = $shop->ptStyle;
  154. if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
  155. $asset = self::getHdBalance();
  156. } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
  157. $asset = self::getGhsBalance();
  158. } else {
  159. util::fail('没有找到平台');
  160. }
  161. if (bccomp($amount, $asset->amount, 2) == 1) {
  162. util::fail('平台余额不足');
  163. }
  164. $currentAmount = bcsub($asset->amount, $amount, 2);
  165. $asset->amount = $currentAmount;
  166. $asset->save();
  167. if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
  168. $txAsset = self::getHdTxBalance();
  169. } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
  170. $txAsset = self::getGhsTxBalance();
  171. } else {
  172. util::fail('没有找到平台');
  173. }
  174. $currentTxBalance = $txAsset->amount;
  175. if ($tx == dict::getDict('yeTx', 'can')) {
  176. if (!empty($currentTxBalance)) {
  177. $reduceTxBalance = $currentTxBalance > $amount ? $amount : $currentTxBalance;
  178. $currentTxBalance = bcsub($currentTxBalance, $reduceTxBalance, 2);
  179. $txAsset->amount = $currentTxBalance;
  180. $txAsset->save();
  181. }
  182. }
  183. $id = $order->id;
  184. $change = [
  185. 'relateId' => $id,
  186. 'capitalType' => $capitalType,
  187. 'amount' => $amount,
  188. 'balance' => $currentAmount,
  189. 'txBalance' => $currentTxBalance,
  190. 'io' => 0,
  191. 'payWay' => $order->payWay,
  192. 'event' => "【{$shop->merchantName} {$shop->shopName}】 {$amount}元 订单号:{$order->orderSn}",
  193. 'sjId' => $order->sjId,
  194. 'shopId' => $order->shopId,
  195. 'tx' => $tx,
  196. 'ptStyle' => $ptStyle,
  197. 'shopName' => $shop->shopName,
  198. 'sjName' => $shop->merchantName,
  199. ];
  200. PtYeChangeClass::addChange($change, true);
  201. }
  202. //零售平台余额对象 shish 20210519
  203. public static function getHdBalance()
  204. {
  205. $hd = dict::getDict('ptAsset', 'hdBalance');
  206. $id = $hd['id'];
  207. $name = $hd['name'];
  208. $asset = self::getLockById($id);
  209. if (empty($asset)) {
  210. $data = ['id' => $id, 'name' => $name, 'amount' => 0.00];
  211. self::add($data);
  212. $asset = self::getLockById($id);
  213. if (empty($asset)) {
  214. util::fail('没有找到零售平台余额,请先创建');
  215. }
  216. }
  217. return $asset;
  218. }
  219. //供应商平台余额对象 shish 20210519
  220. public static function getGhsBalance()
  221. {
  222. $ghs = dict::getDict('ptAsset', 'ghsBalance');
  223. $id = $ghs['id'];
  224. $name = $ghs['name'];
  225. $asset = self::getLockById($id);
  226. if (empty($asset)) {
  227. $data = ['id' => $id, 'name' => $name, 'amount' => 0.00];
  228. self::add($data);
  229. $asset = self::getLockById($id);
  230. if (empty($asset)) {
  231. util::fail('没有找到供应商平台余额,请先创建');
  232. }
  233. }
  234. return $asset;
  235. }
  236. //零售平台余额对象 shish 20210519
  237. public static function getHdTxBalance()
  238. {
  239. $txHd = dict::getDict('ptAsset', 'hdTxBalance');
  240. $id = $txHd['id'];
  241. $name = $txHd['name'];
  242. $asset = self::getLockById($id);
  243. if (empty($asset)) {
  244. $data = ['id' => $id, 'name' => $name, 'amount' => 0.00];
  245. self::add($data);
  246. $asset = self::getLockById($id);
  247. if (empty($asset)) {
  248. util::fail('没有找到零售平台可提现余额,请先创建');
  249. }
  250. }
  251. return $asset;
  252. }
  253. //供应商平台余额对象 shish 20210519
  254. public static function getGhsTxBalance()
  255. {
  256. $txGhs = dict::getDict('ptAsset', 'ghsTxBalance');
  257. $id = $txGhs['id'];
  258. $name = $txGhs['name'];
  259. $asset = self::getLockById($id);
  260. if (empty($asset)) {
  261. $data = ['id' => $id, 'name' => $name, 'amount' => 0.00];
  262. self::add($data);
  263. $asset = self::getLockById($id);
  264. if (empty($asset)) {
  265. util::fail('没有找到供应商平台可提现余额,请先创建');
  266. }
  267. }
  268. return $asset;
  269. }
  270. }