|
|
@@ -3,9 +3,10 @@
|
|
|
namespace app\api\controller;
|
|
|
|
|
|
use app\common\model\StockConfig;
|
|
|
-use app\api\service\auth\ApiAuthService;
|
|
|
-use app\common\model\ProductConfig;
|
|
|
+use app\api\service\StockService;
|
|
|
+use app\common\model\StockLog;
|
|
|
use think\exception\ValidateException;
|
|
|
+use app\api\validate\Stock as StockValidate;
|
|
|
use think\facade\Db;
|
|
|
|
|
|
class Inventory extends Base
|
|
|
@@ -18,27 +19,24 @@ class Inventory extends Base
|
|
|
$type_id = $this->request->post('type_id', 'variety_name');
|
|
|
if(!in_array($type_id, [$stockConfig::VarietyName, $stockConfig::PackingBox, $stockConfig::Material])) $this->error(__('参数错误'));
|
|
|
$list = $stockConfig::where('type_id', $type_id)->field('id,title,field_name')->select();
|
|
|
-
|
|
|
$this->success('ok', $list);
|
|
|
}
|
|
|
|
|
|
|
|
|
//添加出入库
|
|
|
- public function stock(ApiAuthService $authService)
|
|
|
+ public function stock(StockLog $stockLog, StockService $stockService)
|
|
|
{
|
|
|
|
|
|
$data = $this->request->post();
|
|
|
$result = false;
|
|
|
Db::startTrans();
|
|
|
try {
|
|
|
-
|
|
|
- $where['user_id'] = $this->userinfo['id'];
|
|
|
|
|
|
+ validate(StockValidate::class)->scene('add')->check($data);
|
|
|
+
|
|
|
+ $resData = $stockService::setGoOutStock($this->userinfo['id'], $data);
|
|
|
|
|
|
- //join
|
|
|
- $data['variety'] = json_encode($data['variety'], JSON_UNESCAPED_UNICODE);
|
|
|
- $result = $userEnterLog::create($data);
|
|
|
-
|
|
|
+ $result = $stockLog->saveAll($resData);
|
|
|
Db::commit();
|
|
|
}catch (ValidateException $e) {
|
|
|
|
|
|
@@ -54,31 +52,14 @@ class Inventory extends Base
|
|
|
}
|
|
|
|
|
|
//出入库记录
|
|
|
- public function stocklog(ApiAuthService $authService)
|
|
|
+ public function stocklog(StockLog $stockLog)
|
|
|
{
|
|
|
|
|
|
$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);
|
|
|
+ //$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();
|
|
|
}
|
|
|
|