SettleLogic.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <?php
  2. /**
  3. * SettleLogic.php UTF-8
  4. * 提现
  5. *
  6. * @date : 2018/5/18 16:27
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace huo\logic\finance;
  13. use huo\model\common\CommonModel;
  14. use huo\model\finance\SettleModel;
  15. use huo\model\user\UserModel;
  16. use huolib\constant\CommonConst;
  17. class SettleLogic extends CommonModel {
  18. /**
  19. * 获取提现列表
  20. *
  21. * @param $agent_id
  22. * @param $param
  23. * @param string $page
  24. * @param string $order
  25. *
  26. * @return array
  27. */
  28. public function getSettleList($agent_id, $param, $page = '1,10', $order = '-create_time') {
  29. $_map = $this->getWhere($param, $agent_id);
  30. $field = $this->getField($agent_id);
  31. return $this->getList($field, $_map, $page, $order);
  32. }
  33. /**
  34. * @param array $param
  35. * @param int $agent_id
  36. *
  37. * @return array
  38. */
  39. protected function getWhere($param = [], $agent_id = 0) {
  40. $_map = [];
  41. if (!empty($param['start_time']) && !empty($param['end_time'])) {
  42. $_map['create_time']
  43. = [
  44. 'between',
  45. [
  46. strtotime($param['start_time']),
  47. CommonConst::CONST_DAY_SECONDS + strtotime($param['end_time'])
  48. ]
  49. ];
  50. } elseif (!empty($param['start_time'])) {
  51. $_map['create_time'] = ['egt', strtotime($param['start_time'])];
  52. } elseif (!empty($param['end_time'])) {
  53. $_map['create_time'] = ['elt', CommonConst::CONST_DAY_SECONDS + strtotime($param['end_time'])];
  54. }
  55. if (!empty($agent_id)) {
  56. $_map['agent_id'] = $agent_id;
  57. }
  58. if (!empty($param['agent_id']) && empty($_map['agent_id'])) {
  59. $_map['agent_id'] = $param['agent_id'];
  60. }
  61. if (!empty($param['agent_name']) && empty($_map['agent_id'])) {
  62. $_map['agent_id'] = (new UserModel())->getIdByName($param['agent_name']);
  63. }
  64. if (!empty($param['agent_nickname']) && empty($_map['agent_id'])) {
  65. $_ids = (new UserModel())->getIdsByNickName($param['agent_nickname']);
  66. $_map['agent_id'] = ['in', $_ids];
  67. }
  68. if (!empty($param['mem_id']) && empty($_map['agent_id'])) {
  69. $_map['agent_id'] = (new UserModel())->getIdByMemId($param['mem_id']);
  70. }
  71. if (!empty($param['status'])) {
  72. $_map['status'] = $param['status'];
  73. }
  74. if (!empty($param['type'])) {
  75. $_map['type'] = $param['type'];
  76. }
  77. if (!empty($param['cardholder'])) {
  78. $_map['cardholder'] = $param['cardholder'];
  79. }
  80. if (!empty($param['tag'])) {
  81. $_map['tag'] = $param['tag'];
  82. }
  83. return $_map;
  84. }
  85. public function getField($agent_id) {
  86. return [];
  87. }
  88. /**
  89. * 获取提现列表
  90. *
  91. * @param array $field
  92. * @param array $where
  93. * @param string $page
  94. * @param string $order
  95. *
  96. * @return array
  97. * @throws \think\db\exception\DataNotFoundException
  98. * @throws \think\db\exception\ModelNotFoundException
  99. * @throws \think\exception\DbException
  100. */
  101. public function getList($field, $where, $page = '1,10', $order = '-create_time') {
  102. $_map = $where;
  103. $_settle_model = new SettleModel();
  104. $_count = $_settle_model->where($_map)->count();
  105. if (empty($_count)) {
  106. return [
  107. 'count' => 0,
  108. 'sum' => ['sum_amount' => 0, 'amount' => 0],
  109. 'list' => []
  110. ];
  111. }
  112. $_sum_data = $_settle_model
  113. ->where($where)
  114. ->sum('amount');
  115. $_field = [
  116. 'id' => 'id',
  117. 'agent_id' => 'agent_id',
  118. 'amount' => 'amount',
  119. 'type' => 'type',
  120. 'bankname' => 'bankname',
  121. 'branchname' => 'branchname',
  122. 'cardholder' => 'cardholder',
  123. 'banknum' => 'banknum',
  124. 'status' => 'status',
  125. 'is_return' => 'is_return',
  126. 'failreason' => 'failreason',
  127. 'create_time' => 'create_time',
  128. 'check_time' => 'check_time',
  129. 'settle_time' => 'settle_time',
  130. ];
  131. $_field = array_merge($_field, $field);
  132. $_order = $_settle_model->orderFilter($order);
  133. $_settle_datas = $_settle_model
  134. ->with('agent,remain,memtag')
  135. ->field($_field)
  136. ->where($where)
  137. ->order($_order)
  138. ->page($page)
  139. ->select();
  140. if (is_object($_settle_datas)) {
  141. $_settle_datas = $_settle_datas->toArray();
  142. }
  143. if (empty($_settle_datas)) {
  144. return [
  145. 'count' => $_count,
  146. 'sum' => ['sum_amount' => round($_sum_data, 2), 'amount' => round($_sum_data, 2)],
  147. 'list' => []
  148. ];
  149. }
  150. $_data = [];
  151. foreach ($_settle_datas as $_settle_data) {
  152. foreach ($_field as $_v) {
  153. $_list[$_v] = $_settle_data[$_v];
  154. }
  155. $_list['agent_name'] = $_settle_data['agent']['user_login'];
  156. $_list['agent_nickname'] = $_settle_data['agent']['user_nicename'];
  157. $_list['share_total'] = $_settle_data['remain']['share_total'];
  158. $_list['frozen_amount'] = $_settle_data['remain']['frozen_amount'];
  159. $_list['share_remain'] = $_settle_data['remain']['share_remain'];
  160. $_list['memtag'] = empty($_settle_data['memtag']['type']) ? 0 : $_settle_data['memtag']['type'];
  161. $_data[] = $_list;
  162. }
  163. return [
  164. 'count' => $_count,
  165. 'sum' => ['sum_amount' => round($_sum_data, 2), 'amount' => round($_sum_data, 2)],
  166. 'list' => $_data
  167. ];
  168. }
  169. /**
  170. * 提现详情
  171. *
  172. * @param int $id
  173. *
  174. * @return false|array
  175. * @throws \think\Exception
  176. * @throws \think\db\exception\DataNotFoundException
  177. * @throws \think\db\exception\ModelNotFoundException
  178. * @throws \think\exception\DbException
  179. */
  180. public function getDetail($id) {
  181. if (empty($id)) {
  182. return false;
  183. }
  184. $_map['id'] = $id;
  185. $_field = [
  186. 'id' => 'id',
  187. 'agent_id' => 'agent_id',
  188. 'amount' => 'amount',
  189. 'type' => 'type',
  190. 'bankname' => 'bankname',
  191. 'branchname' => 'branchname',
  192. 'cardholder' => 'cardholder',
  193. 'banknum' => 'banknum',
  194. 'status' => 'status',
  195. 'is_return' => 'is_return',
  196. 'failreason' => 'failreason',
  197. 'create_time' => 'create_time',
  198. 'check_time' => 'check_time',
  199. 'settle_time' => 'settle_time',
  200. ];
  201. $_data = (new SettleModel())
  202. ->with('agent')
  203. ->with('remain')
  204. ->field($_field)
  205. ->where($_map)
  206. ->find();
  207. if (is_object($_data)) {
  208. $_data = $_data->toArray();
  209. }
  210. if (empty($_data)) {
  211. return false;
  212. }
  213. foreach ($_field as $_v) {
  214. $_list[$_v] = $_data[$_v];
  215. }
  216. $_list['agent_name'] = $_data['agent']['user_login'];
  217. $_list['agent_nickname'] = $_data['agent']['user_nicename'];
  218. $_list['share_total'] = $_data['remain']['share_total'];
  219. $_list['frozen_amount'] = $_data['remain']['frozen_amount'];
  220. $_list['share_remain'] = $_data['remain']['share_remain'];
  221. return $_list;
  222. }
  223. }