SupplierExtract.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\supplier\finance;
  12. use app\services\supplier\finance\SupplierFlowingWaterServices;
  13. use think\exception\ValidateException;
  14. use think\facade\App;
  15. use think\facade\Config;
  16. use app\controller\supplier\AuthController;
  17. use app\services\supplier\finance\SupplierExtractServices;
  18. /**
  19. * 供应商提现
  20. * Class SupplierExtract
  21. * @package app\controller\supplier\finance
  22. */
  23. class SupplierExtract extends AuthController
  24. {
  25. /**
  26. * StoreExtract constructor.
  27. * @param App $app
  28. * @param SupplierExtractServices $services
  29. */
  30. public function __construct(App $app, SupplierExtractServices $services)
  31. {
  32. parent::__construct($app);
  33. $this->services = $services;
  34. }
  35. /**
  36. * 显示资源列表
  37. * @return mixed
  38. * @throws \think\db\exception\DataNotFoundException
  39. * @throws \think\db\exception\DbException
  40. * @throws \think\db\exception\ModelNotFoundException
  41. */
  42. public function index()
  43. {
  44. $where = $this->request->getMore([
  45. ['status', ''],
  46. ['pay_status', ''],
  47. ['extract_type', ''],
  48. ['nireid', '', '', 'like'],
  49. ['data', '', '', 'time'],
  50. ]);
  51. if (isset($where['extract_type']) && $where['extract_type'] == 'wx') {
  52. $where['extract_type'] = 'weixin';
  53. }
  54. $where['supplier_id'] = $this->supplierId;
  55. $whereData = [
  56. 'supplier_id' => $this->supplierId,
  57. 'is_del' => 0,
  58. ];
  59. return app('json')->success($this->services->index($where,$whereData));
  60. }
  61. /**
  62. * 增加备注
  63. * @param $id
  64. * @return mixed
  65. */
  66. public function mark($id)
  67. {
  68. [$mark] = $this->request->getMore([
  69. ['mark', '']
  70. ], true);
  71. if (!$id || !$mark) {
  72. return app('json')->fail('缺少参数');
  73. }
  74. $extract = $this->services->get((int)$id);
  75. if (!$extract) {
  76. return app('json')->fail('转账记录不存在');
  77. }
  78. if (!$this->services->update($id, ['supplier_mark' => $mark])) {
  79. return app('json')->fail('备注失败');
  80. }
  81. return app('json')->success('备注成功');
  82. }
  83. /**
  84. * 提现申请
  85. * @param Request $request
  86. * @return mixed
  87. */
  88. public function cash()
  89. {
  90. $extractInfo = $this->request->postMore([
  91. ['extract_type', ''],
  92. ['money', 0],
  93. ['mark', '']
  94. ]);
  95. $extractType = Config::get('pay.extractType', []);
  96. //最低提现
  97. $supplier_extract_min_price = sys_config('supplier_extract_min_price') ?? 0;
  98. //最高提现
  99. $supplier_extract_max_price = sys_config('supplier_extract_max_price') ?? 0;
  100. if ($extractInfo['money'] < $supplier_extract_min_price)
  101. return app('json')->fail('最低提现' . $supplier_extract_min_price . '元');
  102. if ($extractInfo['money'] > $supplier_extract_max_price)
  103. return app('json')->fail('最高提现' . $supplier_extract_max_price . '元');
  104. //可提现金额
  105. /** @var SupplierFlowingWaterServices $financeFlowServices */
  106. $financeFlowServices = app()->make(SupplierFlowingWaterServices::class);
  107. $whereData = [
  108. 'supplier_id' => $this->supplierId,
  109. 'is_del' => 0,
  110. ];
  111. $price_not = $financeFlowServices->getSumFinance(['supplier_id' => $this->supplierId], $whereData);
  112. if ($extractInfo['money'] > $price_not) {
  113. throw new ValidateException($price_not > 0 ? '可提现金额为' . $price_not . '元': '暂无可提现金额');
  114. }
  115. if (!in_array($extractInfo['extract_type'], $extractType))
  116. return app('json')->fail('转账方式不存在');
  117. if (!preg_match('/^[0-9]+(.[0-9]{1,2})?$/', (float)$extractInfo['money'])) return app('json')->fail('转账金额输入有误');
  118. if ($this->services->cash((int)$this->supplierId, $extractInfo))
  119. return app('json')->successful('申请转账成功!');
  120. else
  121. return app('json')->fail('转账失败');
  122. }
  123. }