| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- <?php
- namespace app\admin\controller;
- use app\admin\logic\PaymentLogic;
- use app\admin\logic\ShopGoodsLogic;
- use app\admin\logic\UserLogic;
- use app\admin\logic\WithdrawLogic;
- use app\common\model\SystemAdmin;
- use app\common\model\SystemQuick;
- use app\common\controller\AdminController;
- use think\App;
- use think\facade\Env;
- class Index extends AdminController
- {
- /**
- * 后台主页
- * @return string
- * @throws \Exception
- */
- public function index()
- {
- return $this->fetch('', [
- 'admin' => session('admin'),
- ]);
- }
- /**
- * 后台欢迎页
- * @return string
- * @throws \Exception
- */
- public function welcome()
- {
- $rechargeTotal = PaymentLogic::getTotal([4,5]);
- $rechargeTotal = $rechargeTotal>100000? round($rechargeTotal/10000, 2).'万' : $rechargeTotal;
- $withdrawTotal = WithdrawLogic::getTotal(0);
- $withdrawTotal = $withdrawTotal>100000? round($withdrawTotal/10000, 2).'万' : $withdrawTotal;
- $counts = [
- 'user_count'=> UserLogic::getCountByTime(0),
- 'goods_count'=> ShopGoodsLogic::getCount(),
- 'recharge_total'=> $rechargeTotal,
- 'withdraw_total'=> $withdrawTotal,
- ];
- $quicks = SystemQuick::field('id,title,icon,href')
- ->where(['status' => 1])
- ->order('sort')
- ->limit(8)
- ->select();
- $this->assign('quicks', $quicks);
- $this->assign('counts', $counts);
- return $this->fetch();
- }
- /**
- * 修改管理员信息
- * @return string
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function editAdmin()
- {
- $id = session('admin.id');
- $row = (new SystemAdmin())
- ->withoutField('password')
- ->find($id);
- empty($row) && $this->error('用户信息不存在');
- if ($this->request->isPost()) {
- $post = $this->request->post();
- $this->isDemo && $this->error('演示环境下不允许修改');
- $rule = [];
- $this->validate($post, $rule);
- try {
- $save = $row
- ->allowField(['head_img', 'phone', 'remark', 'update_time'])
- ->save($post);
- } catch (\Exception $e) {
- $this->error('保存失败');
- }
- $save ? $this->success('保存成功') : $this->error('保存失败');
- }
- $this->assign('row', $row);
- return $this->fetch();
- }
- /**
- * 修改密码
- * @return string
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function editPassword()
- {
- $id = session('admin.id');
- $row = (new SystemAdmin())
- ->withoutField('password')
- ->find($id);
- if (!$row) {
- $this->error('用户信息不存在');
- }
- if ($this->request->isPost()) {
- $post = $this->request->post();
- $this->isDemo && $this->error('演示环境下不允许修改');
- $rule = [
- 'password|登录密码' => 'require',
- 'password_again|确认密码' => 'require',
- ];
- $this->validate($post, $rule);
- if ($post['password'] != $post['password_again']) {
- $this->error('两次密码输入不一致');
- }
- try {
- $save = $row->save([
- 'password' => password($post['password']),
- ]);
- } catch (\Exception $e) {
- $this->error('保存失败');
- }
- if ($save) {
- $this->success('保存成功');
- } else {
- $this->error('保存失败');
- }
- }
- $this->assign('row', $row);
- return $this->fetch();
- }
- }
|