PricetrendController.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2018/2/26/026
  6. * Time: 15:06
  7. */
  8. namespace backend\controllers;
  9. use backend\base\CommonController;
  10. use backend\base\Help;
  11. use Yii;
  12. use common\models\CategoryCity;
  13. use common\models\Pricetrends;
  14. class PricetrendController extends CommonController
  15. {
  16. /*
  17. * 价格走势 列表 页面
  18. * */
  19. public function actionHome()
  20. {
  21. $model = new CategoryCity();
  22. $input = Yii::$app->request->post();
  23. $rows = $model->getList($input,['id as city_id','city_name']);
  24. return $this->render('home',['rows'=>$rows]);
  25. }
  26. /*
  27. * 价格走势 列表 数据
  28. * */
  29. public function actionHomeform()
  30. {
  31. $model = new Pricetrends();
  32. $model->city_id=Yii::$app->request->post("city_id");
  33. $rows = $model->getList(Yii::$app->request->post());
  34. foreach($rows as $k=>$v)
  35. {
  36. $model->city_id=$v['city_id'];
  37. $data = $model->getCityList(Yii::$app->request->post());
  38. $rows[$k]['count']=count($data);
  39. }
  40. if(!empty($rows))
  41. {
  42. return Help::JsonData(0,'成功',$model->Total(),$rows);
  43. }
  44. return Help::JsonCode(Help::ERROR,Yii::t('app','get_error'));
  45. }
  46. /*
  47. * 区域历史价格 页面
  48. * */
  49. public function actionRecordprice()
  50. {
  51. return $this->render('recordprice',['cid'=>Yii::$app->request->get('cid')]);
  52. }
  53. /*
  54. * 区域历史价格数据
  55. * */
  56. public function actionRecordpriceform()
  57. {
  58. $model = new Pricetrends();
  59. $model->city_id = Yii::$app->request->post('city_id');
  60. $rows = $model->getCityList(Yii::$app->request->post());
  61. if(!empty($rows))
  62. {
  63. $arr = Yii::$app->params['CityPriceTrend'];
  64. foreach ($rows as &$val)
  65. {
  66. if(isset($arr[$val['trend']]) && !empty($arr[$val['trend']]))
  67. {
  68. $val['trend'] = $arr[$val['trend']];
  69. }
  70. }
  71. return Help::JsonData(0,'成功',$model->cityTotal(),$rows);
  72. }
  73. return Help::JsonCode(Help::ERROR,Yii::t('app','get_error'));
  74. }
  75. /*
  76. * 价格走势 添加 页面
  77. * */
  78. public function actionPriceadd()
  79. {
  80. $model = new CategoryCity();
  81. $input = Yii::$app->request->post();
  82. $rows = $model->getList($input,['id','city_name']);
  83. return $this->render('priceadd',['rows'=>$rows]);
  84. }
  85. /*
  86. * 价格走势 添加 数据
  87. * */
  88. public function actionPriceaddform()
  89. {
  90. $model = new \common\models\Pricetrends();
  91. $auth = $model->Authenticator(Yii::$app->request->post());
  92. if(is_object($auth))
  93. {
  94. if($auth->save())
  95. {
  96. return Help::JsonCode(Help::SUCCESS,Yii::t('app','add_success'));
  97. }
  98. }
  99. return Help::JsonCode(Help::ERROR,Yii::t('app','add_error'),$auth);
  100. }
  101. /*
  102. * 修改单个区域里面的历史记录
  103. * */
  104. public function actionPriceedit()
  105. {
  106. $model = new Pricetrends();
  107. $row = $model->FindById(Yii::$app->request->get('id'));
  108. return $this->render('priceedit',['model'=>$row]);
  109. }
  110. /*
  111. * 修改单个区域里面的历史记录 数据
  112. * */
  113. public function actionPriceeditform()
  114. {
  115. $model = new Pricetrends();
  116. $auth = $model->Authenticator(Yii::$app->request->post());
  117. if(is_object($auth))
  118. {
  119. $row = $model->FindById(Yii::$app->request->post('id'));
  120. if(!empty($row))
  121. {
  122. $attr = Help::SetAttr(Yii::$app->request->post(),$auth,$row);
  123. if($attr->save())
  124. {
  125. return Help::JsonCode(Help::SUCCESS,Yii::t('app','edit_success'));
  126. }
  127. }
  128. }
  129. return Help::JsonCode(Help::ERROR,Yii::t('app','edit_error'),$auth);
  130. }
  131. /*
  132. * 行里添加按钮
  133. * */
  134. public function actionLineadd()
  135. {
  136. return $this->render('lineadd',['model'=>Yii::$app->request->get()]);
  137. }
  138. /*
  139. * 删除单个区域里面的历史记录 数据
  140. * */
  141. public function actionPricedel()
  142. {
  143. $model = new Pricetrends();
  144. $row = $model->FindById(Yii::$app->request->post('id'));
  145. if(!empty($row))
  146. {
  147. $row->del = 2;
  148. if($row->save(false)) return Help::JsonCode(Help::SUCCESS,Yii::t('app','edit_success'));
  149. }
  150. return Help::JsonCode(Help::ERROR,Yii::t('app','edit_error'));
  151. }
  152. }