Exemplo n.º 1
0
 public function addPayment($workerId, $sum, $sessionId)
 {
     $payment = new Payment();
     $payment->worker_id = $workerId;
     $payment->sum = $sum;
     $payment->session_id = $sessionId;
     $payment->user_id = Yii::$app->user->id;
     $payment->date = date('Y-m-d H:i:s');
     $payment->date_timestamp = time();
     if ($payment->validate() && $payment->save()) {
         $module = \Yii::$app->getModule('staffer');
         $paymentEvent = new PaymentEvent(['model' => $payment]);
         $module->trigger($module::EVENT_PAYMENT_CREATE, $paymentEvent);
         return $payment->id;
     } else {
         return false;
     }
 }
Exemplo n.º 2
0
 public function actionSet()
 {
     $data = yii::$app->request->post();
     $json = ['result' => null, 'error' => null];
     if (!Payment::find()->where(['worker_id' => $data['worker_id'], 'session_id' => $data['session_id']])->one()) {
         $payment = new Payment();
         $payment->worker_id = $data['worker_id'];
         $payment->session_id = $data['session_id'];
         $payment->sum = $data['sum'];
         if ($payment->validate() && $payment->save()) {
             $json['result'] = 'success';
         } else {
             $json['result'] = 'fail';
             $json['error'] = $payment->errors;
         }
     }
     return json_encode($json);
 }