| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- <?php
- namespace app\admin\logic;
- use app\admin\model\dao\MoneyLog;
- use app\admin\model\dao\ScoreLog;
- use app\admin\model\dao\ShopOrder;
- use app\admin\model\dao\User;
- use app\admin\model\dao\WithdrawLog;
- use app\common\model\WithDrawLogModel;
- use think\facade\Cache;
- use think\facade\Db;
- class WithdrawLogLogic
- {
- public static function getList($page, $limit, $where, $userMap, $sort)
- {
- foreach ($where as $key => &$val) {
- if ($val[0] == 'status') {
- $where[$key][0] = 'w.status';
- }
- }
- $model = new WithDrawLogModel();
- $count = $model
- // ->withJoin('user', 'INNER')
- ->where($userMap)
- ->where($where)
- ->count();
- $list = $model
- ->alias('w')
- ->leftJoin('user u', 'u.id = w.uid')
- // ->withJoin('user', 'INNER')
- ->where($userMap)
- ->where($where)
- ->field('w.*,u.path,u.user_type,u.luzi_money')
- ->page($page, $limit)
- ->order($sort)
- ->select();
- $withdrawLog = new WithdrawLogLogic();
- foreach ($list as $key => &$val) {
- // 老刘下级 13824334135 uid 5344367
- // 郑跃兵 17888779318 uid 5344369,13866400965 uid 5344368
- // 大飞 19805553599 uid 5344633 ,18682271568 uid 5344640
- //
- // if ($val['user_type'] == 10){
- // $val['tips_text'] = '潘总号';
- // }else{
- // $val['tips_text'] = '其他线';
- // }
- // $val['tips_text'] = '其他线';
- //
- // if (strpos($val['path'], '5344367') !== false || $val['uid'] == 5344367){
- // $val['tips_text'] = '老刘下级';
- // }
- //
- // if ((strpos($val['path'], '5344633') !== false || $val['uid'] == 5344633) || (strpos($val['path'], '5344640') !== false || $val['uid'] == 5344640)){
- // $val['tips_text'] = '大飞下级';
- // }elseif ((strpos($val['path'], '5344369') !== false || $val['uid'] == 5344369) || (strpos($val['path'], '5344368') !== false || $val['uid'] == 5344368)){
- // $val['tips_text'] = '郑跃兵下级';
- // }
- // if (strpos($val['path'], '7493433') !== false){
- // $val['tips_text'] = '心态下级';
- // }
- //
- if (strpos($val['path'], '7493466') !== false) {
- $val['tips_text'] = '郑下级';
- }
- if ($val['luzi_money'] > 0) {
- $val['tips_text'] = '撸子标记,不要提现';
- } else {
- $val['tips_text'] = '';
- }
- $val['is_show'] = $withdrawLog->isShowReturnServiceMoney($val['id']);
- }
- return [$count, $list];
- }
- public static function withdrawError($id, $post)
- {
- $model = new WithDrawLogModel();
- $row = $model->where('id', $id)->where('status', 'in', '0')->find();
- if (empty($row)) return [false, '取消失败'];
- $row->status = 3;
- $row->fail_log = $post['error_text'];
- $is_backsx = $post['is_backsx'];
- $row->is_backsx = $is_backsx;
- Db::startTrans();
- try {
- if ($is_backsx == 1) {
- edit_user_money(10, $row['uid'], $row['apply_money']);
- } else {
- edit_user_money(10, $row['uid'], $row['practical_money']);
- }
- Db::name('user')->where('id', $row['uid'])->dec('total_withdraw', $row['apply_money'])->update();
- $row->save();
- Db::commit();
- } catch (\Exception $e) {
- Db::rollback();
- return [false, '取消失败' . $e->getMessage()];
- }
- return [true, '取消成功'];
- }
- public static function tx($id)
- {
- $model = new WithDrawLogModel();
- $info = $model->where('id', $id)->where('status', 0)->find();
- if (empty($info)) return [false, '提现记录不存在'];
- $user = User::getUserOrEmptyById($info['uid']);
- if (empty($user) || $user['status'] != 1) return [false, '用户不存在或已被禁用'];
- if ($user['luzi_money'] > 0) return [false, '撸子账号 联系技术处理'];
- User::updateTotalTeamWithdraw($user['path'], $info['apply_money']);
- User::updateTotalTeamWithdraw($user['id'], $info['apply_money']);
- // 支付宝提现
- if ($info['channel'] == 1) {
- $updateData = ['status' => 1, 'out_biz_no' => '1111', 'final_transfer_type' => 1];
- WithdrawLog::update($id, $updateData);
- return [true, '提现成功'];
- } else {
- $info->status = 1;
- $info->update_at = date('Y-m-d H:i:s', time());
- $info->final_transfer_type = 3;
- $info->save();
- }
- return [true, '提现成功'];
- }
- public static function getExportList($where, $page, $limit)
- {
- return (new WithDrawLogModel())
- ->where($where)
- ->withJoin('user', 'INNER')
- ->where($where)
- ->page($page, $limit)
- ->order('id', 'desc')
- ->select()
- ->toArray();
- }
- public function returnServiceMoney($post)
- {
- $withdrawLog = WithdrawLog::getWithdrawLogById($post['id']);
- if (empty($withdrawLog)) {
- return "记录不存在";
- }
- if ($withdrawLog['status'] != 3) {
- return "该提现记录不可以退还服务费";
- }
- if ($withdrawLog['service_money'] < $post['service_money']) {
- return "提现金额不可以大于服务费";
- }
- $moneyLog = MoneyLog::getMoneyLogByFromId($post['id']);
- if ($moneyLog) {
- return "当前提现记录已退还服务费";
- }
- Db::startTrans();
- try {
- $afterMoney = $withdrawLog['service_money'] + $post['service_money'];
- $moneyLog = [
- 'uid' => $withdrawLog['uid'],
- 'type' => 12,
- 'money' => $post['service_money'],
- 'create_at' => date('Y-m-d H:i:s'),
- 'state' => 1,
- 'from_id' => '0',
- 'before_money' => $withdrawLog['service_money'],
- 'after_money' => $afterMoney,
- 'uid2' => 0,
- 'free_type' => '',
- 'remark' => $post['remark'],
- 'withdraw_log_id' => $withdrawLog['id'],
- ];
- $serviceMoney = $withdrawLog['service_money'] - $post['service_money'];
- WithdrawLog::updateServiceMoney($withdrawLog['id'], $serviceMoney);
- MoneyLog::AddMoneyLog($moneyLog);
- User::UpdateUserMoney($withdrawLog['uid'], $afterMoney);
- Db::commit();
- } catch (\Exception $exception) {
- Db::rollback();
- return "失败:" . $exception->getMessage();
- }
- return true;
- }
- public function getWithdrawLog($id)
- {
- $withdrawLog = WithdrawLog::getWithdrawLogById($id);
- return $withdrawLog;
- }
- private function isShowReturnServiceMoney($id)
- {
- $key = 'WITHDRAWLOGRETURNSERVICEMONEY_' . $id;
- if (Cache::has($key) && 1 == 2) {
- return Cache::get($key);
- }
- $moneyLog = MoneyLog::getMoneyLogByFromId($id);
- $isShow = $moneyLog ? 1 : 0;
- Cache::set($key, $isShow, 5 * 60);
- return $isShow;
- }
- }
|