|
|
@@ -350,7 +350,11 @@ sql;
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
+ /**
|
|
|
+ * 获取事务现号
|
|
|
+ *
|
|
|
+ * @return string
|
|
|
+ */
|
|
|
private function getTrNumber()
|
|
|
{
|
|
|
$val = ValueStore::query()->select("value")->where("name","flux_tr_number")->first();
|
|
|
@@ -360,8 +364,80 @@ sql;
|
|
|
return 'W'.$number;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 设置事务现号
|
|
|
+ */
|
|
|
private function setTrNumber()
|
|
|
{
|
|
|
ValueStore::query()->select("value")->where("name","flux_tr_number")->update(["value"=>DB::raw("flux_tr_number+1")]);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 入库
|
|
|
+ *
|
|
|
+ * @param integer $boxId
|
|
|
+ * @param integer $amount
|
|
|
+ * @param integer $commodityId
|
|
|
+ *
|
|
|
+ * @return bool
|
|
|
+ */
|
|
|
+ public function warehousing($boxId, $amount, $commodityId = null):bool
|
|
|
+ {
|
|
|
+ DB::beginTransaction();
|
|
|
+ try{
|
|
|
+ $storage = Storage::query()->where("material_box_id",$boxId)->lockForUpdate()->first();
|
|
|
+ if (!$storage && !$commodityId)return false;
|
|
|
+ if (!$storage){
|
|
|
+ Storage::query()->create([
|
|
|
+ "station_id" => null,
|
|
|
+ "material_box_id" => $boxId,
|
|
|
+ "commodity_id" => $commodityId,
|
|
|
+ "amount" => $amount,
|
|
|
+ ]);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ if ($commodityId && $storage->commodity_id && $storage->commodity_id!=$commodityId)return false;
|
|
|
+ $obj = [
|
|
|
+ "station_id" => null,
|
|
|
+ "amount" => DB::raw("amount + {$amount}"),
|
|
|
+ ];
|
|
|
+ if (!$storage->commodity_id && $commodityId)$obj["commodity_id"] = $commodityId;
|
|
|
+ $storage->update($obj);
|
|
|
+ DB::commit();
|
|
|
+ return true;
|
|
|
+ }catch (\Exception $e){
|
|
|
+ DB::rollBack();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 出库
|
|
|
+ *
|
|
|
+ * @param integer $boxId
|
|
|
+ * @param integer $amount
|
|
|
+ * @param integer $commodityId
|
|
|
+ *
|
|
|
+ * @return bool
|
|
|
+ */
|
|
|
+ public function outWarehousing($boxId, $amount, $commodityId = null):bool
|
|
|
+ {
|
|
|
+ DB::beginTransaction();
|
|
|
+ try{
|
|
|
+ $storage = Storage::query()->where("material_box_id",$boxId)->lockForUpdate()->first();
|
|
|
+ if (!$storage)return false;
|
|
|
+ if ($commodityId && $storage->commodity_id && $storage->commodity_id!=$commodityId)return false;
|
|
|
+ $obj = [
|
|
|
+ "station_id" => null,
|
|
|
+ "amount" => DB::raw("amount - {$amount}"),
|
|
|
+ ];
|
|
|
+ if (!$storage->commodity_id && $commodityId)$obj["commodity_id"] = $commodityId;
|
|
|
+ $storage->update($obj);
|
|
|
+ DB::commit();
|
|
|
+ return true;
|
|
|
+ }catch (\Exception $e){
|
|
|
+ DB::rollBack();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|