123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- <?php
- /**
- * Created by PhpStorm.
- * User: xurongyao <763569752@qq.com>
- * Date: 2018/6/14 下午5:25
- */
- namespace app\admin\controller\finance;
- use app\admin\controller\AuthController;
- use app\models\trade\CashTradeOrder;
- use app\models\user\UserMoney;
- use app\Request;
- use crmeb\basic\BaseModel;
- use crmeb\repositories\ShortLetterRepositories;
- use app\admin\model\user\{User, UserBill};
- use app\admin\model\finance\FinanceModel;
- use crmeb\services\{UtilService as Util, JsonService as Json, UtilService};
- /**
- * 微信充值记录
- * Class UserRecharge
- * @package app\admin\controller\user
- */
- class Finance extends AuthController
- {
- /**
- * 显示资金记录
- */
- public function bill()
- {
- $list = UserBill::where('type', 'not in', ['gain', 'deduction', 'sign'])
- ->where('category', 'not in', 'integral')
- ->field(['title', 'type'])
- ->group('type')
- ->distinct(true)
- ->select()
- ->toArray();
- $this->assign('selectList', $list);
- return $this->fetch();
- }
- /**
- * 显示资金记录ajax列表
- */
- public function billlist()
- {
- $where = Util::getMore([
- ['start_time', ''],
- ['end_time', ''],
- ['nickname', ''],
- ['limit', 20],
- ['page', 1],
- ['type', ''],
- ]);
- return Json::successlayui(FinanceModel::getBillList($where));
- }
- /**
- *保存资金监控的excel表格
- */
- public function save_bell_export()
- {
- $where = Util::getMore([
- ['start_time', ''],
- ['end_time', ''],
- ['nickname', ''],
- ['type', ''],
- ]);
- FinanceModel::SaveExport($where);
- }
- /**
- * 显示佣金记录
- */
- public function commission_list()
- {
- $this->assign('is_layui', true);
- return $this->fetch();
- }
- /**
- * 佣金记录异步获取
- */
- public function get_commission_list()
- {
- $get = Util::getMore([
- ['page', 1],
- ['limit', 20],
- ['nickname', ''],
- ['price_max', ''],
- ['price_min', ''],
- ['order', ''],
- ['excel', ''],
- ]);
- return Json::successlayui(User::getCommissionList($get));
- }
- /**
- * 显示操作记录
- */
- public function index3()
- {
- }
- /**
- * 佣金详情
- */
- public function content_info($uid = '')
- {
- if ($uid == '') return $this->failed('缺少参数');
- $this->assign('userinfo', User::getUserinfo($uid));
- $this->assign('uid', $uid);
- return $this->fetch();
- }
- /**
- * 佣金提现记录个人列表
- */
- public function get_extract_list($uid = '')
- {
- if ($uid == '') return Json::fail('缺少参数');
- $where = Util::getMore([
- ['page', 1],
- ['limit', 20],
- ['start_time', ''],
- ['end_time', ''],
- ['nickname', '']
- ]);
- return Json::successlayui(UserBill::getExtrctOneList($where, $uid));
- }
- public function cashTrade()
- {
- return $this->fetch();
- }
- public function cashTradeList()
- {
- $where = $where = UtilService::getMore([
- ['money_type', ''],
- ['trade_uid', ''],
- ['order_id', ''],
- ['page', 1],
- ['limit', 10],
- ['status', ''],
- ['trade_type', '']
- ], $this->request);
- $data = CashTradeOrder::getList($where);
- $data['data'] = $data['list'];
- unset($data['list']);
- Json::successlayui($data);
- }
- public function check($id, $ok, Request $request)
- {
- $order = CashTradeOrder::where('id', $id)->where('status', 'in', [3, -1])->find();
- if (!in_array($ok, ['y', 'n'])) return app('json')->fail('参数错误');
- $res = true;
- BaseModel::beginTrans();
- if ($ok == 'y') {
- switch ($order['trade_type']) {
- case 1:
- if ($order['trade_uid'] != 0)
- $res = $res && UserMoney::incomeMoney($order['trade_uid'], $order['money_type'], $order['money_num'], 'buy_success', '购币成功', '购币成功,出售方ID' . $order['uid']);
- break;
- case 2:
- $res = $res && UserMoney::incomeMoney($order['uid'], $order['money_type'], $order['money_num'], 'buy_success', '购币成功', '购币成功,出售方ID' . $order['trade_uid']);
- break;
- default:
- break;
- }
- $res = $res && CashTradeOrder::where('id', $id)->update(['status' => 1, 'trade_time' => time()])
- && CashTradeOrder::brokerage($id);
- BaseModel::checkTrans($res);
- if ($res) {
- if ($order['trade_uid'] === 0) {
- $user = \app\models\user\User::getUserInfo($order['uid']);
- ShortLetterRepositories::SMSSend($user['phone'], ['code' => 0], 'SUCCESS_TRADE');
- }
- Json::successful('审核成功');
- // return app('json')->success('审核成功');
- } else {
- return app('json')->fail('审核失败');
- }
- } else {
- switch ($order['trade_type']) {
- case 1:
- $res = $res && UserMoney::incomeMoney($order['uid'], $order['money_type'], $order['money_num'], 'buy_fail', '购币失败', '购币失败,出售方ID' . $order['uid']);
- break;
- case 2:
- $res = $res && UserMoney::incomeMoney($order['trade_uid'], $order['money_type'], $order['money_num'], 'buy_fail', '购币失败', '购币失败,出售方ID' . $order['trade_uid']);
- break;
- default:
- break;
- }
- $res = $res && CashTradeOrder::where('id', $id)->update(['status' => 2, 'end_time' => time()]);
- BaseModel::checkTrans($res);
- if ($res) {
- Json::successful('退回成功');
- } else {
- return app('json')->fail('退回失败');
- }
- }
- }
- public function cancel($id, Request $request)
- {
- $order = CashTradeOrder::get($id);
- if ($order['close_time'] && $order['close_time'] < time()) return app('json')->fail('订单已关闭');
- if ($order['status'] > 0) return app('json')->fail('订单不可撤销');
- BaseModel::beginTrans();
- $res = true;
- switch ($order['trade_type']) {
- case 1:
- //退回币
- $res = $res && UserMoney::incomeMoney($order['uid'], $order['money_type'], $order['money_num'], 'hang_sale_cancel', '挂卖取消', '挂卖取消,退回钱包');
- $res = $res && CashTradeOrder::where('id', $order['id'])->update(['status' => 2]);
- break;
- case 2:
- //
- if ($order['trade_uid'])
- $res = $res && UserMoney::incomeMoney($order['trade_uid'], $order['money_type'], $order['money_num'], 'hang_buy_cancel', '挂买取消', '挂买取消,退回钱包');
- $res = $res && CashTradeOrder::where('id', $order['id'])->update(['status' => 2]);
- break;
- default:
- break;
- }
- BaseModel::checkTrans($res);
- if ($res) {
- Json::successful('取消成功');
- // return app('json')->success('取消成功');
- } else {
- return app('json')->fail('取消失败');
- }
- }
- }
|