Inventory.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\model\StockConfig;
  4. use app\api\service\StockService;
  5. use app\common\model\StockLog;
  6. use think\exception\ValidateException;
  7. use app\api\validate\Stock as StockValidate;
  8. use think\facade\Db;
  9. class Inventory extends Base
  10. {
  11. //品种包装箱/出入库列表
  12. public function stockList(StockConfig $stockConfig)
  13. {
  14. $type_id = $this->request->post('type_id', 'variety_name');
  15. if(!in_array($type_id, [$stockConfig::VarietyName, $stockConfig::PackingBox, $stockConfig::Material])) $this->error(__('参数错误'));
  16. $list = $stockConfig::where('type_id', $type_id)->field('id,title,field_name')->select();
  17. $this->success('ok', $list);
  18. }
  19. //添加出入库
  20. public function stock(StockLog $stockLog, StockService $stockService)
  21. {
  22. $data = $this->request->post();
  23. $result = false;
  24. Db::startTrans();
  25. try {
  26. validate(StockValidate::class)->scene('add')->check($data);
  27. $resData = $stockService::setGoOutStock($this->userinfo['id'], $data);
  28. $result = $stockLog->saveAll($resData);
  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. //出入库记录
  42. public function stocklog(StockLog $stockLog)
  43. {
  44. $data = $this->request->post();
  45. //$result = $userEnterLog::create($data);
  46. $this->success();
  47. }
  48. }