public function integralShopBuyAction() { $this->thisController->view->disable(); if (!$this->thisController->id) { return $this->thisController->displayAjax(false, '参数有误'); } $result = self::$service->getCommon($this->thisController->id, 'Good', true); if (!$result) { return $this->thisController->displayAjax(false, '参数有误'); } if (IS_POST) { $form = BaseForm::getForm('BookOrderForm'); if (!$form->isValid($this->thisController->request->getPost())) { foreach ($form->getMessages() as $message) { return $this->thisController->displayAjax(false, $message->getMessage()); } } //写入数据 $data = $this->thisController->request->getPost(); $data['number'] = st_order_number(); $data['book_id'] = 0; if ($this->thisController->user->getCredit() >= $result->getCredit()) { $data['pay_status'] = 2; $data['status'] = 3; //已支付 } else { return $this->thisController->displayAjax(false, '积分不足'); } $data['price'] = 0; $data['pay_method'] = 'credit'; $data['good_id'] = $this->thisController->id; $data['credit'] = $result->getCredit(); $data['uid'] = $this->thisController->user->id; $insert_result = self::$service->insertCommon($data, 'Order'); if ($insert_result === true) { //减去相应的积分 $update_data = ['credit' => (int) ($this->thisController->user->getCredit() - $result->getCredit())]; self::$service->updateCommon($update_data, $this->thisController->user); //写入积分日志 $insert_data = ['uid' => $this->thisController->user->id, 'val' => -$result->getCredit(), 'type' => 1, 'content' => '兑换积分商品【' . $result->getName() . '】', 'send_uid' => 0, 'classes_id' => $this->thisController->user->type == 1 ? $this->thisController->user->getClassesId() : 0]; self::$service->insertCommon($insert_data, 'UserCreditLog'); } return $this->thisController->ajax($insert_result); } }
public function bookBuyAction() { if (!$this->thisController->id) { return $this->thisController->displayAjax(false, '参数有误'); } $book_info = self::$service->getBook($this->thisController->id); if (!$book_info) { return $this->thisController->displayAjax(false, '参数有误'); } if (IS_POST) { $form = BaseForm::getForm('BookOrderForm'); if (!$form->isValid($this->thisController->request->getPost())) { foreach ($form->getMessages() as $message) { return $this->thisController->displayAjax(false, $message->getMessage()); } } //写入数据 $data = $this->thisController->request->getPost(); $data['number'] = st_order_number(); $data['book_id'] = $this->thisController->id; if ($book_info->getPrice() <= 0) { $data['pay_status'] = 2; $data['status'] = 3; //已支付 } else { $data['pay_status'] = 1; $data['status'] = 4; //未支付 } $data['price'] = $book_info->getPrice(); $data['good_id'] = 0; $data['credit'] = 0; $data['uid'] = $this->thisController->user->id; $result = self::$service->insertCommon($data, 'Order'); return $this->thisController->ajax($result); } }