后台和接口

This commit is contained in:
qinzexin 2025-05-27 18:33:00 +08:00
parent 624b4dd553
commit 11fd07693f
35 changed files with 8064 additions and 72 deletions

View File

@ -17,11 +17,14 @@ class Employee extends Backend
* @var \app\admin\model\score\Employee
*/
protected $model = null;
protected $qSwitch = true;
protected $qFields = ["team_id","user_id"];
public function _initialize()
{
parent::_initialize();
$this->model = new \app\admin\model\score\Employee;
parent::_initialize();
$this->view->assign("statusList", $this->model->getStatusList());
}
@ -48,8 +51,16 @@ class Employee extends Backend
if ($this->request->request('keyField')) {
return $this->selectpage();
}
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
list($where, $sort, $order, $offset, $limit, $page, $alias, $bind,$excludearray) = $this->buildparams(null,null,['opertime']);
//得到查询时间
$opertime = $excludearray['opertime'] ?? [];
$start_time = $end_time =null;
if($opertime){
//得到查询值
$value = $opertime['value'];
list($start_time,$end_time) = explode(" - ",$value);
}
$list = $this->model
->with(['user','team'])
->where($where)
@ -62,9 +73,23 @@ class Employee extends Backend
$row->getRelation('team')->visible(['name']);
}
$result = array("total" => $list->total(), "rows" => $list->items());
$total = $list->total();
$list = $list->items();
foreach ($list as &$row) {
$row['score_count'] = 0;
$row['opertime'] = '';
if($start_time){
$row['opertime'] = $start_time.'至'.$end_time;
}
$row['score_count'] = \app\common\model\score\Employee::getPriceByCoachAndTime($row['id'],$start_time,$end_time);
}
$result = array("total" => $total, "rows" => $list);
return json($result);
}
return $this->view->fetch();
}

View File

@ -3,6 +3,12 @@
namespace app\admin\controller\score;
use app\common\controller\Backend;
use think\Db;
use think\db\exception\DataNotFoundException;
use think\db\exception\ModelNotFoundException;
use think\exception\DbException;
use think\exception\PDOException;
use think\exception\ValidateException;
/**
* 积分记录管理
@ -18,11 +24,15 @@ class Log extends Backend
*/
protected $model = null;
protected $qSwitch = true;
protected $qFields = ["team_id","user_id"];
public function _initialize()
{
parent::_initialize();
$this->model = new \app\admin\model\score\Log;
parent::_initialize();
$this->view->assign("statusList", $this->model->getStatusList());
}
@ -71,4 +81,209 @@ class Log extends Backend
return $this->view->fetch();
}
/**
* 添加
*
* @return string
* @throws \think\Exception
*/
public function add()
{
if (false === $this->request->isPost()) {
return $this->view->fetch();
}
$params = $this->request->post('row/a');
if (empty($params)) {
$this->error(__('Parameter %s can not be empty', ''));
}
$params = $this->preExcludeFields($params);
if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
$params[$this->dataLimitField] = $this->auth->id;
}
try {
$result = (new \app\common\model\score\Log)->add($params ,false, true);
}catch (\Exception $e){
$this->error($e->getMessage());
}
if ($result === false) {
$this->error(__('No rows were inserted'));
}
$this->success();
}
/**
* 编辑
*
* @param $ids
* @return string
* @throws DbException
* @throws \think\Exception
*/
public function edit($ids = null)
{
$row = $this->model->get($ids);
if (!$row) {
$this->error(__('No Results were found'));
}
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
$this->error(__('You have no permission'));
}
if (false === $this->request->isPost()) {
$this->view->assign('row', $row);
return $this->view->fetch();
}
$params = $this->request->post('row/a');
if (empty($params)) {
$this->error(__('Parameter %s can not be empty', ''));
}
$params = $this->preExcludeFields($params);
$result = false;
Db::startTrans();
try {
//是否采用模型验证
if ($this->modelValidate) {
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
$row->validateFailException()->validate($validate);
}
//如果审核失败,需要填写原因
if ($params["status"] == 2) {
if (!$params['reason']) {
$this->error('审核失败,请填写原因');
}
}
if($row["status"] != $params["status"]){
$params['authtime'] = time();
}
$result = $row->allowField(true)->save($params);
Db::commit();
} catch (ValidateException|PDOException|Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if (false === $result) {
$this->error(__('No rows were updated'));
}
$this->success();
}
/**
* 审核成功
*
* @param $ids
* @return void
* @throws DbException
* @throws DataNotFoundException
* @throws ModelNotFoundException
*/
public function auth_yes($ids = null)
{
if (false === $this->request->isPost()) {
$this->error(__("Invalid parameters"));
}
$ids = $ids ?: $this->request->post("ids");
if (empty($ids)) {
$this->error(__('Parameter %s can not be empty', 'ids'));
}
$pk = $this->model->getPk();
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds)) {
$this->model->where($this->dataLimitField, 'in', $adminIds);
}
$list = $this->model->where($pk, 'in', $ids)->select();
$count = 0;
Db::startTrans();
try {
foreach ($list as $item) {
// $count += $item->delete();
if($item["status"]!= 1){
$item["status"] = 1;
$item["authtime"] = time();
$item["reason"] = "";
$item->save();
$count++;
}
}
Db::commit();
} catch (PDOException|Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($count) {
$this->success("操作成功{$count}条记录");
}
$this->error(__('操作成功0条记录'));
}
/**
* 审核失败
*
* @param $ids
* @return void
* @throws DbException
* @throws DataNotFoundException
* @throws ModelNotFoundException
*/
public function auth_no($ids = null)
{
if (false === $this->request->isPost()) {
$this->error(__("Invalid parameters"));
}
$ids = $ids ?: $this->request->post("ids");
if (empty($ids)) {
$this->error(__('Parameter %s can not be empty', 'ids'));
}
$pk = $this->model->getPk();
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds)) {
$this->model->where($this->dataLimitField, 'in', $adminIds);
}
$list = $this->model->where($pk, 'in', $ids)->select();
$count = 0;
Db::startTrans();
try {
foreach ($list as $item) {
// $count += $item->delete();
if($item["status"]!= 2){
$item["status"] = 2;
$item["authtime"] = time();
$item["reason"] = "批量操作拒绝";
$item->save();
$count++;
}
}
Db::commit();
} catch (PDOException|Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($count) {
$this->success("操作成功{$count}条记录");
}
$this->error(__('操作成功0条记录'));
}
}

View File

@ -3,6 +3,12 @@
namespace app\admin\controller\score;
use app\common\controller\Backend;
use think\Db;
use think\exception\DbException;
use think\exception\PDOException;
use think\exception\ValidateException;
use app\common\model\score\Employee;
use think\response\Json;
/**
* 队伍管理
@ -34,4 +40,165 @@ class Team extends Backend
*/
/**
* 查看
*
* @return string|Json
* @throws \think\Exception
* @throws DbException
*/
public function index()
{
//设置过滤方法
$this->request->filter(['strip_tags', 'trim']);
if (false === $this->request->isAjax()) {
return $this->view->fetch();
}
//如果发送的来源是 Selectpage则转发到 Selectpage
if ($this->request->request('keyField')) {
return $this->selectpage();
}
list($where, $sort, $order, $offset, $limit, $page, $alias, $bind,$excludearray) = $this->buildparams(null,null,['opertime']);
//得到查询时间
$opertime = $excludearray['opertime'] ?? [];
$start_time = $end_time =null;
if($opertime){
//得到查询值
$value = $opertime['value'];
list($start_time,$end_time) = explode(" - ",$value);
}
$list = $this->model
->where($where)
->order($sort, $order)
->paginate($limit);
$total = $list->total();
$list = $list->items();
foreach ($list as &$row) {
$row['score_count'] = 0;
$row['opertime'] = '';
if($start_time){
$row['opertime'] = $start_time.'至'.$end_time;
}
$row['score_count'] = \app\common\model\score\Team::getPriceByCoachAndTime($row['id'],$start_time,$end_time);
}
$result = array("total" => $total, "rows" => $list);
return json($result);
}
/**
* 添加
*
* @return string
* @throws \think\Exception
*/
public function add()
{
if (false === $this->request->isPost()) {
return $this->view->fetch();
}
$params = $this->request->post('row/a');
if (empty($params)) {
$this->error(__('Parameter %s can not be empty', ''));
}
$params = $this->preExcludeFields($params);
if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
$params[$this->dataLimitField] = $this->auth->id;
}
$result = false;
Db::startTrans();
try {
//是否采用模型验证
if ($this->modelValidate) {
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
$this->model->validateFailException()->validate($validate);
}
$score_employee_ids = $params["score_employee_ids"] ?? [];
$result = $this->model->allowField(true)->save($params);
//建立新的关联
Employee::where( "id","in",$score_employee_ids)->update(["team_id"=>$this->model->id]);
Db::commit();
} catch (ValidateException|PDOException|Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($result === false) {
$this->error(__('No rows were inserted'));
}
$this->success();
}
/**
* 编辑
*
* @param $ids
* @return string
* @throws DbException
* @throws \think\Exception
*/
public function edit($ids = null)
{
$row = $this->model->get($ids);
if (!$row) {
$this->error(__('No Results were found'));
}
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
$this->error(__('You have no permission'));
}
if (false === $this->request->isPost()) {
$this->view->assign('row', $row);
return $this->view->fetch();
}
$params = $this->request->post('row/a');
if (empty($params)) {
$this->error(__('Parameter %s can not be empty', ''));
}
$params = $this->preExcludeFields($params);
$result = false;
Db::startTrans();
try {
//是否采用模型验证
if ($this->modelValidate) {
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
$row->validateFailException()->validate($validate);
}
$score_employee_ids = $params["score_employee_ids"] ?? [];
$result = $row->allowField(true)->save($params);
//清除旧的关联
Employee::where( "team_id",$row->id)->update(["team_id"=>0]);
//建立新的关联
Employee::where( "id","in",$score_employee_ids)->update(["team_id"=>$row->id]);
Db::commit();
} catch (ValidateException|PDOException|Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if (false === $result) {
$this->error(__('No rows were updated'));
}
$this->success();
}
}

