ManageMoneyController.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace app\api\controller\manege;
  3. use app\models\manage\ManageMoneyProduct;
  4. use app\models\manage\UserManageMoney;
  5. use app\models\trade\CashTradeOrder;
  6. use app\Request;
  7. use crmeb\services\CacheService;
  8. use crmeb\services\UtilService;
  9. use think\db\exception\DataNotFoundException;
  10. use think\db\exception\DbException;
  11. use think\db\exception\ModelNotFoundException;
  12. use think\Exception;
  13. class ManageMoneyController
  14. {
  15. /**
  16. * 算力产品
  17. * @param Request $request
  18. * @return mixed
  19. */
  20. public function lst(Request $request)
  21. {
  22. $page = $request->get('page', 1);
  23. $limit = $request->get('limit', 10);
  24. return app('json')->success('ok', ManageMoneyProduct::getList((int)$page, (int)$limit));
  25. }
  26. /**
  27. * @param $id
  28. * @param Request $request
  29. * @return mixed
  30. * @throws DataNotFoundException
  31. * @throws DbException
  32. * @throws ModelNotFoundException
  33. */
  34. public function detail($id, Request $request)
  35. {
  36. return app('json')->success('ok', ManageMoneyProduct::valid()->where('id', $id)->find()->toArray());
  37. }
  38. public function buy($id, Request $request)
  39. {
  40. $user = $request->user();
  41. list($num,) = UtilService::postMore(
  42. [
  43. ['num', 0,],
  44. ['trade_psw', '', '', '', ['not_empty_check', function ($item) use ($user) {
  45. // var_dump($user);
  46. return md5(md5($item)) == $user['trade_pwd'];
  47. }], ['请输入交易密码', '交易密码错误']],
  48. ], $request, true);
  49. $res = ManageMoneyProduct::buyPoroduct($id, $request->uid(), $num);
  50. if ($res) {
  51. return app('json')->success('购买成功');
  52. } else {
  53. return app('json')->fail(ManageMoneyProduct::getErrorInfo());
  54. }
  55. }
  56. /**
  57. * 我的理财
  58. * @param Request $request
  59. * @return mixed
  60. */
  61. public function myList(Request $request)
  62. {
  63. $page = $request->get('page', 1);
  64. $limit = $request->get('limit', 10);
  65. $where['status'] = $request->get('status', '');
  66. return app('json')->success('ok', UserManageMoney::getList((int)$page, (int)$limit, $where));
  67. }
  68. public function finish($id, Request $request)
  69. {
  70. $info = UserManageMoney::valid()->where('uid', $request->uid())->where('id', $id)->find();
  71. if (!$info) {
  72. return app('json')->fail('数据参数异常');
  73. }
  74. if ($info['time'] != 0) {
  75. return app('json')->fail('定期理财不能自主停止');
  76. }
  77. UserManageMoney::beginTrans();
  78. try {
  79. $res = UserManageMoney::endManege($id);
  80. if ($res) {
  81. UserManageMoney::commitTrans();
  82. return app('json')->success('已回收理财基金');
  83. } else {
  84. UserManageMoney::rollbackTrans();
  85. return app('json')->fail(UserManageMoney::getErrorInfo());
  86. }
  87. } catch (Exception $e) {
  88. UserManageMoney::rollbackTrans();
  89. return app('json')->fail($e->getMessage());
  90. }
  91. }
  92. }