diff --git a/app/Controller/PatientFamilyController.php b/app/Controller/PatientFamilyController.php index a1c150c..d67db0b 100644 --- a/app/Controller/PatientFamilyController.php +++ b/app/Controller/PatientFamilyController.php @@ -205,8 +205,6 @@ class PatientFamilyController extends AbstractController /** * 获取家庭成员用药记录列表 * @return ResponseInterface - * @throws ContainerExceptionInterface - * @throws NotFoundExceptionInterface */ public function getFamilyProductRecord(): ResponseInterface { diff --git a/app/Controller/UserPatientController.php b/app/Controller/UserPatientController.php index daf4714..3ed2f2a 100644 --- a/app/Controller/UserPatientController.php +++ b/app/Controller/UserPatientController.php @@ -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); + } } \ No newline at end of file diff --git a/app/Model/Product.php b/app/Model/Product.php index c377f4f..da9132e 100644 --- a/app/Model/Product.php +++ b/app/Model/Product.php @@ -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 . '%'); diff --git a/app/Request/UserPatientRequest.php b/app/Request/UserPatientRequest.php index 577ce38..07095d3 100644 --- a/app/Request/UserPatientRequest.php +++ b/app/Request/UserPatientRequest.php @@ -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), ]; } } diff --git a/app/Services/BasicDataService.php b/app/Services/BasicDataService.php index 8222681..cf371de 100644 --- a/app/Services/BasicDataService.php +++ b/app/Services/BasicDataService.php @@ -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()); diff --git a/app/Services/LoginService.php b/app/Services/LoginService.php index 1987458..30d1256 100644 --- a/app/Services/LoginService.php +++ b/app/Services/LoginService.php @@ -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; diff --git a/app/Services/UserPatientService.php b/app/Services/UserPatientService.php index 93d9ebf..5e0bd27 100644 --- a/app/Services/UserPatientService.php +++ b/app/Services/UserPatientService.php @@ -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 diff --git a/config/routes.php b/config/routes.php index 233b92d..6bba77d 100644 --- a/config/routes.php +++ b/config/routes.php @@ -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']); }); - - }); // 订单