ShopClass.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  1. <?php
  2. namespace biz\shop\classes;
  3. use biz\ghs\classes\GhsClass;
  4. use biz\pt\classes\PtAssetClass;
  5. use biz\pt\classes\PtYeChangeClass;
  6. use biz\sj\classes\SjClass;
  7. use bizGhs\custom\classes\CustomClass;
  8. use bizGhs\order\classes\OrderClass;
  9. use bizGhs\product\classes\ProductClass;
  10. use bizHd\ad\classes\AdClass;
  11. use bizHd\goods\classes\CategoryClass;
  12. use bizHd\goods\classes\GoodsSettingClass;
  13. use bizHd\saas\classes\ApplyClass;
  14. use common\components\dict;
  15. use common\components\httpUtil;
  16. use common\components\imgUtil;
  17. use common\components\qrCodeUtil;
  18. use common\components\stringUtil;
  19. use common\components\util;
  20. use Yii;
  21. use biz\base\classes\BaseClass;
  22. class ShopClass extends BaseClass
  23. {
  24. public static $baseFile = '\biz\shop\models\Shop';
  25. //营业状态
  26. public static function isOpen($shop)
  27. {
  28. if (isset($shop['open']) == false || $shop['open'] == 0) {
  29. return 0;
  30. }
  31. $openStartTime = $shop['openStartTime'] ?? '';
  32. if (empty($openStartTime)) {
  33. return 1;
  34. }
  35. $openEndTime = $shop['openEndTime'] ?? '';
  36. $start = strtotime(date("Y-m-d") . ' ' . $openStartTime);
  37. $end = strtotime(date("Y-m-d") . ' ' . $openEndTime);
  38. $time = time();
  39. if ($time > $start && $time < $end) {
  40. return 1;
  41. }
  42. return 0;
  43. }
  44. //获取图片信息 ssh 2021.3.14
  45. public static function getShopInfo($id)
  46. {
  47. $info = self::getById($id);
  48. if (empty($info)) {
  49. return $info;
  50. }
  51. $list = self::groupShopInfo([$info]);
  52. return current($list);
  53. }
  54. public static function getShopList($where)
  55. {
  56. $list = self::getList('*', $where, 'addTime DESC');
  57. return $list;
  58. }
  59. //查看店铺 ssh 2021.3.1
  60. public static function getShopByIds($ids)
  61. {
  62. $list = self::getByIds($ids);
  63. return self::groupShopInfo($list);
  64. }
  65. //门店 ssh 2021.3.1
  66. public static function groupShopInfo($list)
  67. {
  68. if (empty($list)) {
  69. return $list;
  70. }
  71. foreach ($list as $key => $val) {
  72. $avatar = imgUtil::groupImg($val['avatar']);
  73. $list[$key]['avatar'] = $avatar;
  74. //店长微信
  75. $superWx = $val['superWx'] ?? '';
  76. $list[$key]['superWx'] = imgUtil::groupImg($superWx) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
  77. }
  78. return $list;
  79. }
  80. //获取商家默认的门店ID ssh 2020.1.19
  81. public static function getDefaultShopId($merchant)
  82. {
  83. return isset($merchant['defaultShopId']) ? $merchant['defaultShopId'] : 0;
  84. }
  85. //更新门店 ssh 2020.2.29
  86. public static function updateShop($shop, $data)
  87. {
  88. $id = $shop['id'] ?? 0;
  89. $shopName = isset($data['shopName']) ? $data['shopName'] : '';
  90. if (stringUtil::getWordNum($shopName) > 8) {
  91. util::fail('门店名称不能超过8个汉字,2个字母顶一个汉字');
  92. }
  93. $sjId = $data['sjId'];
  94. $findShop = self::getByCondition(['sjId' => $sjId, 'shopName' => $shopName]);
  95. if (!empty($findShop) && $findShop['id'] != $id) {
  96. util::fail('门店名称已经存在');
  97. }
  98. $dist = $data['dist'] ?? '';
  99. $floor = $data['floor'] ?? '';
  100. $address = $data['address'] ?? '';
  101. $data['fullAddress'] = $data['city'] . $dist . $address . $floor;
  102. // 营业时间设置逻辑
  103. if ($data['openType'] == 0) { // openType: 0. 表示 24小时营业 1. 表示 xx ~ xx
  104. $data['openStartTime'] = ''; // openStartTime 营业开始时间,空表示24小时
  105. $data['openEndTime'] = '';
  106. }
  107. $respond = self::updateById($id, $data);
  108. $ptStyle = $shop['ptStyle'] ?? dict::getDict('ptStyle', 'hd');
  109. $default = $shop['default'] ?? 0;
  110. $sjName = $shop['merchantName'] ?? '';
  111. //默认门店只显示商家名称即可
  112. $name = $default == 1 ? $sjName : $sjName . ' ' . $shopName;
  113. $shopUpdate = [
  114. 'name' => $name,
  115. 'mobile' => $data['mobile'] ?? '',
  116. 'province' => $data['province'] ?? '',
  117. 'city' => $data['city'] ?? '',
  118. 'dist' => $data['dist'] ?? '',
  119. 'address' => $data['address'] ?? '',
  120. 'floor' => $data['floor'] ?? '',
  121. 'fullAddress' => $data['fullAddress'] ?? '',
  122. 'showAddress' => $data['showAddress'] ?? '',
  123. 'lat' => $data['lat'] ?? '',
  124. 'long' => $data['long'] ?? '',
  125. ];
  126. $where = ['sjId' => $sjId, 'shopId' => $id];
  127. if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
  128. CustomClass::updateByCondition($where, $shopUpdate);
  129. } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
  130. GhsClass::updateByCondition($where, $shopUpdate);
  131. }
  132. return $respond;
  133. }
  134. //取商家所有门店 ssh 2020.2.29
  135. public static function getAllShop($sjId)
  136. {
  137. return self::getAllByCondition(['sjId' => $sjId], null, "*");
  138. }
  139. //验证所属权限 ssh 2020.2.29
  140. public static function valid($shop, $sjId)
  141. {
  142. if (empty($shop)) {
  143. util::fail('门店无效');
  144. }
  145. if (isset($shop['sjId']) == false || $shop['sjId'] != $sjId) {
  146. util::fail('您没有权限访问');
  147. }
  148. }
  149. //删除门店 ssh 2020.3.1
  150. public static function deleteShop($shop)
  151. {
  152. if (isset($shop['default']) && $shop['default'] == 1) {
  153. util::fail('默认门店不允许删除');
  154. }
  155. $id = $shop['id'];
  156. self::updateById($id, ['delStatus' => 1]);
  157. }
  158. //生成收款码 ssh 2020.3.9
  159. public static function generateGatheringCode($sjId, $shopId)
  160. {
  161. $url = Yii::$app->params['mallDomain'] . "/#/pages/pay/index?account=" . $shopId;
  162. //强制转成https
  163. $url = httpUtil::becomeHttps($url);
  164. Yii::info('收款码url:' . $url);
  165. $gatheringCode = qrCodeUtil::generateGatheringQrCode($url, $sjId, $shopId, '', 16);
  166. Yii::info('gatheringCode:' . $gatheringCode);
  167. $imgUrl = Yii::$app->params['hdImgHost'] . 'gathering/1.jpg?x-oss-process=image/watermark,image_' . base64_encode($gatheringCode) . ',g_nw,x_276,y_463/watermark,image_' . base64_encode('gathering/logo_big.png?x-oss-process=image/resize,P_12') . ',g_nw,x_555,y_728';
  168. return $imgUrl;
  169. }
  170. //客户结帐增加余额 ssh 20210729
  171. public static function customClearAddBalance($main, $shop, $order)
  172. {
  173. $mainId = $shop->mainId ?? 0;
  174. $balance = bcadd($main->balance, $order->actPrice, 2);
  175. $txBalance = bcadd($main->txBalance, $order->actPrice, 2);
  176. $main->balance = $balance;
  177. $main->txBalance = $txBalance;
  178. $main->save();
  179. $clearId = $order->id ?? 0;
  180. $tx = dict::getDict('yeTx', 'can');
  181. $capitalType = dict::getDict('capitalType', 'hdPurchaseClear', 'id');
  182. $custom = '客户';
  183. if (isset($order->customName) && !empty($order->customName)) {
  184. $custom = $order->customName;
  185. }
  186. $change = [
  187. 'relateId' => $clearId,
  188. 'capitalType' => $capitalType,
  189. 'amount' => $order->actPrice,
  190. 'balance' => $balance,
  191. 'txBalance' => $txBalance,
  192. 'io' => 1,
  193. 'payWay' => $order->payWay,
  194. 'event' => $custom . "结帐(单号:{$order->orderSn})",
  195. 'sjId' => $shop->sjId,
  196. 'shopId' => $shop->id,
  197. 'mainId' => $shop->mainId,
  198. 'tx' => $tx,
  199. 'ptStyle' => $shop->ptStyle,
  200. 'mainId' => $mainId,
  201. ];
  202. ShopYeChangeClass::addChange($change, true);
  203. //平台余额增加
  204. PtAssetClass::customClearAddBalance($shop, $order, $capitalType, $tx);
  205. }
  206. //客户使用优惠券增加余额 ssh 20210601
  207. public static function customKdUseCouponAddBalance($shop, $order, $capitalType)
  208. {
  209. //门店余额增加
  210. $amount = $order->discountAmount;
  211. $currentBalance = bcadd($shop->balance, $amount, 2);
  212. $shop->balance = $currentBalance;
  213. $shop->totalRecharge = bcadd($shop->totalRecharge, $amount, 2);
  214. //可提现余额同步增加
  215. $currentTx = bcadd($shop->txBalance, $amount, 2);
  216. $shop->txBalance = $currentTx;
  217. $shop->save();
  218. //增加余额变动记录
  219. $id = $order->id;
  220. $event = "客户下单(使用平台优惠券{$amount}元)";
  221. $tx = dict::getDict('yeTx', 'can');
  222. $mainId = $shop->mainId ?? 0;
  223. $change = [
  224. 'relateId' => $id,
  225. 'capitalType' => $capitalType,
  226. 'amount' => $amount,
  227. 'balance' => $currentBalance,
  228. 'txBalance' => $currentTx,
  229. 'io' => 1,
  230. 'payWay' => $order->payWay,
  231. 'event' => $event,
  232. 'mainId' => $mainId,
  233. 'tx' => $tx,
  234. 'ptStyle' => $shop->ptStyle,
  235. ];
  236. ShopYeChangeClass::addChange($change, true);
  237. //平台余额增加
  238. PtAssetClass::customKdUseCouponAddBalance($shop, $order, $capitalType, $tx);
  239. }
  240. //客户下单引起的余额增加 ssh 20210520
  241. public static function customKdAddBalance($main, $shop, $amount, $order, $capitalType)
  242. {
  243. //门店余额增加
  244. $mainId = $shop->mainId ?? 0;
  245. $currentBalance = bcadd($main->balance, $amount, 2);
  246. $main->balance = $currentBalance;
  247. //可提现余额同步增加
  248. $currentTx = bcadd($main->txBalance, $amount, 2);
  249. $main->txBalance = $currentTx;
  250. $main->save();
  251. $ptStyle = $shop->ptStyle ?? dict::getDict('ptStyle', 'hd');
  252. $customName = '客户';
  253. if ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
  254. $customId = $order->customId ?? 0;
  255. $custom = CustomClass::getById($customId, true);
  256. if (isset($custom->name) && !empty($custom->name)) {
  257. $customName = $custom->name;
  258. }
  259. }
  260. //增加余额变动记录
  261. $id = $order->id;
  262. $event = $customName . "下单" . floatval($amount) . "元";
  263. $tx = dict::getDict('yeTx', 'can');
  264. $fromType = $order->fromType ?? 1;
  265. $change = [
  266. 'relateId' => $id,
  267. 'capitalType' => $capitalType,
  268. 'amount' => $amount,
  269. 'balance' => $currentBalance,
  270. 'txBalance' => $currentTx,
  271. 'io' => 1,
  272. 'payWay' => $order->payWay,
  273. 'event' => $event,
  274. 'mainId' => $mainId,
  275. 'tx' => $tx,
  276. 'ptStyle' => $shop->ptStyle,
  277. 'fromType' => $fromType,
  278. ];
  279. ShopYeChangeClass::addChange($change, true);
  280. //平台余额增加
  281. PtAssetClass::customKdAddBalance($shop, $amount, $order, $capitalType, $tx);
  282. }
  283. //门店充值增加余额 ssh 2021.2.21
  284. //$fix = true 余额只能在指定门店使用
  285. public static function rechargeAddBalance($shop, $amount, $order, $tx, $capitalType, $fix = false)
  286. {
  287. $mainId = $shop->mainId ?? 0;
  288. $main = MainClass::getLockById($mainId);
  289. if (empty($main)) {
  290. util::fail('没有找到资产信息');
  291. }
  292. //门店余额增加
  293. $currentBalance = bcadd($main->balance, $amount, 2);
  294. $main->balance = $currentBalance;
  295. $currentTotalRecharge = bcadd($shop->totalRecharge, $amount, 2);
  296. $main->totalRecharge = $currentTotalRecharge;
  297. //定向消费余额
  298. if ($fix) {
  299. $currentFix = bcadd($main->fixBalance, $amount, 2);
  300. $main->fixBalance = $currentFix;
  301. }
  302. $currentTx = $main->txBalance;
  303. //提现余额
  304. if ($tx == dict::getDict('yeTx', 'can')) {
  305. $currentTx = bcadd($main->txBalance, $amount, 2);
  306. $main->txBalance = $currentTx;
  307. }
  308. $main->save();
  309. $order->totalRecharge = $currentTotalRecharge;
  310. $order->save();
  311. //增加余额变动记录
  312. $id = $order->id;
  313. $event = "充值{$amount}元";
  314. if ($order->shopAdminId == 0) {
  315. $event = "系统充值{$amount}元";
  316. }
  317. $change = [
  318. 'relateId' => $id,
  319. 'capitalType' => $capitalType,
  320. 'amount' => $amount,
  321. 'balance' => $currentBalance,
  322. 'txBalance' => $currentTx,
  323. 'io' => 1,
  324. 'payWay' => $order->payWay,
  325. 'event' => $event,
  326. 'sjId' => $order->sjId,
  327. 'shopId' => $order->shopId,
  328. 'mainId' => $mainId,
  329. 'tx' => $tx,
  330. 'ptStyle' => $shop->ptStyle,
  331. ];
  332. ShopYeChangeClass::addChange($change, true);
  333. //平台余额增加
  334. PtAssetClass::rechargeAddBalance($shop, $amount, $order, $capitalType, $tx);
  335. }
  336. //采购余额付款,减少余额 ssh 20210519
  337. public static function purchaseReduceBalance($main, $shop, $amount, $order)
  338. {
  339. if (bccomp($amount, $main->balance, 2) == 1) {
  340. util::fail('余额不足');
  341. }
  342. $sjId = $order->sjId;
  343. $shopId = $order->shopId;
  344. $mainId = $order->mainId ?? 0;
  345. $currentBalance = bcsub($main->balance, $amount, 2);
  346. $main->balance = $currentBalance;
  347. $tx = dict::getDict('yeTx', 'canNot');
  348. //还有可提现余额也要先用掉
  349. $currentTxBalance = $main->txBalance;
  350. if ($currentTxBalance > 0) {
  351. $reduceTxBalance = $currentTxBalance > $amount ? $amount : $currentTxBalance;
  352. $main->txBalance = bcsub($currentTxBalance, $reduceTxBalance, 2);
  353. $tx = dict::getDict('yeTx', 'can');
  354. }
  355. $main->save();
  356. $capitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
  357. //增加余额变动记录
  358. $id = $order->id;
  359. $change = [
  360. 'relateId' => $id,
  361. 'capitalType' => $capitalType,
  362. 'amount' => $amount,
  363. 'balance' => $currentBalance,
  364. 'txBalance' => $currentTxBalance,
  365. 'io' => 0,
  366. 'payWay' => $order->payWay,
  367. 'event' => "采购余额付款{$amount}元",
  368. 'sjId' => $sjId,
  369. 'shopId' => $shopId,
  370. 'mainId' => $mainId,
  371. 'tx' => $tx,
  372. 'ptStyle' => $shop->ptStyle,
  373. ];
  374. ShopYeChangeClass::addChange($change, true);
  375. //平台余额增加
  376. PtAssetClass::reduceBalance($shop, $amount, $order, $capitalType, $tx);
  377. }
  378. //零售采购退款
  379. public static function cgRefundAddBalance($main, $shop, $refundPrice, $cgRefund, $ghs)
  380. {
  381. //客户余额增加
  382. $currentBalance = bcadd($main->balance, $refundPrice, 2);
  383. $main->balance = $currentBalance;
  384. $main->save();
  385. $currentTxBalance = $main->txBalance;
  386. $currentType = dict::getDict('capitalType', 'cgRefund', 'id');
  387. $id = $cgRefund->id;
  388. $ptStyle = $shop->ptStyle;
  389. $sjId = $shop->sjId;
  390. $shopId = $shop->id;
  391. $mainId = $shop->mainId;
  392. $tx = dict::getDict('yeTx', 'canNot');
  393. $ghsName = $ghs->name ?? '';
  394. $change = [
  395. 'relateId' => $id,
  396. 'capitalType' => $currentType,
  397. 'amount' => $refundPrice,
  398. 'balance' => $currentBalance,
  399. 'txBalance' => $currentTxBalance,
  400. 'io' => 1,
  401. 'payWay' => 0,
  402. 'event' => "采购退款({$ghsName})",
  403. 'sjId' => $sjId,
  404. 'shopId' => $shopId,
  405. 'mainId' => $mainId,
  406. 'tx' => $tx,
  407. 'ptStyle' => $ptStyle,
  408. ];
  409. ShopYeChangeClass::addChange($change, true);
  410. PtAssetClass::cgRefundAddBalance($shop, $refundPrice, $cgRefund, $currentType, $tx);
  411. }
  412. //供货商预订被多付了退款减少余额 ssh 20220324
  413. public static function ghsBookOrderRefundReduceBalance($main, $shop, $refund, $refundPrice)
  414. {
  415. $currentBalance = bcsub($main->balance, $refundPrice, 2);
  416. if ($currentBalance < 0) {
  417. util::fail('余额不足,请先充值');
  418. }
  419. $main->balance = $currentBalance;
  420. $currentTx = $main->txBalance;
  421. if ($currentTx > 0) {
  422. if ($refundPrice > $currentTx) {
  423. $currentTx = 0;
  424. } else {
  425. $currentTx = bcsub($currentTx, $refundPrice, 2);
  426. }
  427. }
  428. $main->txBalance = $currentTx;
  429. $main->save();
  430. $currentType = dict::getDict('capitalType', 'ghsBookRefund');
  431. $id = $refund->id;
  432. $event = "预订单被多付退给客户(退款单 {$refund->orderSn} 订单{$refund->relateOrderSn})";
  433. $relateOrderSn = $refund->relateOrderSn ?? '';
  434. if (!empty($relateOrderSn)) {
  435. $relateOrder = OrderClass::getByCondition(['orderSn' => $relateOrderSn], true);
  436. $customName = $relateOrder->customName ?? '';
  437. if (!empty($customName)) {
  438. $event = "预订单{$customName}多付退款(退款单 {$refund->orderSn} 订单{$refund->relateOrderSn})";
  439. }
  440. }
  441. $tx = dict::getDict('yeTx', 'can');
  442. $change = [
  443. 'relateId' => $id,
  444. 'capitalType' => $currentType,
  445. 'amount' => $refundPrice,
  446. 'balance' => $currentBalance,
  447. 'txBalance' => $currentTx,
  448. 'io' => 0,
  449. 'payWay' => 0,
  450. 'event' => $event,
  451. 'sjId' => $shop->sjId,
  452. 'shopId' => $shop->id,
  453. 'mainId' => $shop->mainId,
  454. 'tx' => $tx,
  455. 'ptStyle' => $shop->ptStyle,
  456. ];
  457. ShopYeChangeClass::addChange($change, true);
  458. //平台余额增加
  459. PtAssetClass::ghsBookOrderRefundReduceBalance($shop, $refund, $refundPrice);
  460. }
  461. //花店销售单退款减少余额
  462. public static function hdSaleRefundReduceBalance($main, $shop, $refund, $refundPrice)
  463. {
  464. //门店余额减少
  465. $currentBalance = bcsub($main->balance, $refundPrice, 2);
  466. if ($currentBalance < 0) {
  467. util::fail('余额不足,请先充值');
  468. }
  469. $main->balance = $currentBalance;
  470. $currentTx = $main->txBalance;
  471. if ($currentTx > 0) {
  472. if ($refundPrice > $currentTx) {
  473. $currentTx = 0;
  474. } else {
  475. $currentTx = bcsub($currentTx, $refundPrice, 2);
  476. }
  477. }
  478. $main->txBalance = $currentTx;
  479. $main->save();
  480. $currentType = dict::getDict('capitalType', 'hdOrderRefund');
  481. $id = $refund->id;
  482. $event = "退款给客户(退款单 {$refund->refundSn})";
  483. $relateOrderSn = $refund->orderSn ?? '';
  484. if (!empty($relateOrderSn)) {
  485. $relateOrder = OrderClass::getByCondition(['orderSn' => $relateOrderSn], true);
  486. $customName = $relateOrder->customName ?? '';
  487. if (!empty($customName)) {
  488. $event = "退款给{$customName}(退款单 {$refund->refundSn})";
  489. }
  490. }
  491. $tx = dict::getDict('yeTx', 'can');
  492. $change = [
  493. 'relateId' => $id,
  494. 'capitalType' => $currentType,
  495. 'amount' => $refundPrice,
  496. 'balance' => $currentBalance,
  497. 'txBalance' => $currentTx,
  498. 'io' => 0,
  499. 'payWay' => 0,
  500. 'event' => $event,
  501. 'sjId' => $shop->sjId,
  502. 'shopId' => $shop->id,
  503. 'mainId' => $shop->mainId,
  504. 'tx' => $tx,
  505. 'ptStyle' => $shop->ptStyle,
  506. ];
  507. ShopYeChangeClass::addChange($change, true);
  508. //平台余额增加
  509. PtAssetClass::hdSaleRefundReduceBalance($shop, $refund, $refundPrice);
  510. }
  511. //销售单退款减少余额 ssh 2021.2.21
  512. public static function saleRefundReduceBalance($main, $shop, $refund, $refundPrice)
  513. {
  514. //门店余额减少
  515. $currentBalance = bcsub($main->balance, $refundPrice, 2);
  516. if ($currentBalance < 0) {
  517. util::fail('余额不足,请先充值');
  518. }
  519. $main->balance = $currentBalance;
  520. $currentTx = $main->txBalance;
  521. if ($currentTx > 0) {
  522. if ($refundPrice > $currentTx) {
  523. $currentTx = 0;
  524. } else {
  525. $currentTx = bcsub($currentTx, $refundPrice, 2);
  526. }
  527. }
  528. $main->txBalance = $currentTx;
  529. $main->save();
  530. $currentType = dict::getDict('capitalType', 'saleRefund');
  531. $id = $refund->id;
  532. $event = "退款给客户(退款单 {$refund->orderSn})";
  533. $relateOrderSn = $refund->relateOrderSn ?? '';
  534. if (!empty($relateOrderSn)) {
  535. $relateOrder = OrderClass::getByCondition(['orderSn' => $relateOrderSn], true);
  536. $customName = $relateOrder->customName ?? '';
  537. if (!empty($customName)) {
  538. $event = "退款给{$customName}(退款单 {$refund->orderSn})";
  539. }
  540. }
  541. $tx = dict::getDict('yeTx', 'can');
  542. $change = [
  543. 'relateId' => $id,
  544. 'capitalType' => $currentType,
  545. 'amount' => $refundPrice,
  546. 'balance' => $currentBalance,
  547. 'txBalance' => $currentTx,
  548. 'io' => 0,
  549. 'payWay' => 0,
  550. 'event' => $event,
  551. 'sjId' => $shop->sjId,
  552. 'shopId' => $shop->id,
  553. 'mainId' => $shop->mainId,
  554. 'tx' => $tx,
  555. 'ptStyle' => $shop->ptStyle,
  556. ];
  557. ShopYeChangeClass::addChange($change, true);
  558. //平台余额增加
  559. PtAssetClass::saleRefundReduceBalance($shop, $refund, $refundPrice);
  560. }
  561. //获取商家所有的门店 ssh 2021.2.26
  562. public static function getSjShopList($sjId)
  563. {
  564. return self::getAllByCondition(['sjId' => $sjId, 'delStatus' => 0], null, ['id']);
  565. }
  566. //取门店长信息 ssh 2021.1.17
  567. public static function getSuper($id)
  568. {
  569. $shop = self::getById($id);
  570. if (empty($shop)) {
  571. return [];
  572. }
  573. $adminId = $shop['adminId'] ?? 0;
  574. return \bizHd\admin\classes\AdminClass::getDetail($adminId);
  575. }
  576. //佣金引起的余额增加 lqh 2021211
  577. /**
  578. * @param $shop
  579. * @param $amount 提现金额
  580. * @param $cashId 提现主键ID
  581. * @param $capitalType
  582. */
  583. public static function brokerageAddBalance($shop, $cash, $capitalType)
  584. {
  585. $amount = $cash->amount ?? 0;
  586. $amount = floatval($amount);
  587. $cashId = $cash->id ?? 0;
  588. $customerSjName = $cash->sjName ?? '';
  589. $customerName = $cash->shopName ?? '';
  590. //获取的佣金 万分之三 暂时先写死,后续可走配置
  591. $brokerage = bcmul($amount, 0.0003, 2);
  592. //门店余额增加
  593. $currentBalance = bcadd($shop->balance, $brokerage, 2);
  594. $shop->balance = $currentBalance;
  595. $shop->totalRecharge = bcadd($shop->totalRecharge, $brokerage, 2);
  596. //可提现余额同步增加
  597. $currentTx = bcadd($shop->txBalance, $brokerage, 2);
  598. $shop->txBalance = $currentTx;
  599. $shop->save();
  600. //增加余额变动记录
  601. $tx = dict::getDict('yeTx', 'can');
  602. $change = [
  603. 'relateId' => $cashId,
  604. 'capitalType' => $capitalType,
  605. 'amount' => $brokerage,
  606. 'balance' => $currentBalance,
  607. 'txBalance' => $currentTx,
  608. 'io' => 1,
  609. 'payWay' => 0,
  610. 'event' => $customerSjName . '-' . $customerName . "提现" . $amount . "元获得佣金",
  611. 'sjId' => $shop->sjId,
  612. 'shopId' => $shop->id,
  613. 'mainId' => $shop->mainId,
  614. 'tx' => $tx,
  615. 'ptStyle' => $shop->ptStyle,
  616. ];
  617. ShopYeChangeClass::addChange($change, true);
  618. //平台余额增加
  619. $ptStyle = $shop->ptStyle;
  620. if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
  621. $asset = PtAssetClass::getHdBalance();
  622. } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
  623. $asset = PtAssetClass::getGhsBalance();
  624. } else {
  625. util::fail('没有找到平台');
  626. }
  627. //增加平台可余额
  628. $currentPtBalance = bcadd($asset->amount, $brokerage, 2);
  629. $asset->amount = $currentPtBalance;
  630. $asset->save();
  631. if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
  632. $txAsset = PtAssetClass::getHdTxBalance();
  633. } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
  634. $txAsset = PtAssetClass::getGhsTxBalance();
  635. } else {
  636. util::fail('没有找到平台');
  637. }
  638. //增加平台可提现余额
  639. $currentPtTxBalance = $txAsset->amount;
  640. $currentPtTxBalance = bcadd($currentPtTxBalance, $brokerage, 2);
  641. $txAsset->amount = $currentPtTxBalance;
  642. $txAsset->save();
  643. $change = [
  644. 'relateId' => $cashId,
  645. 'capitalType' => $capitalType,
  646. 'amount' => $brokerage,
  647. 'balance' => $currentPtBalance,
  648. 'txBalance' => $currentPtTxBalance,
  649. 'io' => 1,
  650. 'payWay' => 0,
  651. 'event' => $customerSjName . '-' . $customerName . "提现" . $amount . "元,代理商【{$shop->merchantName}-{$shop->shopName}】获得佣金",
  652. 'sjId' => $shop->sjId,
  653. 'shopId' => $shop->id,
  654. 'tx' => $tx,
  655. 'ptStyle' => $ptStyle,
  656. 'shopName' => $shop->shopName,
  657. 'sjName' => $shop->merchantName,
  658. ];
  659. PtYeChangeClass::addChange($change, true);
  660. }
  661. }