Tx.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | [ WE CAN DO IT MORE SIMPLE ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2018-2020 rights reserved.
  6. // +----------------------------------------------------------------------
  7. // |
  8. // +----------------------------------------------------------------------
  9. // | Date: 2020-11-08 12:56
  10. // +----------------------------------------------------------------------
  11. namespace app\system\controller\v1;
  12. use app\BaseController;
  13. use app\model\api\Tx as TxModel;
  14. use app\model\api\User as UserModel;
  15. use app\model\api\Sys as SysModel;
  16. use app\model\api\Bank as BankModel;
  17. use app\model\api\UserDetail as UserDetailModel;
  18. use app\model\api\TuserDetail as TuserDetailModel;
  19. use think\db\exception\DbException;
  20. use think\facade\Db;
  21. use app\Request;
  22. use library\services\UtilService;
  23. class Tx extends BaseController
  24. {
  25. /**
  26. * 初始化
  27. * @param Request $request
  28. * @return type
  29. */
  30. public function init(Request $request)
  31. {
  32. [$isTuser] = UtilService::getMore(
  33. [
  34. ['isTuser',0],
  35. ], $request,true);
  36. $isTuser = empty($isTuser) ? 0 : 1;
  37. $where=[];
  38. //获取全部提现
  39. $allTx = (new TxModel)->where($where)->count();
  40. $noTx = (new TxModel)->where($where)->where('status', 0)->count();
  41. $yeTx = (new TxModel)->where($where)->where('status', 1)->count();
  42. $errTx = (new TxModel)->where($where)->where('status', -1)->count();
  43. $bankList = (new BankModel)
  44. // ->where("status",1)
  45. ->order("seq","desc")
  46. ->order("id","desc")
  47. ->select()
  48. ->toArray();
  49. $bankList = empty($bankList)?[]:$bankList;
  50. return app('json')->success([
  51. 'all_tx' => $allTx,
  52. 'no_tx' => $noTx,
  53. 'yes_tx' => $yeTx,
  54. 'err_tx' => $errTx,
  55. 'bankList'=>$bankList,
  56. ]);
  57. }
  58. /**
  59. * 获取提现列表
  60. * @param Request $request
  61. */
  62. public function list(Request $request)
  63. {
  64. $pageSize = 50;
  65. $post = UtilService::getMore(
  66. [
  67. //公共参数
  68. ['page', 1],
  69. ['status', ''],
  70. ['bank_type', ''],
  71. ['time',[]],
  72. //手机用户
  73. ['mobile',''],
  74. ['uip', ''],
  75. ['uid', ''],
  76. ], $request
  77. );
  78. $where=[];
  79. //公共参数
  80. if(is_numeric($post['status'])) {
  81. $where[]=['t.status',"=",$post['status']];
  82. }
  83. if(!empty($post['bank_type'])) {
  84. $where[]=['t.bank_type',"=",$post['bank_type']];
  85. }
  86. //提现时间
  87. $startTime = "";
  88. $endTime = "";
  89. if(!empty($post['time'][0]) && !empty($post['time'][1])) {
  90. $startTime = strtotime($post['time'][0]);
  91. $endTime = strtotime($post['time'][1]);
  92. $where[]=['t.time',"between","{$startTime},{$endTime}"];
  93. }
  94. //用户uid
  95. if(is_numeric($post['uid'])) {
  96. $where[]=['t.uid',"=",$post['uid']];
  97. }else if (!empty($post['uip'])) {
  98. $m = Db::name("user")->where("uip",$post['uip'])->find();
  99. if(!empty($m)) {
  100. $where[]=['t.uid',"=",$m['uid']];
  101. }
  102. }else if (!empty($post['mobile'])) {
  103. $m = Db::name("user")->where("mobile",$post['mobile'])->find();
  104. if(!empty($m)) {
  105. $where[]=['t.uid',"=",$m['uid']];
  106. }
  107. }
  108. $data = (new TxModel)
  109. ->alias("t")
  110. ->field("t.*,u.uip,u.nickname,u.mobile,a.username as admin_name,b.name as bank_type_name")
  111. ->leftJoin("user u", "u.uid = t.uid")
  112. ->leftJoin("admin a", "a.id = t.admin_id")
  113. ->leftJoin("bank b", "b.code = t.bank_type")
  114. ->where($where)
  115. ->page((int)$post["page"], $pageSize)
  116. ->order("t.id","desc")
  117. ->select()
  118. ->toArray();
  119. $pageCount = (new TxModel)->alias("t")->where($where)->count();
  120. $result = UtilService::getParam([
  121. "id",
  122. "uid",
  123. "bank_type",
  124. "bank_type_name",
  125. "bank_num",
  126. "bank_name",
  127. "bank_ad",
  128. "money",
  129. "tx_money",
  130. "hand_money",
  131. "status",
  132. ["time", "time", "date('Y-m-d H:i:s',$1)"],
  133. "admin_id",
  134. "admin_remark",
  135. ["admin_time", "admin_time", function ($item) {
  136. return empty($item) ? '' : date('Y-m-d H:i:s', $item);
  137. }],
  138. "admin_name",
  139. "mobile",
  140. "nickname",
  141. "uip",
  142. ], $data);
  143. return app('json')->success([
  144. 'list' => $result,
  145. 'pageCount' => $pageCount,
  146. 'pageSize' => $pageSize,
  147. 'page' => $post['page'],
  148. ]);
  149. }
  150. /**
  151. * 提现处理
  152. * @param Request $request
  153. */
  154. public function dealSub(Request $request)
  155. {
  156. $post = UtilService::getMore(
  157. [
  158. ['id', '', 'empty', '参数错误'],
  159. ['mono'],
  160. ['type', 0],
  161. ], $request);
  162. $txData = (new TxModel)->where('id', $post['id'])->find();
  163. if (empty($txData)) {
  164. return app('json')->fail('数据不存在');
  165. }
  166. if ($txData['status']!=0) {
  167. return app('json')->success( '当前提现申请已处理');
  168. }
  169. //提现通过
  170. if ($post['type'] == 1) {
  171. (new TxModel)
  172. ->where('id', $post['id'])
  173. ->save([
  174. 'status' => 1,
  175. 'admin_remark' => empty($post['mono'])?"已确认打款":$post['mono'],
  176. 'admin_time' => time(),
  177. 'admin_id' => $request->adminInfo['id'],
  178. ]);
  179. return app('json')->success('操作成功');
  180. }
  181. //提现驳回
  182. if ($post['type'] == -1) {
  183. //添加事件回滚
  184. try{
  185. Db::startTrans();
  186. (new TxModel)
  187. ->where('id', $post['id'])
  188. ->save([
  189. 'status' => -1,
  190. 'admin_remark' => empty($post['mono'])?"已驳回申请":$post['mono'],
  191. 'admin_time' => time(),
  192. 'admin_id' => $request->adminInfo['id'],
  193. ]);
  194. if($txData["uid"]>0){
  195. //用户提现驳回
  196. (new UserDetailModel)->txRefundMoney($txData['uid'],$txData["money"],$txData["id"]);
  197. }else{
  198. return app("json")->fail("提现用户不存在");
  199. }
  200. Db::commit();
  201. return app('json')->success('操作成功');
  202. }catch(DbException $db){
  203. Db::rollback();
  204. return app("json")->fail("操作失败");
  205. }
  206. }
  207. }
  208. /**
  209. * 获取订单数据
  210. * @param Request $request
  211. */
  212. public function down(Request $request)
  213. {
  214. $pageSize = 40000;
  215. $post = UtilService::getMore(
  216. [
  217. ['page', 1],
  218. ['mobile',''],
  219. ['status', ''],
  220. ['bank_type', ''],
  221. ['uid', ''],
  222. ['time',[]],
  223. ], $request
  224. );
  225. $where = [];
  226. $where=[];
  227. if(is_numeric($post['status'])) {
  228. $where['t.status'] = $post['status'];
  229. }
  230. if(is_numeric($post['uid'])) {
  231. $where['t.uid'] = $post['uid'];
  232. }
  233. if (!empty($post['mobile'])) {
  234. $m = Db::name("user")->where("mobile",$post['mobile'])->find();
  235. if(!empty($m)) {
  236. $where['t.uid'] = $m['uid'];
  237. }
  238. }
  239. if(!empty($post['bank_type'])) {
  240. $where['t.bank_type'] = $post['bank_type'];
  241. }
  242. $startTime = "";
  243. $endTime = "";
  244. if(!empty($post['time'][0]) && !empty($post['time'][1])) {
  245. $startTime = strtotime($post['time'][0]);
  246. $endTime = strtotime($post['time'][1]);
  247. }
  248. $data = (new TxModel)
  249. ->alias("t")
  250. ->field("t.*,u.uip,u.nickname,u.mobile,a.username as admin_name")
  251. ->leftJoin("user u", "u.uid = t.uid")
  252. ->leftJoin("admin a", "a.id = t.admin_id")
  253. ->where($where)
  254. ->when((!empty($startTime) && !empty($endTime)),function($query)use($startTime,$endTime){
  255. $query->whereBetween("t.time","{$startTime},{$endTime}");
  256. })
  257. ->limit(0,30000)
  258. ->order("t.id","desc")
  259. ->select()
  260. ->toArray();
  261. $pageCount = (new TxModel)
  262. ->alias("t")
  263. ->leftJoin("user u", "u.uid = t.uid")
  264. ->leftJoin("admin a", "a.id = t.admin_id")
  265. ->where($where)
  266. ->when((!empty($startTime) && !empty($endTime)),function($query)use($startTime,$endTime){
  267. $query->whereBetween("t.time","{$startTime},{$endTime}");
  268. })
  269. ->count();
  270. $result = UtilService::getParam([
  271. "id",
  272. "uid",
  273. "bank_type",
  274. "bank_num",
  275. "bank_name",
  276. "bank_ad",
  277. "money",
  278. "tx_money",
  279. "hand_money",
  280. "status",
  281. ["time", "time", "date('Y-m-d H:i:s',$1)"],
  282. "admin_id",
  283. "admin_remark",
  284. ["admin_time", "admin_time", function ($item) {
  285. return empty($item) ? '' : date('Y-m-d H:i:s', $item);
  286. }],
  287. "admin_name",
  288. "mobile",
  289. "nickname",
  290. "uip",
  291. ], $data);
  292. return app('json')->success([
  293. 'list' => $result,
  294. 'pageCount' => $pageCount,
  295. 'pageSize' => $pageSize,
  296. 'page' => $post['page'],
  297. ]);
  298. }
  299. }