CustomClass.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. <?php
  2. namespace bizGhs\custom\classes;
  3. use biz\ghs\classes\GhsClass;
  4. use biz\sj\classes\MerchantClass;
  5. use bizGhs\custom\models\Custom;
  6. use bizGhs\ghs\classes\GhsBalanceChangeClass;
  7. use bizGhs\shop\classes\MainClass;
  8. use bizGhs\shop\classes\TotalDebtChangeClass;
  9. use bizGhs\ghs\classes\GhsBalanceClass;
  10. use bizGhs\ghs\classes\GhsRechargeClass;
  11. use bizGhs\shop\classes\ShopClass;
  12. use common\components\business;
  13. use common\components\dict;
  14. use common\components\imgUtil;
  15. use common\components\noticeUtil;
  16. use common\components\util;
  17. use common\components\orderSn;
  18. use bizHd\base\classes\BaseClass;
  19. class CustomClass extends BaseClass
  20. {
  21. public static $baseFile = '\bizGhs\custom\models\Custom';
  22. const IS_DEBT_NO = 0;
  23. const IS_DEBT_YES = 1;
  24. const NOT_BLACK = 1;
  25. const IS_BLACK = 2;
  26. const LEVEL_SK = 0; //散客
  27. const LEVEL_PT = 1; //花店
  28. const LEVEL_HJ = 2; //同行
  29. const LEVEL_ZS = 3; //金店
  30. public static $levelMap = [
  31. self::LEVEL_SK => '散客',
  32. self::LEVEL_PT => '花店',
  33. self::LEVEL_HJ => '同行',
  34. self::LEVEL_ZS => '金店',
  35. ];
  36. public static $nickNameMap = [
  37. self::LEVEL_SK => '零售',
  38. self::LEVEL_PT => '批发',
  39. self::LEVEL_HJ => '同行',
  40. self::LEVEL_ZS => '金店',
  41. ];
  42. public static $levelPriceKeyMap = [
  43. self::LEVEL_SK => 'skPrice',
  44. self::LEVEL_PT => 'price',
  45. self::LEVEL_HJ => 'hjPrice',
  46. self::LEVEL_ZS => 'zsPrice',
  47. ];
  48. public static $levelAddPriceKeyMap = [
  49. self::LEVEL_SK => 'skMore',
  50. self::LEVEL_PT => 'addPrice',
  51. self::LEVEL_HJ => 'hjAddPrice',
  52. self::LEVEL_ZS => 'zsAddPrice',
  53. ];
  54. //消费余额 ssh 20240311
  55. public static function clearConsumeBalance($amount, $custom, $ghs, $shop, $staff, $clear)
  56. {
  57. $customId = $custom->id ?? 0;
  58. $ghsId = $ghs->id ?? 0;
  59. $relateId = $clear->id ?? 0;
  60. $staffId = $staff->id ?? 0;
  61. $staffName = $staff->name ?? '';
  62. $clearSn = $clear->orderSn;
  63. $mainId = $shop->mainId ?? 0;
  64. $shopId = $shop->id ?? 0;
  65. $sjId = $shop->sjId ?? 0;
  66. $newGhsBalance = bcsub($ghs->balance, $amount, 2);
  67. $ghs->balance = $newGhsBalance;
  68. $ghs->save();
  69. $newCustomBalance = bcsub($custom->balance, $amount, 2);
  70. $custom->balance = $newCustomBalance;
  71. $custom->save();
  72. if ($newGhsBalance < 0) {
  73. util::fail('余额有问题哦..');
  74. }
  75. if (floatval($newGhsBalance) != floatval($newCustomBalance)) {
  76. util::fail('余额有问题...');
  77. }
  78. $capitalType = dict::getDict('capitalType', 'ghsHelpCustomUseBalanceClear', 'id');
  79. $fromType = dict::getDict('fromType', 'shop');
  80. $cbData = [
  81. 'customId' => $customId,
  82. 'relateId' => $relateId,
  83. 'onlinePay' => 1,
  84. 'ptStyle' => 2,
  85. 'capitalType' => $capitalType,
  86. 'amount' => $amount,
  87. 'balance' => $newCustomBalance,
  88. 'staffId' => $staffId,
  89. 'staffName' => $staffName,
  90. 'io' => 0,
  91. 'side' => 0,
  92. 'payWay' => 0,
  93. 'fromType' => $fromType,
  94. 'event' => '结账 ' . $clearSn,
  95. 'mainId' => $mainId,
  96. 'shopId' => $shopId,
  97. 'sjId' => $sjId,
  98. 'remark' => '',
  99. ];
  100. $cbc = CustomBalanceChangeClass::add($cbData, true);
  101. $customShopId = $custom->shopId ?? 0;
  102. $customShop = ShopClass::getById($customShopId, true);
  103. if (empty($customShop)) {
  104. util::fail('没有找到客户门店呢..');
  105. }
  106. $customShopSjId = $customShop->sjId ?? 0;
  107. $customShopMainId = $customShop->mainId ?? 0;
  108. $capitalType = dict::getDict('capitalType', 'customAskGhsUseBalanceClear', 'id');
  109. $gbData = [
  110. 'ghsId' => $ghsId,
  111. 'relateId' => $relateId,
  112. 'ptStyle' => 2,
  113. 'capitalType' => $capitalType,
  114. 'amount' => $amount,
  115. 'balance' => $newGhsBalance,
  116. 'io' => 0,
  117. 'side' => 0,
  118. 'onlinePay' => 1,
  119. 'payWay' => 0,
  120. 'fromType' => $fromType,
  121. 'event' => '结账 ' . $clearSn,
  122. 'sjId' => $customShopSjId,
  123. 'mainId' => $customShopMainId,
  124. 'shopId' => $customShopId,
  125. 'remark' => '',
  126. ];
  127. $gbc = GhsBalanceChangeClass::add($gbData, true);
  128. $clear->customBalanceChangeId = $cbc->id ?? 0;
  129. $clear->ghsBalanceChangeId = $gbc->id ?? 0;
  130. $clear->save();
  131. }
  132. //充值金额,有多个地方要同步修改,请搜索关键词custom_ghs_recharge ssh 20240310
  133. public static function rechargeBalance($custom, $amount, $shop, $staff, $payWay, $params = [])
  134. {
  135. $ghsId = $custom->ghsId ?? 0;
  136. $ghsInfo = GhsClass::getLockById($ghsId);
  137. if (empty($ghsInfo)) {
  138. util::fail('没有找到供货商');
  139. }
  140. $ghsShopId = $ghsInfo->shopId ?? 0;
  141. $ghsName = $ghsInfo->name ?? '';
  142. $customId = $custom->id ?? 0;
  143. $customShopId = $custom->shopId ?? 0;
  144. $customName = $custom->name ?? '';
  145. $customShop = ShopClass::getById($customShopId, true);
  146. if (empty($customShop)) {
  147. util::fail('没有找到客户门店');
  148. }
  149. $payTime = date("Y-m-d H:i:s");
  150. $customShopSjId = $customShop->sjId ?? 0;
  151. $customShopMainId = $customShop->mainId ?? 0;
  152. $payMap = dict::getDict('payWayName');
  153. $payName = $payMap[$payWay] ?? '';
  154. $rechargeEvent = $payName . '充值';
  155. $custom->balance = bcadd($custom->balance, $amount, 2);
  156. $custom->save();
  157. $orderSn = orderSn::getGhsCustomRechargeSn();
  158. $shopId = $shop->id ?? 0;
  159. $sjId = $shop->sjId ?? 0;
  160. $mainId = $shop->mainId ?? 0;
  161. $staffId = $staff->id ?? 0;
  162. $staffName = $staff->name ?? '';
  163. $remark = $params['remark'] ?? '';
  164. $cData = [
  165. 'orderSn' => $orderSn,
  166. 'onlinePay' => 1,
  167. 'payWay' => $payWay,
  168. 'shopId' => $shopId,
  169. 'mainId' => $mainId,
  170. 'amount' => $amount,
  171. 'balance' => $custom->balance,
  172. 'side' => 0,
  173. 'staffId' => $staffId,
  174. 'staffName' => $staffName,
  175. 'payStatus' => 1,
  176. 'status' => 1,
  177. 'remark' => '',
  178. 'ghsId' => $ghsId,
  179. 'ghsShopId' => $ghsShopId,
  180. 'ghsName' => $ghsName,
  181. 'customId' => $customId,
  182. 'customShopId' => $customShopId,
  183. 'customName' => $customName,
  184. 'remark' => $remark,
  185. 'payTime' => $payTime,
  186. ];
  187. $cRecharge = CustomRechargeClass::add($cData, true);
  188. $cRechargeId = $cRecharge->id ?? 0;
  189. $capitalType = dict::getDict('capitalType', 'ghsHelpCustomRecharge', 'id');
  190. $fromType = dict::getDict('fromType', 'shop');
  191. $cbData = [
  192. 'customId' => $customId,
  193. 'relateId' => $cRechargeId,
  194. 'onlinePay' => 1,
  195. 'ptStyle' => 2,
  196. 'capitalType' => $capitalType,
  197. 'amount' => $amount,
  198. 'balance' => $custom->balance,
  199. 'staffId' => $staffId,
  200. 'staffName' => $staffName,
  201. 'io' => 1,
  202. 'side' => 0,
  203. 'payWay' => $payWay,
  204. 'fromType' => $fromType,
  205. 'event' => $rechargeEvent,
  206. 'mainId' => $mainId,
  207. 'shopId' => $shopId,
  208. 'sjId' => $sjId,
  209. 'remark' => $remark,
  210. ];
  211. CustomBalanceChangeClass::add($cbData, true);
  212. $ghsInfo->balance = bcadd($ghsInfo->balance, $amount, 2);
  213. $ghsInfo->save();
  214. $orderSn = orderSn::getGhsRechargeSn();
  215. $customMainId = $custom->mainId ?? 0;
  216. $gData = [
  217. 'orderSn' => $orderSn,
  218. 'onlinePay' => 1,
  219. 'payWay' => $payWay,
  220. 'shopId' => $customShopId,
  221. 'mainId' => $customMainId,
  222. 'amount' => $amount,
  223. 'balance' => $ghsInfo->balance,
  224. 'side' => 0,
  225. 'staffId' => 0,
  226. 'staffName' => '',
  227. 'payStatus' => 1,
  228. 'status' => 1,
  229. 'remark' => '',
  230. 'ghsId' => $ghsId,
  231. 'ghsShopId' => $ghsShopId,
  232. 'ghsName' => $ghsName,
  233. 'customId' => $customId,
  234. 'customShopId' => $customShopId,
  235. 'customName' => $customName,
  236. 'remark' => $remark,
  237. 'payTime' => $payTime,
  238. ];
  239. $gRecharge = GhsRechargeClass::add($gData, true);
  240. $gRechargeId = $gRecharge->id ?? 0;
  241. $capitalType = dict::getDict('capitalType', 'customAskGhsRecharge', 'id');
  242. $gbData = [
  243. 'ghsId' => $ghsId,
  244. 'relateId' => $gRechargeId,
  245. 'ptStyle' => 2,
  246. 'capitalType' => $capitalType,
  247. 'amount' => $amount,
  248. 'balance' => $ghsInfo->balance,
  249. 'io' => 1,
  250. 'side' => 0,
  251. 'onlinePay' => 1,
  252. 'payWay' => $payWay,
  253. 'fromType' => $fromType,
  254. 'event' => $rechargeEvent,
  255. 'sjId' => $customShopSjId,
  256. 'mainId' => $customShopMainId,
  257. 'shopId' => $customShopId,
  258. 'remark' => $remark,
  259. ];
  260. GhsBalanceChangeClass::add($gbData, true);
  261. return ['custom' => $custom, 'ghs' => $ghsInfo, 'customRecharge' => $cRecharge, 'ghsRecharge' => $gRecharge];
  262. }
  263. public static function createSeatSn($mainId)
  264. {
  265. $max = Custom::find(['mainId' => $mainId])->max('seatSn');
  266. $new = bcadd($max, 1);
  267. return $new;
  268. }
  269. //建立客户和供货商关系
  270. public static function build($ghsShopId, $hdShopId, $changeName = '')
  271. {
  272. return GhsClass::build($ghsShopId, $hdShopId, 2, $changeName);
  273. }
  274. //添加客户 ssh 2021.2.24
  275. public static function addCustom($data)
  276. {
  277. return self::add($data);
  278. }
  279. //获取客户信息 ssh 2021.2.4
  280. public static function getCustom($id)
  281. {
  282. $info = self::getById($id);
  283. if (empty($info)) {
  284. return $info;
  285. }
  286. $respond = self::groupBaseInfo([$info]);
  287. return current($respond);
  288. }
  289. public static function getCustomByIds($ids)
  290. {
  291. $list = self::getByIds($ids, null, 'id');
  292. return self::groupBaseInfo($list);
  293. }
  294. //整合头像等信息 ssh 2021.1.8
  295. public static function groupBaseInfo($list)
  296. {
  297. if (empty($list)) {
  298. return $list;
  299. }
  300. //获取客户信息
  301. $customSjIdList = array_unique(array_filter(array_column($list, 'sjId')));
  302. $sjInfo = MerchantClass::getByIds($customSjIdList, null, 'id');
  303. $levelMap = self::$levelMap;
  304. foreach ($list as $key => $val) {
  305. $customSjId = $val['sjId'];
  306. $currentInfo = isset($sjInfo[$customSjId]) ? $sjInfo[$customSjId] : [];
  307. $currentInfo = business::formatMerchantLogo($currentInfo);
  308. $smallAvatar = !empty($currentInfo['smallLogoUrl']) ? $currentInfo['smallLogoUrl'] : imgUtil::getPrefix() . '/hhb_small.png';
  309. $avatar = !empty($currentInfo['logoUrl']) ? $currentInfo['logoUrl'] : imgUtil::getPrefix() . '/hhb_small.png';
  310. $list[$key]['smallAvatar'] = $smallAvatar;
  311. $list[$key]['shortSmallAvatar'] = $currentInfo['shortSmallLogoUrl'];
  312. $list[$key]['avatar'] = $avatar;
  313. $list[$key]['shortAvatar'] = $currentInfo['shortLogoUrl'];
  314. $list[$key]['sn'] = $val['id'];
  315. $level = $val['level'] ?? 1;
  316. $levelName = $levelMap[$level] ?? '';
  317. $list[$key]['levelName'] = $levelName;
  318. $debtAmount = $val['debtAmount'] ?? 0;
  319. $balance = $val['balance'] ?? 0;
  320. $remainDebtAmount = bcsub($debtAmount, $balance, 2);
  321. $list[$key]['remainDebtAmount'] = $remainDebtAmount;
  322. $recentExpend = $val['recentExpend'] ?? '';
  323. $recentExpendTime = strtotime($recentExpend);
  324. $seven = bcmul(86400, 7);
  325. $addTime = bcadd($recentExpendTime, $seven);
  326. $list[$key]['overSevenUnExpend'] = 0;
  327. if ($addTime < time()) {
  328. //超过7天未下单
  329. $list[$key]['overSevenUnExpend'] = 1;
  330. }
  331. //超时未下单
  332. $list[$key]['overTimeUnExpend'] = 0;
  333. if ($recentExpend == '0000-00-00 00:00:00') {
  334. $list[$key]['overTimeUnExpend'] = 10000;
  335. } else {
  336. $recentExpendTime = strtotime($recentExpend);
  337. $seven = bcmul(86400, 7);
  338. $sevenTime = bcadd($recentExpendTime, $seven);
  339. if ($sevenTime < time()) {
  340. $list[$key]['overTimeUnExpend'] = 7;
  341. }
  342. $month = bcmul(86400, 30);
  343. $monthTime = bcadd($recentExpendTime, $month);
  344. if ($monthTime < time()) {
  345. $list[$key]['overTimeUnExpend'] = 30;
  346. }
  347. $halfYear = bcmul(86400, 180);
  348. $halfYearTime = bcadd($recentExpendTime, $halfYear);
  349. if ($halfYearTime < time()) {
  350. $list[$key]['overTimeUnExpend'] = 180;
  351. }
  352. $year = bcmul(86400, 365);
  353. $yearTime = bcmul($recentExpendTime, $year);
  354. if ($yearTime < time()) {
  355. $list[$key]['overTimeUnExpend'] = 365;
  356. }
  357. }
  358. }
  359. return $list;
  360. }
  361. //欠款权限开关 ssh 2021.1.8
  362. public static function debt($custom, $debt)
  363. {
  364. $id = isset($custom['id']) ? $custom['id'] : 0;
  365. self::updateById($id, ['debt' => $debt]);
  366. return true;
  367. }
  368. //采购查看权限的黑白名单设置 shizhongqi 2021.08.08
  369. public static function black($custom, $black)
  370. {
  371. $id = isset($custom['id']) ? $custom['id'] : 0;
  372. self::updateById($id, ['black' => $black]);
  373. return true;
  374. }
  375. //权限判断 ssh 2021.1.8
  376. public static function valid($custom, $shopId)
  377. {
  378. if (empty($custom)) {
  379. util::fail('没有找到客户');
  380. }
  381. if ($custom['ownShopId'] != $shopId) {
  382. util::fail('您无法操作此客户');
  383. }
  384. }
  385. //客户采购欠款金额增加 ssh 20220306
  386. public static function cgDebtAmountAdd($custom, $order, $bookOrder = false)
  387. {
  388. $amount = $order->remainDebtPrice ?? 0;
  389. $custom->isDebt = CustomClass::IS_DEBT_YES;
  390. $debtLimit = $custom->debtLimit ?? 0;
  391. if ($bookOrder == false) {
  392. if (isset($order->shopAdminId) && $order->shopAdminId == 0) {
  393. //客户自己下单要受额度限制
  394. if ($custom->debtAmount > $debtLimit) {
  395. util::fail("已欠款{$custom->debtAmount},请先结账哦");
  396. }
  397. }
  398. }
  399. $balance = bcadd($custom->debtAmount, $amount, 2);
  400. $mustNotice = false;
  401. if (getenv('YII_ENV') == 'production') {
  402. //王品牛排 黄先生
  403. if ($custom->id == 11726) {
  404. $mustNotice = true;
  405. }
  406. } else {
  407. if ($custom->id == 577) {
  408. $mustNotice = true;
  409. }
  410. }
  411. if (getenv('YII_ENV', 'local') == 'production') {
  412. if ($mustNotice) {
  413. noticeUtil::push("【开单动作 | 客户】变化前欠款:{$custom->debtAmount} 变化金额:{$amount} 变化后欠款:{$balance}", '15280215347');
  414. }
  415. }
  416. $custom->debtAmount = $balance;
  417. $custom->save();
  418. $relateId = $order->id ?? 0;
  419. $customId = $custom->id ?? 0;
  420. $orderSn = $order->orderSn ?? '';
  421. $capitalType = dict::getDict('capitalType', 'xhGhsOrder', 'id');
  422. $event = '购买花材,单号:' . $orderSn;
  423. if ($bookOrder) {
  424. $event = '预订单多退少补,单号:' . $orderSn;
  425. }
  426. $change = [
  427. 'relateId' => $relateId,
  428. 'customId' => $customId,
  429. 'ptStyle' => dict::getDict('ptStyle', 'ghs'),
  430. 'capitalType' => $capitalType,
  431. 'amount' => $amount,
  432. 'balance' => $balance,
  433. 'io' => 1,
  434. 'payWay' => $order->payWay,
  435. 'event' => $event,
  436. 'sjId' => $order->sjId,
  437. 'shopId' => $order->id,
  438. 'mainId' => $order->mainId,
  439. ];
  440. CustomDebtChangeClass::addChange($change);
  441. $mainId = $order->mainId ?? 0;
  442. $main = MainClass::getLockById($mainId);
  443. if (empty($main)) {
  444. util::fail('没有main信息');
  445. }
  446. $debt = $main->debt ?? 0;
  447. $remain = bcadd($debt, $amount, 2);
  448. if (getenv('YII_ENV', 'local') == 'production') {
  449. if ($mustNotice) {
  450. noticeUtil::push("【开单动作 | 总欠款】变化前欠款:{$debt} 变化金额:{$amount} 变化后欠款:{$remain}", '15280215347');
  451. }
  452. }
  453. $main->debt = $remain;
  454. $main->save();
  455. $event = $custom->name . ' 购买花材,单号:' . $orderSn;
  456. $change['balance'] = $remain;
  457. $change['event'] = $event;
  458. TotalDebtChangeClass::addChange($change);
  459. }
  460. //客户结账欠款金额减少 ssh 20220306
  461. public static function clearDebtAmountReduce($custom, $ghs, $amount, $clear)
  462. {
  463. $debtAmount = $custom->debtAmount ?? 0.00;
  464. $remain = bcsub($debtAmount, $amount, 2);
  465. if ($remain < 0) {
  466. noticeUtil::push("客户欠款总金额:{$custom->debtAmount} 本次结账金额:{$amount} 客户ID:{$custom->id} 【里外金额有问题】", '15280215347');
  467. util::fail('收款失败,结账后欠款金额会出现负数');
  468. }
  469. $custom->isDebt = $remain <= 0 ? 0 : 1;
  470. $custom->debtAmount = $remain;
  471. $custom->save();
  472. $relateId = $clear->id ?? 0;
  473. $customId = $custom->id ?? 0;
  474. $capitalType = dict::getDict('capitalType', 'ghsXsClear', 'id');
  475. $orderSn = $clear->orderSn ?? '';
  476. $change = [
  477. 'relateId' => $relateId,
  478. 'customId' => $customId,
  479. 'ptStyle' => dict::getDict('ptStyle', 'ghs'),
  480. 'capitalType' => $capitalType,
  481. 'amount' => $amount,
  482. 'balance' => $remain,
  483. 'io' => 0,
  484. 'payWay' => 0,
  485. 'event' => "结账,单号:{$orderSn}",
  486. 'sjId' => $ghs->sjId,
  487. 'shopId' => $ghs->id,
  488. 'mainId' => $ghs->mainId,
  489. ];
  490. CustomDebtChangeClass::addChange($change);
  491. $mainId = $ghs->mainId ?? 0;
  492. $main = MainClass::getLockById($mainId);
  493. if (empty($main)) {
  494. util::fail('没有main信息');
  495. }
  496. $debt = $main->debt ?? 0;
  497. $remain = bcsub($debt, $amount, 2);
  498. $main->debt = $remain;
  499. $main->save();
  500. $event = $custom->name . " 结账,单号:{$orderSn}";
  501. $change['balance'] = $remain;
  502. $change['event'] = $event;
  503. TotalDebtChangeClass::addChange($change);
  504. }
  505. //客户退款欠款金额减少 ssh 20220306
  506. public static function refundDebtAmountReduce($custom, $refund, $order)
  507. {
  508. $refundPrice = $refund->refundPrice ?? 0;
  509. $balance = bcsub($custom->debtAmount, $refundPrice, 2);
  510. $custom->debtAmount = $balance;
  511. $custom->save();
  512. $relateId = $refund->id ?? 0;
  513. $customId = $custom->id ?? 0;
  514. $saleOrderSn = $order->orderSn ?? '';
  515. $capitalType = dict::getDict('capitalType', 'saleRefund', 'id');
  516. $change = [
  517. 'relateId' => $relateId,
  518. 'customId' => $customId,
  519. 'ptStyle' => dict::getDict('ptStyle', 'ghs'),
  520. 'capitalType' => $capitalType,
  521. 'amount' => $refundPrice,
  522. 'balance' => $balance,
  523. 'io' => 0,
  524. 'payWay' => 0,
  525. 'event' => "订单号:{$saleOrderSn} 退款",
  526. 'sjId' => $refund->sjId,
  527. 'shopId' => $refund->id,
  528. 'mainId' => $order->mainId,
  529. ];
  530. CustomDebtChangeClass::addChange($change);
  531. $mainId = $order->mainId ?? 0;
  532. $main = MainClass::getLockById($mainId);
  533. if (empty($main)) {
  534. util::fail('没有main信息');
  535. }
  536. $debt = $main->debt ?? 0;
  537. $remain = bcsub($debt, $refundPrice, 2);
  538. $main->debt = $remain;
  539. $main->save();
  540. $event = $custom->name . " 订单号:{$saleOrderSn} 退款";
  541. $change['balance'] = $remain;
  542. $change['event'] = $event;
  543. TotalDebtChangeClass::addChange($change);
  544. }
  545. public static function exportCustom($where, $sort)
  546. {
  547. $list = self::getAllByCondition($where, $sort, '*', null);
  548. if (empty($list)) {
  549. util::fail('没有找到客户');
  550. }
  551. $list = self::groupBaseInfo($list);
  552. print_r($list);die;
  553. }
  554. }