| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- <?php
- namespace app\command;
- use app\common\model\shared\SharedProsperityPartnerConsumeUpdateLog;
- use app\common\repositories\shared\SharedProsperityRecommendConfigRepository;
- use think\console\Command;
- use think\console\Input;
- use think\console\Output;
- use think\facade\Db;
- class SharedOfflineOrderProfitDelete extends Command
- {
- // 变更数量
- const NUMBER = 5;
- const CONFIG_ID = 2;
- protected function configure()
- {
- // 指令配置
- $this->setName('sharedOfflineOrderProfitDelete')
- ->setDescription('共富区线下扫码订单分账回撤');
- }
- protected function execute(Input $input, Output $output)
- {
- $output->writeln('定时任务执行中...');
- $this->delete();
- $output->writeln('定时任务执行完成');
- }
- private function delete()
- {
- $ids = [
- 13799,
- 13798,
- 13795,
- 13784,
- 13775,
- 13774,
- 13773,
- 13754,
- 13753,
- 13750,
- 13749
- ];
- $orderData = Db::name('order_merchant')
- ->where(['id' => $ids])
- ->select()
- ->toArray();
- Db::startTrans();
- try {
- foreach ($orderData as $order) {
- // bill表
- $billData = Db::name('user_bill')->where(['order_sn' => $order['out_trade_no']])->select()->toArray();
- foreach ($billData as $bill) {
- // 消费者本人和推荐人养老金数据删除
- if ($bill['commission_type'] == 5) {
- Db::name('user_bill')->where(['bill_id' => $bill['bill_id']])->delete();
- }
- // 商户跨店佣金删除
- if ($bill['commission_type'] == 7) {
- Db::name('user_bill')->where(['bill_id' => $bill['bill_id']])->delete();
- Db::name("user")->where("uid", $bill['uid'])->dec('brokerage_price', $bill['number'])->update();
- }
- // 佣金删除
- if ($bill['commission_type'] == 3) {
- Db::name('user_bill')->where(['bill_id' => $bill['bill_id']])->delete();
- Db::name("user")->where("uid", $bill['uid'])->dec('brokerage_price', $bill['number'])->update();
- }
- }
- // 删除红包数据和用户表字段数据
- $red = Db::name('user_sign_hongbao')->where(['order_id' => $order['id']])->find();
- if ($red) {
- Db::name('user_sign_hongbao')->where(['id' => $red['id']])->delete();
- Db::name('user')->where(['uid' => $red['uid']])->dec('hongbao', $red['number'])->update();
- }
- // 删除积分数据和用户表字段数据
- $scoreData = Db::name('user_sign_score')->where(['order_id' => $order['id']])->select()->toArray();
- if ($scoreData) {
- foreach ($scoreData as $score) {
- Db::name('user_sign_score')->where(['id' => $score['id']])->delete();
- Db::name('user')->where(['uid' => $score['uid']])->dec('score', $score['reward_socre'])->update();
- }
- }
- // 删除贡献值数据和用户表字段数据
- $contributionData = Db::name('user_sign_gongxian')->where(['order_id' => $order['id']])->select()->toArray();
- if ($contributionData) {
- foreach ($contributionData as $contribution) {
- Db::name('user_sign_gongxian')->where(['id' => $contribution['id']])->delete();
- Db::name('user')->where(['uid' => $contribution['uid']])->dec('contribute', $contribution['number'])->update();
- }
- }
- // pv
- $pvData = Db::name('user_pv_log')->where(['order_id' => $order['id']])->find();
- if ($pvData) {
- Db::name('user_pv_log')->where(['id' => $pvData['id']])->delete();
- Db::name('user')->where(['uid' => $pvData['uid']])->dec('pv', $pvData['pv'])->update();
- }
- // 复购金
- $rebuyData = Db::name('user_sign_fugou')->where(['order_id' => $order['id']])->find();
- if ($rebuyData) {
- Db::name('user_sign_fugou')->where(['id' => $rebuyData['id']])->delete();
- Db::name('user')->where(['uid' => $rebuyData['uid']])->dec('fugou', $rebuyData['number'])->update();
- }
- // 商户得到的京豆
- $beanData = Db::name('user_sign_jingdou')->where(['order_id' => $order['id']])->find();
- if ($beanData) {
- Db::name('user_sign_jingdou')->where(['id' => $beanData['id']])->delete();
- Db::name('user')->where(['uid' => $beanData['uid']])->dec('jingdou', $beanData['number'])->update();
- }
- //扫码下单产生分润值
- $profitData = Db::name('user_sign_fenrun')->where(['order_id' => $order['id']])->find();
- if ($profitData) {
- Db::name('user_sign_fenrun')->where(['id' => $profitData['id']])->delete();
- }
- }
- Db::commit();
- return true;
- } catch (\Exception $e) {
- Db::rollback();
- dd($e->getFile(),$e->getMessage(),$e->getLine());
- }
- }
- }
|