IncomeWithdrawController.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789
  1. <?php
  2. /****************************************************************
  3. * Author: libaojia
  4. * Date: 2017/9/7 下午4:11
  5. * Email: livsyitian@163.com
  6. * QQ: 995265288
  7. * User: 芸众商城 www.yunzshop.com
  8. ****************************************************************/
  9. namespace app\frontend\modules\finance\controllers;
  10. use app\backend\modules\withdraw\models\WithdrawRichText;
  11. use app\common\components\ApiController;
  12. use app\common\facades\Setting;
  13. use app\common\models\Income;
  14. use app\common\models\MemberShopInfo;
  15. use app\common\services\finance\IncomeService;
  16. use app\frontend\modules\finance\models\Withdraw;
  17. use app\frontend\modules\member\models\MemberBankCard;
  18. use Yunshop\ShopEsignV2\common\models\ShopContract;
  19. use Yunshop\TeamDividend\services\withdraw\IncomeWithdrawApply;
  20. use app\common\services\finance\Withdraw as WithdrawService;
  21. use Yunshop\ShopEsign\common\service\ContractService;
  22. class IncomeWithdrawController extends ApiController
  23. {
  24. //提现设置
  25. private $withdraw_set;
  26. //收入设置
  27. private $income_set;
  28. //提现方式
  29. private $pay_way;
  30. //手续费比例
  31. private $poundage_rate;
  32. //手续费类型
  33. private $poundage_type;
  34. //劳务税比例
  35. private $service_tax_rate;
  36. private $special_poundage_type;
  37. //
  38. private $special_poundage_rate;
  39. //
  40. private $special_service_tax_rate;
  41. //提现金额
  42. private $withdraw_amounts;
  43. public function preAction()
  44. {
  45. parent::preAction();
  46. $this->setWithdrawSet();
  47. }
  48. /**
  49. * 可提现数据接口【完成】
  50. * @return \Illuminate\Http\JsonResponse
  51. */
  52. public function getWithdraw()
  53. {
  54. $shopEsign = $this->shopEsign();
  55. $income_config = \app\backend\modules\income\Income::current()->getItems();
  56. $income_data = [];
  57. $loveName = '爱心值';
  58. if (app('plugins')->isEnabled('love')) {
  59. $loveName = LOVE_NAME;
  60. }
  61. $deductionLove = [
  62. 'love_name' => $loveName,
  63. 'deduction_type' => 0,
  64. 'deduction_radio' => 0,
  65. 'deduction_value' => 0,
  66. 'deduction_status' => 0,
  67. ];
  68. $all_withdraw_income = 0;
  69. foreach ($income_config as $key => $income) {
  70. //余额不计算 拍卖预付款不计算
  71. if ($income['type'] == 'balance' || $income['type'] == 'auction_prepayment') {
  72. continue;
  73. }
  74. //获取收入独立设置
  75. $this->setIncomeSet($income['type']);
  76. //附值手续费、劳务税(收银台不计算手续费、劳务税)
  77. if ($income['type'] == 'kingtimes_provider' || $income['type'] == 'kingtimes_distributor') {
  78. $this->poundage_rate = 0;
  79. $this->service_tax_rate = 0;
  80. $this->special_poundage_rate = 0;
  81. $this->special_service_tax_rate = 0;
  82. } else {
  83. $this->setSpecialPoundageType();
  84. $this->setPoundageRate($income['type']);
  85. $this->setServiceTaxRate($income['type']);
  86. $this->setSpecialPoundageRate();
  87. $this->setSpecialServiceTaxRate($income['type']);
  88. }
  89. $data = $this->getItemData($key, $income);
  90. if ($data['income'] > 0) {
  91. $all_withdraw_income += $data['income'];
  92. $income_data[] = $data;
  93. }
  94. //dd($income_data);
  95. //增加经销商提现显示口爱心值
  96. if ($income['type'] == 'teamDividend') {
  97. $teamDividendWithdraw = (new IncomeWithdrawApply());
  98. $deductionLove['deduction_type'] = $teamDividendWithdraw->deductionType();
  99. $deductionLove['deduction_radio'] = $teamDividendWithdraw->deductionRadio();
  100. $deductionLove['deduction_status'] = $teamDividendWithdraw->deductionStatus();
  101. $deductionLove['deduction_value'] = $teamDividendWithdraw->deductionAmount($this->withdraw_amounts);
  102. }
  103. }
  104. $withdraw_rich_text = WithdrawRichText::uniacid()->first() ?: [];
  105. $data = [
  106. 'data' => $income_data,
  107. 'setting' => [
  108. 'balance_special' => $this->getBalanceSpecialSet(),
  109. 'service_switch' => $this->withdraw_set['service_switch'] ?: 0,
  110. 'withdraw_rich_text' => $withdraw_rich_text,
  111. 'customer_service' => $this->getCustomerService(),
  112. ],
  113. 'special_type' => $this->special_poundage_type,
  114. 'deduction_love' => $deductionLove,
  115. 'shop_esign' => $shopEsign,
  116. 'all_withdraw_income' => $all_withdraw_income ?: 0.00,
  117. 'need_sign' => $this->needSign(),
  118. ];
  119. return $this->successJson('获取数据成功!', $data);
  120. }
  121. private function needSign()
  122. {
  123. if (!app('plugins')->isEnabled('shop-esign-v2')) {
  124. return false;
  125. }
  126. $plugin_set = Setting::get('plugin.shop_esign_v2');
  127. $scene_id = $plugin_set['withdraw_scene_id'];
  128. if (!$scene_id) {
  129. return false;
  130. }
  131. $contract = ShopContract::uniacid()
  132. ->where('member_id', \YunShop::app()->getMemberId())
  133. ->where('scene_id', $scene_id)
  134. ->where('status', 1)
  135. ->where('scene_type', 2)
  136. ->first();
  137. if (!$contract) {
  138. return true;
  139. }
  140. return false;
  141. }
  142. private function getCustomerService()
  143. {
  144. $plugin_set = array_pluck(Setting::getAllByGroup('customer-service')->toArray(), 'value', 'key');
  145. if (app('plugins')->isEnabled('customer-service') && $plugin_set['is_open']) {
  146. if (request()->type == 2) {
  147. return [
  148. 'service' => $plugin_set['mini_link'],
  149. 'service_QRcode' => yz_tomedia($plugin_set['mini_QRcode']),
  150. 'service_mobile' => $plugin_set['mini_mobile'],
  151. 'customer_open' => $plugin_set['mini_open'],
  152. ];
  153. }
  154. return [
  155. 'service' => $plugin_set['link'],
  156. 'service_QRcode' => yz_tomedia($plugin_set['QRcode']),
  157. 'service_mobile' => $plugin_set['mobile'],
  158. ];
  159. }
  160. $shop_set = Setting::get('shop.shop');
  161. if (request()->type == 2) {
  162. return [
  163. 'service' => $shop_set['cservice_mini'] ?: '',
  164. ];
  165. }
  166. return ['service' => $shop_set['cservice'] ?: ''];
  167. }
  168. public function getMergeServicetax()
  169. {
  170. if (!$income_type = request()->income_type) {
  171. return $this->errorJson('请选择要提现的收入');
  172. }
  173. $withdraw_set = \Setting::get('withdraw.income');
  174. $res = self::getWithdraw();
  175. $res = json_decode($res->getContent(), true);
  176. if (!$res) {
  177. return $this->errorJson('获取收入数据失败');
  178. }
  179. $income_data = $res['data']['data'];
  180. $amount = 0; //劳务费计算基础金额
  181. $sum_amount = 0; //总提现金额
  182. $poundage_amount = 0; // 总手续费
  183. $special_poundage_amount = 0; //余额独立手续费
  184. $special_tax_amount = 0; //余额独立劳务税
  185. foreach ($income_data as $k => $v) {
  186. if (!in_array($v['key_name'], $income_type)) {
  187. continue;
  188. }
  189. $special_tax_amount = bcadd($special_tax_amount, $v['special_service_tax'], 2);
  190. $special_poundage_amount = bcadd($special_poundage_amount, $v['special_poundage'], 2);
  191. $sum_amount = bcadd($sum_amount, $v['income'], 2);
  192. $poundage_amount = bcadd($poundage_amount, $v['poundage'], 2);
  193. if (in_array($v['key_name'], ['StoreCashier', 'StoreWithdraw', 'StoreBossWithdraw'])) {
  194. continue;
  195. }
  196. if (!$withdraw_set['service_tax_calculation']) {
  197. $this_amount = bcsub($v['income'], $v['poundage'], 2);
  198. if (bccomp($this_amount, 0, 2) != 1) $this_amount = 0;
  199. } else {
  200. $this_amount = $v['income'];
  201. }
  202. $amount = bcadd($amount, $this_amount, 2);
  203. }
  204. $servicetax_data = WithdrawService::getWithdrawServicetaxPercent($amount);
  205. return $this->successJson('成功', [
  206. 'sum_amount' => $sum_amount,
  207. 'poundage_amount' => $poundage_amount,
  208. 'servicetax_amount' => $servicetax_data['servicetax_amount'] ?: 0,
  209. 'servicetax_percent' => $servicetax_data['servicetax_percent'] ?: 0,
  210. 'special_tax_amount' => $special_tax_amount,
  211. 'special_poundage_amount' => $special_poundage_amount
  212. ]);
  213. }
  214. public function getLangTitle($data)
  215. {
  216. $lang = Setting::get('shop.lang');
  217. $langData = $lang[$lang['lang']];
  218. $titleType = '';
  219. foreach ($langData as $key => $item) {
  220. $names = explode('_', $key);
  221. foreach ($names as $k => $name) {
  222. if ($k == 0) {
  223. $titleType = $name;
  224. } else {
  225. $titleType .= ucwords($name);
  226. }
  227. }
  228. if ($data == $titleType) {
  229. return $item[$key];
  230. }
  231. }
  232. }
  233. /**
  234. * @param $income_type
  235. * @return int|mixed
  236. */
  237. private function setPoundageRate($income_type)
  238. {
  239. !isset($this->income_set) && $this->income_set = $this->setIncomeSet($income_type);
  240. $value = array_get($this->income_set, 'poundage_rate', 0);
  241. $type = array_get($this->income_set, 'poundage_type', 0);
  242. $this->poundage_type = $type ?: 0;
  243. return $this->poundage_rate = empty($value) ? 0 : $value;
  244. }
  245. /**
  246. * @return int|mixed
  247. */
  248. private function setServiceTaxRate($income_type)
  249. {
  250. $value = array_get($this->withdraw_set, 'servicetax_rate', 0);
  251. if (in_array($income_type, ['StoreCashier', 'StoreWithdraw', 'StoreBossWithdraw'])) {
  252. $value = 0;
  253. }
  254. return $this->service_tax_rate = empty($value) ? 0 : $value;
  255. }
  256. /**
  257. * @param string $incomeType
  258. * @param float $incomeAmount
  259. *
  260. * @return float
  261. */
  262. private function getLastServiceTaxRate($incomeType, $incomeAmount)
  263. {
  264. if (in_array($incomeType, ['StoreCashier', 'StoreWithdraw', 'StoreBossWithdraw'])) {
  265. return 0;
  266. }
  267. $serviceTaxRateLadder = array_get($this->withdraw_set, 'servicetax', []);
  268. if (!empty($serviceTaxRateLadder)) {
  269. $ladderSet = array_column($serviceTaxRateLadder, 'servicetax_money');
  270. array_multisort($ladderSet, SORT_DESC, $serviceTaxRateLadder);
  271. foreach ($serviceTaxRateLadder as $value) {
  272. if ($incomeAmount >= $value['servicetax_money'] && !empty($value['servicetax_money'])) {
  273. return $value['servicetax_rate'];
  274. }
  275. }
  276. }
  277. return array_get($this->withdraw_set, 'servicetax_rate', 0);
  278. }
  279. /**
  280. * 提现到余额独立手续费比例
  281. * @return int|mixed
  282. */
  283. private function setSpecialPoundageRate()
  284. {
  285. $value = array_get($this->withdraw_set, 'special_poundage', 0);
  286. return $this->special_poundage_rate = empty($value) ? 0 : $value;
  287. }
  288. /**
  289. * 提现到余额独立手续费比例
  290. * @return int|mixed
  291. */
  292. private function setSpecialPoundageType()
  293. {
  294. $value = array_get($this->withdraw_set, 'special_poundage_type', 0);
  295. return $this->special_poundage_type = empty($value) ? 0 : $value;
  296. }
  297. /**
  298. * 提现到余额独立劳务税
  299. * @return int|mixed
  300. */
  301. private function setSpecialServiceTaxRate($income_type)
  302. {
  303. $value = array_get($this->withdraw_set, 'special_service_tax', 0);
  304. if (in_array($income_type, ['StoreCashier', 'StoreWithdraw', 'StoreBossWithdraw'])) {
  305. $value = 0;
  306. }
  307. return $this->special_service_tax_rate = empty($value) ? 0 : $value;
  308. }
  309. /**
  310. * 是否使用余额独立手续费、劳务税
  311. * @return bool
  312. */
  313. private function isUseBalanceSpecialSet()
  314. {
  315. // if ($this->pay_way == Withdraw::WITHDRAW_WITH_BALANCE && 这里判断不知道有什么意义,暂时屏蔽
  316. if (
  317. $this->getBalanceSpecialSet()
  318. ) {
  319. return true;
  320. }
  321. return false;
  322. }
  323. /**
  324. * 是否开启提现到余额独立手续费、劳务税
  325. * @return bool
  326. */
  327. private function getBalanceSpecialSet()
  328. {
  329. return empty(array_get($this->withdraw_set, 'balance_special', 0)) ? false : true;
  330. }
  331. /**
  332. * 手续费计算公式
  333. * @param $amount
  334. * @param $rate
  335. * @return string
  336. */
  337. private function poundageMath($amount, $rate)
  338. {
  339. return bcmul(bcdiv($amount, 100, 4), $rate, 2);
  340. }
  341. /*
  342. * 获取收入提现全局设置
  343. * @return mixed
  344. */
  345. private function setWithdrawSet()
  346. {
  347. return $this->withdraw_set = Setting::get('withdraw.income');
  348. }
  349. /**
  350. * 获取收入类型独立设置
  351. * @param $income_type
  352. * @return mixed
  353. */
  354. private function setIncomeSet($income_type)
  355. {
  356. return $this->income_set = Setting::get('withdraw.' . $income_type);
  357. }
  358. /**
  359. * @return mixed
  360. */
  361. private function getIncomeModel()
  362. {
  363. return Income::uniacid()->canWithdraw()
  364. ->where('member_id', \YunShop::app()->getMemberId());
  365. //->where('incometable_type', $this->item['class']);
  366. }
  367. /**
  368. * 可提现数据 item
  369. * @return array
  370. */
  371. private function getItemData($key, $income)
  372. {
  373. $this->withdraw_amounts = $this->getIncomeModel()->where('incometable_type', $income['class'])->sum('amount');
  374. //手续费
  375. $poundage = $this->poundageMath($this->withdraw_amounts, $this->poundage_rate);
  376. if ($this->poundage_type == 1) {
  377. $poundage = number_format($this->poundage_rate, 2, '.', '');
  378. }
  379. //劳务税
  380. //因为增加阶梯劳务税,这里重新赋值付费比例
  381. $this->service_tax_rate = $this->getLastServiceTaxRate($income['type'], $this->withdraw_amounts);
  382. if (array_get($this->withdraw_set, 'service_tax_calculation', 0) == 1) {
  383. $service_tax = $this->poundageMath($this->withdraw_amounts, $this->service_tax_rate);
  384. } else {
  385. $service_tax = $this->poundageMath($this->withdraw_amounts - $poundage, $this->service_tax_rate);
  386. }
  387. //提现到余额独立手续费
  388. $special_poundage = $this->poundageMath($this->withdraw_amounts, $this->special_poundage_rate);
  389. if ($this->isUseBalanceSpecialSet()) {
  390. if ($this->special_poundage_type == 1) {
  391. $special_poundage = number_format($this->special_poundage_rate, 2, '.', '');
  392. }
  393. }
  394. //提现到余额独立劳务税
  395. if (array_get($this->withdraw_set, 'service_tax_calculation', 0) == 1) {
  396. $special_service_tax = $this->poundageMath($this->withdraw_amounts, $this->special_service_tax_rate);
  397. } else {
  398. $special_service_tax = $this->poundageMath(($this->withdraw_amounts - $special_poundage), $this->special_service_tax_rate);
  399. }
  400. $can = $this->incomeIsCanWithdraw();
  401. if ($income['type'] == 'commission') {
  402. $max = $this->getWithdrawLog($income['class']);
  403. if (is_numeric($this->getIncomeAmountMax()) || is_numeric($this->getIncomeTimeMax())) {
  404. if (!is_numeric($this->getIncomeAmountMax())) {
  405. if ($max['max_time'] >= $this->getIncomeTimeMax()) {
  406. $can = false;
  407. }
  408. } elseif (!is_numeric($this->getIncomeTimeMax())) {
  409. if ($max['max_amount'] + $this->withdraw_amounts > $this->getIncomeAmountMax()) {
  410. $can = false;
  411. }
  412. } else {
  413. if ($max['max_time'] >= $this->getIncomeTimeMax()) {
  414. $can = false;
  415. } elseif ($max['max_amount'] + $this->withdraw_amounts > $this->getIncomeAmountMax()) {
  416. $can = false;
  417. }
  418. }
  419. }
  420. }
  421. $actualAmount = bcsub(bcsub($this->withdraw_amounts, $poundage, 2), $service_tax, 2);
  422. return [
  423. 'type' => $income['class'],
  424. 'key_name' => $income['type'],
  425. 'type_name' => $this->getLangTitle($key) ? $this->getLangTitle($key) : $income['title'],
  426. 'income' => $this->withdraw_amounts,
  427. 'poundage' => $poundage,
  428. 'poundage_type' => $this->poundage_type ?: 0,
  429. 'poundage_rate' => $this->poundage_rate,
  430. 'servicetax' => $service_tax,
  431. 'servicetax_rate' => $this->service_tax_rate ?: 0,
  432. 'roll_out_limit' => $this->getIncomeAmountFetter(),
  433. 'max_roll_out_limit' => $this->getIncomeAmountMax(),
  434. 'max_time_out_limit' => $this->getIncomeTimeMax(),
  435. 'can' => $can,
  436. 'selected' => $this->incomeIsCanWithdraw(),
  437. 'type_id' => $this->getIncomeTypeIds($income['class']),
  438. 'special_poundage' => $special_poundage,
  439. 'special_poundage_rate' => $this->special_poundage_rate,
  440. 'special_service_tax' => $special_service_tax,
  441. 'special_service_tax_rate' => $this->special_service_tax_rate,
  442. 'actual_amount' => $actualAmount,
  443. 'income_type' => $this->incomeType($income['type']),
  444. ];
  445. }
  446. /**
  447. * 兼容开发,为了处理门店提现、收银台提现、连锁店提现设置独立的提现打款方式(最快的解决办法,todo 需要优化)
  448. *
  449. * @param string $incomeType
  450. *
  451. * @return string
  452. */
  453. private function incomeType($incomeType)
  454. {
  455. //'StoreCashier', 'StoreWithdraw', 'StoreBossWithdraw'
  456. switch ($incomeType) {
  457. case 'StoreCashier':
  458. return 'StoreCashier';
  459. case 'StoreWithdraw':
  460. return 'StoreWithdraw';
  461. case 'StoreBossWithdraw':
  462. return 'StoreBossWithdraw';
  463. default:
  464. return 'default';
  465. }
  466. }
  467. /**
  468. * 提现最小额度
  469. * @return string
  470. */
  471. private function getIncomeAmountFetter()
  472. {
  473. $value = array_get($this->income_set, 'roll_out_limit', 0);
  474. return empty($value) ? 0 : $value;
  475. }
  476. /**
  477. * 提现最高额度
  478. * @return string
  479. */
  480. private function getIncomeAmountMax()
  481. {
  482. $value = array_get($this->income_set, 'max_roll_out_limit');
  483. return $value;
  484. }
  485. /**
  486. * 提现最高次数
  487. * @return string
  488. */
  489. private function getIncomeTimeMax()
  490. {
  491. $value = array_get($this->income_set, 'max_time_out_limit');
  492. return $value;
  493. }
  494. /**
  495. * 获取提现记录
  496. * @return string
  497. */
  498. private function getWithdrawLog($class)
  499. {
  500. $before_dawn = mktime(0, 0, 0, date("m"), date("d"), date("Y"));
  501. $now = time();
  502. $max_time = Withdraw::where('type', $class)->where('member_id', \YunShop::app()->getMemberId())->whereBetween('created_at', [$before_dawn, $now])->count();
  503. $max_amount = Withdraw::where('type', $class)->where('member_id', \YunShop::app()->getMemberId())->whereBetween('created_at', [$before_dawn, $now])->sum('amounts');
  504. $max = ['max_time' => $max_time, 'max_amount' => $max_amount];
  505. return $max;
  506. }
  507. /**
  508. * 是否可以提现
  509. * @return bool
  510. */
  511. private function incomeIsCanWithdraw()
  512. {
  513. if (bccomp($this->withdraw_amounts, $this->getIncomeAmountFetter(), 2) == -1 || bccomp($this->withdraw_amounts, 0, 2) != 1) {
  514. return false;
  515. }
  516. return true;
  517. }
  518. /**
  519. * 获取 item 对应 id 集
  520. * @return string
  521. */
  522. private function getIncomeTypeIds($income_class)
  523. {
  524. if ($this->incomeIsCanWithdraw()) {
  525. $type_ids = '';
  526. foreach ($this->getIncomeModel()->where('incometable_type', $income_class)->get() as $ids) {
  527. $type_ids .= $ids->id . ",";
  528. }
  529. return $type_ids;
  530. }
  531. return '';
  532. }
  533. /************************ todo 杨雷原代码 *********************************/
  534. /**
  535. * @return \Illuminate\Http\JsonResponse
  536. */
  537. public function getIncomeCount()
  538. {
  539. $status = \YunShop::request()->status;
  540. $incomeModel = Income::getIncomes()->where('member_id', \YunShop::app()->getMemberId())->get();
  541. if ($status >= '0') {
  542. $incomeModel = $incomeModel->where('status', $status);
  543. }
  544. $config = \app\common\modules\shop\ShopConfig::current()->get('plugin');
  545. $incomeData['total'] = [
  546. 'title' => '推广收入',
  547. 'type' => 'total',
  548. 'type_name' => '推广佣金',
  549. 'income' => $incomeModel->sum('amount')
  550. ];
  551. foreach ($config as $key => $item) {
  552. $typeModel = $incomeModel->where('incometable_type', $item['class']);
  553. $incomeData[$key] = [
  554. 'title' => $item['title'],
  555. 'ico' => $item['ico'],
  556. 'type' => $item['type'],
  557. 'type_name' => $item['title'],
  558. 'income' => $typeModel->sum('amount')
  559. ];
  560. if ($item['agent_class']) {
  561. $agentModel = $item['agent_class']::{$item['agent_name']}(\YunShop::app()->getMemberId());
  562. if ($item['agent_status']) {
  563. $agentModel = $agentModel->where('status', 1);
  564. }
  565. //推广中心显示
  566. if (!$agentModel) {
  567. $incomeData[$key]['can'] = false;
  568. } else {
  569. $agent = $agentModel->first();
  570. if ($agent) {
  571. $incomeData[$key]['can'] = true;
  572. } else {
  573. $incomeData[$key]['can'] = false;
  574. }
  575. }
  576. } else {
  577. $incomeData[$key]['can'] = true;
  578. }
  579. }
  580. if ($incomeData) {
  581. return $this->successJson('获取数据成功!', $incomeData);
  582. }
  583. return $this->errorJson('未检测到数据!');
  584. }
  585. /**
  586. * @return \Illuminate\Http\JsonResponse
  587. */
  588. public function getIncomeList()
  589. {
  590. $configs = \app\backend\modules\income\Income::current()->getItems();
  591. $type = \YunShop::request()->income_type;
  592. $search = [];
  593. foreach ($configs as $key => $config) {
  594. if ($config['type'] == $type) {
  595. $search['type'] = $config['class'];
  596. break;
  597. }
  598. }
  599. // $incomeModel = Income::getIncomeInMonth($search)->where('member_id', \YunShop::app()->getMemberId())->get();
  600. $incomeModel = Income::getIncomesList($search)->where('member_id', \YunShop::app()->getMemberId())->paginate(20);
  601. if ($incomeModel) {
  602. return $this->successJson('获取数据成功!', $incomeModel);
  603. }
  604. return $this->errorJson('未检测到数据!');
  605. }
  606. /**
  607. * @return \Illuminate\Http\JsonResponse|string
  608. */
  609. public function getDetail()
  610. {
  611. $data = "";
  612. $id = \YunShop::request()->id;
  613. $detailModel = Income::getDetailById($id);
  614. if ($detailModel) {
  615. if ($detailModel->first()->detail != '') {
  616. $data = $detailModel->first()->detail;
  617. return '{"result":1,"msg":"成功","data":' . $data . '}';
  618. }
  619. return '{"result":1,"msg":"成功","data":""}';
  620. }
  621. return $this->errorJson('未检测到数据!');
  622. }
  623. /**
  624. * @return \Illuminate\Http\JsonResponse
  625. */
  626. public function getSearchType()
  627. {
  628. $configs = \app\backend\modules\income\Income::current()->getItems();
  629. foreach ($configs as $key => $config) {
  630. if ($config['type'] == 'balance') {
  631. continue;
  632. }
  633. $searchType[] = [
  634. 'title' => $config['title'],
  635. 'type' => $config['type']
  636. ];
  637. }
  638. if ($searchType) {
  639. return $this->successJson('获取数据成功!', $searchType);
  640. }
  641. return $this->errorJson('未检测到数据!');
  642. }
  643. /**
  644. * 获取收入提现按钮开关
  645. * @return \Illuminate\Http\JsonResponse
  646. */
  647. public function getIncomeWithdrawMode()
  648. {
  649. $incomeWithdrawMode = (new IncomeService())->withdrawButton(request()->income_type);
  650. if ($incomeWithdrawMode) {
  651. if ($incomeWithdrawMode['manual']) {
  652. $member_id = \YunShop::app()->getMemberId();
  653. $yz_member = MemberShopInfo::uniacid()->select(['alipay','wechat'])->where('member_id', $member_id)->first();
  654. $member_bank = MemberBankCard::uniacid()->select(['member_name','bank_card'])->where('member_id', $member_id)->first();
  655. if ($member_bank->bank_card) {
  656. $member_bank->bank_card = $member_bank->bank_card ? substr_replace($member_bank->bank_card,'******',6,-4): '';
  657. }
  658. $incomeWithdrawMode['manual']['manual_type'] = $this->withdraw_set['manual_type'];
  659. $incomeWithdrawMode['manual']['alipay'] = $yz_member->alipay;
  660. $incomeWithdrawMode['manual']['wechat'] = $yz_member->wechat;
  661. $incomeWithdrawMode['manual']['member_name'] = $member_bank->member_name;
  662. $incomeWithdrawMode['manual']['bank_card'] = $member_bank->bank_card;
  663. }
  664. return $this->successJson('获取数据成功!', $incomeWithdrawMode);
  665. }
  666. return $this->errorJson('未检测到数据!');
  667. }
  668. /**
  669. * @return bool
  670. * 电子合同验证
  671. */
  672. private function shopEsign()
  673. {
  674. if (app('plugins')->isEnabled('shop-esign')) {
  675. $data = ContractService::checkNeedSign();
  676. if ($data) {
  677. return true;
  678. } else {
  679. return false;
  680. }
  681. } else {
  682. return false;
  683. }
  684. }
  685. }