Credit.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Author: 芸众商城 www.yunzshop.com
  5. * Date: 2017/5/15
  6. * Time: 上午8:56
  7. */
  8. namespace app\common\services\credit;
  9. use app\common\events\finance\LoveChangeEvent;
  10. use app\common\exceptions\ShopException;
  11. use app\framework\Support\Facades\Log;
  12. use Illuminate\Support\Facades\DB;
  13. abstract class Credit
  14. {
  15. protected $data = [];
  16. protected $type = ConstService::TYPE_INCOME;
  17. protected $source;
  18. protected $change_value;
  19. protected $memberModel;
  20. //abstract function changeValue();
  21. abstract function getMemberModel();
  22. abstract function recordSave();
  23. abstract function updateMemberCredit();
  24. abstract function validatorData();
  25. //abstract function validatorOzy();
  26. /**
  27. * 打赏接口
  28. * @param array $data
  29. * @return string
  30. */
  31. public function giveReward(array $data)
  32. {
  33. $this->source = ConstService::KART_GIVE_REWARD;
  34. return $this->addition($data);
  35. }
  36. /**
  37. * 充值接口
  38. * @param array $data
  39. * @return string
  40. */
  41. public function recharge(array $data)
  42. {
  43. $this->source = ConstService::SOURCE_RECHARGE;
  44. return $this->addition($data);
  45. }
  46. /**
  47. * 后台扣除
  48. * @param array $data
  49. * @return string
  50. */
  51. public function rechargeMinus(array $data)
  52. {
  53. $this->source = ConstService::SOURCE_RECHARGE_MINUS;
  54. return $this->subtraction($data);
  55. }
  56. /**
  57. * 自定义 source 参数,消费接口
  58. * @param array $data
  59. * @return string
  60. */
  61. public function customConsume(array $data)
  62. {
  63. if ($data['source']) {
  64. $this->source = $data['source'];
  65. } else {
  66. $this->source = ConstService::SOURCE_CONSUME;
  67. }
  68. return $this->subtraction($data);
  69. }
  70. /**
  71. * 消费接口
  72. * @param array $data
  73. * @return string
  74. */
  75. public function consume(array $data)
  76. {
  77. $this->source = ConstService::SOURCE_CONSUME;
  78. return $this->subtraction($data);
  79. }
  80. /**
  81. * 转让接口
  82. * @param array $data
  83. * @return string
  84. */
  85. public function transfer(array $data)
  86. {
  87. $this->source = ConstService::SOURCE_TRANSFER;
  88. return $this->subtraction($data);
  89. }
  90. /**
  91. * 余额转化爱心值
  92. * @param array $data
  93. * @return bool|string
  94. */
  95. public function convert(array $data)
  96. {
  97. $this->source = ConstService::SOURCE_CONVERT;
  98. return $this->subtraction($data);
  99. }
  100. /**
  101. * 余额转化爱心值回滚
  102. * @param array $data
  103. * @return bool|string
  104. */
  105. public function convertCancel(array $data)
  106. {
  107. $this->source = ConstService::SOURCE_CONVERT_CANCEL;
  108. return $this->addition($data);
  109. }
  110. /**
  111. * 转让收入接口
  112. * @param array $data
  113. * @return string
  114. */
  115. public function recipient(array $data)
  116. {
  117. $this->source = ConstService::SOURCE_TRANSFER;
  118. return $this->addition($data);
  119. }
  120. /**
  121. * 抵扣接口
  122. * @param array $data
  123. * @return string
  124. */
  125. public function deduction(array $data)
  126. {
  127. $this->source = ConstService::SOURCE_DEDUCTION;
  128. return $this->subtraction($data);
  129. }
  130. /**
  131. * 奖励接口
  132. * @param array $data
  133. * @return string
  134. */
  135. public function award(array $data)
  136. {
  137. $this->source = ConstService::SOURCE_AWARD;
  138. if ($data['source']) {
  139. $this->source = $data['source'];
  140. }
  141. return $this->addition($data);
  142. }
  143. /**
  144. * 充值消费积分赠送爱心值
  145. * @param array $data
  146. * @return string
  147. */
  148. public function integralAward(array $data)
  149. {
  150. $this->source = ConstService::SOURCE_AWARD;
  151. return $this->addition($data);
  152. }
  153. /**
  154. * 提现接口
  155. * @param array $data
  156. * @return string
  157. */
  158. public function withdrawal(array $data)
  159. {
  160. $this->source = ConstService::SOURCE_WITHDRAWAL;
  161. return $this->subtraction($data);
  162. }
  163. /**
  164. * 提现至………(余额)………接口
  165. * @param array $data
  166. * @return string
  167. */
  168. public function income(array $data)
  169. {
  170. $this->source = ConstService::SOURCE_INCOME;
  171. return $this->addition($data);
  172. }
  173. /**
  174. * 抵扣取消回滚接口
  175. * @param array $data
  176. * @return string
  177. */
  178. public function cancelDeduction(array $data)
  179. {
  180. $this->source = ConstService::SOURCE_CANCEL_DEDUCTION;
  181. return $this->addition($data);
  182. }
  183. /**
  184. * 奖励取消回滚接口
  185. * @param array $data
  186. * @return string
  187. */
  188. public function cancelAward(array $data)
  189. {
  190. $this->source = ConstService::SOURCE_CANCEL_AWARD;
  191. return $this->subtraction($data);
  192. }
  193. /**
  194. * 消费取消回滚接口
  195. * @param array $data
  196. * @return string
  197. */
  198. public function cancelConsume(array $data)
  199. {
  200. \Log::debug("消费取消回滚接口", $data);
  201. $this->source = ConstService::SOURCE_CANCEL_CONSUME;
  202. return $this->addition($data);
  203. }
  204. /**
  205. * 抽奖获得余额
  206. * @param array $data
  207. * @return string
  208. */
  209. public function DrawGet(array $data)
  210. {
  211. $this->source = ConstService::SOURCE_DRAW_CHARGE;
  212. return $this->addition($data);
  213. }
  214. /**
  215. * 抽奖奖励余额
  216. * @param array $data
  217. * @return string
  218. */
  219. public function DrawReward(array $data)
  220. {
  221. $this->source = ConstService::SOURCE_DRAW_REWARD;
  222. return $this->addition($data);
  223. }
  224. /**
  225. * 新人奖奖励余额
  226. * @param array $data
  227. * @return string
  228. */
  229. public function NewMemberPrizeReward(array $data)
  230. {
  231. $this->source = ConstService::SOURCE_NEW_MEMBER_PRIZE;
  232. return $this->addition($data);
  233. }
  234. //第三方同步
  235. public function ThirdSynchronization(array $data)
  236. {
  237. $this->source = ConstService::SOURCE_THIRD_SYN;
  238. return $this->addition($data);
  239. }
  240. /**
  241. * 直播会员观看获得余额
  242. * @param array $data
  243. * @return string
  244. */
  245. public function RoomMemberActivity(array $data)
  246. {
  247. $this->source = ConstService::ROOM_MEMBER_ACTIVITY;
  248. return $this->addition($data);
  249. }
  250. /**
  251. * 直播会员观看获得余额
  252. * @param array $data
  253. * @return string
  254. */
  255. public function RoomActivity(array $data)
  256. {
  257. $this->source = ConstService::ROOM_ACTIVITY;
  258. return $this->addition($data);
  259. }
  260. /**
  261. * 直播会员观看获得余额
  262. * @param array $data
  263. * @return string
  264. */
  265. public function RoomAnchorActivity(array $data)
  266. {
  267. $this->source = ConstService::ROOM_ANCHOR_ACTIVITY;
  268. return $this->addition($data);
  269. }
  270. /**
  271. * 直播打赏支出
  272. * @param array $data
  273. * @return string
  274. */
  275. public function RoomRewardTransfer(array $data)
  276. {
  277. $this->source = ConstService::ROOM_REWARD_TRANSFER;
  278. return $this->subtraction($data);
  279. }
  280. /**
  281. * 直播打赏收入
  282. * @param array $data
  283. * @return string
  284. */
  285. public function RoomRewardRecipient(array $data)
  286. {
  287. $this->source = ConstService::ROOM_REWARD_RECIPIENT;
  288. return $this->addition($data);
  289. }
  290. /**
  291. * 层链充值
  292. * @param array $data
  293. * @return string
  294. */
  295. public function LayerChainRecharge(array $data)
  296. {
  297. $this->source = ConstService::LAYER_CHAIN_RECHARGE;
  298. return $this->addition($data);
  299. }
  300. /**
  301. * 拼团成功奖励
  302. * @param array $data
  303. * @return string
  304. */
  305. public function FightGroupsSuccessReward(array $data)
  306. {
  307. $this->source = ConstService::FIGHT_GROUPS_SUCCESS_REWARD;
  308. return $this->addition($data);
  309. }
  310. /**
  311. * 拼团抽奖奖励
  312. * @param array $data
  313. * @return string
  314. */
  315. public function FightGroupsLotterySuccessReward(array $data)
  316. {
  317. $this->source = $data['source'];
  318. return $this->addition($data);
  319. }
  320. /**
  321. * 拼团抽奖奖励余额
  322. * @param array $data
  323. * @return bool|string
  324. */
  325. public function FightGroupsLotteryComfortReward(array $data)
  326. {
  327. $this->source = $data['source'];
  328. return $this->addition($data);
  329. }
  330. /**
  331. * 加入付费圈子奖励
  332. * @param array $data
  333. * @return string
  334. */
  335. public function CircleAddReward(array $data)
  336. {
  337. $this->source = $data['source'];
  338. return $this->addition($data);
  339. }
  340. /**
  341. * 抢团成功奖励
  342. * @param array $data
  343. * @return string
  344. */
  345. public function SnatchRegimentSuccessReward(array $data)
  346. {
  347. $this->source = ConstService::SNATCH_REGIMENT_SUCCESS_AWARD;
  348. return $this->addition($data);
  349. }
  350. /**
  351. * 星拼乐成功奖励
  352. * @param array $data
  353. * @return string
  354. */
  355. public function StarSpellSuccessReward(array $data)
  356. {
  357. $this->source = ConstService::STAR_SPELL_SUCCESS_AWARD;
  358. return $this->addition($data);
  359. }
  360. /**
  361. * 抽奖奖励
  362. * @param array $data
  363. * @return string
  364. */
  365. public function LuckDrawReward(array $data)
  366. {
  367. $this->source = ConstService::LUCK_DRAW_AWARD;
  368. return $this->addition($data);
  369. }
  370. /**
  371. * 社群接龙奖励
  372. * @param array $data
  373. * @return string
  374. */
  375. public function CommunityRelayAward(array $data)
  376. {
  377. $this->source = ConstService::COMMUNITY_RELAY_AWARD;
  378. return $this->addition($data);
  379. }
  380. /**
  381. * 信用值中南呗转入
  382. * @param array $data
  383. * @return string
  384. */
  385. public function CreditZnbTransfer(array $data)
  386. {
  387. $this->source = ConstService::CREDIT_ZNB_TRANSFER;
  388. return $this->addition($data);
  389. }
  390. /**
  391. * 投放广告插件-获得红包
  392. * @param array $data
  393. * @return string
  394. */
  395. public function AdServingRedpackReward(array $data)
  396. {
  397. $this->source = ConstService::AD_SERVING_REDPACK_REWARD;
  398. return $this->addition($data);
  399. }
  400. /**
  401. * 投放广告插件-投放广告扣除金额
  402. * @param array $data
  403. * @return string
  404. */
  405. public function AdServingPutInAdvertisingDeduct(array $data)
  406. {
  407. $this->source = ConstService::AD_SERVING_PUT_IN_ADVERTISING_DEDUCT;
  408. return $this->subtraction($data);
  409. }
  410. /**
  411. * 投放广告插件-退款
  412. * @param array $data
  413. * @return string
  414. */
  415. public function AdServingRefund(array $data)
  416. {
  417. $this->source = ConstService::AD_SERVING_REFUND;
  418. return $this->addition($data);
  419. }
  420. public function CpsSubPlatformReward(array $data)
  421. {
  422. $this->source = ConstService::CPS_SUB_PLATFORM;
  423. return $this->addition($data);
  424. }
  425. /**
  426. * 珍惠拼 - 退团
  427. * @param array $data
  428. * @return string
  429. */
  430. public function ZhpQuitGroupRefund(array $data)
  431. {
  432. $this->source = ConstService::ZHP_QUIT_GROUP_REFUND;
  433. return $this->addition($data);
  434. }
  435. /**
  436. * 拼团成团奖-上级奖励
  437. * @param array $data
  438. * @return string
  439. */
  440. public function FightGroupsOperatorsParentReward(array $data)
  441. {
  442. $this->source = ConstService::FIGHT_GROUPS_OPERATORS_SETTLE_REWARD;
  443. return $this->addition($data);
  444. }
  445. /**
  446. * 爱心值转余额
  447. * @param array $data
  448. * @return string
  449. */
  450. public function LoveToBalance(array $data)
  451. {
  452. $this->source = ConstService::LOVE_TO_BALANCE;
  453. return $this->addition($data);
  454. }
  455. /**
  456. * 珍惠拼 - 易货
  457. * @param array $data
  458. * @return string
  459. */
  460. public function zhpBarterReward(array $data)
  461. {
  462. $this->source = ConstService::ZHP_BARTER;
  463. return $this->addition($data);
  464. }
  465. /**
  466. * 群拓客奖励-进群奖励
  467. * @param array $data
  468. * @return bool|string
  469. */
  470. public function groupChatActivity(array $data)
  471. {
  472. $this->source = ConstService::GROUP_CHAT_ACTIVITY;
  473. return $this->addition($data);
  474. }
  475. /* 企业微信好友裂变活动奖励
  476. * @param array $data
  477. * @return string
  478. */
  479. public function CustomerIncreaseAward(array $data)
  480. {
  481. $this->source = ConstService::CUSTOMER_INCREASE_REWARD;
  482. return $this->addition($data);
  483. }
  484. /**
  485. * 每日红包转入
  486. * @param array $data
  487. * @return string
  488. */
  489. public function RedPacketReward(array $data)
  490. {
  491. $this->source = ConstService::RED_PACKET_REWARD;
  492. return $this->addition($data);
  493. }
  494. /**
  495. * 珍惠拼-统一时间奖励
  496. * @param array $data
  497. * @return string
  498. */
  499. public function ZhpUnifyReward(array $data)
  500. {
  501. $this->source = ConstService::ZHP_UNIFY_REWARD;
  502. return $this->addition($data);
  503. }
  504. /**
  505. * ywm-拼团成功奖励
  506. * @param array $data
  507. * @return string
  508. */
  509. public function YwmFightGroupsSuccessReward(array $data)
  510. {
  511. $this->source = ConstService::YWM_FIGHT_GROUPS_SUCCESS_REWARD;
  512. return $this->addition($data);
  513. }
  514. /**
  515. * 直播-拼手气红包发放接口
  516. * @param array $data
  517. * @return string
  518. */
  519. public function roomRedPackSend(array $data)
  520. {
  521. $this->source = ConstService::ROOM_REDPACK_SEND;
  522. return $this->subtraction($data);
  523. }
  524. /**
  525. * 直播-拼手气红包领取接口
  526. * @param array $data
  527. * @return string
  528. */
  529. public function roomRedPackReceive(array $data)
  530. {
  531. $this->source = ConstService::ROOM_REDPACK_RECEIVE;
  532. return $this->addition($data);
  533. }
  534. /**
  535. * 直播-拼手气红包退还接口
  536. * @param array $data
  537. * @return string
  538. */
  539. public function roomRedPackRefund(array $data)
  540. {
  541. $this->source = ConstService::ROOM_REDPACK_REFUND;
  542. return $this->addition($data);
  543. }
  544. /*
  545. * 新客裂变奖励
  546. * @param array $data
  547. * @return string
  548. */
  549. public function newcomerFissionReward(array $data)
  550. {
  551. $this->source = ConstService::NEWCOMER_FISSION_REWARD;
  552. return $this->addition($data);
  553. }
  554. /*
  555. * 存货服务奖励
  556. * @param array $data
  557. * @return string
  558. */
  559. public function stockServiceReward(array $data)
  560. {
  561. $this->source = ConstService::STOCK_SERVICE_BACK;
  562. return $this->addition($data);
  563. }
  564. /**
  565. * 手签协议奖励
  566. * @param array $data
  567. * @return string
  568. */
  569. public function handSignProtocolReward(array $data)
  570. {
  571. $this->source = ConstService::HAND_SIGN_PROTOCOL;
  572. return $this->addition($data);
  573. }
  574. /**
  575. * 活动排行榜额度不足扣除
  576. * @param array $data
  577. * @return string
  578. */
  579. public function activityRankingQuotaDissatisfy(array $data)
  580. {
  581. $this->source = ConstService::ACTIVITY_RANKING_QUOTA_DISSATISFY;
  582. return $this->subtraction($data);
  583. }
  584. /**
  585. * 会员合并转入
  586. * @param array $data
  587. * @return string
  588. */
  589. public function memberMerge(array $data)
  590. {
  591. $this->source = ConstService::MEMBER_MERGE;
  592. return $this->addition($data);
  593. }
  594. //加法
  595. protected function addition($data)
  596. {
  597. if (!isset($data['change_value']) || $data['change_value'] < 0) {
  598. return '变动值必须是正数';
  599. }
  600. $this->data = $data;
  601. $this->type = ConstService::TYPE_INCOME;
  602. $this->change_value = $this->data['change_value'];
  603. \Log::debug("监听加法", $this->change_value);
  604. event(new LoveChangeEvent($data['member_id']));
  605. return $this->result();
  606. }
  607. //加法
  608. protected function ozyAddition($data)
  609. {
  610. if (!isset($data['change_value']) || $data['change_value'] < 0) {
  611. return '变动值必须是正数';
  612. }
  613. $this->data = $data;
  614. $this->type = ConstService::TYPE_INCOME;
  615. $this->change_value = $this->data['change_value'];
  616. \Log::debug("监听加法", $this->change_value);
  617. event(new LoveChangeEvent($data['member_id']));
  618. return $this->result();
  619. }
  620. //减法
  621. protected function subtraction($data)
  622. {
  623. if (!isset($data['change_value']) || $data['change_value'] < 0) {
  624. return '变动值必须是正数';
  625. }
  626. $this->data = $data;
  627. $this->type = ConstService::TYPE_EXPENDITURE;
  628. $this->change_value = -$this->data['change_value'];
  629. return $this->result();
  630. }
  631. protected function ozySubtraction($data)
  632. {
  633. if (!isset($data['change_value']) || $data['change_value'] < 0) {
  634. return '变动值必须是正数';
  635. }
  636. $this->data = $data;
  637. $this->type = ConstService::TYPE_EXPENDITURE;
  638. $this->change_value = -$this->data['change_value'];
  639. return $this->result();
  640. }
  641. //余额提现驳回
  642. public function rejected($data)
  643. {
  644. $this->source = ConstService::SOURCE_REJECTED;
  645. return $this->addition($data);
  646. }
  647. //批量充值正数
  648. public function excelRecharge(array $data)
  649. {
  650. $this->source = ConstService::SOURCE_EXCEL_RECHARGE;
  651. return $this->addition($data);
  652. }
  653. //批量充值负数
  654. public function excelRechargeSubtraction(array $data)
  655. {
  656. $this->source = ConstService::SOURCE_EXCEL_RECHARGE;
  657. return $this->subtraction($data);
  658. }
  659. // 个人红包发放
  660. public function redpackUserSend(array $data)
  661. {
  662. $this->source = ConstService::REDPACK_USER_SEND;
  663. return $this->subtraction($data);
  664. }
  665. /**
  666. * 企业微信好友分裂活动奖励
  667. * @param array $data
  668. * @return string
  669. */
  670. public function customerIncreaseReward(array $data)
  671. {
  672. $this->source = ConstService::CUSTOMER_INCREASE_REWARD;
  673. return $this->addition($data);
  674. }
  675. protected function result()
  676. {
  677. if (!(double)$this->data['change_value']) return true;
  678. DB::transaction(function () {
  679. $this->_result();
  680. });
  681. return true;
  682. }
  683. //todo 应该改为私有
  684. protected function _result()
  685. {
  686. $this->memberModel = $this->getMemberModel();
  687. if (!$this->memberModel) {
  688. throw new ShopException("未获取到会员数据");
  689. }
  690. $validator = $this->validatorData();
  691. if (!($validator === true)) {
  692. throw new ShopException("$validator");
  693. }
  694. $result = $this->recordSave();
  695. if (!$result) {
  696. throw new ShopException("数据写入错误:CREDIT_RECORD");
  697. }
  698. $result = $this->updateMemberCredit();
  699. if (!$result) {
  700. throw new ShopException("数据写入错误:CREDIT_UPDATE");
  701. }
  702. return true;
  703. }
  704. /**
  705. * 拓客活动余额奖励
  706. * @param array $data
  707. * @return string
  708. */
  709. public function activityRewardBalance(array $data)
  710. {
  711. $this->source = $data['source'];
  712. return $this->addition($data);
  713. }
  714. }