物品扫码领用与库存
This commit is contained in:
@@ -40,8 +40,8 @@ class InvItemController extends BaseController
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
protected function indexFormat($data)
|
||||
{
|
||||
protected function indexFormat($data)
|
||||
{
|
||||
if (isset($data['created_at']))
|
||||
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
||||
if (isset($data['updated_at']))
|
||||
@@ -52,4 +52,82 @@ class InvItemController extends BaseController
|
||||
$data['manage_user_name'] = User::where('id', $data['manage_user_id'])->value('name');
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成物品二维码
|
||||
*
|
||||
* @param Request $request
|
||||
* @return mixed
|
||||
*/
|
||||
public function generateQrCode(Request $request)
|
||||
{
|
||||
try {
|
||||
$id = $request->post('id');
|
||||
if (!$id) {
|
||||
return $this->error('物品ID不能为空');
|
||||
}
|
||||
|
||||
$item = \app\common\model\InvItem::find($id);
|
||||
if (!$item) {
|
||||
return $this->error('物品不存在');
|
||||
}
|
||||
|
||||
// 获取应用访问地址
|
||||
$appUrl = config('app.app_url', 'http://127.0.0.1:25616');
|
||||
|
||||
$qrCodeService = new \app\common\service\QrCodeService();
|
||||
$content = $qrCodeService->generateItemQrCode($id, $appUrl);
|
||||
$fileName = 'qr_item_' . $id . '_' . time() . '.png';
|
||||
|
||||
$result = $qrCodeService->generateAndUploadQrCode($id, $content, $fileName);
|
||||
|
||||
// 更新物品记录
|
||||
$item->qr_code = $result['path'];
|
||||
$item->qr_code_url = $result['url'];
|
||||
$item->save();
|
||||
|
||||
return $this->success([
|
||||
'qr_code_url' => $result['url'],
|
||||
'content' => $content,
|
||||
], '二维码生成成功');
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除物品二维码
|
||||
*
|
||||
* @param Request $request
|
||||
* @return mixed
|
||||
*/
|
||||
public function deleteQrCode(Request $request)
|
||||
{
|
||||
try {
|
||||
$id = $request->post('id');
|
||||
if (!$id) {
|
||||
return $this->error('物品ID不能为空');
|
||||
}
|
||||
|
||||
$item = \app\common\model\InvItem::find($id);
|
||||
if (!$item) {
|
||||
return $this->error('物品不存在');
|
||||
}
|
||||
|
||||
// 删除 OSS 文件
|
||||
if ($item->qr_code) {
|
||||
$qrCodeService = new \app\common\service\QrCodeService();
|
||||
$qrCodeService->deleteQrCode($item->qr_code);
|
||||
}
|
||||
|
||||
// 清空物品记录中的二维码字段
|
||||
$item->qr_code = null;
|
||||
$item->qr_code_url = null;
|
||||
$item->save();
|
||||
|
||||
return $this->success([], '二维码删除成功');
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user