BalanceService.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Author: 芸众商城 www.yunzshop.com
  5. * Date: 2017/4/13
  6. * Time: 下午7:01
  7. */
  8. namespace app\frontend\modules\finance\services;
  9. use app\backend\modules\member\models\Member;
  10. use app\common\exceptions\AppException;
  11. use app\common\models\member\ChildrenOfMember;
  12. use app\common\models\member\ParentOfMember;
  13. use app\common\services\credit\ConstService;
  14. use app\common\services\finance\BalanceChange;
  15. use app\common\facades\Setting;
  16. use app\frontend\modules\finance\models\Balance as BalanceCommon;
  17. use app\frontend\modules\finance\models\BalanceRecharge;
  18. class BalanceService
  19. {
  20. private $_recharge_set;
  21. private $_withdraw_set;
  22. public function __construct()
  23. {
  24. $this->_recharge_set = Setting::get('finance.balance');
  25. $this->_withdraw_set = Setting::get('withdraw.balance');
  26. }
  27. /**
  28. * 余额首页数据
  29. * @return array
  30. */
  31. public function getIndexData()
  32. {
  33. $this->setButtonArray($index_data);
  34. $this->setRechargeActivity($index_data);
  35. $this->setOther($index_data);
  36. $index_data['balance_log'] = BalanceCommon::getThreeData();
  37. $index_data['balance'] = Member::where('uid', \YunShop::app()->getMemberId())->value('credit2');
  38. return $index_data;
  39. }
  40. /**
  41. * 余额首页的按钮
  42. * @param $index_data
  43. * @return void
  44. */
  45. private function setButtonArray(&$index_data)
  46. {
  47. $index_data['balance_button'] = [];
  48. $this->getRechargeData($index_data);
  49. $this->getTransferData($index_data);
  50. $this->getWithdrawData($index_data);
  51. }
  52. /**
  53. * 充值按钮
  54. * @return void
  55. */
  56. private function getRechargeData(&$index_data): void
  57. {
  58. if ($this->_recharge_set['recharge']) {
  59. $index_data['balance_button'][] = [
  60. 'title' => '充值',
  61. 'url' => 'Balance_recharge'
  62. ];
  63. }
  64. }
  65. /**
  66. * 转账按钮
  67. * @return void
  68. */
  69. private function getTransferData(&$index_data): void
  70. {
  71. if ($this->_recharge_set['transfer']) {
  72. $index_data['balance_button'][] = [
  73. 'title' => '转账',
  74. 'url' => 'balance_transfer'
  75. ];
  76. }
  77. }
  78. /**
  79. * 提现按钮
  80. * @return void
  81. */
  82. private function getWithdrawData(&$index_data): void
  83. {
  84. $name = Setting::get('shop.lang.zh_cn.income.name_of_withdrawal');
  85. if (Setting::get('withdraw.balance.status')) {
  86. $index_data['balance_button'][] = [
  87. 'title' => empty($name) ? '提现' : $name,
  88. 'url' => 'balance_withdrawals'
  89. ];
  90. }
  91. }
  92. /**
  93. * 其他功能
  94. * @param $index_data
  95. * @return void
  96. */
  97. private function setOther(&$index_data): void
  98. {
  99. $index_data["other"] = [];
  100. //转化爱心值
  101. $this->getLove($index_data);
  102. if(empty($index_data['other'])){
  103. $index_data['other']=false;
  104. }
  105. }
  106. private function getLove(&$index_data)
  107. {
  108. //转化爱心值
  109. if ($this->_recharge_set['love_swich']) {
  110. $index_data["other"]["love"] = [
  111. 'title' => LOVE_NAME,
  112. 'img' => 'https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/images/balance/balanceLove@2x.png'
  113. ];
  114. }
  115. }
  116. /**
  117. * 活动数据
  118. * @return void
  119. */
  120. private function setRechargeActivity(&$index_data): void
  121. {
  122. $start = $this->_recharge_set['recharge_activity_start'];
  123. $end = $this->_recharge_set['recharge_activity_end'];
  124. $time_bool = (time() >= $start) && (time() <= $end);
  125. $index_data['recharge_activity'] = [];
  126. //开启活动 && 活动时间内 && 开启了充值 && 有活动内容
  127. if ($this->_recharge_set['recharge_activity'] && $time_bool && $this->_recharge_set['recharge'] && $this->_recharge_set['sale']) {
  128. $index_data['recharge_activity'] = [
  129. 'activity' => $this->_recharge_set['sale'],//活动说明,
  130. 'type' => $this->_recharge_set['proportion_status']//充值返回类型(0固定数值/1比例)
  131. ];
  132. }
  133. }
  134. //余额设置接口
  135. public function getBalanceSet()
  136. {
  137. return array(
  138. 'recharge' => $this->_recharge_set['recharge'] ? 1 : 0,
  139. 'transfer' => $this->_recharge_set['transfer'] ? 1 : 0,
  140. 'withdraw' => $this->_withdraw_set['status'] ? 1 : 0,
  141. 'withdrawToWechat' => $this->withdrawWechat(),
  142. 'withdrawToAlipay' => $this->withdrawAlipay(),
  143. 'withdrawToManual' => $this->withdrawManual(),
  144. 'withdrawEup' => $this->withdrawEup()
  145. );
  146. }
  147. //余额充值设置
  148. public function rechargeSet()
  149. {
  150. return $this->_recharge_set['recharge'] ? true : false;
  151. }
  152. //余额充值优惠
  153. public function rechargeSale()
  154. {
  155. return $this->rechargeSet() ? $this->_recharge_set['sale'] : [];
  156. }
  157. //0赠送固定金额,1赠送充值比例
  158. public function proportionStatus()
  159. {
  160. return isset($this->_recharge_set['proportion_status']) ? $this->_recharge_set['proportion_status'] : '0';
  161. }
  162. //余额转让设置
  163. public function transferSet()
  164. {
  165. return $this->_recharge_set['transfer'] ? true : false;
  166. }
  167. //余额转让设置
  168. public function teamTransferSet()
  169. {
  170. return $this->_recharge_set['team_transfer'] ? true : false;
  171. }
  172. //余额转化爱心值
  173. public function convertSet()
  174. {
  175. return $this->_recharge_set['love_swich'] ? true : false;
  176. }
  177. // 余额转化爱心值,为0或为空 按100计算
  178. public function convertRate()
  179. {
  180. return $this->_recharge_set['love_rate'] ?: 100;
  181. }
  182. //余额提现设置
  183. public function withdrawSet()
  184. {
  185. return $this->_withdraw_set['status'] ? true : false;
  186. }
  187. //余额提现限额设置
  188. public function withdrawAstrict()
  189. {
  190. return $this->_withdraw_set['withdrawmoney'] ?: '0';
  191. }
  192. //余额提现倍数限制
  193. public function withdrawMultiple()
  194. {
  195. return $this->_withdraw_set['withdraw_multiple'];
  196. }
  197. //余额提现手续费
  198. public function withdrawPoundage()
  199. {
  200. return $this->_withdraw_set['poundage'] ?: '0';
  201. }
  202. //余额提现到微信
  203. public function withdrawWechat()
  204. {
  205. return $this->_withdraw_set['wechat'] ? true : false;
  206. }
  207. //余额提现到微信限制
  208. public function withdrawWechatLimit()
  209. {
  210. $wechat_min = $this->_withdraw_set['wechat_min'];
  211. $wechat_max = $this->_withdraw_set['wechat_max'];
  212. $wechat_frequency = $this->_withdraw_set['wechat_frequency'];
  213. $data = [
  214. 'wechat_min' => $wechat_min,
  215. 'wechat_max' => $wechat_max,
  216. 'wechat_frequency' => $wechat_frequency,
  217. ];
  218. return $data;
  219. }
  220. //余额提现到支付寶限制
  221. public function withdrawAlipayLimit()
  222. {
  223. $alipay_min = $this->_withdraw_set['alipay_min'];
  224. $alipay_max = $this->_withdraw_set['alipay_max'];
  225. $alipay_frequency = $this->_withdraw_set['alipay_frequency'];
  226. $data = [
  227. 'alipay_min' => $alipay_min,
  228. 'alipay_max' => $alipay_max,
  229. 'alipay_frequency' => $alipay_frequency,
  230. ];
  231. return $data;
  232. }
  233. //余额提现到好灵工-支付宝限制
  234. public function withdrawWorkerWithdrawAlipayLimit()
  235. {
  236. $data = [
  237. 'worker_withdraw_alipay_min' => $this->_withdraw_set['worker_withdraw_alipay_min'],
  238. 'worker_withdraw_alipay_max' => $this->_withdraw_set['worker_withdraw_alipay_max'],
  239. 'worker_withdraw_alipay_frequency' => $this->_withdraw_set['worker_withdraw_alipay_frequency'],
  240. ];
  241. return $data;
  242. }
  243. //余额提现到好灵工-微信限制
  244. public function withdrawWorkerWithdrawWechatLimit()
  245. {
  246. $data = [
  247. 'worker_withdraw_wechat_min' => $this->_withdraw_set['worker_withdraw_wechat_min'],
  248. 'worker_withdraw_wechat_max' => $this->_withdraw_set['worker_withdraw_wechat_max'],
  249. 'worker_withdraw_wechat_frequency' => $this->_withdraw_set['worker_withdraw_wechat_frequency'],
  250. ];
  251. return $data;
  252. }
  253. //余额提现到好灵工-银行卡限制
  254. public function withdrawWorkerWithdrawBankLimit()
  255. {
  256. $data = [
  257. 'worker_withdraw_bank_min' => $this->_withdraw_set['worker_withdraw_bank_min'],
  258. 'worker_withdraw_bank_max' => $this->_withdraw_set['worker_withdraw_bank_max'],
  259. 'worker_withdraw_bank_frequency' => $this->_withdraw_set['worker_withdraw_bank_frequency'],
  260. ];
  261. return $data;
  262. }
  263. //余额提现到智E+-银行卡限制
  264. public function withdrawEplusWithdrawBankLimit()
  265. {
  266. $data = [
  267. 'eplus_withdraw_bank_min' => $this->_withdraw_set['eplus_withdraw_bank_min'],
  268. 'eplus_withdraw_bank_max' => $this->_withdraw_set['eplus_withdraw_bank_max'],
  269. 'eplus_withdraw_bank_frequency' => $this->_withdraw_set['eplus_withdraw_bank_frequency'],
  270. ];
  271. return $data;
  272. }
  273. //余额提现到支付宝
  274. public function withdrawAlipay()
  275. {
  276. return $this->_withdraw_set['alipay'] ? true : false;
  277. }
  278. //余额手动提现
  279. public function withdrawManual()
  280. {
  281. return $this->_withdraw_set['balance_manual'] ? true : false;
  282. }
  283. //余额EUP提现
  284. public function withdrawEup()
  285. {
  286. if (app('plugins')->isEnabled('eup-pay')) {
  287. return $this->_withdraw_set['eup_pay'] ? true : false;
  288. }
  289. return false;
  290. }
  291. //余额环迅提现
  292. public function withdrawHuanxun()
  293. {
  294. if (app('plugins')->isEnabled('huanxun')) {
  295. return $this->_withdraw_set['huanxun'] ? true : false;
  296. }
  297. return false;
  298. }
  299. //余额汇聚提现
  300. public function withdrawConverge()
  301. {
  302. if (app('plugins')->isEnabled('converge_pay')) {
  303. return $this->_withdraw_set['converge_pay'] ? true : false;
  304. }
  305. return false;
  306. }
  307. //余额高灯提现
  308. public function withdrawHighLight($withdrawType)
  309. {
  310. if (app('plugins')->isEnabled('high-light')) {
  311. return $this->_withdraw_set[$withdrawType] ? true : false;
  312. }
  313. return false;
  314. }
  315. /**
  316. * @return array|int[]
  317. * 余额提现额外数据
  318. */
  319. public function extraData()
  320. {
  321. $return_data = [];
  322. if (app('plugins')->isEnabled('worker-withdraw')) {
  323. $return_data['worker_withdraw'] = \Yunshop\WorkerWithdraw\services\SettingService::withdrawListExtraData();
  324. }
  325. if (app('plugins')->isEnabled('eplus-pay')) {
  326. $return_data['eplus_withdraw'] = \Yunshop\EplusPay\services\SettingService::withdrawListBankExtraData();
  327. }
  328. return $return_data;
  329. }
  330. public function eplusWithdrawEnable()
  331. {
  332. return $this->_withdraw_set['eplus_withdraw_bank'] && \Yunshop\EplusPay\services\SettingService::usable();
  333. }
  334. public function silverPointWithdrawEnable()
  335. {
  336. return $this->_withdraw_set['silver_point']
  337. && app('plugins')->isEnabled('silver-point-pay')
  338. && Setting::get('silver-point-pay.set.plugin_enable')
  339. && Setting::get('silver-point-pay.set.behalf_enable');
  340. }
  341. //帮扶中心核销
  342. public function supportCenterWithdrawEnable()
  343. {
  344. return app('plugins')->isEnabled('support-center') && \Yunshop\SupportCenter\models\SupportCenterConfigModel::getConfig('is_open');
  345. }
  346. //帮扶中心核销
  347. public function supportCenterWithdrawName()
  348. {
  349. return SUPPORT_CENTER_NAME ?: '帮扶中心';
  350. }
  351. /**
  352. * @param $withdrawType
  353. * @return bool
  354. * 好灵工余额提现是否可用
  355. */
  356. public function workerWithdrawEnable($withdrawType)
  357. {
  358. switch ($withdrawType) {
  359. case 'worker_withdraw_wechat':
  360. $re_type = 2;
  361. break;
  362. case 'worker_withdraw_alipay':
  363. $re_type = 1;
  364. break;
  365. case 'worker_withdraw_bank':
  366. $re_type = 1;
  367. break;
  368. }
  369. if ($this->_withdraw_set[$withdrawType] && app('plugins')->isEnabled(
  370. 'worker-withdraw'
  371. ) && \Yunshop\WorkerWithdraw\services\SettingService::usable([], $re_type)) {
  372. return true;
  373. }
  374. return false;
  375. }
  376. /**
  377. * 提现满 N元 减免手续费 [注意为 0, 为空则不计算,按正常手续费扣]
  378. * 2017-09-28
  379. * @return string
  380. */
  381. public function withdrawPoundageFullCut()
  382. {
  383. return $this->_withdraw_set['poundage_full_cut'] ?: '0';
  384. }
  385. /**
  386. * 增加提现手续费类型,1固定金额,0(默认)手续费比例
  387. * 2017-09-28
  388. * @return int
  389. */
  390. public function withdrawPoundageType()
  391. {
  392. return $this->_withdraw_set['poundage_type'] ? 1 : 0;
  393. }
  394. public function rechargeActivityStatus()
  395. {
  396. return $this->_recharge_set['recharge_activity'] ? true : false;
  397. }
  398. public function rechargeActivityStartTime()
  399. {
  400. return $this->_recharge_set['recharge_activity_start'] ?: 0;
  401. }
  402. public function rechargeActivityEndTime()
  403. {
  404. return $this->_recharge_set['recharge_activity_end'] ?: 0;
  405. }
  406. public function rechargeActivityCount()
  407. {
  408. return $this->_recharge_set['recharge_activity_count'] ?: 1;
  409. }
  410. public function rechargeActivityFetter()
  411. {
  412. return $this->_recharge_set['recharge_activity_fetter'];
  413. }
  414. public function teamTransfer($recipient)
  415. {
  416. $parent_ids = [];
  417. $child_ids = [];
  418. $parent = ParentOfMember::uniacid()->where('member_id', \Yunshop::app()->getMemberId())->get();
  419. if (!$parent->isEmpty()) {
  420. $parent_ids = $parent->pluck('parent_id')->toArray();
  421. }
  422. $children = ChildrenOfMember::uniacid()->where('member_id', \Yunshop::app()->getMemberId())->get();
  423. if (!$children->isEmpty()) {
  424. $child_ids = $children->pluck('child_id')->toArray();
  425. }
  426. $ids = array_merge($parent_ids, $child_ids);
  427. if (in_array($recipient, $ids)) {
  428. return true;
  429. }
  430. return false;
  431. }
  432. }