Inventory.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\model\StockConfig;
  4. use app\api\service\auth\ApiAuthService;
  5. use app\common\model\ProductConfig;
  6. use think\exception\ValidateException;
  7. use think\facade\Db;
  8. class Inventory extends Base
  9. {
  10. //品种包装箱/出入库列表
  11. public function stockList( StockConfig $stockConfig)
  12. {
  13. $type_id = $this->request->post('type_id', 'variety_name');
  14. if(!in_array($type_id, [$stockConfig::VarietyName, $stockConfig::PackingBox, $stockConfig::Material])) $this->error(__('参数错误'));
  15. $list = $stockConfig::where('type_id', $type_id)->field('id,title')->select();
  16. $this->success('ok', $list);
  17. }
  18. //出入库记录
  19. public function stocklog(ApiAuthService $authService)
  20. {
  21. $data = $this->request->post();
  22. $result = false;
  23. Db::startTrans();
  24. try {
  25. validate(ShopValidate::class)->scene('add')->check($data);
  26. $data['user_id'] = $this->userinfo['id'];
  27. $data['variety'] = json_encode($data['variety'], JSON_UNESCAPED_UNICODE);
  28. $result = $userEnterLog::create($data);
  29. Db::commit();
  30. }catch (ValidateException $e) {
  31. return $this->error($e->getError());
  32. } catch (\Exception $e) {
  33. Db::rollback();
  34. $this->error($e->getMessage());
  35. }
  36. if ($result === false) {
  37. $this->error(__('没有新增任何数据'));
  38. }
  39. $this->success();
  40. }
  41. }