问题说明:微信扫核销码权限判断处理
修改文件:app\controller\api\admin\order\StoreOrder
修改方法:order_verific()
public function order_verific(Request $request, WriteOffOrderServices $writeOffOrderServices, StoreOrderCartInfoServices $orderCartInfo, StoreOrderServices $orderServices)
{
[$code, $auth] = $request->postMore([
['code', ''],
['auth', 0],
], true);
if (!$code) return app('json')->fail('Lack of write-off code');
$uid = $request->uid();
/** @var StoreServiceServices $storeService */
$storeService = app()->make(StoreServiceServices::class);
$userService = $storeService->checkoutIsService(['uid' => $uid, 'status' => 1, 'account_status' => 1]); //客服权限是否存在
if ($auth == 1 && !$userService) return app('json')->fail('您没有客服权限!');
/** @var DeliveryServiceServices $deliveryService */
$deliveryService = app()->make(DeliveryServiceServices::class);
$deliveryUser = $deliveryService->checkoutIsService($uid); // 检查用户是否是配送员
if ($auth == 2 && !$deliveryUser) return app('json')->fail('您不是配送员!');
//验证店员
/** @var SystemStoreStaffServices $storeStaffServices */
$storeStaffServices = app()->make(SystemStoreStaffServices::class);
$where = ['uid' => $uid, 'is_del' => 0, 'status' => 1, 'verify_status' => 1];
$info = $storeStaffServices->getOne($where);
if($auth == 4 && !$info) return app('json')->fail('您不是店员!');
if ($auth == 3) {
if ($userService) {
$auth = 1;
} else if ($info) {
$auth = 4;
} else if ($deliveryUser) {
$auth = 2;
} else {
return app('json')->fail('您没有任何权限!');
}
}
/** @var UserServices $userServices */
$userServices = app()->make(UserServices::class);
$userInfo = $userServices->getOne(['bar_code' => $code]);
if ($userInfo) {
$userInfo = $userInfo->toArray();
$is_order_code = 0;
} else {
$orderInfo = $orderServices->getOne(['verify_code' => $code, 'is_del' => 0]);
if ($orderInfo) {
$is_order_code = 1;
} else {
return app('json')->fail('暂未获取到订单信息,请先确认传入的码是否正确');
}
}
$product_type = 0;
if ($is_order_code == 1) {
$orderInfo = $writeOffOrderServices->writeoffOrderInfo($uid, $code, $auth);
if ($orderInfo && isset($orderInfo['product_type'])) {
$product_type = $orderInfo['product_type'];
}
$data = [$orderInfo];
} else {
$data = $writeOffOrderServices->userUnWriteoffOrder($uid, $code, $auth);
if (count($data) == 1) {
$is_order_code = 1;
$orderInfo = $data[0];
if ($orderInfo && isset($orderInfo['product_type'])) {
$product_type = $orderInfo['product_type'];
}
}
}
$res = [];
if ($data) {
/** @var StoreOrderServices $orderServices */
$orderServices = app()->make(StoreOrderServices::class);
$res = $orderServices->tidyOrderList($data, false);
foreach ($res as &$orderInfo) {
$orderInfo['image'] = '';
if (isset($orderInfo['cart_id'][0])) {
$cartInfo = $orderCartInfo->getOne(['oid' => $orderInfo['id'], 'cart_id' => $orderInfo['cart_id'][0]], 'cart_info');
if ($cartInfo) $orderInfo['image'] = $cartInfo['cart_info']['productInfo']['image'] ?? '';
}
}
}
return app('json')->success(['data' => $res, 'is_order_code' => $is_order_code, 'product_type' => $product_type, 'auth' => $auth]);
}
修改文件:app\controller\api\store\order\StoreOrder
修改方法:order_verific()
public function order_verific(Request $request, WriteOffOrderServices $writeOffOrderServices, StoreOrderCartInfoServices $orderCartInfo, StoreOrderServices $orderServices)
{
[$code, $auth] = $request->postMore([
['code', ''],
['auth', 0],
], true);
if (!$code) return app('json')->fail('Lack of write-off code');
$uid = $request->uid();
/** @var StoreServiceServices $storeService */
$storeService = app()->make(StoreServiceServices::class);
$userService = $storeService->checkoutIsService(['uid' => $uid, 'status' => 1, 'account_status' => 1]); //客服权限是否存在
if ($auth == 2 && !$userService) return app('json')->fail('您没有客服权限!');
/** @var DeliveryServiceServices $deliveryService */
$deliveryService = app()->make(DeliveryServiceServices::class);
$deliveryUser = $deliveryService->checkoutIsService($uid); // 检查用户是否是配送员
if ($auth == 2 && !$deliveryUser) return app('json')->fail('您不是配送员!');
//验证店员
/** @var SystemStoreStaffServices $storeStaffServices */
$storeStaffServices = app()->make(SystemStoreStaffServices::class);
$where = ['uid' => $uid, 'is_del' => 0, 'status' => 1, 'verify_status' => 1];
$info = $storeStaffServices->getOne($where);
if($auth == 4 && !$info) return app('json')->fail('您不是店员!');
if ($auth == 3) {
if ($userService) {
$auth = 1;
} else if ($info) {
$auth = 4;
} else if ($deliveryUser) {
$auth = 2;
} else {
return app('json')->fail('您没有任何权限!');
}
}
/** @var UserServices $userServices */
$userServices = app()->make(UserServices::class);
$userInfo = $userServices->getOne(['bar_code' => $code]);
if ($userInfo) {
$userInfo = $userInfo->toArray();
$is_order_code = 0;
} else {
$orderInfo = $orderServices->getOne(['verify_code' => $code, 'is_del' => 0]);
if ($orderInfo) {
$is_order_code = 1;
} else {
return app('json')->fail('暂未获取到订单信息,请先确认传入的码是否正确');
}
}
$product_type = 0;
if ($is_order_code == 1) {
$orderInfo = [];
try {
$orderInfo = $writeOffOrderServices->writeoffOrderInfo($uid, $code, $auth);
} catch (\Throwable $e) {
}
if ($orderInfo && isset($orderInfo['product_type'])) {
$product_type = $orderInfo['product_type'];
}
$data = [$orderInfo];
} else {
$data = [];
try {
$data = $writeOffOrderServices->userUnWriteoffOrder($uid, $code, $auth);
} catch (\Throwable $e) {
}
if (count($data) == 1) {
$is_order_code = 1;
$orderInfo = $data[0];
if ($orderInfo && isset($orderInfo['product_type'])) {
$product_type = $orderInfo['product_type'];
}
}
}
$res = [];
if ($data) {
/** @var StoreOrderServices $orderServices */
$orderServices = app()->make(StoreOrderServices::class);
$res = $orderServices->tidyOrderList($data, false);
foreach ($res as &$orderInfo) {
$orderInfo['image'] = '';
if (isset($orderInfo['cart_id'][0])) {
$cartInfo = $orderCartInfo->getOne(['oid' => $orderInfo['id'], 'cart_id' => $orderInfo['cart_id'][0]], 'cart_info');
if ($cartInfo) $orderInfo['image'] = $cartInfo['cart_info']['productInfo']['image'] ?? '';
}
}
}
return app('json')->success(['data' => $res, 'is_order_code' => $is_order_code, 'product_type' => $product_type, 'auth' => $auth]);
}
{{item.user_info.nickname ? item.user_info.nickname : item.user_name}}
作者 管理员 企业
{{itemf.name}}
{{itemc.user_info.nickname}}
{{itemc.user_name}}
回复 {{itemc.comment_user_info.nickname}}
{{itemf.name}}