作者 anyv
1 个管道 的构建 通过 耗费 0 秒

支付测试

@@ -91,167 +91,173 @@ class PayController extends HomeBaseController @@ -91,167 +91,173 @@ class PayController extends HomeBaseController
91 return 'Order not exist.'; // 告诉微信,我已经处理完了,订单没找到,别再通知我了 91 return 'Order not exist.'; // 告诉微信,我已经处理完了,订单没找到,别再通知我了
92 } 92 }
93 if($successful){ 93 if($successful){
94 -  
95 - $update['state'] = 2;  
96 - //更新订单状态为待发货  
97 - Db::name('indent')->where('order_number',$out_trade_no)->update($update);  
98 - $uid = $order['uid'];  
99 - //查询当前用户身份  
100 - $data_user = Db::name('my_user')->where('uid',$uid)->find();  
101 - if($order['indent_type'] == 1){  
102 - //如果是平台商品 学生购买  
103 - if($data_user['status'] == 4){  
104 - //查询平台商品老师和业务员所占的佣金比例  
105 - $money_ratio = Db::name('money_ratio') -> where('id',1) -> find();  
106 - //查询这条订单下的所有商品  
107 - $data_indent_goods = Db::name('indent_goods') -> where('indent_id',$order['id']) -> select();  
108 - $money_salesman = 0;  
109 - //查询老师的uid  
110 - $teacher = Db::name('my_user') -> where('id',$data_user['pid']) -> find();  
111 - //查询业务员的uid  
112 - $salesman = Db::name('my_user') -> where('id',$teacher['pid']) -> find();  
113 - foreach ($data_indent_goods as $key => $val){  
114 - $money_salesman += $val['price']*$val['number']*$money_ratio['salesman_ratio'];  
115 - $data_money_income_salesman['create_time'] = time();  
116 - $data_money_income_salesman['money'] = $money_salesman;  
117 - $data_money_income_salesman['type'] = 1;  
118 - $data_money_income_salesman['book_name'] = $val['book_name'];  
119 - $data_money_income_salesman['book_thumbnail'] = $val['thumbnail'];  
120 - $data_money_income_salesman['book_num'] = $val['number'];  
121 - $data_money_income_salesman['uid'] = $salesman['uid'];  
122 - Db::name('money_income') -> insert($data_money_income_salesman); 94 + Db::startTrans();
  95 + try {
  96 + $update['state'] = 2;
  97 + //更新订单状态为待发货
  98 + Db::name('indent')->where('order_number',$out_trade_no)->update($update);
  99 + $uid = $order['uid'];
  100 + //查询当前用户身份
  101 + $data_user = Db::name('my_user')->where('uid',$uid)->find();
  102 + if($order['indent_type'] == 1){
  103 + //如果是平台商品 学生购买
  104 + if($data_user['status'] == 4){
  105 + //查询平台商品老师和业务员所占的佣金比例
  106 + $money_ratio = Db::name('money_ratio') -> where('id',1) -> find();
  107 + //查询这条订单下的所有商品
  108 + $data_indent_goods = Db::name('indent_goods') -> where('indent_id',$order['id']) -> select();
  109 + $money_salesman = 0;
  110 + //查询老师的uid
  111 + $teacher = Db::name('my_user') -> where('id',$data_user['pid']) -> find();
  112 + //查询业务员的uid
  113 + $salesman = Db::name('my_user') -> where('id',$teacher['pid']) -> find();
  114 + foreach ($data_indent_goods as $key => $val){
  115 + $money_salesman += $val['price']*$val['number']*$money_ratio['salesman_ratio'];
  116 + $data_money_income_salesman['create_time'] = time();
  117 + $data_money_income_salesman['money'] = $money_salesman;
  118 + $data_money_income_salesman['type'] = 1;
  119 + $data_money_income_salesman['book_name'] = $val['book_name'];
  120 + $data_money_income_salesman['book_thumbnail'] = $val['thumbnail'];
  121 + $data_money_income_salesman['book_num'] = $val['number'];
  122 + $data_money_income_salesman['uid'] = $salesman['uid'];
  123 + Db::name('money_income') -> insert($data_money_income_salesman);
  124 + }
  125 + Db::name('my_user') -> where('uid',$salesman['uid']) -> setInc('balance',$money_salesman);
  126 +
  127 + $money_teacher = 0;
  128 + foreach ($data_indent_goods as $key => $val){
  129 + $money_teacher += $val['price']*$val['number']*$money_ratio['teacher_ratio'];
  130 + $data_money_income_teacher['create_time'] = time();
  131 + $data_money_income_teacher['money'] = $money_teacher;
  132 + $data_money_income_teacher['type'] = 1;
  133 + $data_money_income_teacher['book_name'] = $val['book_name'];
  134 + $data_money_income_teacher['book_thumbnail'] = $val['thumbnail'];
  135 + $data_money_income_teacher['book_num'] = $val['number'];
  136 + $data_money_income_teacher['uid'] = $teacher['uid'];
  137 + Db::name('money_income') -> insert($data_money_income_teacher);
  138 + }
  139 + Db::name('my_user') -> where('uid',$teacher['uid']) -> setInc('balance',$money_teacher);
123 } 140 }
124 - Db::name('my_user') -> where('uid',$salesman['uid']) -> setInc('balance',$money_salesman);  
125 -  
126 - $money_teacher = 0;  
127 - foreach ($data_indent_goods as $key => $val){  
128 - $money_teacher += $val['price']*$val['number']*$money_ratio['teacher_ratio'];  
129 - $data_money_income_teacher['create_time'] = time();  
130 - $data_money_income_teacher['money'] = $money_teacher;  
131 - $data_money_income_teacher['type'] = 1;  
132 - $data_money_income_teacher['book_name'] = $val['book_name'];  
133 - $data_money_income_teacher['book_thumbnail'] = $val['thumbnail'];  
134 - $data_money_income_teacher['book_num'] = $val['number'];  
135 - $data_money_income_teacher['uid'] = $teacher['uid'];  
136 - Db::name('money_income') -> insert($data_money_income_teacher); 141 + //如果是平台商品 老师购买
  142 + if($data_user['status'] == 3){
  143 + //查询平台商品老师和业务员所占的佣金比例
  144 + $money_ratio = Db::name('money_ratio') -> where('id',1) -> find();
  145 + //查询这条订单下的所有商品
  146 + $data_indent_goods = Db::name('indent_goods') -> where('indent_id',$order['id']) -> select();
  147 + $money_salesman = 0;
  148 + //查询老师的uid
  149 + /* $teacher = Db::name('my_user') -> where('id',$data_user['pid']) -> find();*/
  150 + //查询业务员的uid
  151 + $salesman = Db::name('my_user') -> where('id',$data_user['pid']) -> find();
  152 + foreach ($data_indent_goods as $key => $val){
  153 + $money_salesman += $val['price']*$val['number']*$money_ratio['salesman_ratio'];
  154 + $data_money_income_salesman['create_time'] = time();
  155 + $data_money_income_salesman['money'] = $money_salesman;
  156 + $data_money_income_salesman['type'] = 1;
  157 + $data_money_income_salesman['book_name'] = $val['book_name'];
  158 + $data_money_income_salesman['book_thumbnail'] = $val['thumbnail'];
  159 + $data_money_income_salesman['book_num'] = $val['number'];
  160 + $data_money_income_salesman['uid'] = $salesman['uid'];
  161 + Db::name('money_income') -> insert($data_money_income_salesman);
  162 + }
  163 + Db::name('my_user') -> where('uid',$salesman['uid']) -> setInc('balance',$money_salesman);
  164 + $money_teacher = 0;
  165 + foreach ($data_indent_goods as $key => $val){
  166 + $money_teacher += $val['price']*$val['number']*$money_ratio['teacher_ratio'];
  167 + $data_money_income_teacher['create_time'] = time();
  168 + $data_money_income_teacher['money'] = $money_teacher;
  169 + $data_money_income_teacher['type'] = 1;
  170 + $data_money_income_teacher['book_name'] = $val['book_name'];
  171 + $data_money_income_teacher['book_thumbnail'] = $val['thumbnail'];
  172 + $data_money_income_teacher['book_num'] = $val['number'];
  173 + $data_money_income_teacher['uid'] = $data_user['uid'];
  174 + Db::name('money_income') -> insert($data_money_income_teacher);
  175 + }
  176 + Db::name('my_user') -> where('uid',$data_user['uid']) -> setInc('balance',$money_teacher);
137 } 177 }
138 - Db::name('my_user') -> where('uid',$teacher['uid']) -> setInc('balance',$money_teacher);  
139 - }  
140 - //如果是平台商品 老师购买  
141 - if($data_user['status'] == 3){ 178 + }else if($order['indent_type'] == 2){
  179 + //如果是业务员订单
142 //查询平台商品老师和业务员所占的佣金比例 180 //查询平台商品老师和业务员所占的佣金比例
143 $money_ratio = Db::name('money_ratio') -> where('id',1) -> find(); 181 $money_ratio = Db::name('money_ratio') -> where('id',1) -> find();
  182 + //判断这条订单是否为快递配送
  183 + if($order['is_courier'] == 2){
  184 + $order['money'] = $order['money']-$money_ratio['courier'];
  185 + }
144 //查询这条订单下的所有商品 186 //查询这条订单下的所有商品
145 $data_indent_goods = Db::name('indent_goods') -> where('indent_id',$order['id']) -> select(); 187 $data_indent_goods = Db::name('indent_goods') -> where('indent_id',$order['id']) -> select();
146 - $money_salesman = 0;  
147 - //查询老师的uid  
148 - /* $teacher = Db::name('my_user') -> where('id',$data_user['pid']) -> find();*/  
149 - //查询业务员的uid  
150 - $salesman = Db::name('my_user') -> where('id',$data_user['pid']) -> find();  
151 - foreach ($data_indent_goods as $key => $val){  
152 - $money_salesman += $val['price']*$val['number']*$money_ratio['salesman_ratio'];  
153 - $data_money_income_salesman['create_time'] = time();  
154 - $data_money_income_salesman['money'] = $money_salesman;  
155 - $data_money_income_salesman['type'] = 1;  
156 - $data_money_income_salesman['book_name'] = $val['book_name'];  
157 - $data_money_income_salesman['book_thumbnail'] = $val['thumbnail'];  
158 - $data_money_income_salesman['book_num'] = $val['number'];  
159 - $data_money_income_salesman['uid'] = $salesman['uid'];  
160 - Db::name('money_income') -> insert($data_money_income_salesman);  
161 - }  
162 - Db::name('my_user') -> where('uid',$salesman['uid']) -> setInc('balance',$money_salesman);  
163 - $money_teacher = 0;  
164 - foreach ($data_indent_goods as $key => $val){  
165 - $money_teacher += $val['price']*$val['number']*$money_ratio['teacher_ratio'];  
166 - $data_money_income_teacher['create_time'] = time();  
167 - $data_money_income_teacher['money'] = $money_teacher;  
168 - $data_money_income_teacher['type'] = 1;  
169 - $data_money_income_teacher['book_name'] = $val['book_name'];  
170 - $data_money_income_teacher['book_thumbnail'] = $val['thumbnail'];  
171 - $data_money_income_teacher['book_num'] = $val['number'];  
172 - $data_money_income_teacher['uid'] = $data_user['uid'];  
173 - Db::name('money_income') -> insert($data_money_income_teacher);  
174 - }  
175 - Db::name('my_user') -> where('uid',$data_user['uid']) -> setInc('balance',$money_teacher);  
176 - }  
177 - }else if($order['indent_type'] == 2){  
178 - //如果是业务员订单  
179 - //查询平台商品老师和业务员所占的佣金比例  
180 - $money_ratio = Db::name('money_ratio') -> where('id',1) -> find();  
181 - //判断这条订单是否为快递配送  
182 - if($order['is_courier'] == 2){  
183 - $order['money'] = $order['money']-$money_ratio['courier'];  
184 - }  
185 - //查询这条订单下的所有商品  
186 - $data_indent_goods = Db::name('indent_goods') -> where('indent_id',$order['id']) -> select();  
187 - //业务员商品学生购买  
188 - if($data_user['status'] == 4){  
189 - $teacher = Db::name('my_user') -> where('id',$data_user['pid']) -> find();  
190 - $money = 0;  
191 - foreach ($data_indent_goods as $key => $val){  
192 - $money += $val['commission']*$val['number'];  
193 - $money_income_teacher['create_time'] = time();  
194 - $money_income_teacher['money'] = $money;  
195 - $money_income_teacher['type'] = 2;  
196 - $money_income_teacher['book_name'] = $val['book_name'];  
197 - $money_income_teacher['book_thumbnail'] = $val['thumbnail'];  
198 - $money_income_teacher['book_num'] = $val['number'];  
199 - $money_income_teacher['uid'] = $teacher['uid'];  
200 - Db::name('money_income') -> insert($money_income_teacher); 188 + //业务员商品学生购买
  189 + if($data_user['status'] == 4){
  190 + $teacher = Db::name('my_user') -> where('id',$data_user['pid']) -> find();
  191 + $money = 0;
  192 + foreach ($data_indent_goods as $key => $val){
  193 + $money += $val['commission']*$val['number'];
  194 + $money_income_teacher['create_time'] = time();
  195 + $money_income_teacher['money'] = $money;
  196 + $money_income_teacher['type'] = 2;
  197 + $money_income_teacher['book_name'] = $val['book_name'];
  198 + $money_income_teacher['book_thumbnail'] = $val['thumbnail'];
  199 + $money_income_teacher['book_num'] = $val['number'];
  200 + $money_income_teacher['uid'] = $teacher['uid'];
  201 + Db::name('money_income') -> insert($money_income_teacher);
  202 + }
  203 + //增加老师余额
  204 + Db::name('my_user') -> where('uid',$teacher['uid']) -> setInc('balance',$money);
  205 + //计算业务员这条订单的收入
  206 + $balance_salesman = $order['money'] - $order['money']*$money_ratio['platform_ratio'] - $money;
  207 + //增加业务员的余额
  208 + Db::name('my_user') -> where('uid',$order['salesman_uid']) -> setInc('balance',$balance_salesman);
  209 + //添加业务员的收入记录
  210 + $money_income_salesman_indent['create_time'] = time();
  211 + $money_income_salesman_indent['uid'] = $order['salesman_uid'];
  212 + $money_income_salesman_indent['money'] = $balance_salesman;
  213 + $money_income_salesman_indent['type'] = 2;
  214 + $money_income_salesman_indent['indent_id'] = $order['id'];
  215 + Db::name('money_income') -> insert($money_income_salesman_indent);
  216 +
201 } 217 }
202 - //增加老师余额  
203 - Db::name('my_user') -> where('uid',$teacher['uid']) -> setInc('balance',$money);  
204 - //计算业务员这条订单的收入  
205 - $balance_salesman = $order['money'] - $order['money']*$money_ratio['platform_ratio'] - $money;  
206 - //增加业务员的余额  
207 - Db::name('my_user') -> where('uid',$order['salesman_uid']) -> setInc('balance',$balance_salesman);  
208 - //添加业务员的收入记录  
209 - $money_income_salesman_indent['create_time'] = time();  
210 - $money_income_salesman_indent['uid'] = $order['salesman_uid'];  
211 - $money_income_salesman_indent['money'] = $balance_salesman;  
212 - $money_income_salesman_indent['type'] = 2;  
213 - $money_income_salesman_indent['indent_id'] = $order['id'];  
214 - Db::name('money_income') -> insert($money_income_salesman_indent); 218 + //业务员商品老师购买
  219 + if ($data_user['status'] == 3){
  220 + $teacher = $data_user['uid'];
  221 + $money = 0;
  222 + foreach ($data_indent_goods as $key => $val){
  223 + $money += $val['commission']*$val['number'];
  224 + $money_income_teacher['create_time'] = time();
  225 + $money_income_teacher['money'] = $money;
  226 + $money_income_teacher['type'] = 2;
  227 + $money_income_teacher['book_name'] = $val['book_name'];
  228 + $money_income_teacher['book_thumbnail'] = $val['thumbnail'];
  229 + $money_income_teacher['book_num'] = $val['number'];
  230 + $money_income_teacher['uid'] = $teacher;
  231 + Db::name('money_income') -> insert($money_income_teacher);
  232 + }
  233 + //增加老师余额
  234 + Db::name('my_user') -> where('uid',$teacher) -> setInc('balance',$money);
  235 + //计算业务员这条订单的收入
  236 + $balance_salesman = $order['money'] - $order['money']*$money_ratio['platform_ratio'] - $money;
  237 + //增加业务员的余额
  238 + Db::name('my_user') -> where('uid',$order['salesman_uid']) -> setInc('balance',$balance_salesman);
  239 + //添加业务员的收入记录
  240 + $money_income_salesman_indent['create_time'] = time();
  241 + $money_income_salesman_indent['uid'] = $order['salesman_uid'];
  242 + $money_income_salesman_indent['money'] = $balance_salesman;
  243 + $money_income_salesman_indent['type'] = 2;
  244 + $money_income_salesman_indent['indent_id'] = $order['id'];
  245 + Db::name('money_income') -> insert($money_income_salesman_indent);
215 246
216 - }  
217 - //业务员商品老师购买  
218 - if ($data_user['status'] == 3){  
219 - $teacher = $data_user['uid'];  
220 - $money = 0;  
221 - foreach ($data_indent_goods as $key => $val){  
222 - $money += $val['commission']*$val['number'];  
223 - $money_income_teacher['create_time'] = time();  
224 - $money_income_teacher['money'] = $money;  
225 - $money_income_teacher['type'] = 2;  
226 - $money_income_teacher['book_name'] = $val['book_name'];  
227 - $money_income_teacher['book_thumbnail'] = $val['thumbnail'];  
228 - $money_income_teacher['book_num'] = $val['number'];  
229 - $money_income_teacher['uid'] = $teacher;  
230 - Db::name('money_income') -> insert($money_income_teacher);  
231 } 247 }
232 - //增加老师余额  
233 - Db::name('my_user') -> where('uid',$teacher) -> setInc('balance',$money);  
234 - //计算业务员这条订单的收入  
235 - $balance_salesman = $order['money'] - $order['money']*$money_ratio['platform_ratio'] - $money;  
236 - //增加业务员的余额  
237 - Db::name('my_user') -> where('uid',$order['salesman_uid']) -> setInc('balance',$balance_salesman);  
238 - //添加业务员的收入记录  
239 - $money_income_salesman_indent['create_time'] = time();  
240 - $money_income_salesman_indent['uid'] = $order['salesman_uid'];  
241 - $money_income_salesman_indent['money'] = $balance_salesman;  
242 - $money_income_salesman_indent['type'] = 2;  
243 - $money_income_salesman_indent['indent_id'] = $order['id'];  
244 - Db::name('money_income') -> insert($money_income_salesman_indent);  
245 248
246 } 249 }
247 - 250 + Db::commit();
  251 + } catch (Exception $e) {
  252 + Db::rollback();
248 } 253 }
249 - cache('a1',"789"); 254 +
  255 + /*cache('a1',"789");
250 $bird = new BirdController; 256 $bird = new BirdController;
251 $createOrder = $bird -> createOrder($order['id']); 257 $createOrder = $bird -> createOrder($order['id']);
252 cache('yuyue1',$createOrder); 258 cache('yuyue1',$createOrder);
253 $takeOrder = $bird -> takeOrder($order['id']); 259 $takeOrder = $bird -> takeOrder($order['id']);
254 - cache('dingyue1',$takeOrder); 260 + cache('dingyue1',$takeOrder);*/
255 } 261 }
256 return true; // 返回处理完成 262 return true; // 返回处理完成
257 }); 263 });