TeamGroup.php
1.8 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
58
59
<?php
namespace app\api\model;
use app\api\controller\Pay;
use think\Model;
use think\Db;
class TeamGroup extends Model
{
public function selectData($where, $limit)
{
$where['status'] = 1;
$where['grouptime'] = ['>',time()];
$data = $this
->where($where)
->limit($limit)
->order('createtime desc')
->field('id team_group_id,user_avatar,user_nickname,grouptime,group_num ')
->select();
return $data;
}
public function pastDue($ids){
Db::startTrans();
$orderModel = new Order();
$pay = new Pay();
$userModel = new User();
try {
//修改拼团表状态
$res1 = $this->where(['id'=>['in',$ids]])->update(['status'=>3]);
//修改订单表拼团状态
$res2 = $orderModel->where(['team_group_id'=>['in',$ids]])->update(['team_group_status'=>3]);
$orderList = $orderModel->where(['team_group_id'=>['in',$ids]])->field('id,order_num,pay_total,pay_type,user_id')->select();
//退款
foreach ($orderList as $k => $orderInfo){
if ($orderInfo['pay_type'] == 1){
//微信退款
$res3 = $pay->refund($orderInfo['order_num'],$orderInfo['pay_total']);
}else{
//余额退款
$res3 = $userModel->refund($orderInfo['user_id'],$orderInfo['pay_total'],$orderInfo['id']);
}
if (!$res3) return false;
}
if ($res1 && $res2){
Db::commit();
return true;
}else{
return false;
}
} catch (Exception $e) {
Db::rollback();
return false;
}
}
}