CourseOrder.php
1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
namespace app\mobile\model;
use think\Model;
use think\Db;
class CourseOrder extends Model
{
// 表名
protected $name = 'mobile_course_order';
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
// 课程信息
public function course(){
return $this->belongsTo('Course');
}
/**
* 新增订单
*/
public function add($user, $order, $pay_type)
{
Db::startTrans();
$save_data = [
'user_id' => $user['id'],
'course_id' => $order['course_info']['id'],
'order_sn' => get_order_sn(),
'pay_price' => $order['pay_price'],
'pay_type' => $pay_type,
'course_price' => $order['course_price'],
];
// 记录订单信息
if($user['group_id'] == 1){
$this->save(array_merge([
'company_id' => Company::where('user_id',$user['id'])->value('id'),
'people_num' => $order['spec_info']['people_num'],
'course_spec_id' => $order['spec_info']['id'],
'is_top' => $order['spec_info']['is_top']
],$save_data));
}else{
$this->save(array_merge([
'score' => $order['score_info']['use_score'],
'score_price' => $order['score_info']['score_price'],
],$save_data));
// 用掉积分
if($order['score_info']['use_score'] > 0){
\app\common\model\User::score(-$order['score_info']['use_score'],$user['id'],'课程下单-使用积分');
}
}
Db::commit();
return true;
}
}