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.
 
 

91 lines
3.1 KiB

<?php
namespace App\Service;
use App\Model\Order;
use App\Model\OrderGoods;
use App\Model\OrderMain;
use Hyperf\Di\Annotation\Inject;
use Hyperf\DbConnection\Db;
use App\Model\Goods;
use App\Model\Combination;
use App\Model\ShopCar;
use App\Constants\LogLabel;
use App\Commons\Log;
use Hyperf\Utils\ApplicationContext;
use App\TaskWorker\SSDBTask;
use App\Constants\SsdbKeysPrefix;
class PurchaseLimitService implements PurchaseLimitServiceInterface
{
public function getStoreIdByMarketId($params)
{
$res = [
'id' => 7,
'item' => 1,
'item_text' => 'page',
'logo' => 'http://lanzutest.lanzulive.com/attachment/images/2/2020/08/PY55Y3Mz17yJo17rv1Z7vImX1V5159.jpg',
'redirect_url' => '/zh_cjdianc/pages/takeout/takeoutindex?storeid=123',
'src' => '/zh_cjdianc/pages/takeout/takeoutindex?storeid=123',
'src2' => '/zh_cjdianc/pages/takeout/takeoutindex?storeid=123',
];
return $res;
}
public function ssdbPurchaseRecord($data,$user_id,$global_order_id)
{
foreach ($data as $k => $v){
if($v['money'] == 0.01){
//添加特价商品购买记录到ssdb
$ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
$ssdb->exec('set', SsdbKeysPrefix::PURCHASE_RECORD. date('Ymd') .'_'.$user_id.'_'.$v['good_id'], $global_order_id);
$end_timestamp = strtotime(date('Y-m-d').'23:59:59');
$end_time = $end_timestamp - time();
$ssdb->exec('expire', SsdbKeysPrefix::PURCHASE_RECORD. date('Ymd') .'_'.$user_id.'_'.$v['good_id'],$end_time);
}
}
return true;
}
public function delSsdbPurchaseRecord($global_order_id)
{
$order_main = OrderMain::where('global_order_id',$global_order_id)
->select('id','user_id')
->first();
$order_id = $order_main->id;
$ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
$order = Order::query()
->where('order_main_id',$order_id)
->select('id','user_id')
->get()
->toArray();
foreach ($order as $k1 => $v1){
$goods = OrderGoods::query()
->where([
['order_id','=',$v1['id']],
['money','=',0.01],
])
->select('good_id')
->get()
->toArray();
foreach ($goods as $k2 => $v2) {
$ssdb->exec('del', SsdbKeysPrefix::PURCHASE_RECORD. date('Ymd') .'_'.$v1['user_id'].'_'.$v2['good_id']);
var_dump($v1['user_id']);
var_dump($v1['good_id']);
}
}
return true;
}
public function test($params)
{
$ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
//添加领取记录到ssdb
$data = [
'620',1561,
];
$test = $ssdb->exec('multi_hset', SsdbKeysPrefix::PURCHASE_RECORD. date('Ymd') .'_620', $data);
return $test;
}
}