1 line
2.6 KiB
PHP
1 line
2.6 KiB
PHP
<?php
|
||
|
||
namespace app\store\controller\food;
|
||
|
||
|
||
use app\store\controller\food\Controller;
|
||
|
||
use app\store\model\food\Shop as ShopModel;
|
||
|
||
use app\store\model\food\User as UserModel;
|
||
|
||
use app\store\model\food\Record as RecordModel;
|
||
|
||
use think\Db;
|
||
use think\facade\View;
|
||
|
||
|
||
/**
|
||
* 用户管理
|
||
*/
|
||
class User extends Controller
|
||
|
||
{
|
||
|
||
|
||
/**
|
||
* 用户列表
|
||
*/
|
||
|
||
public function index($gender = 'all', $search = '')
|
||
|
||
{
|
||
|
||
$model = new ShopModel;
|
||
|
||
$shop = $model->getList(false);
|
||
|
||
$model = new UserModel;
|
||
|
||
$list = $model->getList($gender, $search);
|
||
|
||
return View::fetch('index', compact('list', 'shop', 'gender', 'search'));
|
||
|
||
}
|
||
|
||
/**
|
||
* 用户列表
|
||
* @param string $gender
|
||
* @param string $search
|
||
* @return string
|
||
* @throws \think\db\exception\DbException
|
||
*/
|
||
public function wx_index($gender = 'all', $search = '')
|
||
|
||
{
|
||
$list = \think\facade\Db::name('user_wx')->where([])->field('id,nickname,headimgurl,is_role,create_time')->select()->toArray();
|
||
|
||
foreach ($list as $key => $value) {
|
||
$list[$key]['create_time'] = date('Y-m-d H:i:s');
|
||
$list[$key]['is_role'] = $value['is_role'] == 1 ? '核销员' : '用户';
|
||
}
|
||
|
||
View::assign('list', $list);
|
||
|
||
return View::fetch('wx_index');
|
||
|
||
}
|
||
|
||
|
||
/**
|
||
* 用户充值
|
||
*$recharge 接收表单数据(数组)
|
||
*$source 0为充值余额,1为充值积分
|
||
*/
|
||
|
||
public function recharge()
|
||
|
||
{
|
||
|
||
if ($this->request->isPost()) {
|
||
|
||
$model = new RecordModel;
|
||
|
||
$data = $this->postData('data');
|
||
|
||
if ($this->shop_mode == 10) {
|
||
|
||
$data['shop_id'] = $this->shop_id;
|
||
|
||
}
|
||
|
||
if ($model->add($data)) {
|
||
|
||
return $this->renderSuccess('添加成功', url('food.user/index'));
|
||
|
||
}
|
||
|
||
$error = $model->getError() ?: '添加失败';
|
||
|
||
return $this->renderError($error);
|
||
|
||
}
|
||
|
||
return redirect(url('food.user/index'));
|
||
|
||
}
|
||
|
||
|
||
/**
|
||
* 用户充值
|
||
*$recharge 接收表单数据(数组)
|
||
*$source 0为充值余额,1为充值积分
|
||
*/
|
||
|
||
public function recharge1()
|
||
|
||
{
|
||
|
||
if ($this->request->isPost()) {
|
||
|
||
|
||
$data = $this->request->post();
|
||
|
||
|
||
$info = \think\facade\Db::name('user_wx')->where(['id' => $data['id']])->update(['is_role' => $data['is_role']]);
|
||
|
||
if ($info) {
|
||
|
||
return $this->renderSuccess('成功', url('food.user/wx_index'));
|
||
|
||
}
|
||
|
||
|
||
return $this->renderError('失败');
|
||
|
||
}
|
||
|
||
return redirect(url('food.user/wx_index'));
|
||
|
||
}
|
||
}
|
||
|