Recharge.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. <?php
  2. namespace app\admin\controller\user;
  3. use app\common\model\MoneyLog;
  4. use app\common\model\PaymentModel;
  5. use app\common\model\RechargeOrderModel;
  6. use app\common\model\ScoreLog;
  7. //use app\admin\model\UpgradeLog;
  8. use app\common\model\ScoreLogModel;
  9. use app\common\model\User as UserModel;
  10. use app\common\model\UserData;
  11. use app\admin\traits\Curd;
  12. use app\common\constants\AdminConstant;
  13. use app\common\controller\AdminController;
  14. use app\common\model\UserMoneyModel;
  15. use app\common\model\UserteamLogModel;
  16. use app\Request;
  17. use EasyAdmin\tool\CommonTool;
  18. use jianyan\excel\Excel;
  19. use think\App;
  20. use think\facade\Db;
  21. class Recharge extends AdminController
  22. {
  23. public function __construct (App $app)
  24. {
  25. parent::__construct($app);
  26. $this->model = new RechargeOrderModel();
  27. }
  28. protected $sort = [
  29. 'order_id' => 'desc',
  30. ];
  31. use Curd;
  32. /**
  33. * 充值列表
  34. * @return mixed|\think\response\Json
  35. * @throws \think\db\exception\DataNotFoundException
  36. * @throws \think\db\exception\DbException
  37. * @throws \think\db\exception\ModelNotFoundException
  38. */
  39. public function index ()
  40. {
  41. if ($this->request->isAjax()) {
  42. if (input('selectFields')) {
  43. return $this->selectList();
  44. }
  45. list($page, $limit, $where) = $this->buildTableParames();
  46. // if (($pid = $this->request->param('pid')) !== false && $pid)
  47. // $where[] = ['pid', '=', $this->request->param('pid', '')];
  48. sr_log(json_encode($where));
  49. $count = $this->model
  50. // ->withJoin('userData', 'INNER')
  51. ->where($where)
  52. // ->where($this->user_map)
  53. ->count();
  54. $list = $this->model
  55. // ->withJoin('userData', 'INNER')
  56. ->where($where)
  57. // ->where($this->user_map)
  58. ->page($page, $limit)
  59. ->order($this->sort)
  60. ->select();
  61. $data = [
  62. 'code' => 0,
  63. 'msg' => Db::getLastSql(),
  64. 'count' => $count,
  65. 'data' => $list,
  66. ];
  67. return json($data);
  68. }
  69. return $this->fetch();
  70. }
  71. public function agree($id){
  72. $info = $this->model->where('order_id', $id)->where('status', 3)->find();
  73. if (empty($info))
  74. $this->error('记录不存在');
  75. $user = Db::name('user')->findOrEmpty(['id' => $info['user_id']]);
  76. if (empty($user) || $user['status'] != 1)
  77. $this->error('用户不存在或已被禁用');
  78. $paymodel = new PaymentModel();
  79. // $pay_info = $paymodel->where('remarks', $info['recharge_sn']);
  80. $nowTime = date('Y-m-d H:i:s', time());
  81. $info->save(['status'=>2, 'pay_type'=>19,'updated_time' => $nowTime]);
  82. edit_user_money(12, $info['user_id'], $info['payment']);
  83. $this->success('处理成功');
  84. }
  85. public function disagree($id){
  86. if ($this->request->isPost()){
  87. $post = $this->request->post();
  88. $row = $this->model->where('order_id', $id)->where('status', 'in', '3')->find();
  89. empty($row) && $this->error('取消失败');
  90. $row->status = 4;
  91. $row->error_text = $post['error_text'];
  92. Db::startTrans();
  93. try {
  94. $row->save();
  95. Db::commit();
  96. } catch (\Exception $e) {
  97. Db::rollback();
  98. $this->error('取消失败'.$e->getMessage());
  99. }
  100. $this->success('取消成功');
  101. }
  102. return $this->fetch();
  103. }
  104. /**
  105. * 禁用用户
  106. * @param $id
  107. */
  108. public function forbid ($id)
  109. {
  110. $user = $this->model->findOrEmpty($id);
  111. empty($user) && $this->error('数据不存在');
  112. $user['status'] == 0 && $this->error('该用户已被禁用');
  113. if ($this->model->where('id', $id)->save(['status' => 0]))
  114. $this->success('禁用成功');
  115. else
  116. $this->error('禁用失败');
  117. }
  118. /**
  119. * 启用用户
  120. * @param $id
  121. */
  122. public function enable ($id)
  123. {
  124. $user = $this->model->findOrEmpty($id);
  125. empty($user) && $this->error('数据不存在');
  126. $user['status'] == 1 && $this->error('该用户已启用');
  127. if ($this->model->where('id', $id)->save(['status' => 1]))
  128. $this->success('启用成功');
  129. else
  130. $this->error('启用失败');
  131. }
  132. /**
  133. * 会员详情
  134. * @param Request $request
  135. * @param UpgradeLog $upgradeLog
  136. * @return mixed
  137. * @throws \think\db\exception\DataNotFoundException
  138. * @throws \think\db\exception\DbException
  139. * @throws \think\db\exception\ModelNotFoundException
  140. */
  141. public function details (Request $request)
  142. {
  143. $id = $request->param('id');
  144. $info = $this->model
  145. ->withJoin('userData', 'INNER')
  146. ->where('id', $id)
  147. ->find()
  148. ->toArray();
  149. // $upgrade_log = $upgradeLog->where('uid', $id)->order('create_at', 'desc')->select();
  150. // $this->assign('upgrade_log', $upgrade_log);
  151. $this->assign('info', $info);
  152. return $this->fetch();
  153. }
  154. /**
  155. * 添加用户
  156. * @return mixed
  157. */
  158. public function add ()
  159. {
  160. if ($this->request->isAjax()) {
  161. $post = $this->request->post();
  162. $mobile = $this->model->where('mobile', $post['mobile'])->value('id');
  163. $mobile && $this->error('该手机号码已被注册');
  164. $invite = $this->model->where('code|px_code', $post['code'])->value('id');
  165. !$invite && $this->error('邀请人不存在');
  166. $this->model->startTrans();
  167. try {
  168. $insert['mobile'] = $post['mobile'];
  169. $insert['reg_ip'] = $this->request->ip();
  170. $insert['avatar'] = 'http://images.yxj.hongyun63.com/user/default_avatar.jpg';
  171. $insert['code'] = create_invite_code();
  172. $insert['px_code'] = create_invite_code();
  173. $insert['user_type'] = 2;
  174. $rz_money = 1.5 + rand(0, 30) / 100;
  175. $this->model->save($insert);
  176. $uid = $this->model->id;
  177. $user_data = new UserData();
  178. $user_data->save(['uid' => $uid, 'rz_money' => $rz_money]); // 保存用户关联信息
  179. $this->bindRelation($post['code'], $uid); // 绑定关系
  180. $this->model->commit();
  181. } catch (\Exception $e) {
  182. $this->model->rollback();
  183. $this->error('添加用户失败');
  184. }
  185. $this->success('添加成功');
  186. }
  187. return $this->fetch();
  188. }
  189. /**
  190. * 邀请页面
  191. * @return mixed
  192. */
  193. public function invite ()
  194. {
  195. $admin = session('admin');
  196. !$admin['user_id'] && $this->error('没有该权限');
  197. $user = $this->model->findOrEmpty(['id' => $admin['user_id']]);
  198. empty($user) && $this->error('用户信息不存在');
  199. $this->assign('user_id', encode($admin['user_id']));
  200. return $this->fetch();
  201. }
  202. /**
  203. * 兜底
  204. * @return mixed
  205. */
  206. public function doudi ()
  207. {
  208. return 22;
  209. if ($this->request->isAjax()) {
  210. $post = $this->request->post();
  211. $user = $this->model->findOrEmpty(['id' => $post['uid']]);
  212. empty($user) && $this->error('用户不存在');
  213. $post['active'] <= 0 && $this->error('参数错误');
  214. $path = trim_string($user['path'] . ',' . $user['id']);
  215. $path_explode = explode(',', $path);
  216. $insert = [];
  217. foreach ($path_explode as $value) {
  218. $insert[] = [
  219. 'active' => $post['active'],
  220. 'uid' => $value,
  221. 'ip' => $this->request->ip(),
  222. 'user_admin' => session('?admin.username') ? session('admin.username') : '',
  223. 'from_uid' => $post['uid'],
  224. 'failure_at' => date('Y-m-d H:i:s', time() + 86400 * 30),
  225. ];
  226. }
  227. $this->model->startTrans();
  228. try {
  229. $this->model->whereIn('id', $path)->save(['active_set' => ['inc', $post['active']], 'total_number' => ['inc', $post['active']], 'total_number_real' => ['inc', $post['active']], 'total_active' => ['inc', $post['active']]]);
  230. ActiveSet::insertAll($insert);
  231. $this->model->commit();
  232. } catch (\Exception $e) {
  233. $this->model->rollback();
  234. $this->error('失败');
  235. }
  236. $this->success('成功');
  237. }
  238. return $this->fetch();
  239. }
  240. /**
  241. * 增加余额
  242. * @return mixed
  243. */
  244. public function editmoney ()
  245. {
  246. if ($this->request->isPost()) {
  247. $post = $this->request->post();
  248. $user = $this->model->findOrEmpty(['id' => $post['uid']]);
  249. $money = $post['money'];
  250. $type = $post['type'];
  251. empty($user) && $this->error('用户不存在');
  252. $this->model->startTrans();
  253. try {
  254. if ($type == 'more'){
  255. edit_user_money(7, $post['uid'], $money);
  256. }else {
  257. edit_user_money(8, $post['uid'], $money);
  258. }
  259. $this->model->commit();
  260. } catch (\Exception $e) {
  261. $this->model->rollback();
  262. $this->error('失败'.$e->getMessage());
  263. }
  264. $this->success('成功');
  265. }
  266. return $this->fetch();
  267. }
  268. /**
  269. * 末尾奖励
  270. * @return mixed
  271. */
  272. public function moweiscore ()
  273. {
  274. if ($this->request->isPost()) {
  275. $post = $this->request->post();
  276. $user = $this->model->findOrEmpty(['id' => $post['uid']]);
  277. $money = $post['money'];
  278. empty($user) && $this->error('用户不存在');
  279. $this->model->startTrans();
  280. try {
  281. edit_user_score(8, $post['uid'], $money);
  282. $this->model->commit();
  283. } catch (\Exception $e) {
  284. $this->model->rollback();
  285. $this->error('失败'.$e->getMessage());
  286. }
  287. $this->success('成功');
  288. }
  289. return $this->fetch();
  290. }
  291. /**
  292. * 余额明细
  293. * @param MoneyLog $model
  294. * @return mixed|\think\response\Json
  295. * @throws \think\db\exception\DataNotFoundException
  296. * @throws \think\db\exception\DbException
  297. * @throws \think\db\exception\ModelNotFoundException
  298. */
  299. public function moneyLog (UserMoneyModel $model)
  300. {
  301. if ($this->request->isAjax()) {
  302. if (input('selectFields')) {
  303. return $this->selectList();
  304. }
  305. list($page, $limit, $where) = $this->buildTableParames();
  306. $where[] = ['uid', '=', $this->request->param('id', '')];
  307. $count = $model
  308. ->where($where)
  309. ->count();
  310. $type_conf = config('type.money');
  311. $list = $model
  312. ->where($where)
  313. ->withAttr('type', function ($value, $data) use ($type_conf) {
  314. return $type_conf[$value];
  315. })
  316. ->withAttr('money', function ($value, $data) {
  317. if ($data['state'] == 2)
  318. $value = '-' . $value;
  319. return $value;
  320. })
  321. ->page($page, $limit)
  322. ->order($this->sort)
  323. ->select();
  324. $data = [
  325. 'code' => 0,
  326. 'msg' => '',
  327. 'count' => $count,
  328. 'data' => $list,
  329. ];
  330. return json($data);
  331. }
  332. return $this->fetch();
  333. }
  334. /**
  335. * 查看上级
  336. * @param Request $request
  337. * @param UpgradeLog $upgradeLog
  338. * @return mixed
  339. * @throws \think\db\exception\DataNotFoundException
  340. * @throws \think\db\exception\DbException
  341. * @throws \think\db\exception\ModelNotFoundException
  342. */
  343. public function lookpidlevel (Request $request)
  344. {
  345. if ($this->request->isAjax()) {
  346. // if (($pid = $this->request->param('pid')) !== false && $pid)
  347. // $where[] = ['pid', '=', $this->request->param('pid', '')];
  348. $id = $this->request->param('id');
  349. $path = Db::name('user')->where('id', $id)->value('path');
  350. $arr = explode(',', $path);
  351. $ids = $arr;
  352. $ids = implode(',',$ids);
  353. $order= 'field(id,'.$ids.')';
  354. // return User::whereIn('id',$ids)->order(Db::raw($order))->select();
  355. $where = array();
  356. $where[] = ['uid', 'in', $arr];
  357. sr_log($where);
  358. $count = $this->model
  359. ->withJoin('userData', 'INNER')
  360. ->where($where)
  361. ->count();
  362. $list = $this->model
  363. ->withJoin('userData', 'INNER')
  364. ->where($where)
  365. ->order(Db::raw($order))
  366. ->select();
  367. $data = [
  368. 'code' => 0,
  369. 'msg' => '成功',
  370. 'count' => $count,
  371. 'data' => $list,
  372. ];
  373. return json($data);
  374. }
  375. return $this->fetch();
  376. }
  377. /**
  378. * 元宝明细
  379. * @param CoinLog $model
  380. * @return mixed|\think\response\Json
  381. * @throws \think\db\exception\DataNotFoundException
  382. * @throws \think\db\exception\DbException
  383. * @throws \think\db\exception\ModelNotFoundException
  384. */
  385. public function coinLog (CoinLog $model)
  386. {
  387. if ($this->request->isAjax()) {
  388. if (input('selectFields')) {
  389. return $this->selectList();
  390. }
  391. list($page, $limit, $where) = $this->buildTableParames();
  392. $where[] = ['uid', '=', $this->request->param('id', '')];
  393. $count = $model
  394. ->where($where)
  395. ->count();
  396. $type_conf = config('type.coin');
  397. $list = $model
  398. ->where($where)
  399. ->withAttr('type', function ($value, $data) use ($type_conf) {
  400. return $type_conf[$value];
  401. })
  402. ->withAttr('coin', function ($value, $data) {
  403. if ($data['state'] == 2)
  404. $value = '-' . $value;
  405. return $value;
  406. })
  407. ->page($page, $limit)
  408. ->order($this->sort)
  409. ->select();
  410. $data = [
  411. 'code' => 0,
  412. 'msg' => '',
  413. 'count' => $count,
  414. 'data' => $list,
  415. ];
  416. return json($data);
  417. }
  418. return $this->fetch();
  419. }
  420. /**
  421. * 积分明细
  422. * @param ScoreLog $model
  423. * @return mixed|\think\response\Json
  424. * @throws \think\db\exception\DataNotFoundException
  425. * @throws \think\db\exception\DbException
  426. * @throws \think\db\exception\ModelNotFoundException
  427. */
  428. public function scoreLog (ScoreLogModel $model)
  429. {
  430. if ($this->request->isAjax()) {
  431. if (input('selectFields')) {
  432. return $this->selectList();
  433. }
  434. list($page, $limit, $where) = $this->buildTableParames();
  435. $where[] = ['uid', '=', $this->request->param('id', '')];
  436. $count = $model
  437. ->where($where)
  438. ->count();
  439. $type_conf = config('type.score');
  440. $list = $model
  441. ->where($where)
  442. ->withAttr('type', function ($value, $data) use ($type_conf) {
  443. return $type_conf[$value];
  444. })
  445. ->withAttr('score', function ($value, $data) {
  446. if ($data['state'] == 2)
  447. $value = '-' . $value;
  448. return $value;
  449. })
  450. ->page($page, $limit)
  451. ->order($this->sort)
  452. ->select();
  453. $data = [
  454. 'code' => 0,
  455. 'msg' => '',
  456. 'count' => $count,
  457. 'data' => $list,
  458. ];
  459. return json($data);
  460. }
  461. return $this->fetch();
  462. }
  463. /**
  464. * 积分明细
  465. * @param ActiveLog $model
  466. * @return mixed|\think\response\Json
  467. * @throws \think\db\exception\DataNotFoundException
  468. * @throws \think\db\exception\DbException
  469. * @throws \think\db\exception\ModelNotFoundException
  470. */
  471. public function activeLog (ActiveLog $model)
  472. {
  473. if ($this->request->isAjax()) {
  474. if (input('selectFields')) {
  475. return $this->selectList();
  476. }
  477. list($page, $limit, $where) = $this->buildTableParames();
  478. $where[] = ['uid', '=', $this->request->param('id', '')];
  479. $count = $model
  480. ->where($where)
  481. ->count();
  482. $type_conf = config('type.active');
  483. $list = $model
  484. ->where($where)
  485. ->withAttr('type', function ($value, $data) use ($type_conf) {
  486. return $type_conf[$value];
  487. })
  488. ->withAttr('active', function ($value, $data) {
  489. if ($data['state'] == 2)
  490. $value = '-' . $value;
  491. return $value;
  492. })
  493. ->page($page, $limit)
  494. ->order($this->sort)
  495. ->select();
  496. $data = [
  497. 'code' => 0,
  498. 'msg' => '',
  499. 'count' => $count,
  500. 'data' => $list,
  501. ];
  502. return json($data);
  503. }
  504. return $this->fetch();
  505. }
  506. /**
  507. * @NodeAnotation(title="导出")
  508. */
  509. public function export ()
  510. {
  511. list($page, $limit, $where) = $this->buildTableParames();
  512. $tableName = $this->model->getName();
  513. $tableName = CommonTool::humpToLine(lcfirst($tableName));
  514. $prefix = config('database.connections.mysql.prefix');
  515. $dbList = Db::query("show full columns from {$prefix}{$tableName}");
  516. $header = [];
  517. foreach ($dbList as $vo) {
  518. $comment = !empty($vo['Comment']) ? $vo['Comment'] : $vo['Field'];
  519. if (!in_array($vo['Field'], $this->noExportFields)) {
  520. $header[] = [$comment, $vo['Field']];
  521. }
  522. }
  523. $list = $this->model
  524. ->where($where)
  525. ->withJoin('userData', 'INNER')
  526. ->where($where)
  527. ->limit(100000)
  528. ->order('id', 'desc')
  529. ->select()
  530. ->toArray();
  531. $fileName = time();
  532. return Excel::exportData($list, $header, $fileName, 'xlsx');
  533. }
  534. public function teamincome (Request $request)
  535. {
  536. if ($this->request->isAjax()) {
  537. // if (($pid = $this->request->param('pid')) !== false && $pid)
  538. // $where[] = ['pid', '=', $this->request->param('pid', '')];
  539. $id = $this->request->param('id');
  540. // $path = Db::name('user')->where('id', $id)->value('path');
  541. $where = array();
  542. $where[] = ['uid', '=', $id];
  543. $where[] = ['type', '=', 3];
  544. $count = Db::name('userteam_log')
  545. // ->withJoin('user', 'INNER')
  546. ->where($where)
  547. ->count();
  548. $list = Db::name('userteam_log')
  549. // ->withJoin('user', 'INNER')
  550. ->where($where)
  551. ->order($this->sort)
  552. ->select();
  553. $data = [
  554. 'code' => 0,
  555. 'msg' => '成功',
  556. 'count' => $count,
  557. 'data' => $list,
  558. ];
  559. return json($data);
  560. }
  561. return $this->fetch();
  562. }
  563. }