* @day: 2017/11/11 */ namespace app\admin\controller\money; use app\admin\controller\AuthController; use app\models\manage\ManageMoneyProduct; use app\models\manage\UserManageMoney; use crmeb\services\FormBuilder; use crmeb\services\JsonService; use crmeb\services\UtilService; use think\facade\Route; /** * 用户管理控制器 * Class User * @package app\admin\controller\user */ class Manage extends AuthController { /** * 显示资源列表 * * @return string|\think\Response */ public function index() { return $this->fetch(); } /** * 分组列表 */ public function getList() { $where = UtilService::getMore([ ['page', 1], ['limit', 20], ]); JsonService::successlayui(ManageMoneyProduct::getList((int)$where['page'], (int)$where['limit'])); } /** * 添加/修改分组页面 * @param int $id * @return string */ public function add($id = 0) { $money_type = sys_data('money_type'); $money_type_select = []; foreach ($money_type as $v) { $money_type_select[] = ['label' => $v['name'], 'value' => $v['code']]; } $group = ManageMoneyProduct::get($id); $f = array(); $f[] = FormBuilder::input('name', '产品名称', $group ? $group->name : '')->required(); $f[] = FormBuilder::number('ratio', '年化利率(%)', $group ? $group->ratio : 0)->required()->step(0.01); $f[] = FormBuilder::number('stand_time', '年化时间(天)', $group ? $group->name : 0)->required(); $f[] = FormBuilder::select('money_type', '币种', $group ? $group->money_type : '')->setOptions($money_type_select)->required(); $f[] = FormBuilder::number('personal_limit', '个人上限', $group ? $group->personal_limit : 0)->required()->step(0.00000001); $f[] = FormBuilder::number('time', '存期[0为活期]', $group ? $group->time : 0)->required(); $f[] = FormBuilder::select('unit', '存期单位[释放周期]', $group ? (string)$group->unit : '1')->setOptions([['value' => 1, 'label' => '天'], ['value' => 2, 'label' => '月'], ['value' => 3, 'label' => '年']]); $form = FormBuilder::make_post_form('添加理财产品', $f, Route::buildUrl('save', array('id' => $id))); $this->assign(compact('form')); return $this->fetch('public/form-builder'); } /** * 添加/修改 * @param int $id */ public function save($id = 0) { $data = UtilService::postMore([ ['name', ''], ['ratio', 0], ['stand_time', 0], ['money_type', ''], ['personal_limit', 0], ['time', 0], ['unit', 1], ]); if ($id) { if (ManageMoneyProduct::where('id', $id)->update($data)) { JsonService::success('修改成功'); } else { JsonService::fail('修改失败或者您没有修改什么!'); } } else { if ($res = ManageMoneyProduct::create($data)) { JsonService::success('保存成功', ['id' => $res->id]); } else { JsonService::fail('保存失败!'); } } } /** * 删除 * @param $id * @throws \Exception */ public function delete($id) { if (!$id) JsonService::fail('数据不存在'); if (!ManageMoneyProduct::be(['id' => $id])) JsonService::fail('数据不存在'); if (!ManageMoneyProduct::where('id', $id)->update(['is_del' => 1])) JsonService::fail(ManageMoneyProduct::getErrorInfo('删除失败,请稍候再试!')); else JsonService::successful('删除成功!'); } public function user($id) { $this->assign('id', $id); return $this->fetch(); } public function getUserList($id) { $where = UtilService::getMore([ ['page', 1], ['limit', 20], ]); $map['mid'] = $id; UserManageMoney::daySend(); JsonService::successlayui(UserManageMoney::getList((int)$where['page'], (int)$where['limit'], $map)); } }