CustomAmount.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php namespace App\Http\Controllers\Api;
  2. use App\Models\CustomAmountRecord as CustomAmountRecord;
  3. use App\Models\CustomAmount as Model;
  4. /**
  5. * 用户余额接口
  6. *
  7. * @author jun
  8. *
  9. * */
  10. class CustomAmount extends Api{
  11. /**
  12. * 获取余额记录 /api/custom_amount/get_record_list
  13. *
  14. * @param string $code 授权码
  15. *
  16. * */
  17. public function get_record_list(Model $Model,CustomAmountRecord $CustomAmountRecord){
  18. // 接口验签
  19. // $this->verify_sign();
  20. // 检查登录
  21. $uid = $this->checkLogin();
  22. // 接收参数
  23. $limit = request('limit',15);
  24. // 查询条件
  25. $map = [['custom_uid','=',$uid]];
  26. // 查询数据
  27. $Paginator = $CustomAmountRecord->query()->where($map)->orderByDesc('id')
  28. ->paginate($limit,['id','buy_type','pay_type','prefix','description','insert_time','pay_time','status','transfer_bill_no','balance','amount']);
  29. // 重置数据
  30. $list = [];
  31. // 获取数据
  32. $list['total'] = $Paginator->total();
  33. $list['current_page'] = $Paginator->currentPage();
  34. $list['per_page'] = $Paginator->perPage();
  35. $list['last_page'] = $Paginator->lastPage();
  36. $list['data'] = $Paginator->items();
  37. // 循环数据
  38. foreach ($list['data'] as $key => $value) {
  39. // 处理时间
  40. $value['pay_time'] = $value['pay_time'] ? date('Y-m-d H:i:s',$value['pay_time']) : '';
  41. $value['insert_time'] = date('Y-m-d H:i:s',$value['insert_time']);
  42. // 获取子列表
  43. $value['type_state'] = (string) $CustomAmountRecord->getPayType($value['buy_type'],$value['pay_type'],'name');
  44. if ($value['buy_type'] == 2){
  45. $value['state'] = $CustomAmountRecord->getState($value['status'],'state');
  46. }
  47. // 重组
  48. $list['data'][$key] = $value;
  49. }
  50. // 返回结果
  51. return json_send(['code'=>'success','msg'=>'获取成功','data'=>$list]);
  52. }
  53. /**
  54. * 获取余额详情 /api/custom_amount/get_record_info
  55. *
  56. * @param string record_id 记录ID
  57. *
  58. * */
  59. public function get_record_info(Model $Model,CustomAmountRecord $CustomAmountRecord){
  60. // 检查登录
  61. $uid = $this->checkLogin();
  62. // 接收参数
  63. $recordId = request('record_id',0);
  64. $info = $CustomAmountRecord::query()->where(['custom_uid'=>$uid,'id'=>$recordId])->first(['id','buy_type','pay_type','prefix','description','insert_time','pay_time','status','transfer_bill_no','balance','amount']);
  65. if($info){
  66. $info['id_code'] = $CustomAmountRecord->idToCode($info['id']);
  67. }
  68. return json_send(['code'=>'success','msg'=>'获取成功','data'=>$info]);
  69. }
  70. }