Finance.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. $where = array_merge($where, $this->main_where);
  59. Json::successlayui(StoreBill::getBillList($where));
  60. }
  61. /**
  62. * 添加/修改分组页面
  63. * @param int $id
  64. * @return string
  65. */
  66. public function extract($type = 'alipay')
  67. {
  68. $store_info = SystemStore::where('id', $this->adminInfo['store_id'])->find();
  69. if (!$store_info) $this->failed('门店不存在');
  70. $f = array();
  71. $f[] = Form::number('money', '提现金额', '')->step(0.01)->max($store_info['money'])->min(0)->required();
  72. $f[] = Form::hidden('extract_type', $type);
  73. switch ($type) {
  74. case 'alipay':
  75. $f[] = Form::input('name', '姓名')->required();
  76. $f[] = Form::input('alipay_code', '支付宝账号')->required();
  77. break;
  78. case 'bank':
  79. $f[] = Form::input('name', '姓名')->required();
  80. $f[] = Form::input('bankname', '开户行')->required();
  81. $f[] = Form::input('cardnum', '银行卡号')->required();
  82. break;
  83. case 'weixin':
  84. $f[] = Form::input('name', '姓名')->required();
  85. $f[] = Form::input('weixin', '微信号')->required();
  86. break;
  87. default:
  88. $this->failed('不允许的提现方式');
  89. break;
  90. }
  91. $form = Form::make_post_form('申请提现', $f, Url::buildUrl('saveExtract'));
  92. $this->assign(compact('form'));
  93. return $this->fetch('public/form-builder');
  94. }
  95. /**
  96. * 添加/修改
  97. * @param int $id
  98. */
  99. public function saveExtract()
  100. {
  101. $store_info = SystemStore::where('id', $this->adminInfo['store_id'])->find();
  102. if (!$store_info) Json::fail('门店不存在');
  103. $uid = \app\models\user\User::where('user_store_id', $store_info['id'])->column('uid');
  104. if (!count($uid)) Json::fail('推荐用户不足100人');
  105. $count = \app\models\user\User::where('spread_uid', 'in', $uid)->count();
  106. if ($count < 100) Json::fail('推荐用户不足100人');
  107. $data = UtilService::postMore([
  108. ['alipay_code', ''],
  109. ['extract_type', ''],
  110. ['money', 0],
  111. ['name', ''],
  112. ['bankname', ''],
  113. ['cardnum', ''],
  114. ['weixin', ''],
  115. ]);
  116. if ($data['money'] > $store_info['money']) Json::fail('可提余额不足');
  117. if (!$data['cardnum'] == '')
  118. if (!preg_match('/^([1-9]{1})(\d{14}|\d{18})$/', $data['cardnum']))
  119. Json::fail('银行卡号输入有误');
  120. if (StoreExtract::userExtract($store_info, $data))
  121. Json::success('申请提现成功!');
  122. else
  123. Json::fail(StoreExtract::getErrorInfo('提现失败'));
  124. }
  125. }