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.

67 lines
1.8 KiB

5 years ago
5 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. foreach ($k->ShoppingCart as &$v){
  35. switch (mt_rand(1,3)) {
  36. case 1:
  37. $str = '已下架';
  38. break;
  39. case 2:
  40. $str = '已抢光';
  41. break;
  42. case 3:
  43. $str = '已打烊';
  44. break;
  45. }
  46. $v['goods']['invalid_cause'] = $str;
  47. }
  48. }
  49. return $res;
  50. }
  51. public function countGoods()
  52. {
  53. return mt_rand(1,100);
  54. }
  55. public function getTotal()
  56. {
  57. $randomFloat = rand(100,999)/100;
  58. return $randomFloat;
  59. }
  60. }