PushcitypriceController.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: xiaofeng
  5. * Date: 2018/6/19
  6. * Time: 下午3:10
  7. */
  8. namespace backend\controllers;
  9. use backend\base\CommonController;
  10. use backend\base\Help;
  11. use Yii;
  12. use common\models\PushCityprice;
  13. class PushcitypriceController extends CommonController
  14. {
  15. /*
  16. * 首页- 区域价格 页面
  17. * */
  18. public function actionPrice()
  19. {
  20. return $this->render('price',['type'=>1]);
  21. }
  22. /*
  23. * 首页 - 区域价格数据
  24. * */
  25. public function actionPriceform()
  26. {
  27. $model = new PushCityprice();
  28. $model->type = Yii::$app->request->post('type');
  29. $rows = $model->getList(Yii::$app->request->post());
  30. if(!empty($rows))
  31. {
  32. foreach ($rows as &$val)
  33. {
  34. $val['create_at'] = date('Y-m-d H:i',$val['create_at']);
  35. }
  36. return Help::JsonData(0,Yii::t('app','get_success'),$model->Total(),$rows);
  37. }
  38. }
  39. /*
  40. * 首页-区域价格添加-页面
  41. * */
  42. public function actionPriceadd()
  43. {
  44. return $this->render('priceadd',['type'=>Yii::$app->request->get('type')]);
  45. }
  46. /*
  47. * 首页-区域价格添加-数据
  48. * */
  49. public function actionPricdeaddform()
  50. {
  51. $model = new PushCityprice();
  52. $input = Yii::$app->request->post();
  53. $true = false;
  54. if(!empty($input['city_id']))
  55. {
  56. $transaction = Yii::$app->db->beginTransaction();
  57. foreach ($input['city_id'] as $val)
  58. {
  59. $_model = clone $model;
  60. $cloneRow = $_model::find()->andWhere(['del'=>1])->andWhere(['type'=>$input['type']])->andWhere(['city_id'=>$val])->one();
  61. if($cloneRow == null)
  62. {
  63. $_model->city_id = $val;
  64. $_model->type = $input['type'];
  65. if($_model->save(false))
  66. {
  67. $true = true;
  68. }
  69. else
  70. {
  71. $true = false;
  72. break;
  73. }
  74. }
  75. else
  76. {
  77. return Help::JsonCode(Help::ERROR,'添加失败,请查看该区域是否存在!');
  78. }
  79. }
  80. if($true){
  81. $transaction->commit();
  82. return Help::JsonCode(Help::SUCCESS,Yii::t('app','add_success'));
  83. }
  84. $transaction->rollBack();
  85. }
  86. return Help::JsonCode(Help::ERROR,Yii::t('app','add_error'));
  87. }
  88. /*
  89. * 删除
  90. * */
  91. public function actionPriceeditanddel()
  92. {
  93. $model = new PushCityprice();
  94. $input = Yii::$app->request->post();
  95. $row = $model->FindById($input['id']);
  96. if($row != null)
  97. {
  98. switch ($input['type'])
  99. {
  100. case 'show':
  101. if($row->is_show == 1)
  102. {
  103. $row->is_show = 2;
  104. }
  105. else if($row->is_show == 2)
  106. {
  107. $row->is_show = 1;
  108. }
  109. break;
  110. case 'del':
  111. $row->del = 2;
  112. break;
  113. case 'sort':
  114. if(is_numeric($input['sort']))
  115. {
  116. $row->sort = $input['sort'];
  117. }
  118. break;
  119. }
  120. if($row->save(false)) return Help::JsonCode(Help::SUCCESS,Yii::t('app','edit_success'));
  121. }
  122. return Help::JsonCode(Help::ERROR,Yii::t('app','edit_error'));
  123. }
  124. }