软路由产品
This commit is contained in:
48
app/ros/controller/Buyer.php
Normal file
48
app/ros/controller/Buyer.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace app\ros\controller;
|
||||
|
||||
use app\ros\model\Product as ProductModel;
|
||||
use app\ros\model\Buyer as BuyerModel;
|
||||
use fastphp\base\Controller;
|
||||
|
||||
class Buyer extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct('','');
|
||||
if (empty($this->userinfo['UserId'])) {
|
||||
die;
|
||||
}
|
||||
}
|
||||
|
||||
//获取产品列表
|
||||
public function getBuyerInfo() {
|
||||
$buyer_model = new BuyerModel();
|
||||
|
||||
$info = $buyer_model->getOne(['user_id'=>$this->userinfo['UserId']]);
|
||||
echo json_encode($info);
|
||||
}
|
||||
|
||||
public function updateBuyerInfo() {
|
||||
$userinfo = json_decode(file_get_contents("php://input"),true)['user_info'];
|
||||
$userinfo['user_id'] = $this->userinfo['UserId'];
|
||||
|
||||
if (empty($userinfo['name']) || empty($userinfo['phone']) || empty($userinfo['address'])) {
|
||||
echo json_encode(['code' => -1]);
|
||||
die;
|
||||
}
|
||||
|
||||
$buyer_model = new BuyerModel();
|
||||
|
||||
$info = $buyer_model->getOne(['user_id'=>$this->userinfo['UserId']]);
|
||||
|
||||
$flag = false;
|
||||
if (empty($info)) {
|
||||
$flag = $buyer_model->add($userinfo);
|
||||
} else {
|
||||
$flag = $buyer_model->updateOne(['user_id'=>$this->userinfo['UserId']],$userinfo);
|
||||
}
|
||||
echo json_encode(['code' => 1]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user