MessageHistoryController.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace addons\Wechat\merchant\controllers;
  3. use Yii;
  4. use common\enums\StatusEnum;
  5. use common\models\base\SearchModel;
  6. use common\traits\MerchantCurd;
  7. use addons\Wechat\common\models\MessageHistory;
  8. use addons\Wechat\common\enums\RuleModuleEnum;
  9. /**
  10. * 微信历史消息
  11. *
  12. * Class MessageHistoryController
  13. * @package addons\Wechat\merchant\controllers
  14. * @author jianyan74 <751393839@qq.com>
  15. */
  16. class MessageHistoryController extends BaseController
  17. {
  18. use MerchantCurd;
  19. /**
  20. * @var messageHistory
  21. */
  22. public $modelClass = MessageHistory::class;
  23. /**
  24. * 首页
  25. *
  26. * @return string
  27. * @throws \yii\web\NotFoundHttpException
  28. */
  29. public function actionIndex()
  30. {
  31. $startTime = Yii::$app->request->get('start_time', date('Y-m-d', strtotime("-10 day")));
  32. $endTime = Yii::$app->request->get('end_time', date('Y-m-d', strtotime("+1 day")));
  33. $searchModel = new SearchModel([
  34. 'model' => $this->modelClass,
  35. 'scenario' => 'default',
  36. 'partialMatchAttributes' => ['message'], // 模糊查询
  37. 'defaultOrder' => [
  38. 'id' => SORT_DESC
  39. ],
  40. 'pageSize' => $this->pageSize
  41. ]);
  42. $dataProvider = $searchModel
  43. ->search(Yii::$app->request->queryParams);
  44. $dataProvider->query
  45. ->andWhere(['>=', 'status', StatusEnum::DISABLED])
  46. ->andFilterWhere(['merchant_id' => $this->getMerchantId()])
  47. ->andFilterWhere(['between', 'created_at', !empty($startTime) ? strtotime($startTime) : '', !empty($endTime) ? strtotime($endTime) : ''])
  48. ->with(['fans', 'auth', 'rule']);
  49. return $this->render($this->action->id, [
  50. 'dataProvider' => $dataProvider,
  51. 'searchModel' => $searchModel,
  52. 'moduleExplain' => RuleModuleEnum::getMap(),
  53. 'startTime' => $startTime,
  54. 'endTime' => $endTime,
  55. ]);
  56. }
  57. }
粤ICP备19079148号