|
@@ -125,49 +125,57 @@ class Order extends Backend |
|
@@ -125,49 +125,57 @@ class Order extends Backend |
125
|
{
|
125
|
{
|
126
|
if ($ids) {
|
126
|
if ($ids) {
|
127
|
$pk = $this->model->getPk();
|
127
|
$pk = $this->model->getPk();
|
128
|
- $res = Db::name('order')->where($pk,$ids)->field('id,pay_order_sn,total_goods_price')->find();
|
|
|
129
|
- $status = config('verify.status');
|
|
|
130
|
- //处理退款逻辑
|
|
|
131
|
- $config = config('verify.wx_pay');
|
|
|
132
|
- $app = Factory::payment($config);
|
|
|
133
|
-// $security_price = $res['total_goods_price']*100;
|
|
|
134
|
- $security_price = 1;
|
|
|
135
|
- $refundNumber = $this->genPayOrderSn('refund');//商户退款单号
|
|
|
136
|
- $result = $app->refund->byOutTradeNumber($res['pay_order_sn'], $refundNumber, $security_price, $security_price, [
|
|
|
137
|
- // 可在此处传入其他参数,详细参数见微信支付文档
|
|
|
138
|
- ]);
|
|
|
139
|
- if($result['return_code'] === 'SUCCESS' && $result['result_code'] === 'SUCCESS'){
|
|
|
140
|
- $this->model->where($pk, '=', $ids)->update(['status'=>$status[4]]);
|
|
|
141
|
-
|
|
|
142
|
- //增加库存
|
|
|
143
|
- $res1 = Db::name('ogoods')->where(['o_id'=>$res['id']])->field('id,g_id,style,goods_number')->select();
|
|
|
144
|
- $g_ids = array_column($res1,'g_id');
|
|
|
145
|
-
|
|
|
146
|
- $res_stock = Common::selectSoftWhereData('goods',['id'=>['in',$g_ids]],'id,style g_style,stock');
|
|
|
147
|
- $goodsModel = new \app\admin\model\Goods();
|
|
|
148
|
-
|
|
|
149
|
- foreach($res_stock as $g_value){
|
|
|
150
|
- $arr_stock = explode('|',$g_value['stock']);
|
|
|
151
|
- $sale_number = 1;
|
|
|
152
|
- foreach($res1 as $value){
|
|
|
153
|
- if($g_value['id'] == $value['g_id']){
|
|
|
154
|
- $s_index = array_search($value['style'],Common::salePrice($g_value['g_style']));
|
|
|
155
|
- $stock = Common::salePrice($g_value['stock'])[$s_index] + $value['goods_number'];
|
|
|
156
|
- $arr_stock[$s_index] = $stock;
|
|
|
157
|
- $sale_number = $value['goods_number'];
|
128
|
+ $res = Db::name('order')->where($pk,$ids)->field('id,pay_order_sn,total_expense_price,total_price')->find();
|
|
|
129
|
+ if($res){
|
|
|
130
|
+ if($res['total_price'] == 0){
|
|
|
131
|
+ //支付总金额为0,
|
|
|
132
|
+ $this->success('成功');
|
|
|
133
|
+ }
|
|
|
134
|
+ $status = config('verify.status');
|
|
|
135
|
+ //处理退款逻辑
|
|
|
136
|
+ $config = config('verify.wx_pay');
|
|
|
137
|
+ $app = Factory::payment($config);
|
|
|
138
|
+ //退款金额 支付金额-运费
|
|
|
139
|
+// $security_price = ($res['total_price'] - $res['total_expense_price'])*100;
|
|
|
140
|
+ $security_price = 1;
|
|
|
141
|
+ $refundNumber = $this->genPayOrderSn('refund');//商户退款单号
|
|
|
142
|
+ $result = $app->refund->byOutTradeNumber($res['pay_order_sn'], $refundNumber, $security_price, $security_price, [
|
|
|
143
|
+ // 可在此处传入其他参数,详细参数见微信支付文档
|
|
|
144
|
+ ]);
|
|
|
145
|
+ if($result['return_code'] === 'SUCCESS' && $result['result_code'] === 'SUCCESS'){
|
|
|
146
|
+ $this->model->where($pk, '=', $ids)->update(['status'=>$status[4]]);
|
|
|
147
|
+
|
|
|
148
|
+ //增加库存
|
|
|
149
|
+ $res1 = Db::name('ogoods')->where(['o_id'=>$res['id']])->field('id,g_id,style,goods_number')->select();
|
|
|
150
|
+ $g_ids = array_column($res1,'g_id');
|
|
|
151
|
+
|
|
|
152
|
+ $res_stock = Common::selectSoftWhereData('goods',['id'=>['in',$g_ids]],'id,style g_style,stock');
|
|
|
153
|
+ $goodsModel = new \app\admin\model\Goods();
|
|
|
154
|
+
|
|
|
155
|
+ foreach($res_stock as $g_value){
|
|
|
156
|
+ $arr_stock = explode('|',$g_value['stock']);
|
|
|
157
|
+ $sale_number = 1;
|
|
|
158
|
+ foreach($res1 as $value){
|
|
|
159
|
+ if($g_value['id'] == $value['g_id']){
|
|
|
160
|
+ $s_index = array_search($value['style'],Common::salePrice($g_value['g_style']));
|
|
|
161
|
+ $stock = Common::salePrice($g_value['stock'])[$s_index] + $value['goods_number'];
|
|
|
162
|
+ $arr_stock[$s_index] = $stock;
|
|
|
163
|
+ $sale_number = $value['goods_number'];
|
|
|
164
|
+ }
|
158
|
}
|
165
|
}
|
|
|
166
|
+ //更新增加库存
|
|
|
167
|
+ $stock1 = implode('|',$arr_stock);
|
|
|
168
|
+ $goodsModel->where(['id'=>$g_value['id']])->update(['stock'=>$stock1]);
|
|
|
169
|
+ //减少销售
|
|
|
170
|
+ Common::decSales(['id'=>['in',$g_ids]],$sale_number);
|
159
|
}
|
171
|
}
|
160
|
- //更新增加库存
|
|
|
161
|
- $stock1 = implode('|',$arr_stock);
|
|
|
162
|
- $goodsModel->where(['id'=>$g_value['id']])->update(['stock'=>$stock1]);
|
|
|
163
|
- //减少销售
|
|
|
164
|
- Common::decSales(['id'=>['in',$g_ids]],$sale_number);
|
|
|
165
|
- }
|
|
|
166
|
|
172
|
|
167
|
- $this->success('成功');
|
|
|
168
|
- }else{
|
|
|
169
|
- $this->error('退款失败');
|
173
|
+ $this->success('成功');
|
|
|
174
|
+ }else{
|
|
|
175
|
+ $this->error('退款失败');
|
|
|
176
|
+ }
|
170
|
}
|
177
|
}
|
|
|
178
|
+ $this->error('未查到订单');
|
171
|
|
179
|
|
172
|
}
|
180
|
}
|
173
|
$this->error(__('Parameter %s can not be empty', 'ids'));
|
181
|
$this->error(__('Parameter %s can not be empty', 'ids'));
|