SharedOfflineOrderProfitDelete.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. namespace app\command;
  3. use app\common\model\shared\SharedProsperityPartnerConsumeUpdateLog;
  4. use app\common\repositories\shared\SharedProsperityRecommendConfigRepository;
  5. use think\console\Command;
  6. use think\console\Input;
  7. use think\console\Output;
  8. use think\facade\Db;
  9. class SharedOfflineOrderProfitDelete extends Command
  10. {
  11. // 变更数量
  12. const NUMBER = 5;
  13. const CONFIG_ID = 2;
  14. protected function configure()
  15. {
  16. // 指令配置
  17. $this->setName('sharedOfflineOrderProfitDelete')
  18. ->setDescription('共富区线下扫码订单分账回撤');
  19. }
  20. protected function execute(Input $input, Output $output)
  21. {
  22. $output->writeln('定时任务执行中...');
  23. $this->delete();
  24. $output->writeln('定时任务执行完成');
  25. }
  26. private function delete()
  27. {
  28. $ids = [
  29. 13799,
  30. 13798,
  31. 13795,
  32. 13784,
  33. 13775,
  34. 13774,
  35. 13773,
  36. 13754,
  37. 13753,
  38. 13750,
  39. 13749
  40. ];
  41. $orderData = Db::name('order_merchant')
  42. ->where(['id' => $ids])
  43. ->select()
  44. ->toArray();
  45. Db::startTrans();
  46. try {
  47. foreach ($orderData as $order) {
  48. // bill表
  49. $billData = Db::name('user_bill')->where(['order_sn' => $order['out_trade_no']])->select()->toArray();
  50. foreach ($billData as $bill) {
  51. // 消费者本人和推荐人养老金数据删除
  52. if ($bill['commission_type'] == 5) {
  53. Db::name('user_bill')->where(['bill_id' => $bill['bill_id']])->delete();
  54. }
  55. // 商户跨店佣金删除
  56. if ($bill['commission_type'] == 7) {
  57. Db::name('user_bill')->where(['bill_id' => $bill['bill_id']])->delete();
  58. Db::name("user")->where("uid", $bill['uid'])->dec('brokerage_price', $bill['number'])->update();
  59. }
  60. // 佣金删除
  61. if ($bill['commission_type'] == 3) {
  62. Db::name('user_bill')->where(['bill_id' => $bill['bill_id']])->delete();
  63. Db::name("user")->where("uid", $bill['uid'])->dec('brokerage_price', $bill['number'])->update();
  64. }
  65. }
  66. // 删除红包数据和用户表字段数据
  67. $red = Db::name('user_sign_hongbao')->where(['order_id' => $order['id']])->find();
  68. if ($red) {
  69. Db::name('user_sign_hongbao')->where(['id' => $red['id']])->delete();
  70. Db::name('user')->where(['uid' => $red['uid']])->dec('hongbao', $red['number'])->update();
  71. }
  72. // 删除积分数据和用户表字段数据
  73. $scoreData = Db::name('user_sign_score')->where(['order_id' => $order['id']])->select()->toArray();
  74. if ($scoreData) {
  75. foreach ($scoreData as $score) {
  76. Db::name('user_sign_score')->where(['id' => $score['id']])->delete();
  77. Db::name('user')->where(['uid' => $score['uid']])->dec('score', $score['reward_socre'])->update();
  78. }
  79. }
  80. // 删除贡献值数据和用户表字段数据
  81. $contributionData = Db::name('user_sign_gongxian')->where(['order_id' => $order['id']])->select()->toArray();
  82. if ($contributionData) {
  83. foreach ($contributionData as $contribution) {
  84. Db::name('user_sign_gongxian')->where(['id' => $contribution['id']])->delete();
  85. Db::name('user')->where(['uid' => $contribution['uid']])->dec('contribute', $contribution['number'])->update();
  86. }
  87. }
  88. // pv
  89. $pvData = Db::name('user_pv_log')->where(['order_id' => $order['id']])->find();
  90. if ($pvData) {
  91. Db::name('user_pv_log')->where(['id' => $pvData['id']])->delete();
  92. Db::name('user')->where(['uid' => $pvData['uid']])->dec('pv', $pvData['pv'])->update();
  93. }
  94. // 复购金
  95. $rebuyData = Db::name('user_sign_fugou')->where(['order_id' => $order['id']])->find();
  96. if ($rebuyData) {
  97. Db::name('user_sign_fugou')->where(['id' => $rebuyData['id']])->delete();
  98. Db::name('user')->where(['uid' => $rebuyData['uid']])->dec('fugou', $rebuyData['number'])->update();
  99. }
  100. // 商户得到的京豆
  101. $beanData = Db::name('user_sign_jingdou')->where(['order_id' => $order['id']])->find();
  102. if ($beanData) {
  103. Db::name('user_sign_jingdou')->where(['id' => $beanData['id']])->delete();
  104. Db::name('user')->where(['uid' => $beanData['uid']])->dec('jingdou', $beanData['number'])->update();
  105. }
  106. //扫码下单产生分润值
  107. $profitData = Db::name('user_sign_fenrun')->where(['order_id' => $order['id']])->find();
  108. if ($profitData) {
  109. Db::name('user_sign_fenrun')->where(['id' => $profitData['id']])->delete();
  110. }
  111. }
  112. Db::commit();
  113. return true;
  114. } catch (\Exception $e) {
  115. Db::rollback();
  116. dd($e->getFile(),$e->getMessage(),$e->getLine());
  117. }
  118. }
  119. }