問題說明:配送員送貨掃核銷碼提示沒有核銷權限,目前好像必須是店員+配送員身份才能核銷,既然配送員是單獨添加的,那配送員就應該單獨設置核銷權限開關,要不配送給消費者就沒辦法顯示送達。
修改文件:app/services/order/store/WriteOffOrderServices.php
修改方法:checkWriteoffAuth()
public function checkWriteoffAuth(int $id, int $oid, string $userType = 'user', string $orderType = 'order', $orderInfo = [])
{
if (!$id && !$oid) {
throw new ValidateException('核銷單不存在');
}
if (!$orderInfo) {
switch ($orderType) {
case 'order'://訂單
$orderInfo = $this->dao->getOne(['id' => $oid, 'is_del' => 0], '*', ['user', 'pink']);
break;
case 'reservation'://預約單
/** @var StoreReservationOrderServices $reservationOrderService */
$reservationOrderService = app()->make(StoreReservationOrderServices::class);
$orderInfo = $reservationOrderService->getReservationOrderInfo(0, (int)$id);
break;
}
}
if (!$orderInfo) {
throw new ValidateException('核銷單不存在');
}
$storeId = $orderInfo['store_id'] ?? 0;
$isAuth = false;
$auth = 0;
try {
switch ($userType) {
case 'admin'://超級管理員
$isAuth = true;
break;
case 'kefu'://平臺客服
/** @var StoreServiceServices $storeService */
$storeService = app()->make(StoreServiceServices::class);
$userService = $storeService->checkoutIsService(['uid' => $id, 'status' => 1, 'account_status' => 1, 'customer' => 1]);
if ($userService) {//平臺客服
$isAuth = true;
$auth = 1;
}
break;
case 'user'://移動端用戶
/** @var StoreServiceServices $storeService */
$storeService = app()->make(StoreServiceServices::class);
$userService = $storeService->checkoutIsService(['uid' => $id, 'status' => 1, 'account_status' => 1, 'customer' => 1]);
if ($userService) {//平臺客服
$isAuth = true;
$auth = 1;
} else {
try {
/** @var SystemStoreStaffServices $storeStaffServices */
$storeStaffServices = app()->make(SystemStoreStaffServices::class);
$staff = $storeStaffServices->getStaffInfoByUid($id);
} catch (\Throwable $e){
$staff = [];
}
//店員存在 && 開啟核銷權限 && 訂單是前端門店的
if ($staff && $staff['verify_status'] == 1 && $staff['store_id'] == $storeId) {
$isAuth = true;
$auth = 4;
} else {//配送員
/** @var DeliveryServiceServices $deliverServiceServices */
$deliverServiceServices = app()->make(DeliveryServiceServices::class);
$deliver = $deliverServiceServices->getDeliveryInfoByUid($id);
if (in_array($orderInfo['shipping_type'], [1, 3]) && $deliver && $orderInfo['delivery_type'] == 'send' && $orderInfo['delivery_uid'] == $id) {
$isAuth = true;
$auth = 2;
}
}
}
break;
case 'store'://門店核銷
case 'cashier'://收銀員
if ($id) {//傳入id 就驗證店員權限,不傳默認門店后臺管理員操作
//驗證店員
/** @var SystemStoreStaffServices $storeStaffServices */
$storeStaffServices = app()->make(SystemStoreStaffServices::class);
$info = $storeStaffServices->getStaffInfo($id);
//店員存在 && 開啟核銷權限 && 訂單是前端門店的
if ($info && $info['verify_status'] == 1 && $info['store_id'] == $storeId) {
$isAuth = true;
}
} else {
$isAuth = true;
}
$auth = 4;
break;
}
} catch (\Throwable $e) {
}
if (!$isAuth) {
throw new ValidateException('您無權限核銷此訂單,請聯系管理員');
}
return $auth;
}
修改文件:app/services/order/store/WriteOffOrderServices.php
修改方法:checkUserAuth()
public function checkUserAuth(int $uid)
{
$auth = [];
$store_id = 0;
/** @var StoreServiceServices $storeService */
$storeService = app()->make(StoreServiceServices::class);
$userService = $storeService->checkoutIsService(['uid' => $uid, 'status' => 1, 'account_status' => 1, 'customer' => 1]);
if ($userService) {
$auth[] = 1;
}
try {
/** @var DeliveryServiceServices $deliverServiceServices */
$deliverServiceServices = app()->make(DeliveryServiceServices::class);
$info = $deliverServiceServices->getDeliveryInfoByUid($uid);
if ($info) {
$auth[] = 2;
}
} catch (\Throwable $e) {
}
try {
/** @var SystemStoreStaffServices $storeStaffServices */
$storeStaffServices = app()->make(SystemStoreStaffServices::class);
$info = $storeStaffServices->getStaffInfoByUid($uid);
if ($info && $info['verify_status'] == 1) {
$auth[] = 4;
$store_id = $info['store_id'];
}
} catch (\Throwable $e) {
}
return [$auth, $store_id];
}