Finance.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. namespace app\admin\controller\company;
  3. use app\admin\controller\AuthController;
  4. use crmeb\services\{JsonService, JsonService as Json, UtilService as Util, FormBuilder as Form, UtilService};
  5. use crmeb\traits\CurdControllerTrait;
  6. use think\facade\Route as Url;
  7. use app\admin\model\system\{StoreBill, StoreExtract, SystemAttachment, ShippingTemplates, SystemStore};
  8. /**
  9. * 产品管理
  10. * Class StoreProduct
  11. * @package app\admin\controller\store
  12. */
  13. class Finance extends AuthController
  14. {
  15. use CurdControllerTrait;
  16. protected $store;
  17. protected $main_where = [];
  18. public function initialize()
  19. {
  20. parent::initialize(); // TODO: Change the autogenerated stub
  21. $store_id = $this->adminInfo['store_id'];
  22. $this->store = SystemStore::where('id', $store_id)->find();
  23. if ($this->store && $this->store['is_triple']) {
  24. $this->main_where['store_id'] = $store_id;
  25. }
  26. }
  27. /**
  28. * 显示资金记录
  29. */
  30. public function index()
  31. {
  32. $list = StoreBill::where($this->main_where)
  33. ->field(['title', 'type'])
  34. ->group('type')
  35. ->distinct(true)
  36. ->select()
  37. ->toArray();
  38. if ($this->adminInfo['store_id'] > 0) {
  39. $balance = SystemStore::where('id', $this->adminInfo['store_id'])->value('money');
  40. }
  41. $this->assign('selectList', $list);
  42. $this->assign('balance', $balance ?? 0);
  43. return $this->fetch();
  44. }
  45. /**
  46. * 显示资金记录ajax列表
  47. */
  48. public function billlist()
  49. {
  50. $where = Util::getMore([
  51. ['start_time', ''],
  52. ['end_time', ''],
  53. ['nickname', ''],
  54. ['limit', 20],
  55. ['page', 1],
  56. ['type', ''],
  57. ]);
  58. Json::successlayui(StoreBill::getBillList($where));
  59. }
  60. /**
  61. * 添加/修改分组页面
  62. * @param int $id
  63. * @return string
  64. */
  65. public function extract($type = 'alipay')
  66. {
  67. $store_info = SystemStore::where('id', $this->adminInfo['store_id'])->find();
  68. if (!$store_info) $this->failed('门店不存在');
  69. $f = array();
  70. $f[] = Form::number('money', '提现金额', '')->step(0.01)->max($store_info['money'])->min(0)->required();
  71. $f[] = Form::hidden('extract_type', $type);
  72. switch ($type) {
  73. case 'alipay':
  74. $f[] = Form::input('name', '姓名')->required();
  75. $f[] = Form::input('alipay_code', '支付宝账号')->required();
  76. break;
  77. case 'bank':
  78. $f[] = Form::input('name', '姓名')->required();
  79. $f[] = Form::input('bankname', '开户行')->required();
  80. $f[] = Form::input('cardnum', '银行卡号')->required();
  81. break;
  82. case 'weixin':
  83. $f[] = Form::input('name', '姓名')->required();
  84. $f[] = Form::input('weixin', '微信号')->required();
  85. break;
  86. default:
  87. $this->failed('不允许的提现方式');
  88. break;
  89. }
  90. $form = Form::make_post_form('申请提现', $f, Url::buildUrl('saveExtract'));
  91. $this->assign(compact('form'));
  92. return $this->fetch('public/form-builder');
  93. }
  94. /**
  95. * 添加/修改
  96. * @param int $id
  97. */
  98. public function saveExtract()
  99. {
  100. $store_info = SystemStore::where('id', $this->adminInfo['store_id'])->find();
  101. if (!$store_info) Json::fail('门店不存在');
  102. $data = UtilService::postMore([
  103. ['alipay_code', ''],
  104. ['extract_type', ''],
  105. ['money', 0],
  106. ['name', ''],
  107. ['bankname', ''],
  108. ['cardnum', ''],
  109. ['weixin', ''],
  110. ]);
  111. if ($data['money'] > $store_info['money']) Json::fail('可提余额不足');
  112. if (!$data['cardnum'] == '')
  113. if (!preg_match('/^([1-9]{1})(\d{14}|\d{18})$/', $data['cardnum']))
  114. Json::fail('银行卡号输入有误');
  115. if (StoreExtract::userExtract($store_info, $data))
  116. Json::success('申请提现成功!');
  117. else
  118. Json::fail(StoreExtract::getErrorInfo('提现失败'));
  119. }
  120. }