TradeService.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2017~2021 LARAVEL研发中心
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://www.laravel.cn
  8. // +----------------------------------------------------------------------
  9. // | Author: laravel开发员 <laravel.qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace App\Services\Common;
  12. use App\Models\AcceptorModel;
  13. use App\Models\TradeModel;
  14. use App\Services\BaseService;
  15. use Illuminate\Support\Facades\DB;
  16. /**
  17. * 承兑商管理-服务类
  18. * @author laravel开发员
  19. * @since 2020/11/11
  20. * @package App\Services\Common
  21. */
  22. class TradeService extends BaseService
  23. {
  24. /**
  25. * 构造函数
  26. * @author laravel开发员
  27. * @since 2020/11/11
  28. */
  29. public function __construct()
  30. {
  31. $this->model = new TradeModel();
  32. }
  33. /**
  34. * 获取列表
  35. * @param $params 参数
  36. * @param int $pageSize 分页大小:默认 15
  37. * @return array
  38. */
  39. public function getDataList($params, $pageSize = 10, $field = [])
  40. {
  41. $where = ['a.mark' => 1];
  42. if (isset($params['status']) && $params['status'] != '') {
  43. $where['a.status'] = $params['status'];
  44. }
  45. if (isset($params['type']) && $params['type'] != '') {
  46. $where['a.type'] = $params['type'];
  47. }
  48. if (isset($params['pay_type']) && $params['pay_type'] != '') {
  49. $where['a.pay_type'] = $params['pay_type'];
  50. }
  51. if (isset($params['pay_status']) && $params['pay_status'] != '') {
  52. $where['a.pay_status'] = $params['pay_status'];
  53. }
  54. if (isset($params['exception_status']) && $params['exception_status'] != '') {
  55. $where['a.exception_status'] = $params['exception_status'];
  56. }
  57. if (isset($params['cancel_type']) && $params['cancel_type'] != '') {
  58. $where['a.cancel_type'] = $params['cancel_type'];
  59. }
  60. $list = $this->model->with(['member', 'acceptor'])
  61. ->from('trade as a')
  62. ->leftJoin('member as b', 'b.id', 'a.user_id')
  63. ->leftJoin('acceptor as c', 'c.id', 'a.acceptor_id')
  64. ->where($where)
  65. ->where(function ($query) use ($params) {
  66. $word = isset($params['user']) ? trim($params['user']) : '';
  67. if ($query) {
  68. $query->where('b.username', 'like', "%{$word}%")->orWhere('b.realname', 'like', "%{$word}%")->orWhere('b.nickname', 'like', "%{$word}%");
  69. }
  70. })
  71. ->where(function ($query) use ($params) {
  72. $word = isset($params['acceptor']) ? trim($params['acceptor']) : '';
  73. if ($query) {
  74. $query->where('c.name', 'like', "%{$word}%")->orWhere('a.real_name', 'like', "%{$word}%");
  75. }
  76. })
  77. ->select($field ? $field : ['a.*', 'b.username'])
  78. ->paginate($pageSize > 0 ? $pageSize : 9999999);
  79. $list = $list ? $list->toArray() : [];
  80. if ($list) {
  81. foreach ($list['data'] as &$item) {
  82. if (!empty($item['pay_img'])) {
  83. $info['pay_img'] = isValidUrl($item['pay_img']) ? $item['pay_img'] : get_image_url($item['pay_img']);
  84. }
  85. }
  86. }
  87. return [
  88. 'pageSize' => $pageSize,
  89. 'total' => isset($list['total']) ? $list['total'] : 0,
  90. 'list' => isset($list['data']) ? $list['data'] : []
  91. ];
  92. }
  93. /**
  94. * 添加会编辑会员
  95. * @return array
  96. * @since 2020/11/11
  97. * @author laravel开发员
  98. */
  99. public function edit()
  100. {
  101. // 请求参数
  102. $data = request()->all();
  103. return parent::edit($data); // TODO: Change the autogenerated stub
  104. }
  105. }