DividendCashLogic.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. <?php
  2. namespace app\admin\logic\finance;
  3. use app\common\basics\Logic;
  4. use app\common\model\DividendOrder;
  5. use app\common\model\WithdrawApply;
  6. use app\common\enum\WithdrawEnum;
  7. use app\common\server\ExportExcelServer;
  8. use app\common\model\AccountLog;
  9. use app\common\model\DividendCashLog;
  10. use app\common\model\DividendOrderLog;
  11. use think\facade\Db;
  12. use think\Exception;
  13. /**
  14. * Class
  15. * @package app\admin\logic\finance
  16. */
  17. class DividendCashLogic extends Logic
  18. {
  19. /**
  20. * @notes 分红池明细
  21. * @param $get
  22. * @return array
  23. * @throws \think\db\exception\DataNotFoundException
  24. * @throws \think\db\exception\DbException
  25. * @throws \think\db\exception\ModelNotFoundException
  26. * @author suny
  27. * @date 2021/7/14 10:01 上午
  28. */
  29. public static function cash($get, $is_export = false)
  30. {
  31. $where = [];
  32. if (isset($get['change_type']) && !empty($get['change_type'])) {
  33. $where[] = ['a.change_type', '=', $get['change_type']];
  34. }
  35. if (empty($get['start_time']) && empty($get['end_time'])) {
  36. $where[] = ['a.create_time', '>=', strtotime(date("Y-m-d", time()))];
  37. $where[] = ['a.create_time', '<=', strtotime(date("Y-m-d", time())) + 86399];
  38. }
  39. //明细时间
  40. if (isset($get['start_time']) && $get['start_time'] != '') {
  41. $where[] = ['a.create_time', '>=', strtotime($get['start_time'])];
  42. }
  43. if (isset($get['end_time']) && $get['end_time'] != '') {
  44. $where[] = ['a.create_time', '<=', strtotime($get['end_time'])];
  45. }
  46. // 导出
  47. if (true === $is_export) {
  48. return self::cashExport($where);
  49. }
  50. $lists = DividendCashLog::alias('a')
  51. ->field('a.*,o.order_sn')
  52. ->join('order o', 'o.id = a.order_id')
  53. ->append(['change_type_desc'])
  54. ->where($where)
  55. ->page($get['page'], $get['limit'])
  56. ->order('a.id desc')
  57. ->select();
  58. foreach ($lists as &$v){
  59. if($v['change_type'] == 2){
  60. $v['order_sn'] = DividendOrder::where(['id'=>$v['order_id']])->value('sn');
  61. }
  62. }
  63. $count = DividendCashLog::alias('a')
  64. ->field('a.*')
  65. ->join('order o', 'o.id = a.order_id')
  66. ->where($where)
  67. ->order('a.id desc')
  68. ->count();
  69. return ['count' => $count, 'lists' => $lists];
  70. }
  71. /**
  72. * @notes 分红订单明细
  73. * @param $get
  74. * @return array
  75. * @throws \think\db\exception\DataNotFoundException
  76. * @throws \think\db\exception\DbException
  77. * @throws \think\db\exception\ModelNotFoundException
  78. * @author suny
  79. * @date 2021/7/14 10:01 上午
  80. */
  81. public static function order($get, $is_export = false)
  82. {
  83. $where = [];
  84. if (isset($get['status']) && $get['status'] <>'') {
  85. $where[] = ['do.status', '=', $get['status']];
  86. }
  87. if (isset($get['is_exchange']) && $get['is_exchange'] <>'') {
  88. $where[] = ['do.is_exchange', '=', $get['is_exchange']];
  89. }
  90. if (empty($get['start_time']) && empty($get['end_time'])) {
  91. $where[] = ['do.create_time', '>=', strtotime(date("Y-m-d", time()))];
  92. $where[] = ['do.create_time', '<=', strtotime(date("Y-m-d", time())) + 86399];
  93. }
  94. //明细时间
  95. if (isset($get['start_time']) && $get['start_time'] != '') {
  96. $where[] = ['do.create_time', '>=', strtotime($get['start_time'])];
  97. }
  98. if (isset($get['end_time']) && $get['end_time'] != '') {
  99. $where[] = ['do.create_time', '<=', strtotime($get['end_time'])];
  100. }
  101. // 导出
  102. if (true === $is_export) {
  103. return self::orderExport($where);
  104. }
  105. $lists = DividendOrder::alias('do')
  106. ->field('do.*,o.order_sn')
  107. ->join('order o', 'o.id = do.order_id')
  108. ->append(['status_desc','is_exchange_desc'])
  109. ->where($where)
  110. ->page($get['page'], $get['limit'])
  111. ->order('do.id desc')
  112. ->select();
  113. $count = DividendOrder::alias('do')
  114. ->field('do.*,o.order_sn')
  115. ->join('order o', 'o.id = do.order_id')
  116. ->where($where)
  117. ->order('do.id desc')
  118. ->count();
  119. return ['count' => $count, 'lists' => $lists];
  120. }
  121. /**
  122. * @notes 会员佣金提现详情
  123. * @param $id
  124. * @return array|\think\Model|null
  125. * @throws \think\db\exception\DataNotFoundException
  126. * @throws \think\db\exception\DbException
  127. * @throws \think\db\exception\ModelNotFoundException
  128. * @author suny
  129. * @date 2021/7/14 10:01 上午
  130. */
  131. public static function detail($get, $is_export = false)
  132. {
  133. $where = [];
  134. if (isset($get['id']) && $get['id'] != '') {
  135. $where[] = ['dol.do_id', '=', $get['id']];
  136. }
  137. if (empty($get['start_time']) && empty($get['end_time'])) {
  138. $where[] = ['dol.create_time', '>=', strtotime(date("Y-m-d", time()))];
  139. $where[] = ['dol.create_time', '<=', strtotime(date("Y-m-d", time())) + 86399];
  140. }
  141. //明细时间
  142. if (isset($get['start_time']) && $get['start_time'] != '') {
  143. $where[] = ['dol.create_time', '>=', strtotime($get['start_time'])];
  144. }
  145. if (isset($get['end_time']) && $get['end_time'] != '') {
  146. $where[] = ['dol.create_time', '<=', strtotime($get['end_time'])];
  147. }
  148. // 导出
  149. if (true === $is_export) {
  150. return self::detailExport($where);
  151. }
  152. $lists = DividendOrderLog::alias('dol')
  153. ->field('dol.*,o.order_sn')
  154. ->join('order o', 'o.id = dol.order_id')
  155. ->where($where)
  156. ->page($get['page'], $get['limit'])
  157. ->order('dol.id desc')
  158. ->select();
  159. $count = DividendOrderLog::alias('dol')
  160. ->field('dol.*,o.order_sn')
  161. ->join('order o', 'o.id = dol.order_id')
  162. ->where($where)
  163. ->order('dol.id desc')
  164. ->count();
  165. return ['count' => $count, 'lists' => $lists];
  166. }
  167. /**
  168. * @notes 导出Excel
  169. * @param array $where
  170. * @return array|false
  171. * @author 段誉
  172. * @date 2022/4/24 10:10
  173. */
  174. public static function orderExport($where)
  175. {
  176. try {
  177. $lists = DividendOrder::alias('do')
  178. ->field('do.*,o.order_sn')
  179. ->join('order o', 'o.id = do.order_id')
  180. ->append(['status_desc','is_exchange_desc'])
  181. ->where($where)
  182. ->order('do.id desc')
  183. ->select();
  184. $excelFields = [
  185. 'id' => 'ID',
  186. 'sn' => '排队单号',
  187. 'rated_money' => '目标金额',
  188. 'money' => '已得金额',
  189. 'status_desc' => '排队状态',
  190. 'is_exchange_desc' => '兑换状态',
  191. 'order_sn' => '来源单号',
  192. 'update_time' => '更新时间',
  193. 'create_time' => '记录时间',
  194. ];
  195. $export = new ExportExcelServer();
  196. $export->setFileName('排队订单信息');
  197. $result = $export->createExcel($excelFields, $lists);
  198. return ['url' => $result];
  199. } catch (\Exception $e) {
  200. self::$error = $e->getMessage();
  201. return false;
  202. }
  203. }
  204. /**
  205. * @notes 导出Excel
  206. * @param array $where
  207. * @return array|false
  208. * @author 段誉
  209. * @date 2022/4/24 10:10
  210. */
  211. public static function cashExport($where)
  212. {
  213. try {
  214. $lists = DividendCashLog::alias('a')
  215. ->field('a.*,o.order_sn')
  216. ->join('order o', 'o.id = a.order_id')
  217. ->append(['change_type_desc'])
  218. ->where($where)
  219. ->order('a.id desc')
  220. ->select();
  221. foreach ($lists as &$v){
  222. if($v['change_type'] == 2){
  223. $v['order_sn'] = DividendOrder::where(['id'=>$v['order_id']])->value('sn');
  224. }
  225. }
  226. $excelFields = [
  227. 'id' => 'ID',
  228. 'change_type_desc' => '变动类型',
  229. 'change_money' => '变动金额',
  230. 'total_money' => '剩余金额',
  231. 'order_sn' => '来源单号',
  232. 'create_time' => '记录时间',
  233. ];
  234. $export = new ExportExcelServer();
  235. $export->setFileName('分红订单列表信息');
  236. $result = $export->createExcel($excelFields, $lists);
  237. return ['url' => $result];
  238. } catch (\Exception $e) {
  239. self::$error = $e->getMessage();
  240. return false;
  241. }
  242. }
  243. /**
  244. * @notes 导出Excel
  245. * @param array $condition
  246. * @return array|false
  247. * @author 段誉
  248. * @date 2022/4/24 10:10
  249. */
  250. public static function detailExport($where)
  251. {
  252. try {
  253. $lists = DividendOrderLog::alias('dol')
  254. ->field('dol.*,o.order_sn')
  255. ->join('order o', 'o.id = dol.order_id')
  256. ->where($where)
  257. ->order('dol.id desc')
  258. ->select();
  259. $excelFields = [
  260. 'order_sn' => '来源单号',
  261. 'money' => '金额',
  262. 'create_time' => '发生时间',
  263. ];
  264. $export = new ExportExcelServer();
  265. $export->setFileName('分红订单明细记录');
  266. $result = $export->createExcel($excelFields, $lists);
  267. return ['url' => $result];
  268. } catch (\Exception $e) {
  269. self::$error = $e->getMessage();
  270. return false;
  271. }
  272. }
  273. }