DividendCashLogic.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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 (empty($get['start_time']) && empty($get['end_time'])) {
  85. $where[] = ['do.create_time', '>=', strtotime(date("Y-m-d", time()))];
  86. $where[] = ['do.create_time', '<=', strtotime(date("Y-m-d", time())) + 86399];
  87. }
  88. //明细时间
  89. if (isset($get['start_time']) && $get['start_time'] != '') {
  90. $where[] = ['do.create_time', '>=', strtotime($get['start_time'])];
  91. }
  92. if (isset($get['end_time']) && $get['end_time'] != '') {
  93. $where[] = ['do.create_time', '<=', strtotime($get['end_time'])];
  94. }
  95. // 导出
  96. if (true === $is_export) {
  97. return self::orderExport($where);
  98. }
  99. $lists = DividendOrder::alias('do')
  100. ->field('do.*,o.order_sn')
  101. ->join('order o', 'o.id = do.order_id')
  102. ->append(['status_desc','is_exchange_desc'])
  103. ->where($where)
  104. ->page($get['page'], $get['limit'])
  105. ->order('do.id desc')
  106. ->select();
  107. $count = DividendOrder::alias('do')
  108. ->field('do.*,o.order_sn')
  109. ->join('order o', 'o.id = do.order_id')
  110. ->where($where)
  111. ->order('do.id desc')
  112. ->count();
  113. return ['count' => $count, 'lists' => $lists];
  114. }
  115. /**
  116. * @notes 会员佣金提现详情
  117. * @param $id
  118. * @return array|\think\Model|null
  119. * @throws \think\db\exception\DataNotFoundException
  120. * @throws \think\db\exception\DbException
  121. * @throws \think\db\exception\ModelNotFoundException
  122. * @author suny
  123. * @date 2021/7/14 10:01 上午
  124. */
  125. public static function detail($get, $is_export = false)
  126. {
  127. $where = [];
  128. if (isset($get['id']) && $get['id'] != '') {
  129. $where[] = ['dol.do_id', '=', $get['id']];
  130. }
  131. if (empty($get['start_time']) && empty($get['end_time'])) {
  132. $where[] = ['dol.create_time', '>=', strtotime(date("Y-m-d", time()))];
  133. $where[] = ['dol.create_time', '<=', strtotime(date("Y-m-d", time())) + 86399];
  134. }
  135. //明细时间
  136. if (isset($get['start_time']) && $get['start_time'] != '') {
  137. $where[] = ['dol.create_time', '>=', strtotime($get['start_time'])];
  138. }
  139. if (isset($get['end_time']) && $get['end_time'] != '') {
  140. $where[] = ['dol.create_time', '<=', strtotime($get['end_time'])];
  141. }
  142. // 导出
  143. if (true === $is_export) {
  144. return self::detailExport($where);
  145. }
  146. $lists = DividendOrderLog::alias('dol')
  147. ->field('dol.*,o.order_sn')
  148. ->join('order o', 'o.id = dol.order_id')
  149. ->where($where)
  150. ->page($get['page'], $get['limit'])
  151. ->order('dol.id desc')
  152. ->select();
  153. $count = DividendOrderLog::alias('dol')
  154. ->field('dol.*,o.order_sn')
  155. ->join('order o', 'o.id = dol.order_id')
  156. ->where($where)
  157. ->order('dol.id desc')
  158. ->count();
  159. return ['count' => $count, 'lists' => $lists];
  160. }
  161. /**
  162. * @notes 导出Excel
  163. * @param array $where
  164. * @return array|false
  165. * @author 段誉
  166. * @date 2022/4/24 10:10
  167. */
  168. public static function orderExport($where)
  169. {
  170. try {
  171. $lists = DividendOrder::alias('do')
  172. ->field('do.*,o.order_sn')
  173. ->join('order o', 'o.id = do.order_id')
  174. ->append(['status_desc','is_exchange_desc'])
  175. ->where($where)
  176. ->order('do.id desc')
  177. ->select();
  178. $excelFields = [
  179. 'id' => 'ID',
  180. 'sn' => '排队单号',
  181. 'rated_money' => '目标金额',
  182. 'money' => '已得金额',
  183. 'status_desc' => '排队状态',
  184. 'is_exchange_desc' => '兑换状态',
  185. 'order_sn' => '来源单号',
  186. 'update_time' => '更新时间',
  187. 'create_time' => '记录时间',
  188. ];
  189. $export = new ExportExcelServer();
  190. $export->setFileName('排队订单信息');
  191. $result = $export->createExcel($excelFields, $lists);
  192. return ['url' => $result];
  193. } catch (\Exception $e) {
  194. self::$error = $e->getMessage();
  195. return false;
  196. }
  197. }
  198. /**
  199. * @notes 导出Excel
  200. * @param array $where
  201. * @return array|false
  202. * @author 段誉
  203. * @date 2022/4/24 10:10
  204. */
  205. public static function cashExport($where)
  206. {
  207. try {
  208. $lists = DividendCashLog::alias('a')
  209. ->field('a.*,o.order_sn')
  210. ->join('order o', 'o.id = a.order_id')
  211. ->append(['change_type_desc'])
  212. ->where($where)
  213. ->order('a.id desc')
  214. ->select();
  215. foreach ($lists as &$v){
  216. if($v['change_type'] == 2){
  217. $v['order_sn'] = DividendOrder::where(['id'=>$v['order_id']])->value('sn');
  218. }
  219. }
  220. $excelFields = [
  221. 'id' => 'ID',
  222. 'change_type_desc' => '变动类型',
  223. 'change_money' => '变动金额',
  224. 'total_money' => '剩余金额',
  225. 'order_sn' => '来源单号',
  226. 'create_time' => '记录时间',
  227. ];
  228. $export = new ExportExcelServer();
  229. $export->setFileName('分红订单列表信息');
  230. $result = $export->createExcel($excelFields, $lists);
  231. return ['url' => $result];
  232. } catch (\Exception $e) {
  233. self::$error = $e->getMessage();
  234. return false;
  235. }
  236. }
  237. /**
  238. * @notes 导出Excel
  239. * @param array $condition
  240. * @return array|false
  241. * @author 段誉
  242. * @date 2022/4/24 10:10
  243. */
  244. public static function detailExport($where)
  245. {
  246. try {
  247. $lists = DividendOrderLog::alias('dol')
  248. ->field('dol.*,o.order_sn')
  249. ->join('order o', 'o.id = dol.order_id')
  250. ->where($where)
  251. ->order('dol.id desc')
  252. ->select();
  253. $excelFields = [
  254. 'order_sn' => '来源单号',
  255. 'money' => '金额',
  256. 'create_time' => '发生时间',
  257. ];
  258. $export = new ExportExcelServer();
  259. $export->setFileName('分红订单明细记录');
  260. $result = $export->createExcel($excelFields, $lists);
  261. return ['url' => $result];
  262. } catch (\Exception $e) {
  263. self::$error = $e->getMessage();
  264. return false;
  265. }
  266. }
  267. }