MemberController.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. namespace addons\TinyShop\merchant\modules\statistics\controllers;
  3. use common\enums\PayStatusEnum;
  4. use Yii;
  5. use common\enums\StatusEnum;
  6. use common\models\base\SearchModel;
  7. use addons\TinyShop\common\models\order\Order;
  8. use addons\TinyShop\merchant\controllers\BaseController;
  9. use addons\TinyShop\common\enums\MemberActiveEnum;
  10. use addons\TinyShop\merchant\modules\statistics\forms\OrderForm;
  11. /**
  12. * Class MemberController
  13. * @package addons\TinyShop\merchant\modules\statistics\controllers
  14. * @author jianyan74 <751393839@qq.com>
  15. */
  16. class MemberController extends BaseController
  17. {
  18. public function actionIndex()
  19. {
  20. $start_time = Yii::$app->request->get('start_time', date('Y-m-d', strtotime("-60 day")));
  21. $end_time = Yii::$app->request->get('end_time', date('Y-m-d', strtotime("+1 day")));
  22. $searchModel = new SearchModel([
  23. 'model' => Order::class,
  24. 'scenario' => 'default',
  25. 'partialMatchAttributes' => [], // 模糊查询
  26. 'defaultOrder' => [
  27. 'pay_money' => SORT_DESC,
  28. ],
  29. 'pageSize' => $this->pageSize,
  30. ]);
  31. $dataProvider = $searchModel
  32. ->search(Yii::$app->request->queryParams);
  33. $dataProvider->query
  34. ->select([
  35. 'buyer_id',
  36. 'sum(product_count) as product_count',
  37. 'sum(pay_money) as pay_money',
  38. 'sum(refund_money) as refund_money'
  39. ])
  40. ->where(['pay_status' => PayStatusEnum::YES])
  41. ->andWhere(['>', 'buyer_id', 0])
  42. ->andFilterWhere(['merchant_id' => $this->getMerchantId()])
  43. ->andFilterWhere(['between', 'created_at', strtotime($start_time), strtotime($end_time)])
  44. ->groupBy('buyer_id')
  45. ->with(['member']);
  46. return $this->render('index', [
  47. 'searchModel' => $searchModel,
  48. 'dataProvider' => $dataProvider,
  49. 'start_time' => $start_time,
  50. 'end_time' => $end_time,
  51. ]);
  52. }
  53. /**
  54. * @return string
  55. */
  56. public function actionActive()
  57. {
  58. $type = Yii::$app->request->get('type', MemberActiveEnum::ACTIVE);
  59. $time = MemberActiveEnum::getTime($type);
  60. $searchModel = new SearchModel([
  61. 'model' => OrderForm::class,
  62. 'scenario' => 'default',
  63. 'partialMatchAttributes' => [], // 模糊查询
  64. 'defaultOrder' => [
  65. 'created_at' => SORT_DESC,
  66. ],
  67. 'pageSize' => $this->pageSize,
  68. ]);
  69. $dataProvider = $searchModel
  70. ->search(Yii::$app->request->queryParams);
  71. $dataProvider->query
  72. ->select([
  73. 'buyer_id',
  74. 'max(created_at) as created_at',
  75. 'max(id) as id',
  76. 'count(id) as count',
  77. 'sum(product_count) as product_count',
  78. 'sum(pay_money) as pay_money',
  79. 'sum(refund_money) as refund_money'
  80. ])
  81. ->where(['pay_status' => PayStatusEnum::YES])
  82. ->andWhere(['>', 'buyer_id', 0])
  83. ->andWhere(['>=', 'status', StatusEnum::DISABLED])
  84. ->andFilterWhere(['merchant_id' => $this->getMerchantId()])
  85. ->having(['between', 'created_at', $time['start_time'], $time['end_time']])
  86. ->groupBy('buyer_id')
  87. ->with(['member', 'order']);
  88. return $this->render($this->action->id, [
  89. 'searchModel' => $searchModel,
  90. 'dataProvider' => $dataProvider,
  91. 'type' => $type,
  92. 'time' => $time,
  93. ]);
  94. }
  95. }
粤ICP备19079148号