...
|
...
|
@@ -125,49 +125,57 @@ class Order extends Backend |
|
|
{
|
|
|
if ($ids) {
|
|
|
$pk = $this->model->getPk();
|
|
|
$res = Db::name('order')->where($pk,$ids)->field('id,pay_order_sn,total_goods_price')->find();
|
|
|
$status = config('verify.status');
|
|
|
//处理退款逻辑
|
|
|
$config = config('verify.wx_pay');
|
|
|
$app = Factory::payment($config);
|
|
|
// $security_price = $res['total_goods_price']*100;
|
|
|
$security_price = 1;
|
|
|
$refundNumber = $this->genPayOrderSn('refund');//商户退款单号
|
|
|
$result = $app->refund->byOutTradeNumber($res['pay_order_sn'], $refundNumber, $security_price, $security_price, [
|
|
|
// 可在此处传入其他参数,详细参数见微信支付文档
|
|
|
]);
|
|
|
if($result['return_code'] === 'SUCCESS' && $result['result_code'] === 'SUCCESS'){
|
|
|
$this->model->where($pk, '=', $ids)->update(['status'=>$status[4]]);
|
|
|
|
|
|
//增加库存
|
|
|
$res1 = Db::name('ogoods')->where(['o_id'=>$res['id']])->field('id,g_id,style,goods_number')->select();
|
|
|
$g_ids = array_column($res1,'g_id');
|
|
|
|
|
|
$res_stock = Common::selectSoftWhereData('goods',['id'=>['in',$g_ids]],'id,style g_style,stock');
|
|
|
$goodsModel = new \app\admin\model\Goods();
|
|
|
|
|
|
foreach($res_stock as $g_value){
|
|
|
$arr_stock = explode('|',$g_value['stock']);
|
|
|
$sale_number = 1;
|
|
|
foreach($res1 as $value){
|
|
|
if($g_value['id'] == $value['g_id']){
|
|
|
$s_index = array_search($value['style'],Common::salePrice($g_value['g_style']));
|
|
|
$stock = Common::salePrice($g_value['stock'])[$s_index] + $value['goods_number'];
|
|
|
$arr_stock[$s_index] = $stock;
|
|
|
$sale_number = $value['goods_number'];
|
|
|
$res = Db::name('order')->where($pk,$ids)->field('id,pay_order_sn,total_expense_price,total_price')->find();
|
|
|
if($res){
|
|
|
if($res['total_price'] == 0){
|
|
|
//支付总金额为0,
|
|
|
$this->success('成功');
|
|
|
}
|
|
|
$status = config('verify.status');
|
|
|
//处理退款逻辑
|
|
|
$config = config('verify.wx_pay');
|
|
|
$app = Factory::payment($config);
|
|
|
//退款金额 支付金额-运费
|
|
|
// $security_price = ($res['total_price'] - $res['total_expense_price'])*100;
|
|
|
$security_price = 1;
|
|
|
$refundNumber = $this->genPayOrderSn('refund');//商户退款单号
|
|
|
$result = $app->refund->byOutTradeNumber($res['pay_order_sn'], $refundNumber, $security_price, $security_price, [
|
|
|
// 可在此处传入其他参数,详细参数见微信支付文档
|
|
|
]);
|
|
|
if($result['return_code'] === 'SUCCESS' && $result['result_code'] === 'SUCCESS'){
|
|
|
$this->model->where($pk, '=', $ids)->update(['status'=>$status[4]]);
|
|
|
|
|
|
//增加库存
|
|
|
$res1 = Db::name('ogoods')->where(['o_id'=>$res['id']])->field('id,g_id,style,goods_number')->select();
|
|
|
$g_ids = array_column($res1,'g_id');
|
|
|
|
|
|
$res_stock = Common::selectSoftWhereData('goods',['id'=>['in',$g_ids]],'id,style g_style,stock');
|
|
|
$goodsModel = new \app\admin\model\Goods();
|
|
|
|
|
|
foreach($res_stock as $g_value){
|
|
|
$arr_stock = explode('|',$g_value['stock']);
|
|
|
$sale_number = 1;
|
|
|
foreach($res1 as $value){
|
|
|
if($g_value['id'] == $value['g_id']){
|
|
|
$s_index = array_search($value['style'],Common::salePrice($g_value['g_style']));
|
|
|
$stock = Common::salePrice($g_value['stock'])[$s_index] + $value['goods_number'];
|
|
|
$arr_stock[$s_index] = $stock;
|
|
|
$sale_number = $value['goods_number'];
|
|
|
}
|
|
|
}
|
|
|
//更新增加库存
|
|
|
$stock1 = implode('|',$arr_stock);
|
|
|
$goodsModel->where(['id'=>$g_value['id']])->update(['stock'=>$stock1]);
|
|
|
//减少销售
|
|
|
Common::decSales(['id'=>['in',$g_ids]],$sale_number);
|
|
|
}
|
|
|
//更新增加库存
|
|
|
$stock1 = implode('|',$arr_stock);
|
|
|
$goodsModel->where(['id'=>$g_value['id']])->update(['stock'=>$stock1]);
|
|
|
//减少销售
|
|
|
Common::decSales(['id'=>['in',$g_ids]],$sale_number);
|
|
|
}
|
|
|
|
|
|
$this->success('成功');
|
|
|
}else{
|
|
|
$this->error('退款失败');
|
|
|
$this->success('成功');
|
|
|
}else{
|
|
|
$this->error('退款失败');
|
|
|
}
|
|
|
}
|
|
|
$this->error('未查到订单');
|
|
|
|
|
|
}
|
|
|
$this->error(__('Parameter %s can not be empty', 'ids'));
|
...
|
...
|
|