StoreExtract.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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\store\finance;
  12. use app\services\store\finance\StoreFinanceFlowServices;
  13. use think\exception\ValidateException;
  14. use think\facade\App;
  15. use think\facade\Config;
  16. use app\controller\store\AuthController;
  17. use app\services\store\finance\StoreExtractServices;
  18. /**
  19. * 门店提现
  20. * Class StoreExtract
  21. * @package app\controller\store\finance
  22. */
  23. class StoreExtract extends AuthController
  24. {
  25. /**
  26. * StoreExtract constructor.
  27. * @param App $app
  28. * @param StoreExtractServices $services
  29. */
  30. public function __construct(App $app, StoreExtractServices $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['store_id'] = $this->storeId;
  55. $whereData = [
  56. 'store_id' => $this->storeId,
  57. 'is_del' => 0,
  58. 'trade_type'=>1,
  59. 'no_type'=>1
  60. ];
  61. return app('json')->success($this->services->index($where,$whereData));
  62. }
  63. /**
  64. * 增加备注
  65. * @param $id
  66. * @return mixed
  67. */
  68. public function mark($id)
  69. {
  70. [$mark] = $this->request->getMore([
  71. ['mark', '']
  72. ], true);
  73. if (!$id || !$mark) {
  74. return app('json')->fail('缺少参数');
  75. }
  76. $storeExtract = $this->services->get((int)$id);
  77. if (!$storeExtract) {
  78. return app('json')->fail('转账记录不存在');
  79. }
  80. if (!$this->services->update($id, ['store_mark' => $mark])) {
  81. return app('json')->fail('备注失败');
  82. }
  83. return app('json')->success('备注成功');
  84. }
  85. /**
  86. * 提现申请
  87. * @param Request $request
  88. * @return mixed
  89. */
  90. public function cash()
  91. {
  92. $extractInfo = $this->request->postMore([
  93. ['extract_type', ''],
  94. ['money', 0],
  95. ['mark', '']
  96. ]);
  97. $extractType = Config::get('pay.extractType', []);
  98. //最低提现
  99. $store_extract_min_price = sys_config('store_extract_min_price') ?? 0;
  100. //最高提现
  101. $store_extract_max_price = sys_config('store_extract_max_price') ?? 0;
  102. if ($extractInfo['money'] < $store_extract_min_price)
  103. return app('json')->fail('最低提现' . $store_extract_min_price . '元');
  104. if ($extractInfo['money'] > $store_extract_max_price)
  105. return app('json')->fail('最高提现' . $store_extract_max_price . '元');
  106. //可提现金额
  107. /** @var StoreFinanceFlowServices $storeFinanceFlowServices */
  108. $storeFinanceFlowServices = app()->make(StoreFinanceFlowServices::class);
  109. $whereData = [
  110. 'store_id' => $this->storeId,
  111. 'is_del' => 0,
  112. 'trade_type' => 1,
  113. 'no_type' => 1
  114. ];
  115. $price_not = $storeFinanceFlowServices->getSumFinance(['store_id' => $this->storeId], $whereData);
  116. if ($extractInfo['money'] > $price_not) {
  117. throw new ValidateException($price_not > 0 ? '可提现金额为' . $price_not . '元': '暂无可提现金额');
  118. }
  119. if (!in_array($extractInfo['extract_type'], $extractType))
  120. return app('json')->fail('转账方式不存在');
  121. if (!preg_match('/^[0-9]+(.[0-9]{1,2})?$/', (float)$extractInfo['money'])) return app('json')->fail('转账金额输入有误');
  122. if ($this->services->cash((int)$this->storeId, $this->storeStaffId, $extractInfo))
  123. return app('json')->successful('申请转账成功!');
  124. else
  125. return app('json')->fail('转账失败');
  126. }
  127. }