...
|
...
|
@@ -28,9 +28,11 @@ class Notify extends Api |
|
|
return;
|
|
|
}
|
|
|
$data = $pay->verify();
|
|
|
$data = json_decode($data,true);
|
|
|
$model = new \app\api\model\Order();
|
|
|
$goodsmodel = new \app\api\model\OrderGoods();
|
|
|
$skumodel = new \app\api\model\GoodsSpec();
|
|
|
$goods_model = new \app\api\model\Goods();
|
|
|
try {
|
|
|
$out_trade_no = $data['out_trade_no'];
|
|
|
$order = $model
|
...
|
...
|
@@ -44,13 +46,16 @@ class Notify extends Api |
|
|
$order->pay_time = time();
|
|
|
$order->isUpdate()->save();
|
|
|
// 减少库存
|
|
|
$sales_actual = 0;
|
|
|
$list = $goodsmodel->where('order_id',$order['id'])->select();
|
|
|
foreach ($list as $key => $value){
|
|
|
$sales_actual+=$value['total_num'];
|
|
|
if ($value['deduct_stock_type'] == 20){
|
|
|
$skumodel->where('goods_spec_id',$value['goods_spec_id'])->setDec('stock_num',$value['total_num']);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 增加销量
|
|
|
$goods_model->setInc('sales_actual',$sales_actual);
|
|
|
// 判断是否邀请成功
|
|
|
$user = \app\api\model\User::get($order['user_id']);
|
|
|
if ($user['invite_user_id'] > 0 && $user['invite_status'] != 1) {
|
...
|
...
|
@@ -62,4 +67,51 @@ class Notify extends Api |
|
|
}
|
|
|
echo $pay->success()->send();
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 订单退款回调
|
|
|
*/
|
|
|
public function refund()
|
|
|
{
|
|
|
$paytype = $this->request->param('type');
|
|
|
$pay = Service::checkNotify($paytype,'refund');
|
|
|
if (!$pay) {
|
|
|
echo '签名错误';
|
|
|
return;
|
|
|
}
|
|
|
$data = $pay->verify();
|
|
|
$data = json_decode($data,true);
|
|
|
$model = new \app\api\model\Order();
|
|
|
$goodsmodel = new \app\api\model\OrderGoods();
|
|
|
$skumodel = new \app\api\model\GoodsSpec();
|
|
|
$goods_model = new \app\api\model\Goods();
|
|
|
try {
|
|
|
$out_trade_no = $data['out_refund_no'];
|
|
|
$order = $model
|
|
|
->where('refund_no',$out_trade_no)
|
|
|
->where('pay_status','20')
|
|
|
->where('order_status','10')
|
|
|
->find();
|
|
|
if (!$order) $this->error('订单不存在');
|
|
|
$order->refund_id = $data['refund_id'];
|
|
|
$order->refund_time = time();
|
|
|
$order->order_status = '20';
|
|
|
$order->isUpdate()->save();
|
|
|
// 增加库存
|
|
|
$sales_actual = 0;
|
|
|
$list = $goodsmodel->where('order_id',$order['id'])->select();
|
|
|
foreach ($list as $key => $value){
|
|
|
$sales_actual+=$value['total_num'];
|
|
|
if ($value['deduct_stock_type'] == 20){
|
|
|
$skumodel->where('goods_spec_id',$value['goods_spec_id'])->setInc('stock_num',$value['total_num']);
|
|
|
}
|
|
|
}
|
|
|
// 减少销量
|
|
|
$goods_model->setDec('sales_actual',$sales_actual);
|
|
|
//你可以在此编写订单逻辑
|
|
|
} catch (Exception $e) {
|
|
|
}
|
|
|
echo $pay->success()->send();
|
|
|
}
|
|
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|