|
|
@@ -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
|
}
|