| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265 |
- <?php
- // +----------------------------------------------------------------------
- // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
- // +----------------------------------------------------------------------
- // | 版权所有 2017~2021 LARAVEL研发中心
- // +----------------------------------------------------------------------
- // | 官方网站: http://www.laravel.cn
- // +----------------------------------------------------------------------
- // | Author: laravel开发员 <laravel.qq.com>
- // +----------------------------------------------------------------------
- namespace App\Services\Common;
- use App\Models\AccountLogModel;
- use App\Models\ActionLogModel;
- use App\Models\MemberModel;
- use App\Services\BaseService;
- use App\Services\RedisService;
- use Illuminate\Support\Facades\DB;
- /**
- * 承兑商管理-服务类
- * @author laravel开发员
- * @since 2020/11/11
- * @package App\Services\Common
- */
- class AccountLogService extends BaseService
- {
- /**
- * 构造函数
- * @author laravel开发员
- * @since 2020/11/11
- */
- public function __construct()
- {
- $this->model = new AccountLogModel();
- }
- /**
- * 获取列表
- * @param $params 参数
- * @param int $pageSize 分页大小:默认 15
- * @return array
- */
- public function getDataList($params, $pageSize = 10, $field = [])
- {
- $query = $this->getQuery($params);
- $list = $query->select($field ? $field : ['a.*', 'b.nickname','b.wallet_url'])
- ->orderBy('a.create_time','desc')
- ->paginate($pageSize > 0 ? $pageSize : 9999999);
- $list = $list ? $list->toArray() : [];
- if ($list) {
- foreach ($list['data'] as &$item) {
- $item['create_time'] = datetime($item['create_time'],'Y-m-d H:i:s');
- if($item['user_type'] == 1){
- $item['uid'] = $item['user_id'];
- $item['account'] = isset($item['nickname'])&& $item['nickname']?$item['nickname']: $item['user_id'];
- }
- }
- }
- return [
- 'pageSize' => $pageSize,
- 'total' => isset($list['total']) ? $list['total'] : 0,
- 'list' => isset($list['data']) ? $list['data'] : []
- ];
- }
- /**
- * 查询构造
- * @param $params
- * @return \Illuminate\Database\Eloquent\Builder
- */
- public function getQuery($params)
- {
- $where = ['a.mark' => 1];
- return $this->model->with(['member'])
- ->from('account_log as a')
- ->leftJoin('member as b', function($join) {
- $join->on('b.id','=', 'a.user_id')->where('a.user_type',1);
- })
- ->where($where)
- ->where(function ($query) use ($params) {
- $kw = isset($params['keyword']) ? trim($params['keyword']) : '';
- if ($kw) {
- $query->where('b.nickname', 'like', "%{$params['keyword']}%")
- ->orWhere('b.wallet_url', '=', trim($params['keyword']))
- ->orWhere('b.id', '=', $params['keyword']);
- }
- })
- ->where(function ($query) use($params){
- // 日期
- $date = isset($params['date']) ? $params['date'] : [];
- $start = isset($date[0])? $date[0] : '';
- $end = isset($date[1])? $date[1] : '';
- $end = $start>=$end? '' : $end;
- if ($start) {
- $query->where('a.create_time','>=', strtotime($start));
- }
- if($end){
- $query->where('a.create_time','<=', strtotime($end));
- }
- $orderNo = isset($params['order_no'])? trim($params['order_no']) : '';
- if($orderNo){
- $query->where('a.order_no', 'like', "%{$orderNo}%");
- }
- $hash = isset($params['hash'])? trim($params['hash']) : '';
- if($hash){
- $query->where('a.hash', '=', trim($hash));
- }
- $walletUrl = isset($params['wallet_url']) ? trim($params['wallet_url']) : '';
- if ($walletUrl) {
- $query->where('b.wallet_url', $walletUrl);
- }
- $userId = isset($params['user_id'])? $params['user_id'] : 0;
- if ($userId) {
- $query->where('a.user_id', $userId);
- }
- $userType = isset($params['user_type'])? $params['user_type'] : 0;
- if ($userType) {
- $query->where('a.user_type', $userType);
- }
- $type = isset($params['type'])? $params['type'] : 0;
- if (is_array($type)) {
- $query->whereIn('a.type', $type);
- } else if($type){
- $query->where('a.type', $type);
- }
- $coinType = isset($params['coin_type'])? $params['coin_type'] : 0;
- if (is_array($coinType)) {
- $query->whereIn('a.coin_type', $coinType);
- } else if($coinType){
- $query->where('a.coin_type', $coinType);
- }
- $status = isset($params['status'])? $params['status'] : 0;
- if (is_array($status)) {
- $query->whereIn('a.status', $status);
- } else if($status){
- $query->where('a.status', $status);
- }
- });
- }
- /**
- * 统计
- * @param $params
- * @return array
- */
- public function count($params)
- {
- $query = $this->getQuery($params);
- $count = $query->count('a.id');
- $query1 = clone $query;
- $query2 = clone $query;
- $total1 = $query1->where('a.money','>',0)->sum('a.money');
- $total2 = $query2->where('a.money','<=',0)->sum('a.money');
- return [
- 'count' => $count,
- 'total1' => round(abs($total1),2), // 进
- 'total2' => round(abs($total2),2), // 出
- 'total' => round(abs($total1)+abs($total2),2)
- ];
- }
- /**
- * 平台充兑
- * @param $adminId
- * @param $params
- * @return bool
- */
- public function changeAccount($adminId,$params)
- {
- $userType = isset($params['user_type'])? intval($params['user_type']) : 1;
- $coinType = isset($params['coin_type'])? intval($params['coin_type']) : 1;
- $type = isset($params['type'])? intval($params['type']) : 1;
- $accountId = isset($params['user_id'])? intval($params['user_id']) : 0;
- $amount = isset($params['amount'])? floatval($params['amount']) : 0;
- if($amount<=0){
- $this->error = 4100;
- return false;
- }
- if(!in_array($type,[1,2])){
- $this->error = 4003;
- return false;
- }
- $userTypes = [1=>'会员'];
- $fields = [1=>'usdt',2=>'sbt',3=>'profit'];
- $coinNames = [1=>'USDT余额',2=>'SBT',3=>'收益/奖励'];
- $field = isset($fields[$coinType])? $fields[$coinType] : 'usdt';
- $coinName = isset($coinNames[$coinType])? $coinNames[$coinType] : 'USDT余额';
- $accountName = isset($userTypes[$userType])? $userTypes[$userType] : '会员';
- ActionLogModel::setTitle("{$accountName}[ID:{$accountId}]{$coinName}账户上下分");
- ActionLogModel::record();
- $userInfo = MemberModel::where(['id'=> $accountId,'mark'=>1])->first();
- $userId = isset($userInfo['id'])? $userInfo['id'] : 0;
- if(empty($userInfo) || $userId<=0){
- $this->error = 4004;
- return false;
- }
- if(!in_array($coinType,[1,2,3])){
- $this->error = 4003;
- return false;
- }
- // 账户余额
- $userAmount = isset($userInfo[$field])? $userInfo[$field] : 0;
- if($type == 2 && $userAmount < $amount){
- $this->error = lang(2035,['name'=>$coinName]);
- return false;
- }
- DB::beginTransaction();
- $amount = $type == 1? $amount : -$amount;
- $updateData = [$field=>DB::raw("{$field} + {$amount}"),'update_time'=>time()];
- if(!MemberModel::where(['id'=> $accountId])->update($updateData)){
- DB::rollBack();
- $this->error = 1003;
- return false;
- }
- // 账户明细
- $orderNo = get_order_num('PC');
- $log = [
- 'user_id' => $accountId,
- 'source_uid' => 0,
- 'order_no' => $orderNo,
- 'type' => $type==1?5:6,
- 'coin_type' => $coinType,
- 'user_type'=> 1,
- 'money' => $amount,
- 'before_money' => isset($userInfo[$field])? $userInfo[$field] : 0,
- 'create_time' => time(),
- 'admin_id' => $adminId,
- 'action_ip' => get_client_ip(),
- 'remark' => $type==1?"链上充值":"链上扣除",
- 'status' => 1,
- 'mark' => 1,
- ];
- if(!AccountLogModel::insertGetId($log)){
- DB::rollBack();
- $this->error = 2029;
- return false;
- }
- DB::commit();
- ActionLogModel::setTitle("{$coinName}账户上分/下分");
- ActionLogModel::record();
- $this->error = 1002;
- return true;
- }
- }
|