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

支付测试

... ... @@ -91,167 +91,173 @@ class PayController extends HomeBaseController
return 'Order not exist.'; // 告诉微信,我已经处理完了,订单没找到,别再通知我了
}
if($successful){
$update['state'] = 2;
//更新订单状态为待发货
Db::name('indent')->where('order_number',$out_trade_no)->update($update);
$uid = $order['uid'];
//查询当前用户身份
$data_user = Db::name('my_user')->where('uid',$uid)->find();
if($order['indent_type'] == 1){
//如果是平台商品 学生购买
if($data_user['status'] == 4){
//查询平台商品老师和业务员所占的佣金比例
$money_ratio = Db::name('money_ratio') -> where('id',1) -> find();
//查询这条订单下的所有商品
$data_indent_goods = Db::name('indent_goods') -> where('indent_id',$order['id']) -> select();
$money_salesman = 0;
//查询老师的uid
$teacher = Db::name('my_user') -> where('id',$data_user['pid']) -> find();
//查询业务员的uid
$salesman = Db::name('my_user') -> where('id',$teacher['pid']) -> find();
foreach ($data_indent_goods as $key => $val){
$money_salesman += $val['price']*$val['number']*$money_ratio['salesman_ratio'];
$data_money_income_salesman['create_time'] = time();
$data_money_income_salesman['money'] = $money_salesman;
$data_money_income_salesman['type'] = 1;
$data_money_income_salesman['book_name'] = $val['book_name'];
$data_money_income_salesman['book_thumbnail'] = $val['thumbnail'];
$data_money_income_salesman['book_num'] = $val['number'];
$data_money_income_salesman['uid'] = $salesman['uid'];
Db::name('money_income') -> insert($data_money_income_salesman);
Db::startTrans();
try {
$update['state'] = 2;
//更新订单状态为待发货
Db::name('indent')->where('order_number',$out_trade_no)->update($update);
$uid = $order['uid'];
//查询当前用户身份
$data_user = Db::name('my_user')->where('uid',$uid)->find();
if($order['indent_type'] == 1){
//如果是平台商品 学生购买
if($data_user['status'] == 4){
//查询平台商品老师和业务员所占的佣金比例
$money_ratio = Db::name('money_ratio') -> where('id',1) -> find();
//查询这条订单下的所有商品
$data_indent_goods = Db::name('indent_goods') -> where('indent_id',$order['id']) -> select();
$money_salesman = 0;
//查询老师的uid
$teacher = Db::name('my_user') -> where('id',$data_user['pid']) -> find();
//查询业务员的uid
$salesman = Db::name('my_user') -> where('id',$teacher['pid']) -> find();
foreach ($data_indent_goods as $key => $val){
$money_salesman += $val['price']*$val['number']*$money_ratio['salesman_ratio'];
$data_money_income_salesman['create_time'] = time();
$data_money_income_salesman['money'] = $money_salesman;
$data_money_income_salesman['type'] = 1;
$data_money_income_salesman['book_name'] = $val['book_name'];
$data_money_income_salesman['book_thumbnail'] = $val['thumbnail'];
$data_money_income_salesman['book_num'] = $val['number'];
$data_money_income_salesman['uid'] = $salesman['uid'];
Db::name('money_income') -> insert($data_money_income_salesman);
}
Db::name('my_user') -> where('uid',$salesman['uid']) -> setInc('balance',$money_salesman);
$money_teacher = 0;
foreach ($data_indent_goods as $key => $val){
$money_teacher += $val['price']*$val['number']*$money_ratio['teacher_ratio'];
$data_money_income_teacher['create_time'] = time();
$data_money_income_teacher['money'] = $money_teacher;
$data_money_income_teacher['type'] = 1;
$data_money_income_teacher['book_name'] = $val['book_name'];
$data_money_income_teacher['book_thumbnail'] = $val['thumbnail'];
$data_money_income_teacher['book_num'] = $val['number'];
$data_money_income_teacher['uid'] = $teacher['uid'];
Db::name('money_income') -> insert($data_money_income_teacher);
}
Db::name('my_user') -> where('uid',$teacher['uid']) -> setInc('balance',$money_teacher);
}
Db::name('my_user') -> where('uid',$salesman['uid']) -> setInc('balance',$money_salesman);
$money_teacher = 0;
foreach ($data_indent_goods as $key => $val){
$money_teacher += $val['price']*$val['number']*$money_ratio['teacher_ratio'];
$data_money_income_teacher['create_time'] = time();
$data_money_income_teacher['money'] = $money_teacher;
$data_money_income_teacher['type'] = 1;
$data_money_income_teacher['book_name'] = $val['book_name'];
$data_money_income_teacher['book_thumbnail'] = $val['thumbnail'];
$data_money_income_teacher['book_num'] = $val['number'];
$data_money_income_teacher['uid'] = $teacher['uid'];
Db::name('money_income') -> insert($data_money_income_teacher);
//如果是平台商品 老师购买
if($data_user['status'] == 3){
//查询平台商品老师和业务员所占的佣金比例
$money_ratio = Db::name('money_ratio') -> where('id',1) -> find();
//查询这条订单下的所有商品
$data_indent_goods = Db::name('indent_goods') -> where('indent_id',$order['id']) -> select();
$money_salesman = 0;
//查询老师的uid
/* $teacher = Db::name('my_user') -> where('id',$data_user['pid']) -> find();*/
//查询业务员的uid
$salesman = Db::name('my_user') -> where('id',$data_user['pid']) -> find();
foreach ($data_indent_goods as $key => $val){
$money_salesman += $val['price']*$val['number']*$money_ratio['salesman_ratio'];
$data_money_income_salesman['create_time'] = time();
$data_money_income_salesman['money'] = $money_salesman;
$data_money_income_salesman['type'] = 1;
$data_money_income_salesman['book_name'] = $val['book_name'];
$data_money_income_salesman['book_thumbnail'] = $val['thumbnail'];
$data_money_income_salesman['book_num'] = $val['number'];
$data_money_income_salesman['uid'] = $salesman['uid'];
Db::name('money_income') -> insert($data_money_income_salesman);
}
Db::name('my_user') -> where('uid',$salesman['uid']) -> setInc('balance',$money_salesman);
$money_teacher = 0;
foreach ($data_indent_goods as $key => $val){
$money_teacher += $val['price']*$val['number']*$money_ratio['teacher_ratio'];
$data_money_income_teacher['create_time'] = time();
$data_money_income_teacher['money'] = $money_teacher;
$data_money_income_teacher['type'] = 1;
$data_money_income_teacher['book_name'] = $val['book_name'];
$data_money_income_teacher['book_thumbnail'] = $val['thumbnail'];
$data_money_income_teacher['book_num'] = $val['number'];
$data_money_income_teacher['uid'] = $data_user['uid'];
Db::name('money_income') -> insert($data_money_income_teacher);
}
Db::name('my_user') -> where('uid',$data_user['uid']) -> setInc('balance',$money_teacher);
}
Db::name('my_user') -> where('uid',$teacher['uid']) -> setInc('balance',$money_teacher);
}
//如果是平台商品 老师购买
if($data_user['status'] == 3){
}else if($order['indent_type'] == 2){
//如果是业务员订单
//查询平台商品老师和业务员所占的佣金比例
$money_ratio = Db::name('money_ratio') -> where('id',1) -> find();
//判断这条订单是否为快递配送
if($order['is_courier'] == 2){
$order['money'] = $order['money']-$money_ratio['courier'];
}
//查询这条订单下的所有商品
$data_indent_goods = Db::name('indent_goods') -> where('indent_id',$order['id']) -> select();
$money_salesman = 0;
//查询老师的uid
/* $teacher = Db::name('my_user') -> where('id',$data_user['pid']) -> find();*/
//查询业务员的uid
$salesman = Db::name('my_user') -> where('id',$data_user['pid']) -> find();
foreach ($data_indent_goods as $key => $val){
$money_salesman += $val['price']*$val['number']*$money_ratio['salesman_ratio'];
$data_money_income_salesman['create_time'] = time();
$data_money_income_salesman['money'] = $money_salesman;
$data_money_income_salesman['type'] = 1;
$data_money_income_salesman['book_name'] = $val['book_name'];
$data_money_income_salesman['book_thumbnail'] = $val['thumbnail'];
$data_money_income_salesman['book_num'] = $val['number'];
$data_money_income_salesman['uid'] = $salesman['uid'];
Db::name('money_income') -> insert($data_money_income_salesman);
}
Db::name('my_user') -> where('uid',$salesman['uid']) -> setInc('balance',$money_salesman);
$money_teacher = 0;
foreach ($data_indent_goods as $key => $val){
$money_teacher += $val['price']*$val['number']*$money_ratio['teacher_ratio'];
$data_money_income_teacher['create_time'] = time();
$data_money_income_teacher['money'] = $money_teacher;
$data_money_income_teacher['type'] = 1;
$data_money_income_teacher['book_name'] = $val['book_name'];
$data_money_income_teacher['book_thumbnail'] = $val['thumbnail'];
$data_money_income_teacher['book_num'] = $val['number'];
$data_money_income_teacher['uid'] = $data_user['uid'];
Db::name('money_income') -> insert($data_money_income_teacher);
}
Db::name('my_user') -> where('uid',$data_user['uid']) -> setInc('balance',$money_teacher);
}
}else if($order['indent_type'] == 2){
//如果是业务员订单
//查询平台商品老师和业务员所占的佣金比例
$money_ratio = Db::name('money_ratio') -> where('id',1) -> find();
//判断这条订单是否为快递配送
if($order['is_courier'] == 2){
$order['money'] = $order['money']-$money_ratio['courier'];
}
//查询这条订单下的所有商品
$data_indent_goods = Db::name('indent_goods') -> where('indent_id',$order['id']) -> select();
//业务员商品学生购买
if($data_user['status'] == 4){
$teacher = Db::name('my_user') -> where('id',$data_user['pid']) -> find();
$money = 0;
foreach ($data_indent_goods as $key => $val){
$money += $val['commission']*$val['number'];
$money_income_teacher['create_time'] = time();
$money_income_teacher['money'] = $money;
$money_income_teacher['type'] = 2;
$money_income_teacher['book_name'] = $val['book_name'];
$money_income_teacher['book_thumbnail'] = $val['thumbnail'];
$money_income_teacher['book_num'] = $val['number'];
$money_income_teacher['uid'] = $teacher['uid'];
Db::name('money_income') -> insert($money_income_teacher);
//业务员商品学生购买
if($data_user['status'] == 4){
$teacher = Db::name('my_user') -> where('id',$data_user['pid']) -> find();
$money = 0;
foreach ($data_indent_goods as $key => $val){
$money += $val['commission']*$val['number'];
$money_income_teacher['create_time'] = time();
$money_income_teacher['money'] = $money;
$money_income_teacher['type'] = 2;
$money_income_teacher['book_name'] = $val['book_name'];
$money_income_teacher['book_thumbnail'] = $val['thumbnail'];
$money_income_teacher['book_num'] = $val['number'];
$money_income_teacher['uid'] = $teacher['uid'];
Db::name('money_income') -> insert($money_income_teacher);
}
//增加老师余额
Db::name('my_user') -> where('uid',$teacher['uid']) -> setInc('balance',$money);
//计算业务员这条订单的收入
$balance_salesman = $order['money'] - $order['money']*$money_ratio['platform_ratio'] - $money;
//增加业务员的余额
Db::name('my_user') -> where('uid',$order['salesman_uid']) -> setInc('balance',$balance_salesman);
//添加业务员的收入记录
$money_income_salesman_indent['create_time'] = time();
$money_income_salesman_indent['uid'] = $order['salesman_uid'];
$money_income_salesman_indent['money'] = $balance_salesman;
$money_income_salesman_indent['type'] = 2;
$money_income_salesman_indent['indent_id'] = $order['id'];
Db::name('money_income') -> insert($money_income_salesman_indent);
}
//增加老师余额
Db::name('my_user') -> where('uid',$teacher['uid']) -> setInc('balance',$money);
//计算业务员这条订单的收入
$balance_salesman = $order['money'] - $order['money']*$money_ratio['platform_ratio'] - $money;
//增加业务员的余额
Db::name('my_user') -> where('uid',$order['salesman_uid']) -> setInc('balance',$balance_salesman);
//添加业务员的收入记录
$money_income_salesman_indent['create_time'] = time();
$money_income_salesman_indent['uid'] = $order['salesman_uid'];
$money_income_salesman_indent['money'] = $balance_salesman;
$money_income_salesman_indent['type'] = 2;
$money_income_salesman_indent['indent_id'] = $order['id'];
Db::name('money_income') -> insert($money_income_salesman_indent);
//业务员商品老师购买
if ($data_user['status'] == 3){
$teacher = $data_user['uid'];
$money = 0;
foreach ($data_indent_goods as $key => $val){
$money += $val['commission']*$val['number'];
$money_income_teacher['create_time'] = time();
$money_income_teacher['money'] = $money;
$money_income_teacher['type'] = 2;
$money_income_teacher['book_name'] = $val['book_name'];
$money_income_teacher['book_thumbnail'] = $val['thumbnail'];
$money_income_teacher['book_num'] = $val['number'];
$money_income_teacher['uid'] = $teacher;
Db::name('money_income') -> insert($money_income_teacher);
}
//增加老师余额
Db::name('my_user') -> where('uid',$teacher) -> setInc('balance',$money);
//计算业务员这条订单的收入
$balance_salesman = $order['money'] - $order['money']*$money_ratio['platform_ratio'] - $money;
//增加业务员的余额
Db::name('my_user') -> where('uid',$order['salesman_uid']) -> setInc('balance',$balance_salesman);
//添加业务员的收入记录
$money_income_salesman_indent['create_time'] = time();
$money_income_salesman_indent['uid'] = $order['salesman_uid'];
$money_income_salesman_indent['money'] = $balance_salesman;
$money_income_salesman_indent['type'] = 2;
$money_income_salesman_indent['indent_id'] = $order['id'];
Db::name('money_income') -> insert($money_income_salesman_indent);
}
//业务员商品老师购买
if ($data_user['status'] == 3){
$teacher = $data_user['uid'];
$money = 0;
foreach ($data_indent_goods as $key => $val){
$money += $val['commission']*$val['number'];
$money_income_teacher['create_time'] = time();
$money_income_teacher['money'] = $money;
$money_income_teacher['type'] = 2;
$money_income_teacher['book_name'] = $val['book_name'];
$money_income_teacher['book_thumbnail'] = $val['thumbnail'];
$money_income_teacher['book_num'] = $val['number'];
$money_income_teacher['uid'] = $teacher;
Db::name('money_income') -> insert($money_income_teacher);
}
//增加老师余额
Db::name('my_user') -> where('uid',$teacher) -> setInc('balance',$money);
//计算业务员这条订单的收入
$balance_salesman = $order['money'] - $order['money']*$money_ratio['platform_ratio'] - $money;
//增加业务员的余额
Db::name('my_user') -> where('uid',$order['salesman_uid']) -> setInc('balance',$balance_salesman);
//添加业务员的收入记录
$money_income_salesman_indent['create_time'] = time();
$money_income_salesman_indent['uid'] = $order['salesman_uid'];
$money_income_salesman_indent['money'] = $balance_salesman;
$money_income_salesman_indent['type'] = 2;
$money_income_salesman_indent['indent_id'] = $order['id'];
Db::name('money_income') -> insert($money_income_salesman_indent);
}
Db::commit();
} catch (Exception $e) {
Db::rollback();
}
cache('a1',"789");
/*cache('a1',"789");
$bird = new BirdController;
$createOrder = $bird -> createOrder($order['id']);
cache('yuyue1',$createOrder);
$takeOrder = $bird -> takeOrder($order['id']);
cache('dingyue1',$takeOrder);
cache('dingyue1',$takeOrder);*/
}
return true; // 返回处理完成
});
... ...