IncomeService.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. <?php
  2. /**
  3. * Author: 芸众商城 www.yunzshop.com
  4. * Date: 2017/6/8
  5. * Time: 下午5:49
  6. */
  7. namespace app\common\services\finance;
  8. use app\common\facades\Setting;
  9. class IncomeService
  10. {
  11. private static $payWay = [
  12. 'balance',
  13. 'wechat',
  14. 'alipay',
  15. 'manual',
  16. 'huanxun',
  17. 'eup_pay',
  18. 'yop_pay',
  19. 'yee_pay',
  20. 'converge_pay',
  21. 'high_light_wechat',
  22. 'high_light_alipay',
  23. 'high_light_bank',
  24. 'worker_withdraw_wechat',
  25. 'worker_withdraw_alipay',
  26. 'worker_withdraw_bank',
  27. 'eplus_withdraw_bank',
  28. 'silver_point'
  29. ];
  30. private static $payWayName = [
  31. 'balance' => "提现到余额",
  32. 'wechat' => "提现到微信",
  33. 'alipay' => "提现到支付宝",
  34. 'manual' => "提现到手动打款",
  35. 'huanxun' => "提现到银行卡",
  36. 'eup_pay' => "提现到EUP",
  37. 'yop_pay' => "提现到易宝",
  38. 'converge_pay' => "提现到银行卡-HJ",
  39. 'yee_pay' => "提现到易宝代付",
  40. 'high_light_wechat' => "提现到微信-高灯",
  41. 'high_light_alipay' => "提现到支付宝-高灯",
  42. 'high_light_bank' => "提现到银行卡-高灯",
  43. 'worker_withdraw_wechat' => "提现到微信-好灵工",
  44. 'worker_withdraw_alipay' => "提现到支付宝-好灵工",
  45. 'worker_withdraw_bank' => "提现到银行卡-好灵工",
  46. 'eplus_withdraw_bank' => "提现到银行卡(智E+)",
  47. 'silver_point' => "提现到银典支付"
  48. ];
  49. public function withdrawButton($incomeType = 'default')
  50. {
  51. switch ($incomeType) {
  52. case 'StoreCashier':
  53. return $this->storeCashierButton();
  54. case 'StoreWithdraw':
  55. return $this->storeWithdrawButton();
  56. case 'StoreBossWithdraw':
  57. return $this->storeBossWithdrawButton();
  58. default:
  59. return $this->defaultButton();
  60. }
  61. }
  62. /**
  63. * 门店收银台提现方式按钮组
  64. *
  65. * @return array
  66. */
  67. private function storeCashierButton()
  68. {
  69. return $this->customButton('StoreCashier');
  70. }
  71. /**
  72. * 门店提现方式按钮组
  73. *
  74. * @return array
  75. */
  76. private function storeWithdrawButton()
  77. {
  78. return $this->customButton('StoreWithdraw');
  79. }
  80. /**
  81. * 连锁店现方式按钮组
  82. *
  83. * @return array
  84. */
  85. private function storeBossWithdrawButton()
  86. {
  87. return $this->customButton('StoreBossWithdraw');
  88. }
  89. /**
  90. * 通过收入类型获取对应开启的提现方式按钮组
  91. *
  92. * @param string $incomeType
  93. *
  94. * @return array
  95. */
  96. private function customButton($incomeType)
  97. {
  98. if (!$this->incomeCustomStatus($incomeType)) {
  99. return $this->defaultButton();
  100. }
  101. return $this->_customButton($incomeType);
  102. }
  103. /**
  104. * @param string $incomeType
  105. *
  106. * @return array
  107. */
  108. private function _customButton($incomeType)
  109. {
  110. $defaultButton = ['service_switch' => $this->serviceSwitch()];
  111. foreach ($this->incomeCustomSet($incomeType) as $item) {
  112. if (in_array($item, static::$payWay)) {
  113. $defaultButton[$item] = [
  114. 'name' => $this->buttonName($item),
  115. 'value' => $item,
  116. 'other_name' => $this->otherButtonName($item),
  117. ];
  118. }
  119. }
  120. return $defaultButton;
  121. }
  122. /**
  123. * 提现方式按钮,读取提现设置中开启的提现方式,返回按钮格式
  124. *
  125. * @return array
  126. */
  127. private function defaultButton()
  128. {
  129. $defaultButton = ['service_switch' => $this->serviceSwitch()];
  130. foreach ($this->withdrawSet() as $key => $item) {
  131. if (in_array($key, static::$payWay) && $item && $this->buttonEnabled($key)) {
  132. $defaultButton[$key] = [
  133. 'name' => $this->buttonName($key),
  134. 'value' => $key,
  135. 'other_name' => $this->otherButtonName($key),
  136. 'extra_data' => $this->extraData($key),
  137. ];
  138. }
  139. }
  140. return $defaultButton;
  141. }
  142. private function extraData($key)
  143. {
  144. $return_data = [];
  145. if (!is_null($data = \app\common\modules\shop\ShopConfig::current()->get('withdraw_list_extra_data.' . $key))) {
  146. if (($class = $data['class']) && ($function = $data['function']) && method_exists($class, $function)) {
  147. $return_data = $class::$function();
  148. }
  149. }
  150. return $return_data;
  151. }
  152. private function buttonName($key)
  153. {
  154. $balance = Setting::get('shop.shop');
  155. $set = Setting::get('shop.lang.zh_cn.income');
  156. if ($set['name_of_withdrawal']) {
  157. $name = $set['name_of_withdrawal'] ?: '';
  158. } else {
  159. $name = '提现';
  160. }
  161. $high_light_name = '高灯提现';
  162. if (app('plugins')->isEnabled('high-light')) {
  163. $high_light_name = \Yunshop\HighLight\services\SetService::getDiyName();
  164. }
  165. $manual_withdrawal = Setting::get('shop.lang.zh_cn.income.manual_withdrawal');
  166. switch ($key) {
  167. case 'balance':
  168. return $name . '到 ' . ($balance['credit'] ?: '余额');
  169. case 'wechat':
  170. return $name . '到 微信';
  171. case 'alipay':
  172. return $name . '到 支付宝';
  173. case 'manual':
  174. return $name . '到 ' . ($manual_withdrawal ?: '手动打款');
  175. case 'huanxun':
  176. return $name . '到 银行卡';
  177. case 'eup_pay':
  178. return $name . '到 EUP';
  179. case 'yop_pay':
  180. return $name . '到 易宝';
  181. case 'converge_pay':
  182. return $name . '到 银行卡-HJ';
  183. case 'yee_pay':
  184. return $name . '到 易宝代付';
  185. case 'high_light_wechat':
  186. return $name . '到 微信-' . $high_light_name;
  187. case 'high_light_alipay':
  188. return $name . '到 支付宝-' . $high_light_name;
  189. case 'high_light_bank':
  190. return $name . '到 银行卡-' . $high_light_name;
  191. case 'eplus_withdraw_bank':
  192. return $name . '到 银行卡-智E+';
  193. case 'silver_point':
  194. return $name . '到 银典支付';
  195. default:
  196. return '';
  197. }
  198. }
  199. private function otherButtonName($key)
  200. {
  201. if (app('plugins')->isEnabled('high-light')) {
  202. $high_light_name = \Yunshop\HighLight\services\SetService::getDiyName();
  203. }
  204. $balance = Setting::get('shop.shop');
  205. $manual_withdrawal = Setting::get('shop.lang.zh_cn.income.manual_withdrawal');
  206. switch ($key) {
  207. case 'balance':
  208. return $balance['credit'] ?: '余额';
  209. case 'wechat':
  210. return '微信';
  211. case 'alipay':
  212. return '支付宝';
  213. case 'manual':
  214. return $manual_withdrawal ?: '手动打款';
  215. case 'huanxun':
  216. return '银行卡';
  217. case 'eup_pay':
  218. return 'EUP';
  219. case 'yop_pay':
  220. return '易宝';
  221. case 'converge_pay':
  222. return '银行卡-HJ';
  223. case 'yee_pay':
  224. return '易宝代付';
  225. case 'high_light_wechat':
  226. return '微信-' . (isset($high_light_name) ? $high_light_name : '高灯');
  227. case 'high_light_alipay':
  228. return '支付宝-' . (isset($high_light_name) ? $high_light_name : '高灯');
  229. case 'high_light_bank':
  230. return '银行卡-' . (isset($high_light_name) ? $high_light_name : '高灯');
  231. case 'eplus_withdraw_bank':
  232. return '银行卡-智E+';
  233. case 'silver_point':
  234. return '银典支付';
  235. default:
  236. return '';
  237. }
  238. }
  239. private function buttonEnabled($key)
  240. {
  241. switch ($key) {
  242. case 'balance':
  243. case 'wechat':
  244. case 'alipay':
  245. case 'manual':
  246. case 'yop_pay':
  247. return true;
  248. case 'silver_point':
  249. if (!app('plugins')->isEnabled('silver-point-pay')) {
  250. return false;
  251. }
  252. return Setting::get('silver-point-pay.set.plugin_enable') && Setting::get('silver-point-pay.set.behalf_enable');
  253. case 'huanxun':
  254. if (!app('plugins')->isEnabled('huanxun')) {
  255. return false;
  256. }
  257. return true;
  258. case 'eup_pay':
  259. if (!app('plugins')->isEnabled('eup-pay')) {
  260. return false;
  261. }
  262. return true;
  263. case 'converge_pay':
  264. if (!app('plugins')->isEnabled('converge_pay')) {
  265. return false;
  266. }
  267. return true;
  268. case 'yee_pay':
  269. if (!app('plugins')->isEnabled('yee-pay') || !\Yunshop\YeePay\services\SetService::getStatus()) {
  270. return false;
  271. }
  272. return true;
  273. case 'worker_withdraw_wechat':
  274. return self::workerWithdrawEnable(2);
  275. case 'worker_withdraw_alipay':
  276. case 'worker_withdraw_bank':
  277. return self::workerWithdrawEnable(1);
  278. case 'eplus_withdraw_bank':
  279. return app('plugins')->isEnabled('eplus-pay') && \Yunshop\EplusPay\services\SettingService::usable();
  280. case 'high_light_wechat':
  281. case 'high_light_alipay':
  282. case 'high_light_bank':
  283. if (!app('plugins')->isEnabled('high-light') || !\Yunshop\HighLight\services\SetService::getStatus()) {
  284. return false;
  285. }
  286. return true;
  287. default:
  288. return false;
  289. }
  290. }
  291. /**
  292. * @return bool
  293. * 好灵工提现是否可用
  294. */
  295. public static function workerWithdrawEnable($re_type)
  296. {
  297. return app('plugins')->isEnabled('worker-withdraw') && \Yunshop\WorkerWithdraw\services\SettingService::usable(
  298. [],
  299. $re_type
  300. );
  301. }
  302. /**
  303. * 收入类型是否开启自定义提现方式
  304. *
  305. * @param string $incomeType
  306. *
  307. * @return bool
  308. */
  309. private function incomeCustomStatus($incomeType)
  310. {
  311. return !!Setting::get("withdraw.{$incomeType}.withdraw_type");
  312. }
  313. /**
  314. * 收入类型自定义提现方式设置
  315. *
  316. * @param string $incomeType
  317. *
  318. * @return array
  319. */
  320. private function incomeCustomSet($incomeType)
  321. {
  322. return Setting::get("withdraw.{$incomeType}.withdraw_method");
  323. }
  324. /**
  325. * 提现设置
  326. *
  327. * @return array
  328. */
  329. private function withdrawSet()
  330. {
  331. return Setting::get('withdraw.income');
  332. }
  333. /**
  334. * 是否显示劳务税
  335. *
  336. * @return int
  337. */
  338. private function serviceSwitch()
  339. {
  340. return Setting::get('withdraw.income.service_switch') ?: 0;
  341. }
  342. }