public function post() { try { /*$requestBody = $app->request->getBody(); $requestJson = json_decode($requestBody, true);*/ $requestJson = RequestBodyHandler::getJsonBody($this->_app); RequestBodyHandler::verifyJsonBody($requestJson, array("ProductId", "Comment", "ConsumerId")); $obj = R::dispense('productcomment'); $obj->productid = $requestJson->ProductId; $obj->comment = $requestJson->Comment; $obj->consumerid = $requestJson->ConsumerId; $obj->lastmodifiedtime = now(); $id = R::store($obj); $response = R::find('productcomment', 'id=?', array($id)); echo ResponseJsonHandler::normalizeJsonResponse(R::exportAll($response)); //sendSuccess(json_encode(R::exportAll($obj)), 201); } catch (Exception $ex) { return ExceptionHandler::Response($ex, $this->_app); } }
public function get_ProducerConsumer($ProducerId) { try { /*$requestBody = $this->_app->request->getBody(); $requestBody = DecodeBody($requestBody); $requestJson = json_decode($requestBody);*/ $requestJson = RequestBodyHandler::getJsonBody($this->_app); $records = R::getAll("SELECT a.id AS contactid, a.consumerid, a.lastmodifiedtime AS contacttime, b.displayname, b.smallportraiturl, b.province, b.city, b.address, b.telephone " . "FROM producercontactconsumer a " . "JOIN consumer b ON a.consumerid = b.id " . "WHERE producerid = ?", [$ProducerId]); if (!isset($records) || empty($records)) { throw new RecordNotFoundException("Record not found, id:" . $ProducerId); } $Count = count($records); $List = array(); foreach ($records as $record) { $OrderInfo = R::getRow('SELECT a.id AS orderid, a.productid, a.count, a.status, a.lastmodifiedtime AS ordertime, b.name AS productname, b.type, b.price, b.originalprice, b.unit, b.freight FROM orders a JOIN product b ON a.productid = b.id WHERE a.consumerid=? ORDER BY a.id DESC LIMIT 5', array($record['consumerid'])); $List[] = array('ContactInfo' => $record, 'OrderInfo' => array($OrderInfo)); //$List[] = array('ContactId' => $record['id'], 'ConsumerId' => $record['consumerid'], 'Time' => $record['lastmodifiedtime']); } sendSuccess(array('Count' => $Count, 'List' => $List)); } catch (Exception $ex) { return ExceptionHandler::Response($ex, $this->_app); } }
public function put_BasicInfo($ProductId) { try { $requestJson = RequestBodyHandler::getJsonBody($this->_app); RequestBodyHandler::verifyJsonBody($requestJson, array("Name", "Description", "Type", "Price", "OriginalPrice", "Unit", "Freight")); $product = R::findOne('product', 'id=?', array($ProductId)); if (!isset($product) || empty($product)) { throw new RecordNotFoundException("Record not found, id:" . $ProductId); } $product->name = $requestJson->Name; $product->description = $requestJson->Description; $product->type = $requestJson->Type; $product->price = $requestJson->Price; $product->originalprice = $requestJson->OriginalPrice; $product->unit = $requestJson->Unit; $product->freight = $requestJson->Freight; $product->lastmodifiedtime = now(); R::store($product); $response = R::find('product', 'id=?', array($ProductId)); echo ResponseJsonHandler::normalizeJsonResponse(R::exportAll($response)); } catch (Exception $ex) { return ExceptionHandler::Response($ex, $this->_app); } }
public function postSmsCode() { try { $requestJson = RequestBodyHandler::getJsonBody($this->_app); RequestBodyHandler::verifyJsonBody($requestJson, array("Telephone")); $randomCode = rand(1000, 9999); $expireInMins = "1"; $tempId = "46556"; //发送短信验证码 $reponseArray = SMS::SendTemplateSMS($requestJson->Telephone, array($randomCode, $expireInMins), $tempId); $rdb = R::dispense('producersmscode'); $rdb->telephone = $requestJson->Telephone; $rdb->code = $randomCode; $rdb->expirationtime = date('Y-m-d H:i:s', strtotime("+1 minute")); $rdb->statuscode = $reponseArray[0]; $rdb->smsmessagesid = $reponseArray[1]; $rdb->datecreated = $reponseArray[2]; $rdb->lastmodifiedtime = now(); $id = R::store($rdb); echo ResponseJsonHandler::normalizeJsonResponse(array("id" => $id, "smsCode" => $randomCode, "telephone" => $requestJson->Telephone)); } catch (Exception $ex) { return ExceptionHandler::Response($ex, $this->_app); } }
public function put_Consignee($ConsigneeId) { try { $requestJson = RequestBodyHandler::getJsonBody($this->_app); RequestBodyHandler::verifyJsonBody($requestJson, array("Name", "Telephone", "Address", "IsDefault")); $obj = R::findOne('consignee', 'id=?', array($ConsigneeId)); if (!isset($obj) || empty($obj)) { throw new RecordNotFoundException("Record not found, id:" . $ConsigneeId); } $obj->name = $requestJson->Name; $obj->telephone = $requestJson->Telephone; $obj->address = $requestJson->Address; $obj->isdefault = $requestJson->IsDefault; $obj->lastmodifiedtime = now(); $id = R::store($obj); if ($requestJson->IsDefault == "true") { R::exec('UPDATE consignee SET isdefault = "false" WHERE id <> ?', array($id)); } $response = R::find('consignee', 'id=?', array($id)); echo ResponseJsonHandler::normalizeJsonResponse(R::exportAll($response)); /* $order = R::findOne('orders', 'id=?', array($OrderId)); if (!isset($order) || empty($order)) { throw new RecordNotFoundException("Record not found, id:" . $OrderId); } $order->count = $requestJson->Count; $order->unit = $requestJson->Unit; $order->description = $requestJson->Description; $order->lastmodifiedtime = now(); R::store($order); $response = R::find('orders', 'id=?', array($OrderId)); //echo json_encode(R::exportAll($response)); echo ResponseJsonHandler::normalizeJsonResponse(R::exportAll($response)); */ } catch (Exception $ex) { return ExceptionHandler::Response($ex, $this->_app); } }