作者 开飞机的舒克

学生得分

... ... @@ -3,6 +3,10 @@
namespace app\api\controller;
use app\common\controller\Api;
use app\common\model\Item;
use app\common\model\Study;
use app\common\model\StudyScoreLog;
use app\common\model\Team;
use think\Db;
use think\Exception;
use think\exception\PDOException;
... ... @@ -192,6 +196,8 @@ class Bind extends Api
if (empty($unique) && empty($id)) {
$this->error('参数错误', ['status' => 2]);
}
$model = new StudyScoreLog();
$model->addScore($id,$unique);
$study = db('study')->where('unique', $unique)->field('id,grade,name,team,earn_score')->find();
$item = db('item')->where('id', $id)->field('score,title,campus_id')->find();
$team = \db('team')->where('title', $study['team'])->field('title,score')->find();
... ... @@ -340,7 +346,7 @@ class Bind extends Api
$sid = \db('study')->where('user_id', $user['id'])->value('id');
//获取学生的信息
$data = \db('study')->where('id', $sid)->field('avatar,name,earn_score')->find();
$data['avatar'] = cdnurl( $data['avatar'], true);
$data['avatar'] = cdnurl($data['avatar'], true);
//获取雷达维度
$data['item'] = \db('study_score_log')
->distinct('item_id')
... ...
... ... @@ -58,4 +58,5 @@ class Item extends Model
return $title;
}
}
\ No newline at end of file
... ...
<?php
namespace app\common\model;
use think\Db;
use think\Model;
class Study extends Model
{
// 表名
protected $name = 'study';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
// 追加属性
protected $append = [
];
/**
* 变更会员余额
* @param int $score 余额
* @param int $study_id 会员ID
* @param string $memo 备注
*/
public static function score($score, $study_id, $memo)
{
Db::startTrans();
try {
$study = self::lock(true)->find($study_id);
if ($study && $score != 0) {
$after = function_exists('bcadd') ? bcadd($study->earn_score, $score, 2) : $study->earn_score + $score;
//更新会员信息
$study->save(['score' => $after]);
//写入日志
StudyScoreLog::create(['study_id' => $study_id, 'score' => $score, 'memo' => $memo]);
}
Db::commit();
} catch (\Exception $e) {
Db::rollback();
}
}
}
\ No newline at end of file
... ...
<?php
namespace app\common\model;
use think\Model;
class StudyScoreLog extends Model
{
// 表名
protected $name = 'study_score_log';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
// 追加属性
protected $append = [
];
//加分
public function addScore($id,$unique){
$study = new Study();
$team = new Team();
$item = new Item();
$stu = $study->where('unique',$unique)->find()->toArray();
$xm = $item->where('id',$id)->find()->toArray();
}
}
\ No newline at end of file
... ...
<?php
namespace app\common\model;
use think\Model;
class Team extends Model
{
// 表名
protected $name = 'team';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
// 追加属性
protected $append = [
];
}
\ No newline at end of file
... ...