Borrow.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. /**
  3. *
  4. * @author: xaboy<365615158@qq.com>
  5. * @day: 2017/11/11
  6. */
  7. namespace app\admin\controller\money;
  8. use app\admin\controller\AuthController;
  9. use app\models\manage\ManageMoneyProduct;
  10. use app\models\manage\UserManageMoney;
  11. use crmeb\services\FormBuilder;
  12. use crmeb\services\JsonService;
  13. use crmeb\services\UtilService;
  14. use think\facade\Route;
  15. /**
  16. * 用户管理控制器
  17. * Class User
  18. * @package app\admin\controller\user
  19. */
  20. class Borrow extends AuthController
  21. {
  22. /**
  23. * 显示资源列表
  24. *
  25. * @return string|\think\Response
  26. */
  27. public function index()
  28. {
  29. return $this->fetch();
  30. }
  31. /**
  32. * 分组列表
  33. */
  34. public function getList()
  35. {
  36. $where = UtilService::getMore([
  37. ['page', 1],
  38. ['limit', 20],
  39. ]);
  40. JsonService::successlayui(ManageMoneyProduct::getList((int)$where['page'], (int)$where['limit']));
  41. }
  42. /**
  43. * 添加/修改分组页面
  44. * @param int $id
  45. * @return string
  46. */
  47. public function add($id = 0)
  48. {
  49. $money_type = sys_data('money_type');
  50. $money_type_select = [];
  51. foreach ($money_type as $v) {
  52. $money_type_select[] = ['label' => $v['name'], 'value' => $v['code']];
  53. }
  54. $group = ManageMoneyProduct::get($id);
  55. $f = array();
  56. $f[] = FormBuilder::input('name', '产品名称', $group ? $group->name : '')->required();
  57. $f[] = FormBuilder::number('ratio', '年化利率(%)', $group ? $group->ratio : 0)->required()->step(0.01);
  58. $f[] = FormBuilder::number('stand_time', '年化时间(天)', $group ? $group->name : 0)->required();
  59. $f[] = FormBuilder::select('money_type', '币种', $group ? $group->money_type : '')->setOptions($money_type_select)->required();
  60. $f[] = FormBuilder::number('personal_limit', '个人上限', $group ? $group->personal_limit : 0)->required()->step(0.00000001);
  61. $f[] = FormBuilder::number('time', '存期[0为活期]', $group ? $group->time : 0)->required();
  62. $f[] = FormBuilder::select('unit', '存期单位[释放周期]', $group ? (string)$group->unit : '1')->setOptions([['value' => 1, 'label' => '天'], ['value' => 2, 'label' => '月'], ['value' => 3, 'label' => '年']]);
  63. $form = FormBuilder::make_post_form('添加理财产品', $f, Route::buildUrl('save', array('id' => $id)));
  64. $this->assign(compact('form'));
  65. return $this->fetch('public/form-builder');
  66. }
  67. /**
  68. * 添加/修改
  69. * @param int $id
  70. */
  71. public function save($id = 0)
  72. {
  73. $data = UtilService::postMore([
  74. ['name', ''],
  75. ['ratio', 0],
  76. ['stand_time', 0],
  77. ['money_type', ''],
  78. ['personal_limit', 0],
  79. ['time', 0],
  80. ['unit', 1],
  81. ]);
  82. if ($id) {
  83. if (ManageMoneyProduct::where('id', $id)->update($data)) {
  84. JsonService::success('修改成功');
  85. } else {
  86. JsonService::fail('修改失败或者您没有修改什么!');
  87. }
  88. } else {
  89. if ($res = ManageMoneyProduct::create($data)) {
  90. JsonService::success('保存成功', ['id' => $res->id]);
  91. } else {
  92. JsonService::fail('保存失败!');
  93. }
  94. }
  95. }
  96. /**
  97. * 删除
  98. * @param $id
  99. * @throws \Exception
  100. */
  101. public function delete($id)
  102. {
  103. if (!$id) JsonService::fail('数据不存在');
  104. if (!ManageMoneyProduct::be(['id' => $id])) JsonService::fail('数据不存在');
  105. if (!ManageMoneyProduct::where('id', $id)->update(['is_del' => 1]))
  106. JsonService::fail(ManageMoneyProduct::getErrorInfo('删除失败,请稍候再试!'));
  107. else
  108. JsonService::successful('删除成功!');
  109. }
  110. public function user($id)
  111. {
  112. $this->assign('id', $id);
  113. return $this->fetch();
  114. }
  115. public function getUserList($id)
  116. {
  117. $where = UtilService::getMore([
  118. ['page', 1],
  119. ['limit', 20],
  120. ]);
  121. $map['mid'] = $id;
  122. UserManageMoney::daySend();
  123. JsonService::successlayui(UserManageMoney::getList((int)$where['page'], (int)$where['limit'], $map));
  124. }
  125. }