CustomClass.php 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468
  1. <?php
  2. namespace bizGhs\custom\classes;
  3. use biz\ghs\classes\GhsClass;
  4. use biz\sj\classes\SjClass;
  5. use bizGhs\admin\classes\AdminClass;
  6. use bizGhs\book\classes\BookCustomClass;
  7. use bizGhs\book\classes\BookItemCustomClass;
  8. use bizGhs\custom\classes\AccountMoneyClass;
  9. use bizGhs\custom\models\Custom;
  10. use bizGhs\ghs\classes\GhsBalanceChangeClass;
  11. use bizGhs\shop\classes\MainClass;
  12. use bizGhs\shop\classes\ShopMoneyClass;
  13. use bizGhs\shop\classes\TotalDebtChangeClass;
  14. use bizGhs\ghs\classes\GhsBalanceClass;
  15. use bizGhs\ghs\classes\GhsRechargeClass;
  16. use bizGhs\order\classes\OrderClearClass;
  17. use bizGhs\shop\classes\ShopClass;
  18. use bizHd\member\classes\MemberLevelClass;
  19. use bizHd\purchase\classes\PurchaseClass;
  20. use bizHd\saas\classes\ApplyClass;
  21. use bizHd\saas\services\ApplyService;
  22. use common\components\dict;
  23. use common\components\imgUtil;
  24. use common\components\noticeUtil;
  25. use common\components\stringUtil;
  26. use common\components\util;
  27. use common\components\orderSn;
  28. use bizHd\base\classes\BaseClass;
  29. use Yii;
  30. class CustomClass extends BaseClass
  31. {
  32. public static $baseFile = '\bizGhs\custom\models\Custom';
  33. const IS_DEBT_NO = 0;
  34. const IS_DEBT_YES = 1;
  35. const NOT_BLACK = 1;
  36. const IS_BLACK = 2;
  37. const LEVEL_SK = 0; //散客
  38. const LEVEL_PT = 1; //花店
  39. const LEVEL_HJ = 2; //同行
  40. const LEVEL_ZS = 3; //金店
  41. public static $levelMap = [
  42. self::LEVEL_SK => '散客',
  43. self::LEVEL_PT => '花店',
  44. self::LEVEL_HJ => '同行',
  45. self::LEVEL_ZS => '金店',
  46. ];
  47. public static $nickNameMap = [
  48. self::LEVEL_SK => '零售',
  49. self::LEVEL_PT => '批发',
  50. self::LEVEL_HJ => '同行',
  51. self::LEVEL_ZS => '金店',
  52. ];
  53. public static $levelPriceKeyMap = [
  54. self::LEVEL_SK => 'skPrice',
  55. self::LEVEL_PT => 'price',
  56. self::LEVEL_HJ => 'hjPrice',
  57. self::LEVEL_ZS => 'zsPrice',
  58. ];
  59. public static $levelAddPriceKeyMap = [
  60. self::LEVEL_SK => 'skMore',
  61. self::LEVEL_PT => 'addPrice',
  62. self::LEVEL_HJ => 'hjAddPrice',
  63. self::LEVEL_ZS => 'zsAddPrice',
  64. ];
  65. public static function pullOtherShopCustom($data)
  66. {
  67. $connection = Yii::$app->db;
  68. $transaction = $connection->beginTransaction();
  69. try {
  70. $toShopId = $data['toShopId'] ?? 0;
  71. $fromShopId = $data['fromShopId'] ?? 0;
  72. //指定当前环境为批发商,重要!!!
  73. Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'ghs');
  74. $fromCustomList = CustomClass::getAllByCondition(['ownShopId' => $fromShopId], null, '*');
  75. if (!empty($fromCustomList)) {
  76. foreach ($fromCustomList as $fromCustomer) {
  77. $exist = CustomClass::exists(['ownShopId' => $toShopId, 'shopId' => $fromCustomer['shopId']]);
  78. if (!$exist) {
  79. CustomClass::build($toShopId, $fromCustomer['shopId'], $fromCustomer['name']);
  80. }
  81. }
  82. }
  83. $transaction->commit();
  84. return true;
  85. } catch (\Exception $exception) {
  86. $transaction->rollBack();
  87. noticeUtil::push("批量拉取客户时报错了,fromShopId:{$fromShopId} toShopId:{$toShopId},报错内容:" . $exception->getMessage(), '15280215347');
  88. }
  89. return true;
  90. }
  91. public static function generateCustom($data)
  92. {
  93. $connection = Yii::$app->db;
  94. $transaction = $connection->beginTransaction();
  95. try {
  96. // 组织表单数据
  97. $shopName = $data['name'] ?? '';
  98. $mobile = $data['mobile'] ?? '';
  99. $post = [];
  100. $post['introSjId'] = $data['sjId'] ?? '';
  101. $post['introShopId'] = $data['shopId'] ?? '';
  102. $post['introSjName'] = $data['sjName'] ?? '';
  103. $post['introStyle'] = SjClass::STYLE_SUPPLIER;
  104. $post['name'] = $shopName;
  105. if (empty($shopName)) {
  106. noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,名称没有填写", '15280215347');
  107. $transaction->rollBack();
  108. return true;
  109. }
  110. $post['mobile'] = $mobile;
  111. if (!stringUtil::isMobile($mobile)) {
  112. noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,手机号填写错误", '15280215347');
  113. $transaction->rollBack();
  114. return true;
  115. }
  116. if (stringUtil::getWordNum($shopName) > 15) {
  117. noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,名称超过了15个汉字", '15280215347');
  118. $transaction->rollBack();
  119. return true;
  120. }
  121. $has = ApplyClass::getByCondition(['mobile' => $mobile]);
  122. if (!empty($has)) {
  123. noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,手机号已经存在了哦", '15280215347');
  124. $transaction->rollBack();
  125. return true;
  126. }
  127. $hasShop = \biz\shop\classes\ShopClass::getByCondition(['mobile' => $mobile]);
  128. if (!empty($hasShop)) {
  129. noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,手机号已经存在了", '15280215347');
  130. $transaction->rollBack();
  131. return true;
  132. }
  133. $adminName = $post['adminName'] ?? '';
  134. $miniOpenId = $post['miniOpenId'] ?? '';
  135. $adminInfo = ['name' => $adminName, 'mobile' => $mobile, 'miniOpenId' => $miniOpenId];
  136. $fromApp = dict::getDict('userSourceGetId', 'app', 'id');
  137. $admin = AdminClass::replaceAdmin($adminInfo, $fromApp);
  138. $adminId = $admin['id'] ?? 0;
  139. $post['adminId'] = $adminId;
  140. $post['adminName'] = $admin['name'] ?? '';
  141. $post['long'] = isset($post['longitude']) ? $post['longitude'] : '';
  142. $post['lat'] = isset($post['latitude']) ? $post['latitude'] : '';
  143. $post['from'] = ApplyClass::FROM_RETAIL;
  144. $post['style'] = SjClass::STYLE_RETAIL;
  145. //增加或更新申请
  146. $respond = ApplyService::replaceRetail($post);
  147. $id = $respond['id'] ?? 0;
  148. //后面的代码,要用到此参数,重要
  149. Yii::$app->params['ptStyle'] = 2;
  150. ApplyService::pass($id, '批发商手动添加');
  151. $transaction->commit();
  152. //只要手动添加的都标记为花店,任何情况都不会标记为散客,任何情况都是审核通过的状态
  153. $customList = CustomClass::getAllByCondition(['mobile' => $mobile], null, '*', null, true);
  154. if (!empty($customList)) {
  155. foreach ($customList as $custom) {
  156. $custom->isHd = 1;
  157. $custom->passStatus = 1;
  158. $custom->save();
  159. $ghsId = $custom->ghsId;
  160. GhsClass::updateById($ghsId, ['passStatus' => 1]);
  161. }
  162. }
  163. //noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 由批发商添加成功");
  164. return true;
  165. } catch (\Exception $exception) {
  166. $transaction->rollBack();
  167. noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,原因:" . $exception->getMessage(), '15280215347');
  168. }
  169. return true;
  170. }
  171. //预订相关表同步更新货位 ssh 20240729
  172. public static function syncBookSeat($shop, $custom, $seatSn)
  173. {
  174. $bookSn = $shop->bookSn ?? 0;
  175. if (empty($bookSn)) {
  176. return true;
  177. }
  178. $customId = $custom->id ?? 0;
  179. BookItemCustomClass::updateByCondition(['bookSn' => $bookSn, 'customId' => $customId], ['seatSn' => $seatSn]);
  180. BookCustomClass::updateByCondition(['bookSn' => $bookSn, 'customId' => $customId], ['seatSn' => $seatSn]);
  181. }
  182. /**
  183. * 用账面正余额支付挂账:扣减净 balance 并记「结账」流水。
  184. * 来款充值后的自动销单不要调本方法(对照 hd:来款已入账,销单只改订单)。
  185. * 调用方:GhsRechargeSettleService::consumePositiveBalanceFifo。
  186. */
  187. public static function clearConsumeBalance($amount, $custom, $ghs, $shop, $staff, $clear, $options = [])
  188. {
  189. $skipBalanceChangeRecord = !empty($options['skipBalanceChangeRecord']);
  190. // 先合并历史挂账到 balance,再扣减(只记余额变动)
  191. AccountMoneyClass::ensureCustomMoneyReady($custom, true);
  192. AccountMoneyClass::ensureGhsMoneyReady($ghs, true);
  193. $customId = $custom->id ?? 0;
  194. $customName = $custom->name ?? '';
  195. $ghsId = $ghs->id ?? 0;
  196. $relateId = $clear->id ?? 0;
  197. $staffId = $staff->id ?? 0;
  198. $staffName = $staff->name ?? '';
  199. $clearSn = $clear->orderSn;
  200. $mainId = $shop->mainId ?? 0;
  201. $shopId = $shop->id ?? 0;
  202. $sjId = $shop->sjId ?? 0;
  203. $amount = bcadd((string)$amount, '0', 2);
  204. if (bccomp($amount, '0', 2) <= 0) {
  205. util::fail('销账扣款金额须大于0');
  206. }
  207. $newGhsBalance = bcsub((string)($ghs->balance ?? '0'), $amount, 2);
  208. $newCustomBalance = bcsub((string)($custom->balance ?? '0'), $amount, 2);
  209. // 合并后净余额可为负(待结),勿再因扣款后 <0 报错;金额由 CustomPaymentAllocateService 按来款池控制
  210. if (bccomp($newGhsBalance, $newCustomBalance, 2) !== 0) {
  211. util::fail('客户与供货商余额不一致,无法结账,请联系管理员');
  212. }
  213. $ghs->balance = $newGhsBalance;
  214. $ghs->save();
  215. $custom->balance = $newCustomBalance;
  216. $custom->save();
  217. // 充值销账:只记一条充值流水(附 clearAmount),不另记「结账 -X」行(对照 hd settleAmount)
  218. if ($skipBalanceChangeRecord) {
  219. return;
  220. }
  221. $capitalType = dict::getDict('capitalType', 'ghsHelpCustomUseBalanceClear', 'id');
  222. $fromType = dict::getDict('fromType', 'shop');
  223. $cbData = [
  224. 'customId' => $customId,
  225. 'customName' => $customName,
  226. 'relateId' => $relateId,
  227. 'onlinePay' => 1,
  228. 'ptStyle' => 2,
  229. 'capitalType' => $capitalType,
  230. 'amount' => $amount,
  231. 'balance' => $newCustomBalance,
  232. 'staffId' => $staffId,
  233. 'staffName' => $staffName,
  234. 'io' => 0,
  235. 'side' => 0,
  236. 'payWay' => 0,
  237. 'fromType' => $fromType,
  238. 'event' => '结账 ' . $clearSn,
  239. 'mainId' => $mainId,
  240. 'shopId' => $shopId,
  241. 'sjId' => $sjId,
  242. 'remark' => '',
  243. ];
  244. $cbc = CustomBalanceChangeClass::add($cbData, true);
  245. $customShopId = $custom->shopId ?? 0;
  246. $customShop = ShopClass::getById($customShopId, true);
  247. if (empty($customShop)) {
  248. util::fail('没有找到客户门店呢..');
  249. }
  250. $customShopSjId = $customShop->sjId ?? 0;
  251. $customShopMainId = $customShop->mainId ?? 0;
  252. $capitalType = dict::getDict('capitalType', 'customAskGhsUseBalanceClear', 'id');
  253. $gbData = [
  254. 'ghsId' => $ghsId,
  255. 'relateId' => $relateId,
  256. 'ptStyle' => 2,
  257. 'capitalType' => $capitalType,
  258. 'amount' => $amount,
  259. 'balance' => $newGhsBalance,
  260. 'io' => 0,
  261. 'side' => 0,
  262. 'onlinePay' => 1,
  263. 'payWay' => 0,
  264. 'fromType' => $fromType,
  265. 'event' => '结账 ' . $clearSn,
  266. 'sjId' => $customShopSjId,
  267. 'mainId' => $customShopMainId,
  268. 'shopId' => $customShopId,
  269. 'remark' => '',
  270. ];
  271. $gbc = GhsBalanceChangeClass::add($gbData, true);
  272. $clear->customBalanceChangeId = $cbc->id ?? 0;
  273. $clear->ghsBalanceChangeId = $gbc->id ?? 0;
  274. $clear->save();
  275. }
  276. /** 供货商帮充与花店线上充:成对充值单互相关联,供余额明细展示结账单 */
  277. protected static function linkCustomAndGhsRecharge($customRecharge, $ghsRecharge)
  278. {
  279. if (empty($customRecharge) || empty($ghsRecharge)) {
  280. return;
  281. }
  282. $customRechargeId = intval(is_object($customRecharge) ? ($customRecharge->id ?? 0) : 0);
  283. $ghsRechargeId = intval(is_object($ghsRecharge) ? ($ghsRecharge->id ?? 0) : 0);
  284. if ($customRechargeId <= 0 || $ghsRechargeId <= 0) {
  285. return;
  286. }
  287. $cProbe = new \bizGhs\custom\models\CustomRecharge();
  288. if (method_exists($cProbe, 'hasAttribute') && $cProbe->hasAttribute('ghsRechargeId')) {
  289. $customRecharge->ghsRechargeId = $ghsRechargeId;
  290. $customRecharge->save(false, ['ghsRechargeId']);
  291. }
  292. $gProbe = new \bizGhs\ghs\models\GhsRecharge();
  293. if (method_exists($gProbe, 'hasAttribute') && $gProbe->hasAttribute('customRechargeId')) {
  294. $ghsRecharge->customRechargeId = $customRechargeId;
  295. $ghsRecharge->save(false, ['customRechargeId']);
  296. }
  297. }
  298. // 充值/返充(增加净 balance);有多个地方要同步修改,请搜索关键词 custom_ghs_recharge ssh 20240310
  299. public static function rechargeBalance($custom, $amount, $shop, $staff, $payWay, $params = [])
  300. {
  301. // 充值前合并;之后对 balance 做 bcadd(只记余额变动)
  302. AccountMoneyClass::ensureCustomMoneyReady($custom, true);
  303. $ghsId = $custom->ghsId ?? 0;
  304. $ghsInfo = GhsClass::getLockById($ghsId);
  305. AccountMoneyClass::ensureGhsMoneyReady($ghsInfo, true);
  306. if (empty($ghsInfo)) {
  307. util::fail('没有找到供货商');
  308. }
  309. $ghsShopId = $ghsInfo->shopId ?? 0;
  310. $ghsName = $ghsInfo->name ?? '';
  311. $customId = $custom->id ?? 0;
  312. $customShopId = $custom->shopId ?? 0;
  313. $customName = $custom->name ?? '';
  314. $customShop = ShopClass::getById($customShopId, true);
  315. if (empty($customShop)) {
  316. util::fail('没有找到客户门店');
  317. }
  318. $payTime = date("Y-m-d H:i:s");
  319. $customShopSjId = $customShop->sjId ?? 0;
  320. $customShopMainId = $customShop->mainId ?? 0;
  321. $custom->balance = bcadd($custom->balance, $amount, 2);
  322. $custom->save();
  323. $orderSn = orderSn::getGhsCustomRechargeSn();
  324. $shopId = $shop->id ?? 0;
  325. $sjId = $shop->sjId ?? 0;
  326. $mainId = $shop->mainId ?? 0;
  327. $staffId = $staff->id ?? 0;
  328. $staffName = $staff->name ?? '';
  329. $remark = $params['remark'] ?? '';
  330. $rechargeType = $params['rechargeType'] ?? 0;
  331. $payMap = dict::getDict('payWayName');
  332. $payName = $payMap[$payWay] ?? '';
  333. $rechargeEvent = $payName . '充值';
  334. if ($rechargeType == 1) {
  335. $rechargeEvent = '售后返充';
  336. }
  337. $cData = [
  338. 'orderSn' => $orderSn,
  339. 'onlinePay' => 1,
  340. 'payWay' => $payWay,
  341. 'shopId' => $shopId,
  342. 'mainId' => $mainId,
  343. 'amount' => $amount,
  344. 'balance' => $custom->balance,
  345. 'side' => 0,
  346. 'staffId' => $staffId,
  347. 'staffName' => $staffName,
  348. 'payStatus' => 1,
  349. 'status' => 1,
  350. 'ghsId' => $ghsId,
  351. 'ghsShopId' => $ghsShopId,
  352. 'ghsName' => $ghsName,
  353. 'customId' => $customId,
  354. 'customShopId' => $customShopId,
  355. 'customName' => $customName,
  356. 'remark' => $remark,
  357. 'payTime' => $payTime,
  358. 'rechargeType' => $rechargeType,
  359. ];
  360. if (!empty($params['clearAudit']) && is_array($params['clearAudit'])) {
  361. $cData = CustomBalanceChangeClass::mergeClearAuditIntoRechargeData($cData, $params['clearAudit']);
  362. }
  363. $cRecharge = CustomRechargeClass::add($cData, true);
  364. $cRechargeId = $cRecharge->id ?? 0;
  365. $capitalType = dict::getDict('capitalType', 'ghsHelpCustomRecharge', 'id');
  366. if ($rechargeType == 1) {
  367. //售后返充
  368. $capitalType = dict::getDict('capitalType', 'ghsHelpCustomRechargeReturn', 'id');
  369. }
  370. $fromType = dict::getDict('fromType', 'shop');
  371. $cbData = [
  372. 'customId' => $customId,
  373. 'customName' => $customName,
  374. 'relateId' => $cRechargeId,
  375. 'onlinePay' => 1,
  376. 'ptStyle' => 2,
  377. 'capitalType' => $capitalType,
  378. 'amount' => $amount,
  379. 'balance' => $custom->balance,
  380. 'staffId' => $staffId,
  381. 'staffName' => $staffName,
  382. 'io' => 1,
  383. 'side' => 0,
  384. 'payWay' => $payWay,
  385. 'fromType' => $fromType,
  386. 'event' => $rechargeEvent,
  387. 'mainId' => $mainId,
  388. 'shopId' => $shopId,
  389. 'sjId' => $sjId,
  390. 'remark' => $remark,
  391. ];
  392. if (!empty($params['clearAudit']) && is_array($params['clearAudit'])) {
  393. $cbData = CustomBalanceChangeClass::mergeClearAuditIntoRowData($cbData, $params['clearAudit']);
  394. }
  395. CustomBalanceChangeClass::add($cbData, true);
  396. $ghsInfo->balance = bcadd($ghsInfo->balance, $amount, 2);
  397. $ghsInfo->save();
  398. $orderSn = orderSn::getGhsRechargeSn();
  399. $customMainId = $custom->mainId ?? 0;
  400. $gData = [
  401. 'orderSn' => $orderSn,
  402. 'onlinePay' => 1,
  403. 'payWay' => $payWay,
  404. 'shopId' => $customShopId,
  405. 'mainId' => $customMainId,
  406. 'amount' => $amount,
  407. 'balance' => $ghsInfo->balance,
  408. 'side' => 0,
  409. 'staffId' => 0,
  410. 'staffName' => '',
  411. 'payStatus' => 1,
  412. 'status' => 1,
  413. 'ghsId' => $ghsId,
  414. 'ghsShopId' => $ghsShopId,
  415. 'ghsName' => $ghsName,
  416. 'customId' => $customId,
  417. 'customShopId' => $customShopId,
  418. 'customName' => $customName,
  419. 'remark' => $remark,
  420. 'payTime' => $payTime,
  421. 'rechargeType' => $rechargeType,
  422. ];
  423. $gRecharge = GhsRechargeClass::add($gData, true);
  424. $gRechargeId = $gRecharge->id ?? 0;
  425. self::linkCustomAndGhsRecharge($cRecharge, $gRecharge);
  426. $capitalType = dict::getDict('capitalType', 'customAskGhsRecharge', 'id');
  427. if ($rechargeType == 1) {
  428. //售后返充
  429. $capitalType = dict::getDict('capitalType', 'customAskGhsRechargeReturn', 'id');
  430. }
  431. $gbData = [
  432. 'ghsId' => $ghsId,
  433. 'ghsName' => $ghsName,
  434. 'relateId' => $gRechargeId,
  435. 'ptStyle' => 2,
  436. 'capitalType' => $capitalType,
  437. 'amount' => $amount,
  438. 'balance' => $ghsInfo->balance,
  439. 'io' => 1,
  440. 'side' => 0,
  441. 'onlinePay' => 1,
  442. 'payWay' => $payWay,
  443. 'fromType' => $fromType,
  444. 'event' => $rechargeEvent,
  445. 'sjId' => $customShopSjId,
  446. 'mainId' => $customShopMainId,
  447. 'shopId' => $customShopId,
  448. 'remark' => $remark,
  449. ];
  450. GhsBalanceChangeClass::add($gbData, true);
  451. // 现金充值,同步更新表 xhMain 的 money 字段
  452. if ($payWay == 4) {
  453. $m = \bizGhs\shop\classes\MainClass::getById($mainId, true, 'id, money');
  454. $balance = $m->money;
  455. $m->money = bcadd($m->money, $amount);
  456. $m->save();
  457. $event = '客户(' . $customName . ')充值' . $amount . '元';
  458. $data = [
  459. 'amount' => $amount,
  460. 'balance' => $balance,
  461. 'io' => 1,
  462. 'mainId' => $mainId,
  463. 'capitalType' => $capitalType,
  464. 'ptStyle' => dict::getDict('ptStyle', 'ghs'),
  465. 'event' => $event,
  466. 'remark' => $remark,
  467. ];
  468. ShopMoneyClass::addData($data);
  469. }
  470. return ['custom' => $custom, 'ghs' => $ghsInfo, 'customRecharge' => $cRecharge, 'ghsRecharge' => $gRecharge];
  471. }
  472. public static function createSeatSn($mainId)
  473. {
  474. $max = Custom::find(['mainId' => $mainId])->max('seatSn');
  475. $new = bcadd($max, 1);
  476. return $new;
  477. }
  478. //建立客户和供货商关系
  479. public static function build($ghsShopId, $hdShopId, $changeName = '')
  480. {
  481. return GhsClass::build($ghsShopId, $hdShopId, 2, $changeName);
  482. }
  483. //添加客户 ssh 2021.2.24
  484. public static function addCustom($data)
  485. {
  486. return self::add($data);
  487. }
  488. //获取客户信息 ssh 2021.2.4
  489. public static function getCustom($id)
  490. {
  491. $info = self::getById($id);
  492. if (empty($info)) {
  493. return $info;
  494. }
  495. $respond = self::groupBaseInfo([$info]);
  496. return current($respond);
  497. }
  498. public static function getCustomByIds($ids)
  499. {
  500. $list = self::getByIds($ids, null, 'id');
  501. return self::groupBaseInfo($list);
  502. }
  503. //整合头像等信息 ssh 2021.1.8
  504. public static function groupBaseInfo($list, $mainId = 0)
  505. {
  506. if (empty($list)) {
  507. return $list;
  508. }
  509. //片区划分
  510. $distMap = [];
  511. $custom = current($list);
  512. if (!empty($custom) && !empty($custom['ownMainId'])) {
  513. $distMap = DistClass::getAllByCondition(['mainId' => $custom['ownMainId']], null, '*', 'id');
  514. }
  515. $levelMap = self::$levelMap;
  516. foreach ($list as $key => $val) {
  517. $smallAvatar = imgUtil::getPrefix() . (!empty($val['avatar']) ? $val['avatar'] : '/hhb_small.png') . '?x-oss-process=image/resize,m_fill,h_130,w_130';
  518. $avatar = imgUtil::getPrefix() . (!empty($val['avatar']) ? $val['avatar'] : '/hhb_small.png');
  519. $list[$key]['smallAvatar'] = $smallAvatar;
  520. $list[$key]['avatar'] = $avatar;
  521. $list[$key]['sn'] = $val['id'];
  522. $level = $val['level'] ?? 1;
  523. $levelName = $levelMap[$level] ?? '';
  524. $list[$key]['levelName'] = $levelName;
  525. // 按 appVersion 输出净 balance 或旧版待结+余额字段(合并仅由控制台脚本执行)
  526. $list[$key] = AccountMoneyClass::formatMoneyForClient($list[$key]);
  527. //前端使用,走播,预订客户添加新客户
  528. $list[$key]['zbNum'] = '';
  529. $list[$key]['zbPrice'] = '';
  530. //片区划分
  531. $distId = $val['distId'] ?? 0;
  532. $distInfo = $distMap[$distId] ?? [];
  533. $distName = $distInfo['name'] ?? '';
  534. //注意区别 dist 字段,dist字段是地图里的区
  535. $list[$key]['distName'] = $distName;
  536. //超时未下单
  537. $recentExpend = $val['recentExpend'] ?? '';
  538. $list[$key]['overTimeUnExpend'] = 0;
  539. if ($recentExpend == '0000-00-00 00:00:00') {
  540. $list[$key]['overTimeUnExpend'] = 10000;
  541. } else {
  542. $recentExpendTime = strtotime($recentExpend);
  543. $seven = bcmul(86400, 7);
  544. $sevenTime = bcadd($recentExpendTime, $seven);
  545. if ($sevenTime < time()) {
  546. $list[$key]['overTimeUnExpend'] = 7;
  547. }
  548. $month = bcmul(86400, 30);
  549. $monthTime = bcadd($recentExpendTime, $month);
  550. if ($monthTime < time()) {
  551. $list[$key]['overTimeUnExpend'] = 30;
  552. }
  553. $halfYear = bcmul(86400, 180);
  554. $halfYearTime = bcadd($recentExpendTime, $halfYear);
  555. if ($halfYearTime < time()) {
  556. $list[$key]['overTimeUnExpend'] = 180;
  557. }
  558. $year = bcmul(86400, 365);
  559. $yearTime = bcmul($recentExpendTime, $year);
  560. if ($yearTime < time()) {
  561. $list[$key]['overTimeUnExpend'] = 365;
  562. }
  563. }
  564. }
  565. return $list;
  566. }
  567. //欠款权限开关 ssh 2021.1.8
  568. public static function debt($custom, $debt)
  569. {
  570. $id = $custom['id'] ?? 0;
  571. self::updateById($id, ['debt' => $debt]);
  572. return true;
  573. }
  574. //采购查看权限的黑白名单设置 shizhongqi 2021.08.08
  575. public static function black($custom, $black)
  576. {
  577. $id = $custom['id'] ?? 0;
  578. self::updateById($id, ['black' => $black]);
  579. return true;
  580. }
  581. //权限判断 ssh 2021.1.8
  582. public static function valid($custom, $shopId)
  583. {
  584. if (empty($custom)) {
  585. util::fail('没有找到客户');
  586. }
  587. if ($custom['ownShopId'] != $shopId) {
  588. util::fail('您无法操作此客户');
  589. }
  590. }
  591. /**
  592. * 调用方已 lockAccountPair 时,校验 custom/ghs 净余额一致。
  593. */
  594. protected static function assertPairBalanceEqual($custom, $ghs)
  595. {
  596. if (empty($ghs)) {
  597. return;
  598. }
  599. $customBal = bcadd((string)($custom->balance ?? '0'), '0', 2);
  600. $ghsBal = bcadd((string)($ghs->balance ?? '0'), '0', 2);
  601. if (bccomp($customBal, $ghsBal, 2) !== 0) {
  602. util::fail('余额不一致,请联系管理员');
  603. }
  604. }
  605. /**
  606. * 开单扣减净 balance:写 custom(及成对 ghs),调用方须已 FOR UPDATE 锁行。
  607. */
  608. protected static function savePairBalanceAfterDeduct($custom, $ghs, $newBalance)
  609. {
  610. $newBalance = bcadd((string)$newBalance, '0', 2);
  611. $custom->balance = $newBalance;
  612. $custom->isDebt = bccomp($newBalance, '0', 2) < 0 ? CustomClass::IS_DEBT_YES : CustomClass::IS_DEBT_NO;
  613. $custom->save(false, ['balance', 'isDebt']);
  614. if (empty($ghs)) {
  615. return;
  616. }
  617. AccountMoneyClass::ensureGhsMoneyReady($ghs, true);
  618. $ghs->balance = $newBalance;
  619. $ghs->debt = bccomp($newBalance, '0', 2) < 0 ? 2 : 1;
  620. $ghs->save(false, ['balance', 'debt']);
  621. self::assertPairBalanceEqual($custom, $ghs);
  622. }
  623. /**
  624. * hdApp 供货商余额明细:事项单号优先用 xhCg.orderSn,无采购单时再退回销售单号。
  625. *
  626. * @param object|array $order 供货商销售单
  627. * @return string
  628. */
  629. protected static function resolveXhCgOrderSnForHdEvent($order)
  630. {
  631. $saleOrderSn = is_object($order) ? ($order->orderSn ?? '') : ($order['orderSn'] ?? '');
  632. $purchaseId = intval(is_object($order) ? ($order->purchaseId ?? 0) : ($order['purchaseId'] ?? 0));
  633. if ($purchaseId <= 0) {
  634. return $saleOrderSn;
  635. }
  636. $cg = PurchaseClass::getById($purchaseId, true);
  637. if (empty($cg)) {
  638. return $saleOrderSn;
  639. }
  640. $cgOrderSn = $cg->orderSn ?? '';
  641. return $cgOrderSn !== '' ? $cgOrderSn : $saleOrderSn;
  642. }
  643. /**
  644. * 花店采购余额付售后:成对账户原路退回(与 payToChangeBalance 对称)。
  645. * 调用方须已 lockAccountPair;同时写客户余额明细与 xhGhs 余额明细(hdApp 可查)。
  646. */
  647. public static function refundBalancePayToPair($custom, $ghs, $refund, $order)
  648. {
  649. AccountMoneyClass::ensureCustomMoneyReady($custom, true);
  650. if (!empty($ghs)) {
  651. AccountMoneyClass::ensureGhsMoneyReady($ghs, true);
  652. self::assertPairBalanceEqual($custom, $ghs);
  653. }
  654. $refundPrice = bcadd((string)($refund->refundPrice ?? '0'), '0', 2);
  655. if (bccomp($refundPrice, '0', 2) <= 0) {
  656. return;
  657. }
  658. $newBalance = bcadd((string)($custom->balance ?? '0'), $refundPrice, 2);
  659. self::savePairBalanceAfterDeduct($custom, $ghs, $newBalance);
  660. $relateId = $refund->id ?? 0;
  661. $customId = $custom->id ?? 0;
  662. $customName = $custom->name ?? '';
  663. $saleOrderSn = $order->orderSn ?? '';
  664. $capitalType = dict::getDict('capitalType', 'saleRefund', 'id');
  665. $payTime = $order->payTime ?? '';
  666. $change = [
  667. 'relateId' => $relateId,
  668. 'customId' => $customId,
  669. 'customName' => $customName,
  670. 'ptStyle' => dict::getDict('ptStyle', 'ghs'),
  671. 'capitalType' => $capitalType,
  672. 'amount' => $refundPrice,
  673. 'balance' => $newBalance,
  674. 'io' => 1,
  675. 'payWay' => dict::getDict('payWay', 'balancePay'),
  676. 'event' => "订单售后退款,单号:{$saleOrderSn}",
  677. 'sjId' => $refund->sjId ?? 0,
  678. 'shopId' => $refund->shopId ?? 0,
  679. 'mainId' => $order->mainId ?? 0,
  680. 'payTime' => $payTime,
  681. 'staffId' => 0,
  682. 'staffName' => '',
  683. 'side' => 0,
  684. 'fromType' => dict::getDict('fromType', 'shop'),
  685. 'remark' => '',
  686. ];
  687. CustomBalanceChangeClass::add($change, true);
  688. self::addGhsRefundBalanceChange($custom, $ghs, $refund, $order, $refundPrice, $newBalance);
  689. }
  690. /** 花店采购余额退款:记 xhGhs 余额变动(与 addGhsOrderBalanceChange 对称,hdApp 余额明细展示) */
  691. protected static function addGhsRefundBalanceChange($custom, $ghs, $refund, $order, $amount, $newBalance)
  692. {
  693. if (empty($ghs)) {
  694. return;
  695. }
  696. // hd 端明细展示采购单号 xhCg.orderSn
  697. $orderSn = self::resolveXhCgOrderSnForHdEvent($order);
  698. $customShopId = $custom->shopId ?? 0;
  699. $customShop = ShopClass::getById($customShopId, true);
  700. $gbData = [
  701. 'ghsId' => $ghs->id ?? 0,
  702. 'relateId' => $refund->id ?? 0,
  703. 'ptStyle' => dict::getDict('ptStyle', 'ghs'),
  704. 'capitalType' => dict::getDict('capitalType', 'saleRefund', 'id'),
  705. 'amount' => $amount,
  706. 'balance' => $newBalance,
  707. 'io' => 1,
  708. 'side' => 0,
  709. 'onlinePay' => 1,
  710. 'payWay' => dict::getDict('payWay', 'balancePay'),
  711. 'fromType' => dict::getDict('fromType', 'shop'),
  712. 'event' => "订单售后退款,单号:{$orderSn}",
  713. 'sjId' => $customShop->sjId ?? ($custom->sjId ?? 0),
  714. 'mainId' => $customShop->mainId ?? 0,
  715. 'shopId' => $customShopId,
  716. 'remark' => '',
  717. ];
  718. GhsBalanceChangeClass::add($gbData, true);
  719. }
  720. protected static function addGhsOrderBalanceChange($custom, $ghs, $order, $amount, $newBalance, $bookOrder = false)
  721. {
  722. if (empty($ghs)) {
  723. return;
  724. }
  725. // hd 端明细展示采购单号 xhCg.orderSn
  726. $orderSn = self::resolveXhCgOrderSnForHdEvent($order);
  727. $event = '购买花材,单号:' . $orderSn;
  728. if ($bookOrder) {
  729. $event = '预订单多退少补,单号:' . $orderSn;
  730. }
  731. $customShopId = $custom->shopId ?? 0;
  732. $customShop = ShopClass::getById($customShopId, true);
  733. $gbData = [
  734. 'ghsId' => $ghs->id ?? 0,
  735. 'relateId' => $order->id ?? 0,
  736. 'ptStyle' => dict::getDict('ptStyle', 'ghs'),
  737. 'capitalType' => dict::getDict('capitalType', 'xhGhsOrder', 'id'),
  738. 'amount' => $amount,
  739. 'balance' => $newBalance,
  740. 'io' => 0,
  741. 'side' => 0,
  742. 'onlinePay' => 1,
  743. 'payWay' => $order->payWay ?? 0,
  744. 'fromType' => dict::getDict('fromType', 'shop'),
  745. 'event' => $event,
  746. 'sjId' => $customShop->sjId ?? ($custom->sjId ?? 0),
  747. 'mainId' => $customShop->mainId ?? 0,
  748. 'shopId' => $customShopId,
  749. 'remark' => '',
  750. ];
  751. GhsBalanceChangeClass::add($gbData, true);
  752. }
  753. /**
  754. * 充值退款:扣减成对客户/供货商净余额(调用方须已 lockAccountPair)。
  755. *
  756. * @return string 扣减后的净余额
  757. */
  758. public static function deductPairBalanceForRefund($custom, $ghs, $amount)
  759. {
  760. AccountMoneyClass::ensureCustomMoneyReady($custom, true);
  761. if (!empty($ghs)) {
  762. AccountMoneyClass::ensureGhsMoneyReady($ghs, true);
  763. self::assertPairBalanceEqual($custom, $ghs);
  764. }
  765. $amount = bcadd((string)$amount, '0', 2);
  766. if (bccomp($amount, '0', 2) <= 0) {
  767. util::fail('退款金额有误');
  768. }
  769. $beforeBalance = bcadd((string)($custom->balance ?? '0'), '0', 2);
  770. if (bccomp($beforeBalance, $amount, 2) < 0) {
  771. util::fail('客户余额不足,本笔充值可能已用于销账或消费');
  772. }
  773. $newBalance = bcsub($beforeBalance, $amount, 2);
  774. self::savePairBalanceAfterDeduct($custom, $ghs, $newBalance);
  775. return $newBalance;
  776. }
  777. /**
  778. * 后台手动减少客户净余额(只减正余额部分,不增加待结)。
  779. * 调用方须已通过 lockAccountPair 锁定 custom/ghs。
  780. */
  781. public static function manualDeductBalance($shop, $custom, $ghs, $amount, $params = [])
  782. {
  783. if (empty($custom)) {
  784. util::fail('没有找到客户');
  785. }
  786. AccountMoneyClass::ensureCustomMoneyReady($custom, true);
  787. if (!empty($ghs)) {
  788. AccountMoneyClass::ensureGhsMoneyReady($ghs, true);
  789. self::assertPairBalanceEqual($custom, $ghs);
  790. }
  791. $amount = bcadd((string)$amount, '0', 2);
  792. if (bccomp($amount, '0', 2) <= 0) {
  793. util::fail('金额要大于0');
  794. }
  795. $beforeBalance = bcadd((string)($custom->balance ?? '0'), '0', 2);
  796. if (bccomp($beforeBalance, '0', 2) <= 0) {
  797. util::fail('没有可减余额');
  798. }
  799. if (bccomp($beforeBalance, $amount, 2) < 0) {
  800. util::fail('余额不够扣');
  801. }
  802. $newBalance = bcsub($beforeBalance, $amount, 2);
  803. self::savePairBalanceAfterDeduct($custom, $ghs, $newBalance);
  804. $remark = $params['remark'] ?? '';
  805. $staffId = intval($params['staffId'] ?? 0);
  806. $staffName = $params['staffName'] ?? '';
  807. $mainId = $shop->mainId ?? 0;
  808. $shopId = $shop->id ?? 0;
  809. $sjId = $shop->sjId ?? 0;
  810. $customId = $custom->id ?? 0;
  811. $customName = $custom->name ?? '';
  812. $capitalType = dict::getDict('capitalType', 'deduct', 'id');
  813. $fromType = dict::getDict('fromType', 'shop');
  814. $event = '手动减少';
  815. CustomBalanceChangeClass::add([
  816. 'customId' => $customId,
  817. 'customName' => $customName,
  818. 'relateId' => 0,
  819. 'onlinePay' => 1,
  820. 'ptStyle' => dict::getDict('ptStyle', 'ghs'),
  821. 'capitalType' => $capitalType,
  822. 'amount' => $amount,
  823. 'balance' => $newBalance,
  824. 'staffId' => $staffId,
  825. 'staffName' => $staffName,
  826. 'io' => 0,
  827. 'side' => 0,
  828. 'payWay' => 0,
  829. 'fromType' => $fromType,
  830. 'event' => $event,
  831. 'mainId' => $mainId,
  832. 'shopId' => $shopId,
  833. 'sjId' => $sjId,
  834. 'remark' => $remark,
  835. ], true);
  836. if (!empty($ghs)) {
  837. $customShopId = $custom->shopId ?? 0;
  838. $customShop = ShopClass::getById($customShopId, true);
  839. GhsBalanceChangeClass::add([
  840. 'ghsId' => $ghs->id ?? 0,
  841. 'relateId' => 0,
  842. 'ptStyle' => dict::getDict('ptStyle', 'ghs'),
  843. 'capitalType' => $capitalType,
  844. 'amount' => $amount,
  845. 'balance' => $newBalance,
  846. 'io' => 0,
  847. 'side' => 0,
  848. 'onlinePay' => 1,
  849. 'payWay' => 0,
  850. 'fromType' => $fromType,
  851. 'event' => $event,
  852. 'sjId' => $customShop->sjId ?? 0,
  853. 'mainId' => $customShop->mainId ?? 0,
  854. 'shopId' => $customShopId,
  855. 'remark' => $remark,
  856. ], true);
  857. }
  858. }
  859. /**
  860. * 开单余额支付:扣减净 balance 并记购买流水(须传入 payAfter 已 lockAccountPair 的 custom/ghs)。
  861. */
  862. public static function payToChangeBalance($order, $custom, $ghs = null)
  863. {
  864. $actPrice = bcadd((string)($order->actPrice ?? '0'), '0', 2);
  865. if (bccomp($actPrice, '0', 2) <= 0) {
  866. return;
  867. }
  868. if (empty($custom)) {
  869. util::fail('没有找到客户');
  870. }
  871. AccountMoneyClass::ensureCustomMoneyReady($custom, true);
  872. if (!empty($ghs)) {
  873. AccountMoneyClass::ensureGhsMoneyReady($ghs, true);
  874. self::assertPairBalanceEqual($custom, $ghs);
  875. }
  876. $beforeBalance = bcadd((string)($custom->balance ?? '0'), '0', 2);
  877. if (bccomp($beforeBalance, $actPrice, 2) < 0) {
  878. util::fail('余额不足');
  879. }
  880. $newBalance = bcsub($beforeBalance, $actPrice, 2);
  881. self::savePairBalanceAfterDeduct($custom, $ghs, $newBalance);
  882. $orderSn = $order->orderSn ?? '';
  883. $customId = $custom->id ?? 0;
  884. $capitalType = dict::getDict('capitalType', 'xhGhsOrder', 'id');
  885. $change = [
  886. 'relateId' => $order->id ?? 0,
  887. 'customId' => $customId,
  888. 'customName' => $custom->name ?? '',
  889. 'ptStyle' => dict::getDict('ptStyle', 'ghs'),
  890. 'capitalType' => $capitalType,
  891. 'amount' => $actPrice,
  892. 'balance' => $newBalance,
  893. 'io' => 0,
  894. 'payWay' => dict::getDict('payWay', 'balancePay'),
  895. 'event' => '购买花材,单号:' . $orderSn,
  896. 'sjId' => $order->sjId ?? 0,
  897. 'shopId' => $order->shopId ?? 0,
  898. 'mainId' => $order->mainId ?? 0,
  899. 'staffId' => $order->shopAdminId ?? 0,
  900. 'staffName' => $order->shopAdminName ?? '',
  901. 'side' => 0,
  902. 'fromType' => dict::getDict('fromType', 'shop'),
  903. 'remark' => '',
  904. ];
  905. CustomBalanceChangeClass::add($change, true);
  906. self::addGhsOrderBalanceChange($custom, $ghs, $order, $actPrice, $newBalance, false);
  907. }
  908. /**
  909. * 挂账开单时若账户有正余额且不足本单:用余额先结本单一部分(只改 remainDebtPrice,不另扣 balance)。
  910. */
  911. protected static function inlineOrderBalancePartialClear($custom, $order, $clearAmount)
  912. {
  913. $clearAmount = bcadd((string)$clearAmount, '0', 2);
  914. if (bccomp($clearAmount, '0', 2) <= 0) {
  915. return;
  916. }
  917. $orderId = intval($order->id ?? 0);
  918. if ($orderId <= 0) {
  919. return;
  920. }
  921. $shopId = intval($order->shopId ?? 0);
  922. $shop = ShopClass::getById($shopId, true);
  923. if (empty($shop)) {
  924. util::fail('没有找到门店');
  925. }
  926. $staffId = intval($order->shopAdminId ?? 0);
  927. $staffName = $order->shopAdminName ?? '';
  928. $sjId = $shop->sjId ?? 0;
  929. $orderSn = $order->orderSn ?? '';
  930. OrderClearClass::expireAwaitPayClears(intval($custom->id ?? 0));
  931. $clear = OrderClearClass::clearWithAmountMap([
  932. 'customId' => $custom->id ?? 0,
  933. 'ghsShopAdminId' => $staffId,
  934. 'ghsShopId' => $shopId,
  935. 'ghsShopAdminName' => $staffName,
  936. 'modifyPrice' => $clearAmount,
  937. 'payWay' => dict::getDict('payWay', 'balancePay'),
  938. 'complete' => 0,
  939. 'remark' => '开单余额抵挂账',
  940. ], [
  941. ['orderId' => $orderId, 'clearAmount' => $clearAmount, 'orderSn' => $orderSn],
  942. ], $sjId, $shopId);
  943. OrderClearClass::applyNetBalanceClear($clear, dict::getDict('payWay', 'balancePay'), ['skipCashMoney' => true]);
  944. }
  945. /**
  946. * 挂账开单:增加客户待结(改造后 balance 减少,只记余额变动,不再记挂账变动)
  947. * ssh 20220306
  948. */
  949. public static function cgDebtAmountAdd($custom, $order, $bookOrder = false, $ghs = null)
  950. {
  951. // 挂账开单:合并后 balance 减少,不再写 CustomDebtChange
  952. AccountMoneyClass::ensureCustomMoneyReady($custom, true);
  953. if (!empty($ghs)) {
  954. AccountMoneyClass::ensureGhsMoneyReady($ghs, true);
  955. self::assertPairBalanceEqual($custom, $ghs);
  956. }
  957. $amount = bcadd((string)($order->remainDebtPrice ?? '0'), '0', 2);
  958. if (bccomp($amount, '0', 2) <= 0) {
  959. return;
  960. }
  961. $beforeBalance = bcadd((string)($custom->balance ?? '0'), '0', 2);
  962. $positiveBalance = bccomp($beforeBalance, '0', 2) > 0 ? $beforeBalance : '0.00';
  963. if (bccomp($positiveBalance, $amount, 2) >= 0) {
  964. util::fail('余额充足,请用余额支付');
  965. }
  966. if (bccomp($positiveBalance, '0', 2) > 0) {
  967. self::inlineOrderBalancePartialClear($custom, $order, $positiveBalance);
  968. }
  969. $custom->isDebt = CustomClass::IS_DEBT_YES;
  970. $debtLimit = $custom->debtLimit ?? 0;
  971. if (!$bookOrder) {
  972. if (isset($order->shopAdminId) && $order->shopAdminId == 0) {
  973. $outstanding = AccountMoneyClass::getOutstandingDebt($custom);
  974. if (bccomp($outstanding, $debtLimit, 2) > 0) {
  975. if ($custom->live == 1) {
  976. util::fail("已欠款{$outstanding},请先结账哦");
  977. }
  978. }
  979. }
  980. }
  981. $newBalance = bcsub($beforeBalance, $amount, 2);
  982. $mustNotice = false;
  983. if (getenv('YII_ENV') == 'production') {
  984. if ($custom->id == 11726) {
  985. $mustNotice = true;
  986. }
  987. } else {
  988. if ($custom->id == 577) {
  989. $mustNotice = true;
  990. }
  991. }
  992. if (getenv('YII_ENV', 'local') == 'production') {
  993. if ($mustNotice) {
  994. noticeUtil::push("【开单动作 | 客户】变化前余额:{$beforeBalance} 变化金额:{$amount} 变化后余额:{$newBalance}", '15280215347');
  995. }
  996. }
  997. self::savePairBalanceAfterDeduct($custom, $ghs, $newBalance);
  998. $relateId = $order->id ?? 0;
  999. $customId = $custom->id ?? 0;
  1000. $customName = $custom->name ?? '';
  1001. $orderSn = $order->orderSn ?? '';
  1002. $capitalType = dict::getDict('capitalType', 'xhGhsOrder', 'id');
  1003. $event = '购买花材,单号:' . $orderSn;
  1004. if ($bookOrder) {
  1005. $event = '预订单多退少补,单号:' . $orderSn;
  1006. }
  1007. $change = [
  1008. 'relateId' => $relateId,
  1009. 'customId' => $customId,
  1010. 'customName' => $customName,
  1011. 'ptStyle' => dict::getDict('ptStyle', 'ghs'),
  1012. 'capitalType' => $capitalType,
  1013. 'amount' => $amount,
  1014. 'balance' => $newBalance,
  1015. 'io' => 0,
  1016. 'payWay' => $order->payWay,
  1017. 'event' => $event,
  1018. 'sjId' => $order->sjId,
  1019. 'shopId' => $order->shopId,
  1020. 'mainId' => $order->mainId,
  1021. 'staffId' => 0,
  1022. 'staffName' => '',
  1023. 'side' => 0,
  1024. 'fromType' => dict::getDict('fromType', 'shop'),
  1025. 'remark' => '',
  1026. ];
  1027. CustomBalanceChangeClass::add($change, true);
  1028. self::addGhsOrderBalanceChange($custom, $ghs, $order, $amount, $newBalance, $bookOrder);
  1029. $mainId = $order->mainId ?? 0;
  1030. $main = MainClass::getLockById($mainId);
  1031. if (empty($main)) {
  1032. util::fail('没有main信息8');
  1033. }
  1034. $debt = $main->debt ?? 0;
  1035. $remain = bcadd($debt, $amount, 2);
  1036. if (getenv('YII_ENV', 'local') == 'production') {
  1037. if ($mustNotice) {
  1038. noticeUtil::push("【开单动作 | 总欠款】变化前欠款:{$debt} 变化金额:{$amount} 变化后欠款:{$remain}", '15280215347');
  1039. }
  1040. }
  1041. $main->debt = $remain;
  1042. $main->save();
  1043. $event = $custom->name . ' 购买花材,单号:' . $orderSn;
  1044. $change['balance'] = $remain;
  1045. $change['event'] = $event;
  1046. TotalDebtChangeClass::addChange($change);
  1047. }
  1048. /**
  1049. * 结账收回挂账:balance 增加(原 debtAmount 减少逻辑)
  1050. * ssh 20220306
  1051. */
  1052. public static function clearDebtAmountReduce($custom, $ghs, $amount, $clear)
  1053. {
  1054. // 结账收回挂账:balance 增加,只记余额变动
  1055. AccountMoneyClass::ensureCustomMoneyReady($custom, true);
  1056. $beforeBalance = $custom->balance ?? '0.00';
  1057. $newBalance = bcadd($beforeBalance, $amount, 2);
  1058. if (bccomp($beforeBalance, '0', 2) < 0 && bccomp($newBalance, '0', 2) > 0) {
  1059. noticeUtil::push("客户账户余额:{$beforeBalance} 本次结账金额:{$amount} 客户ID:{$custom->id} 【里外金额有问题】", '15280215347');
  1060. util::fail('收款失败,结账后欠款金额会出现负数');
  1061. }
  1062. $custom->isDebt = bccomp($newBalance, '0', 2) < 0 ? CustomClass::IS_DEBT_YES : CustomClass::IS_DEBT_NO;
  1063. $custom->balance = $newBalance;
  1064. $custom->save(false, ['balance', 'isDebt']);
  1065. $relateId = $clear->id ?? 0;
  1066. $customId = $custom->id ?? 0;
  1067. $customName = $custom->name ?? '';
  1068. $capitalType = dict::getDict('capitalType', 'ghsXsClear', 'id');
  1069. $orderSn = $clear->orderSn ?? '';
  1070. $change = [
  1071. 'relateId' => $relateId,
  1072. 'customId' => $customId,
  1073. 'customName' => $customName,
  1074. 'ptStyle' => dict::getDict('ptStyle', 'ghs'),
  1075. 'capitalType' => $capitalType,
  1076. 'amount' => $amount,
  1077. 'balance' => $newBalance,
  1078. 'io' => 1,
  1079. 'payWay' => 0,
  1080. 'event' => "结账,单号:{$orderSn}",
  1081. 'sjId' => $ghs->sjId,
  1082. 'shopId' => $ghs->shopId,
  1083. 'mainId' => $ghs->mainId,
  1084. 'staffId' => 0,
  1085. 'staffName' => '',
  1086. 'side' => 0,
  1087. 'fromType' => dict::getDict('fromType', 'shop'),
  1088. 'remark' => '',
  1089. ];
  1090. CustomBalanceChangeClass::add($change, true);
  1091. $mainId = $ghs->mainId ?? 0;
  1092. $main = MainClass::getLockById($mainId);
  1093. if (empty($main)) {
  1094. util::fail('没有main信息9');
  1095. }
  1096. $debt = $main->debt ?? 0;
  1097. $remain = bcsub($debt, $amount, 2);
  1098. $main->debt = $remain;
  1099. $main->save();
  1100. $event = $custom->name . " 结账,单号:{$orderSn}";
  1101. $change['balance'] = $remain;
  1102. $change['event'] = $event;
  1103. TotalDebtChangeClass::addChange($change);
  1104. }
  1105. /**
  1106. * 售后退款:减少待结(balance 增加),只记余额变动
  1107. * ssh 20220306
  1108. */
  1109. public static function refundDebtAmountReduce($custom, $refund, $order)
  1110. {
  1111. // 退款减待结:balance 增加,只记余额变动
  1112. AccountMoneyClass::ensureCustomMoneyReady($custom, true);
  1113. $refundPrice = $refund->refundPrice ?? 0;
  1114. if (bccomp($refundPrice, '0', 2) <= 0) {
  1115. return;
  1116. }
  1117. $newBalance = bcadd($custom->balance ?? '0.00', $refundPrice, 2);
  1118. $custom->balance = $newBalance;
  1119. $custom->isDebt = bccomp($newBalance, '0', 2) < 0 ? CustomClass::IS_DEBT_YES : CustomClass::IS_DEBT_NO;
  1120. $custom->save(false, ['balance', 'isDebt']);
  1121. $relateId = $refund->id ?? 0;
  1122. $customId = $custom->id ?? 0;
  1123. $customName = $custom->name ?? '';
  1124. $saleOrderSn = $order->orderSn ?? '';
  1125. $capitalType = dict::getDict('capitalType', 'saleRefund', 'id');
  1126. $payTime = $order->payTime;
  1127. $change = [
  1128. 'relateId' => $relateId,
  1129. 'customId' => $customId,
  1130. 'customName' => $customName,
  1131. 'ptStyle' => dict::getDict('ptStyle', 'ghs'),
  1132. 'capitalType' => $capitalType,
  1133. 'amount' => $refundPrice,
  1134. 'balance' => $newBalance,
  1135. 'io' => 1,
  1136. 'payWay' => 0,
  1137. 'event' => "订单号:{$saleOrderSn} 退款",
  1138. 'sjId' => $refund->sjId,
  1139. 'shopId' => $refund->shopId,
  1140. 'mainId' => $order->mainId,
  1141. 'payTime' => $payTime,
  1142. 'staffId' => 0,
  1143. 'staffName' => '',
  1144. 'side' => 0,
  1145. 'fromType' => dict::getDict('fromType', 'shop'),
  1146. 'remark' => '',
  1147. ];
  1148. CustomBalanceChangeClass::add($change, true);
  1149. $mainId = $order->mainId ?? 0;
  1150. $main = MainClass::getLockById($mainId);
  1151. if (empty($main)) {
  1152. util::fail('没有main信息10');
  1153. }
  1154. $debt = $main->debt ?? 0;
  1155. $remain = bcsub($debt, $refundPrice, 2);
  1156. $main->debt = $remain;
  1157. $main->save();
  1158. $event = $custom->name . " 订单号:{$saleOrderSn} 退款";
  1159. $change['balance'] = $remain;
  1160. $change['event'] = $event;
  1161. TotalDebtChangeClass::addChange($change);
  1162. }
  1163. public static function exportCustom($where, $sort, $mainId)
  1164. {
  1165. $list = self::getAllByCondition($where, $sort, '*', null);
  1166. if (empty($list)) {
  1167. util::fail('没有找到客户');
  1168. }
  1169. $list = self::groupBaseInfo($list);
  1170. $phpExcelFile = Yii::getAlias("@vendor/phpoffice/phpexcel/");
  1171. require_once($phpExcelFile . 'Classes/PHPExcel.php');
  1172. $objPHPExcel = new \PHPExcel();
  1173. $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
  1174. ->setLastModifiedBy("Maarten Balliauw")
  1175. ->setTitle("Office 2007 XLSX Document")
  1176. ->setSubject("Office 2007 XLSX Document")
  1177. ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
  1178. ->setKeywords("office 2007 openxml php")
  1179. ->setCategory("file");
  1180. $ghsTitle = '供货商';
  1181. $objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddHeader(date('n月j日') . " " . $ghsTitle);
  1182. $objPHPExcel->getActiveSheet()->getPageMargins()->setTop(0.7);
  1183. $objPHPExcel->getActiveSheet()->getPageMargins()->setBottom(0.1);
  1184. $objPHPExcel->getActiveSheet()->getPageMargins()->setLeft(0.5);
  1185. $objPHPExcel->getActiveSheet()->getPageMargins()->setRight(0);
  1186. $objPHPExcel->getActiveSheet()->getPageMargins()->setHeader(0.1);
  1187. $objPHPExcel->getActiveSheet()->getPageMargins()->setFooter(0);
  1188. $objPHPExcel->getActiveSheet()->setCellValue('A1', 'ID');
  1189. $objPHPExcel->getActiveSheet()->setCellValue('B1', '客户');
  1190. $objPHPExcel->getActiveSheet()->setCellValue('C1', '手机号');
  1191. $objPHPExcel->getActiveSheet()->setCellValue('D1', '欠款');
  1192. $objPHPExcel->getActiveSheet()->setCellValue('E1', '余额');
  1193. $objPHPExcel->getActiveSheet()->setCellValue('F1', '待结金额');
  1194. $objPHPExcel->getActiveSheet()->setCellValue('G1', '最近下单');
  1195. $objPHPExcel->getActiveSheet()->setCellValue('H1', '累计消费');
  1196. $objPHPExcel->getActiveSheet()->setCellValue('I1', '累计消费次数');
  1197. //设置宽度
  1198. $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(25);
  1199. $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(20);
  1200. $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(20);
  1201. $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(20);
  1202. $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(15);
  1203. $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(30);
  1204. $objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(15);
  1205. $objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(20);
  1206. //加粗
  1207. $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setSize(9)->setBold(true);
  1208. $objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->setSize(9)->setBold(true);
  1209. $objPHPExcel->getActiveSheet()->getStyle('C1')->getFont()->setSize(9)->setBold(true);
  1210. $objPHPExcel->getActiveSheet()->getStyle('D1')->getFont()->setSize(9)->setBold(true);
  1211. $objPHPExcel->getActiveSheet()->getStyle('E1')->getFont()->setSize(9)->setBold(true);
  1212. $objPHPExcel->getActiveSheet()->getStyle('F1')->getFont()->setSize(9)->setBold(true);
  1213. $objPHPExcel->getActiveSheet()->getStyle('G1')->getFont()->setSize(9)->setBold(true);
  1214. $objPHPExcel->getActiveSheet()->getStyle('H1')->getFont()->setSize(9)->setBold(true);
  1215. $objPHPExcel->getActiveSheet()->getStyle('I1')->getFont()->setSize(9)->setBold(true);
  1216. $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
  1217. $objPHPExcel->getActiveSheet()->getStyle('B1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
  1218. $objPHPExcel->getActiveSheet()->getStyle('C1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
  1219. $objPHPExcel->getActiveSheet()->getStyle('D1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
  1220. $objPHPExcel->getActiveSheet()->getStyle('E1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
  1221. $baseRow = 2;
  1222. foreach ($list as $key => $custom) {
  1223. $i = $baseRow + $key;
  1224. $objPHPExcel->getActiveSheet()->setCellValue('A' . $i, $custom['id']);
  1225. $objPHPExcel->getActiveSheet()->setCellValue('B' . $i, $custom['name']);
  1226. $objPHPExcel->getActiveSheet()->setCellValue('C' . $i, $custom['mobile'], \PHPExcel_Cell_DataType::TYPE_STRING);
  1227. $objPHPExcel->getActiveSheet()->setCellValue('D' . $i, $custom['debtAmount']);
  1228. $objPHPExcel->getActiveSheet()->setCellValue('E' . $i, $custom['balance']);
  1229. $objPHPExcel->getActiveSheet()->setCellValue('F' . $i, $custom['remainDebtAmount']);
  1230. if ($custom['recentExpend'] == '0000-00-00 00:00:00') {
  1231. $objPHPExcel->getActiveSheet()->setCellValue('G' . $i, '没有下过单');
  1232. } else {
  1233. $objPHPExcel->getActiveSheet()->setCellValue('G' . $i, $custom['recentExpend']);
  1234. }
  1235. $objPHPExcel->getActiveSheet()->setCellValue('H' . $i, $custom['buyAmount']);
  1236. $objPHPExcel->getActiveSheet()->setCellValue('I' . $i, $custom['buyNum']);
  1237. //居左
  1238. $objPHPExcel->getActiveSheet()->getStyle('A' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
  1239. $objPHPExcel->getActiveSheet()->getStyle('B' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
  1240. $objPHPExcel->getActiveSheet()->getStyle('C' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
  1241. $objPHPExcel->getActiveSheet()->getStyle('D' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
  1242. $objPHPExcel->getActiveSheet()->getStyle('E' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
  1243. $objPHPExcel->getActiveSheet()->getStyle('F' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
  1244. $objPHPExcel->getActiveSheet()->getStyle('G' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
  1245. $objPHPExcel->getActiveSheet()->getStyle('H' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
  1246. $objPHPExcel->getActiveSheet()->getStyle('I' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
  1247. }
  1248. $fileName = '客户-' . date("m-d");
  1249. $objPHPExcel->getActiveSheet()->setTitle($fileName);
  1250. $objPHPExcel->setActiveSheetIndex(0);
  1251. $dir = './priceTable/' . $mainId;
  1252. if (file_exists($dir) == false) {
  1253. mkdir($dir, 0777, true);
  1254. }
  1255. $date = $fileName;
  1256. $file = $date . '.xls';
  1257. $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  1258. if (file_exists($dir . '/' . $file)) {
  1259. unlink($dir . '/' . $file);
  1260. }
  1261. $objWriter->save($dir . '/' . $file);
  1262. $fileUrl = Yii::$app->params['ghsHost'] . '/priceTable/' . $mainId . '/' . $file;
  1263. util::success(['file' => $fileUrl, 'shortFile' => $file]);
  1264. }
  1265. public static function showTotalBalance($pfShopId = 0, $lsShopId = 0)
  1266. {
  1267. ini_set('memory_limit', '2045M');
  1268. set_time_limit(0);
  1269. $pfAmount = 0;
  1270. $lsAmount = 0;
  1271. if (!empty($pfShopId)) {
  1272. $custom = CustomClass::getAllByCondition(['ownShopId' => $pfShopId], null, '*', null, true);
  1273. if (!empty($custom)) {
  1274. foreach ($custom as $c) {
  1275. $new = AccountMoneyClass::getNetBalanceFromRow($c);
  1276. $pfAmount = bcadd($pfAmount, $new, 2);
  1277. }
  1278. }
  1279. }
  1280. if (!empty($lsShopId)) {
  1281. $lsCustom = \bizHd\custom\classes\CustomClass::getAllByCondition(['shopId' => $lsShopId], null, '*', null, true);
  1282. if (!empty($lsCustom)) {
  1283. foreach ($lsCustom as $lc) {
  1284. $balance = $lc->balance ?? 0;
  1285. $lsAmount = bcadd($balance, $lsAmount, 2);
  1286. }
  1287. }
  1288. }
  1289. return ['pfAmount' => $pfAmount, 'lsAmount' => $lsAmount];
  1290. }
  1291. /**
  1292. * 冲销凭证返充余额:同步增加 xhGhsCustom.balance 与镜像 xhGhs.balance,并各写余额变动。
  1293. * 用途:方案A ForwardService 在 fundType=返余额时调用;挂账结清后再冲销时语义等同「冲减欠款」。
  1294. * @param $custom object 已加锁的客户模型
  1295. * @param $forward object 冲销凭证模型(xhGhsForward)
  1296. * @param $returnAmount string|float 返充金额(正数)
  1297. * @return string 返充后的客户余额
  1298. */
  1299. public static function forwardReturnBalance($custom, $forward, $returnAmount)
  1300. {
  1301. $returnAmount = bcadd((string)$returnAmount, '0', 2);
  1302. if (bccomp($returnAmount, '0', 2) <= 0) {
  1303. util::fail('返充金额必须大于0');
  1304. }
  1305. AccountMoneyClass::ensureCustomMoneyReady($custom, true);
  1306. $ghsId = $custom->ghsId ?? 0;
  1307. $ghs = GhsClass::getLockById($ghsId);
  1308. if (!empty($ghs)) {
  1309. AccountMoneyClass::ensureGhsMoneyReady($ghs, true);
  1310. self::assertPairBalanceEqual($custom, $ghs);
  1311. }
  1312. $newBalance = bcadd((string)($custom->balance ?? '0'), $returnAmount, 2);
  1313. self::savePairBalanceAfterDeduct($custom, $ghs, $newBalance);
  1314. $forwardSn = $forward->forwardSn ?? '';
  1315. $customId = $custom->id ?? 0;
  1316. $capitalTypeCustom = dict::getDict('capitalType', 'ghsHelpCustomRechargeReturn', 'id');
  1317. $capitalTypeGhs = dict::getDict('capitalType', 'customAskGhsRechargeReturn', 'id');
  1318. CustomBalanceChangeClass::add([
  1319. 'relateId' => $forward->id ?? 0,
  1320. 'customId' => $customId,
  1321. 'customName' => $custom->name ?? '',
  1322. 'ptStyle' => dict::getDict('ptStyle', 'ghs'),
  1323. 'capitalType' => $capitalTypeCustom,
  1324. 'amount' => $returnAmount,
  1325. 'balance' => $newBalance,
  1326. 'io' => 1,
  1327. 'payWay' => dict::getDict('payWay', 'balancePay'),
  1328. 'event' => "冲销返充余额,凭证号:{$forwardSn}",
  1329. 'sjId' => $forward->sjId ?? 0,
  1330. 'shopId' => $forward->shopId ?? 0,
  1331. 'mainId' => $forward->mainId ?? 0,
  1332. 'payTime' => date('Y-m-d H:i:s'),
  1333. 'staffId' => $forward->shopAdminId ?? 0,
  1334. 'staffName' => $forward->shopAdminName ?? '',
  1335. 'side' => 0,
  1336. 'fromType' => dict::getDict('fromType', 'shop'),
  1337. 'remark' => '',
  1338. ], true);
  1339. if (!empty($ghs)) {
  1340. $customShopId = $custom->shopId ?? 0;
  1341. $customShop = ShopClass::getById($customShopId, true);
  1342. GhsBalanceChangeClass::add([
  1343. 'ghsId' => $ghs->id ?? 0,
  1344. 'relateId' => $forward->id ?? 0,
  1345. 'ptStyle' => dict::getDict('ptStyle', 'ghs'),
  1346. 'capitalType' => $capitalTypeGhs,
  1347. 'amount' => $returnAmount,
  1348. 'balance' => $newBalance,
  1349. 'io' => 1,
  1350. 'side' => 0,
  1351. 'onlinePay' => 1,
  1352. 'payWay' => dict::getDict('payWay', 'balancePay'),
  1353. 'fromType' => dict::getDict('fromType', 'shop'),
  1354. 'event' => "冲销返充余额,凭证号:{$forwardSn}",
  1355. 'sjId' => $customShop->sjId ?? ($custom->sjId ?? 0),
  1356. 'mainId' => $customShop->mainId ?? 0,
  1357. 'shopId' => $customShopId,
  1358. 'remark' => '',
  1359. ], true);
  1360. }
  1361. return $newBalance;
  1362. }
  1363. }