PayWayValidatorService.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. *
  5. * User: king/QQ:995265288
  6. * Date: 2018/6/13 下午2:22
  7. * Email: livsyitian@163.com
  8. */
  9. namespace app\frontend\modules\withdraw\services;
  10. use app\common\exceptions\AppException;
  11. use app\common\facades\Setting;
  12. use app\common\models\McMappingFans;
  13. use app\frontend\modules\finance\services\WithdrawManualService;
  14. use app\frontend\modules\withdraw\models\Withdraw;
  15. class PayWayValidatorService
  16. {
  17. public function validator($pay_way)
  18. {
  19. //todo 临时使用,应该提供一个系统的验证
  20. switch ($pay_way) {
  21. case 'balance':
  22. $this->balanceValidator();
  23. break;
  24. case 'wechat':
  25. $this->weChatValidator();
  26. break;
  27. case 'alipay':
  28. $this->alPayValidator();
  29. break;
  30. case 'huanxun':
  31. $this->huanXunValidator();
  32. break;
  33. case 'manual':
  34. $this->manualValidator();
  35. break;
  36. case 'eup_pay':
  37. $this->eupPayValidator();
  38. break;
  39. case 'yop_pay':
  40. $this->yopPayValidator();
  41. break;
  42. case 'converge_pay':
  43. $this->convergePayValidator();
  44. break;
  45. case 'yee_pay':
  46. $this->yeePayValidator();
  47. break;
  48. case 'converge-alloc-funds':
  49. $this->convergeSeparatePayValidator();
  50. break;
  51. case 'high_light_wechat':
  52. $this->highLightValidator('high_light_wechat');
  53. break;
  54. case 'high_light_alipay':
  55. $this->highLightValidator('high_light_alipay');
  56. break;
  57. case 'high_light_bank':
  58. $this->highLightValidator('high_light_bank');
  59. break;
  60. case 'worker_withdraw_alipay':
  61. case 'worker_withdraw_bank':
  62. case 'worker_withdraw_wechat':
  63. $this->workerWithdrawValidator($pay_way);
  64. break;
  65. case 'eplus_withdraw_bank':
  66. $this->eplusWithdrawBankValidator();
  67. break;
  68. case 'silver_point':
  69. $this->silverPointValidator();
  70. break;
  71. default:
  72. throw new AppException('未知提现方式');
  73. break;
  74. }
  75. }
  76. protected function convergeSeparatePayValidator()
  77. {
  78. }
  79. protected function balanceValidator()
  80. {
  81. }
  82. protected function weChatValidator()
  83. {
  84. }
  85. protected function alPayValidator()
  86. {
  87. if (!WithdrawManualService::getAlipayStatus()) {
  88. throw new AppException('您未配置支付宝信息,请先修改个人信息中支付宝信息', ['status' => 1]);
  89. }
  90. }
  91. protected function huanXunValidator()
  92. {
  93. }
  94. protected function eupPayValidator()
  95. {
  96. }
  97. protected function yopPayValidator()
  98. {
  99. }
  100. protected function convergePayValidator()
  101. {
  102. }
  103. protected function manualValidator()
  104. {
  105. switch ($this->getManualType()) {
  106. case Withdraw::MANUAL_TO_WECHAT:
  107. $result = $this->weChatStatus();
  108. break;
  109. case Withdraw::MANUAL_TO_ALIPAY:
  110. $result = $this->alipayStatus();
  111. break;
  112. default:
  113. $result = $this->bankStatus();
  114. }
  115. if ($result !== true) {
  116. throw new AppException($result, ['status' => 1]);
  117. }
  118. }
  119. protected function yeePayValidator()
  120. {
  121. if (!app('plugins')->isEnabled('yee-pay')) {
  122. throw new AppException('易宝代付插件未开启');
  123. }
  124. $employee = \Yunshop\YeePay\services\EmployeeService::employee([
  125. 'member_id' => \YunShop::app()->getMemberId()
  126. ])->first();
  127. if (!$employee) {
  128. throw new AppException('您未完成易宝代付签约,暂不能进行提现', ['yee_pay' => 1]);
  129. }
  130. return true;
  131. }
  132. protected function eplusWithdrawBankValidator()
  133. {
  134. if (!app('plugins')->isEnabled('eplus-pay')) {
  135. throw new AppException('智E+插件未开启');
  136. }
  137. if (!\Yunshop\EplusPay\services\SettingService::usable()) {
  138. throw new AppException('智E+插件不可用');
  139. }
  140. }
  141. protected function silverPointValidator()
  142. {
  143. }
  144. protected function workerWithdrawValidator($type)
  145. {
  146. if (!app('plugins')->isEnabled('worker-withdraw')) {
  147. throw new AppException('好灵工插件未开启');
  148. }
  149. if (!\Yunshop\WorkerWithdraw\services\SettingService::usableByType($type)) {
  150. throw new AppException('当前提现方式不可用');
  151. }
  152. $check = \Yunshop\WorkerWithdraw\services\SettingService::getRequestAccountByMember(
  153. \YunShop::app()->getMemberId(),
  154. $type
  155. );
  156. if (!$check['code']) {
  157. throw new AppException($check['message']);
  158. }
  159. if (!\Yunshop\WorkerWithdraw\models\Register::getByMember(
  160. \YunShop::app()->getMemberId(),
  161. $type == 'worker_withdraw_wechat' ? 2 : 1
  162. )) {
  163. throw new AppException('请先注册好灵工账户');
  164. }
  165. }
  166. protected function highLightValidator($type)
  167. {
  168. if (!app('plugins')->isEnabled('high-light') || !\Yunshop\HighLight\services\SetService::getStatus()) {
  169. throw new AppException('高灯提现插件未开启');
  170. }
  171. try {
  172. $agreementInfo = \Yunshop\HighLight\services\AgreementService::agreementInfo(
  173. ['member_id' => \Yunshop::app()->getMemberId()]
  174. )->first();
  175. if (!$agreementInfo || !\Yunshop\HighLight\services\AgreementService::checkAgreement($agreementInfo)) {
  176. $is_check = false;
  177. } else {
  178. $is_check = true;
  179. }
  180. } catch (\Exception $e) {
  181. throw new AppException($e->getMessage());
  182. }
  183. if (!$is_check) {
  184. throw new AppException('您未完成签约,暂不能进行提现', ['high_light' => 1]);
  185. }
  186. if ($agreementInfo->certificate_type == 1) {
  187. $year = substr($agreementInfo->certificate_no, 6, 4);
  188. if ((date('Y') - $year) > 65) {
  189. throw new AppException('超龄警告,大于65岁的会员无法进行此方式提现', ['high_light' => 1]);
  190. }
  191. }
  192. switch ($type) {
  193. case 'high_light_wechat':
  194. $fans = McMappingFans::where('uid', \Yunshop::app()->getMemberId())->first();
  195. if (!$fans) {
  196. throw new AppException(
  197. '您未在公众号商城中授权登录过,无法进行' . \Yunshop\HighLight\services\SetService::getDiyName() . '微信提现'
  198. );
  199. }
  200. break;
  201. case 'high_light_alipay':
  202. if (!$agreementInfo->payment_account) {
  203. throw new AppException('请您填写好所要提现到的支付宝账号', ['high_light' => 1]);
  204. }
  205. break;
  206. case 'high_light_bank':
  207. if (!$agreementInfo->bank_name || !$agreementInfo->bankcard_num) {
  208. throw new AppException('请您填写好所要提现到的银行信息', ['high_light' => 1]);
  209. }
  210. break;
  211. default:
  212. throw new AppException('未知提现类型');
  213. }
  214. }
  215. /**
  216. * 是否配置银行卡信息
  217. * @return bool|string
  218. */
  219. protected function bankStatus()
  220. {
  221. if (!WithdrawManualService::getBankStatus()) {
  222. return '请先完善您个人信息中银行卡信息';
  223. }
  224. return true;
  225. }
  226. /**
  227. * 是否配置微信信息
  228. * @return bool|string
  229. */
  230. protected function weChatStatus()
  231. {
  232. if (!WithdrawManualService::getWeChatStatus()) {
  233. return '请先完善您个人信息中的微信信息';
  234. }
  235. return true;
  236. }
  237. /**
  238. * 是否配置支付宝信息
  239. * @return bool|string
  240. */
  241. protected function alipayStatus()
  242. {
  243. if (!WithdrawManualService::getAlipayStatus()) {
  244. return '请先完善您个人信息中支付宝信息';
  245. }
  246. return true;
  247. }
  248. protected function getManualType()
  249. {
  250. $set = Setting::get('withdraw.income');
  251. return empty($set['manual_type']) ? 1 : $set['manual_type'];
  252. }
  253. }