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.

113 lines
3.8 KiB

5 years ago
5 years ago
5 years ago
5 years ago
  1. <?php
  2. namespace App\Service;
  3. use App\Model\Order;
  4. use App\Model\OrderGoods;
  5. use App\Model\OrderMain;
  6. use Hyperf\Di\Annotation\Inject;
  7. use Hyperf\DbConnection\Db;
  8. use App\Model\Goods;
  9. use App\Model\Combination;
  10. use App\Model\ShopCar;
  11. use App\Constants\LogLabel;
  12. use App\Commons\Log;
  13. use Hyperf\Utils\ApplicationContext;
  14. use App\TaskWorker\SSDBTask;
  15. use App\Constants\SsdbKeysPrefix;
  16. class PurchaseLimitService implements PurchaseLimitServiceInterface
  17. {
  18. public function getStoreIdByMarketId($params)
  19. {
  20. $res[] = [
  21. 'id' => 7,
  22. 'item' => 1,
  23. 'item_text' => 'page',
  24. 'logo' => 'http://lanzutest.lanzulive.com/attachment/images/2/2020/08/PY55Y3Mz17yJo17rv1Z7vImX1V5159.jpg',
  25. 'redirect_url' => '/zh_cjdianc/pages/takeout/takeoutindex?storeid=123',
  26. 'src' => '/zh_cjdianc/pages/takeout/takeoutindex?storeid=123',
  27. 'src2' => '/zh_cjdianc/pages/takeout/takeoutindex?storeid=123',
  28. ];
  29. $res[] = [
  30. 'id' => 8,
  31. 'item' => 1,
  32. 'item_text' => 'page',
  33. 'logo' => 'http://lanzutest.lanzulive.com/attachment/images/2/2020/08/PY55Y3Mz17yJo17rv1Z7vImX1V5159.jpg',
  34. 'redirect_url' => '/zh_cjdianc/pages/takeout/takeoutindex?storeid=109',
  35. 'src' => '/zh_cjdianc/pages/takeout/takeoutindex?storeid=109',
  36. 'src2' => '/zh_cjdianc/pages/takeout/takeoutindex?storeid=109',
  37. ];
  38. return $res;
  39. }
  40. public function ssdbPurchaseRecord($data,$user_id,$global_order_id)
  41. {
  42. foreach ($data as $k => $v){
  43. if($v['money'] == 0.01){
  44. //添加特价商品购买记录到ssdb
  45. $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
  46. $ssdb->exec('set', SsdbKeysPrefix::PURCHASE_RECORD. date('Ymd') .'_'.$user_id.'_'.$v['good_id'], $global_order_id);
  47. $end_timestamp = strtotime(date('Y-m-d').'23:59:59');
  48. $end_time = $end_timestamp - time();
  49. $ssdb->exec('expire', SsdbKeysPrefix::PURCHASE_RECORD. date('Ymd') .'_'.$user_id.'_'.$v['good_id'],$end_time);
  50. }
  51. }
  52. return true;
  53. }
  54. public function delSsdbPurchaseRecord($global_order_id)
  55. {
  56. $order_main = OrderMain::where('global_order_id',$global_order_id)
  57. ->select('id','user_id')
  58. ->first();
  59. $order_id = $order_main->id;
  60. $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
  61. $order = Order::query()
  62. ->where('order_main_id',$order_id)
  63. ->select('id','user_id')
  64. ->get()
  65. ->toArray();
  66. foreach ($order as $k1 => $v1){
  67. $goods = OrderGoods::query()
  68. ->where([
  69. ['order_id','=',$v1['id']],
  70. ['money','=',0.01],
  71. ])
  72. ->select('good_id')
  73. ->get()
  74. ->toArray();
  75. foreach ($goods as $k2 => $v2) {
  76. $ssdb->exec('del', SsdbKeysPrefix::PURCHASE_RECORD. date('Ymd') .'_'.$v1['user_id'].'_'.$v2['good_id']);
  77. }
  78. }
  79. return true;
  80. }
  81. public function PurchaseLimit($orderGoods)
  82. {
  83. $sum = 0;
  84. foreach ($orderGoods as $goods){
  85. if($goods['money'] == 0.01){
  86. if($sum > 0){
  87. return false;
  88. }
  89. $sum++;
  90. }
  91. }
  92. return true;
  93. }
  94. public function test($params)
  95. {
  96. $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
  97. //添加领取记录到ssdb
  98. $data = [
  99. '620',1561,
  100. ];
  101. $test = $ssdb->exec('multi_hset', SsdbKeysPrefix::PURCHASE_RECORD. date('Ymd') .'_620', $data);
  102. return $test;
  103. }
  104. }