Explorar o código

平台后台-完善退款逻辑

sunxbiao hai 1 ano
pai
achega
0f5c60b14c
Modificáronse 1 ficheiros con 186 adicións e 0 borrados
  1. 186 0
      app/controller/admin/order/RefundOrder.php

+ 186 - 0
app/controller/admin/order/RefundOrder.php

@@ -121,6 +121,192 @@ class RefundOrder extends BaseController
121 121
 //            Db::name('log')->insert(['data'=>'这了'. 1]);
122 122
             $this->repository->agree($id,$data,$this->request->adminId(),1);
123 123
 
124
+            // 获取订单金额
125
+            $store_order_info = Db::name('store_order')
126
+                ->where('order_id', $refund_order['order_id'])
127
+                ->find();
128
+            $group_order_map = Db::name('store_group_order')
129
+                ->where('group_order_id', $store_order_info['group_order_id'])
130
+                ->field('uid,pay_price,hf_pay_id,fzone_paytype')
131
+                ->find();
132
+            $make = '商贸区';
133
+            if ($store_order_info['mer_id'] == 439) {
134
+                $make = '精彩生活区';
135
+            } else if ($store_order_info['mer_id'] == 496) {
136
+                $make = '会员专区';
137
+            } else if ($store_order_info['mer_id'] == 491) {
138
+                $make = '复购区';
139
+            }
140
+
141
+            // 如果是组合支付 现金 + 积分 则需要把积分退回
142
+            // 参考 app\controller\api\Notify.php -- 745 $array_fzone_paytype['type']=='b2'
143
+            $array_fzone_paytype = json_decode($group_order_map['fzone_paytype'], true);
144
+            if (!empty($array_fzone_paytype)) {
145
+                if ($array_fzone_paytype['type'] == 'b1') {
146
+                    // VR+积分 {"checked":true,"note":"VR+积分","other":210.0,"price":970.0,"total":0.0,"type":"b1","vr":"47557.5"}
147
+                    $vrpri = Db::name("user")->where("uid", $group_order_map['uid'])->value('vr');
148
+                    $vrpri += $array_fzone_paytype['price'];
149
+                    Db::name("user")->where("uid", $group_order_map['uid'])->update(['vr' => $vrpri]);
150
+                    Db::name("user_sign_vr")->insert([
151
+                        'uid' => $store_order_info['uid'],
152
+                        'number' => $array_fzone_paytype['price'],
153
+                        'mark' => "{$make}商品申请退款退回VR",
154
+                        'desc' => "VR",
155
+                        'order_type' => 0,
156
+                        'order_id' => $store_order_info['order_id'],
157
+                        'surplus' => $vrpri,
158
+                        'type' => 1,
159
+                        'addtime' => time()
160
+                    ]);
161
+
162
+                    // {"checked":true,"note":"VR+积分","other":1.5,"price":8.5,"total":0.0,"type":"b2","vr":"48799.82"}
163
+                    $vrpri = Db::name("user")->where("uid", $group_order_map['uid'])->value('score');
164
+                    $vrpri += $array_fzone_paytype['other'];
165
+                    Db::name("user")->where("uid", $group_order_map['uid'])->update(['score' => $vrpri]);
166
+
167
+                    $data = [
168
+                        "uid" => $store_order_info['uid'],
169
+                        "reward_socre" => $array_fzone_paytype['other'],
170
+                        "addtime" => time(),
171
+                        "status" => 1,
172
+                        "order_id" => $store_order_info['order_id'],
173
+                        "mark" => "{$make}商品申请退款退回积分",
174
+                        "surplus" => $vrpri,
175
+                        "pm" => 1,
176
+                        "source_type" => 3
177
+                    ];
178
+                    Db::name("user_sign_score")->insert($data);//添加积分记录
179
+                } else if ($array_fzone_paytype['type'] == 'b2') {
180
+                    // {"checked":true,"note":"现金+积分","other":1.5,"price":8.5,"total":0.0,"type":"b2","vr":"48799.82"}
181
+
182
+                    $vrpri = Db::name("user")->where("uid", $group_order_map['uid'])->value('score');
183
+                    $vrpri += $array_fzone_paytype['other'];
184
+                    Db::name("user")->where("uid", $group_order_map['uid'])->update(['score' => $vrpri]);
185
+
186
+                    $data = [
187
+                        "uid" => $store_order_info['uid'],
188
+                        "reward_socre" => $array_fzone_paytype['other'],
189
+                        "addtime" => time(),
190
+                        "status" => 1,
191
+                        "order_id" => $store_order_info['order_id'],
192
+                        "mark" => "{$make}商品申请退款退回积分",
193
+                        "surplus" => $vrpri,
194
+                        "pm" => 1,
195
+                        "source_type" => 3
196
+                    ];
197
+                    Db::name("user_sign_score")->insert($data);//添加积分记录
198
+                } else if ($array_fzone_paytype['type'] == 'b3') {
199
+                    // VR+积分 {"checked":true,"note":"VR+积分","other":210.0,"price":970.0,"total":0.0,"type":"b1","vr":"47557.5"}
200
+                    $vrpri = Db::name("user")->where("uid", $group_order_map['uid'])->value('vr');
201
+                    $vrpri += $array_fzone_paytype['price'];
202
+                    Db::name("user")->where("uid", $group_order_map['uid'])->update(['vr' => $vrpri]);
203
+                    Db::name("user_sign_vr")->insert([
204
+                        'uid' => $store_order_info['uid'],
205
+                        'number' => $array_fzone_paytype['price'],
206
+                        'mark' => "{$make}商品申请退款退回VR",
207
+                        'desc' => "VR",
208
+                        'order_type' => 0,
209
+                        'order_id' => $store_order_info['order_id'],
210
+                        'surplus' => $vrpri,
211
+                        'type' => 1,
212
+                        'addtime' => time()
213
+                    ]);
214
+
215
+                    // {"checked":true,"note":"VR+积分","other":1.5,"price":8.5,"total":0.0,"type":"b2","vr":"48799.82"}
216
+                    $vrpri = Db::name("user")->where("uid", $group_order_map['uid'])->value('jingdou');
217
+                    $vrpri += $array_fzone_paytype['other'];
218
+                    Db::name("user")->where("uid", $group_order_map['uid'])->update(['jingdou' => $vrpri]);
219
+
220
+                    Db::name('user_sign_jingdou')->insert([
221
+                        'uid' => $store_order_info['uid'],
222
+                        'number' => $array_fzone_paytype['other'],
223
+                        'status' => 1,
224
+                        'mark' => "{$make}商品申请退款退回京豆",
225
+                        'addtime' => time(),
226
+                        'surplus' => $vrpri,
227
+                        'settlement_time' => date('Y-m-d H:i:s'),
228
+                        'type' => 1,
229
+                        'order_type' => 0,
230
+                        'order_id' => $store_order_info['order_id']
231
+                    ]);
232
+                } else if ($array_fzone_paytype['type'] == 'b4') {
233
+                    // {"checked":true,"note":"现金+积分","other":1.5,"price":8.5,"total":0.0,"type":"b2","vr":"48799.82"}
234
+
235
+                    $jingdoupri = Db::name("user")->where("uid", $group_order_map['uid'])->value('jingdou');
236
+                    $jingdoupri += $array_fzone_paytype['other'];
237
+                    Db::name("user")->where("uid", $group_order_map['uid'])->update(['jingdou' => $jingdoupri]);
238
+
239
+                    Db::name('user_sign_jingdou')->insert([
240
+                        'uid' => $store_order_info['uid'],
241
+                        'number' => $array_fzone_paytype['other'],
242
+                        'status' => 1,
243
+                        'mark' => "{$make}商品申请退款退回京豆",
244
+                        'addtime' => time(),
245
+                        'surplus' => $jingdoupri,
246
+                        'settlement_time' => date('Y-m-d H:i:s'),
247
+                        'type' => 1,
248
+                        'order_type' => 0,
249
+                        'order_id' => $store_order_info['order_id']
250
+                    ]);
251
+                } else if ($array_fzone_paytype['type'] == 'b5') {
252
+                    // {"checked":true,"note":"VR","other":0.0,"price":1.0,"total":0.0,"type":"b5","vr":"10"}
253
+                    $vrpri = Db::name("user")->where("uid", $group_order_map['uid'])->value('vr');
254
+                    $vrpri += $array_fzone_paytype['price'];
255
+                    Db::name("user")->where("uid", $group_order_map['uid'])->update(['vr' => $vrpri]);
256
+                    Db::name("user_sign_vr")->insert([
257
+                        'uid' => $store_order_info['uid'],
258
+                        'number' => $array_fzone_paytype['price'],
259
+                        'mark' => "{$make}商品申请退款退回VR",
260
+                        'desc' => "VR",
261
+                        'order_type' => 0,
262
+                        'order_id' => $store_order_info['order_id'],
263
+                        'surplus' => $vrpri,
264
+                        'type' => 1,
265
+                        'addtime' => time()
266
+                    ]);
267
+                } else if ($array_fzone_paytype['type'] == 'a3') {
268
+                    // {"checked":true,"note":"现金+VR","other":1.5,"price":8.5,"total":0.0,"type":"a3","vr":"48799.82"}
269
+                    $vrpri = Db::name("user")->where("uid", $group_order_map['uid'])->value('vr');
270
+                    $vrpri += $array_fzone_paytype['other'];
271
+                    Db::name("user")->where("uid", $group_order_map['uid'])->update(['vr' => $vrpri]);
272
+
273
+                    //VR入账
274
+                    $insertdata = [
275
+                        'uid'=> $store_order_info['uid'],
276
+                        'number' =>  $array_fzone_paytype['other'],
277
+                        'surplus' => $vrpri,
278
+                        'mark' => "{$make}商品申请退款退回VR",
279
+                        'order_id'=> $store_order_info['order_id'],
280
+                        'type' => 2,
281
+                        'addtime' => time(),
282
+                        'settlement_time'=> date('Y-m-d H:i:s', time())
283
+                    ];
284
+                    Db::name('user_sign_vr')->insert($insertdata);
285
+
286
+                }
287
+                // else if ($array_fzone_paytype['type'] == 'c1') {
288
+                //     // {"checked":true,"note":"复购金","other":1.5,"price":8.5,"total":0.0,"type":"c1","vr":"48799.82"}
289
+                //     $vrpri = Db::name("user")->where("uid", $group_order_map['uid'])->value('fugou');
290
+                //     $vrpri += $array_fzone_paytype['other'];
291
+                //     Db::name("user")->where("uid", $group_order_map['uid'])->update(['fugou' => $vrpri]);
292
+                //     //支出账号存到log日志
293
+                //     $log_data = [
294
+                //         'uid' => $store_order_info['uid'],
295
+                //         'number' => $array_fzone_paytype['price'],
296
+                //         'mark' => "复购区商品申请退款退回复购金:" . $array_fzone_paytype['price'],
297
+                //         'desc' => "复购金",
298
+                //         'order_id' =>  $store_order_info['order_id'],
299
+                //         'surplus' => $vrpri,
300
+                //         'order_type' => 0,
301
+                //         'type' => 2,
302
+                //         'addtime' => time()
303
+                //     ];
304
+                //     $user_res_log = Db::name("user_sign_fugou")->insert($log_data);
305
+                // }
306
+            }
307
+
308
+            // 取消 订单所发放的福利
309
+            $this->repository->cancelOrderBonus($id);
124 310
         }else{
125 311
             $fail_message = $this->request->param('fail_message','');
126 312
             if($status == -1 && empty($fail_message)){