WithdrawLogLogic.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. <?php
  2. namespace app\admin\logic;
  3. use app\admin\model\dao\MoneyLog;
  4. use app\admin\model\dao\ScoreLog;
  5. use app\admin\model\dao\ShopOrder;
  6. use app\admin\model\dao\User;
  7. use app\admin\model\dao\WithdrawLog;
  8. use app\common\model\WithDrawLogModel;
  9. use think\facade\Cache;
  10. use think\facade\Db;
  11. class WithdrawLogLogic
  12. {
  13. public static function getList($page, $limit, $where, $userMap, $sort)
  14. {
  15. foreach ($where as $key => &$val) {
  16. if ($val[0] == 'status') {
  17. $where[$key][0] = 'w.status';
  18. }
  19. }
  20. $model = new WithDrawLogModel();
  21. $count = $model
  22. // ->withJoin('user', 'INNER')
  23. ->where($userMap)
  24. ->where($where)
  25. ->count();
  26. $list = $model
  27. ->alias('w')
  28. ->leftJoin('user u', 'u.id = w.uid')
  29. // ->withJoin('user', 'INNER')
  30. ->where($userMap)
  31. ->where($where)
  32. ->field('w.*,u.path,u.user_type,u.luzi_money')
  33. ->page($page, $limit)
  34. ->order($sort)
  35. ->select();
  36. $withdrawLog = new WithdrawLogLogic();
  37. foreach ($list as $key => &$val) {
  38. // 老刘下级 13824334135 uid 5344367
  39. // 郑跃兵 17888779318 uid 5344369,13866400965 uid 5344368
  40. // 大飞 19805553599 uid 5344633 ,18682271568 uid 5344640
  41. //
  42. // if ($val['user_type'] == 10){
  43. // $val['tips_text'] = '潘总号';
  44. // }else{
  45. // $val['tips_text'] = '其他线';
  46. // }
  47. // $val['tips_text'] = '其他线';
  48. //
  49. // if (strpos($val['path'], '5344367') !== false || $val['uid'] == 5344367){
  50. // $val['tips_text'] = '老刘下级';
  51. // }
  52. //
  53. // if ((strpos($val['path'], '5344633') !== false || $val['uid'] == 5344633) || (strpos($val['path'], '5344640') !== false || $val['uid'] == 5344640)){
  54. // $val['tips_text'] = '大飞下级';
  55. // }elseif ((strpos($val['path'], '5344369') !== false || $val['uid'] == 5344369) || (strpos($val['path'], '5344368') !== false || $val['uid'] == 5344368)){
  56. // $val['tips_text'] = '郑跃兵下级';
  57. // }
  58. // if (strpos($val['path'], '7493433') !== false){
  59. // $val['tips_text'] = '心态下级';
  60. // }
  61. //
  62. if (strpos($val['path'], '7493466') !== false) {
  63. $val['tips_text'] = '郑下级';
  64. }
  65. if ($val['luzi_money'] > 0) {
  66. $val['tips_text'] = '撸子标记,不要提现';
  67. } else {
  68. $val['tips_text'] = '';
  69. }
  70. $val['is_show'] = $withdrawLog->isShowReturnServiceMoney($val['id']);
  71. }
  72. return [$count, $list];
  73. }
  74. public static function withdrawError($id, $post)
  75. {
  76. $model = new WithDrawLogModel();
  77. $row = $model->where('id', $id)->where('status', 'in', '0')->find();
  78. if (empty($row)) return [false, '取消失败'];
  79. $row->status = 3;
  80. $row->fail_log = $post['error_text'];
  81. $is_backsx = $post['is_backsx'];
  82. $row->is_backsx = $is_backsx;
  83. Db::startTrans();
  84. try {
  85. if ($is_backsx == 1) {
  86. edit_user_money(10, $row['uid'], $row['apply_money']);
  87. } else {
  88. edit_user_money(10, $row['uid'], $row['practical_money']);
  89. }
  90. Db::name('user')->where('id', $row['uid'])->dec('total_withdraw', $row['apply_money'])->update();
  91. $row->save();
  92. Db::commit();
  93. } catch (\Exception $e) {
  94. Db::rollback();
  95. return [false, '取消失败' . $e->getMessage()];
  96. }
  97. return [true, '取消成功'];
  98. }
  99. public static function tx($id)
  100. {
  101. $model = new WithDrawLogModel();
  102. $info = $model->where('id', $id)->where('status', 0)->find();
  103. if (empty($info)) return [false, '提现记录不存在'];
  104. $user = User::getUserOrEmptyById($info['uid']);
  105. if (empty($user) || $user['status'] != 1) return [false, '用户不存在或已被禁用'];
  106. if ($user['luzi_money'] > 0) return [false, '撸子账号 联系技术处理'];
  107. User::updateTotalTeamWithdraw($user['path'], $info['apply_money']);
  108. User::updateTotalTeamWithdraw($user['id'], $info['apply_money']);
  109. // 支付宝提现
  110. if ($info['channel'] == 1) {
  111. $updateData = ['status' => 1, 'out_biz_no' => '1111', 'final_transfer_type' => 1];
  112. WithdrawLog::update($id, $updateData);
  113. return [true, '提现成功'];
  114. } else {
  115. $info->status = 1;
  116. $info->update_at = date('Y-m-d H:i:s', time());
  117. $info->final_transfer_type = 3;
  118. $info->save();
  119. }
  120. return [true, '提现成功'];
  121. }
  122. public static function getExportList($where, $page, $limit)
  123. {
  124. return (new WithDrawLogModel())
  125. ->where($where)
  126. ->withJoin('user', 'INNER')
  127. ->where($where)
  128. ->page($page, $limit)
  129. ->order('id', 'desc')
  130. ->select()
  131. ->toArray();
  132. }
  133. public function returnServiceMoney($post)
  134. {
  135. $withdrawLog = WithdrawLog::getWithdrawLogById($post['id']);
  136. if (empty($withdrawLog)) {
  137. return "记录不存在";
  138. }
  139. if ($withdrawLog['status'] != 3) {
  140. return "该提现记录不可以退还服务费";
  141. }
  142. if ($withdrawLog['service_money'] < $post['service_money']) {
  143. return "提现金额不可以大于服务费";
  144. }
  145. $moneyLog = MoneyLog::getMoneyLogByFromId($post['id']);
  146. if ($moneyLog) {
  147. return "当前提现记录已退还服务费";
  148. }
  149. Db::startTrans();
  150. try {
  151. $afterMoney = $withdrawLog['service_money'] + $post['service_money'];
  152. $moneyLog = [
  153. 'uid' => $withdrawLog['uid'],
  154. 'type' => 12,
  155. 'money' => $post['service_money'],
  156. 'create_at' => date('Y-m-d H:i:s'),
  157. 'state' => 1,
  158. 'from_id' => '0',
  159. 'before_money' => $withdrawLog['service_money'],
  160. 'after_money' => $afterMoney,
  161. 'uid2' => 0,
  162. 'free_type' => '',
  163. 'remark' => $post['remark'],
  164. 'withdraw_log_id' => $withdrawLog['id'],
  165. ];
  166. $serviceMoney = $withdrawLog['service_money'] - $post['service_money'];
  167. WithdrawLog::updateServiceMoney($withdrawLog['id'], $serviceMoney);
  168. MoneyLog::AddMoneyLog($moneyLog);
  169. User::UpdateUserMoney($withdrawLog['uid'], $afterMoney);
  170. Db::commit();
  171. } catch (\Exception $exception) {
  172. Db::rollback();
  173. return "失败:" . $exception->getMessage();
  174. }
  175. return true;
  176. }
  177. public function getWithdrawLog($id)
  178. {
  179. $withdrawLog = WithdrawLog::getWithdrawLogById($id);
  180. return $withdrawLog;
  181. }
  182. private function isShowReturnServiceMoney($id)
  183. {
  184. $key = 'WITHDRAWLOGRETURNSERVICEMONEY_' . $id;
  185. if (Cache::has($key) && 1 == 2) {
  186. return Cache::get($key);
  187. }
  188. $moneyLog = MoneyLog::getMoneyLogByFromId($id);
  189. $isShow = $moneyLog ? 1 : 0;
  190. Cache::set($key, $isShow, 5 * 60);
  191. return $isShow;
  192. }
  193. }