/**
* 开启并发锁
* @param $orderId
* @create_time:2020/12/24 0024 10:50
* @return RestResponse
*/
function doBeforeTransaction($orderId){
$accountId = Yii::app()->user->getAccountId();
if(is_array($orderId)){
$orderMd5 = md5(implode(',',$orderId));
}else{
$orderMd5 = md5($orderId);
}
$redisKey = 'plm:lock:production_order:' . $orderMd5 . '_' . $accountId;
if (Yii::app()->redis->get($redisKey)) {
return new RestResponse(ErrorCode::UNKNOWN_ERROR, '此工单正在操作中,请勿重复操作');
} else {
Yii::app()->redis->set($redisKey, 1);
$time = 20;
$now = time();
Yii::app()->redis->expireAt($redisKey, $now + $time);
}
return new RestResponse();
}
/**
* 关闭并发锁
* @param $orderId
* @create_time:2020/12/24 0024 10:50
* @return RestResponse
*/
function doAfterTransaction($orderId){
$accountId = Yii::app()->user->getAccountId();
if(is_array($orderId)){
$orderMd5 = md5(implode(',',$orderId));
}else{
$orderMd5 = md5($orderId);
}
$redisKey = 'plm:lock:production_order:' . $orderMd5 . '_' . $accountId;
Yii::app()->redis->del($redisKey);
return new RestResponse();
}