FinanceController.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: leo
  5. * Date: 2018/3/9
  6. * Time: 上午11:56
  7. */
  8. namespace console\controllers;
  9. use backendApi\modules\v1\models\lists\finance\BalanceAuditList;
  10. use backendApi\modules\v1\models\lists\finance\HistoryBonusList;
  11. use backendApi\modules\v1\models\lists\finance\RechargeList;
  12. use backendApi\modules\v1\models\lists\finance\TransferList;
  13. use backendApi\modules\v1\models\lists\finance\WithdrawList;
  14. use common\libs\export\module\FinanceExport;
  15. use common\models\Withdraw;
  16. use Yii;
  17. class FinanceController extends BaseController {
  18. /**
  19. * 会员余额调整列表导出
  20. * @param $taskId
  21. * @return bool
  22. */
  23. public function actionBalanceAuditListExport($taskId) {
  24. return $this->_export($taskId, BalanceAuditList::class, '会员余额调整列表');
  25. }
  26. // /**
  27. // * 会员业绩调整列表导出
  28. // * @param $taskId
  29. // * @return bool
  30. // */
  31. // public function actionPerfAuditListExport($taskId) {
  32. // return $this->_export($taskId, PerfAuditList::class, '会员业绩调整列表');
  33. // }
  34. /**
  35. * 转账列表导出
  36. * @param $taskId
  37. * @return bool
  38. */
  39. public function actionTransferListExport($taskId) {
  40. return $this->_export($taskId, TransferList::class, '转账列表');
  41. }
  42. /**
  43. * 历史奖金余额导出
  44. * @param $taskId
  45. * @return bool
  46. */
  47. public function actionHistoryBonusExport($taskId) {
  48. return $this->_export($taskId, HistoryBonusList::class, '历史奖金余额');
  49. }
  50. /**
  51. * 提现明细导出到excel
  52. * @param $taskId
  53. * @return bool
  54. */
  55. public function actionWithdrawExport($taskId) {
  56. return $this->_export($taskId, WithdrawList::class, '提现明细');
  57. }
  58. /**
  59. * 充值明细导出到excel
  60. * @param $taskId
  61. * @return bool
  62. */
  63. public function actionRechargeExport($taskId) {
  64. return $this->_export($taskId, RechargeList::class, '充值明细');
  65. }
  66. /**
  67. * 导出方法
  68. * @param $taskId
  69. * @param $className
  70. * @param $listName
  71. * @return bool
  72. */
  73. private function _export($taskId, $className, $listName){
  74. $factory = FinanceExport::factory($taskId);
  75. $factory->listModelClass = $className;
  76. try {
  77. if ($factory->generate()) {
  78. \Yii::$app->swooleAsyncTimer->pushAsyncResultToAdmin($factory->getUserId(), $listName.'导出成功');
  79. }
  80. unset($factory, $taskId, $className, $listName);
  81. return true;
  82. } catch (\Exception $e) {
  83. echo $listName.'导出失败。详情:' . $e->getMessage();
  84. \Yii::$app->swooleAsyncTimer->pushAsyncResultToAdmin($factory->getUserId(), $listName.'导出失败。详情:' . $e->getMessage(), false);
  85. }
  86. unset($factory, $taskId, $className, $listName);
  87. return false;
  88. }
  89. }