You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.3 KiB

6 years ago
  1. <?php
  2. namespace App\Service\v3\Implementations;
  3. use App\Model\v3\ShoppingCart;
  4. use App\Model\v3\Store;
  5. use App\Service\v3\Interfaces\ShopCartServiceInterface;
  6. use Hyperf\DbConnection\Db;
  7. class ShopCartService implements ShopCartServiceInterface
  8. {
  9. public function do()
  10. {
  11. $storeIds = Db::table('lanzu_shopping_cart')->where('user_id',15)->pluck('store_id')->toArray();
  12. $res = Store::query()->with(['ShoppingCart' => function($query) {
  13. $query->with('goods');
  14. }])->whereIn('id',$storeIds)
  15. ->get();
  16. foreach ($res as &$k){
  17. $k->subtotal = '99.90';
  18. }
  19. return $res;
  20. }
  21. public function check($goodsId)
  22. {
  23. return mt_rand(0,6);
  24. }
  25. public function undo()
  26. {
  27. $storeIds = Db::table('lanzu_shopping_cart')->where('user_id',198)->pluck('store_id')->toArray();
  28. $res = Store::query()->with(['ShoppingCart' => function($query) {
  29. $query->with('goods');
  30. }])->whereIn('id',$storeIds)
  31. ->get();
  32. foreach ($res as &$k){
  33. $k->subtotal = '99.90';
  34. }
  35. return $res;
  36. }
  37. public function countGoods()
  38. {
  39. return mt_rand(1,100);
  40. }
  41. public function getTotal()
  42. {
  43. $randomFloat = rand(100,999)/100;
  44. return $randomFloat;
  45. }
  46. }