123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <?php
- namespace app\api\controller\manege;
- use app\models\manage\ManageMoneyProduct;
- use app\models\manage\UserManageMoney;
- use app\models\trade\CashTradeOrder;
- use app\Request;
- use crmeb\services\CacheService;
- use crmeb\services\UtilService;
- use think\db\exception\DataNotFoundException;
- use think\db\exception\DbException;
- use think\db\exception\ModelNotFoundException;
- use think\Exception;
- class ManageMoneyController
- {
- /**
- * 算力产品
- * @param Request $request
- * @return mixed
- */
- public function lst(Request $request)
- {
- $page = $request->get('page', 1);
- $limit = $request->get('limit', 10);
- return app('json')->success('ok', ManageMoneyProduct::getList((int)$page, (int)$limit));
- }
- /**
- * @param $id
- * @param Request $request
- * @return mixed
- * @throws DataNotFoundException
- * @throws DbException
- * @throws ModelNotFoundException
- */
- public function detail($id, Request $request)
- {
- return app('json')->success('ok', ManageMoneyProduct::valid()->where('id', $id)->find()->toArray());
- }
- public function buy($id, Request $request)
- {
- $user = $request->user();
- list($num,) = UtilService::postMore(
- [
- ['num', 0,],
- ['trade_psw', '', '', '', ['not_empty_check', function ($item) use ($user) {
- // var_dump($user);
- return md5(md5($item)) == $user['trade_pwd'];
- }], ['请输入交易密码', '交易密码错误']],
- ], $request, true);
- $res = ManageMoneyProduct::buyPoroduct($id, $request->uid(), $num);
- if ($res) {
- return app('json')->success('购买成功');
- } else {
- return app('json')->fail(ManageMoneyProduct::getErrorInfo());
- }
- }
- /**
- * 我的理财
- * @param Request $request
- * @return mixed
- */
- public function myList(Request $request)
- {
- $page = $request->get('page', 1);
- $limit = $request->get('limit', 10);
- $where['status'] = $request->get('status', '');
- return app('json')->success('ok', UserManageMoney::getList((int)$page, (int)$limit, $where));
- }
- public function finish($id, Request $request)
- {
- $info = UserManageMoney::valid()->where('uid', $request->uid())->where('id', $id)->find();
- if (!$info) {
- return app('json')->fail('数据参数异常');
- }
- if ($info['time'] != 0) {
- return app('json')->fail('定期理财不能自主停止');
- }
- UserManageMoney::beginTrans();
- try {
- $res = UserManageMoney::endManege($id);
- if ($res) {
- UserManageMoney::commitTrans();
- return app('json')->success('已回收理财基金');
- } else {
- UserManageMoney::rollbackTrans();
- return app('json')->fail(UserManageMoney::getErrorInfo());
- }
- } catch (Exception $e) {
- UserManageMoney::rollbackTrans();
- return app('json')->fail($e->getMessage());
- }
- }
- }
|