Answer the question
In order to leave comments, you need to log in
How to organize the save?
there is a controller
public function actionSaveSend
$user=Yii::$app->user->identity;
$order=Order::findOne(['id'=>$post['id'],'user_id'=>$user->id]);
if(!empty($order)){
$bonus=$this->getPrioritiBonus();
$paysum=round($this->getBonusSum($bonus),5);
$bonusRu=$this->getBonusRu($order,$bonus);
$order->points_bonus=$paysum;
$order->bonus=$bonusRu;
$order->save();
$client = new Client();
$body=json_encode([
"ref"=>$user->code,
"key" => Yii::$app->params['pvk'],
'sum'=>$paysum,
'order'=>$order->id]);
$response = $client->post(\Yii::$app->params['url'],$body, Yii::$app->params['headers'])->send();
if (!$response->isOk)
Yii::$app->session->setFlash('error',$response->data['message']);
}
$transaction=Yii::$app->db->beginTransaction();
if($order->save()){
$client = new Client();
$body=json_encode([
"ref"=>$user->affliliateProgramCode->code,
"key" => Yii::$app->params['pvk'],
'sum'=>$paysum,
'orderNumber'=>$order->id]);
$response = $client->post(\Yii::$app->params['url'],$body, Yii::$app->params['headers'])->send();
if (!$response->isOk){
Yii::$app->session->setFlash('error',$response->data['message']);
$transaction->rollBack();
return false;
}
}
$transaction->commit();
return $this->redirect('/cabinet');
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question