View File

@ -4,6 +4,8 @@ namespace app\admin\controller\user;
use app\common\controller\Backend;
use app\common\library\Auth;
use fast\Tree;
use think\Model;
/**
* 会员管理
@ -102,4 +104,185 @@ class User extends Backend
$this->success();
}
/**
* Selectpage的实现方法
*
* 当前方法只是一个比较通用的搜索匹配,请按需重载此方法来编写自己的搜索逻辑,$where按自己的需求写即可
* 这里示例了所有的参数,所以比较复杂,实现上自己实现只需简单的几行即可
*
*/
protected function selectpage()
{
//设置过滤方法
$this->request->filter(['trim', 'strip_tags', 'htmlspecialchars']);
//搜索关键词,客户端输入以空格分开,这里接收为数组
$word = (array)$this->request->request("q_word/a");
//当前页
$page = $this->request->request("pageNumber");
//分页大小
$pagesize = $this->request->request("pageSize");
//搜索条件
$andor = $this->request->request("andOr", "and", "strtoupper");
//排序方式
$orderby = (array)$this->request->request("orderBy/a");
//显示的字段
$field = $this->request->request("showField");
//主键
$primarykey = $this->request->request("keyField");
//主键值
$primaryvalue = $this->request->request("keyValue");
//搜索字段
// $searchfield = (array)$this->request->request("searchField/a");
$searchfield = [
'id','realname','nickname','mobile'
];
//自定义搜索条件
$custom = (array)$this->request->request("custom/a");
//是否返回树形结构
$istree = $this->request->request("isTree", 0);
$ishtml = $this->request->request("isHtml", 0);
if ($istree) {
$word = [];
$pagesize = 999999;
}
$order = [];
foreach ($orderby as $k => $v) {
$order[$v[0]] = $v[1];
}
$field = $field ? $field : 'name';
//如果有primaryvalue,说明当前是初始化传值
if ($primaryvalue !== null) {
$where = [$primarykey => ['in', $primaryvalue]];
$pagesize = 999999;
} else {
$where = function ($query) use ($word, $andor, $field, $searchfield, $custom) {
$logic = $andor == 'AND' ? '&' : '|';
$searchfield = is_array($searchfield) ? implode($logic, $searchfield) : $searchfield;
$searchfield = str_replace(',', $logic, $searchfield);
$word = array_filter(array_unique($word));
if (count($word) == 1) {
$query->where($searchfield, "like", "%" . reset($word) . "%");
} else {
$query->where(function ($query) use ($word, $searchfield) {
foreach ($word as $index => $item) {
$query->whereOr(function ($query) use ($item, $searchfield) {
$query->where($searchfield, "like", "%{$item}%");
});
}
});
}
if ($custom && is_array($custom)) {
foreach ($custom as $k => $v) {
if (is_array($v) && 2 == count($v)) {
$query->where($k, trim($v[0]), $v[1]);
} else {
$query->where($k, '=', $v);
}
}
}
};
}
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds)) {
$this->model->where($this->dataLimitField, 'in', $adminIds);
}
$list = [];
$total = $this->model->where($where)->count();
if ($total > 0) {
if (is_array($adminIds)) {
$this->model->where($this->dataLimitField, 'in', $adminIds);
}
$fields = is_array($this->selectpageFields) ? $this->selectpageFields : ($this->selectpageFields && $this->selectpageFields != '*' ? explode(',', $this->selectpageFields) : []);
//如果有primaryvalue,说明当前是初始化传值,按照选择顺序排序
if ($primaryvalue !== null && preg_match("/^[a-z0-9_\-]+$/i", $primarykey)) {
$primaryvalue = array_unique(is_array($primaryvalue) ? $primaryvalue : explode(',', $primaryvalue));
//修复自定义data-primary-key为字符串内容时给排序字段添加上引号
$primaryvalue = array_map(function ($value) {
return '\'' . $value . '\'';
}, $primaryvalue);
$primaryvalue = implode(',', $primaryvalue);
$this->model->orderRaw("FIELD(`{$primarykey}`, {$primaryvalue})");
} else {
$this->model->order($order);
}
$datalist = $this->model->where($where)
->page($page, $pagesize)
->select();
foreach ($datalist as $index => $item) {
unset($item['password'], $item['salt']);
if ($this->selectpageFields == '*') {
$result = [
$primarykey => $item[$primarykey] ?? '',
$field => $item[$field] ?? '',
'nickname' => isset($item['nickname']) ? $item['nickname'] : '',
'mobile' => isset($item['mobile']) ? $item['mobile'] : '',
'realname' => isset($item['realname']) ? $item['realname'] : '',
];
} else {
$result = array_intersect_key(($item instanceof Model ? $item->toArray() : (array)$item), array_flip($fields));
}
$result['pid'] = isset($item['pid']) ? $item['pid'] : (isset($item['parent_id']) ? $item['parent_id'] : 0);
$list[] = $result;
}
if ($istree && !$primaryvalue) {
$tree = Tree::instance();
$tree->init(collection($list)->toArray(), 'pid');
$list = $tree->getTreeList($tree->getTreeArray(0), $field);
if (!$ishtml) {
foreach ($list as &$item) {
$item = str_replace(' ', ' ', $item);
}
unset($item);
}
}
}
//这里一定要返回有list这个字段,total是可选的,如果total<=list的数量,则会隐藏分页按钮
return json(['list' => $list, 'total' => $total]);
}
/**变更学员信息(教练专属)
* @return string
* @throws \think\Exception
* @throws \think\exception\DbException
*/
public function changeuser(){
if($this->request->isPost())
{
try{
$people_name = $this->request->param('people_name/s');
$people_mobile = $this->request->param('people_mobile/s');
$password = $this->request->param('password/s');
if (!$password) throw new \Exception("请设置登录密码!");
$user = \app\common\model\User::where("mobile",$people_mobile)->find();
//检测更新教练下单学员账号创建状态 2022/8/27 new
if(!$user)$user = (new \app\common\model\User)->addUserByMobile($people_mobile,$people_name,$password);
$user['nickname'] = $people_name;
$user->save();
}catch (\Exception $e){
$this->error($e->getMessage());
}
//退押金
$this->success("已成功创建{$people_name}");
}
// $row = $this->model->get($param['ids']);
// $this->view->assign('vo', $row);
return $this->view->fetch();
}
}

View File

