| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?php
- namespace app\api\controller;
- use app\api\service\auth\MysqlAdapter;
- use app\api\service\auth\ApiAuthService;
- use app\api\validate\User as UserValidate;
- use think\exception\ValidateException;
- use think\facade\Db;
- class Inventory extends Base
- {
- //出入库
- public function stock()
- {
-
- $data = $this->request->post();
- $result = false;
- Db::startTrans();
- try {
-
- validate(ShopValidate::class)->scene('add')->check($data);
- $data['user_id'] = $this->userinfo['id'];
- $data['variety'] = json_encode($data['variety'], JSON_UNESCAPED_UNICODE);
- $result = $userEnterLog::create($data);
- Db::commit();
- }catch (ValidateException $e) {
-
- return $this->error($e->getError());
- } catch (\Exception $e) {
- Db::rollback();
- $this->error($e->getMessage());
- }
- if ($result === false) {
- $this->error(__('没有新增任何数据'));
- }
- $this->success();
-
- }
- //出入库记录
- public function stocklog(ApiAuthService $authService)
- {
-
- $data = $this->request->post();
- $result = false;
- Db::startTrans();
- try {
-
- validate(ShopValidate::class)->scene('add')->check($data);
- $data['user_id'] = $this->userinfo['id'];
- $data['variety'] = json_encode($data['variety'], JSON_UNESCAPED_UNICODE);
- $result = $userEnterLog::create($data);
- Db::commit();
- }catch (ValidateException $e) {
-
- return $this->error($e->getError());
- } catch (\Exception $e) {
- Db::rollback();
- $this->error($e->getMessage());
- }
- if ($result === false) {
- $this->error(__('没有新增任何数据'));
- }
- $this->success();
- }
-
- }
|