新增搜索商品库存字段返回

This commit is contained in:
wucongxing 2023-03-23 17:20:03 +08:00
parent 9dd6116f44
commit 983f4d8909
8 changed files with 106 additions and 10 deletions

View File

@ -205,8 +205,6 @@ class PatientFamilyController extends AbstractController
/**
* 获取家庭成员用药记录列表
* @return ResponseInterface
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function getFamilyProductRecord(): ResponseInterface
{

View File

@ -64,6 +64,33 @@ class UserPatientController extends AbstractController
return $this->response->json($data);
}
// public function
/**
* 获取购物车药品数据
* @return ResponseInterface
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function getShoppingCart(): ResponseInterface
{
$UserPatientService = new UserPatientService();
$data = $UserPatientService->getShoppingCart();
return $this->response->json($data);
}
/**
* 添加购物车药品数据
* @return ResponseInterface
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function addShoppingCart(): ResponseInterface
{
$request = $this->container->get(UserPatientRequest::class);
$request->scene('addShoppingCart')->validateResolved();
$UserPatientService = new UserPatientService();
$data = $UserPatientService->addShoppingCart();
return $this->response->json($data);
}
}

View File

@ -103,7 +103,10 @@ class Product extends Model
*/
public static function getSearchKeywordList(array $params = [],string $keyword = '',array $fields = ['*']): Collection|array
{
return self::when($keyword, function ($query, $keyword) {
return self::with([
'ProductPlatformAmount:amount_id,product_platform_id,stock'
])
->when($keyword, function ($query, $keyword) {
$query->where(function ($query) use ($keyword) {
$query->orwhere("product_name", 'like', '%' . $keyword . '%');
$query->orwhere("common_name", 'like', '%' . $keyword . '%');

View File

@ -13,6 +13,9 @@ class UserPatientRequest extends FormRequest
'getPatientCouponlist' => [ // 获取患者优惠卷列表
'user_coupon_status',
],
'addShoppingCart' => [ // 添加购物车药品数据
'product_id',
],
];
/**
@ -30,6 +33,7 @@ class UserPatientRequest extends FormRequest
{
return [
'user_coupon_status' => 'required|integer|min:0|max:2',
'product_id' => 'required',
];
}
@ -43,6 +47,7 @@ class UserPatientRequest extends FormRequest
'user_coupon_status.integer' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR),
'user_coupon_status.min' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR),
'user_coupon_status.max' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR),
'product_id.required' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR),
];
}
}

View File

@ -214,6 +214,7 @@ class BasicDataService extends BaseService
$fields = [
'product_id',
'product_platform_id',
'product_name',
'product_price',
'product_cover_img',
@ -237,6 +238,12 @@ class BasicDataService extends BaseService
$item['product_cover_img'] = addAliyunOssWebsite($item['product_cover_img']);
$item['product_name'] = $item['product_name'] . ' ' . $item['product_spec'];
$item['stock'] = 0;
if (!empty($item['ProductPlatformAmount'])){
$item['stock'] = $item['ProductPlatformAmount']['stock'];
}
unset($item['ProductPlatformAmount']);
}
return success($product->toArray());

View File

@ -397,6 +397,9 @@ class LoginService extends BaseService
$Jwt = new Jwt();
$token = $Jwt->encode($token_user_data);
// 登录成功,删除验证码
// $redis->del("login_code" . $phone);
// 组合返回数据
$data = array();
$data['token'] = $token;

View File

@ -6,11 +6,15 @@ use App\Constants\HttpEnumCode;
use App\Model\Coupon;
use App\Model\OrderInquiry;
use App\Model\PatientHistoryInquiry;
use App\Model\Product;
use App\Model\User;
use App\Model\UserCoupon;
use App\Model\UserPatient;
use App\Utils\Mask;
use Hyperf\DbConnection\Db;
use Hyperf\Redis\Redis;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
/**
* 患者
@ -197,6 +201,57 @@ class UserPatientService extends BaseService
return success();
}
/**
* 获取购物车药品数据
* @return array
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function getShoppingCart(): array
{
$user_info = $this->request->getAttribute("userInfo") ?? [];
$redis = $this->container->get(Redis::class);
$redis_key = "shopping_cart" . $user_info['client_user_id'];
$shopping_cart = $redis->get($redis_key);
if (empty($shopping_cart)){
// 购物车为空
return success();
}
$shopping_cart = json_decode($shopping_cart,true);
return success($shopping_cart);
}
/**
* 添加购物车药品数据
* @return array
*/
public function addShoppingCart(): array
{
$user_info = $this->request->getAttribute("userInfo") ?? [];
$product_id = $this->request->route('product_id');
// $redis = $this->container->get(Redis::class);
// 验证商品数据
$params =array();
$params['product_id'] = $product_id;
$product = Product::getOne($params);
if (empty($product)){
return fail();
}
// 获取商品库存
return success();
}
/**
* 获取用户可领取优惠卷
* @param string|int $user_id

View File

@ -310,17 +310,15 @@ Router::addGroup('/patient', function () {
Router::addGroup('/product', function () {
// 购物车
Router::addGroup('/shopping', function () {
// 获取购物车
Router::get('/cart', [UserPatientController::class, 'addShoppingCart']);
// 获取购物车药品数据
Router::get('/cart', [UserPatientController::class, 'getShoppingCart']);
// 添加购物车
// 添加购物车药品数据
Router::post('/cart', [UserPatientController::class, 'addShoppingCart']);
// 修改购物车
// 修改购物车药品数据
Router::put('/cart', [UserPatientController::class, 'putShoppingCart']);
});
});
// 订单