@ -3,6 +3,7 @@
return [
'User_id' => '前端登錄用戶',
'Name' => '姓名',
'Image' => '员工头像',
'Team_id' => '队伍id',
'Status' => '状态',
'Status entry' => '入职',

View File

@ -27,8 +27,8 @@ return [
'Frequency day' => '天',
'Frequency week' => '周',
'Frequency once' => '次',
'Max_times' => '最高次数(0为不限制)',
'Monthly_highest_score' => '月度最高分(0为不限制)',
'Max_times' => '当前频率最高次数(0为不限制)',
'Monthly_highest_score' => '当前频率最高分(0为不限制)',
'Way' => '得分方式(多选)',
'Way free' => '自由申请',
'Way direct' => '直接奖励',

View File

@ -9,6 +9,15 @@ return [
'Score' => '分值',
'Images' => '多图',
'Desc' => '备注',
'Status' => '审核状态',
'Status 0' => '待审核',
'Set status to 0' => '设为待审核',
'Status 1' => '审核通过',
'Set status to 1' => '设为审核通过',
'Status 2' => '审核不通过',
'Set status to 2' => '设为审核不通过',
'Reason' => '审核不通过原因',
'Authtime' => '审核时间',
'Createtime' => '创建时间',
'Updatetime' => '更新时间',
'Deletetime' => '删除时间',

View File

@ -2,6 +2,8 @@
return [
'Name' => '队伍名',
'Image' => '队伍头像',
'Score_employee_ids' => '队伍成员',
'Createtime' => '创建时间',
'Updatetime' => '更新时间'
];

View File

@ -25,16 +25,36 @@ class Log extends Model
// 追加属性
protected $append = [
'status_text',
'authtime_text'
];
public function getStatusList()
{
return ['0' => __('Status 0'), '1' => __('Status 1'), '2' => __('Status 2')];
}
public function getStatusTextAttr($value, $data)
{
$value = $value ?: ($data['status'] ?? '');
$list = $this->getStatusList();
return $list[$value] ?? '';
}
public function getAuthtimeTextAttr($value, $data)
{
$value = $value ?: ($data['authtime'] ?? '');
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
}
protected function setAuthtimeAttr($value)
{
return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
}
public function scoreevent()

View File

@ -25,10 +25,41 @@ class Team extends Model
// 追加属性
protected $append = [
"score_employee_ids",
"people_num",
"people_names"
];
public function getPeopleNumAttr($value, $data)
{
$value = $value ?: ($data['id'] ?? '');
if(!$value) return 0;
$score_employee_ids = Employee::where( "team_id", $value)->count();
return $score_employee_ids;
}
public function getPeopleNamesAttr($value, $data)
{
$value = $value ?: ($data['id'] ?? '');
if(!$value) return "";
$score_employee_ids = Employee::where( "team_id", $value)->column( "name");
return implode(",", $score_employee_ids);
}
public function getScoreEmployeeIdsAttr($value, $data)
{
$value = $value ?: ($data['id'] ?? '');
if(!$value) return "";
$score_employee_ids = Employee::where( "team_id", $value)->column( "id");
return implode(",", $score_employee_ids);
}

View File

@ -3,21 +3,46 @@
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('User_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-user_id" data-rule="required" data-source="user/user/index" data-field="nickname" class="form-control selectpage" name="row[user_id]" type="text" value="">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Name')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-name" data-rule="required" class="form-control" name="row[name]" type="text">
<input id="c-user_id" data-rule="required" data-source="user/user/index" data-field="mobile" data-format-item="{id} - {nickname} - {mobile}" class="form-control selectpage" name="row[user_id]" type="text" value="{$q_user_id}">
<span style="color: red">
(没找到用户则点击按钮创建用户后重新下拉框选用户)
<a data-url="user/user/changeuser" href="javascript:;" class="btn btn-success btn-changeuser {:$auth->check('user/user/changeuser')?'':'hide'}" title="根据手机号生成用户" ><i class="fa fa-plus"></i> 根据手机号生成用户</a>
</span>
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Team_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-team_id" data-rule="required" data-source="score/team/index" class="form-control selectpage" name="row[team_id]" type="text" value="">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Name')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-name" data-rule="required" class="form-control" name="row[name]" type="text">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Image')}:</label>
<div class="col-xs-12 col-sm-8">
<div class="input-group">
<input id="c-image" data-rule="required" class="form-control" size="50" name="row[image]" type="text" value="" >
<div class="input-group-addon no-border no-padding">
<span><button type="button" id="faupload-image" class="btn btn-danger faupload" data-input-id="c-image" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/bmp,image/webp" data-multiple="false" data-preview-id="p-image"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
<span><button type="button" id="fachoose-image" class="btn btn-primary fachoose" data-input-id="c-image" data-mimetype="image/*" data-multiple="false"><i class="fa fa-list"></i> {:__('Choose')}</button></span>
</div>
<span class="msg-box n-right" for="c-image"></span>
</div>
<ul class="row list-inline faupload-preview" id="p-image"></ul>
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Status')}:</label>
<div class="col-xs-12 col-sm-8">

View File

@ -3,21 +3,47 @@
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('User_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-user_id" data-rule="required" data-source="user/user/index" data-field="nickname" class="form-control selectpage" name="row[user_id]" type="text" value="{$row.user_id|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Name')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-name" data-rule="required" class="form-control" name="row[name]" type="text" value="{$row.name|htmlentities}">
<input id="c-user_id" data-rule="required" data-source="user/user/index" data-field="mobile" data-format-item="{id} - {nickname} - {mobile}" class="form-control selectpage" name="row[user_id]" type="text" value="{$row.user_id|htmlentities}">
<span style="color: red">
(没找到用户则点击按钮创建用户后重新下拉框选用户)
<a data-url="user/user/changeuser" href="javascript:;" class="btn btn-success btn-changeuser {:$auth->check('user/user/changeuser')?'':'hide'}" title="根据手机号生成用户" ><i class="fa fa-plus"></i> 根据手机号生成用户</a>
</span>
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Team_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-team_id" data-rule="required" data-source="score/team/index" class="form-control selectpage" name="row[team_id]" type="text" value="{$row.team_id|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Name')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-name" data-rule="required" class="form-control" name="row[name]" type="text" value="{$row.name|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Image')}:</label>
<div class="col-xs-12 col-sm-8">
<div class="input-group">
<input id="c-image" data-rule="required" class="form-control" size="50" name="row[image]" type="text" value="{$row.image|htmlentities}">
<div class="input-group-addon no-border no-padding">
<span><button type="button" id="faupload-image" class="btn btn-danger faupload" data-input-id="c-image" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/bmp,image/webp" data-multiple="false" data-preview-id="p-image"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
<span><button type="button" id="fachoose-image" class="btn btn-primary fachoose" data-input-id="c-image" data-mimetype="image/*" data-multiple="false"><i class="fa fa-list"></i> {:__('Choose')}</button></span>
</div>
<span class="msg-box n-right" for="c-image"></span>
</div>
<ul class="row list-inline faupload-preview" id="p-image"></ul>
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Status')}:</label>
<div class="col-xs-12 col-sm-8">

View File

@ -3,39 +3,62 @@
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Score_event_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-score_event_id" data-rule="required" data-source="score/event/index" class="form-control selectpage" name="row[score_event_id]" type="text" value="">
<input id="c-score_event_id" data-source="score/event/index" class="form-control selectpage" name="row[score_event_id]" type="text" value="">
<span style="color: red">
(没找到积分规则则点击按钮创建积分规则后重新下拉框选积分规则)
<a data-url="score/event/add" href="javascript:;" class="btn btn-success btn-changeuser {:$auth->check('score/event/add')?'':'hide'}" title="添加新积分规则" ><i class="fa fa-plus"></i> 添加新积分规则</a>
</span>
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Score_employee_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-score_employee_id" data-rule="required" data-source="score/employee/index" class="form-control selectpage" name="row[score_employee_id]" type="text" value="">
<span style="color: red">
(没找到员工则点击按钮创建员工后重新下拉框选员工)
<a data-url="score/employee/add" href="javascript:;" class="btn btn-success btn-changeuser {:$auth->check('score/employee/add')?'':'hide'}" title="添加新员工" ><i class="fa fa-plus"></i> 添加新员工</a>
</span>
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('User_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-user_id" data-rule="required" data-source="user/user/index" data-field="nickname" class="form-control selectpage" name="row[user_id]" type="text" value="">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Score_team_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-score_team_id" data-rule="required" data-source="score/team/index" class="form-control selectpage" name="row[score_team_id]" type="text" value="">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Name')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-name" class="form-control" name="row[name]" type="text">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Score')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-score" data-rule="required" class="form-control" name="row[score]" type="number" value="0">
</div>
</div>
<!-- <div class="form-group">-->
<!-- <label class="control-label col-xs-12 col-sm-2">{:__('User_id')}:</label>-->
<!-- <div class="col-xs-12 col-sm-8">-->
<!-- <input id="c-user_id" data-rule="required" data-source="user/user/index" data-field="mobile" data-format-item="{id} - {nickname} - {mobile}" class="form-control selectpage" name="row[user_id]" type="text" value="{$q_user_id}">-->
<!-- <span style="color: red">-->
<!-- (没找到用户则点击按钮创建用户后重新下拉框选用户)-->
<!-- <a data-url="user/user/changeuser" href="javascript:;" class="btn btn-success btn-changeuser {:$auth->check('user/user/changeuser')?'':'hide'}" title="根据手机号生成用户" ><i class="fa fa-plus"></i> 根据手机号生成用户</a>-->
<!-- </span>-->
<!-- </div>-->
<!-- </div>-->
<!-- <div class="form-group">-->
<!-- <label class="control-label col-xs-12 col-sm-2">{:__('Score_team_id')}:</label>-->
<!-- <div class="col-xs-12 col-sm-8">-->
<!-- <input id="c-score_team_id" data-rule="required" data-source="score/team/index" class="form-control selectpage" name="row[score_team_id]" type="text" value="">-->
<!-- </div>-->
<!-- </div>-->
<!-- <div class="form-group">-->
<!-- <label class="control-label col-xs-12 col-sm-2">{:__('Name')}:</label>-->
<!-- <div class="col-xs-12 col-sm-8">-->
<!-- <input id="c-name" class="form-control" name="row[name]" type="text">-->
<!-- </div>-->
<!-- </div>-->
<!-- <div class="form-group">-->
<!-- <label class="control-label col-xs-12 col-sm-2">{:__('Score')}:</label>-->
<!-- <div class="col-xs-12 col-sm-8">-->
<!-- <input id="c-score" data-rule="required" class="form-control" name="row[score]" type="number" value="0">-->
<!-- </div>-->
<!-- </div>-->
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Images')}:</label>
<div class="col-xs-12 col-sm-8">
@ -56,6 +79,30 @@
<input id="c-desc" class="form-control" name="row[desc]" type="text">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Status')}:</label>
<div class="col-xs-12 col-sm-8">
<div class="radio">
{foreach name="statusList" item="vo"}
<label for="row[status]-{$key}"><input id="row[status]-{$key}" name="row[status]" type="radio" value="{$key}" {in name="key" value="0"}checked{/in} /> {$vo}</label>
{/foreach}
</div>
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Reason')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-reason" class="form-control" name="row[reason]" type="text" value="">
</div>
</div>
<!-- <div class="form-group">-->
<!-- <label class="control-label col-xs-12 col-sm-2">{:__('Authtime')}:</label>-->
<!-- <div class="col-xs-12 col-sm-8">-->
<!-- <input id="c-authtime" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[authtime]" type="text" value="{:date('Y-m-d H:i:s')}">-->
<!-- </div>-->
<!-- </div>-->
<div class="form-group layer-footer">
<label class="control-label col-xs-12 col-sm-2"></label>
<div class="col-xs-12 col-sm-8">

View File

@ -4,24 +4,31 @@
<label class="control-label col-xs-12 col-sm-2">{:__('Score_event_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-score_event_id" data-rule="required" data-source="score/event/index" class="form-control selectpage" name="row[score_event_id]" type="text" value="{$row.score_event_id|htmlentities}">
<span style="color: red">
(没找到积分规则则点击按钮创建积分规则后重新下拉框选积分规则)
<a data-url="score/event/add" href="javascript:;" class="btn btn-success btn-changeuser {:$auth->check('score/event/add')?'':'hide'}" title="添加新积分规则" ><i class="fa fa-plus"></i> 添加新积分规则</a>
</span>
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Score_employee_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-score_employee_id" data-rule="required" data-source="score/employee/index" class="form-control selectpage" name="row[score_employee_id]" type="text" value="{$row.score_employee_id|htmlentities}">
<input id="c-score_employee_id" data-rule="required" disabled data-source="score/employee/index" class="form-control selectpage" name="row[score_employee_id]" type="text" value="{$row.score_employee_id|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('User_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-user_id" data-rule="required" data-source="user/user/index" data-field="nickname" class="form-control selectpage" name="row[user_id]" type="text" value="{$row.user_id|htmlentities}">
<input id="c-user_id" data-rule="required" disabled data-source="user/user/index" data-field="nickname" class="form-control selectpage" name="row[user_id]" type="text" value="{$row.user_id|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Score_team_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-score_team_id" data-rule="required" data-source="score/team/index" class="form-control selectpage" name="row[score_team_id]" type="text" value="{$row.score_team_id|htmlentities}">
<input id="c-score_team_id" data-rule="required" disabled data-source="score/team/index" class="form-control selectpage" name="row[score_team_id]" type="text" value="{$row.score_team_id|htmlentities}">
</div>
</div>
<div class="form-group">
@ -56,6 +63,30 @@
<input id="c-desc" class="form-control" name="row[desc]" type="text" value="{$row.desc|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Status')}:</label>
<div class="col-xs-12 col-sm-8">
<div class="radio">
{foreach name="statusList" item="vo"}
<label for="row[status]-{$key}"><input id="row[status]-{$key}" name="row[status]" type="radio" value="{$key}" {in name="key" value="$row.status"}checked{/in} /> {$vo}</label>
{/foreach}
</div>
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Reason')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-reason" class="form-control" name="row[reason]" type="text" value="{$row.reason|htmlentities}">
</div>
</div>
<!-- <div class="form-group">-->
<!-- <label class="control-label col-xs-12 col-sm-2">{:__('Authtime')}:</label>-->
<!-- <div class="col-xs-12 col-sm-8">-->
<!-- <input id="c-authtime" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[authtime]" type="text" value="{:$row.authtime?datetime($row.authtime):''}">-->
<!-- </div>-->
<!-- </div>-->
<div class="form-group layer-footer">
<label class="control-label col-xs-12 col-sm-2"></label>
<div class="col-xs-12 col-sm-8">

View File

@ -1,5 +1,15 @@
<div class="panel panel-default panel-intro">
{:build_heading()}
<div class="panel-heading">
{:build_heading(null,FALSE)}
<ul class="nav nav-tabs" data-field="status">
<li class="{:$Think.get.status === null ? 'active' : ''}"><a href="#t-all" data-value="" data-toggle="tab">{:__('All')}</a></li>
{foreach name="statusList" item="vo"}
<li class="{:$Think.get.status === (string)$key ? 'active' : ''}"><a href="#t-{$key}" data-value="{$key}" data-toggle="tab">{$vo}</a></li>
{/foreach}
</ul>
</div>
<div class="panel-body">
<div id="myTabContent" class="tab-content">
@ -12,8 +22,19 @@
<a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('score/log/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>
<a href="javascript:;" class="btn btn-danger btn-auth_yes btn-disabled disabled {:$auth->check('score/log/auth_yes')?'':'hide'}" title="{:__('批量审核通过')}" > {:__('批量审核通过')}</a>
<a href="javascript:;" class="btn btn-danger btn-auth_no btn-disabled disabled {:$auth->check('score/log/auth_no')?'':'hide'}" title="{:__('批量审核拒绝')}" > {:__('批量审核拒绝')}</a>
<div class="dropdown btn-group {:$auth->check('score/log/multi')?'':'hide'}">
<a class="btn btn-primary btn-more dropdown-toggle btn-disabled disabled" data-toggle="dropdown"><i class="fa fa-cog"></i> {:__('More')}</a>
<ul class="dropdown-menu text-left" role="menu">
{foreach name="statusList" item="vo"}
<li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:" data-params="status={$key}">{:__('Set status to ' . $key)}</a></li>
{/foreach}
</ul>
</div>
<a class="btn btn-success btn-recyclebin btn-dialog {:$auth->check('score/log/recyclebin')?'':'hide'}" href="score/log/recyclebin" title="{:__('Recycle bin')}"><i class="fa fa-recycle"></i> {:__('Recycle bin')}</a>
</div>
<table id="table" class="table table-striped table-bordered table-hover table-nowrap"

View File

@ -1,11 +1,39 @@
<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Image')}:</label>
<div class="col-xs-12 col-sm-8">
<div class="input-group">
<input id="c-image" data-rule="required" class="form-control" size="50" name="row[image]" type="text" value="" >
<div class="input-group-addon no-border no-padding">
<span><button type="button" id="faupload-image" class="btn btn-danger faupload" data-input-id="c-image" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/bmp,image/webp" data-multiple="false" data-preview-id="p-image"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
<span><button type="button" id="fachoose-image" class="btn btn-primary fachoose" data-input-id="c-image" data-mimetype="image/*" data-multiple="false"><i class="fa fa-list"></i> {:__('Choose')}</button></span>
</div>
<span class="msg-box n-right" for="c-image"></span>
</div>
<ul class="row list-inline faupload-preview" id="p-image"></ul>
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Name')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-name" class="form-control" name="row[name]" type="text">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Score_employee_ids')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-score_employee_ids" data-rule="required" data-multiple="true" data-source="score/employee/index" class="form-control selectpage" name="row[score_employee_ids]" type="text" value="">
</div>
</div>
<div class="form-group layer-footer">
<label class="control-label col-xs-12 col-sm-2"></label>
<div class="col-xs-12 col-sm-8">

View File

@ -1,11 +1,39 @@
<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Image')}:</label>
<div class="col-xs-12 col-sm-8">
<div class="input-group">
<input id="c-image" data-rule="required" class="form-control" size="50" name="row[image]" type="text" value="{$row.image|htmlentities}">
<div class="input-group-addon no-border no-padding">
<span><button type="button" id="faupload-image" class="btn btn-danger faupload" data-input-id="c-image" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/bmp,image/webp" data-multiple="false" data-preview-id="p-image"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
<span><button type="button" id="fachoose-image" class="btn btn-primary fachoose" data-input-id="c-image" data-mimetype="image/*" data-multiple="false"><i class="fa fa-list"></i> {:__('Choose')}</button></span>
</div>
<span class="msg-box n-right" for="c-image"></span>
</div>
<ul class="row list-inline faupload-preview" id="p-image"></ul>
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Name')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-name" class="form-control" name="row[name]" type="text" value="{$row.name|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Score_employee_ids')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-score_employee_ids" data-rule="required" data-multiple="true" data-source="score/employee/index" class="form-control selectpage" name="row[score_employee_ids]" type="text" value="{$row.score_employee_ids|htmlentities}">
</div>
</div>
<div class="form-group layer-footer">
<label class="control-label col-xs-12 col-sm-2"></label>
<div class="col-xs-12 col-sm-8">

View File

@ -0,0 +1,34 @@
<form id="changeuser-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<fieldset>
<legend><h4>根据手机号和姓名创建用户(已存在则不更改任何信息!)</h4></legend>
<div class="form-group">
<label for="c-people_name" class="control-label col-xs-12 col-sm-2">姓名(昵称):</label>
<div class="col-xs-12 col-sm-8">
<input placeholder="" id="c-people_name" data-rule="required" class="form-control" name="people_name" type="text" value="">
</div>
</div>
<div class="form-group">
<label for="c-people_mobile" class="control-label col-xs-12 col-sm-2">手机号:</label>
<div class="col-xs-12 col-sm-8">
<input placeholder="" id="c-people_mobile" data-rule="required" class="form-control" name="people_mobile" type="text" value="">
<span style="color: red">(手机号将自动创建并关联对应微信小程序账号,请认真核对确认无误!)</span>
</div>
</div>
<div class="form-group">
<label for="c-password" class="control-label col-xs-12 col-sm-2">{:__('Password')}:</label>
<div class="col-xs-12 col-sm-4">
<input id="c-password" data-rule="password" class="form-control" name="password" type="password" value="" placeholder="请设置登录密码" autocomplete="new-password" />
</div>
</div>
</fieldset>
<div class="form-group layer-footer">
<label class="control-label col-xs-12 col-sm-2"></label>
<div class="col-xs-12 col-sm-8">
<button type="button" id="changeuser" data-type="changeuser" class="btn btn-success btn-embossed">确认创建</button>
</div>
</div>
</form>

View File

@ -14,6 +14,8 @@
<li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=hidden"><i class="fa fa-eye-slash"></i> {:__('Set to hidden')}</a></li>
</ul>
</div>
<a data-url="user/user/changeuser" href="javascript:;" class="btn btn-success btn-changeuser {:$auth->check('user/user/changeuser')?'':'hide'}" title="根据手机号生成用户" ><i class="fa fa-plus"></i> 根据手机号生成用户</a>
</div>
<table id="table" class="table table-striped table-bordered table-hover table-nowrap"
data-operate-edit="{:$auth->check('user/user/edit')}"

View File

@ -0,0 +1,177 @@
<?php
namespace app\api\controller;
use app\common\controller\Api;
use think\Config;
use app\common\model\score\Log;
use app\common\model\score\Event;
/**
* 积分接口
*/
class Score extends Api
{
/**
* @var \app\common\model\score\Log
*/
protected $model = null;
protected $noNeedRight = ['*'];
public function _initialize()
{
parent::_initialize();
$this->model = new Log;
}
/**
* @ApiTitle( 积分项列表)
* @ApiSummary(积分项列表)
* @ApiMethod(GET)
* @ApiParams(name = "keywords", type = "string",required=false,description = "搜索关键字")
* @ApiParams(name = "page", type = "string",required=true,description = "页数")
* @ApiParams(name = "limit", type = "string",required=true,description = "条数")
* @ApiParams(name = "way", type = "string",required=false,description = "free=自由申请,direct=直接奖励 默认自由申请")
* @ApiReturn({
*
*})
*/
public function index()
{
$user_id = 0;
$user = $this->auth->getUser();//登录用户
if($user)$user_id = $user['id'];
$page = $this->request->param('page/d', 0); //页数
$limit = $this->request->param('limit/d', 0); //条数
$keywords = $this->request->param('keywords/s', ''); //搜索关键字
$way = $this->request->param('way/s', 'free'); //搜索关键字
try{
//当前申请状态
$res = Event::allList($page, $limit,$keywords,$way,[]);
// var_dump($this->model->getLastSql());
}catch (\Exception $e){
$this->error($e->getMessage());
}
$this->success('查询成功', $res);
}
/**
* @ApiTitle( 我的积分申请列表)
* @ApiSummary(我的积分申请列表)
* @ApiMethod(GET)
* @ApiParams(name = "keywords", type = "string",required=false,description = "搜索关键字")
* @ApiParams(name = "page", type = "string",required=true,description = "页数")
* @ApiParams(name = "limit", type = "string",required=true,description = "条数")
* @ApiParams(name = "status", type = "string",required=false,description = "审核状态:0=待审核,1=审核通过,2=审核不通过 可多值逗号拼接")
* @ApiParams(name = "time", type = "string",required=false,description = "复合时间查询:today今天,week本周,month本月,year本年,yesterday昨天,last year上一年,last week上周last month上個月lately7最近7天 lately30最近30天按开始时间区间查传值格式Y/m/d H:M:S-Y/m/d H:M:S")
* @ApiReturn({
*
*})
*/
public function log()
{
$user_id = 0;
$user = $this->auth->getUser();//登录用户
if($user)$user_id = $user['id'];
$page = $this->request->param('page/d', 0); //页数
$limit = $this->request->param('limit/d', 0); //条数
$keywords = $this->request->param('keywords/s', ''); //搜索关键字
$params = [];
$params["status"] = $this->request->param('status/s', ''); //搜索关键字
$params["time"] = $this->request->param('time/s', ''); //搜索关键字
$params["user_id"] = $user_id;
try{
//当前申请状态
$res = Log::allList($page, $limit,$keywords,$params);
// var_dump($this->model->getLastSql());
}catch (\Exception $e){
$this->error($e->getMessage());
}
$this->success('查询成功', $res);
}
/**
* @ApiTitle( 月度积分排行榜及个人月度当前积分累计)
* @ApiSummary(月度积分排行榜及个人月度当前积分累计)
* @ApiMethod(GET)
* @ApiParams(name = "time", type = "string",required=false,description = "要查询的月份的时间戳")
* @ApiReturn({
*
*})
*/
public function month()
{
$user_id = 0;
$user = $this->auth->getUser();//登录用户
if($user)$user_id = $user['id'];
$time = $this->request->param('time/d', null); //搜索关键字
try{
//当前申请状态
$res = Log::statistics($user_id,$time);
// var_dump($this->model->getLastSql());
}catch (\Exception $e){
$this->error($e->getMessage());
}
$this->success('查询成功', $res);
}
/**
* @ApiTitle( 积分申请)
* @ApiSummary(积分申请)
* @ApiMethod(POST)
* @ApiParams(name = "score_event_id", type = "string",required=true,description = "积分事件id")
* @ApiParams(name = "images", type = "string",required=true,description = "多图逗号拼接,附件只要相对路径,不要全路径")
* @ApiParams(name = "desc", type = "string",required=false,description = "备注")
* @ApiReturn({
*
*})
*/
public function add()
{
$user_id = 0;
$user = $this->auth->getUser();//登录用户
if($user)$user_id = $user['id'];
$params=[];
$params["user_id"] = $user_id; //页数
$params["score_event_id"] = $this->request->post('score_event_id/d', ''); //条数
$params["images"] = $this->request->post('images/s', ''); //搜索关键字
$params["desc"] = $this->request->post('desc/s', ''); //搜索关键字
//全局锁
$this->setUrlLock("only");
try{
if(!$params["score_event_id"]) throw new \Exception(__('积分项不存在'));
//当前申请状态
$res = $this->model->add($params,true,true);
// var_dump($this->model->getLastSql());
}catch (\Exception $e){
$this->error($e->getMessage());
}
$this->success('添加成功', $res);
}
}

View File

@ -32,7 +32,13 @@ class User extends Api
*/
public function index()
{
$this->success('', ['welcome' => $this->auth->nickname]);
$user = \app\common\model\User::where( 'id', $this->auth->id)->find();
$data["employee_info"] = $user->employee;
$data["team_info"] = $user->employee->team;
$data["welcome"] = $this->auth->nickname;
$this->success('', $data);
}
/**
@ -52,6 +58,10 @@ class User extends Api
$ret = $this->auth->login($account, $password);
if ($ret) {
$data = ['userinfo' => $this->auth->getUserinfo()];
$user = \app\common\model\User::where( 'id', $this->auth->id)->find();
$data["employee_info"] = $user->employee;
$data["team_info"] = $user->employee->team;
$this->success(__('Logged in successful'), $data);
} else {
$this->error($this->auth->getError());

View File

@ -580,4 +580,75 @@ class Auth
{
return $this->_error ? __($this->_error) : '';
}
/**
* 注册用户(自定义)
*
* @param string $username 用户名
* @param string $password 密码
* @param string $email 邮箱
* @param string $mobile 手机号
* @param array $extend 扩展参数
*/
public function registerNoLogin($username, $password, $email = '', $mobile = '', $extend = [])
{
// 检测用户名、昵称、邮箱、手机号是否存在
if (User::getByUsername($username)) {
$this->setError('Username already exist');
return false;
}
if (User::getByNickname($username)) {
$this->setError('Nickname already exist');
return false;
}
if ($email && User::getByEmail($email)) {
$this->setError('Email already exist');
return false;
}
if ($mobile && User::getByMobile($mobile)) {
$this->setError('Mobile already exist');
return false;
}
$ip = request()->ip();
$time = time();
$data = [
'username' => $username,
'password' => $password,
'email' => $email,
'mobile' => $mobile,
'level' => 1,
'score' => 0,
'avatar' => '',
];
$params = array_merge($data, [
'nickname' => preg_match("/^1[3-9]{1}\d{9}$/",$username) ? substr_replace($username,'****',3,4) : $username,
'salt' => Random::alnum(),
'jointime' => $time,
'joinip' => $ip,
'logintime' => $time,
'loginip' => $ip,
'prevtime' => $time,
'status' => 'normal'
]);
$params['password'] = $this->getEncryptPassword($password, $params['salt']);
$params = array_merge($params, $extend);
//账号注册时需要开启事务,避免出现垃圾数据
Db::startTrans();
try {
$user = User::create($params, true);
//注册成功的事件
Hook::listen("user_register_successed", $this->_user, $data);
Db::commit();
} catch (Exception $e) {
$this->setError($e->getMessage());
Db::rollback();
return false;
}
return User::get($user->id);
}
}

View File

@ -2,7 +2,13 @@
namespace app\common\model;
use app\common\library\Auth;
use app\common\model\score\Employee;
use app\common\model\score\Team;
use fast\Random;
use think\Db;
use think\Exception;
use think\Hook;
use think\Model;
/**
@ -152,4 +158,61 @@ class User extends Model
}
return $level;
}
/**添加用户:通过 手机号 和昵称
* @param $mobile
* @param $nickname
*/
public function addUserByMobile($mobile,$nickname,$password=null,$check=true){
//去除空格
$nickname = trim($nickname);
$mobile = trim($mobile);
if(!is_numeric($mobile))throw new \Exception("不是合法手机号!");
if(strlen($mobile)!=11)throw new \Exception("请输入11位手机号");
if($check){
if (!preg_match("/[\x7f-\xff]/", $nickname)) throw new \Exception("名称必须是汉字,请去除空格和其他特殊符号!");
preg_match_all("/[\x{4e00}-\x{9fa5}]/u","$nickname",$result);
if(!$result || join('',$result[0])!=$nickname)throw new \Exception("名称必须是汉字,请去除空格和其他特殊符号!");
}
//判断用户存不存在
$user = self::where("mobile",$mobile)->find();
if($user){
//如果存在,直接返回
return $user;
}else{
//如果不存在,创建并返回
//得到认证实例
$auth = Auth::instance();
//拼装提交参数
// $extend = $this->getUserDefaultFields();
$extend=[];
$extend['nickname'] = $nickname;
$extend['avatar'] = config("site.default_avatar");
if(!$password) $password = rand(100000,999999);
//调用注册方法
$user = $auth->registerNoLogin("{$mobile}_user", $password, "{$mobile}@user.com", $mobile,$extend);
if(!$user)throw new \Exception($auth->getError());
//更新已认证方式
$user = self::where("id", $user->id)->find();
$verification = $user->verification;
$verification->mobile = 1;
$user->verification = $verification;
$user->save();
//返回对象
return self::where("id", $user->id)->find();
}
}
public function employee()
{
return $this->hasOne(Employee::class, 'user_id', 'id');
}
}

View File

@ -0,0 +1,83 @@
<?php
namespace app\common\model\score;
use think\Model;
class Employee extends Model
{
// 表名
protected $name = 'score_employee';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'integer';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = false;
// 追加属性
protected $append = [
'status_text'
];
public function getStatusList()
{
return ['entry' => __('Status entry'), 'exit' => __('Status exit')];
}
public function getStatusTextAttr($value, $data)
{
$value = $value ?: ($data['status'] ?? '');
$list = $this->getStatusList();
return $list[$value] ?? '';
}
public function getImageAttr($value, $data)
{
if (!empty($value)) return cdnurl($value, true);
}
public function user()
{
return $this->belongsTo('app\admin\model\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
public function team()
{
return $this->belongsTo('Team', 'team_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
/** 查询积分统计,按时间查询
* @param $coach_id
* @param $start_time
* @param $end_time
*/
public static function getPriceByCoachAndTime($id,$start_time=0,$end_time=0){
$where = [[]];
if($start_time){
$where = ['createtime', 'between time', [$start_time, $end_time]];
}
//统计已核销未退款金额
$pay_fee = Log::where('score_employee_id',$id)->where('status','=',1)->where(...$where)->sum('score');
return $pay_fee;
}
}

View File

@ -0,0 +1,187 @@
<?php
namespace app\common\model\score;
use app\common\model\BaseModel;
use think\Model;
use traits\model\SoftDelete;
class Event extends BaseModel
{
use SoftDelete;
// 表名
protected $name = 'score_event';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'integer';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = 'deletetime';
// 追加属性
protected $append = [
'status_text',
'frequency_text',
'way_text'
];
protected static function init()
{
self::afterInsert(function ($row) {
if (!$row['weigh']) {
$pk = $row->getPk();
$row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
}
});
}
public function getStatusList()
{
return ['attendance' => __('Status attendance'), 'morning_meeting_hosting' => __('Status morning_meeting_hosting'), 'safety_environment' => __('Status safety_environment'), 'appearance_demeanor' => __('Status appearance_demeanor'), 'thorough_summarization' => __('Status thorough_summarization'), 'good_people_deeds' => __('Status good_people_deeds'), 'customer_service' => __('Status customer_service'), 'corporate_culture' => __('Status corporate_culture')];
}
public function getFrequencyList()
{
return ['month' => __('Frequency month'), 'day' => __('Frequency day'), 'week' => __('Frequency week'), 'once' => __('Frequency once')];
}
public function getWayList()
{
return ['free' => __('Way free'), 'direct' => __('Way direct')];
}
public function getStatusTextAttr($value, $data)
{
$value = $value ?: ($data['status'] ?? '');
$list = $this->getStatusList();
return $list[$value] ?? '';
}
public function getFrequencyTextAttr($value, $data)
{
$value = $value ?: ($data['frequency'] ?? '');
$list = $this->getFrequencyList();
return $list[$value] ?? '';
}
public function getWayTextAttr($value, $data)
{
$value = $value ?: ($data['way'] ?? '');
$valueArr = explode(',', $value);
$list = $this->getWayList();
return implode(',', array_intersect_key($list, array_flip($valueArr)));
}
protected function setWayAttr($value)
{
return is_array($value) ? implode(',', $value) : $value;
}
/**得到基础条件
* @param $status
* @param null $model
* @param string $alisa
*/
public static function getBaseWhere($whereData = [], $model = null, $alisa = '',$with = false)
{
if (!$model) {
$model = new static;
if ($alisa&&!$with) $model = $model->alias($alisa);
}
if ($alisa) $alisa = $alisa . '.';
$tableFields = (new static)->getTableFields();
foreach ($tableFields as $fields)
{
if(in_array($fields, ['way']))continue;
// if (isset($whereData[$fields]) && $whereData[$fields]) $model = $model->where("{$alisa}{$fields}", '=', $whereData[$fields]);
if (isset($whereData[$fields]) && $whereData[$fields]){
if(is_array($whereData[$fields])){
$model = $model->where("{$alisa}{$fields}", $whereData[$fields][0], $whereData[$fields][1]);
}else{
$model = $model->where("{$alisa}{$fields}", '=', $whereData[$fields]);
}
}
}
if (isset($whereData['keywords'])&&$whereData['keywords']){
$model = $model->where("{$alisa}event_name|{$alisa}name|{$alisa}desc", 'LIKE', "%{$whereData['keywords']}%" );
}
if (isset($whereData['way']) && $whereData['way']!=="" && $whereData['way']!==null){
//针对set数据字段用find_in_set查询
$way = implode("|",explode(',',$whereData['way']));
$model = $model->whereRaw(" {$alisa}way REGEXP '({$way})'");
}
if (isset($whereData['time'])&&$whereData['time']){
$model = $model->time(["{$alisa}createtime",$whereData['time']]);
}
// if (isset($whereData['has_evaluate'])&&$whereData['has_evaluate']){
// //1查已评价 2查未评价
// if($whereData['has_evaluate'] == 1){
// //1查已评价
// $model = $model->where("{$alisa}classes_evaluate_id", '<>', 0);
// }else{
// //2查未评价
// $model = $model->whereExists(function ($query) use ($alisa) {
// $order_table_name = (new \app\common\model\school\classes\hourorder\Order())->getQuery()->getTable();
// $query->table($order_table_name)->where($order_table_name . '.classes_order_id=' . $alisa . 'id')->where('status', '=', '3');
// })->where("{$alisa}classes_evaluate_id", '=', 0);
//
// }
// }
return $model;
}
public static function allList($page, $limit,$keywords,$way="",$params=[]){
$with_field = [
// 'cate'=>['image','name'],
'base'=>['*'],
];
// $alisa = (new self)->getWithAlisaName();
// $sort = "{$alisa}.weigh desc,{$alisa}.id desc";
$sort = "weigh desc,id desc";
$serch_where = ['way'=>$way,'keywords'=>$keywords];
return (new self)->getBaseList(array_merge($serch_where,$params), $page, $limit,$sort,$with_field);
}
}

View File

@ -0,0 +1,505 @@
<?php
namespace app\common\model\score;
use app\common\model\BaseModel;
use think\Model;
use traits\model\SoftDelete;
class Log extends BaseModel
{
use SoftDelete;
// 表名
protected $name = 'score_log';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'integer';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = 'deletetime';
// 追加属性
protected $append = [
'status_text',
'authtime_text',
'createtime_text'
];
public function getCreatetimeTextAttr($value, $data)
{
$value = $value ?: ($data['createtime'] ?? '');
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
}
public function getStatusList()
{
return ['0' => __('Status 0'), '1' => __('Status 1'), '2' => __('Status 2')];
}
public function getStatusTextAttr($value, $data)
{
$value = $value ?: ($data['status'] ?? '');
$list = $this->getStatusList();
return $list[$value] ?? '';
}
public function getAuthtimeTextAttr($value, $data)
{
$value = $value ?: ($data['authtime'] ?? '');
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
}
protected function setAuthtimeAttr($value)
{
return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
}
public function scoreevent()
{
return $this->belongsTo('Event', 'score_event_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
public function employee()
{
return $this->belongsTo('Employee', 'score_employee_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
public function user()
{
return $this->belongsTo('app\admin\model\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
public function team()
{
return $this->belongsTo('Team', 'score_team_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
public function getImagesAttr($value, $data)
{
$imagesArray = [];
if (!empty($value)) {
$imagesArray = explode(',', $value);
foreach ($imagesArray as &$v) {
$v = cdnurl($v, true);
}
return $imagesArray;
}
return $imagesArray;
}
public function setImagesAttr($value, $data)
{
$imagesArray = $value;
if (!empty($value) && is_array($value)) {
//转成逗号拼接字符串
$imagesArray = implode(',', $value);
}
return $imagesArray;
}
/** 通用新增(后台api版本)
* @param $params
* @param $trans
* @return $this
* @throws \Exception
*/
public function add($params,$check = true,$trans=false){
if (empty($params)) {
throw new \Exception(__('Parameter %s can not be empty', ''));
}
if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
$params[$this->dataLimitField] = $this->auth->id;
}
//判断逻辑
if($trans){
self::beginTrans();
}
$res = true;
try{
$user_id = $params["user_id"]??0;
$score_event_id = $params["score_event_id"]??0;
$score_employee_id = $params["score_employee_id"]??0;
$employee = null;
if($score_employee_id){
//判断是否是员工
$employee = Employee::where("id",$score_employee_id)->find();
if(!$user_id){
$user_id = $employee["user_id"];
$params["user_id"] = $user_id;
}
}
if($score_event_id){
$score_event = Event::where("id",$score_event_id)->find();
if(!$score_event) throw new \Exception(__('积分项不存在'));
$way = explode(",",$score_event["way"]);
if($check){
if(!in_array( "free",$way))throw new \Exception(__('该积分项不允许申请'));
}
//进行频次判断
switch ($score_event["frequency"]){
case "day":
$count = self::where("score_event_id",$score_event_id)
->where("user_id",$user_id)
->where("status","in",[0,1])
->whereTime("createtime","today")
->count();
if($score_event["max_times"] > 0 && $count >= $score_event["max_times"]){
throw new \Exception(__('积分项在期限内已申请上限,请明日再尝试!'));
}
$score = self::where("score_event_id",$score_event_id)
->where("user_id",$user_id)
->where("status","in",[0,1])
->whereTime("createtime","today")
->sum( "score");
if($score_event["monthly_highest_score"] > 0 && $score >= $score_event["monthly_highest_score"]){
throw new \Exception(__('积分项在期限内已申请上限,请明日再尝试!'));
}
break;
case "week":
$count = self::where("score_event_id",$score_event_id)
->where("user_id",$user_id)
->where("status","in",[0,1])
->whereTime("createtime","week")
->count();
if($score_event["max_times"] > 0 && $count >= $score_event["max_times"]){
throw new \Exception(__('积分项在期限内已申请上限,请明日再尝试!'));
}
$score = self::where("score_event_id",$score_event_id)
->where("user_id",$user_id)
->where("status","in",[0,1])
->whereTime("createtime","week")
->sum( "score");
if($score_event["monthly_highest_score"] > 0 && $score >= $score_event["monthly_highest_score"]){
throw new \Exception(__('积分项在期限内已申请上限,请明日再尝试!'));
}
break;
case "month":
$count = self::where("score_event_id",$score_event_id)
->where("user_id",$user_id)
->where("status","in",[0,1])
->whereTime("createtime","month")
->count();
if($score_event["max_times"] > 0 && $count >= $score_event["max_times"]){
throw new \Exception(__('积分项在期限内已申请上限,请明日再尝试!'));
}
$score = self::where("score_event_id",$score_event_id)
->where("user_id",$user_id)
->where("status","in",[0,1])
->whereTime("createtime","month")
->sum( "score");
if($score_event["monthly_highest_score"] > 0 && $score >= $score_event["monthly_highest_score"]){
throw new \Exception(__('积分项在期限内已申请上限,请明日再尝试!'));
}
break;
case "once":
$count = self::where("score_event_id",$score_event_id)
->where("status","in",[0,1])
->where("user_id",$user_id)->count();
if($score_event["max_times"] > 0 && $count >= $score_event["max_times"]){
throw new \Exception(__('积分项已申请上限,无法再申请!'));
}
$score = self::where("score_event_id",$score_event_id)
->where("user_id",$user_id)
->where("status","in",[0,1])
->sum( "score");
if($score_event["monthly_highest_score"] > 0 && $score >= $score_event["monthly_highest_score"]){
throw new \Exception(__('积分项已申请上限,无法再申请!'));
}
break;
}
$params["name"] = $score_event["name"];
$params["score"] = $score_event["score"];
}
if(!$user_id) throw new \Exception(__('用户需登录'));
//判断是否是员工
if(!$employee)$employee = Employee::where("user_id",$user_id)->find();
if(!$employee) throw new \Exception(__('用户不是员工'));
if(!$employee["team_id"])throw new \Exception(__('用户未加入队伍!'));
$team = Team::where("id",$employee["team_id"])->find();
if(!$team)throw new \Exception(__('用户未加入队伍!'));
if(!$params["images"] || !$params["name"] || !$params["score"])throw new \Exception(__('缺少关键申请参数!'));
$params["score_employee_id"] = $employee["id"];
$params["score_event_id"] = $score_event_id;
$params["score_team_id"] = $team["id"];
$params["status"] = $params["status"] ?? 0;
$params["authtime"] = $params["status"] != 0 ? time() : NULL;
$params["reason"] = $params["reason"] ?? "";
//如果审核失败,需要填写原因
if ($params["status"] == 2) {
if (!$params['reason']) {
$this->error('审核失败,请填写原因');
}
}
//是否采用模型验证
if ($this->modelValidate) {
$name = str_replace("\\model\\", "\\validate\\", get_class($this));
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
$this->validateFailException()->validate($validate);
}
$result = $this->allowField(true)->save($params);
if($trans){
self::commitTrans();
}
}catch (\Exception $e){
if($trans){
self::rollbackTrans();
}
throw new \Exception($e->getMessage());
}
return $this;
}
/**得到基础条件
* @param $status
* @param null $model
* @param string $alisa
*/
public static function getBaseWhere($whereData = [], $model = null, $alisa = '',$with = false)
{
if (!$model) {
$model = new static;
if ($alisa&&!$with) $model = $model->alias($alisa);
}
if ($alisa) $alisa = $alisa . '.';
$tableFields = (new static)->getTableFields();
foreach ($tableFields as $fields)
{
if(in_array($fields, ['status']))continue;
// if (isset($whereData[$fields]) && $whereData[$fields]) $model = $model->where("{$alisa}{$fields}", '=', $whereData[$fields]);
if (isset($whereData[$fields]) && $whereData[$fields]){
if(is_array($whereData[$fields])){
$model = $model->where("{$alisa}{$fields}", $whereData[$fields][0], $whereData[$fields][1]);
}else{
$model = $model->where("{$alisa}{$fields}", '=', $whereData[$fields]);
}
}
}
if (isset($whereData['keywords'])&&$whereData['keywords']){
if($with){
$model = $model->where( function($query) use($whereData,$alisa,$with){
$query = $query->where("{$alisa}name|{$alisa}desc|{$alisa}reason", '=', $whereData['keywords']);
if(in_array('user',$with)){
$query = $query->whereOr("user.nickname|user.mobile", 'like', "%". $whereData['keywords']."%");
}
if(in_array('scoreevent',$with)){
$query = $query->whereOr("scoreevent.event_name|scoreevent.name|scoreevent.desc", 'like', "%". $whereData['keywords']."%");
}
if(in_array('employee',$with)){
$query = $query->whereOr("employee.name", 'like', "%". $whereData['keywords']."%");
}
if(in_array('team',$with)){
$query = $query->whereOr("team.name", 'like', "%". $whereData['keywords']."%");
}
});
}else{
$model = $model->where("{$alisa}name|{$alisa}desc|{$alisa}reason", '=', $whereData['keywords']);
}
}
if (isset($whereData['status']) && $whereData['status']!=="" && $whereData['status']!==null){
$model = $model->where("{$alisa}status","in",$whereData['status']);
}
if (isset($whereData['time'])&&$whereData['time']){
$model = $model->time(["{$alisa}createtime",$whereData['time']]);
}
// if (isset($whereData['has_evaluate'])&&$whereData['has_evaluate']){
// //1查已评价 2查未评价
// if($whereData['has_evaluate'] == 1){
// //1查已评价
// $model = $model->where("{$alisa}classes_evaluate_id", '<>', 0);
// }else{
// //2查未评价
// $model = $model->whereExists(function ($query) use ($alisa) {
// $order_table_name = (new \app\common\model\school\classes\hourorder\Order())->getQuery()->getTable();
// $query->table($order_table_name)->where($order_table_name . '.classes_order_id=' . $alisa . 'id')->where('status', '=', '3');
// })->where("{$alisa}classes_evaluate_id", '=', 0);
//
// }
// }
return $model;
}
public static function allList($page, $limit,$keywords,$params=[]){
$with_field = [
'user'=>['nickname','mobile','avatar'],
'scoreevent'=>['*'],
'employee'=>['name',"image"],
'team'=>['name',"image"],
'base'=>['*'],
];
$alisa = (new self)->getWithAlisaName();
$sort = "{$alisa}.id desc";
// $sort = "weigh desc,id desc";
$serch_where = ['keywords'=>$keywords];
return (new self)->getBaseList(array_merge($serch_where,$params), $page, $limit,$sort,$with_field);
}
public static function statistics($user_id=null,$time=null){
if(!$time) $time = time();
//得到当前时间戳指向的月开始和结束时间戳
$month_start = strtotime(date('Y-m-01 00:00:00', $time)); // 月初
$month_end = strtotime(date('Y-m-t 23:59:59', $time)); // 月末
// var_dump($month_start,$month_end);
//统计当前所有员工积分
$employees = Employee::where("status","entry")->select();
$employee_score = [];
$team_score = [];
//自己的积分
$my_employee_score = null;
//自己团队的积分
$my_team_score = null;
$my_team_id = null;
foreach ($employees as $employee){
//统计当前员工积分
$score = self::where("score_employee_id",$employee['id'])
->where("createtime",">=",$month_start)
->where("createtime","<=",$month_end)
->where("status","1")
->sum('score');
$employeedata = [
'id'=>$employee['id'],
'name'=>$employee['name'],
'image'=>$employee['image'],
'score'=>$score
];
$employee_score[$employee['id']] = $employeedata;
if($user_id && $user_id == $employee['user_id']){
$my_employee_score = $employeedata;
$my_team_id = $employee['team_id'];
}
if(!isset($team_score[$employee['team_id']])){
$team_data = [
'id'=>$employee['team_id'],
'name'=>$employee['team']['name'],
'image'=>$employee['team']['image'],
'score'=>$score
];
$team_score[$employee['team_id']] = $team_data;
}else{
//累加积分
$team_score[$employee['team_id']]['score'] += $score;
}
}
//自己团队的积分
if($my_team_id){
$my_team_score = $team_score[$my_team_id];
}
//清除各自键
$employee_score = array_values($employee_score);
$team_score = array_values($team_score);
//根据$employee_score 查询当前时间戳所在月份的个人排行前10
// $employee_rank = array_slice(array_values(array_sort($employee_score, 'score', 'desc')),0,10);
// 对员工积分进行降序排序
usort($employee_score, function ($a, $b) {
return $b['score'] <=> $a['score'];
});
$employee_rank = array_values($employee_score);
// 对团队积分进行降序排序
usort($team_score, function ($a, $b) {
return $b['score'] <=> $a['score'];
});
$team_rank = array_values($team_score);
//查询当前时间戳个人所在月积分
//查询当前时间戳个人所在队伍总积分
return [
'my_employee_score'=>$my_employee_score,
'my_team_score'=>$my_team_score,
'employee_rank'=>$employee_rank,
'team_rank'=>$team_rank
];
}
}

View File

@ -0,0 +1,72 @@
<?php
namespace app\common\model\score;
use think\Model;
class Team extends Model
{
// 表名
protected $name = 'score_team';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'integer';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = false;
// 追加属性
protected $append = [
"score_employee_ids"
];
public function getImageAttr($value, $data)
{
if (!empty($value)) return cdnurl($value, true);
}
public function getScoreEmployeeIdsAttr($value, $data)
{
$value = $value ?: ($data['id'] ?? '');
if(!$value) return "";
$score_employee_ids = Employee::where( "team_id", $value)->column( "id");
return implode(",", $score_employee_ids);
}
/** 查询积分统计,按时间查询
* @param $coach_id
* @param $start_time
* @param $end_time
*/
public static function getPriceByCoachAndTime($id,$start_time=0,$end_time=0){
$where = [[]];
if($start_time){
$where = ['createtime', 'between time', [$start_time, $end_time]];
}
//统计已核销未退款金额
$pay_fee = Log::where('score_team_id',$id)->where('status','=',1)->where(...$where)->sum('score');
return $pay_fee;
}
}

View File

@ -306,4 +306,13 @@ return [
//API接口地址
'api_url' => 'https://api.fastadmin.net',
],
//增加 redis 配置
'redis' => [
'host' => '127.0.0.1', // redis 主机地址
'password' => '', // redis 密码
'port' => 6379, // redis 端口
'select' => 3, // redis 数据库
'timeout' => 0, // redis 超时时间
'persistent' => false, // redis 持续性,连接复用
]
];

5648
public/api.html Normal file

File diff suppressed because it is too large Load Diff

View File

@ -22,21 +22,59 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
fixedColumns: true,
fixedRightNumber: 1,
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'user_id', title: __('User_id')},
{field: 'user_id', title: __('User_id'),visible: false},
{field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
{field: 'team.name', title: __('Team.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
{field: 'name', title: __('Name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
{field: 'team_id', title: __('Team_id')},
{field: 'opertime', title: __('统计时间查询'), operate:'RANGE', addclass:'datetimerange', autocomplete:false,formatter:function (value, row, index) {
return row.opertime ? row.opertime : '未查询';
}},
{field: 'score_count', title: __('积分统计(根据具体统计时间筛选)'),formatter:function (value, row, index) {
// if( !row.opertime){
// return "<span style='color: #0d6aad'>#请在点开【搜索栏】后选择【统计时间查询】提交查询#</span>";
// }
return `
<span style="color: #0d6aad">${row.score_count}</span>
`;
},searchable:false},
{field: 'user.nickname', title: __('User.nickname'),visible: false, operate: 'LIKE'},
{field: 'user.mobile', title: __('User.mobile'), operate: 'LIKE'},
{field: 'user.avatar', title: __('User.avatar'),visible: false, operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image},
{field: 'team_id', title: __('Team_id'),visible: false},
{field: 'status', title: __('Status'), searchList: {"entry":__('Status entry'),"exit":__('Status exit')}, formatter: Table.api.formatter.status},
{field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
{field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
{field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
{field: 'user.mobile', title: __('User.mobile'), operate: 'LIKE'},
{field: 'user.avatar', title: __('User.avatar'), operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image},
{field: 'team.name', title: __('Team.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
// {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
{field: 'operate', title: __('Operate'), table: table , buttons: [
{
name: 'select',
text: __('积分记录'),
title: __('查看积分记录'),
classname: 'btn btn-xs btn-primary btn-dialog',
icon: 'fa fa-list',
url: log_url,
callback: function (data) {
},
// visible: function (row) {
// if(row.status == '1' || row.status == '2' ) return true;
// return false;
// }
},
], events: Table.api.events.operate, formatter: Table.api.formatter.operate},
]
]
});
@ -52,9 +90,35 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
},
api: {
bindevent: function () {
$(document).on('click', '.btn-changeuser', function (event) {
var url = $(this).attr('data-url');
if(!url) return false;
var title = $(this).attr('title');
var width = $(this).attr('data-width');
var height = $(this).attr('data-height');
// var ids = $(this).attr('data-id');
var area = [$(window).width() > 800 ? (width?width:'800px') : '95%', $(window).height() > 600 ? (height?height:'600px') : '95%'];
var options = {
shadeClose: false,
shade: [0.3, '#393D49'],
area: area,
callback:function(ret){//回调方法需要在本页面Controller中增加方法监听且调用Fast.api.close(ret)传递结果;
Fast.api.close(ret);
}
};
Fast.api.open(url,title,options);
});
Form.api.bindevent($("form[role=form]"));
}
}
};
var log_url = function (row,dom) {
return 'score/log/index?score_employee_id='+row.id;
}
return Controller;
});

View File

@ -118,6 +118,27 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
},
api: {
bindevent: function () {
$(document).on('click', '.btn-changeuser', function (event) {
var url = $(this).attr('data-url');
if(!url) return false;
var title = $(this).attr('title');
var width = $(this).attr('data-width');
var height = $(this).attr('data-height');
// var ids = $(this).attr('data-id');
var area = [$(window).width() > 800 ? (width?width:'800px') : '95%', $(window).height() > 600 ? (height?height:'600px') : '95%'];
var options = {
shadeClose: false,
shade: [0.3, '#393D49'],
area: area,
callback:function(ret){//回调方法需要在本页面Controller中增加方法监听且调用Fast.api.close(ret)传递结果;
Fast.api.close(ret);
}
};
Fast.api.open(url,title,options);
});
Form.api.bindevent($("form[role=form]"));
}
}

View File

@ -11,6 +11,10 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
del_url: 'score/log/del',
multi_url: 'score/log/multi',
import_url: 'score/log/import',
auth_yes_url: 'score/log/auth_yes',
auth_no_url: 'score/log/auth_no',
table: 'score_log',
}
});
@ -28,22 +32,30 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
[
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'score_event_id', title: __('Score_event_id')},
{field: 'score_employee_id', title: __('Score_employee_id')},
{field: 'user_id', title: __('User_id')},
{field: 'score_team_id', title: __('Score_team_id')},
{field: 'score_event_id', title: __('Score_event_id'),visible: false},
{field: 'score_employee_id', title: __('Score_employee_id'),visible: false},
{field: 'user_id', title: __('User_id'),visible: false},
{field: 'score_team_id', title: __('Score_team_id'),visible: false},
{field: 'name', title: __('Name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
{field: 'score', title: __('Score')},
{field: 'score', title: __('Score'), operate: false},
{field: 'images', title: __('Images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
{field: 'desc', title: __('Desc'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
{field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
{field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
{field: 'scoreevent.name', title: __('Event.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
{field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.status},
{field: 'reason', title: __('Reason'), operate: 'LIKE'},
{field: 'employee.name', title: __('Employee.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
{field: 'team.name', title: __('Team.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
{field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
{field: 'user.mobile', title: __('User.mobile'), operate: 'LIKE'},
{field: 'user.avatar', title: __('User.avatar'), operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image},
{field: 'team.name', title: __('Team.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
{field: 'authtime', title: __('Authtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
{field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
{field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
// {field: 'scoreevent.name', title: __('Event.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
]
]
@ -51,6 +63,82 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
// 为表格绑定事件
Table.api.bindevent(table);
// 批量审核成功
$(document).on("click", ".btn-auth_yes", function () {
let ids = Table.api.selectedids(table);
ids = ($.isArray(ids) ? ids.join(",") : ids);
//先提示,确认是否提交,确认提交再调用接口
Layer.confirm('确定要批量审核通过吗?', function (index) {
//调用接口
let url = $.fn.bootstrapTable.defaults.extend.auth_yes_url;
options = {url: url, data: { ids: ids}};
Fast.api.ajax(options, function (data, ret) {
table.trigger("uncheckbox");
// var success = $(element).data("success") || $.noop;
//提交成功提示信息
Fast.api.success(ret.msg);
// if (typeof success === 'function') {
// if (false === success.call(element, data, ret)) {
// return false;
// }
// }
table.bootstrapTable('refresh');
}, function (data, ret) {
// var error = $(element).data("error") || $.noop;
//提交失败提示信息
Fast.api.error(ret.msg);
// if (typeof error === 'function') {
// if (false === error.call(element, data, ret)) {
// return false;
// }
// }
});
});
});
// 批量审核失败
$(document).on("click", ".btn-auth_no", function () {
let ids = Table.api.selectedids(table);
ids = ($.isArray(ids) ? ids.join(",") : ids);
//调用接口
Layer.confirm('确定要批量审核不通过吗?', function (index) {
//调用接口
let url = $.fn.bootstrapTable.defaults.extend.auth_no_url;
options = {url: url, data: { ids: ids}};
Fast.api.ajax(options, function (data, ret) {
table.trigger("uncheckbox");
// var success = $(element).data("success") || $.noop;
//提交成功提示信息
Fast.api.success(ret.msg);
// if (typeof success === 'function') {
// if (false === success.call(element, data, ret)) {
// return false;
// }
// }
table.bootstrapTable('refresh');
}, function (data, ret) {
// var error = $(element).data("error") || $.noop;
//提交失败提示信息
Fast.api.error(ret.msg);
// if (typeof error === 'function') {
// if (false === error.call(element, data, ret)) {
// return false;
// }
// }
});
});
});
},
recyclebin: function () {
// 初始化表格参数配置
@ -121,6 +209,26 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
},
api: {
bindevent: function () {
$(document).on('click', '.btn-changeuser', function (event) {
var url = $(this).attr('data-url');
if(!url) return false;
var title = $(this).attr('title');
var width = $(this).attr('data-width');
var height = $(this).attr('data-height');
// var ids = $(this).attr('data-id');
var area = [$(window).width() > 800 ? (width?width:'800px') : '95%', $(window).height() > 600 ? (height?height:'600px') : '95%'];
var options = {
shadeClose: false,
shade: [0.3, '#393D49'],
area: area,
callback:function(ret){//回调方法需要在本页面Controller中增加方法监听且调用Fast.api.close(ret)传递结果;
Fast.api.close(ret);
}
};
Fast.api.open(url,title,options);
});
Form.api.bindevent($("form[role=form]"));
}
}

View File

@ -22,14 +22,64 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
fixedColumns: true,
fixedRightNumber: 1,
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
{field: 'name', title: __('Name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
{field: 'people_num', title: __('人数'), operate: false},
{field: 'people_names', title: __('成员'), operate: false},
{field: 'opertime', title: __('统计时间查询'), operate:'RANGE', addclass:'datetimerange', autocomplete:false,formatter:function (value, row, index) {
return row.opertime ? row.opertime : '未查询';
}},
{field: 'score_count', title: __('积分统计(根据具体统计时间筛选)'),formatter:function (value, row, index) {
// if( !row.opertime){
// return "<span style='color: #0d6aad'>#请在点开【搜索栏】后选择【统计时间查询】提交查询#</span>";
// }
return `
<span style="color: #0d6aad">${row.score_count}</span>
`;
},searchable:false},
{field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
{field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
// {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
{field: 'operate', title: __('Operate'), table: table , buttons: [
{
name: 'select',
text: __('积分记录'),
title: __('查看积分记录'),
classname: 'btn btn-xs btn-primary btn-dialog',
icon: 'fa fa-list',
url: log_url,
callback: function (data) {
},
// visible: function (row) {
// if(row.status == '1' || row.status == '2' ) return true;
// return false;
// }
},
{
name: 'select2',
text: __('队员详情'),
title: __('队员详情'),
classname: 'btn btn-xs btn-primary btn-dialog',
icon: 'fa fa-list',
url: employee_url,
callback: function (data) {
},
// visible: function (row) {
// if(row.status == '1' || row.status == '2' ) return true;
// return false;
// }
},
], events: Table.api.events.operate, formatter: Table.api.formatter.operate},
]
]
});
@ -45,9 +95,38 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
},
api: {
bindevent: function () {
$(document).on('click', '.btn-changeuser', function (event) {
var url = $(this).attr('data-url');
if(!url) return false;
var title = $(this).attr('title');
var width = $(this).attr('data-width');
var height = $(this).attr('data-height');
// var ids = $(this).attr('data-id');
var area = [$(window).width() > 800 ? (width?width:'800px') : '95%', $(window).height() > 600 ? (height?height:'600px') : '95%'];
var options = {
shadeClose: false,
shade: [0.3, '#393D49'],
area: area,
callback:function(ret){//回调方法需要在本页面Controller中增加方法监听且调用Fast.api.close(ret)传递结果;
Fast.api.close(ret);
}
};
Fast.api.open(url,title,options);
});
Form.api.bindevent($("form[role=form]"));
}
}
};
var log_url = function (row,dom) {
return 'score/log/index?score_team_id='+row.id;
}
var employee_url= function (row,dom) {
return 'score/employee/index?team_id='+row.id;
}
return Controller;
});

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB