数据写入成功,为什么还是提示失败
public function adduser() {
$salt = Random::build('alnum', 16);
$data = [
'avatar' => $this->request->post('image'),
'nickname' => $this->request->post('xm'),
'zjlx' => $this->request->post('zjlx'),
'zjh' => $this->request->post('zjhm'),
'mobile' => $this->request->post('mobile'),
'email' => $this->request->post('email'),
'sg' => $this->request->post('sg'),
'xjzd' => $this->request->post('xjd'),
'gender' => $this->request->post('sex'),
'birthday' => $this->request->post('csrq'),
'mz' => $this->request->post('mz'),
'zzmm' => $this->request->post('zzmm'),
'hyzk' => $this->request->post('hyzk'),
'jg' => $this->request->post('jg'),
'tz' => $this->request->post('tz'),
'username' => "jgh01sss" . time(),
'salt' => $salt,
'status' => "enable",
'group_id' => 1,
'money' => 0,
'score' => 0,
'password' => encrypt_password('123456', $salt)
];
Db::startTrans();
try {
// 插入数据到 user 表
$userId = Db::name('user')->insertGetId($data);
if (!$userId) {
throw new \Exception('插入 user 表失败');
}
$datadpt = [
'uid' => $userId,
'rzgw' => is_array($this->request->post('rzgw')) ? implode(',', $this->request->post('rzgw')) : $this->request->post('rzgw'),
'htsj' => is_array($this->request->post('htsj')) ? implode(',', $this->request->post('htsj')) : $this->request->post('htsj'),
'rzbm' => is_array($this->request->post('rzbm')) ? implode(',', $this->request->post('rzbm')) : $this->request->post('rzbm'),
'bzlx' => $this->request->post('bzlx'),
'rzsj' => $this->request->post('rzsj'),
'rzht' => $this->request->post('file')
];
// 插入数据到 hr_userdpt 表
$insertDptResult = Db::name('hr_userdpt')->insert($datadpt);
if (!$insertDptResult) {
throw new \Exception('插入 hr_userdpt 表失败');
}
// 提交事务
Db::commit();
$this->success('操作成功', null, 1);
} catch (\Exception $e) {
// 回滚事务
Db::rollback();
// 输出详细的错误信息
$this->error('操作失败', [
'message' => $e->getMessage(),
'file' => $e->getFile(),
'line' => $e->getLine(),
'trace' => $e->getTraceAsString()
]);
}
}
{
"code": 0,
"msg": "操作失败",
"time": 1723647396,
"data": {
"message": "",
"file": "D:\\web\\intelligent-integrated-system\\app\\common\\controller\\Api.php",
"line": 127,
"trace": "#0 D:\\web\\intelligent-integrated-system\\app\\common\\controller\\Api.php(82): app\\common\\controller\\Api->result('\\xE6\\x93\\x8D\\xE4\\xBD\\x9C\\xE6\\x88\\x90\\xE5\\x8A\\x9F', NULL, 200, 'json', Array, Array)\n#1 D:\\web\\intelligent-integrated-system\\app\\admin\\controller\\hr\\Adduser.php(89): app\\common\\controller\\Api->success('\\xE6\\x93\\x8D\\xE4\\xBD\\x9C\\xE6\\x88\\x90\\xE5\\x8A\\x9F', NULL, 1)\n#2 [internal function]: app\\admin\\controller\\hr\\Adduser->adduser()\n#3 D:\\web\\intelligent-integrated-system\\vendor\\topthink\\framework\\src\\think\\Container.php(345): ReflectionMethod->invokeArgs(Object(app\\admin\\controller\\hr\\Adduser), Array)\n#4 D:\\web\\intelligent-integrated-system\\vendor\\topthink\\framework\\src\\think\\route\\dispatch\\Controller.php(110): think\\Container->invokeReflectMethod(Object(app\\admin\\controller\\hr\\Adduser), Object(ReflectionMethod), Array)\n#5 D:\\web\\intelligent-integrated-system\\vendor\\topthink\\framework\\src\\think\\Pipeline.php(59): think\\route\\dispatch\\Controller->think\\route\\dispatch\\{closure}(Object(app\\Request))\n#6 D:\\web\\intelligent-integrated-system\\vendor\\topthink\\framework\\src\\think\\Pipeline.php(66): think\\Pipeline->think\\{closure}(Object(app\\Request))\n#7 D:\\web\\intelligent-integrated-system\\vendor\\topthink\\framework\\src\\think\\route\\dispatch\\Controller.php(84): think\\Pipeline->then(Object(Closure))\n#8 D:\\web\\intelligent-integrated-system\\vendor\\topthink\\framework\\src\\think\\route\\Dispatch.php(52): think\\route\\dispatch\\Controller->exec()\n#9 D:\\web\\intelligent-integrated-system\\vendor\\topthink\\framework\\src\\think\\Route.php(755): think\\route\\Dispatch->run()\n#10 D:\\web\\intelligent-integrated-system\\vendor\\topthink\\framework\\src\\think\\Pipeline.php(59): think\\Route->think\\{closure}(Object(app\\Request))\n#11 D:\\web\\intelligent-integrated-system\\vendor\\topthink\\framework\\src\\think\\Pipeline.php(66): think\\Pipeline->think\\{closure}(Object(app\\Request))\n#12 D:\\web\\intelligent-integrated-system\\vendor\\topthink\\framework\\src\\think\\Route.php(754): think\\Pipeline->then(Object(Closure))\n#13 D:\\web\\intelligent-integrated-system\\vendor\\topthink\\framework\\src\\think\\Http.php(208): think\\Route->dispatch(Object(app\\Request), Object(Closure))\n#14 D:\\web\\intelligent-integrated-system\\vendor\\topthink\\framework\\src\\think\\Http.php(198): think\\Http->dispatchToRoute(Object(app\\Request))\n#15 D:\\web\\intelligent-integrated-system\\vendor\\topthink\\framework\\src\\think\\Pipeline.php(59): think\\Http->think\\{closure}(Object(app\\Request))\n#16 D:\\web\\intelligent-integrated-system\\vendor\\topthink\\think-multi-app\\src\\MultiApp.php(51): think\\Pipeline->think\\{closure}(Object(app\\Request))\n#17 D:\\web\\intelligent-integrated-system\\vendor\\topthink\\framework\\src\\think\\Pipeline.php(59): think\\app\\MultiApp->think\\app\\{closure}(Object(app\\Request))\n#18 D:\\web\\intelligent-integrated-system\\vendor\\topthink\\framework\\src\\think\\middleware\\LoadLangPack.php(53): think\\Pipeline->think\\{closure}(Object(app\\Request))\n#19 [internal function]: think\\middleware\\LoadLangPack->handle(Object(app\\Request), Object(Closure))\n#20 D:\\web\\intelligent-integrated-system\\vendor\\topthink\\framework\\src\\think\\Middleware.php(134): call_user_func(Array, Object(app\\Request), Object(Closure))\n#21 D:\\web\\intelligent-integrated-system\\vendor\\topthink\\framework\\src\\think\\Pipeline.php(85): think\\Middleware->think\\{closure}(Object(app\\Request), Object(Closure))\n#22 D:\\web\\intelligent-integrated-system\\app\\common\\middleware\\AdminLog.php(18): think\\Pipeline->think\\{closure}(Object(app\\Request))\n#23 [internal function]: app\\common\\middleware\\AdminLog->handle(Object(app\\Request), Object(Closure))\n#24 D:\\web\\intelligent-integrated-system\\vendor\\topthink\\framework\\src\\think\\Middleware.php(134): call_user_func(Array, Object(app\\Request), Object(Closure))\n#25 D:\\web\\intelligent-integrated-system\\vendor\\topthink\\framework\\src\\think\\Pipeline.php(85): think\\Middleware->think\\{closure}(Object(app\\Request), Object(Closure))\n#26 D:\\web\\intelligent-integrated-system\\app\\common\\middleware\\AllowCrossDomain.php(64): think\\Pipeline->think\\{closure}(Object(app\\Request))\n#27 [internal function]: app\\common\\middleware\\AllowCrossDomain->handle(Object(app\\Request), Object(Closure))\n#28 D:\\web\\intelligent-integrated-system\\vendor\\topthink\\framework\\src\\think\\Middleware.php(134): call_user_func(Array, Object(app\\Request), Object(Closure))\n#29 D:\\web\\intelligent-integrated-system\\vendor\\topthink\\framework\\src\\think\\Pipeline.php(85): think\\Middleware->think\\{closure}(Object(app\\Request), Object(Closure))\n#30 D:\\web\\intelligent-integrated-system\\vendor\\topthink\\framework\\src\\think\\Pipeline.php(66): think\\Pipeline->think\\{closure}(Object(app\\Request))\n#31 D:\\web\\intelligent-integrated-system\\vendor\\topthink\\think-multi-app\\src\\MultiApp.php(50): think\\Pipeline->then(Object(Closure))\n#32 [internal function]: think\\app\\MultiApp->handle(Object(app\\Request), Object(Closure))\n#33 D:\\web\\intelligent-integrated-system\\vendor\\topthink\\framework\\src\\think\\Middleware.php(134): call_user_func(Array, Object(app\\Request), Object(Closure))\n#34 D:\\web\\intelligent-integrated-system\\vendor\\topthink\\framework\\src\\think\\Pipeline.php(85): think\\Middleware->think\\{closure}(Object(app\\Request), Object(Closure))\n#35 D:\\web\\intelligent-integrated-system\\vendor\\topthink\\think-throttle\\src\\Throttle.php(140): think\\Pipeline->think\\{closure}(Object(app\\Request))\n#36 [internal function]: think\\middleware\\Throttle->handle(Object(app\\Request), Object(Closure))\n#37 D:\\web\\intelligent-integrated-system\\vendor\\topthink\\framework\\src\\think\\Middleware.php(134): call_user_func(Array, Object(app\\Request), Object(Closure))\n#38 D:\\web\\intelligent-integrated-system\\vendor\\topthink\\framework\\src\\think\\Pipeline.php(85): think\\Middleware->think\\{closure}(Object(app\\Request), Object(Closure))\n#39 D:\\web\\intelligent-integrated-system\\vendor\\topthink\\think-trace\\src\\TraceDebug.php(71): think\\Pipeline->think\\{closure}(Object(app\\Request))\n#40 [internal function]: think\\trace\\TraceDebug->handle(Object(app\\Request), Object(Closure))\n#41 D:\\web\\intelligent-integrated-system\\vendor\\topthink\\framework\\src\\think\\Middleware.php(134): call_user_func(Array, Object(app\\Request), Object(Closure))\n#42 D:\\web\\intelligent-integrated-system\\vendor\\topthink\\framework\\src\\think\\Pipeline.php(85): think\\Middleware->think\\{closure}(Object(app\\Request), Object(Closure))\n#43 D:\\web\\intelligent-integrated-system\\vendor\\topthink\\framework\\src\\think\\Pipeline.php(66): think\\Pipeline->think\\{closure}(Object(app\\Request))\n#44 D:\\web\\intelligent-integrated-system\\vendor\\topthink\\framework\\src\\think\\Http.php(197): think\\Pipeline->then(Object(Closure))\n#45 D:\\web\\intelligent-integrated-system\\vendor\\topthink\\framework\\src\\think\\Http.php(162): think\\Http->runWithRequest(Object(app\\Request))\n#46 D:\\web\\intelligent-integrated-system\\public\\index.php(43): think\\Http->run()\n#47 D:\\web\\intelligent-integrated-system\\public\\router.php(20): require('D:\\\\web\\\\intellig...')\n#48 {main}"
}
}
1个回答默认排序 投票数排序
adminchat
这家伙很懒,什么也没写~
3月前
return json([
'code' => 1,
'msg' => '操作成功',
'data' => []
]);
用return json 才能正常,是不是$this->success
和$this->error
的问题
请先登录
热门问题
不可以在 try 里边使用 success 或 error