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.

88 lines
3.0 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. return $res;
  30. }
  31. public function ssdbPurchaseRecord($data,$user_id,$global_order_id)
  32. {
  33. foreach ($data as $k => $v){
  34. if($v['money'] == 0.01){
  35. //添加特价商品购买记录到ssdb
  36. $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
  37. $ssdb->exec('set', SsdbKeysPrefix::PURCHASE_RECORD. date('Ymd') .'_'.$user_id.'_'.$v['good_id'], $global_order_id);
  38. $end_timestamp = strtotime(date('Y-m-d').'23:59:59');
  39. $end_time = $end_timestamp - time();
  40. $ssdb->exec('expire', SsdbKeysPrefix::PURCHASE_RECORD. date('Ymd') .'_'.$user_id.'_'.$v['good_id'],$end_time);
  41. }
  42. }
  43. return true;
  44. }
  45. public function delSsdbPurchaseRecord($global_order_id)
  46. {
  47. $order_main = OrderMain::where('global_order_id',$global_order_id)
  48. ->select('id','user_id')
  49. ->first();
  50. $order_id = $order_main->id;
  51. $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
  52. $order = Order::query()
  53. ->where('order_main_id',$order_id)
  54. ->select('id','user_id')
  55. ->get()
  56. ->toArray();
  57. foreach ($order as $k1 => $v1){
  58. $goods = OrderGoods::query()
  59. ->where([
  60. ['order_id','=',$v1['id']],
  61. ['money','=',0.01],
  62. ])
  63. ->select('good_id')
  64. ->get()
  65. ->toArray();
  66. foreach ($goods as $k2 => $v2) {
  67. $ssdb->exec('del', SsdbKeysPrefix::PURCHASE_RECORD. date('Ymd') .'_'.$v1['user_id'].'_'.$v2['good_id']);
  68. }
  69. }
  70. return true;
  71. }
  72. public function test($params)
  73. {
  74. $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
  75. //添加领取记录到ssdb
  76. $data = [
  77. '620',1561,
  78. ];
  79. $test = $ssdb->exec('multi_hset', SsdbKeysPrefix::PURCHASE_RECORD. date('Ymd') .'_620', $data);
  80. return $test;
  81. }
  82. }