UpdateAction.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. //namespace yii\rest;
  3. namespace app\controllers;
  4. use Yii;
  5. use yii\rest\Action;
  6. use yii\base\Model;
  7. use yii\db\ActiveRecord;
  8. use yii\web\ServerErrorHttpException;
  9. class UpdateAction extends Action
  10. {
  11. /**
  12. * @var string the scenario to be assigned to the model before it is validated and updated.
  13. */
  14. public $scenario = Model::SCENARIO_DEFAULT;
  15. /**
  16. * Updates an existing model.
  17. * @param string $id the primary key of the model.
  18. * @return \yii\db\ActiveRecordInterface the model being updated
  19. * @throws ServerErrorHttpException if there is any error when updating the model
  20. */
  21. public function run($id)
  22. {
  23. /* @var $model ActiveRecord */
  24. $model = $this->findModel($id); //return $model->last_user; exit;
  25. if ($this->checkAccess) {
  26. call_user_func($this->checkAccess, $this->id, $model);
  27. }
  28. $model->scenario = $this->scenario;
  29. $arr = Yii::$app->getRequest()->getBodyParams(); //return $arr['last_user']; exit;
  30. if($model->type_id=="1") {
  31. $sql = Yii::$app->db->createCommand("SELECT update_price_function(:last_user_in, :id_in, :price_in)")
  32. ->bindValues([':last_user_in' => $arr['last_user'], ':id_in' => $model->id, ':price_in' => $arr['price_in']]);
  33. $res = $sql->queryOne();
  34. // var_dump($res); exit;
  35. foreach ($res as $key => $value) {
  36. return $value;
  37. }
  38. }
  39. if($model->type_id=="2") {
  40. // if ($model->last_user > 0)
  41. // {
  42. // return "3";
  43. // }
  44. $sql = Yii::$app->db->createCommand("SELECT update_price_tipe_id_2_function(:last_user_in, :id_in, :price_in)")
  45. ->bindValues([':last_user_in' => $arr['last_user'], ':id_in' => $model->id, ':price_in' => $arr['price_in']]);
  46. $res = $sql->queryOne();
  47. //var_dump($res);
  48. foreach ($res as $key => $value) {
  49. return $value;
  50. }
  51. }
  52. /*
  53. if($model->last_user != $arr['last_user'])
  54. {
  55. Yii::$app->db->createCommand("CALL update_price_procedure(:last_user,:id)")
  56. ->bindValues([':last_user' => $arr['last_user'], ':id' => $model->id,])
  57. ->execute();
  58. return false;
  59. }
  60. else
  61. {
  62. return false;
  63. }*/
  64. //return $model;
  65. }
  66. }