|
|
@@ -331,4 +331,100 @@ class Order extends BaseController
|
|
331
|
331
|
}
|
|
332
|
332
|
return app('json')->fail('操作失败');
|
|
333
|
333
|
}
|
|
|
334
|
+
|
|
|
335
|
+ /**
|
|
|
336
|
+ * 撤回订单,并撤回订单奖励
|
|
|
337
|
+ */
|
|
|
338
|
+ public function killOrderRewards(){
|
|
|
339
|
+ $group_order_id = request()->param('group_order_id');
|
|
|
340
|
+ $order_id = request()->param('order_id');
|
|
|
341
|
+ $uid = request()->param('uid');
|
|
|
342
|
+ if (empty($order_id) || empty($group_order_id) || empty($uid)) {
|
|
|
343
|
+ return app('json')->fail('参数缺失');
|
|
|
344
|
+ }
|
|
|
345
|
+ try {
|
|
|
346
|
+ Db::startTrans();
|
|
|
347
|
+ // 删除订单相关表 对应备份还没有创建
|
|
|
348
|
+ $this->backupAndDelete('store_order', ['group_order_id' => $group_order_id]);
|
|
|
349
|
+ $this->backupAndDelete('store_group_order', ['group_order_id' => $group_order_id]);
|
|
|
350
|
+// 取出并删除 pv
|
|
|
351
|
+ $pv = $this->getValue('user_pv_log', ['order_id' => $order_id, 'status' => 1,], 'pv');
|
|
|
352
|
+ $this->backupAndDelete('user_pv_log', ['order_id' => $order_id]); //status状态判断还没
|
|
|
353
|
+// 取出 vr 消耗
|
|
|
354
|
+ $payVr = $this->getValue('user_sign_vr', ['order_id' => $order_id, 'type' => 2,], 'number');
|
|
|
355
|
+ $this->backupAndDelete('user_sign_vr', ['order_id' => $order_id]);
|
|
|
356
|
+ // 取出购买赠送积分 / 支出积分
|
|
|
357
|
+ $score = $this->getValue('user_sign_score', ['order_id' => $order_id, 'status' => 1,'source_type' => 3,'uid' => $uid,], 'reward_score');
|
|
|
358
|
+ $payScore = $this->getValue('user_sign_score', ['order_id' => $order_id, 'status' => 1,'pm' => 2,'uid' => $uid,], 'reward_score');
|
|
|
359
|
+// // 取出推广赠送的积分和推广人的 uid
|
|
|
360
|
+ $spreadScore = $this->getValue('user_sign_score', ['order_id' => $order_id, 'status' => 1,'pm' => 2,'source_type' => 3,['mark','like','%推广%'],], 'reward_score');
|
|
|
361
|
+ $spreadUid = $this->getValue('user_sign_score', [['order_id' => $order_id], ['status' => 1],['pm' => 2],['source_type' => 3],['mark','like','%推广%'],], 'uid');
|
|
|
362
|
+// // 删除所有相关积分记录
|
|
|
363
|
+ $this->backupAndDelete('user_sign_score', ['order_id' => $order_id]);
|
|
|
364
|
+// // 贡献值
|
|
|
365
|
+// $gongXian = $this->getValue('user_sign_gongxian', ['order_id' => $order_id, 'status' => 1,'type' => 1,'uid' => $uid,], 'number');
|
|
|
366
|
+// $spreadGongXian = 0;
|
|
|
367
|
+// if ($spreadUid) {
|
|
|
368
|
+// $spreadGongXian = $this->getValue('user_sign_gongxian', ['order_id' => $order_id, 'status' => 1,'type' => 1,'uid' => $spreadUid,], 'number');
|
|
|
369
|
+// }
|
|
|
370
|
+// $this->backupAndDelete('user_sign_gongxian', ['order_id' => $order_id]);
|
|
|
371
|
+// // 养老金 / 推广养老金 / 推广佣金
|
|
|
372
|
+// $yangLaoJin = $this->getValue('user_bill', ['link_id' => $order_id, 'status' => 1,'pm' => 1,'uid' => $uid,], 'number');
|
|
|
373
|
+// $spreadYlj = 0;
|
|
|
374
|
+// $spreadYongJin = 0;
|
|
|
375
|
+// if ($spreadUid) {
|
|
|
376
|
+// $spreadYlj = $this->getValue('user_bill', ['link_id' => $order_id, 'commission_type' => 5,'uid' => $spreadUid,], 'number'); //推荐获得养老金
|
|
|
377
|
+// $spreadYongJin = $this->getValue('user_bill', ['link_id' => $order_id, 'commission_type' => 3,'uid' => $spreadUid,], 'number'); //推荐获得佣金
|
|
|
378
|
+// }
|
|
|
379
|
+// $spreadYongJinTwo = $this->getValue('user_bill', ['link_id' => $order_id, 'commission_type' => 3, ['uid', '<>', $spreadUid],],'number');
|
|
|
380
|
+// $spreadYongJinTwoUid = $this->getValue('user_bill', ['link_id' => $order_id, 'commission_type' => 3, ['uid', '<>', $spreadUid],],'uid');
|
|
|
381
|
+// $this->backupAndDelete('user_bill', ['link_id' => $order_id]);
|
|
|
382
|
+// $this->backupAndDelete('gz_logs', ['link_id' => $order_id]);
|
|
|
383
|
+// //更新对应的user表
|
|
|
384
|
+// $user = Db::name('user')->where('uid', $uid)->find();
|
|
|
385
|
+// if ($user) {
|
|
|
386
|
+// Db::name('backup_user')->insert($user);
|
|
|
387
|
+// }
|
|
|
388
|
+// Db::name('user')->where('uid', $uid)->dec('pv', $pv)->update();
|
|
|
389
|
+// Db::name('user')->where('uid', $uid)->inc('vr', $payVr)->update();
|
|
|
390
|
+// Db::name('user')->where('uid', $uid)->inc('score', $payScore)->update();
|
|
|
391
|
+// Db::name('user')->where('uid', $uid)->dec('score', $score)->update();
|
|
|
392
|
+// Db::name('user')->where('uid', $uid)->dec('contribute', $gongXian)->update();
|
|
|
393
|
+// Db::name('user')->where('uid', $uid)->dec('annuity', $yangLaoJin)->update();
|
|
|
394
|
+// //推荐人user表
|
|
|
395
|
+// $spreadUser = Db::name('user')->where('uid', $spreadUid)->find();
|
|
|
396
|
+// if ($spreadUser) {
|
|
|
397
|
+// Db::name('backup_user')->insert($spreadUser);
|
|
|
398
|
+// }
|
|
|
399
|
+// Db::name('user')->where('uid', $spreadUid)->dec('score', $spreadScore)->update();
|
|
|
400
|
+// Db::name('user')->where('uid', $spreadUid)->dec('per_contribute', $spreadGongXian)->update();
|
|
|
401
|
+// Db::name('user')->where('uid', $spreadUid)->dec('annuity', $spreadYlj)->update();
|
|
|
402
|
+// Db::name('user')->where('uid', $spreadUid)->dec('brokerage_price', $spreadYongJin)->update();
|
|
|
403
|
+// //第二个推荐人
|
|
|
404
|
+// $spreadUserTwo = Db::name('user')->where('uid', $spreadYongJinTwoUid)->find();
|
|
|
405
|
+// if ($spreadUserTwo) {
|
|
|
406
|
+// Db::name('backup_user')->insert($spreadUserTwo);
|
|
|
407
|
+// }
|
|
|
408
|
+// Db::name('user')->where('uid', $spreadYongJinTwoUid)->dec('brokerage_price', $spreadYongJinTwo)->update();
|
|
|
409
|
+ Db::commit();
|
|
|
410
|
+ } catch (\Exception $e) {
|
|
|
411
|
+ Db::rollback();
|
|
|
412
|
+ return app('json')->fail('操作失败');
|
|
|
413
|
+ }
|
|
|
414
|
+ return app('json')->success('操作成功');
|
|
|
415
|
+ }
|
|
|
416
|
+ private function backupAndDelete($table, array $where)
|
|
|
417
|
+ {
|
|
|
418
|
+ $backupTable = 'backup_' . $table;
|
|
|
419
|
+ $rows = Db::name($table)->where($where)->select()->toArray();
|
|
|
420
|
+ if ($rows) {
|
|
|
421
|
+ Db::name($backupTable)->insertAll($rows);
|
|
|
422
|
+ Db::name($table)->where($where)->delete();
|
|
|
423
|
+ }
|
|
|
424
|
+ }
|
|
|
425
|
+ private function getValue($table, array $where, string $field, $default = 0)
|
|
|
426
|
+ {
|
|
|
427
|
+ $value = Db::name($table)->where($where)->value($field);
|
|
|
428
|
+ return $value ?? $default;
|
|
|
429
|
+ }
|
|
334
|
430
|
}
|