MaterialStatisticsController.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace addons\BusinessCard\backend\controllers;
  3. use addons\BusinessCard\common\models\BusinessCardMaterials;
  4. use addons\BusinessCard\common\models\BusinessCardMaterialsStatistics;
  5. use common\enums\StatusEnum;
  6. use Yii;
  7. class MaterialStatisticsController extends BaseController
  8. {
  9. public $enableCsrfValidation = false;
  10. public function actionIndex()
  11. {
  12. if (Yii::$app->request->isAjax && Yii::$app->request->isPost) {
  13. $post = Yii::$app->request->post();
  14. $where = [['=', 'mall_id', $this->mall_id], ['<>', 'status' , StatusEnum::DELETE]];
  15. if (isset($post['material_id']) && $post['material_id']) {
  16. $where[] = ['=', 'material_id', $post['material_id']];
  17. }
  18. if (isset($post['title']) && $post['title']) {
  19. $material_ids = BusinessCardMaterials::find()
  20. ->orWhere(['like', 'title', "%" . $post['title'] . "%", false])
  21. ->select('id')
  22. ->asArray()
  23. ->column();
  24. $where[] = ['in', 'material_id', $material_ids];
  25. }
  26. $params = [
  27. 'limit' => 10,
  28. 'with' => 'material',
  29. 'where' => $where,
  30. 'order' => 'id desc'
  31. ];
  32. $list = BusinessCardMaterialsStatistics::listPage($params);
  33. return $this->success('操作成功', $list);
  34. } else {
  35. return $this->render('index');
  36. }
  37. }
  38. }