正在显示
5 个修改的文件
包含
105 行增加
和
1 行删除
@@ -3,6 +3,10 @@ | @@ -3,6 +3,10 @@ | ||
3 | namespace app\api\controller; | 3 | namespace app\api\controller; |
4 | 4 | ||
5 | use app\common\controller\Api; | 5 | use app\common\controller\Api; |
6 | +use app\common\model\Item; | ||
7 | +use app\common\model\Study; | ||
8 | +use app\common\model\StudyScoreLog; | ||
9 | +use app\common\model\Team; | ||
6 | use think\Db; | 10 | use think\Db; |
7 | use think\Exception; | 11 | use think\Exception; |
8 | use think\exception\PDOException; | 12 | use think\exception\PDOException; |
@@ -192,6 +196,8 @@ class Bind extends Api | @@ -192,6 +196,8 @@ class Bind extends Api | ||
192 | if (empty($unique) && empty($id)) { | 196 | if (empty($unique) && empty($id)) { |
193 | $this->error('参数错误', ['status' => 2]); | 197 | $this->error('参数错误', ['status' => 2]); |
194 | } | 198 | } |
199 | + $model = new StudyScoreLog(); | ||
200 | + $model->addScore($id,$unique); | ||
195 | $study = db('study')->where('unique', $unique)->field('id,grade,name,team,earn_score')->find(); | 201 | $study = db('study')->where('unique', $unique)->field('id,grade,name,team,earn_score')->find(); |
196 | $item = db('item')->where('id', $id)->field('score,title,campus_id')->find(); | 202 | $item = db('item')->where('id', $id)->field('score,title,campus_id')->find(); |
197 | $team = \db('team')->where('title', $study['team'])->field('title,score')->find(); | 203 | $team = \db('team')->where('title', $study['team'])->field('title,score')->find(); |
@@ -340,7 +346,7 @@ class Bind extends Api | @@ -340,7 +346,7 @@ class Bind extends Api | ||
340 | $sid = \db('study')->where('user_id', $user['id'])->value('id'); | 346 | $sid = \db('study')->where('user_id', $user['id'])->value('id'); |
341 | //获取学生的信息 | 347 | //获取学生的信息 |
342 | $data = \db('study')->where('id', $sid)->field('avatar,name,earn_score')->find(); | 348 | $data = \db('study')->where('id', $sid)->field('avatar,name,earn_score')->find(); |
343 | - $data['avatar'] = cdnurl( $data['avatar'], true); | 349 | + $data['avatar'] = cdnurl($data['avatar'], true); |
344 | //获取雷达维度 | 350 | //获取雷达维度 |
345 | $data['item'] = \db('study_score_log') | 351 | $data['item'] = \db('study_score_log') |
346 | ->distinct('item_id') | 352 | ->distinct('item_id') |
application/common/model/Study.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +namespace app\common\model; | ||
4 | + | ||
5 | +use think\Db; | ||
6 | +use think\Model; | ||
7 | + | ||
8 | +class Study extends Model | ||
9 | +{ | ||
10 | + // 表名 | ||
11 | + protected $name = 'study'; | ||
12 | + // 自动写入时间戳字段 | ||
13 | + protected $autoWriteTimestamp = 'int'; | ||
14 | + // 定义时间戳字段名 | ||
15 | + protected $createTime = 'createtime'; | ||
16 | + protected $updateTime = 'updatetime'; | ||
17 | + // 追加属性 | ||
18 | + protected $append = [ | ||
19 | + ]; | ||
20 | + | ||
21 | + | ||
22 | + /** | ||
23 | + * 变更会员余额 | ||
24 | + * @param int $score 余额 | ||
25 | + * @param int $study_id 会员ID | ||
26 | + * @param string $memo 备注 | ||
27 | + */ | ||
28 | + public static function score($score, $study_id, $memo) | ||
29 | + { | ||
30 | + Db::startTrans(); | ||
31 | + try { | ||
32 | + $study = self::lock(true)->find($study_id); | ||
33 | + if ($study && $score != 0) { | ||
34 | + $after = function_exists('bcadd') ? bcadd($study->earn_score, $score, 2) : $study->earn_score + $score; | ||
35 | + //更新会员信息 | ||
36 | + $study->save(['score' => $after]); | ||
37 | + //写入日志 | ||
38 | + StudyScoreLog::create(['study_id' => $study_id, 'score' => $score, 'memo' => $memo]); | ||
39 | + } | ||
40 | + Db::commit(); | ||
41 | + } catch (\Exception $e) { | ||
42 | + Db::rollback(); | ||
43 | + } | ||
44 | + } | ||
45 | +} |
application/common/model/StudyScoreLog.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +namespace app\common\model; | ||
4 | + | ||
5 | +use think\Model; | ||
6 | + | ||
7 | +class StudyScoreLog extends Model | ||
8 | +{ | ||
9 | + // 表名 | ||
10 | + protected $name = 'study_score_log'; | ||
11 | + // 自动写入时间戳字段 | ||
12 | + protected $autoWriteTimestamp = 'int'; | ||
13 | + // 定义时间戳字段名 | ||
14 | + protected $createTime = 'createtime'; | ||
15 | + protected $updateTime = 'updatetime'; | ||
16 | + // 追加属性 | ||
17 | + protected $append = [ | ||
18 | + | ||
19 | + ]; | ||
20 | + | ||
21 | + | ||
22 | + //加分 | ||
23 | + public function addScore($id,$unique){ | ||
24 | + $study = new Study(); | ||
25 | + $team = new Team(); | ||
26 | + $item = new Item(); | ||
27 | + $stu = $study->where('unique',$unique)->find()->toArray(); | ||
28 | + $xm = $item->where('id',$id)->find()->toArray(); | ||
29 | + | ||
30 | + } | ||
31 | + | ||
32 | +} |
application/common/model/Team.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +namespace app\common\model; | ||
4 | + | ||
5 | +use think\Model; | ||
6 | + | ||
7 | +class Team extends Model | ||
8 | +{ | ||
9 | + // 表名 | ||
10 | + protected $name = 'team'; | ||
11 | + // 自动写入时间戳字段 | ||
12 | + protected $autoWriteTimestamp = 'int'; | ||
13 | + // 定义时间戳字段名 | ||
14 | + protected $createTime = 'createtime'; | ||
15 | + protected $updateTime = 'updatetime'; | ||
16 | + // 追加属性 | ||
17 | + protected $append = [ | ||
18 | + | ||
19 | + ]; | ||
20 | +} |
-
请 注册 或 登录 后发表评论