CommissionController.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace addons\WechatVideoShop\backend\controllers;
  3. use addons\WechatVideoShop\common\models\WechatVideoShopCommission;
  4. use addons\WechatVideoShop\common\service\CommissionService;
  5. use addons\WechatVideoShop\common\service\ShopService;
  6. use common\enums\DownloadEnum;
  7. use common\helpers\csv\CsvExportHelper;
  8. class CommissionController extends BaseController
  9. {
  10. public $enableCsrfValidation = false;
  11. public function actionIndex()
  12. {
  13. if (\Yii::$app->request->isAjax) {
  14. if (\Yii::$app->request->isGet) {
  15. $data = \Yii::$app->request->get();
  16. $valid = \Yii::$app->services->validate->validate($data, [
  17. [['page', 'limit', 'shop_id', 'user_id', 'settle_status'], 'integer'],
  18. [['member', 'mobile', 'date_start', 'date_end'], 'string'],
  19. ], []);
  20. if ($valid === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  21. // 获取数据
  22. $ret = (new CommissionService())->page($this->mall_id, $data);
  23. // 获取所有店铺键值对
  24. $ret['shop'] = (new ShopService())->ShopArr($this->mall_id);
  25. $ret['export_list'] = WechatVideoShopCommission::exportFieldsList();
  26. return $this->success('获取成功', $ret);
  27. }
  28. if (\Yii::$app->request->post('flag') == 'EXPORT') {
  29. $post = \Yii::$app->request->post();
  30. $post['mall_id'] = $this->mall_id;
  31. $filename = '微信视频号小店分销员奖励明细列表-' . date('YmdHis') . '_' . rand(10000, 99999);
  32. $res = CsvExportHelper::exportDownLoadCenter($this->mall_id, $filename, DownloadEnum::TYPE_WECHAT_VIDEO_SHOP, WechatVideoShopCommission::class, 'exportHandle', $post);
  33. if ($res === false) return $this->error('加入导出任务失败' . CsvExportHelper::getStaticError());
  34. return $this->success('添加导出任务成功,任务完成后请在下载中心进行下载!');
  35. }
  36. }
  37. return $this->render('index');
  38. }
  39. }