NotifyCommonController.php
6.3 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<?php
/**
* Created by PhpStorm.
* User: 29925
* Date: 2018/7/23
* Time: 15:19
*/
namespace api\portal\controller;
use api\portal\model\AgencyModel;
use api\portal\model\MemberModel;
use api\portal\model\MoneyDetailModel;
use api\portal\model\OrderModel;
use api\portal\model\RewardModel;
use api\portal\model\UserNeedModel;
use cmf\controller\HomeBaseController;
use think\Db;
class NotifyCommonController extends HomeBaseController
{
public function results() {
return 1;
}
/**
* 支付回调处理方法(通用)
* @param where 回调订单的where条件(含订单号,支付金额)
* @param transaction_id 支付业务参数
* @param pay_type 支付类型
* @param title 支付原因
*/
public function changeOrderStatus($where, $transaction_id, $pay_type, $title) {
$order_model = new OrderModel();
$orderInfo = $order_model->where($where)->find();
if($orderInfo['status'] == 1) {
$order_model->startTrans();
$update = [
'status' => 2,
'pay_type' => $pay_type,
'pay_time' => time(),
'transaction_id'=>$transaction_id
];
// 根据支付类型修改不同表的数据
if($orderInfo['type'] == 1) {
$user_need_model = new UserNeedModel();
$pay = $order_model->where($where)->update($update);
$status = $user_need_model->where(['id'=>$orderInfo['need_id']])->update(['status'=>2,'pay_time'=>time()]);
}
if($orderInfo['type'] == 2) {
$agency_model = new AgencyModel();
$pay = $order_model->where($where)->update($update);
$status = $agency_model->where(['id'=>$orderInfo['need_id']])->update(['status'=>2,'pay_time'=>time()]);
// 增加中介报价人数
$need_id = $agency_model->where(['id'=>$orderInfo['need_id']])->value('need_id');
$user_need_model = new UserNeedModel();
$change_people = $user_need_model->where(['id'=>$need_id])->setInc('people');
if(!$change_people) {
return 0;
}
}
if($orderInfo['type'] == 3) {
// $Intermediary = controller('Intermediary','controller');
// $agencyOffer = $Intermediary->agencyOffer($orderInfo['user_id'],
$agencyOffer = $this->agencyOffer($orderInfo['user_id'],$orderInfo['need_id']);
if(empty($agencyOffer) || empty($agencyOffer['money'])) {
return 0;
} else {
$update['lower_price'] = $agencyOffer['money'];
}
$pay = $order_model->where($where)->update($update);
$status = 1;
}
if(!$pay || !$status) {
$order_model->rollback();
return 0;
}
// 记录用户金额记录
$member_model = new MemberModel();
$user = $member_model->field(['id,type,referee_id'])->where(['id'=>$orderInfo['user_id']])->find();
if(!$user) {
$order_model->rollback();
return 0;
}
$money_detail_model = new MoneyDetailModel();
if($orderInfo['type'] == 1) {
$order_type = 1;
}
if($orderInfo['type'] == 2) {
$order_type = 2;
}
if($orderInfo['type'] == 3) {
$order_type = 3;
}
$insert = [
'order_id' => $orderInfo['id'],
'user_id' => $user['id'],
'user_type' => $user['type'],
'title' => $title,
'money' => $orderInfo['money'],
'order_type' => $order_type,
'type' => 2,
'pay_type' => $pay_type,
'create_time' => time(),
'update_time' => time()
];
$money_detail_insert = $money_detail_model->insertGetId($insert);
if(!$money_detail_insert) {
$order_model->rollback();
return 0;
}
$order_model->commit();
return 1;
}
}
// 查询中介报价
// $need_id 需求id
public function agencyOffer($user_id,$need_id){
$where_agency['status'] = 2;
$where_agency['create_time'] = array('lt',time());
$where_agency['need_id'] = $need_id;
$agency_list = Db::name('Agency')
->where($where_agency)
->field("id,housing_price,assessment_tax,security_tax,else_tax,service_charge,refuse_complaint_time")
->select()->toArray();
$final_list = array();
$add_arr = array();
$is_trueMoney = array();
if($agency_list){
foreach ($agency_list as $agencyk=>$agencyv){
$money = $agencyv['housing_price'] + $agencyv['assessment_tax'] + $agencyv['security_tax'] + $agencyv['else_tax'] + $agencyv['service_charge'] ;
if($money > 100000){
$agencyv['need_id'] = $need_id;
$agencyv['agency_id'] = $agencyv['id'];
$agencyv['user_id'] = $user_id;
$money_arr[] = $money;
$fianlMoney = substr($money, 0,-4);
$agencyv['true_money'] = $money;
$agencyv['money'] = $money;
$is_trueMoney[] = $agencyv;
}
}
sort($money_arr);
foreach ($is_trueMoney as $finalk=>$finalv){
if($finalv['true_money'] == $money_arr[0]){
$add_arr['need_id'] = $finalv['need_id'];
$add_arr['agency_id'] = $finalv['agency_id'];
$add_arr['user_id'] = $finalv['user_id'];
$add_arr['money'] = $finalv['money'];
$add_arr['create_time'] = time();
$add_arr['update_time'] = time();
}
}
$save = Db::name('See')->insertGetId($add_arr);
$return['id'] = $save;
$return['money'] = $add_arr['money'];
$return['time'] = time();
return $return;
}
}
}