|
|
|
|
|
|
|
|
use yii\base\UserException; |
|
|
use yii\base\UserException; |
|
|
use common\models\CreditHistorique; |
|
|
use common\models\CreditHistorique; |
|
|
use common\models\Commande; |
|
|
use common\models\Commande; |
|
|
|
|
|
use common\helpers\Mail; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* UserController implements the CRUD actions for User model. |
|
|
* UserController implements the CRUD actions for User model. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function actionCredit($id) { |
|
|
public function actionCredit($id) { |
|
|
$user = User::find()->with('userEtablissement')->where(['id' => $id])->one(); |
|
|
$user = User::find()->with('userEtablissement')->where(['id' => $id])->one(); |
|
|
$user_appartient_etablissement = UserEtablissement::findOne(['id_user' => $id, 'id_etablissement' => Yii::$app->user->identity->id_etablissement]); |
|
|
|
|
|
if (($user_appartient_etablissement) || Yii::$app->user->identity->status == USER::STATUS_ADMIN) { |
|
|
|
|
|
|
|
|
$user_etablissement = UserEtablissement::findOne(['id_user' => $id, 'id_etablissement' => Yii::$app->user->identity->id_etablissement]); |
|
|
|
|
|
$etablissement = Etablissement::findOne(Yii::$app->user->identity->id_etablissement) ; |
|
|
|
|
|
|
|
|
|
|
|
if (($user_etablissement) || Yii::$app->user->identity->status == USER::STATUS_ADMIN) { |
|
|
$credit_historique = new CreditHistorique; |
|
|
$credit_historique = new CreditHistorique; |
|
|
if ($credit_historique->load(Yii::$app->request->post()) && $credit_historique->validate()) { |
|
|
if ($credit_historique->load(Yii::$app->request->post()) && $credit_historique->validate()) { |
|
|
$credit_historique->id_user = $user->id; |
|
|
$credit_historique->id_user = $user->id; |
|
|
$credit_historique->id_user_action = Yii::$app->user->identity->id; |
|
|
$credit_historique->id_user_action = Yii::$app->user->identity->id; |
|
|
$credit_historique->id_etablissement = Yii::$app->user->identity->id_etablissement; |
|
|
$credit_historique->id_etablissement = Yii::$app->user->identity->id_etablissement; |
|
|
$credit_historique->save(); |
|
|
$credit_historique->save(); |
|
|
|
|
|
|
|
|
|
|
|
// on prévient l'utilisateur que son compte vient d'être crédité |
|
|
|
|
|
if($credit_historique->type == CreditHistorique::TYPE_CREDIT) { |
|
|
|
|
|
Mail::send($user->email, 'Votre compte vient d\'être crédité','creditUser', [ |
|
|
|
|
|
'user' => $user, |
|
|
|
|
|
'etablissement' => $etablissement, |
|
|
|
|
|
'user_etablissement' => $user_etablissement, |
|
|
|
|
|
'credit_historique' => $credit_historique |
|
|
|
|
|
]) ; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
$credit_historique = new CreditHistorique; |
|
|
$credit_historique = new CreditHistorique; |
|
|
} |
|
|
} |
|
|
|
|
|
|