OfferdesignController.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. namespace backend\controllers;
  3. use backend\models\AuthArea;
  4. use common\models\Design;
  5. use common\models\Offer;
  6. use yii;
  7. use yii\filters\AccessControl;
  8. /**
  9. * 免费报价/设计
  10. * @package backend\controllers
  11. */
  12. class OfferdesignController extends BaseController
  13. {
  14. public $layout = 'iframe';
  15. const PAGESIZE = 20;//分页数
  16. public function behaviors()
  17. {
  18. return [
  19. 'access' => [
  20. 'class' => AccessControl::className(),
  21. 'rules' => [
  22. [
  23. 'actions' => [],
  24. 'allow' => true,
  25. 'roles' => ['@'],
  26. ],
  27. ],
  28. ],
  29. ];
  30. }
  31. /**
  32. *报价列表
  33. * @return string
  34. */
  35. public function actionOffer()
  36. {
  37. $search =['start'=>'','end'=>''];
  38. $search['start'] = Yii::$app->request->get('start');
  39. $search['end'] = Yii::$app->request->get('end');
  40. $models = Offer::find()->where(['status'=>Offer::STATUS_YES]);
  41. if(!empty($search['start']))
  42. $models->andWhere("c_time > :start",[':start'=>strtotime($search['start'])]);
  43. if(!empty($search['end']))
  44. $models->andWhere("c_time < :end",[':end'=>strtotime($search['end'])+(3600*24-1)]);
  45. $citys = AuthArea::queryAuth();
  46. if($citys=='all')
  47. $models;
  48. elseif (!empty($citys))
  49. $models->andWhere("area_id in ({$citys})");
  50. else
  51. $models->andWhere("area_id = -1");
  52. $pages = new yii\data\Pagination(["totalCount" => $models->count(), "pageSize" => self::PAGESIZE]);
  53. $models = $models->offset($pages->offset)->limit($pages->limit)->orderBy("id DESC")->all();
  54. return $this->render('offer', ['models' => $models, 'pages' => $pages,'name'=>'免费报价列表','search'=>$search]);
  55. }
  56. /**
  57. * 删除报价
  58. */
  59. public function actionDelOffer()
  60. {
  61. $id = Yii::$app->request->post('id');
  62. $model = Offer::find()->where(['id'=>$id])->one();
  63. $result = ['sign'=>1,'msg'=>'删除成功'];
  64. if(!empty($model))
  65. {
  66. $model->status = Offer::STATUS_NO;
  67. if(!$model->save())
  68. $result= ['sign'=>0,'msg'=>'删除失败'];
  69. }else{
  70. $result= ['sign'=>0,'msg'=>'找不到该记录'];
  71. }
  72. return json_encode($result);
  73. }
  74. /**
  75. *设计列表
  76. * @return string
  77. */
  78. public function actionDesign()
  79. {
  80. $search =['start'=>'','end'=>''];
  81. $search['start'] = Yii::$app->request->get('start');
  82. $search['end'] = Yii::$app->request->get('end');
  83. $models = Design::find()->where(['status'=>Design::STATUS_YES]);
  84. if(!empty($search['start']))
  85. $models->andWhere("c_time > :start",[':start'=>strtotime($search['start'])]);
  86. if(!empty($search['end']))
  87. $models->andWhere("c_time < :end",[':end'=>strtotime($search['end'])+(3600*24-1)]);
  88. $citys = AuthArea::queryAuth();
  89. if($citys=='all')
  90. $models;
  91. elseif (!empty($citys))
  92. $models->andWhere("area_id in ({$citys})");
  93. else
  94. $models->andWhere("area_id = -1");
  95. $pages = new yii\data\Pagination(["totalCount" => $models->count(), "pageSize" => self::PAGESIZE]);
  96. $models = $models->offset($pages->offset)->limit($pages->limit)->orderBy(",id DESC")->all();
  97. return $this->render('design', ['models' => $models, 'pages' => $pages,'name'=>'免费设计列表','search'=>$search]);
  98. }
  99. /**
  100. * 删除设计
  101. */
  102. public function actionDelDesign()
  103. {
  104. $id = Yii::$app->request->post('id');
  105. $model = Design::find()->where(['id'=>$id])->one();
  106. $result = ['sign'=>1,'msg'=>'删除成功'];
  107. if(!empty($model))
  108. {
  109. $model->status = Design::STATUS_NO;
  110. if(!$model->save())
  111. $result= ['sign'=>0,'msg'=>'删除失败'];
  112. }else{
  113. $result= ['sign'=>0,'msg'=>'找不到该记录'];
  114. }
  115. return json_encode($result);
  116. }
  117. }