BalanceWithdrawController.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. <?php
  2. /****************************************************************
  3. * Author: libaojia
  4. * Date: 2017/9/28 下午3:49
  5. * Email: livsyitian@163.com
  6. * QQ: 995265288
  7. * User: 芸众商城 www.yunzshop.com
  8. ****************************************************************/
  9. namespace app\frontend\modules\finance\controllers;
  10. use app\common\exceptions\AppException;
  11. use app\common\facades\Setting;
  12. use app\common\models\McMappingFans;
  13. use app\common\services\credit\ConstService;
  14. use app\common\services\finance\BalanceChange;
  15. use app\common\services\finance\BalanceNoticeService;
  16. use app\common\services\password\PasswordService;
  17. use app\frontend\models\Member;
  18. use app\frontend\models\MemberShopInfo;
  19. use app\frontend\modules\finance\models\Withdraw;
  20. use app\frontend\modules\finance\models\WithdrawSetLog;
  21. use app\frontend\modules\finance\services\WithdrawManualService;
  22. use app\frontend\modules\member\models\MemberBankCard;
  23. use app\frontend\modules\withdraw\services\WithdrawMessageService;
  24. use Illuminate\Support\Facades\DB;
  25. use app\common\events\withdraw\WithdrawBalanceAppliedEvent;
  26. use app\common\helpers\Url;
  27. use app\frontend\modules\withdraw\services\StatisticalPresentationService;
  28. class BalanceWithdrawController extends BalanceController
  29. {
  30. public $withdrawModel;
  31. /**
  32. * @var Member
  33. */
  34. public $memberModel;
  35. public function preAction()
  36. {
  37. parent::preAction();
  38. $this->memberModel = $this->getMemberModel();
  39. }
  40. /**
  41. * 余额提现页面按钮接口
  42. *
  43. * @return \Illuminate\Http\JsonResponse
  44. */
  45. public function page()
  46. {
  47. $data = [
  48. 'balance' => $this->memberModel->credit2 ?: 0,
  49. 'wechat' => $this->balanceSet->withdrawWechat(),
  50. 'alipay' => $this->balanceSet->withdrawAlipay(),
  51. 'manual' => $this->balanceSet->withdrawManual(),
  52. 'huanxun' => $this->balanceSet->withdrawHuanxun(),
  53. 'eup_pay' => $this->balanceSet->withdrawEup(),
  54. 'converge_pay' => $this->balanceSet->withdrawConverge(),
  55. 'withdraw_multiple' => $this->balanceSet->withdrawMultiple(),
  56. 'high_light_wechat' => $this->balanceSet->withdrawHighLight('high_light_wechat'),
  57. 'high_light_alipay' => $this->balanceSet->withdrawHighLight('high_light_alipay'),
  58. 'high_light_bank' => $this->balanceSet->withdrawHighLight('high_light_bank'),
  59. 'worker_withdraw_wechat' => $this->balanceSet->workerWithdrawEnable('worker_withdraw_wechat'),
  60. 'worker_withdraw_alipay' => $this->balanceSet->workerWithdrawEnable('worker_withdraw_alipay'),
  61. 'worker_withdraw_bank' => $this->balanceSet->workerWithdrawEnable('worker_withdraw_bank'),
  62. 'eplus_withdraw_bank' => $this->balanceSet->eplusWithdrawEnable(),
  63. 'silver_point' => $this->balanceSet->silverPointWithdrawEnable(),
  64. 'support_center_withdraw'=> $this->balanceSet->supportCenterWithdrawEnable(),
  65. 'support_center_withdraw_name'=> $this->balanceSet->supportCenterWithdrawName(),
  66. 'bank_card_status' => $this->memberBankCardStatus(),
  67. 'extra_data' => $this->balanceSet->extraData(),
  68. 'poundage' => $this->getPagePoundage(),
  69. 'has_password' => $this->hasPassword(),
  70. 'need_password' => $this->needWithdrawPassword()
  71. ];
  72. return $this->successJson('获取数据成功', $data);
  73. }
  74. private function hasPassword()
  75. {
  76. return $this->memberModel->yzMember->hasPayPassword();
  77. }
  78. private function needWithdrawPassword()
  79. {
  80. return (new PasswordService())->isNeed('balance', 'withdraw');
  81. }
  82. private function memberBankCardStatus(): bool
  83. {
  84. return WithdrawManualService::getBankStatus();
  85. }
  86. public function withdraw()
  87. {
  88. if ($this->needWithdrawPassword()) {
  89. (new PasswordService())->checkPayPassword($this->memberId(), $this->password());
  90. }
  91. if (!$this->balanceSet->withdrawSet()) {
  92. return $this->errorJson('未开启余额提现');
  93. }
  94. return $this->withdrawStart();
  95. }
  96. public function isCanSubmit()
  97. {
  98. if ($this->balanceSet->withdrawManual()) {
  99. return $this->successJson('ok', $this->manualIsCanSubmit());
  100. }
  101. return $this->errorJson('未开启余额手动提现');
  102. }
  103. private function getPagePoundage()
  104. {
  105. $lang = \Setting::get('shop.lang.lang');
  106. $langData = \Setting::get('shop.lang.' . $lang);
  107. $poundageName = $langData['income']['poundage_name'] ?: '手续费';
  108. $withdraw_poundage = $this->balanceSet->withdrawPoundage();
  109. if (empty($withdraw_poundage)) {
  110. return '';
  111. }
  112. $poundage = $poundageName . '比例:' . $this->balanceSet->withdrawPoundage() . '%';
  113. if ($this->balanceSet->withdrawPoundageType() == 1) {
  114. $poundage = "固定{$poundageName}:" . $this->balanceSet->withdrawPoundage() . '元';
  115. }
  116. $poundage_full_cut = $this->balanceSet->withdrawPoundageFullCut();
  117. if (!empty($poundage_full_cut)) {
  118. $poundage = $poundage . ",提现金额满" . $poundage_full_cut . "元减免{$poundageName}";
  119. }
  120. return $poundage;
  121. }
  122. private function withdrawStart()
  123. {
  124. $withdrawType = $this->getWithdrawType();
  125. if ($withdrawType == 'wechat' && !$this->balanceSet->withdrawWechat()) {
  126. return $this->errorJson('未开启提现到微信');
  127. }
  128. if ($withdrawType == 'alipay' && !$this->balanceSet->withdrawAlipay()) {
  129. return $this->errorJson('未开启提现到支付宝');
  130. }
  131. if ($withdrawType == 'alipay' && !$this->getMemberAlipaySet()) {
  132. return $this->errorJson('您未配置支付宝信息,请先修改个人信息中支付宝信息', ['status' => 1]);
  133. }
  134. if ($withdrawType == 'manual' && !$this->balanceSet->withdrawManual()) {
  135. return $this->errorJson('未开启余额手动提现');
  136. }
  137. if ($withdrawType == 'eup_pay' && !$this->balanceSet->withdrawEup()) {
  138. return $this->errorJson('未开启余额EUP提现');
  139. }
  140. if ($withdrawType == 'converge_pay' && !$this->balanceSet->withdrawConverge()) {
  141. return $this->errorJson('未开启余额汇聚提现');
  142. }
  143. if ($withdrawType == 'silver_point' && !$this->balanceSet->silverPointWithdrawEnable()) {
  144. return $this->errorJson('未开启余额银典支付提现');
  145. }
  146. if (in_array($withdrawType, ['high_light_wechat', 'high_light_alipay', 'high_light_bank']
  147. ) && !$this->balanceSet->withdrawHighLight($withdrawType)) {
  148. return $this->errorJson('未开启余额高灯提现');
  149. }
  150. $manual_result = $this->manualIsCanSubmit();
  151. if ($withdrawType == 'manual' && !$manual_result['status']) {
  152. return $this->errorJson('需要完善信息', $manual_result);
  153. }
  154. if (in_array($withdrawType, ['high_light_wechat', 'high_light_alipay', 'high_light_bank'])) {
  155. $this->highLightIsCanSubmit($withdrawType);
  156. }
  157. if (in_array($withdrawType, ['worker_withdraw_wechat', 'worker_withdraw_alipay', 'worker_withdraw_bank'])) {
  158. $this->workerWithdrawCanSubmit($withdrawType);
  159. }
  160. if (in_array($withdrawType, ['eplus_withdraw_bank'])) {
  161. $this->eplusWithdrawCanSubmit();
  162. }
  163. if ($withdrawType == 'support_center_withdraw' && !$this->balanceSet->supportCenterWithdrawEnable()) {
  164. return $this->errorJson('未开启' . $this->balanceSet->supportCenterWithdrawName());
  165. }
  166. $withdrawFetter = $this->balanceSet->withdrawAstrict();
  167. if ($withdrawFetter > $withdrawMoney = $this->getWithdrawMoney()) {
  168. return $this->errorJson('提现金额不能小于' . $withdrawFetter . '元');
  169. }
  170. $multiple = $this->balanceSet->withdrawMultiple();
  171. if (!empty($multiple) && fmod($withdrawMoney, $multiple) != 0) {
  172. throw new AppException('提现值必须是' . $multiple . '的倍数');
  173. }
  174. if (bcsub($this->getWithdrawMoney(), $this->getPoundage(), 2) < 1) {
  175. return $this->errorJson('扣除手续费后的金额不能小于1元');
  176. }
  177. $this->cashLimitation();
  178. DB::beginTransaction();
  179. //写入提现记录
  180. $this->withdrawModel = new Withdraw();
  181. $this->withdrawModel->fill($this->getWithdrawData());
  182. $validator = $this->withdrawModel->validator();
  183. if ($validator->fails()) {
  184. return $this->errorJson($validator->messages()->first());
  185. }
  186. if (!$this->withdrawModel->save()) {
  187. return $this->errorJson('提现失败,记录写入失败');
  188. }
  189. //写入提现关联表,当前设置记录
  190. $withdrawSetLog = new WithdrawSetLog();
  191. $withdrawSetLog->fill($this->getWithdrawSetLogData());
  192. $validator = $withdrawSetLog->validator();
  193. if ($validator->fails()) {
  194. return $this->errorJson($validator->messages()->first());
  195. }
  196. if (!$withdrawSetLog->save()) {
  197. return $this->errorJson('提现失败,记录Log写入失败');
  198. }
  199. //修改会员余额
  200. $result = (new BalanceChange())->withdrawal($this->getBalanceChangeData());
  201. if ($result === true) {
  202. DB::commit();
  203. app('plugins')->isEnabled('converge_pay') && Setting::get(
  204. 'withdraw.balance.audit_free'
  205. ) == 1 && $withdrawType == 'converge_pay' ? \Setting::set(
  206. 'plugin.convergePay_set.notifyWithdrawUrl',
  207. Url::shopSchemeUrl('payment/convergepay/notifyUrlWithdraw.php')
  208. ) : null;
  209. event(new WithdrawBalanceAppliedEvent($this->withdrawModel));
  210. BalanceNoticeService::withdrawSubmitNotice($this->withdrawModel);
  211. //提现通知管理员
  212. (new WithdrawMessageService())->withdraw($this->withdrawModel);
  213. if (app('plugins')->isEnabled('shop-assistant')) {
  214. \Log::info('余额提现-店铺助手申请');
  215. (new \Yunshop\ShopAssistant\services\MessageService)->withdrawAudit($this->withdrawModel);
  216. }
  217. return $this->successJson('提现申请成功');
  218. }
  219. DB::rollBack();
  220. return $this->errorJson('提现写入失败,请联系管理员');
  221. }
  222. //提现限制
  223. private function cashLimitation()
  224. {
  225. $set = Setting::get('withdraw.balance');
  226. $withdrawType = $this->getWithdrawType();
  227. $withdrawAmount = $this->getWithdrawMoney();
  228. //今日已经提现次数(收入提现 + 供应商提现)
  229. $submittedCount = (new StatisticalPresentationService())->statisticalPresentation($withdrawType);
  230. //统计用户今天提现的次数
  231. $count = $submittedCount + 1;
  232. switch ($withdrawType) {
  233. case Withdraw::WITHDRAW_WITH_SILVER_POINT:
  234. $min = $set['silver_point_min'];
  235. $max = $set['silver_point_max'];
  236. $limitCount = floor($set['silver_point_frequency'] ?: 10);
  237. break;
  238. case Withdraw::WITHDRAW_WITH_WECHAT:
  239. $min = $set['wechat_min'];
  240. $max = $set['wechat_max'];
  241. $limitCount = floor($set['wechat_frequency'] ?: 10);
  242. break;
  243. case Withdraw::WITHDRAW_WITH_ALIPAY:
  244. $min = $set['alipay_min'];
  245. $max = $set['alipay_max'];
  246. $limitCount = floor($set['alipay_frequency'] ?: 10);
  247. break;
  248. case Withdraw::WITHDRAW_WITH_MANUAL:
  249. $min = $set['manual_min'];
  250. $max = $set['manual_max'];
  251. $limitCount = floor($set['manual_frequency'] ?: 0);
  252. break;
  253. case Withdraw::WITHDRAW_WITH_EPLUS_WITHDRAW_BANK:
  254. $min = $set['eplus_withdraw_bank_min'];
  255. $max = $set['eplus_withdraw_bank_max'];
  256. $limitCount = floor($set['eplus_withdraw_bank_frequency'] ?: 0);
  257. case Withdraw::WITHDRAW_WITH_WORK_WITHDRAW_WECHAT:
  258. $min = $set['worker_withdraw_wechat_min'];
  259. $max = $set['worker_withdraw_wechat_max'];
  260. $limitCount = floor($set['worker_withdraw_wechat_frequency'] ?: 0);
  261. break;
  262. case Withdraw::WITHDRAW_WITH_WORK_WITHDRAW_BANK:
  263. $min = $set['worker_withdraw_bank_min'];
  264. $max = $set['worker_withdraw_bank_max'];
  265. $limitCount = floor($set['worker_withdraw_bank_frequency'] ?: 0);
  266. break;
  267. case Withdraw::WITHDRAW_WITH_WORK_WITHDRAW_ALIPAY:
  268. $min = $set['worker_withdraw_alipay_min'];
  269. $max = $set['worker_withdraw_alipay_max'];
  270. $limitCount = floor($set['worker_withdraw_alipay_frequency'] ?: 0);
  271. break;
  272. case Withdraw::WITHDRAW_WITH_HIGH_LIGHT_WECHAT:
  273. case Withdraw::WITHDRAW_WITH_HIGH_LIGHT_ALIPAY:
  274. case Withdraw::WITHDRAW_WITH_HIGH_LIGHT_BANK:
  275. if ($withdrawAmount < 1) {
  276. return $this->errorJson("余额" . Withdraw::getPayWayComment($withdrawType) . "失败,提现额必须大于等于1元");
  277. } elseif ($withdrawType == Withdraw::WITHDRAW_WITH_HIGH_LIGHT_WECHAT && $withdrawAmount > 100000) {
  278. return $this->errorJson("高灯微信单笔提现不得大于10万元");
  279. } elseif ($withdrawType == Withdraw::WITHDRAW_WITH_HIGH_LIGHT_ALIPAY && $withdrawAmount > 400000) {
  280. return $this->errorJson("高灯支付宝单笔提现不得大于40万元!");
  281. } elseif ($withdrawType == Withdraw::WITHDRAW_WITH_HIGH_LIGHT_BANK && $withdrawAmount > 100000) {
  282. return $this->errorJson("高灯银行卡单笔提现不得大于10万元!");
  283. }
  284. break;
  285. case Withdraw::WITHDRAW_WITH_CONVERGE_PAY:
  286. $min = $set['converge_pay_min'];
  287. $max = $set['converge_pay_max'];
  288. $limitCount = floor($set['converge_pay_frequency'] ?: 0);
  289. break;
  290. default:
  291. $min = 0;
  292. $max = 0;
  293. $limitCount = 0;
  294. }
  295. $payWayName = Withdraw::getPayWayComment($withdrawType);
  296. if ($min && $withdrawAmount < $min) {
  297. \Log::debug("余额{$payWayName}失败", ['提现金额', $withdrawAmount, '提现最小额', $min]);
  298. return $this->errorJson("余额{$payWayName}失败,{$payWayName}最小额度{$min}元");
  299. }
  300. if ($max && $withdrawAmount > $max) {
  301. \Log::debug("余额{$payWayName}失败", ['提现金额', $withdrawAmount, '提现最大额', $max]);
  302. return $this->errorJson("余额{$payWayName}失败,{$payWayName}最大额度{$max}元");
  303. }
  304. if ($limitCount && $count > $limitCount) {
  305. \Log::debug("余额{$payWayName}失败", ['今天提现次数', $submittedCount, '每日限制次数', $limitCount]);
  306. return $this->errorJson("余额{$payWayName}失败,每日{$payWayName}次数不能超过{$limitCount}次");
  307. }
  308. }
  309. /**
  310. * @return array
  311. */
  312. private function getWithdrawData()
  313. {
  314. $dalance = Setting::get('shop.shop');
  315. $dalance['credit'] = empty($dalance['credit']) ? "余额" : $dalance['credit'];
  316. return array(
  317. 'withdraw_sn' => Withdraw::createOrderSn('WS', 'withdraw_sn'),
  318. 'uniacid' => $this->uniacid,
  319. 'member_id' => $this->memberModel->uid,
  320. 'type' => 'balance',
  321. 'type_id' => '',
  322. 'type_name' => $dalance['credit'],//'余额提现'
  323. 'amounts' => $this->getWithdrawMoney(), //提现金额
  324. 'poundage' => $this->getPoundage(), //提现手续费
  325. 'poundage_rate' => $this->balanceSet->withdrawPoundageType() ? '0' : $this->PoundageRate(),//手续费比例
  326. 'pay_way' => $this->getWithdrawType(), //打款方式
  327. 'status' => '0', //0未审核,1未打款,2已打款, -1无效
  328. 'actual_amounts' => bcsub($this->getWithdrawMoney(), $this->getPoundage(), 2),
  329. 'actual_poundage' => $this->getPoundage(),
  330. 'manual_type' => Setting::get('withdraw.balance')['balance_manual_type'] ?: 1,
  331. );
  332. }
  333. /**
  334. * @return array
  335. */
  336. private function getWithdrawSetLogData()
  337. {
  338. return [
  339. 'withdraw_id' => $this->withdrawModel->id,
  340. 'poundage_type' => $this->balanceSet->withdrawPoundageType(),
  341. 'poundage' => $this->balanceSet->withdrawPoundage(),
  342. 'poundage_full_cut' => $this->balanceSet->withdrawPoundageFullCut(),
  343. 'withdraw_fetter' => $this->balanceSet->withdrawAstrict(),
  344. 'remark' => '',
  345. 'created_at' => time()
  346. ];
  347. }
  348. /**
  349. * 获取余额提现改变余额 data 数据
  350. * @return array
  351. */
  352. private function getBalanceChangeData()
  353. {
  354. return array(
  355. 'member_id' => \YunShop::app()->getMemberId(),
  356. 'remark' => '会员余额提现' . $this->withdrawModel->amounts,
  357. 'source' => ConstService::SOURCE_WITHDRAWAL,
  358. 'relation' => $this->withdrawModel->withdraw_sn,
  359. 'operator' => ConstService::OPERATOR_MEMBER,
  360. 'operator_id' => $this->withdrawModel->member_id,
  361. 'change_value' => $this->withdrawModel->amounts
  362. );
  363. }
  364. /**
  365. * 当前提现金额需支付手续费值
  366. * @return string
  367. */
  368. private function getPoundage()
  369. {
  370. if (!$this->isHasPoundage()) {
  371. return '0';
  372. } elseif ($this->balanceSet->withdrawPoundageType() == 1) {
  373. return $this->balanceSet->withdrawPoundage();
  374. } else {
  375. return bcdiv(bcmul($this->getWithdrawMoney(), $this->balanceSet->withdrawPoundage(), 4), 100, 2);
  376. }
  377. }
  378. /**
  379. * 手续费比例设置值,可以是固定金额,也可以是比例,需要通过 poundage_type 判断
  380. * @return string
  381. */
  382. private function PoundageRate()
  383. {
  384. return $this->isHasPoundage() ? $this->balanceSet->withdrawPoundage() : '0';
  385. }
  386. /**
  387. * 增加 提现金额 满N元 减免手续费,true 正常计算手续费,false 减免手续费 YITIAN::2017-09-28
  388. * @return bool
  389. */
  390. private function isHasPoundage()
  391. {
  392. $poundage_full_cut = $this->balanceSet->withdrawPoundageFullCut();
  393. if (!empty($poundage_full_cut)) {
  394. return bccomp($this->getWithdrawMoney(), $poundage_full_cut, 2) != -1 ? false : true;
  395. }
  396. return true;
  397. }
  398. private function getWithdrawMoney()
  399. {
  400. $withdraw_money = trim(\YunShop::request()->withdraw_money);
  401. if ($withdraw_money) {
  402. return $withdraw_money;
  403. }
  404. throw new AppException('未获取到提现金额');
  405. }
  406. private function getWithdrawType()
  407. {
  408. $requestType = request()->input('withdraw_type');
  409. $result = $this->withdrawTypeArray()[$requestType] ?? '';
  410. if (!$result) {
  411. throw new AppException('未找到提现类型');
  412. }
  413. return $result;
  414. }
  415. private function withdrawTypeArray(): array
  416. {
  417. return [
  418. 1 => 'wechat',
  419. 2 => 'alipay',
  420. 3 => 'manual',
  421. 4 => 'eup_pay',
  422. 5 => 'huanxun',
  423. 6 => 'converge_pay',
  424. 7 => 'high_light_wechat',
  425. 8 => 'high_light_alipay',
  426. 9 => 'high_light_bank',
  427. 10 => 'worker_withdraw_wechat',
  428. 11 => 'worker_withdraw_alipay',
  429. 12 => 'worker_withdraw_bank',
  430. 13 => 'eplus_withdraw_bank',
  431. 14 => 'silver_point',
  432. 15 => 'support_center_withdraw',
  433. ];
  434. }
  435. private function manualIsCanSubmit()
  436. {
  437. $manual_type = Setting::get('withdraw.balance')['balance_manual_type'] ?: 1;
  438. switch ($manual_type) {
  439. case 2:
  440. $result['manual_type'] = 'wechat';
  441. $result['status'] = WithdrawManualService::getWeChatStatus();
  442. break;
  443. case 3:
  444. $result['manual_type'] = 'alipay';
  445. $result['status'] = WithdrawManualService::getAlipayStatus();
  446. break;
  447. default:
  448. $result['manual_type'] = 'bank';
  449. $result['status'] = WithdrawManualService::getBankStatus();
  450. }
  451. return $result;
  452. }
  453. private function eplusWithdrawCanSubmit()
  454. {
  455. if (!app('plugins')->isEnabled('eplus-pay')) {
  456. throw new AppException('智E+插件未开启');
  457. }
  458. if (!\Yunshop\EplusPay\services\SettingService::usable()) {
  459. throw new AppException('智E+插件未启用');
  460. }
  461. if (!\Yunshop\EplusPay\services\SettingService::isNameAuth()) {
  462. throw new AppException('请先完成账户认证');
  463. }
  464. if (!request()->bank_card_no) {
  465. throw new AppException('请选择要提现的银行卡');
  466. }
  467. }
  468. private function workerWithdrawCanSubmit($withdrawType)
  469. {
  470. if (!app('plugins')->isEnabled('worker-withdraw')) {
  471. throw new AppException('好灵工插件未开启');
  472. }
  473. $res = \Yunshop\WorkerWithdraw\services\SettingService::getRequestAccountByMember(
  474. \YunShop::app()->getMemberId(),
  475. $withdrawType
  476. );
  477. if (!$res['code']) {
  478. throw new AppException($res['message']);
  479. }
  480. }
  481. private function highLightIsCanSubmit($withdrawType)
  482. {
  483. try {
  484. $agreementInfo = \Yunshop\HighLight\services\AgreementService::agreementInfo(
  485. ['member_id' => \Yunshop::app()->getMemberId()]
  486. )->first();
  487. if (!$agreementInfo || !\Yunshop\HighLight\services\AgreementService::checkAgreement($agreementInfo)) {
  488. $is_check = false;
  489. } else {
  490. $is_check = true;
  491. }
  492. } catch (\Exception $e) {
  493. throw new AppException($e->getMessage());
  494. }
  495. if (!$is_check) {
  496. throw new AppException('您未完成高灯签约,暂不能进行提现', ['high_light' => 1]);
  497. }
  498. if ($agreementInfo->certificate_type == 1) {
  499. $year = substr($agreementInfo->certificate_no, 6, 4);
  500. if ((date('Y') - $year) > 65) {
  501. throw new AppException('超龄警告,大于65岁的会员无法进行此方式提现', ['high_light' => 1]);
  502. }
  503. }
  504. switch ($withdrawType) {
  505. case 'high_light_wechat':
  506. $fans = McMappingFans::where('uid', \Yunshop::app()->getMemberId())->first();
  507. if (!$fans) {
  508. throw new AppException('您未在公众号商城中授权登录过,无法进行高灯微信提现');
  509. }
  510. break;
  511. case 'high_light_alipay':
  512. if (!$agreementInfo->payment_account) {
  513. throw new AppException('请您填写好所要提现到的支付宝账号', ['high_light' => 1]);
  514. }
  515. break;
  516. case 'high_light_bank':
  517. if (!$agreementInfo->bank_name || !$agreementInfo->bankcard_num) {
  518. throw new AppException('请您填写好所要提现到的银行信息', ['high_light' => 1]);
  519. }
  520. break;
  521. default:
  522. throw new AppException('未知提现类型');
  523. }
  524. return true;
  525. }
  526. //*********************************** 以下方法可以在member model 中实现 ***********************************************//
  527. /**
  528. * 获取会员 支付宝 设置,
  529. * @return bool
  530. */
  531. private function getMemberAlipaySet()
  532. {
  533. $array = MemberShopInfo::select('alipay', 'alipayname')->where(
  534. 'member_id',
  535. \YunShop::app()->getMemberId()
  536. )->first();
  537. if ($array && $array['alipay'] && $array['alipayname']) {
  538. return true;
  539. }
  540. return false;
  541. }
  542. /**
  543. * 获取验证登录会员是否存在, 因支付宝不需要验证,暂时从 BalanceController 中提出来,
  544. * @return mixed
  545. * @throws AppException
  546. */
  547. private function getMemberModel()
  548. {
  549. $memberModel = Member::where('uid', \YunShop::app()->getMemberId())->first();
  550. if ($memberModel) {
  551. return $memberModel;
  552. }
  553. throw new AppException('未获取到会员信息');
  554. }
  555. public function convergeWithdraw()
  556. {
  557. $data['cost_money'] = number_format($this->getWithdrawMoney(), 2);
  558. $data['actual_amount'] = bcsub($this->getWithdrawMoney(), $this->getPoundage(), 2);
  559. $data['poundage'] = number_format($this->getPoundage(), 2);
  560. return $this->successJson('获取数据成功', $data);
  561. }
  562. }