Inventory.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace app\api\controller;
  3. use app\api\service\auth\MysqlAdapter;
  4. use app\api\service\auth\ApiAuthService;
  5. use app\api\validate\User as UserValidate;
  6. use think\exception\ValidateException;
  7. use think\facade\Db;
  8. class Inventory extends Base
  9. {
  10. //出入库
  11. public function stock()
  12. {
  13. $data = $this->request->post();
  14. $result = false;
  15. Db::startTrans();
  16. try {
  17. validate(ShopValidate::class)->scene('add')->check($data);
  18. $data['user_id'] = $this->userinfo['id'];
  19. $data['variety'] = json_encode($data['variety'], JSON_UNESCAPED_UNICODE);
  20. $result = $userEnterLog::create($data);
  21. Db::commit();
  22. }catch (ValidateException $e) {
  23. return $this->error($e->getError());
  24. } catch (\Exception $e) {
  25. Db::rollback();
  26. $this->error($e->getMessage());
  27. }
  28. if ($result === false) {
  29. $this->error(__('没有新增任何数据'));
  30. }
  31. $this->success();
  32. }
  33. //出入库记录
  34. public function stocklog(ApiAuthService $authService)
  35. {
  36. $data = $this->request->post();
  37. $result = false;
  38. Db::startTrans();
  39. try {
  40. validate(ShopValidate::class)->scene('add')->check($data);
  41. $data['user_id'] = $this->userinfo['id'];
  42. $data['variety'] = json_encode($data['variety'], JSON_UNESCAPED_UNICODE);
  43. $result = $userEnterLog::create($data);
  44. Db::commit();
  45. }catch (ValidateException $e) {
  46. return $this->error($e->getError());
  47. } catch (\Exception $e) {
  48. Db::rollback();
  49. $this->error($e->getMessage());
  50. }
  51. if ($result === false) {
  52. $this->error(__('没有新增任何数据'));
  53. }
  54. $this->success();
  55. }
  56. }