作者 何书鹏

删除用户数据

@@ -98,7 +98,67 @@ class User extends Backend @@ -98,7 +98,67 @@ class User extends Backend
98 if (!$row) { 98 if (!$row) {
99 $this->error(__('No Results were found')); 99 $this->error(__('No Results were found'));
100 } 100 }
101 - Auth::instance()->delete($row['id']); 101 + //开启事务
  102 + Db::startTrans();
  103 + try {
  104 + // 删除会员
  105 + Auth::instance()->delete($row['id']);
  106 + // 会员套餐订单
  107 + Db::name('package_order')->where('user_id',$row['id'])->delete();
  108 + // 拼团
  109 + Db::name('shopro_activity_groupon')->where('user_id',$row['id'])->delete();
  110 + // 拼团记录
  111 + Db::name('shopro_activity_groupon_log')->where('user_id',$row['id'])->delete();
  112 + // 购物车
  113 + Db::name('shopro_cart')->where('user_id',$row['id'])->delete();
  114 + // 反馈
  115 + Db::name('shopro_feedback')->where('user_id',$row['id'])->delete();
  116 + // 商品搜索历史
  117 + Db::name('shopro_goods_keywords')->where('user_id',$row['id'])->delete();
  118 + // 订单
  119 + $order_list = Db::name('shopro_order')->where('user_id',$row['id'])->field('id,order_sn')->select();
  120 + foreach ($order_list as $order){
  121 + // 订单操作记录
  122 + Db::name('shopro_order_action')->where('order_id',$order['id'])->delete();
  123 + // 售后单
  124 + Db::name('shopro_order_aftersale')->where('order_id',$order['id'])->delete();
  125 + // 售后单记录
  126 + Db::name('shopro_order_aftersale_log')->where('order_id',$order['id'])->delete();
  127 + // 快递包裹
  128 + Db::name('shopro_order_express')->where('order_id',$order['id'])->delete();
  129 + // 物流信息
  130 + Db::name('shopro_order_express_log')->where('order_id',$order['id'])->delete();
  131 + // 订单商品明细
  132 + Db::name('shopro_order_item')->where('order_id',$order['id'])->delete();
  133 + // 退款日志
  134 + Db::name('shopro_refund_log')->where('order_sn',$order['order_sn'])->delete();
  135 + // 删除订单
  136 + Db::name('shopro_order')->where('id',$order['id'])->delete();
  137 + }
  138 + // 用户地址
  139 + Db::name('shopro_user_address')->where('user_id',$row['id'])->delete();
  140 + // 用户优惠券
  141 + Db::name('shopro_user_coupons')->where('user_id',$row['id'])->delete();
  142 + // 用户收藏
  143 + Db::name('shopro_user_favorite')->where('user_id',$row['id'])->delete();
  144 + // 第三方授权
  145 + Db::name('shopro_user_oauth')->where('user_id',$row['id'])->delete();
  146 + // 用户浏览记录
  147 + Db::name('shopro_user_view')->where('user_id',$row['id'])->delete();
  148 + // 用户提现
  149 + Db::name('shopro_user_wallet_apply')->where('user_id',$row['id'])->delete();
  150 + // 钱包日志
  151 + Db::name('shopro_user_wallet_log')->where('user_id',$row['id'])->delete();
  152 + // 佣金提现
  153 + Db::name('user_commission_apply')->where('user_id',$row['id'])->delete();
  154 + // 佣金日志
  155 + Db::name('user_commission_log')->where('user_id',$row['id'])->delete();
  156 + Db::commit();
  157 + } catch (\Exception $e) {
  158 + Db::rollback();
  159 + $this->error($e->getMessage());
  160 + return false;
  161 + }
102 $this->success(); 162 $this->success();
103 } 163 }
104 164