Bladeren bron

Merge branch 'dev-xpy' into dev

xupuyuan 10 maanden geleden
bovenliggende
commit
b8db2947c1
2 gewijzigde bestanden met toevoegingen van 85 en 0 verwijderingen
  1. 83 0
      app/controller/admin/order/Order.php
  2. 2 0
      route/merchant.php

+ 83 - 0
app/controller/admin/order/Order.php

@@ -331,4 +331,87 @@ 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]);
353
+            // 取出 vr 消耗
354
+            $payVr = $this->getValue('user_sign_vr', ['order_id' => $order_id, 'type' => 2,], 'number');
355
+            // 取出购买赠送积分 / 支出积分
356
+            $score = $this->getValue('user_sign_score', ['order_id' => $order_id, 'status' => 1,'source_type' => 3,'uid' => $uid,], 'reward_score');
357
+            $payScore = $this->getValue('user_sign_score', ['order_id' => $order_id, 'status' => 1,'pm' => 2,'uid' => $uid,], 'reward_score');
358
+            // 取出推广赠送的积分和推广人的 uid
359
+            $spreadScore = $this->getValue('user_sign_score', ['order_id' => $order_id, 'status' => 1,'pm' => 2,'source_type' => 3,['mark','like','%推广%'],], 'reward_score');
360
+            $spreadUid = $this->getValue('user_sign_score', [['order_id' => $order_id], ['status' => 1],['pm' => 2],['source_type' => 3],['mark','like','%推广%'],], 'uid');
361
+            // 删除所有相关积分记录
362
+            $this->backupAndDelete('user_sign_score', ['order_id' => $order_id]);
363
+            // 贡献值
364
+            $gongXian = $this->getValue('user_sign_gongxian', ['order_id' => $order_id, 'status' => 1,'type' => 1,'uid' => $uid,], 'number');
365
+            $spreadGongXian = 0;
366
+            if ($spreadUid) {
367
+                $spreadGongXian = $this->getValue('user_sign_gongxian', ['order_id' => $order_id, 'status' => 1,'type' => 1,'uid' => $spreadUid,], 'number');
368
+            }
369
+            $this->backupAndDelete('user_sign_gongxian', ['order_id' => $order_id]);
370
+            // 养老金 / 推广养老金 / 推广佣金
371
+            $yangLaoJin = $this->getValue('user_bill', ['link_id' => $order_id, 'status' => 1,'pm' => 1,'uid' => $uid,], 'number');
372
+            $spreadYlj = 0;
373
+            $spreadYongJin = 0;
374
+            if ($spreadUid) {
375
+                $spreadYlj = $this->getValue('user_bill', ['link_id' => $order_id, 'commission_type' => 5,'uid' => $spreadUid,], 'number'); //推荐获得养老金
376
+                $spreadYongJin = $this->getValue('user_bill', ['link_id' => $order_id, 'commission_type' => 3,'uid' => $spreadUid,], 'number');  //推荐获得佣金
377
+            }
378
+            $spreadYongJinTwo = $this->getValue('user_bill', ['link_id' => $order_id, 'commission_type'  => 3, ['uid', '<>', $spreadUid],],'number');
379
+            $spreadYongJinTwoUid = $this->getValue('user_bill', ['link_id' => $order_id, 'commission_type'  => 3, ['uid', '<>', $spreadUid],],'uid');
380
+            $this->backupAndDelete('user_bill', ['link_id' => $order_id]);
381
+            $this->backupAndDelete('gz_logs', ['link_id' => $order_id]);
382
+            //更新对应的user表
383
+            Db::name('user')->where('uid', $uid)->dec('pv', $pv)->update();
384
+            Db::name('user')->where('uid', $uid)->inc('vr', $payVr)->update();
385
+            Db::name('user')->where('uid', $uid)->inc('score', $payScore)->update();
386
+            Db::name('user')->where('uid', $uid)->dec('score', $score)->update();
387
+            Db::name('user')->where('uid', $uid)->dec('contribute', $gongXian)->update();
388
+            Db::name('user')->where('uid', $uid)->dec('annuity', $yangLaoJin)->update();
389
+            //推荐人user表
390
+            Db::name('user')->where('uid', $spreadUid)->dec('score', $spreadScore)->update();
391
+            Db::name('user')->where('uid', $spreadUid)->dec('per_contribute', $spreadGongXian)->update();
392
+            Db::name('user')->where('uid', $spreadUid)->dec('annuity', $spreadYlj)->update();
393
+            Db::name('user')->where('uid', $spreadUid)->dec('brokerage_price', $spreadYongJin)->update();
394
+            //第二个推荐人
395
+            Db::name('user')->where('uid', $spreadYongJinTwoUid)->dec('brokerage_price', $spreadYongJinTwo)->update();
396
+            Db::commit();
397
+        } catch (\Exception $e) {
398
+            Db::rollback();
399
+            return app('json')->fail('操作失败');
400
+        }
401
+        return app('json')->success('操作成功');
402
+    }
403
+    private function backupAndDelete($table, array $where)
404
+    {
405
+        $backupTable = 'backup_' . $table;
406
+        $rows = Db::name($table)->where($where)->select()->toArray();
407
+        if ($rows) {
408
+            Db::name($backupTable)->insertAll($rows);
409
+            Db::name($table)->where($where)->delete();
410
+        }
411
+    }
412
+    private function getValue($table, array $where, string $field, $default = 0)
413
+    {
414
+        $value = Db::name($table)->where($where)->value($field);
415
+        return $value ?? $default;
416
+    }
334 417
 }

+ 2 - 0
route/merchant.php

@@ -448,6 +448,7 @@ Route::group(config('admin.api_merchant_prefix') . '/', function () {
448 448
             Route::get('takechart', 'Order/takeChart')->name('merchantStoreTakeOrderTitle');
449 449
             Route::get('filtter', 'Order/orderType')->name('merchantStoreOrderFiltter');
450 450
             Route::get('lst', 'Order/lst')->name('merchantStoreOrderLst');
451
+            Route::post('killOrderRewards/', 'Order/killOrderRewards')->name('merchantStoreOrderKillOrderRewards');
451 452
             Route::get('userLst', 'Order/userLst')->name('merchantUserStoreOrderLst');
452 453
             Route::get('takelst', 'Order/takeLst')->name('merchantStoreTakeOrderLst');
453 454
             Route::get('express/:id', 'Order/express')->name('merchantStoreOrderExpress');
@@ -473,6 +474,7 @@ Route::group(config('admin.api_merchant_prefix') . '/', function () {
473 474
             Route::post('cancel/:id', 'Order/cancelGroupOrder')->name('cancelGroupOrder');// 取消订单
474 475
             Route::get('order_zhifu/:id', 'Order/order_zhifu')->name('zhifuGroupOrder');// 设置成支付成功
475 476
 
477
+
476 478
             Route::post('order_red_num', 'Order/order_red_num')->name('orderRedNum');// 判断是不是红积分支付的订单
477 479
             Route::post('order_red_add', 'Order/order_red_add')->name('orderRedAdd');// 养老金提交打款凭证
478 480
             Route::get('order_red_list', 'Order/order_red_list')->name('orderRedList');// 养老金打款凭证 列表